mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
DashboardScenes: Fix panel links to update on variable or timerange change (#94865)
* Fix panel links to update on variable or timerange change * refactor --------- Co-authored-by: alexandra vargas <alexa1866@gmail.com>
This commit is contained in:
parent
1860737117
commit
beac7de4df
@ -1,5 +1,12 @@
|
|||||||
import { DataLink, LinkModel } from '@grafana/data';
|
import { DataLink, LinkModel } from '@grafana/data';
|
||||||
import { SceneComponentProps, SceneObjectBase, SceneObjectState, VizPanel } from '@grafana/scenes';
|
import {
|
||||||
|
SceneComponentProps,
|
||||||
|
sceneGraph,
|
||||||
|
SceneObjectBase,
|
||||||
|
SceneObjectState,
|
||||||
|
VariableDependencyConfig,
|
||||||
|
VizPanel,
|
||||||
|
} from '@grafana/scenes';
|
||||||
import { Dropdown, Icon, Menu, PanelChrome, ToolbarButton } from '@grafana/ui';
|
import { Dropdown, Icon, Menu, PanelChrome, ToolbarButton } from '@grafana/ui';
|
||||||
|
|
||||||
import { getPanelLinks } from './PanelMenuBehavior';
|
import { getPanelLinks } from './PanelMenuBehavior';
|
||||||
@ -11,11 +18,20 @@ interface VizPanelLinksState extends SceneObjectState {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export class VizPanelLinks extends SceneObjectBase<VizPanelLinksState> {
|
export class VizPanelLinks extends SceneObjectBase<VizPanelLinksState> {
|
||||||
|
protected _variableDependency = new VariableDependencyConfig(this, {
|
||||||
|
onAnyVariableChanged: () => {
|
||||||
|
if (this.state.rawLinks && this.state.rawLinks.length > 0) {
|
||||||
|
this.forceRender();
|
||||||
|
}
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
static Component = VizPanelLinksRenderer;
|
static Component = VizPanelLinksRenderer;
|
||||||
}
|
}
|
||||||
|
|
||||||
function VizPanelLinksRenderer({ model }: SceneComponentProps<VizPanelLinks>) {
|
function VizPanelLinksRenderer({ model }: SceneComponentProps<VizPanelLinks>) {
|
||||||
const { menu, rawLinks } = model.useState();
|
const { menu, rawLinks } = model.useState();
|
||||||
|
sceneGraph.getTimeRange(model).useState();
|
||||||
|
|
||||||
if (!(model.parent instanceof VizPanel)) {
|
if (!(model.parent instanceof VizPanel)) {
|
||||||
throw new Error('VizPanelLinks must be a child of VizPanel');
|
throw new Error('VizPanelLinks must be a child of VizPanel');
|
||||||
|
Loading…
Reference in New Issue
Block a user