Skip to content

Commit

Permalink
DashboardScene: adjust lib panel as a dashboard datasource refresh lo…
Browse files Browse the repository at this point in the history
…gic (#87120)

* activate library viz panel and adjust id extractor

* revert parts that are fixed in #87125

* clean up after activation handler
  • Loading branch information
Sergej-Vlasov committed May 2, 2024
1 parent 8802282 commit afbd02c
Showing 1 changed file with 15 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
import { Unsubscribable } from 'rxjs';

import { SceneObjectBase, SceneObjectState, SceneQueryRunner, VizPanel } from '@grafana/scenes';
import {
CancelActivationHandler,
SceneObjectBase,
SceneObjectState,
SceneQueryRunner,
VizPanel,
} from '@grafana/scenes';
import { SHARED_DASHBOARD_QUERY } from 'app/plugins/datasource/dashboard';

import { findVizPanelByKey, getDashboardSceneFor, getQueryRunnerFor, getVizPanelKeyForPanelId } from '../utils/utils';
Expand Down Expand Up @@ -53,10 +59,15 @@ export class DashboardDatasourceBehaviour extends SceneObjectBase<DashboardDatas

const sourcePanelQueryRunner = getQueryRunnerFor(panel);

let parentLibPanelCleanUp: undefined | CancelActivationHandler;

if (!sourcePanelQueryRunner) {
if (!(panel.parent instanceof LibraryVizPanel)) {
throw new Error('Could not find SceneQueryRunner for panel');
} else {
if (!panel.parent.isActive) {
parentLibPanelCleanUp = panel.parent.activate();
}
// Library panels load and create internal viz panel asynchroniously. Here we are subscribing to
// library panel state, and run dashboard queries when the source panel query runner is ready.
libraryPanelSub = panel.parent.subscribeToState((n, p) => {
Expand All @@ -74,6 +85,9 @@ export class DashboardDatasourceBehaviour extends SceneObjectBase<DashboardDatas
if (libraryPanelSub) {
libraryPanelSub.unsubscribe();
}
if (parentLibPanelCleanUp) {
parentLibPanelCleanUp();
}
};
}

Expand Down

0 comments on commit afbd02c

Please sign in to comment.