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
This commit is contained in:
+4
-2
@@ -5429,8 +5429,7 @@ exports[`better eslint`] = {
|
|||||||
[0, 0, 0, "Unexpected any. Specify a different type.", "8"],
|
[0, 0, 0, "Unexpected any. Specify a different type.", "8"],
|
||||||
[0, 0, 0, "Do not use any type assertions.", "9"],
|
[0, 0, 0, "Do not use any type assertions.", "9"],
|
||||||
[0, 0, 0, "Do not use any type assertions.", "10"],
|
[0, 0, 0, "Do not use any type assertions.", "10"],
|
||||||
[0, 0, 0, "Do not use any type assertions.", "11"],
|
[0, 0, 0, "Do not use any type assertions.", "11"]
|
||||||
[0, 0, 0, "Do not use any type assertions.", "12"]
|
|
||||||
],
|
],
|
||||||
"public/app/features/trails/ActionTabs/AddToFiltersGraphAction.tsx:5381": [
|
"public/app/features/trails/ActionTabs/AddToFiltersGraphAction.tsx:5381": [
|
||||||
[0, 0, 0, "No untranslated strings. Wrap text with <Trans />", "0"]
|
[0, 0, 0, "No untranslated strings. Wrap text with <Trans />", "0"]
|
||||||
@@ -6113,6 +6112,9 @@ exports[`better eslint`] = {
|
|||||||
[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"]
|
||||||
],
|
],
|
||||||
|
"public/app/plugins/datasource/dashboard/datasource.ts:5381": [
|
||||||
|
[0, 0, 0, "Do not use any type assertions.", "0"]
|
||||||
|
],
|
||||||
"public/app/plugins/datasource/dashboard/index.ts:5381": [
|
"public/app/plugins/datasource/dashboard/index.ts:5381": [
|
||||||
[0, 0, 0, "Do not re-export imported variable (\`./runSharedRequest\`)", "0"],
|
[0, 0, 0, "Do not re-export imported variable (\`./runSharedRequest\`)", "0"],
|
||||||
[0, 0, 0, "Do not re-export imported variable (\`./DashboardQueryEditor\`)", "1"],
|
[0, 0, 0, "Do not re-export imported variable (\`./DashboardQueryEditor\`)", "1"],
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ import {
|
|||||||
TemplateSrv as BaseTemplateSrv,
|
TemplateSrv as BaseTemplateSrv,
|
||||||
VariableInterpolation,
|
VariableInterpolation,
|
||||||
} from '@grafana/runtime';
|
} from '@grafana/runtime';
|
||||||
import { sceneGraph, VariableCustomFormatterFn, SafeSerializableSceneObject } 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';
|
||||||
@@ -259,7 +259,8 @@ 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) {
|
||||||
const sceneObject = (scopedVars.__sceneObject.value as SafeSerializableSceneObject).valueOf();
|
// 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(
|
||||||
sceneObject,
|
sceneObject,
|
||||||
target,
|
target,
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ import {
|
|||||||
TestDataSourceResponse,
|
TestDataSourceResponse,
|
||||||
ScopedVar,
|
ScopedVar,
|
||||||
} from '@grafana/data';
|
} from '@grafana/data';
|
||||||
import { SafeSerializableSceneObject, 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';
|
||||||
|
|
||||||
import { DashboardQuery } from './types';
|
import { DashboardQuery } from './types';
|
||||||
@@ -27,13 +27,7 @@ export class DashboardDatasource extends DataSourceApi<DashboardQuery> {
|
|||||||
|
|
||||||
query(options: DataQueryRequest<DashboardQuery>): Observable<DataQueryResponse> {
|
query(options: DataQueryRequest<DashboardQuery>): Observable<DataQueryResponse> {
|
||||||
const sceneScopedVar: ScopedVar | undefined = options.scopedVars?.__sceneObject;
|
const sceneScopedVar: ScopedVar | undefined = options.scopedVars?.__sceneObject;
|
||||||
let scene: SceneObject | undefined;
|
let scene: SceneObject | undefined = sceneScopedVar ? (sceneScopedVar.value.valueOf() as SceneObject) : undefined;
|
||||||
|
|
||||||
if (!(sceneScopedVar instanceof SafeSerializableSceneObject)) {
|
|
||||||
throw new Error('Scene object from scopedVars is not safe serializable.');
|
|
||||||
}
|
|
||||||
|
|
||||||
scene = sceneScopedVar.valueOf();
|
|
||||||
|
|
||||||
if (options.requestId.indexOf('mixed') > -1) {
|
if (options.requestId.indexOf('mixed') > -1) {
|
||||||
throw new Error('Dashboard data source cannot be used with Mixed data source.');
|
throw new Error('Dashboard data source cannot be used with Mixed data source.');
|
||||||
|
|||||||
Reference in New Issue
Block a user