mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Use SafeSerializableSceneObject in TemplateSrv (#90272)
* Test * Opaque object * Update scenes tentatively * Betterer * Fix dashboard data source * Fix dashboard data source test * Scenes bump * Cleanup * Ivan's feedback
This commit is contained in:
parent
093f4cea70
commit
ec9e28567d
@ -5452,7 +5452,8 @@ 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"]
|
||||||
|
@ -260,7 +260,7 @@
|
|||||||
"@grafana/prometheus": "workspace:*",
|
"@grafana/prometheus": "workspace:*",
|
||||||
"@grafana/runtime": "workspace:*",
|
"@grafana/runtime": "workspace:*",
|
||||||
"@grafana/saga-icons": "workspace:*",
|
"@grafana/saga-icons": "workspace:*",
|
||||||
"@grafana/scenes": "5.4.1",
|
"@grafana/scenes": "5.6.0",
|
||||||
"@grafana/schema": "workspace:*",
|
"@grafana/schema": "workspace:*",
|
||||||
"@grafana/sql": "workspace:*",
|
"@grafana/sql": "workspace:*",
|
||||||
"@grafana/ui": "workspace:*",
|
"@grafana/ui": "workspace:*",
|
||||||
|
@ -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, SafeSerializableSceneObject } 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,9 @@ 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();
|
||||||
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,7 +6,14 @@ import {
|
|||||||
LoadingState,
|
LoadingState,
|
||||||
standardTransformersRegistry,
|
standardTransformersRegistry,
|
||||||
} from '@grafana/data';
|
} from '@grafana/data';
|
||||||
import { SceneDataNode, SceneDataTransformer, SceneFlexItem, SceneFlexLayout, VizPanel } from '@grafana/scenes';
|
import {
|
||||||
|
SafeSerializableSceneObject,
|
||||||
|
SceneDataNode,
|
||||||
|
SceneDataTransformer,
|
||||||
|
SceneFlexItem,
|
||||||
|
SceneFlexLayout,
|
||||||
|
VizPanel,
|
||||||
|
} from '@grafana/scenes';
|
||||||
import { getVizPanelKeyForPanelId } from 'app/features/dashboard-scene/utils/utils';
|
import { getVizPanelKeyForPanelId } from 'app/features/dashboard-scene/utils/utils';
|
||||||
import { getStandardTransformers } from 'app/features/transformers/standardTransformers';
|
import { getStandardTransformers } from 'app/features/transformers/standardTransformers';
|
||||||
|
|
||||||
@ -93,7 +100,7 @@ function setup(query: DashboardQuery) {
|
|||||||
intervalMs: 0,
|
intervalMs: 0,
|
||||||
range: getDefaultTimeRange(),
|
range: getDefaultTimeRange(),
|
||||||
scopedVars: {
|
scopedVars: {
|
||||||
__sceneObject: { value: scene },
|
__sceneObject: new SafeSerializableSceneObject(scene),
|
||||||
},
|
},
|
||||||
app: '',
|
app: '',
|
||||||
startTime: 0,
|
startTime: 0,
|
||||||
|
@ -6,8 +6,9 @@ import {
|
|||||||
DataQueryResponse,
|
DataQueryResponse,
|
||||||
DataSourceInstanceSettings,
|
DataSourceInstanceSettings,
|
||||||
TestDataSourceResponse,
|
TestDataSourceResponse,
|
||||||
|
ScopedVar,
|
||||||
} from '@grafana/data';
|
} from '@grafana/data';
|
||||||
import { SceneDataProvider, SceneDataTransformer, SceneObject } from '@grafana/scenes';
|
import { SafeSerializableSceneObject, 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';
|
||||||
@ -25,7 +26,14 @@ 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;
|
||||||
|
|
||||||
|
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.');
|
||||||
|
10
yarn.lock
10
yarn.lock
@ -3553,9 +3553,9 @@ __metadata:
|
|||||||
languageName: unknown
|
languageName: unknown
|
||||||
linkType: soft
|
linkType: soft
|
||||||
|
|
||||||
"@grafana/scenes@npm:5.4.1":
|
"@grafana/scenes@npm:5.6.0":
|
||||||
version: 5.4.1
|
version: 5.6.0
|
||||||
resolution: "@grafana/scenes@npm:5.4.1"
|
resolution: "@grafana/scenes@npm:5.6.0"
|
||||||
dependencies:
|
dependencies:
|
||||||
"@grafana/e2e-selectors": "npm:^11.0.0"
|
"@grafana/e2e-selectors": "npm:^11.0.0"
|
||||||
"@leeoniya/ufuzzy": "npm:^1.0.14"
|
"@leeoniya/ufuzzy": "npm:^1.0.14"
|
||||||
@ -3570,7 +3570,7 @@ __metadata:
|
|||||||
"@grafana/ui": ">=10.4"
|
"@grafana/ui": ">=10.4"
|
||||||
react: ^18.0.0
|
react: ^18.0.0
|
||||||
react-dom: ^18.0.0
|
react-dom: ^18.0.0
|
||||||
checksum: 10/761ba65d492a047eb2235d081c7077c159cbfe623fb860521428c949abe7dfbc78ccb8e235eaabc6a6ad771bdc55e71e781959d5ecba600918d836cab25e86f8
|
checksum: 10/4e1f87b5cce1ce742578eb00a75928c35277fa59a959d7d7adb2e81040e8ca69f9b0764e19cc11ac9b42b84de43224b8860bcba0d06b4983dbc840fd443f5f84
|
||||||
languageName: node
|
languageName: node
|
||||||
linkType: hard
|
linkType: hard
|
||||||
|
|
||||||
@ -17106,7 +17106,7 @@ __metadata:
|
|||||||
"@grafana/prometheus": "workspace:*"
|
"@grafana/prometheus": "workspace:*"
|
||||||
"@grafana/runtime": "workspace:*"
|
"@grafana/runtime": "workspace:*"
|
||||||
"@grafana/saga-icons": "workspace:*"
|
"@grafana/saga-icons": "workspace:*"
|
||||||
"@grafana/scenes": "npm:5.4.1"
|
"@grafana/scenes": "npm:5.6.0"
|
||||||
"@grafana/schema": "workspace:*"
|
"@grafana/schema": "workspace:*"
|
||||||
"@grafana/sql": "workspace:*"
|
"@grafana/sql": "workspace:*"
|
||||||
"@grafana/tsconfig": "npm:^1.3.0-rc1"
|
"@grafana/tsconfig": "npm:^1.3.0-rc1"
|
||||||
|
Loading…
Reference in New Issue
Block a user