azuremonitor: don't go back to dashboard if escape pressed in the editor

This commit is contained in:
Alexander Zobnin 2019-01-31 17:44:00 +03:00
parent 0c3657da7e
commit df9ecc6816
No known key found for this signature in database
GPG Key ID: E17E9ABACEFA59EB
4 changed files with 36 additions and 1 deletions

View File

@ -139,6 +139,10 @@ export class KeybindingSrv {
); );
} }
unbind(keyArg: string, keyType?: string) {
Mousetrap.unbind(keyArg, keyType);
}
showDashEditView() { showDashEditView() {
const search = _.extend(this.$location.search(), { editview: 'settings' }); const search = _.extend(this.$location.search(), { editview: 'settings' });
this.$location.search(search); this.$location.search(search);
@ -293,3 +297,17 @@ export class KeybindingSrv {
} }
coreModule.service('keybindingSrv', KeybindingSrv); coreModule.service('keybindingSrv', KeybindingSrv);
/**
* Code below exports the service to react components
*/
let singletonInstance: KeybindingSrv;
export function setKeybindingSrv(instance: KeybindingSrv) {
singletonInstance = instance;
}
export function getKeybindingSrv(): KeybindingSrv {
return singletonInstance;
}

View File

@ -61,7 +61,7 @@ export default class KustoQueryField extends QueryField {
} }
componentDidMount() { componentDidMount() {
this.updateMenu(); super.componentDidMount();
this.fetchSchema(); this.fetchSchema();
} }

View File

@ -9,6 +9,7 @@ import NewlinePlugin from './slate-plugins/newline';
import RunnerPlugin from './slate-plugins/runner'; import RunnerPlugin from './slate-plugins/runner';
import Typeahead from './typeahead'; import Typeahead from './typeahead';
import { getKeybindingSrv, KeybindingSrv } from 'app/core/services/keybindingSrv';
import { Block, Document, Text, Value } from 'slate'; import { Block, Document, Text, Value } from 'slate';
import { Editor } from 'slate-react'; import { Editor } from 'slate-react';
@ -61,6 +62,7 @@ class QueryField extends React.Component<any, any> {
menuEl: any; menuEl: any;
plugins: any; plugins: any;
resetTimer: any; resetTimer: any;
keybindingSrv: KeybindingSrv = getKeybindingSrv();
constructor(props, context) { constructor(props, context) {
super(props, context); super(props, context);
@ -90,6 +92,7 @@ class QueryField extends React.Component<any, any> {
} }
componentWillUnmount() { componentWillUnmount() {
this.restoreEscapeKeyBinding();
clearTimeout(this.resetTimer); clearTimeout(this.resetTimer);
} }
@ -218,6 +221,7 @@ class QueryField extends React.Component<any, any> {
if (onBlur) { if (onBlur) {
onBlur(); onBlur();
} }
this.restoreEscapeKeyBinding();
}; };
handleFocus = () => { handleFocus = () => {
@ -225,8 +229,18 @@ class QueryField extends React.Component<any, any> {
if (onFocus) { if (onFocus) {
onFocus(); onFocus();
} }
// Don't go back to dashboard if Escape pressed inside the editor.
this.removeEscapeKeyBinding();
}; };
removeEscapeKeyBinding() {
this.keybindingSrv.unbind('esc', 'keydown');
}
restoreEscapeKeyBinding() {
this.keybindingSrv.setupGlobal();
}
onClickItem = item => { onClickItem = item => {
const { suggestions } = this.state; const { suggestions } = this.state;
if (!suggestions || suggestions.length === 0) { if (!suggestions || suggestions.length === 0) {

View File

@ -10,6 +10,7 @@ import appEvents from 'app/core/app_events';
import { BackendSrv, setBackendSrv } from 'app/core/services/backend_srv'; import { BackendSrv, setBackendSrv } from 'app/core/services/backend_srv';
import { TimeSrv, setTimeSrv } from 'app/features/dashboard/services/TimeSrv'; import { TimeSrv, setTimeSrv } from 'app/features/dashboard/services/TimeSrv';
import { DatasourceSrv, setDatasourceSrv } from 'app/features/plugins/datasource_srv'; import { DatasourceSrv, setDatasourceSrv } from 'app/features/plugins/datasource_srv';
import { KeybindingSrv, setKeybindingSrv } from 'app/core/services/keybindingSrv';
import { AngularLoader, setAngularLoader } from 'app/core/services/AngularLoader'; import { AngularLoader, setAngularLoader } from 'app/core/services/AngularLoader';
import { configureStore } from 'app/store/configureStore'; import { configureStore } from 'app/store/configureStore';
@ -25,6 +26,7 @@ export class GrafanaCtrl {
backendSrv: BackendSrv, backendSrv: BackendSrv,
timeSrv: TimeSrv, timeSrv: TimeSrv,
datasourceSrv: DatasourceSrv, datasourceSrv: DatasourceSrv,
keybindingSrv: KeybindingSrv,
angularLoader: AngularLoader angularLoader: AngularLoader
) { ) {
// make angular loader service available to react components // make angular loader service available to react components
@ -32,6 +34,7 @@ export class GrafanaCtrl {
setBackendSrv(backendSrv); setBackendSrv(backendSrv);
setDatasourceSrv(datasourceSrv); setDatasourceSrv(datasourceSrv);
setTimeSrv(timeSrv); setTimeSrv(timeSrv);
setKeybindingSrv(keybindingSrv);
configureStore(); configureStore();
$scope.init = () => { $scope.init = () => {