Moved remove panel logic to dashboard srv

pull/15212/head
Torkel Ödegaard 6 years ago
parent a624c9713a
commit 49a597fcd0
  1. 4
      public/app/core/services/keybindingSrv.ts
  2. 13
      public/app/features/dashboard/services/DashboardSrv.ts
  3. 10
      public/app/features/dashboard/state/initDashboard.ts

@ -144,7 +144,7 @@ export class KeybindingSrv {
this.$location.search(search);
}
setupDashboardBindings(scope, dashboard, onRemovePanel) {
setupDashboardBindings(scope, dashboard) {
this.bind('mod+o', () => {
dashboard.graphTooltip = (dashboard.graphTooltip + 1) % 3;
appEvents.emit('graph-hover-clear');
@ -212,7 +212,7 @@ export class KeybindingSrv {
// delete panel
this.bind('p r', () => {
if (dashboard.meta.focusPanelId && dashboard.meta.canEdit) {
onRemovePanel(dashboard.meta.focusPanelId);
appEvents.emit('remove-panel', dashboard.meta.focusPanelId);
dashboard.meta.focusPanelId = 0;
}
});

@ -2,28 +2,35 @@ import coreModule from 'app/core/core_module';
import { appEvents } from 'app/core/app_events';
import locationUtil from 'app/core/utils/location_util';
import { DashboardModel } from '../state/DashboardModel';
import { removePanel } from '../utils/panel';
export class DashboardSrv {
dash: any;
dash: DashboardModel;
/** @ngInject */
constructor(private backendSrv, private $rootScope, private $location) {
appEvents.on('save-dashboard', this.saveDashboard.bind(this), $rootScope);
appEvents.on('panel-change-view', this.onPanelChangeView);
appEvents.on('remove-panel', this.onRemovePanel);
}
create(dashboard, meta) {
return new DashboardModel(dashboard, meta);
}
setCurrent(dashboard) {
setCurrent(dashboard: DashboardModel) {
this.dash = dashboard;
}
getCurrent() {
getCurrent(): DashboardModel {
return this.dash;
}
onRemovePanel = (panelId: number) => {
const dashboard = this.getCurrent();
removePanel(dashboard, dashboard.getPanelById(panelId), true);
};
onPanelChangeView = (options) => {
const urlParams = this.$location.search();

@ -13,7 +13,6 @@ import { updateLocation } from 'app/core/actions';
import { notifyApp } from 'app/core/actions';
import locationUtil from 'app/core/utils/location_util';
import { setDashboardLoadingState, ThunkResult, setDashboardModel, setDashboardLoadingSlow } from './actions';
import { removePanel } from '../utils/panel';
// Types
import { DashboardLoadingState, DashboardRouteInfo } from 'app/types';
@ -185,15 +184,8 @@ export function initDashboard({
// init unsaved changes tracking
unsavedChangesSrv.init(dashboard, $scope);
keybindingSrv.setupDashboardBindings($scope, dashboard);
// dashboard keybindings should not live in core, this needs a bigger refactoring
// So declaring this here so it can depend on the removePanel util function
// Long term onRemovePanel should be handled via react prop callback
const onRemovePanel = (panelId: number) => {
removePanel(dashboard, dashboard.getPanelById(panelId), true);
};
keybindingSrv.setupDashboardBindings($scope, dashboard, onRemovePanel);
} catch (err) {
dispatch(notifyApp(createErrorNotification('Dashboard init failed', err)));
console.log(err);

Loading…
Cancel
Save