fixed panel removal

This commit is contained in:
Torkel Ödegaard 2019-02-03 17:15:23 +01:00
parent 09efa24f28
commit 4a8effddf5
5 changed files with 40 additions and 33 deletions

View File

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

View File

@ -171,33 +171,29 @@ export class DashNav extends PureComponent<Props> {
<i className="fa fa-link" /> <i className="fa fa-link" />
</a> </a>
)} )}
</div>
<div className="navbar-buttons navbar-buttons--tv"> <div className="navbar-buttons navbar-buttons--tv">
<button className="btn navbar-button navbar-button--tv" onClick={this.onToggleTVMode} title="Cycle view mode">
<i className="fa fa-desktop" />
</button>
</div>
{
// <gf-time-picker class="gf-timepicker-nav" dashboard="ctrl.dashboard" ng-if="!ctrl.dashboard.timepicker.hidden"></gf-time-picker>
}
{(isFullscreen || editview) && (
<div className="navbar-buttons navbar-buttons--close">
<button <button
className="btn navbar-button navbar-button--tv" className="btn navbar-button navbar-button--primary"
onClick={this.onToggleTVMode} onClick={this.onClose}
title="Cycle view mode" title="Back to dashboard"
> >
<i className="fa fa-desktop" /> <i className="fa fa-reply" />
</button> </button>
</div> </div>
)}
{
// <gf-time-picker class="gf-timepicker-nav" dashboard="ctrl.dashboard" ng-if="!ctrl.dashboard.timepicker.hidden"></gf-time-picker>
}
{(isFullscreen || editview) && (
<div className="navbar-buttons navbar-buttons--close">
<button
className="btn navbar-button navbar-button--primary"
onClick={this.onClose}
title="Back to dashboard"
>
<i className="fa fa-reply" />
</button>
</div>
)}
</div>
</div> </div>
); );
} }

View File

@ -1,20 +1,25 @@
// Libaries
import moment from 'moment'; import moment from 'moment';
import _ from 'lodash'; import _ from 'lodash';
import { DEFAULT_ANNOTATION_COLOR } from '@grafana/ui';
// Constants
import { DEFAULT_ANNOTATION_COLOR } from '@grafana/ui';
import { GRID_COLUMN_COUNT, REPEAT_DIR_VERTICAL, GRID_CELL_HEIGHT, GRID_CELL_VMARGIN } from 'app/core/constants'; import { GRID_COLUMN_COUNT, REPEAT_DIR_VERTICAL, GRID_CELL_HEIGHT, GRID_CELL_VMARGIN } from 'app/core/constants';
// Utils & Services
import { Emitter } from 'app/core/utils/emitter'; import { Emitter } from 'app/core/utils/emitter';
import { contextSrv } from 'app/core/services/context_srv'; import { contextSrv } from 'app/core/services/context_srv';
import sortByKeys from 'app/core/utils/sort_by_keys'; import sortByKeys from 'app/core/utils/sort_by_keys';
// Types
import { PanelModel } from './PanelModel'; import { PanelModel } from './PanelModel';
import { DashboardMigrator } from './DashboardMigrator'; import { DashboardMigrator } from './DashboardMigrator';
import { TimeRange } from '@grafana/ui/src'; import { TimeRange } from '@grafana/ui/src';
export class DashboardModel { export class DashboardModel {
id: any; id: any;
uid: any; uid: string;
title: any; title: string;
autoUpdate: any; autoUpdate: any;
description: any; description: any;
tags: any; tags: any;

View File

@ -7,6 +7,7 @@ import { updateLocation } from 'app/core/actions';
import { notifyApp } from 'app/core/actions'; import { notifyApp } from 'app/core/actions';
import locationUtil from 'app/core/utils/location_util'; import locationUtil from 'app/core/utils/location_util';
import { setDashboardLoadingState, ThunkResult, setDashboardModel } from './actions'; import { setDashboardLoadingState, ThunkResult, setDashboardModel } from './actions';
import { removePanel } from '../utils/panel';
// Types // Types
import { DashboardLoadingState } from 'app/types/dashboard'; import { DashboardLoadingState } from 'app/types/dashboard';
@ -102,7 +103,15 @@ export function initDashboard({ $injector, $scope, urlUid, urlSlug, urlType }: I
$scope.dashboard = dashboard; $scope.dashboard = dashboard;
$injector.get('dashboardViewStateSrv').create($scope); $injector.get('dashboardViewStateSrv').create($scope);
$injector.get('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);
};
$injector.get('keybindingSrv').setupDashboardBindings($scope, dashboard, onRemovePanel);
} catch (err) { } catch (err) {
dispatch(notifyApp(createErrorNotification('Dashboard init failed', err.toString()))); dispatch(notifyApp(createErrorNotification('Dashboard init failed', err.toString())));
console.log(err); console.log(err);

View File

@ -7,6 +7,7 @@ import { Emitter } from 'app/core/core';
import getFactors from 'app/core/utils/factors'; import getFactors from 'app/core/utils/factors';
import { import {
duplicatePanel, duplicatePanel,
removePanel,
copyPanel as copyPanelUtil, copyPanel as copyPanelUtil,
editPanelJson as editPanelJsonUtil, editPanelJson as editPanelJsonUtil,
sharePanel as sharePanelUtil, sharePanel as sharePanelUtil,
@ -213,9 +214,7 @@ export class PanelCtrl {
} }
removePanel() { removePanel() {
this.publishAppEvent('panel-remove', { removePanel(this.dashboard, this.panel, true);
panelId: this.panel.id,
});
} }
editPanelJson() { editPanelJson() {