@grafana/scenes 0.0.11 → 0.0.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/esm/components/SceneApp/SceneApp.js +164 -0
- package/dist/esm/components/SceneApp/SceneApp.js.map +1 -0
- package/dist/esm/components/SceneApp/utils.js +38 -0
- package/dist/esm/components/SceneApp/utils.js.map +1 -0
- package/dist/esm/components/SceneTimePicker.js +2 -1
- package/dist/esm/components/SceneTimePicker.js.map +1 -1
- package/dist/esm/components/VizPanel/VizPanel.js.map +1 -1
- package/dist/esm/components/VizPanel/VizPanelRenderer.js +14 -5
- package/dist/esm/components/VizPanel/VizPanelRenderer.js.map +1 -1
- package/dist/esm/core/SceneObjectBase.js +8 -2
- package/dist/esm/core/SceneObjectBase.js.map +1 -1
- package/dist/esm/core/SceneTimeRange.js +0 -2
- package/dist/esm/core/SceneTimeRange.js.map +1 -1
- package/dist/esm/core/types.js.map +1 -1
- package/dist/esm/index.js +1 -0
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/querying/SceneQueryRunner.js +3 -1
- package/dist/esm/querying/SceneQueryRunner.js.map +1 -1
- package/dist/esm/variables/interpolation/sceneInterpolator.js.map +1 -1
- package/dist/esm/variables/sets/SceneVariableSet.js +88 -41
- package/dist/esm/variables/sets/SceneVariableSet.js.map +1 -1
- package/dist/index.d.ts +53 -15
- package/dist/index.js +512 -259
- package/dist/index.js.map +1 -1
- package/package.json +5 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SceneQueryRunner.js","sources":["../../../src/querying/SceneQueryRunner.ts"],"sourcesContent":["import { cloneDeep } from 'lodash';\nimport { mergeMap, MonoTypeOperatorFunction, Unsubscribable, map, of } from 'rxjs';\n\nimport {\n CoreApp,\n DataQuery,\n DataQueryRequest,\n DataSourceRef,\n DataTransformerConfig,\n PanelData,\n rangeUtil,\n ScopedVar,\n TimeRange,\n transformDataFrame,\n} from '@grafana/data';\nimport { getRunRequest } from '@grafana/runtime';\n\nimport { SceneObjectBase } from '../core/SceneObjectBase';\nimport { sceneGraph } from '../core/sceneGraph';\nimport { SceneObject, SceneObjectStatePlain } from '../core/types';\nimport { getDataSource } from '../utils/getDataSource';\nimport { VariableDependencyConfig } from '../variables/VariableDependencyConfig';\n\nlet counter = 100;\n\nexport function getNextRequestId() {\n return 'QS' + counter++;\n}\n\nexport interface QueryRunnerState extends SceneObjectStatePlain {\n data?: PanelData;\n queries: DataQueryExtended[];\n transformations?: DataTransformerConfig[];\n datasource?: DataSourceRef;\n minInterval?: string;\n maxDataPoints?: number;\n // Non persisted state\n maxDataPointsFromWidth?: boolean;\n}\n\nexport interface DataQueryExtended extends DataQuery {\n [key: string]: any;\n}\n\nexport class SceneQueryRunner extends SceneObjectBase<QueryRunnerState> {\n private _querySub?: Unsubscribable;\n private _containerWidth?: number;\n\n protected _variableDependency = new VariableDependencyConfig(this, {\n statePaths: ['queries', 'datasource'],\n onReferencedVariableValueChanged: () => this.runQueries(),\n });\n\n public activate() {\n super.activate();\n const timeRange = sceneGraph.getTimeRange(this);\n\n this._subs.add(\n timeRange.subscribeToState({\n next: (timeRange) => {\n this.runWithTimeRange(timeRange.value);\n },\n })\n );\n\n if (this.shouldRunQueriesOnActivate()) {\n this.runQueries();\n }\n }\n\n private shouldRunQueriesOnActivate() {\n // If we already have data, no need\n // TODO validate that time range is similar and if not we should run queries again\n if (this.state.data) {\n return false;\n }\n\n // If no maxDataPoints specified we need might to wait for container width to be set from the outside\n if (!this.state.maxDataPoints && this.state.maxDataPointsFromWidth && !this._containerWidth) {\n return false;\n }\n\n return true;\n }\n\n public deactivate(): void {\n super.deactivate();\n\n if (this._querySub) {\n this._querySub.unsubscribe();\n this._querySub = undefined;\n }\n }\n\n public setContainerWidth(width: number) {\n // If we don't have a width we should run queries\n if (!this._containerWidth && width > 0) {\n this._containerWidth = width;\n\n // If we don't have maxDataPoints specifically set and maxDataPointsFromWidth is true\n if (this.state.maxDataPointsFromWidth && !this.state.maxDataPoints) {\n // As this is called from render path we need to wait for next tick before running queries\n setTimeout(() => {\n if (this.isActive && !this._querySub) {\n this.runQueries();\n }\n }, 0);\n }\n } else {\n // let's just remember the width until next query issue\n this._containerWidth = width;\n }\n }\n\n public runQueries() {\n const timeRange = sceneGraph.getTimeRange(this);\n this.runWithTimeRange(timeRange.state.value);\n }\n\n private getMaxDataPoints() {\n return this.state.maxDataPoints ?? this._containerWidth ?? 500;\n }\n\n private async runWithTimeRange(timeRange: TimeRange) {\n const { datasource, minInterval, queries } = this.state;\n const sceneObjectScopedVar: Record<string, ScopedVar<SceneQueryRunner>> = {\n __sceneObject: { text: '__sceneObject', value: this },\n };\n const request: DataQueryRequest = {\n app: CoreApp.Dashboard,\n requestId: getNextRequestId(),\n timezone: 'browser',\n panelId: 1,\n dashboardId: 1,\n range: timeRange,\n interval: '1s',\n intervalMs: 1000,\n targets: cloneDeep(queries),\n maxDataPoints: this.getMaxDataPoints(),\n scopedVars: sceneObjectScopedVar,\n startTime: Date.now(),\n };\n\n try {\n const ds = await getDataSource(datasource, request.scopedVars);\n\n // Attach the data source name to each query\n request.targets = request.targets.map((query) => {\n if (!query.datasource) {\n query.datasource = ds.getRef();\n }\n return query;\n });\n\n // TODO interpolate minInterval\n const lowerIntervalLimit = minInterval ? minInterval : ds.interval;\n const norm = rangeUtil.calculateInterval(timeRange, request.maxDataPoints!, lowerIntervalLimit);\n\n // make shallow copy of scoped vars,\n // and add built in variables interval and interval_ms\n request.scopedVars = Object.assign({}, request.scopedVars, {\n __interval: { text: norm.interval, value: norm.interval },\n __interval_ms: { text: norm.intervalMs.toString(), value: norm.intervalMs },\n });\n\n request.interval = norm.interval;\n request.intervalMs = norm.intervalMs;\n\n const runRequest = getRunRequest();\n this._querySub = runRequest(ds, request)\n .pipe(getTransformationsStream(this, this.state.transformations))\n .subscribe({\n next: this.onDataReceived,\n });\n } catch (err) {\n console.error('PanelQueryRunner Error', err);\n }\n }\n\n private onDataReceived = (data: PanelData) => {\n this.setState({ data });\n };\n}\n\nexport const getTransformationsStream: (\n sceneObject: SceneObject,\n transformations?: DataTransformerConfig[]\n) => MonoTypeOperatorFunction<PanelData> = (sceneObject, transformations) => (inputStream) => {\n return inputStream.pipe(\n mergeMap((data) => {\n if (!transformations || transformations.length === 0) {\n return of(data);\n }\n\n const ctx = {\n interpolate: (value: string) => {\n return sceneGraph.interpolate(sceneObject, value, data?.request?.scopedVars);\n },\n };\n\n return transformDataFrame(transformations, data.series, ctx).pipe(map((series) => ({ ...data, series })));\n })\n );\n};\n"],"names":["timeRange"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAuBA,IAAI,OAAU,GAAA,GAAA,CAAA;AAEP,SAAS,gBAAmB,GAAA;AACjC,EAAA,OAAO,IAAO,GAAA,OAAA,EAAA,CAAA;AAChB,CAAA;AAiBO,MAAM,yBAAyB,eAAkC,CAAA;AAAA,EAAjE,WAAA,GAAA;AAAA,IAAA,KAAA,CAAA,GAAA,SAAA,CAAA,CAAA;AAIL,IAAU,IAAA,CAAA,mBAAA,GAAsB,IAAI,wBAAA,CAAyB,IAAM,EAAA;AAAA,MACjE,UAAA,EAAY,CAAC,SAAA,EAAW,YAAY,CAAA;AAAA,MACpC,gCAAA,EAAkC,MAAM,IAAA,CAAK,UAAW,EAAA;AAAA,KACzD,CAAA,CAAA;AAgID,IAAQ,IAAA,CAAA,cAAA,GAAiB,CAAC,IAAoB,KAAA;AAC5C,MAAK,IAAA,CAAA,QAAA,CAAS,EAAE,IAAA,EAAM,CAAA,CAAA;AAAA,KACxB,CAAA;AAAA,GAAA;AAAA,EAhIO,QAAW,GAAA;AAChB,IAAA,KAAA,CAAM,QAAS,EAAA,CAAA;AACf,IAAM,MAAA,SAAA,GAAY,UAAW,CAAA,YAAA,CAAa,IAAI,CAAA,CAAA;AAE9C,IAAA,IAAA,CAAK,KAAM,CAAA,GAAA;AAAA,MACT,UAAU,gBAAiB,CAAA;AAAA,QACzB,IAAA,EAAM,CAACA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AA;AACA,MAAQ,OAAA,CAAA,KAAA,CAAM,0BAA0B,GAAG,CAAA,CAAA;AAAA,KAC7C;AAAA,GACF;AAKF,CAAA;AAEO,MAAM,wBAG8B,GAAA,CAAC,WAAa,EAAA,eAAA,KAAoB,CAAC,WAAgB,KAAA;AAC5F,EAAA,OAAO,WAAY,CAAA,IAAA;AAAA,IACjB,QAAA,CAAS,CAAC,IAAS,KAAA;AACjB,MAAA,IAAI,CAAC,eAAA,IAAmB,eAAgB,CAAA,MAAA,KAAW,CAAG,EAAA;AACpD,QAAA,OAAO,GAAG,IAAI,CAAA,CAAA;AAAA,OAChB;AAEA,MAAA,MAAM,GAAM,GAAA;AAAA,QACV,WAAA,EAAa,CAAC,KAAkB,KAAA;AAnMxC,UAAA,IAAA,EAAA,CAAA;AAoMU,UAAA,OAAO,WAAW,WAAY,CAAA,WAAA,EAAa,QAAO,EAAM,GAAA,IAAA,IAAA,IAAA,GAAA,KAAA,CAAA,GAAA,IAAA,CAAA,OAAA,KAAN,mBAAe,UAAU,CAAA,CAAA;AAAA,SAC7E;AAAA,OACF,CAAA;AAEA,MAAA,OAAO,kBAAmB,CAAA,eAAA,EAAiB,IAAK,CAAA,MAAA,EAAQ,GAAG,CAAE,CAAA,IAAA,CAAK,GAAI,CAAA,CAAC,WAAY,aAAK,CAAA,cAAA,CAAA,EAAA,EAAA,IAAA,CAAA,EAAL,EAAW,MAAA,GAAS,CAAC,CAAA,CAAA;AAAA,KACzG,CAAA;AAAA,GACH,CAAA;AACF;;;;"}
|
|
1
|
+
{"version":3,"file":"SceneQueryRunner.js","sources":["../../../src/querying/SceneQueryRunner.ts"],"sourcesContent":["import { cloneDeep } from 'lodash';\nimport { mergeMap, MonoTypeOperatorFunction, Unsubscribable, map, of } from 'rxjs';\n\nimport {\n CoreApp,\n DataQuery,\n DataQueryRequest,\n DataSourceRef,\n DataTransformerConfig,\n PanelData,\n rangeUtil,\n ScopedVar,\n TimeRange,\n transformDataFrame,\n} from '@grafana/data';\nimport { getRunRequest } from '@grafana/runtime';\n\nimport { SceneObjectBase } from '../core/SceneObjectBase';\nimport { sceneGraph } from '../core/sceneGraph';\nimport { SceneObject, SceneObjectStatePlain } from '../core/types';\nimport { getDataSource } from '../utils/getDataSource';\nimport { VariableDependencyConfig } from '../variables/VariableDependencyConfig';\n\nlet counter = 100;\n\nexport function getNextRequestId() {\n return 'QS' + counter++;\n}\n\nexport interface QueryRunnerState extends SceneObjectStatePlain {\n data?: PanelData;\n queries: DataQueryExtended[];\n transformations?: DataTransformerConfig[];\n datasource?: DataSourceRef;\n minInterval?: string;\n maxDataPoints?: number;\n // Non persisted state\n maxDataPointsFromWidth?: boolean;\n}\n\nexport interface DataQueryExtended extends DataQuery {\n [key: string]: any;\n}\n\nexport class SceneQueryRunner extends SceneObjectBase<QueryRunnerState> {\n private _querySub?: Unsubscribable;\n private _containerWidth?: number;\n\n protected _variableDependency = new VariableDependencyConfig(this, {\n statePaths: ['queries', 'datasource'],\n onReferencedVariableValueChanged: () => this.runQueries(),\n });\n\n public activate() {\n super.activate();\n const timeRange = sceneGraph.getTimeRange(this);\n\n this._subs.add(\n timeRange.subscribeToState({\n next: (timeRange) => {\n this.runWithTimeRange(timeRange.value);\n },\n })\n );\n\n if (this.shouldRunQueriesOnActivate()) {\n this.runQueries();\n }\n }\n\n private shouldRunQueriesOnActivate() {\n // If we already have data, no need\n // TODO validate that time range is similar and if not we should run queries again\n if (this.state.data) {\n return false;\n }\n\n // If no maxDataPoints specified we need might to wait for container width to be set from the outside\n if (!this.state.maxDataPoints && this.state.maxDataPointsFromWidth && !this._containerWidth) {\n return false;\n }\n\n return true;\n }\n\n public deactivate(): void {\n super.deactivate();\n\n if (this._querySub) {\n this._querySub.unsubscribe();\n this._querySub = undefined;\n }\n }\n\n public setContainerWidth(width: number) {\n // If we don't have a width we should run queries\n if (!this._containerWidth && width > 0) {\n this._containerWidth = width;\n\n // If we don't have maxDataPoints specifically set and maxDataPointsFromWidth is true\n if (this.state.maxDataPointsFromWidth && !this.state.maxDataPoints) {\n // As this is called from render path we need to wait for next tick before running queries\n setTimeout(() => {\n if (this.isActive && !this._querySub) {\n this.runQueries();\n }\n }, 0);\n }\n } else {\n // if the updated container width is bigger than 0 let's remember the width until next query issue\n if (width > 0) {\n this._containerWidth = width;\n }\n }\n }\n\n public runQueries() {\n const timeRange = sceneGraph.getTimeRange(this);\n this.runWithTimeRange(timeRange.state.value);\n }\n\n private getMaxDataPoints() {\n return this.state.maxDataPoints ?? this._containerWidth ?? 500;\n }\n\n private async runWithTimeRange(timeRange: TimeRange) {\n const { datasource, minInterval, queries } = this.state;\n const sceneObjectScopedVar: Record<string, ScopedVar<SceneQueryRunner>> = {\n __sceneObject: { text: '__sceneObject', value: this },\n };\n const request: DataQueryRequest = {\n app: CoreApp.Dashboard,\n requestId: getNextRequestId(),\n timezone: 'browser',\n panelId: 1,\n dashboardId: 1,\n range: timeRange,\n interval: '1s',\n intervalMs: 1000,\n targets: cloneDeep(queries),\n maxDataPoints: this.getMaxDataPoints(),\n scopedVars: sceneObjectScopedVar,\n startTime: Date.now(),\n };\n\n try {\n const ds = await getDataSource(datasource, request.scopedVars);\n\n // Attach the data source name to each query\n request.targets = request.targets.map((query) => {\n if (!query.datasource) {\n query.datasource = ds.getRef();\n }\n return query;\n });\n\n // TODO interpolate minInterval\n const lowerIntervalLimit = minInterval ? minInterval : ds.interval;\n const norm = rangeUtil.calculateInterval(timeRange, request.maxDataPoints!, lowerIntervalLimit);\n\n // make shallow copy of scoped vars,\n // and add built in variables interval and interval_ms\n request.scopedVars = Object.assign({}, request.scopedVars, {\n __interval: { text: norm.interval, value: norm.interval },\n __interval_ms: { text: norm.intervalMs.toString(), value: norm.intervalMs },\n });\n\n request.interval = norm.interval;\n request.intervalMs = norm.intervalMs;\n\n const runRequest = getRunRequest();\n this._querySub = runRequest(ds, request)\n .pipe(getTransformationsStream(this, this.state.transformations))\n .subscribe({\n next: this.onDataReceived,\n });\n } catch (err) {\n console.error('PanelQueryRunner Error', err);\n }\n }\n\n private onDataReceived = (data: PanelData) => {\n this.setState({ data });\n };\n}\n\nexport const getTransformationsStream: (\n sceneObject: SceneObject,\n transformations?: DataTransformerConfig[]\n) => MonoTypeOperatorFunction<PanelData> = (sceneObject, transformations) => (inputStream) => {\n return inputStream.pipe(\n mergeMap((data) => {\n if (!transformations || transformations.length === 0) {\n return of(data);\n }\n\n const ctx = {\n interpolate: (value: string) => {\n return sceneGraph.interpolate(sceneObject, value, data?.request?.scopedVars);\n },\n };\n\n return transformDataFrame(transformations, data.series, ctx).pipe(map((series) => ({ ...data, series })));\n })\n );\n};\n"],"names":["timeRange"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAuBA,IAAI,OAAU,GAAA,GAAA,CAAA;AAEP,SAAS,gBAAmB,GAAA;AACjC,EAAA,OAAO,IAAO,GAAA,OAAA,EAAA,CAAA;AAChB,CAAA;AAiBO,MAAM,yBAAyB,eAAkC,CAAA;AAAA,EAAjE,WAAA,GAAA;AAAA,IAAA,KAAA,CAAA,GAAA,SAAA,CAAA,CAAA;AAIL,IAAU,IAAA,CAAA,mBAAA,GAAsB,IAAI,wBAAA,CAAyB,IAAM,EAAA;AAAA,MACjE,UAAA,EAAY,CAAC,SAAA,EAAW,YAAY,CAAA;AAAA,MACpC,gCAAA,EAAkC,MAAM,IAAA,CAAK,UAAW,EAAA;AAAA,KACzD,CAAA,CAAA;AAkID,IAAQ,IAAA,CAAA,cAAA,GAAiB,CAAC,IAAoB,KAAA;AAC5C,MAAK,IAAA,CAAA,QAAA,CAAS,EAAE,IAAA,EAAM,CAAA,CAAA;AAAA,KACxB,CAAA;AAAA,GAAA;AAAA,EAlIO,QAAW,GAAA;AAChB,IAAA,KAAA,CAAM,QAAS,EAAA,CAAA;AACf,IAAM,MAAA,SAAA,GAAY,UAAW,CAAA,YAAA,CAAa,IAAI,CAAA,CAAA;AAE9C,IAAA,IAAA,CAAK,KAAM,CAAA,GAAA;AAAA,MACT,UAAU,gBA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U,CAAA;AAAA,QACT,MAAM,IAAK,CAAA,cAAA;AAAA,OACZ,CAAA,CAAA;AAAA,aACI,GAAP,EAAA;AACA,MAAQ,OAAA,CAAA,KAAA,CAAM,0BAA0B,GAAG,CAAA,CAAA;AAAA,KAC7C;AAAA,GACF;AAKF,CAAA;AAEO,MAAM,wBAG8B,GAAA,CAAC,WAAa,EAAA,eAAA,KAAoB,CAAC,WAAgB,KAAA;AAC5F,EAAA,OAAO,WAAY,CAAA,IAAA;AAAA,IACjB,QAAA,CAAS,CAAC,IAAS,KAAA;AACjB,MAAA,IAAI,CAAC,eAAA,IAAmB,eAAgB,CAAA,MAAA,KAAW,CAAG,EAAA;AACpD,QAAA,OAAO,GAAG,IAAI,CAAA,CAAA;AAAA,OAChB;AAEA,MAAA,MAAM,GAAM,GAAA;AAAA,QACV,WAAA,EAAa,CAAC,KAAkB,KAAA;AArMxC,UAAA,IAAA,EAAA,CAAA;AAsMU,UAAA,OAAO,WAAW,WAAY,CAAA,WAAA,EAAa,QAAO,EAAM,GAAA,IAAA,IAAA,IAAA,GAAA,KAAA,CAAA,GAAA,IAAA,CAAA,OAAA,KAAN,mBAAe,UAAU,CAAA,CAAA;AAAA,SAC7E;AAAA,OACF,CAAA;AAEA,MAAA,OAAO,kBAAmB,CAAA,eAAA,EAAiB,IAAK,CAAA,MAAA,EAAQ,GAAG,CAAE,CAAA,IAAA,CAAK,GAAI,CAAA,CAAC,WAAY,aAAK,CAAA,cAAA,CAAA,EAAA,EAAA,IAAA,CAAA,EAAL,EAAW,MAAA,GAAS,CAAC,CAAA,CAAA;AAAA,KACzG,CAAA;AAAA,GACH,CAAA;AACF;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sceneInterpolator.js","sources":["../../../../src/variables/interpolation/sceneInterpolator.ts"],"sourcesContent":["import { ScopedVars } from '@grafana/data';\nimport { VariableModel, VariableType } from '@grafana/schema';\n\nimport { SceneObject } from '../../core/types';\nimport { VariableValue } from '../types';\n\nimport { getSceneVariableForScopedVar } from './ScopedVarsVariable';\nimport { formatRegistry, FormatRegistryID, FormatVariable } from './formatRegistry';\nimport { VARIABLE_REGEX } from '../constants';\n\nexport type CustomFormatterFn = (\n value: unknown,\n legacyVariableModel: Partial<VariableModel>,\n legacyDefaultFormatter?: CustomFormatterFn\n) => string;\n\n/**\n * This function will try to parse and replace any variable expression found in the target string. The sceneObject will be used as the source of variables. It will\n * use the scene graph and walk up the parent tree until it finds the closest variable.\n *\n * ScopedVars should not really be needed much in the new scene architecture as they can be added to the local scene node instead of passed in interpolate function.\n * It is supported here for backward compatibility and some edge cases where adding scoped vars to local scene node is not practical.\n */\nexport function sceneInterpolator(\n sceneObject: SceneObject,\n target: string | undefined | null,\n scopedVars?: ScopedVars,\n format?: string | CustomFormatterFn\n): string {\n if (!target) {\n return target ?? '';\n }\n\n VARIABLE_REGEX.lastIndex = 0;\n\n return target.replace(VARIABLE_REGEX, (match, var1, var2, fmt2, var3, fieldPath, fmt3) => {\n const variableName = var1 || var2 || var3;\n const fmt = fmt2 || fmt3 || format;\n let variable: FormatVariable | undefined | null;\n\n if (scopedVars && scopedVars[variableName]) {\n variable = getSceneVariableForScopedVar(variableName, scopedVars[variableName]);\n } else {\n variable = lookupSceneVariable(variableName, sceneObject);\n }\n\n if (!variable) {\n return match;\n }\n\n return formatValue(variable, variable.getValue(fieldPath), fmt);\n });\n}\n\nfunction lookupSceneVariable(name: string, sceneObject: SceneObject): FormatVariable | null | undefined {\n const variables = sceneObject.state.$variables;\n if (!variables) {\n if (sceneObject.parent) {\n return lookupSceneVariable(name, sceneObject.parent);\n } else {\n return null;\n }\n }\n\n const found = variables.getByName(name);\n if (found) {\n return found;\n } else if (sceneObject.parent) {\n return lookupSceneVariable(name, sceneObject.parent);\n }\n\n return null;\n}\n\nfunction formatValue(\n variable: FormatVariable,\n value: VariableValue | undefined | null,\n formatNameOrFn
|
|
1
|
+
{"version":3,"file":"sceneInterpolator.js","sources":["../../../../src/variables/interpolation/sceneInterpolator.ts"],"sourcesContent":["import { ScopedVars } from '@grafana/data';\nimport { VariableModel, VariableType } from '@grafana/schema';\n\nimport { SceneObject } from '../../core/types';\nimport { VariableValue } from '../types';\n\nimport { getSceneVariableForScopedVar } from './ScopedVarsVariable';\nimport { formatRegistry, FormatRegistryID, FormatVariable } from './formatRegistry';\nimport { VARIABLE_REGEX } from '../constants';\n\nexport type CustomFormatterFn = (\n value: unknown,\n legacyVariableModel: Partial<VariableModel>,\n legacyDefaultFormatter?: CustomFormatterFn\n) => string;\n\n/**\n * This function will try to parse and replace any variable expression found in the target string. The sceneObject will be used as the source of variables. It will\n * use the scene graph and walk up the parent tree until it finds the closest variable.\n *\n * ScopedVars should not really be needed much in the new scene architecture as they can be added to the local scene node instead of passed in interpolate function.\n * It is supported here for backward compatibility and some edge cases where adding scoped vars to local scene node is not practical.\n */\nexport function sceneInterpolator(\n sceneObject: SceneObject,\n target: string | undefined | null,\n scopedVars?: ScopedVars,\n format?: string | CustomFormatterFn\n): string {\n if (!target) {\n return target ?? '';\n }\n\n VARIABLE_REGEX.lastIndex = 0;\n\n return target.replace(VARIABLE_REGEX, (match, var1, var2, fmt2, var3, fieldPath, fmt3) => {\n const variableName = var1 || var2 || var3;\n const fmt = fmt2 || fmt3 || format;\n let variable: FormatVariable | undefined | null;\n\n if (scopedVars && scopedVars[variableName]) {\n variable = getSceneVariableForScopedVar(variableName, scopedVars[variableName]);\n } else {\n variable = lookupSceneVariable(variableName, sceneObject);\n }\n\n if (!variable) {\n return match;\n }\n\n return formatValue(variable, variable.getValue(fieldPath), fmt);\n });\n}\n\nfunction lookupSceneVariable(name: string, sceneObject: SceneObject): FormatVariable | null | undefined {\n const variables = sceneObject.state.$variables;\n if (!variables) {\n if (sceneObject.parent) {\n return lookupSceneVariable(name, sceneObject.parent);\n } else {\n return null;\n }\n }\n\n const found = variables.getByName(name);\n if (found) {\n return found;\n } else if (sceneObject.parent) {\n return lookupSceneVariable(name, sceneObject.parent);\n }\n\n return null;\n}\n\nfunction formatValue(\n variable: FormatVariable,\n value: VariableValue | undefined | null,\n formatNameOrFn?: string | CustomFormatterFn\n): string {\n if (value === null || value === undefined) {\n return '';\n }\n\n // Special handling for custom values that should not be formatted / escaped\n // This is used by the custom allValue that usually contain wildcards and therefore should not be escaped\n if (typeof value === 'object' && 'isCustomValue' in value && formatNameOrFn !== FormatRegistryID.text) {\n return value.toString();\n }\n\n // if (isAdHoc(variable) && format !== FormatRegistryID.queryParam) {\n // return '';\n // }\n\n // if it's an object transform value to string\n if (!Array.isArray(value) && typeof value === 'object') {\n value = `${value}`;\n }\n\n if (typeof formatNameOrFn === 'function') {\n return formatNameOrFn(value, {\n name: variable.state.name,\n type: variable.state.type as VariableType,\n });\n }\n\n let args: string[] = [];\n\n if (!formatNameOrFn) {\n formatNameOrFn = FormatRegistryID.glob;\n } else {\n // some formats have arguments that come after ':' character\n args = formatNameOrFn.split(':');\n if (args.length > 1) {\n formatNameOrFn = args[0];\n args = args.slice(1);\n } else {\n args = [];\n }\n }\n\n let formatter = formatRegistry.getIfExists(formatNameOrFn);\n\n if (!formatter) {\n console.error(`Variable format ${formatNameOrFn} not found. Using glob format as fallback.`);\n formatter = formatRegistry.get(FormatRegistryID.glob);\n }\n\n return formatter.formatter(value, args, variable);\n}\n"],"names":[],"mappings":";;;;AAuBO,SAAS,iBACd,CAAA,WAAA,EACA,MACA,EAAA,UAAA,EACA,MACQ,EAAA;AACR,EAAA,IAAI,CAAC,MAAQ,EAAA;AACX,IAAA,OAAO,MAAU,IAAA,IAAA,GAAA,MAAA,GAAA,EAAA,CAAA;AAAA,GACnB;AAEA,EAAA,cAAA,CAAe,SAAY,GAAA,CAAA,CAAA;AAE3B,EAAO,OAAA,MAAA,CAAO,OAAQ,CAAA,cAAA,EAAgB,CAAC,KAAA,EAAO,MAAM,IAAM,EAAA,IAAA,EAAM,IAAM,EAAA,SAAA,EAAW,IAAS,KAAA;AACxF,IAAM,MAAA,YAAA,GAAe,QAAQ,I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AAA,CAAM,mBAAmB,cAA0D,CAAA,0CAAA,CAAA,CAAA,CAAA;AAC3F,IAAY,SAAA,GAAA,cAAA,CAAe,GAAI,CAAA,gBAAA,CAAiB,IAAI,CAAA,CAAA;AAAA,GACtD;AAEA,EAAA,OAAO,SAAU,CAAA,SAAA,CAAU,KAAO,EAAA,IAAA,EAAM,QAAQ,CAAA,CAAA;AAClD;;;;"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { isEqual } from 'lodash';
|
|
1
2
|
import { SceneObjectBase } from '../../core/SceneObjectBase.js';
|
|
2
3
|
import { forEachSceneObjectInState } from '../../core/utils.js';
|
|
3
4
|
import { SceneVariableValueChangedEvent } from '../types.js';
|
|
@@ -5,53 +6,78 @@ import { SceneVariableValueChangedEvent } from '../types.js';
|
|
|
5
6
|
class SceneVariableSet extends SceneObjectBase {
|
|
6
7
|
constructor() {
|
|
7
8
|
super(...arguments);
|
|
8
|
-
this.
|
|
9
|
-
this.
|
|
10
|
-
this.
|
|
11
|
-
this.onVariableValueChanged = (event) => {
|
|
12
|
-
const variableThatChanged = event.payload;
|
|
13
|
-
this.variablesThatHaveChanged.add(variableThatChanged);
|
|
14
|
-
if (this.updating.has(variableThatChanged)) {
|
|
15
|
-
return;
|
|
16
|
-
}
|
|
17
|
-
for (const otherVariable of this.state.variables) {
|
|
18
|
-
if (otherVariable.variableDependency) {
|
|
19
|
-
if (otherVariable.variableDependency.hasDependencyOn(variableThatChanged.state.name)) {
|
|
20
|
-
this.variablesToUpdate.add(otherVariable);
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
this.updateNextBatch();
|
|
25
|
-
};
|
|
9
|
+
this._variablesThatHaveChanged = /* @__PURE__ */ new Set();
|
|
10
|
+
this._variablesToUpdate = /* @__PURE__ */ new Set();
|
|
11
|
+
this._updating = /* @__PURE__ */ new Map();
|
|
26
12
|
}
|
|
27
13
|
getByName(name) {
|
|
28
14
|
return this.state.variables.find((x) => x.state.name === name);
|
|
29
15
|
}
|
|
30
16
|
activate() {
|
|
31
17
|
super.activate();
|
|
32
|
-
this._subs.add(
|
|
33
|
-
|
|
18
|
+
this._subs.add(
|
|
19
|
+
this.subscribeToEvent(SceneVariableValueChangedEvent, (event) => this.handleVariableValueChanged(event.payload))
|
|
20
|
+
);
|
|
21
|
+
this.checkForVariablesThatChangedWhileInactive();
|
|
22
|
+
for (const variable of this.state.variables) {
|
|
23
|
+
if (this.variableNeedsUpdate(variable)) {
|
|
24
|
+
this._variablesToUpdate.add(variable);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
this.updateNextBatch();
|
|
28
|
+
}
|
|
29
|
+
checkForVariablesThatChangedWhileInactive() {
|
|
30
|
+
if (!this._validValuesWhenDeactivated) {
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
for (const variable of this.state.variables) {
|
|
34
|
+
if (this._validValuesWhenDeactivated.has(variable)) {
|
|
35
|
+
const value = this._validValuesWhenDeactivated.get(variable);
|
|
36
|
+
if (!isVariableValueEqual(value, variable.getValue())) {
|
|
37
|
+
writeVariableTraceLog(variable, "Changed while in-active");
|
|
38
|
+
this.handleVariableValueChanged(variable);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
variableNeedsUpdate(variable) {
|
|
44
|
+
if (!variable.validateAndUpdate) {
|
|
45
|
+
return false;
|
|
46
|
+
}
|
|
47
|
+
if (this._validValuesWhenDeactivated && this._validValuesWhenDeactivated.has(variable)) {
|
|
48
|
+
const value = this._validValuesWhenDeactivated.get(variable);
|
|
49
|
+
if (isVariableValueEqual(value, variable.getValue())) {
|
|
50
|
+
writeVariableTraceLog(variable, "Skipping updateAndValidate current value valid");
|
|
51
|
+
return false;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
return true;
|
|
34
55
|
}
|
|
35
56
|
deactivate() {
|
|
36
57
|
var _a;
|
|
37
58
|
super.deactivate();
|
|
38
|
-
for (const update of this.
|
|
59
|
+
for (const update of this._updating.values()) {
|
|
39
60
|
(_a = update.subscription) == null ? void 0 : _a.unsubscribe();
|
|
40
61
|
}
|
|
41
|
-
this.
|
|
42
|
-
this.
|
|
43
|
-
|
|
62
|
+
this._validValuesWhenDeactivated = /* @__PURE__ */ new Map();
|
|
63
|
+
for (const variable of this.state.variables) {
|
|
64
|
+
if (!this._variablesToUpdate.has(variable) || !this._updating.has(variable)) {
|
|
65
|
+
this._validValuesWhenDeactivated.set(variable, variable.getValue());
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
this._variablesToUpdate.clear();
|
|
69
|
+
this._updating.clear();
|
|
44
70
|
}
|
|
45
71
|
updateNextBatch() {
|
|
46
|
-
if (this.
|
|
72
|
+
if (this._variablesToUpdate.size === 0 && this._variablesThatHaveChanged.size > 0) {
|
|
47
73
|
this.notifyDependentSceneObjects();
|
|
48
74
|
return;
|
|
49
75
|
}
|
|
50
|
-
for (const variable of this.
|
|
76
|
+
for (const variable of this._variablesToUpdate) {
|
|
51
77
|
if (!variable.validateAndUpdate) {
|
|
52
78
|
throw new Error("Variable added to variablesToUpdate but does not have validateAndUpdate");
|
|
53
79
|
}
|
|
54
|
-
if (this.
|
|
80
|
+
if (this._updating.has(variable)) {
|
|
55
81
|
continue;
|
|
56
82
|
}
|
|
57
83
|
if (this.hasDependendencyInUpdateQueue(variable)) {
|
|
@@ -60,7 +86,8 @@ class SceneVariableSet extends SceneObjectBase {
|
|
|
60
86
|
const variableToUpdate = {
|
|
61
87
|
variable
|
|
62
88
|
};
|
|
63
|
-
this.
|
|
89
|
+
this._updating.set(variable, variableToUpdate);
|
|
90
|
+
writeVariableTraceLog(variable, "updateAndValidate started");
|
|
64
91
|
variableToUpdate.subscription = variable.validateAndUpdate().subscribe({
|
|
65
92
|
next: () => this.validateAndUpdateCompleted(variable),
|
|
66
93
|
error: (err) => this.handleVariableError(variable, err)
|
|
@@ -69,36 +96,45 @@ class SceneVariableSet extends SceneObjectBase {
|
|
|
69
96
|
}
|
|
70
97
|
validateAndUpdateCompleted(variable) {
|
|
71
98
|
var _a;
|
|
72
|
-
const update = this.
|
|
99
|
+
const update = this._updating.get(variable);
|
|
73
100
|
(_a = update == null ? void 0 : update.subscription) == null ? void 0 : _a.unsubscribe();
|
|
74
|
-
this.
|
|
75
|
-
this.
|
|
101
|
+
this._updating.delete(variable);
|
|
102
|
+
this._variablesToUpdate.delete(variable);
|
|
103
|
+
writeVariableTraceLog(variable, "updateAndValidate completed");
|
|
76
104
|
this.updateNextBatch();
|
|
77
105
|
}
|
|
78
106
|
handleVariableError(variable, err) {
|
|
79
107
|
var _a;
|
|
80
|
-
const update = this.
|
|
108
|
+
const update = this._updating.get(variable);
|
|
81
109
|
(_a = update == null ? void 0 : update.subscription) == null ? void 0 : _a.unsubscribe();
|
|
82
|
-
this.
|
|
83
|
-
this.
|
|
110
|
+
this._updating.delete(variable);
|
|
111
|
+
this._variablesToUpdate.delete(variable);
|
|
84
112
|
variable.setState({ loading: false, error: err });
|
|
113
|
+
writeVariableTraceLog(variable, "updateAndValidate error", err);
|
|
85
114
|
}
|
|
86
115
|
hasDependendencyInUpdateQueue(variable) {
|
|
87
116
|
var _a;
|
|
88
117
|
if (!variable.variableDependency) {
|
|
89
118
|
return false;
|
|
90
119
|
}
|
|
91
|
-
for (const otherVariable of this.
|
|
120
|
+
for (const otherVariable of this._variablesToUpdate.values()) {
|
|
92
121
|
if ((_a = variable.variableDependency) == null ? void 0 : _a.hasDependencyOn(otherVariable.state.name)) {
|
|
93
122
|
return true;
|
|
94
123
|
}
|
|
95
124
|
}
|
|
96
125
|
return false;
|
|
97
126
|
}
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
127
|
+
handleVariableValueChanged(variableThatChanged) {
|
|
128
|
+
this._variablesThatHaveChanged.add(variableThatChanged);
|
|
129
|
+
if (this._updating.has(variableThatChanged)) {
|
|
130
|
+
return;
|
|
131
|
+
}
|
|
132
|
+
for (const otherVariable of this.state.variables) {
|
|
133
|
+
if (otherVariable.variableDependency) {
|
|
134
|
+
if (otherVariable.variableDependency.hasDependencyOn(variableThatChanged.state.name)) {
|
|
135
|
+
writeVariableTraceLog(otherVariable, "Added to update quee, dependant variable value changed");
|
|
136
|
+
this._variablesToUpdate.add(otherVariable);
|
|
137
|
+
}
|
|
102
138
|
}
|
|
103
139
|
}
|
|
104
140
|
this.updateNextBatch();
|
|
@@ -108,18 +144,29 @@ class SceneVariableSet extends SceneObjectBase {
|
|
|
108
144
|
return;
|
|
109
145
|
}
|
|
110
146
|
this.traverseSceneAndNotify(this.parent);
|
|
111
|
-
this.
|
|
147
|
+
this._variablesThatHaveChanged.clear();
|
|
112
148
|
}
|
|
113
149
|
traverseSceneAndNotify(sceneObject) {
|
|
114
150
|
if (this === sceneObject) {
|
|
115
151
|
return;
|
|
116
152
|
}
|
|
117
153
|
if (sceneObject.variableDependency) {
|
|
118
|
-
sceneObject.variableDependency.variableValuesChanged(this.
|
|
154
|
+
sceneObject.variableDependency.variableValuesChanged(this._variablesThatHaveChanged);
|
|
119
155
|
}
|
|
120
156
|
forEachSceneObjectInState(sceneObject.state, (child) => this.traverseSceneAndNotify(child));
|
|
121
157
|
}
|
|
122
158
|
}
|
|
159
|
+
function writeVariableTraceLog(variable, message, err) {
|
|
160
|
+
if (window.grafanaLoggingSceneVariables) {
|
|
161
|
+
console.log(`Variable[${variable.state.name}]: ${message}`, err);
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
function isVariableValueEqual(a, b) {
|
|
165
|
+
if (a === b) {
|
|
166
|
+
return true;
|
|
167
|
+
}
|
|
168
|
+
return isEqual(a, b);
|
|
169
|
+
}
|
|
123
170
|
|
|
124
171
|
export { SceneVariableSet };
|
|
125
172
|
//# sourceMappingURL=SceneVariableSet.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SceneVariableSet.js","sources":["../../../../src/variables/sets/SceneVariableSet.ts"],"sourcesContent":["import { Unsubscribable } from 'rxjs';\n\nimport { SceneObjectBase } from '../../core/SceneObjectBase';\nimport { SceneObject } from '../../core/types';\nimport { forEachSceneObjectInState } from '../../core/utils';\nimport { SceneVariable, SceneVariables, SceneVariableSetState, SceneVariableValueChangedEvent } from '../types';\n\nexport class SceneVariableSet extends SceneObjectBase<SceneVariableSetState> implements SceneVariables {\n /** Variables that have changed in since the activation or since the first manual value change */\n private variablesThatHaveChanged = new Set<SceneVariable>();\n\n /** Variables that are scheduled to be validated and updated */\n private variablesToUpdate = new Set<SceneVariable>();\n\n /** Variables currently updating */\n private updating = new Map<SceneVariable, VariableUpdateInProgress>();\n\n public getByName(name: string): SceneVariable | undefined {\n // TODO: Replace with index\n return this.state.variables.find((x) => x.state.name === name);\n }\n\n /**\n * Subscribes to child variable value changes\n * And starts the variable value validation process\n */\n public activate(): void {\n super.activate();\n\n // Subscribe to changes to child variables\n this._subs.add(this.subscribeToEvent(SceneVariableValueChangedEvent, this.onVariableValueChanged));\n this.validateAndUpdateAll();\n }\n\n /**\n * Cancel all currently running updates\n */\n public deactivate(): void {\n super.deactivate();\n\n for (const update of this.updating.values()) {\n update.subscription?.unsubscribe();\n }\n\n this.variablesToUpdate.clear();\n this.updating.clear();\n this.variablesThatHaveChanged.clear();\n }\n\n /**\n * This loops through variablesToUpdate and update all that that can.\n * If one has a dependency that is currently in variablesToUpdate it will be skipped for now.\n */\n private updateNextBatch() {\n // If we have nothing more to update and variable values changed we need to update scene objects that depend on these variables\n if (this.variablesToUpdate.size === 0 && this.variablesThatHaveChanged.size > 0) {\n this.notifyDependentSceneObjects();\n return;\n }\n\n for (const variable of this.variablesToUpdate) {\n if (!variable.validateAndUpdate) {\n throw new Error('Variable added to variablesToUpdate but does not have validateAndUpdate');\n }\n\n // Ignore it if it's already started\n if (this.updating.has(variable)) {\n continue;\n }\n\n // Wait for variables that has dependencies that also needs updates\n if (this.hasDependendencyInUpdateQueue(variable)) {\n continue;\n }\n\n const variableToUpdate: VariableUpdateInProgress = {\n variable,\n };\n\n this.updating.set(variable, variableToUpdate);\n variableToUpdate.subscription = variable.validateAndUpdate().subscribe({\n next: () => this.validateAndUpdateCompleted(variable),\n error: (err) => this.handleVariableError(variable, err),\n });\n }\n }\n\n /**\n * A variable has completed it's update process. This could mean that variables that depend on it can now be updated in turn.\n */\n private validateAndUpdateCompleted(variable: SceneVariable) {\n const update = this.updating.get(variable);\n update?.subscription?.unsubscribe();\n\n this.updating.delete(variable);\n this.variablesToUpdate.delete(variable);\n this.updateNextBatch();\n }\n\n /**\n * TODO handle this properly (and show error in UI).\n * Not sure if this should be handled here on in MultiValueVariable\n */\n private handleVariableError(variable: SceneVariable, err: Error) {\n const update = this.updating.get(variable);\n update?.subscription?.unsubscribe();\n\n this.updating.delete(variable);\n this.variablesToUpdate.delete(variable);\n variable.setState({ loading: false, error: err });\n }\n\n /**\n * Checks if the variable has any dependencies that is currently in variablesToUpdate\n */\n private hasDependendencyInUpdateQueue(variable: SceneVariable) {\n if (!variable.variableDependency) {\n return false;\n }\n\n for (const otherVariable of this.variablesToUpdate.values()) {\n if (variable.variableDependency?.hasDependencyOn(otherVariable.state.name)) {\n return true;\n }\n }\n\n return false;\n }\n\n /**\n * Extract dependencies from all variables and add those that needs update to the variablesToUpdate map\n * Then it will start the update process.\n */\n private validateAndUpdateAll() {\n for (const variable of this.state.variables) {\n if (variable.validateAndUpdate) {\n this.variablesToUpdate.add(variable);\n }\n }\n\n this.updateNextBatch();\n }\n\n /**\n * This will trigger an update of all variables that depend on it.\n * */\n private onVariableValueChanged = (event: SceneVariableValueChangedEvent) => {\n const variableThatChanged = event.payload;\n\n this.variablesThatHaveChanged.add(variableThatChanged);\n\n // Ignore this change if it is currently updating\n if (this.updating.has(variableThatChanged)) {\n return;\n }\n\n // Add variables that depend on the changed variable to the update queue\n for (const otherVariable of this.state.variables) {\n if (otherVariable.variableDependency) {\n if (otherVariable.variableDependency.hasDependencyOn(variableThatChanged.state.name)) {\n this.variablesToUpdate.add(otherVariable);\n }\n }\n }\n\n this.updateNextBatch();\n };\n\n /**\n * Walk scene object graph and update all objects that depend on variables that have changed\n */\n private notifyDependentSceneObjects() {\n if (!this.parent) {\n return;\n }\n\n this.traverseSceneAndNotify(this.parent);\n this.variablesThatHaveChanged.clear();\n }\n\n /**\n * Recursivly walk the full scene object graph and notify all objects with dependencies that include any of changed variables\n */\n private traverseSceneAndNotify(sceneObject: SceneObject) {\n // No need to notify variables under this SceneVariableSet\n if (this === sceneObject) {\n return;\n }\n\n if (sceneObject.variableDependency) {\n sceneObject.variableDependency.variableValuesChanged(this.variablesThatHaveChanged);\n }\n\n forEachSceneObjectInState(sceneObject.state, (child) => this.traverseSceneAndNotify(child));\n }\n}\n\nexport interface VariableUpdateInProgress {\n variable: SceneVariable;\n subscription?: Unsubscribable;\n}\n"],"names":[],"mappings":";;;;AAOO,MAAM,yBAAyB,eAAiE,CAAA;AAAA,EAAhG,WAAA,GAAA;AAAA,IAAA,KAAA,CAAA,GAAA,SAAA,CAAA,CAAA;AAEL,IAAQ,IAAA,CAAA,wBAAA,uBAA+B,GAAmB,EAAA,CAAA;AAG1D,IAAQ,IAAA,CAAA,iBAAA,uBAAwB,GAAmB,EAAA,CAAA;AAGnD,IAAQ,IAAA,CAAA,QAAA,uBAAe,GAA6C,EAAA,CAAA;AAmIpE,IAAQ,IAAA,CAAA,sBAAA,GAAyB,CAAC,KAA0C,KAAA;AAC1E,MAAA,MAAM,sBAAsB,KAAM,CAAA,OAAA,CAAA;AAElC,MAAK,IAAA,CAAA,wBAAA,CAAyB,IAAI,mBAAmB,CAAA,CAAA;AAGrD,MAAA,IAAI,IAAK,CAAA,QAAA,CAAS,GAAI,CAAA,mBAAmB,CAAG,EAAA;AAC1C,QAAA,OAAA;AAAA,OACF;AAGA,MAAW,KAAA,MAAA,aAAA,IAAiB,IAAK,CAAA,KAAA,CAAM,SAAW,EAAA;AAChD,QAAA,IAAI,cAAc,kBAAoB,EAAA;AACpC,UAAA,IAAI,cAA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IAAK,CAAA,KAAA,CAAM,SAAW,EAAA;AAC3C,MAAA,IAAI,SAAS,iBAAmB,EAAA;AAC9B,QAAK,IAAA,CAAA,iBAAA,CAAkB,IAAI,QAAQ,CAAA,CAAA;AAAA,OACrC;AAAA,KACF;AAEA,IAAA,IAAA,CAAK,eAAgB,EAAA,CAAA;AAAA,GACvB;AAAA,EA8BQ,2BAA8B,GAAA;AACpC,IAAI,IAAA,CAAC,KAAK,MAAQ,EAAA;AAChB,MAAA,OAAA;AAAA,KACF;AAEA,IAAK,IAAA,CAAA,sBAAA,CAAuB,KAAK,MAAM,CAAA,CAAA;AACvC,IAAA,IAAA,CAAK,yBAAyB,KAAM,EAAA,CAAA;AAAA,GACtC;AAAA,EAKQ,uBAAuB,WAA0B,EAAA;AAEvD,IAAA,IAAI,SAAS,WAAa,EAAA;AACxB,MAAA,OAAA;AAAA,KACF;AAEA,IAAA,IAAI,YAAY,kBAAoB,EAAA;AAClC,MAAY,WAAA,CAAA,kBAAA,CAAmB,qBAAsB,CAAA,IAAA,CAAK,wBAAwB,CAAA,CAAA;AAAA,KACpF;AAEA,IAAA,yBAAA,CAA0B,YAAY,KAAO,EAAA,CAAC,UAAU,IAAK,CAAA,sBAAA,CAAuB,KAAK,CAAC,CAAA,CAAA;AAAA,GAC5F;AACF;;;;"}
|
|
1
|
+
{"version":3,"file":"SceneVariableSet.js","sources":["../../../../src/variables/sets/SceneVariableSet.ts"],"sourcesContent":["import { isEqual } from 'lodash';\nimport { Unsubscribable } from 'rxjs';\n\nimport { SceneObjectBase } from '../../core/SceneObjectBase';\nimport { SceneObject } from '../../core/types';\nimport { forEachSceneObjectInState } from '../../core/utils';\nimport {\n SceneVariable,\n SceneVariables,\n SceneVariableSetState,\n SceneVariableValueChangedEvent,\n VariableValue,\n} from '../types';\n\nexport class SceneVariableSet extends SceneObjectBase<SceneVariableSetState> implements SceneVariables {\n /** Variables that have changed in since the activation or since the first manual value change */\n private _variablesThatHaveChanged = new Set<SceneVariable>();\n\n /** Variables that are scheduled to be validated and updated */\n private _variablesToUpdate = new Set<SceneVariable>();\n\n /** Variables currently updating */\n private _updating = new Map<SceneVariable, VariableUpdateInProgress>();\n\n private _validValuesWhenDeactivated: Map<SceneVariable, VariableValue | undefined | null> | undefined;\n\n public getByName(name: string): SceneVariable | undefined {\n // TODO: Replace with index\n return this.state.variables.find((x) => x.state.name === name);\n }\n\n /**\n * Subscribes to child variable value changes\n * And starts the variable value validation process\n */\n public activate(): void {\n super.activate();\n\n // Subscribe to changes to child variables\n this._subs.add(\n this.subscribeToEvent(SceneVariableValueChangedEvent, (event) => this.handleVariableValueChanged(event.payload))\n );\n\n this.checkForVariablesThatChangedWhileInactive();\n\n // Add all variables that need updating to queue\n for (const variable of this.state.variables) {\n if (this.variableNeedsUpdate(variable)) {\n this._variablesToUpdate.add(variable);\n }\n }\n\n this.updateNextBatch();\n }\n\n /**\n * If variables changed while in in-active state we don't get any change events, so we need to check for that here.\n */\n private checkForVariablesThatChangedWhileInactive() {\n if (!this._validValuesWhenDeactivated) {\n return;\n }\n\n for (const variable of this.state.variables) {\n if (this._validValuesWhenDeactivated.has(variable)) {\n const value = this._validValuesWhenDeactivated.get(variable);\n if (!isVariableValueEqual(value, variable.getValue())) {\n writeVariableTraceLog(variable, 'Changed while in-active');\n this.handleVariableValueChanged(variable);\n }\n }\n }\n }\n\n private variableNeedsUpdate(variable: SceneVariable): boolean {\n if (!variable.validateAndUpdate) {\n return false;\n }\n\n // Check if we have a value from past active state\n if (this._validValuesWhenDeactivated && this._validValuesWhenDeactivated.has(variable)) {\n const value = this._validValuesWhenDeactivated.get(variable);\n // If value the same no need to re-validate it\n if (isVariableValueEqual(value, variable.getValue())) {\n writeVariableTraceLog(variable, 'Skipping updateAndValidate current value valid');\n return false;\n }\n }\n\n return true;\n }\n\n /**\n * Cancel all currently running updates\n */\n public deactivate(): void {\n super.deactivate();\n\n for (const update of this._updating.values()) {\n update.subscription?.unsubscribe();\n }\n\n // Remember current variable values\n this._validValuesWhenDeactivated = new Map();\n for (const variable of this.state.variables) {\n // if the current variable is not in queue to update and validate and not being actively updated then the value is ok\n if (!this._variablesToUpdate.has(variable) || !this._updating.has(variable)) {\n this._validValuesWhenDeactivated.set(variable, variable.getValue());\n }\n }\n\n this._variablesToUpdate.clear();\n this._updating.clear();\n }\n\n /**\n * This loops through variablesToUpdate and update all that that can.\n * If one has a dependency that is currently in variablesToUpdate it will be skipped for now.\n */\n private updateNextBatch() {\n // If we have nothing more to update and variable values changed we need to update scene objects that depend on these variables\n if (this._variablesToUpdate.size === 0 && this._variablesThatHaveChanged.size > 0) {\n this.notifyDependentSceneObjects();\n return;\n }\n\n for (const variable of this._variablesToUpdate) {\n if (!variable.validateAndUpdate) {\n throw new Error('Variable added to variablesToUpdate but does not have validateAndUpdate');\n }\n\n // Ignore it if it's already started\n if (this._updating.has(variable)) {\n continue;\n }\n\n // Wait for variables that has dependencies that also needs updates\n if (this.hasDependendencyInUpdateQueue(variable)) {\n continue;\n }\n\n const variableToUpdate: VariableUpdateInProgress = {\n variable,\n };\n\n this._updating.set(variable, variableToUpdate);\n writeVariableTraceLog(variable, 'updateAndValidate started');\n\n variableToUpdate.subscription = variable.validateAndUpdate().subscribe({\n next: () => this.validateAndUpdateCompleted(variable),\n error: (err) => this.handleVariableError(variable, err),\n });\n }\n }\n\n /**\n * A variable has completed it's update process. This could mean that variables that depend on it can now be updated in turn.\n */\n private validateAndUpdateCompleted(variable: SceneVariable) {\n const update = this._updating.get(variable);\n update?.subscription?.unsubscribe();\n\n this._updating.delete(variable);\n this._variablesToUpdate.delete(variable);\n\n writeVariableTraceLog(variable, 'updateAndValidate completed');\n\n this.updateNextBatch();\n }\n\n /**\n * TODO handle this properly (and show error in UI).\n * Not sure if this should be handled here on in MultiValueVariable\n */\n private handleVariableError(variable: SceneVariable, err: Error) {\n const update = this._updating.get(variable);\n update?.subscription?.unsubscribe();\n\n this._updating.delete(variable);\n this._variablesToUpdate.delete(variable);\n variable.setState({ loading: false, error: err });\n\n writeVariableTraceLog(variable, 'updateAndValidate error', err);\n }\n\n /**\n * Checks if the variable has any dependencies that is currently in variablesToUpdate\n */\n private hasDependendencyInUpdateQueue(variable: SceneVariable) {\n if (!variable.variableDependency) {\n return false;\n }\n\n for (const otherVariable of this._variablesToUpdate.values()) {\n if (variable.variableDependency?.hasDependencyOn(otherVariable.state.name)) {\n return true;\n }\n }\n\n return false;\n }\n\n private handleVariableValueChanged(variableThatChanged: SceneVariable) {\n this._variablesThatHaveChanged.add(variableThatChanged);\n\n // Ignore this change if it is currently updating\n if (this._updating.has(variableThatChanged)) {\n return;\n }\n\n // Add variables that depend on the changed variable to the update queue\n for (const otherVariable of this.state.variables) {\n if (otherVariable.variableDependency) {\n if (otherVariable.variableDependency.hasDependencyOn(variableThatChanged.state.name)) {\n writeVariableTraceLog(otherVariable, 'Added to update quee, dependant variable value changed');\n this._variablesToUpdate.add(otherVariable);\n }\n }\n }\n\n this.updateNextBatch();\n }\n\n /**\n * Walk scene object graph and update all objects that depend on variables that have changed\n */\n private notifyDependentSceneObjects() {\n if (!this.parent) {\n return;\n }\n\n this.traverseSceneAndNotify(this.parent);\n this._variablesThatHaveChanged.clear();\n }\n\n /**\n * Recursivly walk the full scene object graph and notify all objects with dependencies that include any of changed variables\n */\n private traverseSceneAndNotify(sceneObject: SceneObject) {\n // No need to notify variables under this SceneVariableSet\n if (this === sceneObject) {\n return;\n }\n\n if (sceneObject.variableDependency) {\n sceneObject.variableDependency.variableValuesChanged(this._variablesThatHaveChanged);\n }\n\n forEachSceneObjectInState(sceneObject.state, (child) => this.traverseSceneAndNotify(child));\n }\n}\n\nexport interface VariableUpdateInProgress {\n variable: SceneVariable;\n subscription?: Unsubscribable;\n}\n\nfunction writeVariableTraceLog(variable: SceneVariable, message: string, err?: Error) {\n if ((window as any).grafanaLoggingSceneVariables) {\n console.log(`Variable[${variable.state.name}]: ${message}`, err);\n }\n}\n\nfunction isVariableValueEqual(a: VariableValue | null | undefined, b: VariableValue |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GED
|
@@ -164,7 +164,6 @@ interface SceneTimeRangeState extends SceneObjectStatePlain {
|
|
|
164
164
|
}
|
|
165
165
|
interface SceneTimeRangeLike extends SceneObject<SceneTimeRangeState> {
|
|
166
166
|
onTimeRangeChange(timeRange: TimeRange): void;
|
|
167
|
-
onIntervalChanged(interval: string): void;
|
|
168
167
|
onRefresh(): void;
|
|
169
168
|
}
|
|
170
169
|
interface SceneObjectRef {
|
|
@@ -327,7 +326,6 @@ declare class SceneTimeRange extends SceneObjectBase<SceneTimeRangeState> implem
|
|
|
327
326
|
constructor(state?: Partial<SceneTimeRangeState>);
|
|
328
327
|
onTimeRangeChange: (timeRange: TimeRange) => void;
|
|
329
328
|
onRefresh: () => void;
|
|
330
|
-
onIntervalChanged: (_: string) => void;
|
|
331
329
|
getUrlState(state: SceneTimeRangeState): {
|
|
332
330
|
from: string;
|
|
333
331
|
to: string;
|
|
@@ -440,17 +438,23 @@ declare function VariableValueSelectorsRenderer({ model }: SceneComponentProps<V
|
|
|
440
438
|
|
|
441
439
|
declare class SceneVariableSet extends SceneObjectBase<SceneVariableSetState> implements SceneVariables {
|
|
442
440
|
/** Variables that have changed in since the activation or since the first manual value change */
|
|
443
|
-
private
|
|
441
|
+
private _variablesThatHaveChanged;
|
|
444
442
|
/** Variables that are scheduled to be validated and updated */
|
|
445
|
-
private
|
|
443
|
+
private _variablesToUpdate;
|
|
446
444
|
/** Variables currently updating */
|
|
447
|
-
private
|
|
445
|
+
private _updating;
|
|
446
|
+
private _validValuesWhenDeactivated;
|
|
448
447
|
getByName(name: string): SceneVariable | undefined;
|
|
449
448
|
/**
|
|
450
449
|
* Subscribes to child variable value changes
|
|
451
450
|
* And starts the variable value validation process
|
|
452
451
|
*/
|
|
453
452
|
activate(): void;
|
|
453
|
+
/**
|
|
454
|
+
* If variables changed while in in-active state we don't get any change events, so we need to check for that here.
|
|
455
|
+
*/
|
|
456
|
+
private checkForVariablesThatChangedWhileInactive;
|
|
457
|
+
private variableNeedsUpdate;
|
|
454
458
|
/**
|
|
455
459
|
* Cancel all currently running updates
|
|
456
460
|
*/
|
|
@@ -473,15 +477,7 @@ declare class SceneVariableSet extends SceneObjectBase<SceneVariableSetState> im
|
|
|
473
477
|
* Checks if the variable has any dependencies that is currently in variablesToUpdate
|
|
474
478
|
*/
|
|
475
479
|
private hasDependendencyInUpdateQueue;
|
|
476
|
-
|
|
477
|
-
* Extract dependencies from all variables and add those that needs update to the variablesToUpdate map
|
|
478
|
-
* Then it will start the update process.
|
|
479
|
-
*/
|
|
480
|
-
private validateAndUpdateAll;
|
|
481
|
-
/**
|
|
482
|
-
* This will trigger an update of all variables that depend on it.
|
|
483
|
-
* */
|
|
484
|
-
private onVariableValueChanged;
|
|
480
|
+
private handleVariableValueChanged;
|
|
485
481
|
/**
|
|
486
482
|
* Walk scene object graph and update all objects that depend on variables that have changed
|
|
487
483
|
*/
|
|
@@ -654,6 +650,7 @@ declare namespace VizPanelRenderer {
|
|
|
654
650
|
|
|
655
651
|
interface VizPanelState<TOptions = {}, TFieldConfig = {}> extends SceneLayoutChildState {
|
|
656
652
|
title: string;
|
|
653
|
+
description?: string;
|
|
657
654
|
pluginId: string;
|
|
658
655
|
options: DeepPartial<TOptions>;
|
|
659
656
|
fieldConfig: FieldConfigSource<DeepPartial<TFieldConfig>>;
|
|
@@ -805,4 +802,45 @@ declare class SceneGridLayout extends SceneObjectBase<SceneGridLayoutState> {
|
|
|
805
802
|
}
|
|
806
803
|
declare function SceneGridLayoutRenderer({ model }: SceneComponentProps<SceneGridLayout>): JSX.Element;
|
|
807
804
|
|
|
808
|
-
|
|
805
|
+
interface SceneAppState extends SceneObjectStatePlain {
|
|
806
|
+
pages: SceneAppPage[];
|
|
807
|
+
}
|
|
808
|
+
interface SceneRouteMatch<Params extends {
|
|
809
|
+
[K in keyof Params]?: string;
|
|
810
|
+
} = {}> {
|
|
811
|
+
params: Params;
|
|
812
|
+
isExact: boolean;
|
|
813
|
+
path: string;
|
|
814
|
+
url: string;
|
|
815
|
+
}
|
|
816
|
+
/**
|
|
817
|
+
* Responsible for top level pages routing
|
|
818
|
+
*/
|
|
819
|
+
declare class SceneApp extends SceneObjectBase<SceneAppState> {
|
|
820
|
+
static Component: ({ model }: SceneComponentProps<SceneApp>) => JSX.Element;
|
|
821
|
+
}
|
|
822
|
+
interface SceneAppPageState extends SceneObjectStatePlain {
|
|
823
|
+
title: string;
|
|
824
|
+
subTitle?: string;
|
|
825
|
+
url: string;
|
|
826
|
+
routePath?: string;
|
|
827
|
+
hideFromBreadcrumbs?: boolean;
|
|
828
|
+
tabs?: SceneAppPage[];
|
|
829
|
+
getScene: (routeMatch: SceneRouteMatch) => EmbeddedScene;
|
|
830
|
+
drilldowns?: SceneAppDrilldownView[];
|
|
831
|
+
getParentPage?: () => SceneAppPage;
|
|
832
|
+
preserveUrlKeys?: string[];
|
|
833
|
+
}
|
|
834
|
+
/**
|
|
835
|
+
* Responsible for page's drilldown & tabs routing
|
|
836
|
+
*/
|
|
837
|
+
declare class SceneAppPage extends SceneObjectBase<SceneAppPageState> {
|
|
838
|
+
static Component: typeof SceneAppPageRenderer;
|
|
839
|
+
}
|
|
840
|
+
declare function SceneAppPageRenderer({ model }: SceneComponentProps<SceneAppPage>): JSX.Element;
|
|
841
|
+
interface SceneAppDrilldownView {
|
|
842
|
+
routePath: string;
|
|
843
|
+
getPage: (routeMatch: SceneRouteMatch<any>, parent: SceneAppPage) => SceneAppPage;
|
|
844
|
+
}
|
|
845
|
+
|
|
846
|
+
export { ConstantVariable, CustomFormatterFn, CustomVariable, DataSourceVariable, DeepPartial, EmbeddedScene, EmbeddedSceneState, FormatRegistryID, FormatVariable, NestedScene, QueryRunnerState, QueryVariable, SceneApp, SceneAppPage, SceneByFrameRepeater, SceneCanvasText, SceneComponent, SceneComponentProps, SceneControlsSpacer, SceneDataNode, SceneDataState, SceneDataTransformer, SceneEditor, SceneEditorState, SceneFlexLayout, SceneGridLayout, SceneGridRow, SceneLayout, SceneLayoutChild, SceneLayoutChildOptions, SceneLayoutChildState, SceneLayoutState, SceneObject, SceneObjectBase, SceneObjectRef, SceneObjectState, SceneObjectStateChangedEvent, SceneObjectStateChangedPayload, SceneObjectStatePlain, SceneObjectUrlSyncConfig, SceneObjectUrlSyncHandler, SceneObjectUrlValue, SceneObjectUrlValues, SceneObjectWithUrlSync, SceneQueryRunner, SceneRouteMatch, SceneTimePicker, SceneTimeRange, SceneTimeRangeLike, SceneTimeRangeState, SceneToolbarButton, SceneToolbarInput, SceneVariable, SceneVariableDependencyConfigLike, SceneVariableSet, SceneVariableSetState, SceneVariableState, SceneVariableValueChangedEvent, SceneVariables, TestVariable, UrlSyncManager, ValidateAndUpdateResult, VariableDependencyConfig, VariableValue, VariableValueCustom, VariableValueOption, VariableValueSelectors, VariableValueSingle, VizPanel, VizPanelState, formatRegistry, isSceneObject, sceneGraph };
|