"use strict"; var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); Object.defineProperty(exports, "__esModule", { value: true }); exports.InspectorViewRegistry = void 0; var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty")); var _events = require("events"); /* * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one * or more contributor license agreements. Licensed under the Elastic License * 2.0 and the Server Side Public License, v 1; you may not use this file except * in compliance with, at your election, the Elastic License 2.0 or the Server * Side Public License, v 1. */ /** * @callback viewShouldShowFunc * @param {object} adapters - A list of adapters to check whether or not this view * should be shown for. * @returns {boolean} true - if this view should be shown for the given adapters. */ /** * A registry that will hold inspector views. */ class InspectorViewRegistry extends _events.EventEmitter { constructor(...args) { super(...args); (0, _defineProperty2.default)(this, "views", []); } /** * Register a new inspector view to the registry. Check the README.md in the * inspector directory for more information of the object format to register * here. This will also emit a 'change' event on the registry itself. * * @param {InspectorViewDescription} view - The view description to add to the registry. */ register(view) { if (!view) { return; } this.views.push(view); // Keep registry sorted by the order property this.views.sort((a, b) => (a.order || Number.MAX_VALUE) - (b.order || Number.MAX_VALUE)); this.emit('change'); } /** * Retrieve all views currently registered with the registry. * @returns {InspectorViewDescription[]} A by `order` sorted list of all registered * inspector views. */ getAll() { return this.views; } /** * Retrieve all registered views, that want to be visible for the specified adapters. * @param {object} adapters - an adapter configuration * @returns {InspectorViewDescription[]} All inespector view descriptions visible * for the specific adapters. */ getVisible(adapters) { if (!adapters) { return []; } return this.views.filter(view => !view.shouldShow || view.shouldShow(adapters)); } } exports.InspectorViewRegistry = InspectorViewRegistry;