* Explore: add keyboard shortcut to run queries (#111675) * Update mock * Fix linting --------- Co-authored-by: Piotr Jamróz <pm.jamroz@gmail.com>
This commit is contained in:
co-authored by
Piotr Jamróz
parent
5cb4c311dc
commit
e61e406440
@@ -3,9 +3,19 @@ import { Unsubscribable } from 'rxjs';
|
||||
|
||||
import { getAppEvents } from '@grafana/runtime';
|
||||
import { useGrafana } from 'app/core/context/GrafanaContext';
|
||||
import { AbsoluteTimeEvent, CopyTimeEvent, PasteTimeEvent, ShiftTimeEvent, ZoomOutEvent } from 'app/types/events';
|
||||
import { getState } from 'app/store/store';
|
||||
import {
|
||||
AbsoluteTimeEvent,
|
||||
CopyTimeEvent,
|
||||
PasteTimeEvent,
|
||||
RunQueriesEvent,
|
||||
ShiftTimeEvent,
|
||||
ZoomOutEvent,
|
||||
} from 'app/types/events';
|
||||
import { useDispatch } from 'app/types/store';
|
||||
|
||||
import { runQueries } from '../state/query';
|
||||
import { selectPanesEntries } from '../state/selectors';
|
||||
import {
|
||||
copyTimeRangeToClipboard,
|
||||
makeAbsoluteTime,
|
||||
@@ -21,8 +31,23 @@ export function useKeyboardShortcuts() {
|
||||
useEffect(() => {
|
||||
keybindings.setupTimeRangeBindings(false);
|
||||
|
||||
// Explore-specific: run queries shortcut
|
||||
keybindings.bind('e r', () => {
|
||||
getAppEvents().publish(new RunQueriesEvent());
|
||||
});
|
||||
|
||||
const tearDown: Unsubscribable[] = [];
|
||||
|
||||
tearDown.push(
|
||||
getAppEvents().subscribe(RunQueriesEvent, () => {
|
||||
// Read panes at event time to avoid re-subscribing when panes change
|
||||
const panes = selectPanesEntries(getState());
|
||||
panes.forEach(([exploreId]) => {
|
||||
dispatch(runQueries({ exploreId }));
|
||||
});
|
||||
})
|
||||
);
|
||||
|
||||
tearDown.push(
|
||||
getAppEvents().subscribe(AbsoluteTimeEvent, () => {
|
||||
dispatch(makeAbsoluteTime());
|
||||
@@ -54,6 +79,7 @@ export function useKeyboardShortcuts() {
|
||||
);
|
||||
|
||||
return () => {
|
||||
keybindings.unbind('e r');
|
||||
tearDown.forEach((u) => u.unsubscribe());
|
||||
};
|
||||
}, [dispatch, keybindings]);
|
||||
|
||||
@@ -159,6 +159,10 @@ export class AbsoluteTimeEvent extends BusEventWithPayload<AbsoluteTimeEventPayl
|
||||
static type = 'absolute-time';
|
||||
}
|
||||
|
||||
export class RunQueriesEvent extends BusEventBase {
|
||||
static type = 'run-queries';
|
||||
}
|
||||
|
||||
export class RemovePanelEvent extends BusEventWithPayload<number> {
|
||||
static type = 'remove-panel';
|
||||
}
|
||||
|
||||
@@ -19,6 +19,8 @@ export function getGrafanaContextMock(overrides: Partial<GrafanaContextType> = {
|
||||
clearAndInitGlobalBindings: jest.fn(),
|
||||
setupDashboardBindings: jest.fn(),
|
||||
setupTimeRangeBindings: jest.fn(),
|
||||
bind: jest.fn(),
|
||||
unbind: jest.fn(),
|
||||
} as unknown as KeybindingSrv,
|
||||
newAssetsChecker: {
|
||||
start: jest.fn(),
|
||||
|
||||
Reference in New Issue
Block a user