|
|
|
@ -1,6 +1,6 @@ |
|
|
|
|
import { Unsubscribable } from 'rxjs'; |
|
|
|
|
|
|
|
|
|
import { SceneObjectBase, SceneObjectState, SceneQueryRunner, VizPanel } from '@grafana/scenes'; |
|
|
|
|
import { SceneDataTransformer, SceneObjectBase, SceneObjectState, SceneQueryRunner, VizPanel } from '@grafana/scenes'; |
|
|
|
|
import { SHARED_DASHBOARD_QUERY } from 'app/plugins/datasource/dashboard/constants'; |
|
|
|
|
import { MIXED_DATASOURCE_NAME } from 'app/plugins/datasource/mixed/MixedDataSource'; |
|
|
|
|
|
|
|
|
@ -28,6 +28,7 @@ export class DashboardDatasourceBehaviour extends SceneObjectBase<DashboardDatas |
|
|
|
|
private _activationHandler() { |
|
|
|
|
const queryRunner = this.parent; |
|
|
|
|
let libraryPanelSub: Unsubscribable; |
|
|
|
|
let transformerSub: Unsubscribable; |
|
|
|
|
let dashboard: DashboardScene; |
|
|
|
|
if (!(queryRunner instanceof SceneQueryRunner)) { |
|
|
|
|
throw new Error('DashboardDatasourceBehaviour must be attached to a SceneQueryRunner'); |
|
|
|
@ -73,6 +74,20 @@ export class DashboardDatasourceBehaviour extends SceneObjectBase<DashboardDatas |
|
|
|
|
throw new Error('Could not find SceneQueryRunner for panel'); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
const dataTransformer = sourcePanelQueryRunner.parent; |
|
|
|
|
|
|
|
|
|
if (dataTransformer instanceof SceneDataTransformer && dataTransformer.state.transformations.length) { |
|
|
|
|
// in mixed DS scenario we complete the observable and merge data, so on a variable change
|
|
|
|
|
// the data transformer will emit but there will be no subscription and thus not visual update
|
|
|
|
|
// on the panel. Similar thing happens when going to edit mode and back, where we unsubscribe and
|
|
|
|
|
// since we never re-run the query, only reprocess the transformations, the panel will not update.
|
|
|
|
|
transformerSub = dataTransformer.subscribeToState((newState, oldState) => { |
|
|
|
|
if (newState.data !== oldState.data) { |
|
|
|
|
queryRunner.runQueries(); |
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (this.prevRequestId && this.prevRequestId !== sourcePanelQueryRunner.state.data?.request?.requestId) { |
|
|
|
|
queryRunner.runQueries(); |
|
|
|
|
} |
|
|
|
@ -82,6 +97,10 @@ export class DashboardDatasourceBehaviour extends SceneObjectBase<DashboardDatas |
|
|
|
|
if (libraryPanelSub) { |
|
|
|
|
libraryPanelSub.unsubscribe(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (transformerSub) { |
|
|
|
|
transformerSub.unsubscribe(); |
|
|
|
|
} |
|
|
|
|
}; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -90,14 +109,10 @@ export class DashboardDatasourceBehaviour extends SceneObjectBase<DashboardDatas |
|
|
|
|
return true; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if ( |
|
|
|
|
return ( |
|
|
|
|
queryRunner.state.datasource?.uid === MIXED_DATASOURCE_NAME && |
|
|
|
|
queryRunner.state.queries.some((query) => query.datasource?.uid === SHARED_DASHBOARD_QUERY) |
|
|
|
|
) { |
|
|
|
|
return true; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return false; |
|
|
|
|
); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private handleLibPanelStateUpdates( |
|
|
|
|