mirror of
https://github.com/grafana/grafana.git
synced 2025-02-10 23:55:47 -06:00
KeyboardShortcuts: Support panel attention for scenes (#88476)
* Support panel attention for scenes * Remove console.log * Bump scenes version for good measure * Mock appEvents * Remove unused import
This commit is contained in:
parent
e781716a38
commit
44ca89fe77
@ -1,5 +1,7 @@
|
||||
import { SetPanelAttentionEvent } from '@grafana/data';
|
||||
import { locationService } from '@grafana/runtime';
|
||||
import { sceneGraph, VizPanel } from '@grafana/scenes';
|
||||
import appEvents from 'app/core/app_events';
|
||||
import { KeybindingSet } from 'app/core/services/KeybindingSet';
|
||||
|
||||
import { ShareModal } from '../sharing/ShareModal';
|
||||
@ -12,6 +14,23 @@ import { onRemovePanel, toggleVizPanelLegend } from './PanelMenuBehavior';
|
||||
|
||||
export function setupKeyboardShortcuts(scene: DashboardScene) {
|
||||
const keybindings = new KeybindingSet();
|
||||
let vizPanelKey: string | null = null;
|
||||
|
||||
const panelAttentionSubscription = appEvents.subscribe(SetPanelAttentionEvent, (event) => {
|
||||
if (typeof event.payload.panelId === 'string') {
|
||||
vizPanelKey = event.payload.panelId;
|
||||
}
|
||||
});
|
||||
|
||||
function withFocusedPanel(scene: DashboardScene, fn: (vizPanel: VizPanel) => void) {
|
||||
return () => {
|
||||
const vizPanel = sceneGraph.findObject(scene, (o) => o.state.key === vizPanelKey);
|
||||
if (vizPanel && vizPanel instanceof VizPanel) {
|
||||
fn(vizPanel);
|
||||
return;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
// View panel
|
||||
keybindings.addBinding({
|
||||
@ -140,26 +159,9 @@ export function setupKeyboardShortcuts(scene: DashboardScene) {
|
||||
// collapse all rows (TODO)
|
||||
// expand all rows (TODO)
|
||||
|
||||
return () => keybindings.removeAll;
|
||||
}
|
||||
|
||||
export function withFocusedPanel(scene: DashboardScene, fn: (vizPanel: VizPanel) => void) {
|
||||
return () => {
|
||||
const elements = document.querySelectorAll(':hover');
|
||||
|
||||
for (let i = elements.length - 1; i > 0; i--) {
|
||||
const element = elements[i];
|
||||
|
||||
if (element instanceof HTMLElement && element.dataset?.vizPanelKey) {
|
||||
const panelKey = element.dataset?.vizPanelKey;
|
||||
const vizPanel = sceneGraph.findObject(scene, (o) => o.state.key === panelKey);
|
||||
|
||||
if (vizPanel && vizPanel instanceof VizPanel) {
|
||||
fn(vizPanel);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
keybindings.removeAll();
|
||||
panelAttentionSubscription.unsubscribe();
|
||||
};
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user