Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 16bca17

Browse files
authored
[v11.1.x] TemplateSrv: Backportable version of 90808 (#90837)
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 2e5b41c)
1 parent 907916d commit 16bca17

File tree

3 files changed

+10
-3
lines changed

3 files changed

+10
-3
lines changed

.betterer.results

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6236,6 +6236,9 @@ exports[`better eslint`] = {
62366236
[0, 0, 0, "Do not use any type assertions.", "0"],
62376237
[0, 0, 0, "Do not use any type assertions.", "1"]
62386238
],
6239+
"public/app/plugins/datasource/dashboard/datasource.ts:5381": [
6240+
[0, 0, 0, "Do not use any type assertions.", "0"]
6241+
],
62396242
"public/app/plugins/datasource/dashboard/index.ts:5381": [
62406243
[0, 0, 0, "Do not re-export imported variable (\`./runSharedRequest\`)", "0"],
62416244
[0, 0, 0, "Do not re-export imported variable (\`./DashboardQueryEditor\`)", "1"],

public/app/features/templating/template_srv.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import {
1515
TemplateSrv as BaseTemplateSrv,
1616
VariableInterpolation,
1717
} from '@grafana/runtime';
18-
import { sceneGraph, VariableCustomFormatterFn } from '@grafana/scenes';
18+
import { sceneGraph, VariableCustomFormatterFn, SceneObject } from '@grafana/scenes';
1919
import { VariableFormatID } from '@grafana/schema';
2020

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

public/app/plugins/datasource/dashboard/datasource.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import {
66
DataQueryResponse,
77
DataSourceInstanceSettings,
88
TestDataSourceResponse,
9+
ScopedVar,
910
} from '@grafana/data';
1011
import { SceneDataProvider, SceneDataTransformer, SceneObject } from '@grafana/scenes';
1112
import { findVizPanelByKey, getVizPanelKeyForPanelId } from 'app/features/dashboard-scene/utils/utils';
@@ -25,7 +26,8 @@ export class DashboardDatasource extends DataSourceApi<DashboardQuery> {
2526
}
2627

2728
query(options: DataQueryRequest<DashboardQuery>): Observable<DataQueryResponse> {
28-
const scene: SceneObject | undefined = options.scopedVars?.__sceneObject?.value;
29+
const sceneScopedVar: ScopedVar | undefined = options.scopedVars?.__sceneObject;
30+
let scene: SceneObject | undefined = sceneScopedVar ? (sceneScopedVar.value.valueOf() as SceneObject) : undefined;
2931

3032
if (options.requestId.indexOf('mixed') > -1) {
3133
throw new Error('Dashboard data source cannot be used with Mixed data source.');

0 commit comments

Comments
 (0)