Add list of bindings for updating on change

This commit is contained in:
Kristina Durivage 2023-01-20 17:01:13 -06:00
parent 92936d3a72
commit 092707371d
2 changed files with 9 additions and 1 deletions

View File

@ -29,9 +29,11 @@ import { withFocusedPanel } from './withFocusedPanelId';
export class KeybindingSrv {
constructor(private locationService: LocationService, private chromeService: AppChromeService) {}
bindings: string[] = [];
clearAndInitGlobalBindings() {
Mousetrap.reset();
this.bindings = [];
if (this.locationService.getLocation().pathname !== '/login') {
this.bind(['?', 'h'], this.showHelpModal);
@ -164,6 +166,9 @@ export class KeybindingSrv {
}
bind(keyArg: string | string[], fn: () => void) {
const keyArgArr = Array.isArray(keyArg) ? keyArg : [keyArg];
this.bindings.push(...keyArgArr);
Mousetrap.bind(
keyArg,
(evt) => {
@ -177,6 +182,8 @@ export class KeybindingSrv {
}
bindGlobal(keyArg: string, fn: () => void) {
this.bindings.push(keyArg);
Mousetrap.bindGlobal(
keyArg,
(evt) => {
@ -190,6 +197,7 @@ export class KeybindingSrv {
}
unbind(keyArg: string, keyType?: string) {
this.bindings = this.bindings.filter((binding) => binding !== keyArg);
Mousetrap.unbind(keyArg, keyType);
}

View File

@ -54,7 +54,7 @@ export function ExplorePage(props: GrafanaRouteComponentProps<{}, ExploreQueryPa
useEffect(() => {
keybindings.setupTimeRangeBindings(false);
}, [keybindings]);
}, [keybindings, keybindings.bindings]);
useEffect(() => {
if (!config.featureToggles.correlations) {