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:
Victor Marin 2024-10-17 17:22:04 +03:00 committed by GitHub
parent 1860737117
commit beac7de4df
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -1,5 +1,12 @@
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 { getPanelLinks } from './PanelMenuBehavior';
@ -11,11 +18,20 @@ interface VizPanelLinksState extends SceneObjectState {
}
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;
}
function VizPanelLinksRenderer({ model }: SceneComponentProps<VizPanelLinks>) {
const { menu, rawLinks } = model.useState();
sceneGraph.getTimeRange(model).useState();
if (!(model.parent instanceof VizPanel)) {
throw new Error('VizPanelLinks must be a child of VizPanel');