diff --git a/src/core_plugins/kibana/public/dashboard/components/panel/lib/panel.js b/src/core_plugins/kibana/public/dashboard/components/panel/lib/panel.js index 07aad05710086..38e08660a7fb7 100644 --- a/src/core_plugins/kibana/public/dashboard/components/panel/lib/panel.js +++ b/src/core_plugins/kibana/public/dashboard/components/panel/lib/panel.js @@ -61,14 +61,17 @@ function Panel(id, type, panelId) { this.type = type; } -/** - * Factory function to create a panel object. - * - * @param id {string} - The id of the visualization this panel contains - * @param type {string} - The type of visualization this panel contains - * @param panelId {number} - A unique identifier for this panel in the grid - * @returns {Panel} - */ -export function createNewPanel(id, type, panelId) { - return new Panel(id, type, panelId); + +export class PanelFactory { + /** + * Factory function to create a panel object. + * + * @param id {string} - The id of the visualization this panel contains + * @param type {string} - The type of visualization this panel contains + * @param panelId {number} - A unique identifier for this panel in the grid + * @returns {Panel} + */ + static create(id, type, panelId) { + return new Panel(id, type, panelId); + } } diff --git a/src/core_plugins/kibana/public/dashboard/directives/grid.js b/src/core_plugins/kibana/public/dashboard/directives/grid.js index 42c6296bc2130..eef9f69b89d25 100644 --- a/src/core_plugins/kibana/public/dashboard/directives/grid.js +++ b/src/core_plugins/kibana/public/dashboard/directives/grid.js @@ -40,6 +40,12 @@ app.directive('dashboardGrid', function ($compile, Notifier) { }); }; + /** + * Removes the panel with the given id from the $scope.state.panels array. Does not + * remove the ui element from gridster - that is triggered by a watcher that is + * triggered on changes made to $scope.state.panels. + * @param panelId {number} + */ $scope.getPanelByPanelId = (panelId) => { return _.find($scope.state.panels, function (panel) { return panel.panelId === panelId; diff --git a/src/core_plugins/kibana/public/dashboard/index.js b/src/core_plugins/kibana/public/dashboard/index.js index 5a1eb82559f15..08a6cab3de0da 100644 --- a/src/core_plugins/kibana/public/dashboard/index.js +++ b/src/core_plugins/kibana/public/dashboard/index.js @@ -17,7 +17,7 @@ import uiRoutes from 'ui/routes'; import uiModules from 'ui/modules'; import indexTemplate from 'plugins/kibana/dashboard/index.html'; import { savedDashboardRegister } from 'plugins/kibana/dashboard/services/saved_dashboard_register'; -import { createNewPanel } from 'plugins/kibana/dashboard/components/panel/lib/panel'; +import { PanelFactory } from 'plugins/kibana/dashboard/components/panel/lib/panel'; require('ui/saved_objects/saved_object_registry').register(savedDashboardRegister); const app = uiModules.get('app/dashboard', [ @@ -272,12 +272,12 @@ app.directive('dashboardApp', function (Notifier, courier, AppState, timefilter, // called by the saved-object-finder when a user clicks a vis $scope.addVis = function (hit) { pendingVis++; - $state.panels.push(createNewPanel(hit.id, 'visualization', getMaxPanelId())); + $state.panels.push(PanelFactory.create(hit.id, 'visualization', getMaxPanelId())); }; $scope.addSearch = function (hit) { pendingVis++; - $state.panels.push(createNewPanel(hit.id, 'search', getMaxPanelId())); + $state.panels.push(PanelFactory.create(hit.id, 'search', getMaxPanelId())); }; // Setup configurable values for config directive, after objects are initialized