[v10.4.x] TemplateSrv: Backportable version of 90808 (#91242)

* TemplateSrv: Backportable version of 90808  (#90833)

TemplateSrv: Backportable version of 90808 (#90816)

* TemplateSrv: Add test case for SafeSerializableSceneObject

* Update dashboard data source to use scoped vars scene object valueOf

* 11.1.x Backportable version of 90808

* lint

(cherry picked from commit 2e5b41cbcb)

* betterer
pull/91918/head
Dominik Prokop 11 months ago committed by GitHub
parent 257f46b2e4
commit 79c0be876f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 3
      .betterer.results
  2. 7
      public/app/features/templating/template_srv.ts
  3. 4
      public/app/plugins/datasource/dashboard/datasource.ts

@ -4682,6 +4682,9 @@ exports[`better eslint`] = {
"public/app/plugins/datasource/cloudwatch/utils/logsRetry.ts:5381": [ "public/app/plugins/datasource/cloudwatch/utils/logsRetry.ts:5381": [
[0, 0, 0, "Unexpected any. Specify a different type.", "0"] [0, 0, 0, "Unexpected any. Specify a different type.", "0"]
], ],
"public/app/plugins/datasource/dashboard/datasource.ts:5381": [
[0, 0, 0, "Do not use any type assertions.", "0"]
],
"public/app/plugins/datasource/dashboard/runSharedRequest.ts:5381": [ "public/app/plugins/datasource/dashboard/runSharedRequest.ts:5381": [
[0, 0, 0, "Do not use any type assertions.", "0"], [0, 0, 0, "Do not use any type assertions.", "0"],
[0, 0, 0, "Do not use any type assertions.", "1"] [0, 0, 0, "Do not use any type assertions.", "1"]

@ -15,7 +15,7 @@ import {
TemplateSrv as BaseTemplateSrv, TemplateSrv as BaseTemplateSrv,
VariableInterpolation, VariableInterpolation,
} from '@grafana/runtime'; } from '@grafana/runtime';
import { sceneGraph, VariableCustomFormatterFn } from '@grafana/scenes'; import { sceneGraph, VariableCustomFormatterFn, SceneObject } from '@grafana/scenes';
import { VariableFormatID } from '@grafana/schema'; import { VariableFormatID } from '@grafana/schema';
import { getVariablesCompatibility } from '../dashboard-scene/utils/getVariablesCompatibility'; import { getVariablesCompatibility } from '../dashboard-scene/utils/getVariablesCompatibility';
@ -249,8 +249,11 @@ export class TemplateSrv implements BaseTemplateSrv {
): string { ): string {
// Scenes compatability (primary method) is via SceneObject inside scopedVars. This way we get a much more accurate "local" scope for the evaluation // Scenes compatability (primary method) is via SceneObject inside scopedVars. This way we get a much more accurate "local" scope for the evaluation
if (scopedVars && scopedVars.__sceneObject) { if (scopedVars && scopedVars.__sceneObject) {
// We are using valueOf here as __sceneObject can be after scenes 5.6.0 a SafeSerializableSceneObject that overrides valueOf to return the underlying SceneObject
const sceneObject: SceneObject = scopedVars.__sceneObject.value.valueOf();
return sceneGraph.interpolate( return sceneGraph.interpolate(
scopedVars.__sceneObject.value, sceneObject,
target, target,
scopedVars, scopedVars,
format as string | VariableCustomFormatterFn | undefined format as string | VariableCustomFormatterFn | undefined

@ -6,6 +6,7 @@ import {
DataQueryResponse, DataQueryResponse,
DataSourceInstanceSettings, DataSourceInstanceSettings,
TestDataSourceResponse, TestDataSourceResponse,
ScopedVar,
} from '@grafana/data'; } from '@grafana/data';
import { SceneDataProvider, SceneDataTransformer, SceneObject } from '@grafana/scenes'; import { SceneDataProvider, SceneDataTransformer, SceneObject } from '@grafana/scenes';
import { findVizPanelByKey, getVizPanelKeyForPanelId } from 'app/features/dashboard-scene/utils/utils'; import { findVizPanelByKey, getVizPanelKeyForPanelId } from 'app/features/dashboard-scene/utils/utils';
@ -25,7 +26,8 @@ export class DashboardDatasource extends DataSourceApi<DashboardQuery> {
} }
query(options: DataQueryRequest<DashboardQuery>): Observable<DataQueryResponse> { query(options: DataQueryRequest<DashboardQuery>): Observable<DataQueryResponse> {
const scene: SceneObject | undefined = options.scopedVars?.__sceneObject?.value; const sceneScopedVar: ScopedVar | undefined = options.scopedVars?.__sceneObject;
let scene: SceneObject | undefined = sceneScopedVar ? (sceneScopedVar.value.valueOf() as SceneObject) : undefined;
if (!scene) { if (!scene) {
throw new Error('Can only be called from a scene'); throw new Error('Can only be called from a scene');

Loading…
Cancel
Save