@grafana/scenes 5.11.3--canary.858.10679390033.0 → 5.12.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (34) hide show
  1. package/CHANGELOG.md +17 -5
  2. package/dist/esm/behaviors/SceneQueryController.js +5 -60
  3. package/dist/esm/behaviors/SceneQueryController.js.map +1 -1
  4. package/dist/esm/components/SceneRefreshPicker.js +1 -4
  5. package/dist/esm/components/SceneRefreshPicker.js.map +1 -1
  6. package/dist/esm/components/VizPanel/VizPanel.js +6 -9
  7. package/dist/esm/components/VizPanel/VizPanel.js.map +1 -1
  8. package/dist/esm/core/SceneTimeRange.js +32 -10
  9. package/dist/esm/core/SceneTimeRange.js.map +1 -1
  10. package/dist/esm/core/sceneGraph/index.js +1 -2
  11. package/dist/esm/core/sceneGraph/index.js.map +1 -1
  12. package/dist/esm/core/sceneGraph/sceneGraph.js +16 -1
  13. package/dist/esm/core/sceneGraph/sceneGraph.js.map +1 -1
  14. package/dist/esm/core/types.js.map +1 -1
  15. package/dist/esm/index.js.map +1 -1
  16. package/dist/esm/querying/SceneQueryRunner.js +3 -1
  17. package/dist/esm/querying/SceneQueryRunner.js.map +1 -1
  18. package/dist/esm/querying/registerQueryWithController.js +2 -19
  19. package/dist/esm/querying/registerQueryWithController.js.map +1 -1
  20. package/dist/esm/services/useUrlSync.js.map +1 -1
  21. package/dist/esm/utils/getDataSource.js +1 -17
  22. package/dist/esm/utils/getDataSource.js.map +1 -1
  23. package/dist/esm/variables/components/VariableValueSelect.js +0 -5
  24. package/dist/esm/variables/components/VariableValueSelect.js.map +1 -1
  25. package/dist/esm/variables/variants/MultiValueVariable.js.map +1 -1
  26. package/dist/esm/variables/variants/TestVariable.js.map +1 -1
  27. package/dist/index.d.ts +25 -43
  28. package/dist/index.js +236 -469
  29. package/dist/index.js.map +1 -1
  30. package/package.json +2 -2
  31. package/dist/esm/behaviors/SceneRenderProfiler.js +0 -168
  32. package/dist/esm/behaviors/SceneRenderProfiler.js.map +0 -1
  33. package/dist/esm/core/sceneGraph/getQueryController.js +0 -19
  34. package/dist/esm/core/sceneGraph/getQueryController.js.map +0 -1
@@ -1 +1 @@
1
- {"version":3,"file":"SceneTimeRange.js","sources":["../../../src/core/SceneTimeRange.tsx"],"sourcesContent":["import { getTimeZone, rangeUtil, setWeekStart, TimeRange } from '@grafana/data';\nimport { TimeZone } from '@grafana/schema';\n\nimport { SceneObjectUrlSyncConfig } from '../services/SceneObjectUrlSyncConfig';\n\nimport { SceneObjectBase } from './SceneObjectBase';\nimport { SceneTimeRangeLike, SceneTimeRangeState, SceneObjectUrlValues } from './types';\nimport { getClosest } from './sceneGraph/utils';\nimport { parseUrlParam } from '../utils/parseUrlParam';\nimport { evaluateTimeRange } from '../utils/evaluateTimeRange';\nimport { config, RefreshEvent } from '@grafana/runtime';\nimport { getQueryController } from './sceneGraph/getQueryController';\n\nexport class SceneTimeRange extends SceneObjectBase<SceneTimeRangeState> implements SceneTimeRangeLike {\n protected _urlSync = new SceneObjectUrlSyncConfig(this, { keys: ['from', 'to', 'timezone'] });\n\n public constructor(state: Partial<SceneTimeRangeState> = {}) {\n const from = state.from ?? 'now-6h';\n const to = state.to ?? 'now';\n const timeZone = state.timeZone;\n const value = evaluateTimeRange(\n from,\n to,\n timeZone || getTimeZone(),\n state.fiscalYearStartMonth,\n state.UNSAFE_nowDelay\n );\n const refreshOnActivate = state.refreshOnActivate ?? { percent: 10 };\n super({ from, to, timeZone, value, refreshOnActivate, ...state });\n\n this.addActivationHandler(this._onActivate.bind(this));\n }\n\n private _onActivate() {\n // When SceneTimeRange has no time zone provided, find closest source of time zone and subscribe to it\n if (!this.state.timeZone) {\n const timeZoneSource = this.getTimeZoneSource();\n if (timeZoneSource !== this) {\n this._subs.add(\n timeZoneSource.subscribeToState((n, p) => {\n if (n.timeZone !== undefined && n.timeZone !== p.timeZone) {\n this.setState({\n value: evaluateTimeRange(\n this.state.from,\n this.state.to,\n timeZoneSource.getTimeZone(),\n this.state.fiscalYearStartMonth,\n this.state.UNSAFE_nowDelay\n ),\n });\n }\n })\n );\n }\n }\n\n if (this.state.weekStart) {\n setWeekStart(this.state.weekStart);\n }\n\n if (rangeUtil.isRelativeTimeRange(this.state.value.raw)) {\n this.refreshIfStale();\n }\n\n // Deactivation handler that restore weekStart if it was changed\n return () => {\n if (this.state.weekStart) {\n setWeekStart(config.bootData.user.weekStart);\n }\n };\n }\n\n private refreshIfStale() {\n let ms;\n if (this.state?.refreshOnActivate?.percent !== undefined) {\n ms = this.calculatePercentOfInterval(this.state.refreshOnActivate.percent);\n }\n if (this.state?.refreshOnActivate?.afterMs !== undefined) {\n ms = Math.min(this.state.refreshOnActivate.afterMs, ms ?? Infinity);\n }\n if (ms !== undefined) {\n this.refreshRange(ms);\n }\n }\n\n /**\n * Will traverse up the scene graph to find the closest SceneTimeRangeLike with time zone set\n */\n private getTimeZoneSource() {\n if (!this.parent || !this.parent.parent) {\n return this;\n }\n // Find the closest source of time zone\n const source = getClosest<SceneTimeRangeLike>(this.parent.parent, (o) => {\n if (o.state.$timeRange && o.state.$timeRange.state.timeZone) {\n return o.state.$timeRange;\n }\n return undefined;\n });\n\n if (!source) {\n return this;\n }\n\n return source;\n }\n\n /**\n * Refreshes time range if it is older than the invalidation interval\n * @param refreshAfterMs invalidation interval (milliseconds)\n * @private\n */\n private refreshRange(refreshAfterMs: number) {\n const value = evaluateTimeRange(\n this.state.from,\n this.state.to,\n this.state.timeZone ?? getTimeZone(),\n this.state.fiscalYearStartMonth,\n this.state.UNSAFE_nowDelay\n );\n\n const diff = value.to.diff(this.state.value.to, 'milliseconds');\n if (diff >= refreshAfterMs) {\n this.setState({\n value,\n });\n }\n }\n\n private calculatePercentOfInterval(percent: number): number {\n const intervalMs = this.state.value.to.diff(this.state.value.from, 'milliseconds');\n return Math.ceil(intervalMs / percent);\n }\n\n public getTimeZone(): TimeZone {\n // Return local time zone if provided\n if (this.state.timeZone) {\n return this.state.timeZone;\n }\n\n // Resolve higher level time zone source\n const timeZoneSource = this.getTimeZoneSource();\n if (timeZoneSource !== this) {\n return timeZoneSource.state.timeZone!;\n }\n\n // Return default time zone\n return getTimeZone();\n }\n\n public onTimeRangeChange = (timeRange: TimeRange) => {\n const update: Partial<SceneTimeRangeState> = {};\n\n const updateToEval: Partial<SceneTimeRangeState> = {};\n\n if (typeof timeRange.raw.from === 'string') {\n update.from = timeRange.raw.from;\n updateToEval.from = timeRange.raw.from;\n } else {\n update.from = timeRange.raw.from.toISOString();\n updateToEval.from = timeRange.raw.from.toISOString(true);\n }\n\n if (typeof timeRange.raw.to === 'string') {\n update.to = timeRange.raw.to;\n updateToEval.to = timeRange.raw.to;\n } else {\n update.to = timeRange.raw.to.toISOString();\n updateToEval.to = timeRange.raw.to.toISOString(true);\n }\n\n update.value = evaluateTimeRange(\n updateToEval.from,\n updateToEval.to,\n this.getTimeZone(),\n this.state.fiscalYearStartMonth,\n this.state.UNSAFE_nowDelay\n );\n\n // Only update if time range actually changed\n if (update.from !== this.state.from || update.to !== this.state.to) {\n const queryController = getQueryController(this);\n queryController?.startProfile(this);\n this.setState(update);\n }\n };\n\n public onTimeZoneChange = (timeZone: TimeZone) => {\n this.setState({ timeZone });\n };\n\n public onRefresh = () => {\n this.setState({\n value: evaluateTimeRange(\n this.state.from,\n this.state.to,\n this.getTimeZone(),\n this.state.fiscalYearStartMonth,\n this.state.UNSAFE_nowDelay\n ),\n });\n\n this.publishEvent(new RefreshEvent(), true);\n };\n\n public getUrlState() {\n const urlValues: SceneObjectUrlValues = { from: this.state.from, to: this.state.to };\n if (this.state.timeZone) {\n urlValues.timezone = this.state.timeZone;\n }\n\n return urlValues;\n }\n\n public updateFromUrl(values: SceneObjectUrlValues) {\n // ignore if both are missing\n if (!values.to && !values.from) {\n return;\n }\n\n const update: Partial<SceneTimeRangeState> = {};\n const from = parseUrlParam(values.from);\n\n if (from) {\n update.from = from;\n }\n\n const to = parseUrlParam(values.to);\n if (to) {\n update.to = to;\n }\n\n if (typeof values.timezone === 'string') {\n update.timeZone = values.timezone !== '' ? values.timezone : undefined;\n }\n\n update.value = evaluateTimeRange(\n update.from ?? this.state.from,\n update.to ?? this.state.to,\n update.timeZone ?? this.getTimeZone(),\n this.state.fiscalYearStartMonth,\n this.state.UNSAFE_nowDelay\n );\n\n this.setState(update);\n }\n}\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAaO,MAAM,uBAAuB,eAAmE,CAAA;AAAA,EAG9F,WAAA,CAAY,KAAsC,GAAA,EAAI,EAAA;AAhB/D,IAAA,IAAA,EAAA,EAAA,EAAA,EAAA,EAAA,CAAA;AAiBI,IAAM,MAAA,IAAA,GAAA,CAAO,EAAM,GAAA,KAAA,CAAA,IAAA,KAAN,IAAc,GAAA,EAAA,GAAA,QAAA,CAAA;AAC3B,IAAM,MAAA,EAAA,GAAA,CAAK,EAAM,GAAA,KAAA,CAAA,EAAA,KAAN,IAAY,GAAA,EAAA,GAAA,KAAA,CAAA;AACvB,IAAA,MAAM,WAAW,KAAM,CAAA,QAAA,CAAA;AACvB,IAAA,MAAM,KAAQ,GAAA,iBAAA;AAAA,MACZ,IAAA;AAAA,MACA,EAAA;AAAA,MACA,YAAY,WAAY,EAAA;AAAA,MACxB,KAAM,CAAA,oBAAA;AAAA,MACN,KAAM,CAAA,eAAA;AAAA,KACR,CAAA;AACA,IAAA,MAAM,qBAAoB,EAAM,GAAA,KAAA,CAAA,iBAAA,KAAN,IAA2B,GAAA,EAAA,GAAA,EAAE,SAAS,EAAG,EAAA,CAAA;AACnE,IAAA,KAAA,CAAM,iBAAE,IAAM,EAAA,EAAA,EAAI,QAAU,EAAA,KAAA,EAAO,qBAAsB,KAAO,CAAA,CAAA,CAAA;AAdlE,IAAU,IAAA,CAAA,QAAA,GAAW,IAAI,wBAAA,CAAyB,IAAM,EAAA,EAAE,IAAM,EAAA,CAAC,MAAQ,EAAA,IAAA,EAAM,UAAU,CAAA,EAAG,CAAA,CAAA;AAwI5F,IAAO,IAAA,CAAA,iBAAA,GAAoB,CAAC,SAAyB,KAAA;A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GAAA,IAAA,CAAK,WAAY,EAAA;AAAA,MACpC,KAAK,KAAM,CAAA,oBAAA;AAAA,MACX,KAAK,KAAM,CAAA,eAAA;AAAA,KACb,CAAA;AAEA,IAAA,IAAA,CAAK,SAAS,MAAM,CAAA,CAAA;AAAA,GACtB;AACF;;;;"}
1
+ {"version":3,"file":"SceneTimeRange.js","sources":["../../../src/core/SceneTimeRange.tsx"],"sourcesContent":["import { getTimeZone, rangeUtil, setWeekStart, TimeRange, toUtc } from '@grafana/data';\nimport { TimeZone } from '@grafana/schema';\n\nimport { SceneObjectUrlSyncConfig } from '../services/SceneObjectUrlSyncConfig';\n\nimport { SceneObjectBase } from './SceneObjectBase';\nimport { SceneTimeRangeLike, SceneTimeRangeState, SceneObjectUrlValues } from './types';\nimport { getClosest } from './sceneGraph/utils';\nimport { parseUrlParam } from '../utils/parseUrlParam';\nimport { evaluateTimeRange } from '../utils/evaluateTimeRange';\nimport { config, locationService, RefreshEvent } from '@grafana/runtime';\n\nexport class SceneTimeRange extends SceneObjectBase<SceneTimeRangeState> implements SceneTimeRangeLike {\n protected _urlSync = new SceneObjectUrlSyncConfig(this, { keys: ['from', 'to', 'timezone', 'time', 'time.window'] });\n\n public constructor(state: Partial<SceneTimeRangeState> = {}) {\n const from = state.from ?? 'now-6h';\n const to = state.to ?? 'now';\n const timeZone = state.timeZone;\n const value = evaluateTimeRange(\n from,\n to,\n timeZone || getTimeZone(),\n state.fiscalYearStartMonth,\n state.UNSAFE_nowDelay\n );\n const refreshOnActivate = state.refreshOnActivate ?? { percent: 10 };\n super({ from, to, timeZone, value, refreshOnActivate, ...state });\n\n this.addActivationHandler(this._onActivate.bind(this));\n }\n\n private _onActivate() {\n // When SceneTimeRange has no time zone provided, find closest source of time zone and subscribe to it\n if (!this.state.timeZone) {\n const timeZoneSource = this.getTimeZoneSource();\n if (timeZoneSource !== this) {\n this._subs.add(\n timeZoneSource.subscribeToState((n, p) => {\n if (n.timeZone !== undefined && n.timeZone !== p.timeZone) {\n this.setState({\n value: evaluateTimeRange(\n this.state.from,\n this.state.to,\n timeZoneSource.getTimeZone(),\n this.state.fiscalYearStartMonth,\n this.state.UNSAFE_nowDelay\n ),\n });\n }\n })\n );\n }\n }\n\n if (this.state.weekStart) {\n setWeekStart(this.state.weekStart);\n }\n\n if (rangeUtil.isRelativeTimeRange(this.state.value.raw)) {\n this.refreshIfStale();\n }\n\n // Deactivation handler that restore weekStart if it was changed\n return () => {\n if (this.state.weekStart) {\n setWeekStart(config.bootData.user.weekStart);\n }\n };\n }\n\n private refreshIfStale() {\n let ms;\n if (this.state?.refreshOnActivate?.percent !== undefined) {\n ms = this.calculatePercentOfInterval(this.state.refreshOnActivate.percent);\n }\n if (this.state?.refreshOnActivate?.afterMs !== undefined) {\n ms = Math.min(this.state.refreshOnActivate.afterMs, ms ?? Infinity);\n }\n if (ms !== undefined) {\n this.refreshRange(ms);\n }\n }\n\n /**\n * Will traverse up the scene graph to find the closest SceneTimeRangeLike with time zone set\n */\n private getTimeZoneSource() {\n if (!this.parent || !this.parent.parent) {\n return this;\n }\n // Find the closest source of time zone\n const source = getClosest<SceneTimeRangeLike>(this.parent.parent, (o) => {\n if (o.state.$timeRange && o.state.$timeRange.state.timeZone) {\n return o.state.$timeRange;\n }\n return undefined;\n });\n\n if (!source) {\n return this;\n }\n\n return source;\n }\n\n /**\n * Refreshes time range if it is older than the invalidation interval\n * @param refreshAfterMs invalidation interval (milliseconds)\n * @private\n */\n private refreshRange(refreshAfterMs: number) {\n const value = evaluateTimeRange(\n this.state.from,\n this.state.to,\n this.state.timeZone ?? getTimeZone(),\n this.state.fiscalYearStartMonth,\n this.state.UNSAFE_nowDelay\n );\n\n const diff = value.to.diff(this.state.value.to, 'milliseconds');\n if (diff >= refreshAfterMs) {\n this.setState({\n value,\n });\n }\n }\n\n private calculatePercentOfInterval(percent: number): number {\n const intervalMs = this.state.value.to.diff(this.state.value.from, 'milliseconds');\n return Math.ceil(intervalMs / percent);\n }\n\n public getTimeZone(): TimeZone {\n // Return local time zone if provided\n if (this.state.timeZone) {\n return this.state.timeZone;\n }\n\n // Resolve higher level time zone source\n const timeZoneSource = this.getTimeZoneSource();\n if (timeZoneSource !== this) {\n return timeZoneSource.state.timeZone!;\n }\n\n // Return default time zone\n return getTimeZone();\n }\n\n public onTimeRangeChange = (timeRange: TimeRange) => {\n const update: Partial<SceneTimeRangeState> = {};\n const updateToEval: Partial<SceneTimeRangeState> = {};\n\n if (typeof timeRange.raw.from === 'string') {\n update.from = timeRange.raw.from;\n updateToEval.from = timeRange.raw.from;\n } else {\n update.from = timeRange.raw.from.toISOString();\n updateToEval.from = timeRange.raw.from.toISOString(true);\n }\n\n if (typeof timeRange.raw.to === 'string') {\n update.to = timeRange.raw.to;\n updateToEval.to = timeRange.raw.to;\n } else {\n update.to = timeRange.raw.to.toISOString();\n updateToEval.to = timeRange.raw.to.toISOString(true);\n }\n\n update.value = evaluateTimeRange(\n updateToEval.from,\n updateToEval.to,\n this.getTimeZone(),\n this.state.fiscalYearStartMonth,\n this.state.UNSAFE_nowDelay\n );\n\n // Only update if time range actually changed\n if (update.from !== this.state.from || update.to !== this.state.to) {\n this.setState(update);\n }\n };\n\n public onTimeZoneChange = (timeZone: TimeZone) => {\n this.setState({ timeZone });\n };\n\n public onRefresh = () => {\n this.setState({\n value: evaluateTimeRange(\n this.state.from,\n this.state.to,\n this.getTimeZone(),\n this.state.fiscalYearStartMonth,\n this.state.UNSAFE_nowDelay\n ),\n });\n\n this.publishEvent(new RefreshEvent(), true);\n };\n\n public getUrlState() {\n const params = locationService.getSearchObject();\n const urlValues: SceneObjectUrlValues = { from: this.state.from, to: this.state.to };\n\n if (this.state.timeZone) {\n urlValues.timezone = this.state.timeZone;\n }\n\n // Clear time and time.window once they are converted to from and to\n if (params.time && params['time.window']) {\n urlValues.time = null;\n urlValues['time.window'] = null;\n }\n\n return urlValues;\n }\n\n public updateFromUrl(values: SceneObjectUrlValues) {\n const update: Partial<SceneTimeRangeState> = {};\n\n let from = parseUrlParam(values.from);\n let to = parseUrlParam(values.to);\n\n if (values.time && values['time.window']) {\n const time = Array.isArray(values.time) ? values.time[0] : values.time;\n const timeWindow = Array.isArray(values['time.window']) ? values['time.window'][0] : values['time.window'];\n const timeRange = getTimeWindow(time, timeWindow);\n from = timeRange.from;\n to = timeRange.to;\n }\n\n if (!from && !to) {\n return;\n }\n\n if (from) {\n update.from = from;\n }\n\n if (to) {\n update.to = to;\n }\n\n if (typeof values.timezone === 'string') {\n update.timeZone = values.timezone !== '' ? values.timezone : undefined;\n }\n\n update.value = evaluateTimeRange(\n update.from ?? this.state.from,\n update.to ?? this.state.to,\n update.timeZone ?? this.getTimeZone(),\n this.state.fiscalYearStartMonth,\n this.state.UNSAFE_nowDelay\n );\n\n this.setState(update);\n }\n}\n\n/**\n * Calculates the duration of the time range from time-time.window/2 to time+time.window/2. Both be specified in ms. For example ?time=1500000000000&time.window=10000 results in a 10-second time range from 1499999995000 to 1500000005000`.\n * @param time - time in ms\n * @param timeWindow - time window in ms or interval string\n */\nfunction getTimeWindow(time: string, timeWindow: string) {\n // Parse the time, assuming it could be an ISO string or a number in milliseconds\n const valueTime = isNaN(Date.parse(time)) ? parseInt(time, 10) : Date.parse(time);\n\n let timeWindowMs;\n\n if (timeWindow.match(/^\\d+$/) && parseInt(timeWindow, 10)) {\n // when time window is specified in ms\n timeWindowMs = parseInt(timeWindow, 10);\n } else {\n timeWindowMs = rangeUtil.intervalToMs(timeWindow);\n }\n\n return {\n from: toUtc(valueTime - timeWindowMs / 2).toISOString(),\n to: toUtc(valueTime + timeWindowMs / 2).toISOString(),\n };\n}\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AAYO,MAAM,uBAAuB,eAAmE,CAAA;AAAA,EAG9F,WAAA,CAAY,KAAsC,GAAA,EAAI,EAAA;AAf/D,IAAA,IAAA,EAAA,EAAA,EAAA,EAAA,EAAA,CAAA;AAgBI,IAAM,MAAA,IAAA,GAAA,CAAO,EAAM,GAAA,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AA,CAAA,IAAA,KAAP,IAAe,GAAA,EAAA,GAAA,IAAA,CAAK,KAAM,CAAA,IAAA;AAAA,MAAA,CAC1B,EAAO,GAAA,MAAA,CAAA,EAAA,KAAP,IAAa,GAAA,EAAA,GAAA,IAAA,CAAK,KAAM,CAAA,EAAA;AAAA,MAAA,CACxB,EAAO,GAAA,MAAA,CAAA,QAAA,KAAP,IAAmB,GAAA,EAAA,GAAA,IAAA,CAAK,WAAY,EAAA;AAAA,MACpC,KAAK,KAAM,CAAA,oBAAA;AAAA,MACX,KAAK,KAAM,CAAA,eAAA;AAAA,KACb,CAAA;AAEA,IAAA,IAAA,CAAK,SAAS,MAAM,CAAA,CAAA;AAAA,GACtB;AACF,CAAA;AAOA,SAAS,aAAA,CAAc,MAAc,UAAoB,EAAA;AAEvD,EAAA,MAAM,SAAY,GAAA,KAAA,CAAM,IAAK,CAAA,KAAA,CAAM,IAAI,CAAC,CAAI,GAAA,QAAA,CAAS,IAAM,EAAA,EAAE,CAAI,GAAA,IAAA,CAAK,MAAM,IAAI,CAAA,CAAA;AAEhF,EAAI,IAAA,YAAA,CAAA;AAEJ,EAAA,IAAI,WAAW,KAAM,CAAA,OAAO,KAAK,QAAS,CAAA,UAAA,EAAY,EAAE,CAAG,EAAA;AAEzD,IAAe,YAAA,GAAA,QAAA,CAAS,YAAY,EAAE,CAAA,CAAA;AAAA,GACjC,MAAA;AACL,IAAe,YAAA,GAAA,SAAA,CAAU,aAAa,UAAU,CAAA,CAAA;AAAA,GAClD;AAEA,EAAO,OAAA;AAAA,IACL,MAAM,KAAM,CAAA,SAAA,GAAY,YAAe,GAAA,CAAC,EAAE,WAAY,EAAA;AAAA,IACtD,IAAI,KAAM,CAAA,SAAA,GAAY,YAAe,GAAA,CAAC,EAAE,WAAY,EAAA;AAAA,GACtD,CAAA;AACF;;;;"}
@@ -1,7 +1,6 @@
1
1
  import { lookupVariable } from '../../variables/lookupVariable.js';
2
- import { getQueryController } from './getQueryController.js';
3
2
  import { getTimeRange } from './getTimeRange.js';
4
- import { getVariables, getData, getLayout, getDataLayers, interpolate, hasVariableDependencyInLoadingState, findByKey, findByKeyAndType, findObject, findAllObjects, getAncestor } from './sceneGraph.js';
3
+ import { getVariables, getData, getLayout, getDataLayers, interpolate, hasVariableDependencyInLoadingState, findByKey, findByKeyAndType, findObject, findAllObjects, getAncestor, getQueryController } from './sceneGraph.js';
5
4
 
6
5
  const sceneGraph = {
7
6
  getVariables,
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":["../../../../src/core/sceneGraph/index.ts"],"sourcesContent":["import { lookupVariable } from '../../variables/lookupVariable';\nimport { getQueryController } from './getQueryController';\nimport { getTimeRange } from './getTimeRange';\nimport {\n findByKey,\n findByKeyAndType,\n findObject,\n findAllObjects,\n getData,\n getLayout,\n getVariables,\n getDataLayers,\n hasVariableDependencyInLoadingState,\n interpolate,\n getAncestor,\n} from './sceneGraph';\n\nexport const sceneGraph = {\n getVariables,\n getData,\n getTimeRange,\n getLayout,\n getDataLayers,\n interpolate,\n lookupVariable,\n hasVariableDependencyInLoadingState,\n findByKey,\n findByKeyAndType,\n findObject,\n findAllObjects,\n getAncestor,\n getQueryController,\n};\n"],"names":[],"mappings":";;;;;AAiBO,MAAM,UAAa,GAAA;AAAA,EACxB,YAAA;AAAA,EACA,OAAA;AAAA,EACA,YAAA;AAAA,EACA,SAAA;AAAA,EACA,aAAA;AAAA,EACA,WAAA;AAAA,EACA,cAAA;AAAA,EACA,mCAAA;AAAA,EACA,SAAA;AAAA,EACA,gBAAA;AAAA,EACA,UAAA;AAAA,EACA,cAAA;AAAA,EACA,WAAA;AAAA,EACA,kBAAA;AACF;;;;"}
1
+ {"version":3,"file":"index.js","sources":["../../../../src/core/sceneGraph/index.ts"],"sourcesContent":["import { lookupVariable } from '../../variables/lookupVariable';\nimport { getTimeRange } from './getTimeRange';\nimport {\n findByKey,\n findByKeyAndType,\n findObject,\n findAllObjects,\n getData,\n getLayout,\n getVariables,\n getDataLayers,\n hasVariableDependencyInLoadingState,\n interpolate,\n getAncestor,\n getQueryController,\n} from './sceneGraph';\n\nexport const sceneGraph = {\n getVariables,\n getData,\n getTimeRange,\n getLayout,\n getDataLayers,\n interpolate,\n lookupVariable,\n hasVariableDependencyInLoadingState,\n findByKey,\n findByKeyAndType,\n findObject,\n findAllObjects,\n getAncestor,\n getQueryController,\n};\n"],"names":[],"mappings":";;;;AAiBO,MAAM,UAAa,GAAA;AAAA,EACxB,YAAA;AAAA,EACA,OAAA;AAAA,EACA,YAAA;AAAA,EACA,SAAA;AAAA,EACA,aAAA;AAAA,EACA,WAAA;AAAA,EACA,cAAA;AAAA,EACA,mCAAA;AAAA,EACA,SAAA;AAAA,EACA,gBAAA;AAAA,EACA,UAAA;AAAA,EACA,cAAA;AAAA,EACA,WAAA;AAAA,EACA,kBAAA;AACF;;;;"}
@@ -3,6 +3,7 @@ import { sceneInterpolator } from '../../variables/interpolation/sceneInterpolat
3
3
  import { isDataLayer } from '../types.js';
4
4
  import { lookupVariable } from '../../variables/lookupVariable.js';
5
5
  import { getClosest } from './utils.js';
6
+ import { isQueryController } from '../../behaviors/SceneQueryController.js';
6
7
  import { QueryVariable } from '../../variables/variants/query/QueryVariable.js';
7
8
 
8
9
  function getVariables(sceneObject) {
@@ -141,6 +142,20 @@ function getAncestor(sceneObject, ancestorType) {
141
142
  }
142
143
  return parent;
143
144
  }
145
+ function getQueryController(sceneObject) {
146
+ let parent = sceneObject;
147
+ while (parent) {
148
+ if (parent.state.$behaviors) {
149
+ for (const behavior of parent.state.$behaviors) {
150
+ if (isQueryController(behavior)) {
151
+ return behavior;
152
+ }
153
+ }
154
+ }
155
+ parent = parent.parent;
156
+ }
157
+ return void 0;
158
+ }
144
159
 
145
- export { findAllObjects, findByKey, findByKeyAndType, findObject, getAncestor, getData, getDataLayers, getLayout, getVariables, hasVariableDependencyInLoadingState, interpolate };
160
+ export { findAllObjects, findByKey, findByKeyAndType, findObject, getAncestor, getData, getDataLayers, getLayout, getQueryController, getVariables, hasVariableDependencyInLoadingState, interpolate };
146
161
  //# sourceMappingURL=sceneGraph.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"sceneGraph.js","sources":["../../../../src/core/sceneGraph/sceneGraph.ts"],"sourcesContent":["import { ScopedVars } from '@grafana/data';\nimport { EmptyDataNode, EmptyVariableSet } from '../../variables/interpolation/defaults';\n\nimport { sceneInterpolator } from '../../variables/interpolation/sceneInterpolator';\nimport { VariableCustomFormatterFn, SceneVariables } from '../../variables/types';\n\nimport { isDataLayer, SceneDataLayerProvider, SceneDataProvider, SceneLayout, SceneObject } from '../types';\nimport { lookupVariable } from '../../variables/lookupVariable';\nimport { getClosest } from './utils';\nimport { VariableInterpolation } from '@grafana/runtime';\nimport { QueryVariable } from '../../variables/variants/query/QueryVariable';\n\n/**\n * Get the closest node with variables\n */\nexport function getVariables(sceneObject: SceneObject): SceneVariables {\n return getClosest(sceneObject, (s) => s.state.$variables) ?? EmptyVariableSet;\n}\n\n/**\n * Will walk up the scene object graph to the closest $data scene object\n */\nexport function getData(sceneObject: SceneObject): SceneDataProvider {\n return getClosest(sceneObject, (s) => s.state.$data) ?? EmptyDataNode;\n}\n\nfunction isSceneLayout(s: SceneObject): s is SceneLayout {\n return 'isDraggable' in s;\n}\n\n/**\n * Will walk up the scene object graph to the closest $layout scene object\n */\nexport function getLayout(scene: SceneObject): SceneLayout | null {\n const parent = getClosest(scene, (s) => (isSceneLayout(s) ? s : undefined));\n if (parent) {\n return parent;\n }\n\n return null;\n}\n\n/**\n * Interpolates the given string using the current scene object as context. *\n *\n * Note: the interpolations array will be mutated by adding information about variables that\n * have been interpolated during replacement. Variables that were specified in the target but not found in\n * the list of available variables are also added to the array. See {@link VariableInterpolation} for more details.\n *\n * @param {VariableInterpolation[]} interpolations an optional array that is updated with interpolated variables.\n */\nexport function interpolate(\n sceneObject: SceneObject,\n value: string | undefined | null,\n scopedVars?: ScopedVars,\n format?: string | VariableCustomFormatterFn,\n interpolations?: VariableInterpolation[]\n): string {\n if (value === '' || value == null) {\n return '';\n }\n\n return sceneInterpolator(sceneObject, value, scopedVars, format, interpolations);\n}\n\n/**\n * Checks if the variable is currently loading or waiting to update.\n * It also returns true if a dependency of the variable is loading.\n *\n * For example if C depends on variable B which depends on variable A and A is loading this returns true for variable C and B.\n */\nexport function hasVariableDependencyInLoadingState(sceneObject: SceneObject) {\n if (!sceneObject.variableDependency) {\n return false;\n }\n\n for (const name of sceneObject.variableDependency.getNames()) {\n // This is for backwards compability. In the old architecture query variables could reference itself in a query without breaking.\n if (sceneObject instanceof QueryVariable && sceneObject.state.name === name) {\n console.warn('Query variable is referencing itself');\n continue;\n }\n\n const variable = lookupVariable(name, sceneObject);\n if (!variable) {\n continue;\n }\n\n const set = variable.parent as SceneVariables;\n if (set.isVariableLoadingOrWaitingToUpdate(variable)) {\n return true;\n }\n }\n\n return false;\n}\n\nfunction findObjectInternal(\n scene: SceneObject,\n check: (obj: SceneObject) => boolean,\n alreadySearchedChild?: SceneObject,\n shouldSearchUp?: boolean\n): SceneObject | null {\n if (check(scene)) {\n return scene;\n }\n\n let found: SceneObject | null = null;\n\n scene.forEachChild((child) => {\n if (child === alreadySearchedChild) {\n return;\n }\n\n let maybe = findObjectInternal(child, check);\n if (maybe) {\n found = maybe;\n }\n });\n\n if (found) {\n return found;\n }\n\n if (shouldSearchUp && scene.parent) {\n return findObjectInternal(scene.parent, check, scene, true);\n }\n\n return null;\n}\n\n/**\n * Returns a scene object from the scene graph with the requested key.\n *\n * Throws error if no key-matching scene object found.\n */\nexport function findByKey(sceneObject: SceneObject, key: string) {\n const found = findObject(sceneObject, (sceneToCheck) => {\n return sceneToCheck.state.key === key;\n });\n if (!found) {\n throw new Error('Unable to find scene with key ' + key);\n }\n return found;\n}\n\n/**\n * Returns a scene object from the scene graph with the requested key and type.\n *\n * Throws error if no key-matching scene object found.\n * Throws error if the given type does not match.\n */\nexport function findByKeyAndType<TargetType extends SceneObject>(\n sceneObject: SceneObject,\n key: string,\n targetType: { new (...args: never[]): TargetType }\n) {\n const found = findObject(sceneObject, (sceneToCheck) => {\n return sceneToCheck.state.key === key;\n });\n if (!found) {\n throw new Error('Unable to find scene with key ' + key);\n }\n if (!(found instanceof targetType)) {\n throw new Error(`Found scene object with key ${key} does not match type ${targetType.name}`);\n }\n return found;\n}\n\n/**\n * This will search the full scene graph, starting with the scene node passed in, then walking up the parent chain. *\n */\nexport function findObject(scene: SceneObject, check: (obj: SceneObject) => boolean): SceneObject | null {\n return findObjectInternal(scene, check, undefined, true);\n}\n\n/**\n * This will search down the full scene graph, looking for objects that match the provided predicate.\n */\nexport function findAllObjects(scene: SceneObject, check: (obj: SceneObject) => boolean): SceneObject[] {\n const found: SceneObject[] = [];\n\n scene.forEachChild((child) => {\n if (check(child)) {\n found.push(child);\n }\n\n found.push(...findAllObjects(child, check));\n });\n\n return found;\n}\n\n/**\n * Will walk up the scene object graph up until the root and collect all SceneDataLayerProvider objects.\n * When localOnly set to true, it will only collect the closest layers.\n */\nexport function getDataLayers(sceneObject: SceneObject, localOnly = false): SceneDataLayerProvider[] {\n let currentLevel: SceneObject | undefined = sceneObject;\n let collected: SceneDataLayerProvider[] = [];\n\n while (currentLevel) {\n const dataProvider = currentLevel.state.$data;\n if (!dataProvider) {\n currentLevel = currentLevel.parent;\n continue;\n }\n\n // Check if data layer exists nested inside another data provider\n if (isDataLayer(dataProvider)) {\n collected = collected.concat(dataProvider);\n } else {\n if (dataProvider.state.$data && isDataLayer(dataProvider.state.$data)) {\n collected = collected.concat(dataProvider.state.$data);\n }\n }\n\n if (localOnly && collected.length > 0) {\n break;\n }\n\n currentLevel = currentLevel.parent;\n }\n\n return collected;\n}\n\n/**\n * A utility function to find the closest ancestor of a given type. This function expects\n * to find it and will throw an error if it does not.\n */\nexport function getAncestor<ParentType>(\n sceneObject: SceneObject,\n ancestorType: { new (...args: never[]): ParentType }\n): ParentType {\n let parent: SceneObject | undefined = sceneObject;\n\n while (parent) {\n if (parent instanceof ancestorType) {\n return parent;\n }\n parent = parent.parent;\n }\n\n if (!parent) {\n throw new Error('Unable to find parent of type ' + ancestorType.name);\n }\n\n return parent as ParentType;\n}\n"],"names":[],"mappings":";;;;;;;AAeO,SAAS,aAAa,WAA0C,EAAA;AAfvE,EAAA,IAAA,EAAA,CAAA;AAgBE,EAAO,OAAA,CAAA,EAAA,GAAA,UAAA,CAAW,aAAa,CAAC,CAAA,KAAM,EAAE,KAAM,CAAA,UAAU,MAAjD,IAAsD,GAAA,EAAA,GAAA,gBAAA,CAAA;AAC/D,CAAA;AAKO,SAAS,QAAQ,WAA6C,EAAA;AAtBrE,EAAA,IAAA,EAAA,CAAA;AAuBE,EAAO,OAAA,CAAA,EAAA,GAAA,UAAA,CAAW,aAAa,CAAC,CAAA,KAAM,EAAE,KAAM,CAAA,KAAK,MAA5C,IAAiD,GAAA,EAAA,GAAA,aAAA,CAAA;AAC1D,CAAA;AAEA,SAAS,cAAc,CAAkC,EAAA;AACvD,EAAA,OAAO,aAAiB,IAAA,CAAA,CAAA;AAC1B,CAAA;AAKO,SAAS,UAAU,KAAwC,EAAA;AAChE,EAAM,MAAA,MAAA,GAAS,WAAW,KAAO,EAAA,CAAC,MAAO,aAAc,CAAA,CAAC,CAAI,GAAA,CAAA,GAAI,KAAU,CAAA,CAAA,CAAA;AAC1E,EAAA,IAAI,MAAQ,EAAA;AACV,IAAO,OAAA,MAAA,CAAA;AAAA,GACT;AAEA,EAAO,OAAA,IAAA,CAAA;AACT,CAAA;AAWO,SAAS,WACd,CAAA,WAAA,EACA,KACA,EAAA,UAAA,EACA,QACA,cACQ,EAAA;AACR,EAAI,IAAA,KAAA,KAAU,EAAM,IAAA,KAAA,IAAS,IAAM,EAAA;AACjC,IAAO,OAAA,EAAA,CAAA;AAAA,GACT;AAEA,EAAA,OAAO,iBAAkB,CAAA,WAAA,EAAa,KAAO,EAAA,UAAA,EAAY,QAAQ,cAAc,CAAA,CAAA;AACjF,CAAA;AAQO,SAAS,oCAAoC,WAA0B,EAAA;AA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EA,IAAA,YAAA,GAAe,YAAa,CAAA,MAAA,CAAA;AAAA,GAC9B;AAEA,EAAO,OAAA,SAAA,CAAA;AACT,CAAA;AAMgB,SAAA,WAAA,CACd,aACA,YACY,EAAA;AACZ,EAAA,IAAI,MAAkC,GAAA,WAAA,CAAA;AAEtC,EAAA,OAAO,MAAQ,EAAA;AACb,IAAA,IAAI,kBAAkB,YAAc,EAAA;AAClC,MAAO,OAAA,MAAA,CAAA;AAAA,KACT;AACA,IAAA,MAAA,GAAS,MAAO,CAAA,MAAA,CAAA;AAAA,GAClB;AAEA,EAAA,IAAI,CAAC,MAAQ,EAAA;AACX,IAAA,MAAM,IAAI,KAAA,CAAM,gCAAmC,GAAA,YAAA,CAAa,IAAI,CAAA,CAAA;AAAA,GACtE;AAEA,EAAO,OAAA,MAAA,CAAA;AACT;;;;"}
1
+ {"version":3,"file":"sceneGraph.js","sources":["../../../../src/core/sceneGraph/sceneGraph.ts"],"sourcesContent":["import { ScopedVars } from '@grafana/data';\nimport { EmptyDataNode, EmptyVariableSet } from '../../variables/interpolation/defaults';\n\nimport { sceneInterpolator } from '../../variables/interpolation/sceneInterpolator';\nimport { VariableCustomFormatterFn, SceneVariables } from '../../variables/types';\n\nimport { isDataLayer, SceneDataLayerProvider, SceneDataProvider, SceneLayout, SceneObject } from '../types';\nimport { lookupVariable } from '../../variables/lookupVariable';\nimport { getClosest } from './utils';\nimport { SceneQueryControllerLike, isQueryController } from '../../behaviors/SceneQueryController';\nimport { VariableInterpolation } from '@grafana/runtime';\nimport { QueryVariable } from '../../variables/variants/query/QueryVariable';\n\n/**\n * Get the closest node with variables\n */\nexport function getVariables(sceneObject: SceneObject): SceneVariables {\n return getClosest(sceneObject, (s) => s.state.$variables) ?? EmptyVariableSet;\n}\n\n/**\n * Will walk up the scene object graph to the closest $data scene object\n */\nexport function getData(sceneObject: SceneObject): SceneDataProvider {\n return getClosest(sceneObject, (s) => s.state.$data) ?? EmptyDataNode;\n}\n\nfunction isSceneLayout(s: SceneObject): s is SceneLayout {\n return 'isDraggable' in s;\n}\n\n/**\n * Will walk up the scene object graph to the closest $layout scene object\n */\nexport function getLayout(scene: SceneObject): SceneLayout | null {\n const parent = getClosest(scene, (s) => (isSceneLayout(s) ? s : undefined));\n if (parent) {\n return parent;\n }\n\n return null;\n}\n\n/**\n * Interpolates the given string using the current scene object as context. *\n *\n * Note: the interpolations array will be mutated by adding information about variables that\n * have been interpolated during replacement. Variables that were specified in the target but not found in\n * the list of available variables are also added to the array. See {@link VariableInterpolation} for more details.\n *\n * @param {VariableInterpolation[]} interpolations an optional array that is updated with interpolated variables.\n */\nexport function interpolate(\n sceneObject: SceneObject,\n value: string | undefined | null,\n scopedVars?: ScopedVars,\n format?: string | VariableCustomFormatterFn,\n interpolations?: VariableInterpolation[]\n): string {\n if (value === '' || value == null) {\n return '';\n }\n\n return sceneInterpolator(sceneObject, value, scopedVars, format, interpolations);\n}\n\n/**\n * Checks if the variable is currently loading or waiting to update.\n * It also returns true if a dependency of the variable is loading.\n *\n * For example if C depends on variable B which depends on variable A and A is loading this returns true for variable C and B.\n */\nexport function hasVariableDependencyInLoadingState(sceneObject: SceneObject) {\n if (!sceneObject.variableDependency) {\n return false;\n }\n\n for (const name of sceneObject.variableDependency.getNames()) {\n // This is for backwards compability. In the old architecture query variables could reference itself in a query without breaking.\n if (sceneObject instanceof QueryVariable && sceneObject.state.name === name) {\n console.warn('Query variable is referencing itself');\n continue;\n }\n\n const variable = lookupVariable(name, sceneObject);\n if (!variable) {\n continue;\n }\n\n const set = variable.parent as SceneVariables;\n if (set.isVariableLoadingOrWaitingToUpdate(variable)) {\n return true;\n }\n }\n\n return false;\n}\n\nfunction findObjectInternal(\n scene: SceneObject,\n check: (obj: SceneObject) => boolean,\n alreadySearchedChild?: SceneObject,\n shouldSearchUp?: boolean\n): SceneObject | null {\n if (check(scene)) {\n return scene;\n }\n\n let found: SceneObject | null = null;\n\n scene.forEachChild((child) => {\n if (child === alreadySearchedChild) {\n return;\n }\n\n let maybe = findObjectInternal(child, check);\n if (maybe) {\n found = maybe;\n }\n });\n\n if (found) {\n return found;\n }\n\n if (shouldSearchUp && scene.parent) {\n return findObjectInternal(scene.parent, check, scene, true);\n }\n\n return null;\n}\n\n/**\n * Returns a scene object from the scene graph with the requested key.\n *\n * Throws error if no key-matching scene object found.\n */\nexport function findByKey(sceneObject: SceneObject, key: string) {\n const found = findObject(sceneObject, (sceneToCheck) => {\n return sceneToCheck.state.key === key;\n });\n if (!found) {\n throw new Error('Unable to find scene with key ' + key);\n }\n return found;\n}\n\n/**\n * Returns a scene object from the scene graph with the requested key and type.\n *\n * Throws error if no key-matching scene object found.\n * Throws error if the given type does not match.\n */\nexport function findByKeyAndType<TargetType extends SceneObject>(\n sceneObject: SceneObject,\n key: string,\n targetType: { new (...args: never[]): TargetType }\n) {\n const found = findObject(sceneObject, (sceneToCheck) => {\n return sceneToCheck.state.key === key;\n });\n if (!found) {\n throw new Error('Unable to find scene with key ' + key);\n }\n if (!(found instanceof targetType)) {\n throw new Error(`Found scene object with key ${key} does not match type ${targetType.name}`);\n }\n return found;\n}\n\n/**\n * This will search the full scene graph, starting with the scene node passed in, then walking up the parent chain. *\n */\nexport function findObject(scene: SceneObject, check: (obj: SceneObject) => boolean): SceneObject | null {\n return findObjectInternal(scene, check, undefined, true);\n}\n\n/**\n * This will search down the full scene graph, looking for objects that match the provided predicate.\n */\nexport function findAllObjects(scene: SceneObject, check: (obj: SceneObject) => boolean): SceneObject[] {\n const found: SceneObject[] = [];\n\n scene.forEachChild((child) => {\n if (check(child)) {\n found.push(child);\n }\n\n found.push(...findAllObjects(child, check));\n });\n\n return found;\n}\n\n/**\n * Will walk up the scene object graph up until the root and collect all SceneDataLayerProvider objects.\n * When localOnly set to true, it will only collect the closest layers.\n */\nexport function getDataLayers(sceneObject: SceneObject, localOnly = false): SceneDataLayerProvider[] {\n let currentLevel: SceneObject | undefined = sceneObject;\n let collected: SceneDataLayerProvider[] = [];\n\n while (currentLevel) {\n const dataProvider = currentLevel.state.$data;\n if (!dataProvider) {\n currentLevel = currentLevel.parent;\n continue;\n }\n\n // Check if data layer exists nested inside another data provider\n if (isDataLayer(dataProvider)) {\n collected = collected.concat(dataProvider);\n } else {\n if (dataProvider.state.$data && isDataLayer(dataProvider.state.$data)) {\n collected = collected.concat(dataProvider.state.$data);\n }\n }\n\n if (localOnly && collected.length > 0) {\n break;\n }\n\n currentLevel = currentLevel.parent;\n }\n\n return collected;\n}\n\n/**\n * A utility function to find the closest ancestor of a given type. This function expects\n * to find it and will throw an error if it does not.\n */\nexport function getAncestor<ParentType>(\n sceneObject: SceneObject,\n ancestorType: { new (...args: never[]): ParentType }\n): ParentType {\n let parent: SceneObject | undefined = sceneObject;\n\n while (parent) {\n if (parent instanceof ancestorType) {\n return parent;\n }\n parent = parent.parent;\n }\n\n if (!parent) {\n throw new Error('Unable to find parent of type ' + ancestorType.name);\n }\n\n return parent as ParentType;\n}\n\n/**\n * Returns the closest query controller undefined if none found\n */\nexport function getQueryController(sceneObject: SceneObject): SceneQueryControllerLike | undefined {\n let parent: SceneObject | undefined = sceneObject;\n\n while (parent) {\n if (parent.state.$behaviors) {\n for (const behavior of parent.state.$behaviors) {\n if (isQueryController(behavior)) {\n return behavior;\n }\n }\n }\n parent = parent.parent;\n }\n\n return undefined;\n}\n"],"names":[],"mappings":";;;;;;;;AAgBO,SAAS,aAAa,WAA0C,EAAA;AAhBvE,EAAA,IAAA,EAAA,CAAA;AAiBE,EAAO,OAAA,CAAA,EAAA,GAAA,UAAA,CAAW,aAAa,CAAC,CAAA,KAAM,EAAE,KAAM,CAAA,UAAU,MAAjD,IAAsD,GAAA,EAAA,GAAA,gBAAA,CAAA;AAC/D,CAAA;AAKO,SAAS,QAAQ,WAA6C,EAAA;AAvBrE,EAAA,IAAA,EAAA,CAAA;AAwBE,EAAO,OAAA,CAAA,EAAA,GAAA,UAAA,CAAW,aAAa,CAAC,CAAA,KAAM,EAAE,KAAM,CAAA,KAAK,MAA5C,I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,CAAA;AACT,CAAA;AAKO,SAAS,mBAAmB,WAAgE,EAAA;AACjG,EAAA,IAAI,MAAkC,GAAA,WAAA,CAAA;AAEtC,EAAA,OAAO,MAAQ,EAAA;AACb,IAAI,IAAA,MAAA,CAAO,MAAM,UAAY,EAAA;AAC3B,MAAW,KAAA,MAAA,QAAA,IAAY,MAAO,CAAA,KAAA,CAAM,UAAY,EAAA;AAC9C,QAAI,IAAA,iBAAA,CAAkB,QAAQ,CAAG,EAAA;AAC/B,UAAO,OAAA,QAAA,CAAA;AAAA,SACT;AAAA,OACF;AAAA,KACF;AACA,IAAA,MAAA,GAAS,MAAO,CAAA,MAAA,CAAA;AAAA,GAClB;AAEA,EAAO,OAAA,KAAA,CAAA,CAAA;AACT;;;;"}
@@ -1 +1 @@
1
- {"version":3,"file":"types.js","sources":["../../../src/core/types.ts"],"sourcesContent":["import React from 'react';\nimport { MonoTypeOperatorFunction, Observable, Unsubscribable } from 'rxjs';\n\nimport {\n BusEvent,\n BusEventHandler,\n BusEventType,\n DataFrame,\n DataQueryRequest,\n DataSourceGetTagKeysOptions,\n DataSourceGetTagValuesOptions,\n DataTransformContext,\n PanelData,\n TimeRange,\n} from '@grafana/data';\nimport { DataQuery, DataTopic, TimeZone } from '@grafana/schema';\n\nimport { SceneVariableDependencyConfigLike, SceneVariables } from '../variables/types';\nimport { SceneObjectRef } from './SceneObjectRef';\n\nexport interface SceneObjectState {\n key?: string;\n $timeRange?: SceneTimeRangeLike;\n $data?: SceneDataProvider;\n $variables?: SceneVariables;\n /**\n * @experimental\n * Can be used to add extra behaviors to a scene object.\n * These are activated when the their parent scene object is activated.\n */\n $behaviors?: Array<SceneObject | SceneStatelessBehavior>;\n}\n\nexport interface SceneLayoutChildOptions {\n width?: number | string;\n height?: number | string;\n xSizing?: 'fill' | 'content';\n ySizing?: 'fill' | 'content';\n x?: number;\n y?: number;\n minWidth?: number | string;\n minHeight?: number | string;\n isDraggable?: boolean;\n isResizable?: boolean;\n}\n\nexport interface SceneComponentProps<T> {\n model: T;\n}\n\nexport type SceneComponent<TModel> = (props: SceneComponentProps<TModel>) => React.ReactElement | null;\n\nexport interface SceneDataState extends SceneObjectState {\n data?: PanelData;\n}\n\nexport interface SceneObject<TState extends SceneObjectState = SceneObjectState> {\n /** The current state */\n readonly state: TState;\n\n /** True when there is a React component mounted for this Object */\n readonly isActive: boolean;\n\n /** SceneObject parent */\n readonly parent?: SceneObject;\n\n /** This abtractions declares what variables the scene object depends on and how to handle when they change value. **/\n readonly variableDependency?: SceneVariableDependencyConfigLike;\n\n /** This abstraction declares URL sync dependencies of a scene object. **/\n readonly urlSync?: SceneObjectUrlSyncHandler;\n\n /** Subscribe to state changes */\n subscribeToState(handler: SceneStateChangedHandler<TState>): Unsubscribable;\n\n /** Subscribe to a scene event */\n subscribeToEvent<T extends BusEvent>(typeFilter: BusEventType<T>, handler: BusEventHandler<T>): Unsubscribable;\n\n /** Publish an event and optionally bubble it up the scene */\n publishEvent(event: BusEvent, bubble?: boolean): void;\n\n /** Utility hook that wraps useObservable. Used by React components to subscribes to state changes */\n useState(): TState;\n\n /** How to modify state */\n setState(state: Partial<TState>): void;\n\n /**\n * Called when the Component is mounted. This will also activate any $data, $variables or $timeRange scene object on this level.\n * Don't override this in your custom SceneObjects, instead use addActivationHandler from the constructor.\n **/\n activate(): CancelActivationHandler;\n\n /** Get the scene root */\n getRoot(): SceneObject;\n\n /** Returns a deep clone this object and all its children */\n clone(state?: Partial<TState>): this;\n\n /** A React component to use for rendering the object */\n Component(props: SceneComponentProps<SceneObject<TState>>): React.ReactElement | null;\n\n /** Force a re-render, should only be needed when variable values change */\n forceRender(): void;\n\n /** Returns a SceneObjectRef that will resolve to this object */\n getRef(): SceneObjectRef<this>;\n\n /**\n * Allows external code to register code that is executed on activate and deactivate. This allow you\n * to wire up scene objects that need to respond to state changes in other objects from the outside.\n **/\n addActivationHandler(handler: SceneActivationHandler): void;\n\n /**\n * Loop through state and call callback for each direct child scene object.\n * Checks 1 level deep properties and arrays. So a scene object hidden in a nested plain object will not be detected.\n */\n forEachChild(callback: (child: SceneObject) => void): void;\n}\n\nexport type SceneActivationHandler = () => SceneDeactivationHandler | void;\nexport type SceneDeactivationHandler = () => void;\n\n/**\n * Function returned by activate() that when called will deactivate the object if it's the last activator\n **/\nexport type CancelActivationHandler = () => void;\n\nexport interface SceneLayoutState extends SceneObjectState {\n children: SceneObject[];\n}\n\nexport interface SceneLayout<T extends SceneLayoutState = SceneLayoutState> extends SceneObject<T> {\n isDraggable(): boolean;\n getDragClass?(): string;\n getDragClassCancel?(): string;\n}\n\nexport interface SceneTimeRangeState extends SceneObjectState {\n from: string;\n to: string;\n fiscalYearStartMonth?: number;\n value: TimeRange;\n timeZone?: TimeZone;\n /** weekStart will change the global date locale so having multiple different weekStart values is not supported */\n weekStart?: string;\n /**\n * @internal\n * To enable feature parity with the old time range picker, not sure if it will be kept.\n * Override the now time by entering a time delay. Use this option to accommodate known delays in data aggregation to avoid null values.\n * */\n UNSAFE_nowDelay?: string;\n\n refreshOnActivate?: {\n /**\n * When set, the time range will invalidate relative ranges after the specified interval has elapsed\n */\n afterMs?: number\n /**\n * When set, the time range will invalidate relative ranges after the specified percentage of the current interval has elapsed.\n * If both invalidate values are set, the smaller value will be used for the given interval.\n */\n percent?: number\n }\n}\n\nexport interface SceneTimeRangeLike extends SceneObject<SceneTimeRangeState> {\n onTimeZoneChange(timeZone: TimeZone): void;\n onTimeRangeChange(timeRange: TimeRange): void;\n onRefresh(): void;\n getTimeZone(): TimeZone;\n}\n\nexport function isSceneObject(obj: any): obj is SceneObject {\n return obj.useState !== undefined;\n}\n\nexport interface SceneObjectWithUrlSync extends SceneObject {\n getUrlState(): SceneObjectUrlValues;\n updateFromUrl(values: SceneObjectUrlValues): void;\n}\n\nexport interface SceneObjectUrlSyncHandler {\n getKeys(): string[];\n getUrlState(): SceneObjectUrlValues;\n updateFromUrl(values: SceneObjectUrlValues): void;\n}\n\nexport interface DataRequestEnricher {\n // Return partial data query request that will be merged with the original request provided by SceneQueryRunner\n enrichDataRequest(source: SceneObject): Partial<DataQueryRequest> | null;\n}\n\nexport interface FiltersRequestEnricher {\n // Return partial getTagKeys or getTagValues query request that will be merged with the original request provided by ad hoc or group by variable\n enrichFiltersRequest(\n source: SceneObject\n ): Partial<DataSourceGetTagKeysOptions | DataSourceGetTagValuesOptions> | null;\n}\n\nexport function isDataRequestEnricher(obj: any): obj is DataRequestEnricher {\n return 'enrichDataRequest' in obj;\n}\n\nexport function isFiltersRequestEnricher(obj: any): obj is FiltersRequestEnricher {\n return 'enrichFiltersRequest' in obj;\n}\n\nexport type SceneObjectUrlValue = string | string[] | undefined | null;\nexport type SceneObjectUrlValues = Record<string, SceneObjectUrlValue>;\n\nexport type CustomTransformOperator = (context: DataTransformContext) => MonoTypeOperatorFunction<DataFrame[]>;\nexport type CustomTransformerDefinition =\n | { operator: CustomTransformOperator; topic: DataTopic }\n | CustomTransformOperator;\nexport type SceneStateChangedHandler<TState> = (newState: TState, prevState: TState) => void;\n\nexport type DeepPartial<T> = {\n [K in keyof T]?: T[K] extends object ? DeepPartial<T[K]> : T[K];\n};\n\nexport interface SceneDataProviderResult {\n data: PanelData;\n origin: SceneDataProvider;\n}\n\nexport interface SceneDataProvider<T extends SceneObjectState = SceneDataState> extends SceneObject<T> {\n setContainerWidth?: (width: number) => void;\n isDataReadyToDisplay?: () => boolean;\n cancelQuery?: () => void;\n getResultsStream(): Observable<SceneDataProviderResult>;\n}\n\nexport interface SceneDataLayerProviderState extends SceneDataState {\n name: string;\n description?: string;\n isEnabled?: boolean;\n isHidden?: boolean;\n}\n\nexport interface SceneDataLayerProvider extends SceneDataProvider<SceneDataLayerProviderState> {\n isDataLayer: true;\n}\n\nexport function isDataLayer(obj: SceneObject): obj is SceneDataLayerProvider {\n return 'isDataLayer' in obj;\n}\n\nexport interface DataLayerFilter {\n panelId: number;\n}\n\nexport interface SceneStatelessBehavior<T extends SceneObject = any> {\n (sceneObject: T): CancelActivationHandler | void;\n}\n\nexport type ControlsLayout = 'horizontal' | 'vertical';\n\nexport interface UseStateHookOptions {\n /**\n * For some edge cases other scene objects want to subscribe to scene object state for objects\n * that are not active, or whose main React Component can be un-mounted. Set this to true\n * to keep the scene object active even if the React component is unmounted.\n *\n * Normally you would not need this but this can be useful in some edge cases.\n *\n * @experimental\n */\n shouldActivateOrKeepAlive?: boolean;\n}\n\nexport interface SceneDataQuery extends DataQuery {\n [key: string]: any;\n\n // Opt this query out of time window comparison\n timeRangeCompare?: boolean;\n}\n"],"names":[],"mappings":"AA8KO,SAAS,cAAc,GAA8B,EAAA;AAC1D,EAAA,OAAO,IAAI,QAAa,KAAA,KAAA,CAAA,CAAA;AAC1B,CAAA;AAyBO,SAAS,sBAAsB,GAAsC,EAAA;AAC1E,EAAA,OAAO,mBAAuB,IAAA,GAAA,CAAA;AAChC,CAAA;AAEO,SAAS,yBAAyB,GAAyC,EAAA;AAChF,EAAA,OAAO,sBAA0B,IAAA,GAAA,CAAA;AACnC,CAAA;AAsCO,SAAS,YAAY,GAAiD,EAAA;AAC3E,EAAA,OAAO,aAAiB,IAAA,GAAA,CAAA;AAC1B;;;;"}
1
+ {"version":3,"file":"types.js","sources":["../../../src/core/types.ts"],"sourcesContent":["import React from 'react';\nimport { MonoTypeOperatorFunction, Observable, Unsubscribable } from 'rxjs';\n\nimport {\n BusEvent,\n BusEventHandler,\n BusEventType,\n DataFrame,\n DataQueryRequest,\n DataSourceGetTagKeysOptions,\n DataSourceGetTagValuesOptions,\n DataTransformContext,\n PanelData,\n TimeRange,\n} from '@grafana/data';\nimport { DataQuery, DataTopic, TimeZone } from '@grafana/schema';\n\nimport { SceneVariableDependencyConfigLike, SceneVariables } from '../variables/types';\nimport { SceneObjectRef } from './SceneObjectRef';\n\nexport interface SceneObjectState {\n key?: string;\n $timeRange?: SceneTimeRangeLike;\n $data?: SceneDataProvider;\n $variables?: SceneVariables;\n /**\n * @experimental\n * Can be used to add extra behaviors to a scene object.\n * These are activated when the their parent scene object is activated.\n */\n $behaviors?: Array<SceneObject | SceneStatelessBehavior>;\n}\n\nexport interface SceneLayoutChildOptions {\n width?: number | string;\n height?: number | string;\n xSizing?: 'fill' | 'content';\n ySizing?: 'fill' | 'content';\n x?: number;\n y?: number;\n minWidth?: number | string;\n minHeight?: number | string;\n isDraggable?: boolean;\n isResizable?: boolean;\n}\n\nexport interface SceneComponentProps<T> {\n model: T;\n}\n\nexport type SceneComponent<TModel> = (props: SceneComponentProps<TModel>) => React.ReactElement | null;\n\nexport interface SceneDataState extends SceneObjectState {\n data?: PanelData;\n}\n\nexport interface SceneObject<TState extends SceneObjectState = SceneObjectState> {\n /** The current state */\n readonly state: TState;\n\n /** True when there is a React component mounted for this Object */\n readonly isActive: boolean;\n\n /** SceneObject parent */\n readonly parent?: SceneObject;\n\n /** This abtractions declares what variables the scene object depends on and how to handle when they change value. **/\n readonly variableDependency?: SceneVariableDependencyConfigLike;\n\n /** This abstraction declares URL sync dependencies of a scene object. **/\n readonly urlSync?: SceneObjectUrlSyncHandler;\n\n /** Subscribe to state changes */\n subscribeToState(handler: SceneStateChangedHandler<TState>): Unsubscribable;\n\n /** Subscribe to a scene event */\n subscribeToEvent<T extends BusEvent>(typeFilter: BusEventType<T>, handler: BusEventHandler<T>): Unsubscribable;\n\n /** Publish an event and optionally bubble it up the scene */\n publishEvent(event: BusEvent, bubble?: boolean): void;\n\n /** Utility hook that wraps useObservable. Used by React components to subscribes to state changes */\n useState(): TState;\n\n /** How to modify state */\n setState(state: Partial<TState>): void;\n\n /**\n * Called when the Component is mounted. This will also activate any $data, $variables or $timeRange scene object on this level.\n * Don't override this in your custom SceneObjects, instead use addActivationHandler from the constructor.\n **/\n activate(): CancelActivationHandler;\n\n /** Get the scene root */\n getRoot(): SceneObject;\n\n /** Returns a deep clone this object and all its children */\n clone(state?: Partial<TState>): this;\n\n /** A React component to use for rendering the object */\n Component(props: SceneComponentProps<SceneObject<TState>>): React.ReactElement | null;\n\n /** Force a re-render, should only be needed when variable values change */\n forceRender(): void;\n\n /** Returns a SceneObjectRef that will resolve to this object */\n getRef(): SceneObjectRef<this>;\n\n /**\n * Allows external code to register code that is executed on activate and deactivate. This allow you\n * to wire up scene objects that need to respond to state changes in other objects from the outside.\n **/\n addActivationHandler(handler: SceneActivationHandler): void;\n\n /**\n * Loop through state and call callback for each direct child scene object.\n * Checks 1 level deep properties and arrays. So a scene object hidden in a nested plain object will not be detected.\n */\n forEachChild(callback: (child: SceneObject) => void): void;\n}\n\nexport type SceneActivationHandler = () => SceneDeactivationHandler | void;\nexport type SceneDeactivationHandler = () => void;\n\n/**\n * Function returned by activate() that when called will deactivate the object if it's the last activator\n **/\nexport type CancelActivationHandler = () => void;\n\nexport interface SceneLayoutState extends SceneObjectState {\n children: SceneObject[];\n}\n\nexport interface SceneLayout<T extends SceneLayoutState = SceneLayoutState> extends SceneObject<T> {\n isDraggable(): boolean;\n getDragClass?(): string;\n getDragClassCancel?(): string;\n}\n\nexport interface SceneTimeRangeState extends SceneObjectState {\n from: string;\n to: string;\n fiscalYearStartMonth?: number;\n value: TimeRange;\n timeZone?: TimeZone;\n /** weekStart will change the global date locale so having multiple different weekStart values is not supported */\n weekStart?: string;\n /**\n * @internal\n * To enable feature parity with the old time range picker, not sure if it will be kept.\n * Override the now time by entering a time delay. Use this option to accommodate known delays in data aggregation to avoid null values.\n * */\n UNSAFE_nowDelay?: string;\n\n refreshOnActivate?: {\n /**\n * When set, the time range will invalidate relative ranges after the specified interval has elapsed\n */\n afterMs?: number;\n /**\n * When set, the time range will invalidate relative ranges after the specified percentage of the current interval has elapsed.\n * If both invalidate values are set, the smaller value will be used for the given interval.\n */\n percent?: number;\n };\n}\n\nexport interface SceneTimeRangeLike extends SceneObject<SceneTimeRangeState> {\n onTimeZoneChange(timeZone: TimeZone): void;\n onTimeRangeChange(timeRange: TimeRange): void;\n onRefresh(): void;\n getTimeZone(): TimeZone;\n}\n\nexport function isSceneObject(obj: any): obj is SceneObject {\n return obj.useState !== undefined;\n}\n\nexport interface SceneObjectWithUrlSync extends SceneObject {\n getUrlState(): SceneObjectUrlValues;\n updateFromUrl(values: SceneObjectUrlValues): void;\n}\n\nexport interface SceneObjectUrlSyncHandler {\n getKeys(): string[];\n getUrlState(): SceneObjectUrlValues;\n updateFromUrl(values: SceneObjectUrlValues): void;\n}\n\nexport interface DataRequestEnricher {\n // Return partial data query request that will be merged with the original request provided by SceneQueryRunner\n enrichDataRequest(source: SceneObject): Partial<DataQueryRequest> | null;\n}\n\nexport interface FiltersRequestEnricher {\n // Return partial getTagKeys or getTagValues query request that will be merged with the original request provided by ad hoc or group by variable\n enrichFiltersRequest(\n source: SceneObject\n ): Partial<DataSourceGetTagKeysOptions | DataSourceGetTagValuesOptions> | null;\n}\n\nexport function isDataRequestEnricher(obj: any): obj is DataRequestEnricher {\n return 'enrichDataRequest' in obj;\n}\n\nexport function isFiltersRequestEnricher(obj: any): obj is FiltersRequestEnricher {\n return 'enrichFiltersRequest' in obj;\n}\n\nexport type SceneObjectUrlValue = string | string[] | undefined | null;\nexport type SceneObjectUrlValues = Record<string, SceneObjectUrlValue>;\n\nexport type CustomTransformOperator = (context: DataTransformContext) => MonoTypeOperatorFunction<DataFrame[]>;\nexport type CustomTransformerDefinition =\n | { operator: CustomTransformOperator; topic: DataTopic }\n | CustomTransformOperator;\nexport type SceneStateChangedHandler<TState> = (newState: TState, prevState: TState) => void;\n\nexport type DeepPartial<T> = {\n [K in keyof T]?: T[K] extends object ? DeepPartial<T[K]> : T[K];\n};\n\nexport interface SceneDataProviderResult {\n data: PanelData;\n origin: SceneDataProvider;\n}\n\nexport interface SceneDataProvider<T extends SceneObjectState = SceneDataState> extends SceneObject<T> {\n setContainerWidth?: (width: number) => void;\n isDataReadyToDisplay?: () => boolean;\n cancelQuery?: () => void;\n getResultsStream(): Observable<SceneDataProviderResult>;\n}\n\nexport interface SceneDataLayerProviderState extends SceneDataState {\n name: string;\n description?: string;\n isEnabled?: boolean;\n isHidden?: boolean;\n}\n\nexport interface SceneDataLayerProvider extends SceneDataProvider<SceneDataLayerProviderState> {\n isDataLayer: true;\n}\n\nexport function isDataLayer(obj: SceneObject): obj is SceneDataLayerProvider {\n return 'isDataLayer' in obj;\n}\n\nexport interface DataLayerFilter {\n panelId: number;\n}\n\nexport interface SceneStatelessBehavior<T extends SceneObject = any> {\n (sceneObject: T): CancelActivationHandler | void;\n}\n\nexport type ControlsLayout = 'horizontal' | 'vertical';\n\nexport interface UseStateHookOptions {\n /**\n * For some edge cases other scene objects want to subscribe to scene object state for objects\n * that are not active, or whose main React Component can be un-mounted. Set this to true\n * to keep the scene object active even if the React component is unmounted.\n *\n * Normally you would not need this but this can be useful in some edge cases.\n *\n * @experimental\n */\n shouldActivateOrKeepAlive?: boolean;\n}\n\nexport interface SceneDataQuery extends DataQuery {\n [key: string]: any;\n\n // Opt this query out of time window comparison\n timeRangeCompare?: boolean;\n}\n"],"names":[],"mappings":"AA8KO,SAAS,cAAc,GAA8B,EAAA;AAC1D,EAAA,OAAO,IAAI,QAAa,KAAA,KAAA,CAAA,CAAA;AAC1B,CAAA;AAyBO,SAAS,sBAAsB,GAAsC,EAAA;AAC1E,EAAA,OAAO,mBAAuB,IAAA,GAAA,CAAA;AAChC,CAAA;AAEO,SAAS,yBAAyB,GAAyC,EAAA;AAChF,EAAA,OAAO,sBAA0B,IAAA,GAAA,CAAA;AACnC,CAAA;AAsCO,SAAS,YAAY,GAAiD,EAAA;AAC3E,EAAA,OAAO,aAAiB,IAAA,GAAA,CAAA;AAC1B;;;;"}
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":["../../src/index.ts"],"sourcesContent":["import { getUrlWithAppState } from './components/SceneApp/utils';\nimport { registerRuntimePanelPlugin } from './components/VizPanel/registerRuntimePanelPlugin';\nimport { cloneSceneObjectState } from './core/sceneGraph/utils';\nimport { registerRuntimeDataSource } from './querying/RuntimeDataSource';\nimport { getUrlState, syncStateFromSearchParams } from './services/utils';\n\nimport { registerVariableMacro } from './variables/macros';\nimport { renderPrometheusLabelFilters } from './variables/utils';\nimport {\n isAdHocVariable,\n isQueryVariable,\n isTextBoxVariable,\n isCustomVariable,\n isDataSourceVariable,\n isConstantVariable,\n isIntervalVariable,\n isGroupByVariable,\n} from './variables/variants/guards';\n\nexport * from './core/types';\nexport * from './core/events';\nexport { sceneGraph } from './core/sceneGraph';\nexport * as behaviors from './behaviors';\nexport * as dataLayers from './querying/layers';\n\nexport { SceneObjectBase, useSceneObjectState } from './core/SceneObjectBase';\nexport { SceneDataNode } from './core/SceneDataNode';\nexport { SceneTimeRange } from './core/SceneTimeRange';\nexport { SceneTimeZoneOverride } from './core/SceneTimeZoneOverride';\n\nexport { SceneQueryRunner, type QueryRunnerState } from './querying/SceneQueryRunner';\nexport {\n type ExtraQueryDescriptor,\n type ExtraQueryProvider,\n type ExtraQueryDataProcessor,\n} from './querying/ExtraQueryProvider';\nexport { SceneDataLayerSet, SceneDataLayerSetBase } from './querying/SceneDataLayerSet';\nexport { SceneDataLayerBase } from './querying/layers/SceneDataLayerBase';\nexport { SceneDataLayerControls } from './querying/layers/SceneDataLayerControls';\nexport { SceneDataTransformer } from './querying/SceneDataTransformer';\nexport { registerQueryWithController } from './querying/registerQueryWithController';\nexport { registerRuntimeDataSource, RuntimeDataSource } from './querying/RuntimeDataSource';\nexport type {\n SceneQueryControllerLike,\n SceneQueryControllerEntryType,\n SceneQueryControllerEntry,\n SceneInteractionProfileEvent,\n} from './behaviors/types';\n\nexport * from './variables/types';\nexport { VariableDependencyConfig } from './variables/VariableDependencyConfig';\nexport { formatRegistry, type FormatVariable } from './variables/interpolation/formatRegistry';\nexport { VariableValueSelectors } from './variables/components/VariableValueSelectors';\nexport { VariableValueControl } from './variables/components/VariableValueControl';\nexport { SceneVariableSet } from './variables/sets/SceneVariableSet';\nexport { ConstantVariable } from './variables/variants/ConstantVariable';\nexport { CustomVariable } from './variables/variants/CustomVariable';\nexport { DataSourceVariable } from './variables/variants/DataSourceVariable';\nexport { QueryVariable } from './variables/variants/query/QueryVariable';\nexport { TestVariable } from './variables/variants/TestVariable';\nexport { TextBoxVariable } from './variables/variants/TextBoxVariable';\nexport {\n MultiValueVariable,\n type MultiValueVariableState,\n type VariableGetOptionsArgs,\n} from './variables/variants/MultiValueVariable';\nexport { LocalValueVariable } from './variables/variants/LocalValueVariable';\nexport { IntervalVariable } from './variables/variants/IntervalVariable';\nexport { AdHocFiltersVariable } from './variables/adhoc/AdHocFiltersVariable';\nexport { GroupByVariable } from './variables/groupby/GroupByVariable';\nexport { type MacroVariableConstructor } from './variables/macros/types';\n\nexport { type UrlSyncManagerLike, UrlSyncManager, getUrlSyncManager } from './services/UrlSyncManager';\nexport { useUrlSync } from './services/useUrlSync';\nexport { UrlSyncContextProvider } from './services/UrlSyncContextProvider';\nexport { SceneObjectUrlSyncConfig } from './services/SceneObjectUrlSyncConfig';\n\nexport { EmbeddedScene, type EmbeddedSceneState } from './components/EmbeddedScene';\nexport { VizPanel, type VizPanelState } from './components/VizPanel/VizPanel';\nexport { VizPanelMenu } from './components/VizPanel/VizPanelMenu';\nexport { NestedScene } from './components/NestedScene';\nexport { SceneCanvasText } from './components/SceneCanvasText';\nexport { SceneToolbarButton, SceneToolbarInput } from './components/SceneToolbarButton';\nexport { SceneTimePicker } from './components/SceneTimePicker';\nexport { SceneRefreshPicker, type SceneRefreshPickerState } from './components/SceneRefreshPicker';\nexport { SceneTimeRangeTransformerBase } from './core/SceneTimeRangeTransformerBase';\nexport { SceneTimeRangeCompare } from './components/SceneTimeRangeCompare';\nexport { SceneByFrameRepeater } from './components/SceneByFrameRepeater';\nexport { SceneByVariableRepeater } from './components/SceneByVariableRepeater';\nexport { SceneControlsSpacer } from './components/SceneControlsSpacer';\nexport {\n SceneFlexLayout,\n SceneFlexItem,\n type SceneFlexItemState,\n type SceneFlexItemLike,\n} from './components/layout/SceneFlexLayout';\nexport { SceneCSSGridLayout, SceneCSSGridItem } from './components/layout/CSSGrid/SceneCSSGridLayout';\nexport { SceneGridLayout } from './components/layout/grid/SceneGridLayout';\nexport { SceneGridItem } from './components/layout/grid/SceneGridItem';\nexport { SceneGridRow } from './components/layout/grid/SceneGridRow';\nexport { type SceneGridItemStateLike, type SceneGridItemLike } from './components/layout/grid/types';\nexport { SplitLayout } from './components/layout/split/SplitLayout';\nexport {\n type SceneAppPageLike,\n type SceneRouteMatch,\n type SceneAppPageState,\n type SceneAppDrilldownView,\n type SceneAppRoute,\n} from './components/SceneApp/types';\nexport { SceneApp, useSceneApp } from './components/SceneApp/SceneApp';\nexport { SceneAppPage } from './components/SceneApp/SceneAppPage';\nexport { SceneReactObject } from './components/SceneReactObject';\nexport { SceneObjectRef } from './core/SceneObjectRef';\nexport {\n PanelBuilders,\n PanelOptionsBuilders,\n FieldConfigBuilders,\n FieldConfigOverridesBuilder,\n} from './core/PanelBuilders';\nexport { FieldConfigBuilder } from './core/PanelBuilders/FieldConfigBuilder';\nexport { VizPanelBuilder } from './core/PanelBuilders/VizPanelBuilder';\nexport { SceneDebugger } from './components/SceneDebugger/SceneDebugger';\nexport { VariableValueSelectWrapper } from './variables/components/VariableValueSelectors';\nexport { renderSelectForVariable } from './variables/components/VariableValueSelect';\nexport { VizConfigBuilder } from './core/PanelBuilders/VizConfigBuilder';\nexport { VizConfigBuilders } from './core/PanelBuilders/VizConfigBuilders';\nexport { type VizConfig } from './core/PanelBuilders/types';\n\nexport const sceneUtils = {\n getUrlWithAppState,\n registerRuntimePanelPlugin,\n registerRuntimeDataSource,\n registerVariableMacro,\n cloneSceneObjectState,\n syncStateFromSearchParams,\n getUrlState,\n renderPrometheusLabelFilters,\n\n // Variable guards\n isAdHocVariable,\n isConstantVariable,\n isCustomVariable,\n isDataSourceVariable,\n isIntervalVariable,\n isQueryVariable,\n isTextBoxVariable,\n isGroupByVariable,\n};\n\nexport { SafeSerializableSceneObject } from './utils/SafeSerializableSceneObject';\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAgIO,MAAM,UAAa,GAAA;AAAA,EACxB,kBAAA;AAAA,EACA,0BAAA;AAAA,EACA,yBAAA;AAAA,EACA,qBAAA;AAAA,EACA,qBAAA;AAAA,EACA,yBAAA;AAAA,EACA,WAAA;AAAA,EACA,4BAAA;AAAA,EAGA,eAAA;AAAA,EACA,kBAAA;AAAA,EACA,gBAAA;AAAA,EACA,oBAAA;AAAA,EACA,kBAAA;AAAA,EACA,eAAA;AAAA,EACA,iBAAA;AAAA,EACA,iBAAA;AACF;;;;"}
1
+ {"version":3,"file":"index.js","sources":["../../src/index.ts"],"sourcesContent":["import { getUrlWithAppState } from './components/SceneApp/utils';\nimport { registerRuntimePanelPlugin } from './components/VizPanel/registerRuntimePanelPlugin';\nimport { cloneSceneObjectState } from './core/sceneGraph/utils';\nimport { registerRuntimeDataSource } from './querying/RuntimeDataSource';\nimport { getUrlState, syncStateFromSearchParams } from './services/utils';\n\nimport { registerVariableMacro } from './variables/macros';\nimport { renderPrometheusLabelFilters } from './variables/utils';\nimport {\n isAdHocVariable,\n isQueryVariable,\n isTextBoxVariable,\n isCustomVariable,\n isDataSourceVariable,\n isConstantVariable,\n isIntervalVariable,\n isGroupByVariable,\n} from './variables/variants/guards';\n\nexport * from './core/types';\nexport * from './core/events';\nexport { sceneGraph } from './core/sceneGraph';\nexport * as behaviors from './behaviors';\nexport * as dataLayers from './querying/layers';\n\nexport { SceneObjectBase, useSceneObjectState } from './core/SceneObjectBase';\nexport { SceneDataNode } from './core/SceneDataNode';\nexport { SceneTimeRange } from './core/SceneTimeRange';\nexport { SceneTimeZoneOverride } from './core/SceneTimeZoneOverride';\n\nexport { SceneQueryRunner, type QueryRunnerState } from './querying/SceneQueryRunner';\nexport {\n type ExtraQueryDescriptor,\n type ExtraQueryProvider,\n type ExtraQueryDataProcessor,\n} from './querying/ExtraQueryProvider';\nexport { SceneDataLayerSet, SceneDataLayerSetBase } from './querying/SceneDataLayerSet';\nexport { SceneDataLayerBase } from './querying/layers/SceneDataLayerBase';\nexport { SceneDataLayerControls } from './querying/layers/SceneDataLayerControls';\nexport { SceneDataTransformer } from './querying/SceneDataTransformer';\nexport { registerQueryWithController } from './querying/registerQueryWithController';\nexport { registerRuntimeDataSource, RuntimeDataSource } from './querying/RuntimeDataSource';\nexport type {\n SceneQueryControllerLike,\n SceneQueryControllerEntryType,\n SceneQueryControllerEntry,\n} from './behaviors/SceneQueryController';\n\nexport * from './variables/types';\nexport { VariableDependencyConfig } from './variables/VariableDependencyConfig';\nexport { formatRegistry, type FormatVariable } from './variables/interpolation/formatRegistry';\nexport { VariableValueSelectors } from './variables/components/VariableValueSelectors';\nexport { VariableValueControl } from './variables/components/VariableValueControl';\nexport { SceneVariableSet } from './variables/sets/SceneVariableSet';\nexport { ConstantVariable } from './variables/variants/ConstantVariable';\nexport { CustomVariable } from './variables/variants/CustomVariable';\nexport { DataSourceVariable } from './variables/variants/DataSourceVariable';\nexport { QueryVariable } from './variables/variants/query/QueryVariable';\nexport { TestVariable } from './variables/variants/TestVariable';\nexport { TextBoxVariable } from './variables/variants/TextBoxVariable';\nexport {\n MultiValueVariable,\n type MultiValueVariableState,\n type VariableGetOptionsArgs,\n} from './variables/variants/MultiValueVariable';\nexport { LocalValueVariable } from './variables/variants/LocalValueVariable';\nexport { IntervalVariable } from './variables/variants/IntervalVariable';\nexport { AdHocFiltersVariable } from './variables/adhoc/AdHocFiltersVariable';\nexport { GroupByVariable } from './variables/groupby/GroupByVariable';\nexport { type MacroVariableConstructor } from './variables/macros/types';\n\nexport { type UrlSyncManagerLike, UrlSyncManager, getUrlSyncManager } from './services/UrlSyncManager';\nexport { useUrlSync } from './services/useUrlSync';\nexport { UrlSyncContextProvider } from './services/UrlSyncContextProvider';\nexport { SceneObjectUrlSyncConfig } from './services/SceneObjectUrlSyncConfig';\n\nexport { EmbeddedScene, type EmbeddedSceneState } from './components/EmbeddedScene';\nexport { VizPanel, type VizPanelState } from './components/VizPanel/VizPanel';\nexport { VizPanelMenu } from './components/VizPanel/VizPanelMenu';\nexport { NestedScene } from './components/NestedScene';\nexport { SceneCanvasText } from './components/SceneCanvasText';\nexport { SceneToolbarButton, SceneToolbarInput } from './components/SceneToolbarButton';\nexport { SceneTimePicker } from './components/SceneTimePicker';\nexport { SceneRefreshPicker, type SceneRefreshPickerState } from './components/SceneRefreshPicker';\nexport { SceneTimeRangeTransformerBase } from './core/SceneTimeRangeTransformerBase';\nexport { SceneTimeRangeCompare } from './components/SceneTimeRangeCompare';\nexport { SceneByFrameRepeater } from './components/SceneByFrameRepeater';\nexport { SceneByVariableRepeater } from './components/SceneByVariableRepeater';\nexport { SceneControlsSpacer } from './components/SceneControlsSpacer';\nexport {\n SceneFlexLayout,\n SceneFlexItem,\n type SceneFlexItemState,\n type SceneFlexItemLike,\n} from './components/layout/SceneFlexLayout';\nexport { SceneCSSGridLayout, SceneCSSGridItem } from './components/layout/CSSGrid/SceneCSSGridLayout';\nexport { SceneGridLayout } from './components/layout/grid/SceneGridLayout';\nexport { SceneGridItem } from './components/layout/grid/SceneGridItem';\nexport { SceneGridRow } from './components/layout/grid/SceneGridRow';\nexport { type SceneGridItemStateLike, type SceneGridItemLike } from './components/layout/grid/types';\nexport { SplitLayout } from './components/layout/split/SplitLayout';\nexport {\n type SceneAppPageLike,\n type SceneRouteMatch,\n type SceneAppPageState,\n type SceneAppDrilldownView,\n type SceneAppRoute,\n} from './components/SceneApp/types';\nexport { SceneApp, useSceneApp } from './components/SceneApp/SceneApp';\nexport { SceneAppPage } from './components/SceneApp/SceneAppPage';\nexport { SceneReactObject } from './components/SceneReactObject';\nexport { SceneObjectRef } from './core/SceneObjectRef';\nexport {\n PanelBuilders,\n PanelOptionsBuilders,\n FieldConfigBuilders,\n FieldConfigOverridesBuilder,\n} from './core/PanelBuilders';\nexport { FieldConfigBuilder } from './core/PanelBuilders/FieldConfigBuilder';\nexport { VizPanelBuilder } from './core/PanelBuilders/VizPanelBuilder';\nexport { SceneDebugger } from './components/SceneDebugger/SceneDebugger';\nexport { VariableValueSelectWrapper } from './variables/components/VariableValueSelectors';\nexport { renderSelectForVariable } from './variables/components/VariableValueSelect';\nexport { VizConfigBuilder } from './core/PanelBuilders/VizConfigBuilder';\nexport { VizConfigBuilders } from './core/PanelBuilders/VizConfigBuilders';\nexport { type VizConfig } from './core/PanelBuilders/types';\n\nexport const sceneUtils = {\n getUrlWithAppState,\n registerRuntimePanelPlugin,\n registerRuntimeDataSource,\n registerVariableMacro,\n cloneSceneObjectState,\n syncStateFromSearchParams,\n getUrlState,\n renderPrometheusLabelFilters,\n\n // Variable guards\n isAdHocVariable,\n isConstantVariable,\n isCustomVariable,\n isDataSourceVariable,\n isIntervalVariable,\n isQueryVariable,\n isTextBoxVariable,\n isGroupByVariable,\n};\n\nexport { SafeSerializableSceneObject } from './utils/SafeSerializableSceneObject';\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA+HO,MAAM,UAAa,GAAA;AAAA,EACxB,kBAAA;AAAA,EACA,0BAAA;AAAA,EACA,yBAAA;AAAA,EACA,qBAAA;AAAA,EACA,qBAAA;AAAA,EACA,yBAAA;AAAA,EACA,WAAA;AAAA,EACA,4BAAA;AAAA,EAGA,eAAA;AAAA,EACA,kBAAA;AAAA,EACA,gBAAA;AAAA,EACA,oBAAA;AAAA,EACA,kBAAA;AAAA,EACA,eAAA;AAAA,EACA,iBAAA;AAAA,EACA,iBAAA;AACF;;;;"}
@@ -88,7 +88,9 @@ class SceneQueryRunner extends SceneObjectBase {
88
88
  })
89
89
  );
90
90
  }
91
- this.subscribeToTimeRangeChanges(timeRange);
91
+ this.subscribeToTimeRangeChanges(
92
+ timeRange
93
+ );
92
94
  if (this.shouldRunQueriesOnActivate()) {
93
95
  this.runQueries();
94
96
  }
@@ -1 +1 @@
1
- {"version":3,"file":"SceneQueryRunner.js","sources":["../../../src/querying/SceneQueryRunner.ts"],"sourcesContent":["import { cloneDeep, isEqual } from 'lodash';\nimport { forkJoin, ReplaySubject, Unsubscribable } from 'rxjs';\n\nimport { DataQuery, DataSourceRef, LoadingState } from '@grafana/schema';\n\nimport {\n AlertStateInfo,\n DataFrame,\n DataFrameView,\n DataQueryRequest,\n DataSourceApi,\n DataTopic,\n PanelData,\n preProcessPanelData,\n rangeUtil,\n} from '@grafana/data';\n\n// TODO: Remove this ignore annotation when the grafana runtime dependency has been updated\n// @ts-ignore\nimport { getRunRequest, toDataQueryError, isExpressionReference, config } from '@grafana/runtime';\n\nimport { SceneObjectBase } from '../core/SceneObjectBase';\nimport { sceneGraph } from '../core/sceneGraph';\nimport {\n DataLayerFilter,\n SceneDataProvider,\n SceneDataProviderResult,\n SceneDataQuery,\n SceneObjectState,\n SceneTimeRangeLike,\n} from '../core/types';\nimport { getDataSource } from '../utils/getDataSource';\nimport { VariableDependencyConfig } from '../variables/VariableDependencyConfig';\nimport { writeSceneLog } from '../utils/writeSceneLog';\nimport { VariableValueRecorder } from '../variables/VariableValueRecorder';\nimport { emptyPanelData } from '../core/SceneDataNode';\nimport { getClosest } from '../core/sceneGraph/utils';\nimport { isExtraQueryProvider, ExtraQueryDataProcessor, ExtraQueryProvider } from './ExtraQueryProvider';\nimport { passthroughProcessor, extraQueryProcessingOperator } from './extraQueryProcessingOperator';\nimport { filterAnnotations } from './layers/annotations/filterAnnotations';\nimport { getEnrichedDataRequest } from './getEnrichedDataRequest';\nimport { findActiveAdHocFilterVariableByUid } from '../variables/adhoc/patchGetAdhocFilters';\nimport { registerQueryWithController } from './registerQueryWithController';\nimport { findActiveGroupByVariablesByUid } from '../variables/groupby/findActiveGroupByVariablesByUid';\nimport { GroupByVariable } from '../variables/groupby/GroupByVariable';\nimport { AdHocFiltersVariable, isFilterComplete } from '../variables/adhoc/AdHocFiltersVariable';\nimport { SceneVariable } from '../variables/types';\nimport { DataLayersMerger } from './DataLayersMerger';\nimport { interpolate } from '../core/sceneGraph/sceneGraph';\nimport { wrapInSafeSerializableSceneObject } from '../utils/wrapInSafeSerializableSceneObject';\n\nlet counter = 100;\n\nexport function getNextRequestId() {\n return 'SQR' + counter++;\n}\n\nexport interface QueryRunnerState extends SceneObjectState {\n data?: PanelData;\n queries: SceneDataQuery[];\n datasource?: DataSourceRef;\n minInterval?: string;\n maxDataPoints?: number;\n liveStreaming?: boolean;\n maxDataPointsFromWidth?: boolean;\n cacheTimeout?: DataQueryRequest['cacheTimeout'];\n queryCachingTTL?: DataQueryRequest['queryCachingTTL'];\n /**\n * When set to auto (the default) query runner will issue queries on activate (when variable dependencies are ready) or when time range change.\n * Set to manual to have full manual control over when queries are issued. Try not to set this. This is mainly useful for unit tests, or special edge case workflows.\n */\n runQueriesMode?: 'auto' | 'manual';\n // Filters to be applied to data layer results before combining them with SQR results\n dataLayerFilter?: DataLayerFilter;\n // Private runtime state\n _hasFetchedData?: boolean;\n}\n\nexport interface DataQueryExtended extends DataQuery {\n [key: string]: any;\n\n // Opt this query out of time window comparison\n timeRangeCompare?: boolean;\n}\n\n// The requests that will be run by the query runner.\n//\n// Generally the query runner will run a single primary request.\n// If the scene graph contains implementations of\n// `ExtraQueryProvider`, the requests created by these\n// implementations will be added to the list of secondary requests,\n// and these will be executed at the same time as the primary request.\n//\n// The results of each secondary request will be passed to an associated\n// processor function (along with the results of the primary request),\n// which can transform the results as desired.\ninterface PreparedRequests {\n // The primary request to run.\n primary: DataQueryRequest;\n // A possibly empty list of secondary requests to run alongside\n // the primary request.\n secondaries: DataQueryRequest[];\n // A map from `requestId` of secondary requests to processors\n // for those requests. Provided by the `ExtraQueryProvider`.\n processors: Map<string, ExtraQueryDataProcessor>;\n}\n\nexport class SceneQueryRunner extends SceneObjectBase<QueryRunnerState> implements SceneDataProvider {\n private _querySub?: Unsubscribable;\n private _dataLayersSub?: Unsubscribable;\n private _dataLayersMerger = new DataLayersMerger();\n private _timeSub?: Unsubscribable;\n private _timeSubRange?: SceneTimeRangeLike;\n private _containerWidth?: number;\n private _variableValueRecorder = new VariableValueRecorder();\n private _results = new ReplaySubject<SceneDataProviderResult>(1);\n private _scopedVars = { __sceneObject: wrapInSafeSerializableSceneObject(this) };\n private _layerAnnotations?: DataFrame[];\n private _resultAnnotations?: DataFrame[];\n\n private _adhocFiltersVar?: AdHocFiltersVariable;\n private _groupByVar?: GroupByVariable;\n\n public getResultsStream() {\n return this._results;\n }\n\n protected _variableDependency: VariableDependencyConfig<QueryRunnerState> = new VariableDependencyConfig(this, {\n statePaths: ['queries', 'datasource'],\n onVariableUpdateCompleted: this.onVariableUpdatesCompleted.bind(this),\n onAnyVariableChanged: this.onAnyVariableChanged.bind(this),\n });\n\n public constructor(initialState: QueryRunnerState) {\n super(initialState);\n\n this.addActivationHandler(() => this._onActivate());\n }\n\n private _onActivate() {\n if (this.isQueryModeAuto()) {\n const timeRange = sceneGraph.getTimeRange(this);\n\n // Add subscriptions to any extra providers so that they rerun queries\n // when their state changes and they should rerun.\n const providers = this.getClosestExtraQueryProviders();\n for (const provider of providers) {\n this._subs.add(\n provider.subscribeToState((n, p) => {\n if (provider.shouldRerun(p, n, this.state.queries)) {\n this.runQueries();\n }\n })\n );\n }\n\n this.subscribeToTimeRangeChanges(timeRange);\n\n if (this.shouldRunQueriesOnActivate()) {\n this.runQueries();\n }\n }\n\n if (!this._dataLayersSub) {\n this._handleDataLayers();\n }\n\n return () => this._onDeactivate();\n }\n\n // This method subscribes to all SceneDataLayers up until the root, and combines the results into data provided from SceneQueryRunner\n private _handleDataLayers() {\n const dataLayers = sceneGraph.getDataLayers(this);\n\n if (dataLayers.length === 0) {\n return;\n }\n\n this._dataLayersSub = this._dataLayersMerger\n .getMergedStream(dataLayers)\n .subscribe(this._onLayersReceived.bind(this));\n }\n\n private _onLayersReceived(results: Iterable<SceneDataProviderResult>) {\n const timeRange = sceneGraph.getTimeRange(this);\n const { dataLayerFilter } = this.state;\n\n let annotations: DataFrame[] = [];\n let alertStates: DataFrame[] = [];\n let alertState: AlertStateInfo | undefined;\n\n for (const result of results) {\n for (let frame of result.data.series) {\n if (frame.meta?.dataTopic === DataTopic.Annotations) {\n annotations = annotations.concat(frame);\n }\n if (frame.meta?.dataTopic === DataTopic.AlertStates) {\n alertStates = alertStates.concat(frame);\n }\n }\n }\n\n if (dataLayerFilter?.panelId) {\n if (annotations.length > 0) {\n annotations = filterAnnotations(annotations, dataLayerFilter);\n }\n\n if (alertStates.length > 0) {\n for (const frame of alertStates) {\n const frameView = new DataFrameView<AlertStateInfo>(frame);\n\n for (const row of frameView) {\n if (row.panelId === dataLayerFilter.panelId) {\n alertState = row;\n break;\n }\n }\n }\n }\n }\n\n // Skip unnessary state updates\n if (\n allFramesEmpty(annotations) &&\n allFramesEmpty(this._layerAnnotations) &&\n isEqual(alertState, this.state.data?.alertState)\n ) {\n return;\n }\n\n this._layerAnnotations = annotations;\n\n const baseStateUpdate = this.state.data ? this.state.data : { ...emptyPanelData, timeRange: timeRange.state.value };\n\n this.setState({\n data: {\n ...baseStateUpdate,\n annotations: [...(this._resultAnnotations ?? []), ...annotations],\n alertState: alertState ?? this.state.data?.alertState,\n },\n });\n }\n\n /**\n * This tries to start a new query whenever a variable completes or is changed.\n *\n * We care about variable update completions even when the variable has not changed and even when it is not a direct dependency.\n * Example: Variables A and B (B depends on A). A update depends on time range. So when time change query runner will\n * find that variable A is loading which is a dependency on of variable B so will set _isWaitingForVariables to true and\n * not issue any query.\n *\n * When A completes it's loading (with no value change, so B never updates) it will cause a call of this function letting\n * the query runner know that A has completed, and in case _isWaitingForVariables we try to run the query. The query will\n * only run if all variables are in a non loading state so in other scenarios where a query depends on many variables this will\n * be called many times until all dependencies are in a non loading state. *\n */\n private onVariableUpdatesCompleted() {\n if (this.isQueryModeAuto()) {\n this.runQueries();\n }\n }\n\n /**\n * Check if value changed is a adhoc filter o group by variable that did not exist when we issued the last query\n */\n private onAnyVariableChanged(variable: SceneVariable) {\n // If this variable has already been detected this variable as a dependency onVariableUpdatesCompleted above will handle value changes\n if (this._adhocFiltersVar === variable || this._groupByVar === variable || !this.isQueryModeAuto()) {\n return;\n }\n\n if (variable instanceof AdHocFiltersVariable && this._isRelevantAutoVariable(variable)) {\n this.runQueries();\n }\n\n if (variable instanceof GroupByVariable && this._isRelevantAutoVariable(variable)) {\n this.runQueries();\n }\n }\n\n private _isRelevantAutoVariable(variable: AdHocFiltersVariable | GroupByVariable) {\n const datasource = this.state.datasource ?? findFirstDatasource(this.state.queries);\n return variable.state.applyMode === 'auto' && datasource?.uid === variable.state.datasource?.uid;\n }\n\n private shouldRunQueriesOnActivate() {\n if (this._variableValueRecorder.hasDependenciesChanged(this)) {\n writeSceneLog(\n 'SceneQueryRunner',\n 'Variable dependency changed while inactive, shouldRunQueriesOnActivate returns true'\n );\n return true;\n }\n\n // If we don't have any data we should run queries\n if (!this.state.data) {\n return true;\n }\n\n // If time range is stale / different we should run queries\n if (this._isDataTimeRangeStale(this.state.data)) {\n return true;\n }\n\n return false;\n }\n\n private _isDataTimeRangeStale(data: PanelData) {\n const timeRange = sceneGraph.getTimeRange(this);\n\n const stateTimeRange = timeRange.state.value;\n const dataTimeRange = data.timeRange;\n\n if (\n stateTimeRange.from.unix() === dataTimeRange.from.unix() &&\n stateTimeRange.to.unix() === dataTimeRange.to.unix()\n ) {\n return false;\n }\n writeSceneLog('SceneQueryRunner', 'Data time range is stale');\n return true;\n }\n\n private _onDeactivate(): void {\n if (this._querySub) {\n this._querySub.unsubscribe();\n this._querySub = undefined;\n }\n\n if (this._dataLayersSub) {\n this._dataLayersSub.unsubscribe();\n this._dataLayersSub = undefined;\n }\n\n this._timeSub?.unsubscribe();\n this._timeSub = undefined;\n this._timeSubRange = undefined;\n this._adhocFiltersVar = undefined;\n this._groupByVar = undefined;\n this._variableValueRecorder.recordCurrentDependencyValuesForSceneObject(this);\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.state._hasFetchedData) {\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 isDataReadyToDisplay() {\n return Boolean(this.state._hasFetchedData);\n }\n\n private subscribeToTimeRangeChanges(timeRange: SceneTimeRangeLike) {\n if (this._timeSubRange === timeRange) {\n // Nothing to do, already subscribed\n return;\n }\n\n if (this._timeSub) {\n this._timeSub.unsubscribe();\n }\n\n this._timeSubRange = timeRange;\n this._timeSub = timeRange.subscribeToState(() => {\n this.runWithTimeRange(timeRange);\n });\n }\n\n public runQueries() {\n const timeRange = sceneGraph.getTimeRange(this);\n if (this.isQueryModeAuto()) {\n this.subscribeToTimeRangeChanges(timeRange);\n }\n\n this.runWithTimeRange(timeRange);\n }\n\n private getMaxDataPoints() {\n if (this.state.maxDataPoints) {\n return this.state.maxDataPoints;\n }\n\n return this.state.maxDataPointsFromWidth ? this._containerWidth ?? 500 : 500;\n }\n\n public cancelQuery() {\n this._querySub?.unsubscribe();\n\n if (this._dataLayersSub) {\n this._dataLayersSub.unsubscribe();\n this._dataLayersSub = undefined;\n }\n\n this.setState({\n data: { ...this.state.data!, state: LoadingState.Done },\n });\n }\n\n private async runWithTimeRange(timeRange: SceneTimeRangeLike) {\n // If no maxDataPoints specified we might need to wait for container width to be set from the outside\n if (!this.state.maxDataPoints && this.state.maxDataPointsFromWidth && !this._containerWidth) {\n return;\n }\n\n // If data layers subscription doesn't exist, create one\n if (!this._dataLayersSub) {\n this._handleDataLayers();\n }\n\n // Cancel any running queries\n this._querySub?.unsubscribe();\n\n // Skip executing queries if variable dependency is in loading state\n if (this._variableDependency.hasDependencyInLoadingState()) {\n writeSceneLog('SceneQueryRunner', 'Variable dependency is in loading state, skipping query execution');\n this.setState({ data: { ...(this.state.data ?? emptyPanelData), state: LoadingState.Loading } });\n return;\n }\n\n const { queries } = this.state;\n\n // Simple path when no queries exist\n if (!queries?.length) {\n this._setNoDataState();\n return;\n }\n\n try {\n const datasource = this.state.datasource ?? findFirstDatasource(queries);\n const ds = await getDataSource(datasource, this._scopedVars);\n\n this.findAndSubscribeToAdHocFilters(datasource?.uid);\n\n const runRequest = getRunRequest();\n const { primary, secondaries, processors } = this.prepareRequests(timeRange, ds);\n\n writeSceneLog('SceneQueryRunner', 'Starting runRequest', this.state.key);\n\n let stream = runRequest(ds, primary);\n\n if (secondaries.length > 0) {\n // Submit all secondary requests in parallel.\n const secondaryStreams = secondaries.map((r) => runRequest(ds, r));\n // Create the rxjs operator which will combine the primary and secondary responses\n // by calling the correct processor functions provided by the\n // extra request providers.\n const op = extraQueryProcessingOperator(processors);\n // Combine the primary and secondary streams into a single stream, and apply the operator.\n stream = forkJoin([stream, ...secondaryStreams]).pipe(op);\n }\n\n stream = stream.pipe(\n registerQueryWithController({\n type: 'data',\n request: primary,\n origin: this,\n cancel: () => this.cancelQuery(),\n })\n );\n\n this._querySub = stream.subscribe(this.onDataReceived);\n } catch (err) {\n console.error('PanelQueryRunner Error', err);\n\n this.onDataReceived({\n ...emptyPanelData,\n ...this.state.data,\n state: LoadingState.Error,\n errors: [toDataQueryError(err)],\n });\n }\n }\n\n public clone(withState?: Partial<QueryRunnerState>) {\n const clone = super.clone(withState);\n\n if (this._resultAnnotations) {\n clone['_resultAnnotations'] = this._resultAnnotations.map((frame) => ({ ...frame }));\n }\n\n if (this._layerAnnotations) {\n clone['_layerAnnotations'] = this._layerAnnotations.map((frame) => ({ ...frame }));\n }\n\n clone['_variableValueRecorder'] = this._variableValueRecorder.cloneAndRecordCurrentValuesForSceneObject(this);\n clone['_containerWidth'] = this._containerWidth;\n clone['_results'].next({ origin: this, data: this.state.data ?? emptyPanelData });\n\n return clone;\n }\n\n private prepareRequests(timeRange: SceneTimeRangeLike, ds: DataSourceApi): PreparedRequests {\n const { minInterval, queries } = this.state;\n\n let request: DataQueryRequest<DataQueryExtended> = {\n app: 'scenes',\n requestId: getNextRequestId(),\n timezone: timeRange.getTimeZone(),\n range: timeRange.state.value,\n interval: '1s',\n intervalMs: 1000,\n targets: cloneDeep(queries),\n maxDataPoints: this.getMaxDataPoints(),\n scopedVars: this._scopedVars,\n startTime: Date.now(),\n liveStreaming: this.state.liveStreaming,\n rangeRaw: {\n from: timeRange.state.from,\n to: timeRange.state.to,\n },\n cacheTimeout: this.state.cacheTimeout,\n queryCachingTTL: this.state.queryCachingTTL,\n // This asks the scene root to provide context properties like app, panel and dashboardUID\n ...getEnrichedDataRequest(this),\n };\n\n if (this._adhocFiltersVar) {\n // only pass filters that have both key and value\n // @ts-ignore (Temporary ignore until we update @grafana/data)\n request.filters = this._adhocFiltersVar.state.filters.filter(isFilterComplete);\n }\n\n if (this._groupByVar) {\n // @ts-ignore (Temporary ignore until we update @grafana/data)\n request.groupByKeys = this._groupByVar.state.value;\n }\n\n request.targets = request.targets.map((query) => {\n if (\n !query.datasource ||\n (query.datasource.uid !== ds.uid &&\n !ds.meta?.mixed &&\n isExpressionReference /* TODO: Remove this check when isExpressionReference is properly exported from grafan runtime */ &&\n !isExpressionReference(query.datasource))\n ) {\n query.datasource = ds.getRef();\n }\n return query;\n });\n\n const lowerIntervalLimit = minInterval ? interpolate(this, minInterval) : ds.interval;\n const norm = rangeUtil.calculateInterval(timeRange.state.value, 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 // If there are any extra request providers, we need to add a new request for each\n // and map the request's ID to the processor function given by the provider, to ensure that\n // the processor is called with the correct response data.\n const primaryTimeRange = timeRange.state.value;\n let secondaryRequests: DataQueryRequest[] = [];\n let secondaryProcessors = new Map();\n for (const provider of this.getClosestExtraQueryProviders() ?? []) {\n for (const { req, processor } of provider.getExtraQueries(request)) {\n const requestId = getNextRequestId();\n secondaryRequests.push({ ...req, requestId });\n secondaryProcessors.set(requestId, processor ?? passthroughProcessor);\n }\n }\n request.range = primaryTimeRange;\n return { primary: request, secondaries: secondaryRequests, processors: secondaryProcessors };\n }\n\n private onDataReceived = (data: PanelData) => {\n // Will combine annotations from SQR queries (frames with meta.dataTopic === DataTopic.Annotations)\n const preProcessedData = preProcessPanelData(data, this.state.data);\n\n // Save query annotations\n this._resultAnnotations = data.annotations;\n\n // Will combine annotations & alert state from data layer providers\n const dataWithLayersApplied = this._combineDataLayers(preProcessedData);\n\n let hasFetchedData = this.state._hasFetchedData;\n\n if (!hasFetchedData && preProcessedData.state !== LoadingState.Loading) {\n hasFetchedData = true;\n }\n\n this.setState({ data: dataWithLayersApplied, _hasFetchedData: hasFetchedData });\n this._results.next({ origin: this, data: dataWithLayersApplied });\n };\n\n private _combineDataLayers(data: PanelData) {\n if (this._layerAnnotations && this._layerAnnotations.length > 0) {\n data.annotations = (data.annotations || []).concat(this._layerAnnotations);\n }\n\n if (this.state.data && this.state.data.alertState) {\n data.alertState = this.state.data.alertState;\n }\n\n return data;\n }\n\n private _setNoDataState() {\n if (this.state.data !== emptyPanelData) {\n this.setState({ data: emptyPanelData });\n }\n }\n\n /**\n * Walk up the scene graph and find any ExtraQueryProviders.\n *\n * This will return an array of the closest provider of each type.\n */\n private getClosestExtraQueryProviders(): Array<ExtraQueryProvider<any>> {\n // Maintain a map from provider constructor to provider object. The constructor\n // is used as a unique key for each class, to ensure we have no more than one\n // type of each type of provider.\n const found = new Map();\n if (!this.parent) {\n return [];\n }\n getClosest(this.parent, (s) => {\n if (isExtraQueryProvider(s) && !found.has(s.constructor)) {\n found.set(s.constructor, s);\n }\n s.forEachChild((child) => {\n if (isExtraQueryProvider(child) && !found.has(child.constructor)) {\n found.set(child.constructor, child);\n }\n });\n // Always return null so that the search continues to the top of\n // the scene graph.\n return null;\n });\n return Array.from(found.values());\n }\n\n /**\n * Walk up scene graph and find the closest filterset with matching data source\n */\n private findAndSubscribeToAdHocFilters(uid: string | undefined) {\n const filtersVar = findActiveAdHocFilterVariableByUid(uid);\n\n if (this._adhocFiltersVar !== filtersVar) {\n this._adhocFiltersVar = filtersVar;\n this._updateExplicitVariableDependencies();\n }\n\n const groupByVar = findActiveGroupByVariablesByUid(uid);\n if (this._groupByVar !== groupByVar) {\n this._groupByVar = groupByVar;\n this._updateExplicitVariableDependencies();\n }\n }\n\n private _updateExplicitVariableDependencies() {\n const explicitDependencies: string[] = [];\n\n if (this._adhocFiltersVar) {\n explicitDependencies.push(this._adhocFiltersVar.state.name);\n }\n\n if (this._groupByVar) {\n explicitDependencies.push(this._groupByVar.state.name);\n }\n\n this._variableDependency.setVariableNames(explicitDependencies);\n }\n\n private isQueryModeAuto(): boolean {\n return (this.state.runQueriesMode ?? 'auto') === 'auto';\n }\n}\n\nexport function findFirstDatasource(targets: DataQuery[]): DataSourceRef | undefined {\n return targets.find((t) => t.datasource !== null)?.datasource ?? undefined;\n}\n\nfunction allFramesEmpty(frames?: DataFrame[]) {\n if (!frames) {\n return true;\n }\n\n for (let i = 0; i < frames.length; i++) {\n if (frames[i].length > 0) {\n return false;\n }\n }\n\n return true;\n}\n"],"names":["_a"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAmDA,IAAI,OAAU,GAAA,GAAA,CAAA;AAEP,SAAS,gBAAmB,GAAA;AACjC,EAAA,OAAO,KAAQ,GAAA,OAAA,EAAA,CAAA;AACjB,CAAA;AAoDO,MAAM,yBAAyB,eAA+D,CAAA;AAAA,EA0B5F,YAAY,YAAgC,EAAA;AACjD,IAAA,KAAA,CAAM,YAAY,CAAA,CAAA;AAxBpB,IAAQ,IAAA,CAAA,iBAAA,GAAoB,IAAI,gBAAiB,EAAA,CAAA;A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CAAA,GAAA,EAAA,CAAA,UAAA,KAA5C,IAA0D,GAAA,EAAA,GAAA,KAAA,CAAA,CAAA;AACnE,CAAA;AAEA,SAAS,eAAe,MAAsB,EAAA;AAC5C,EAAA,IAAI,CAAC,MAAQ,EAAA;AACX,IAAO,OAAA,IAAA,CAAA;AAAA,GACT;AAEA,EAAA,KAAA,IAAS,CAAI,GAAA,CAAA,EAAG,CAAI,GAAA,MAAA,CAAO,QAAQ,CAAK,EAAA,EAAA;AACtC,IAAI,IAAA,MAAA,CAAO,CAAG,CAAA,CAAA,MAAA,GAAS,CAAG,EAAA;AACxB,MAAO,OAAA,KAAA,CAAA;AAAA,KACT;AAAA,GACF;AAEA,EAAO,OAAA,IAAA,CAAA;AACT;;;;"}
1
+ {"version":3,"file":"SceneQueryRunner.js","sources":["../../../src/querying/SceneQueryRunner.ts"],"sourcesContent":["import { cloneDeep, isEqual } from 'lodash';\nimport { forkJoin, ReplaySubject, Unsubscribable } from 'rxjs';\n\nimport { DataQuery, DataSourceRef, LoadingState } from '@grafana/schema';\n\nimport {\n AlertStateInfo,\n DataFrame,\n DataFrameView,\n DataQueryRequest,\n DataSourceApi,\n DataTopic,\n PanelData,\n preProcessPanelData,\n rangeUtil,\n} from '@grafana/data';\n\n// TODO: Remove this ignore annotation when the grafana runtime dependency has been updated\n// @ts-ignore\nimport { getRunRequest, toDataQueryError, isExpressionReference, config } from '@grafana/runtime';\n\nimport { SceneObjectBase } from '../core/SceneObjectBase';\nimport { sceneGraph } from '../core/sceneGraph';\nimport {\n DataLayerFilter,\n SceneDataProvider,\n SceneDataProviderResult,\n SceneDataQuery,\n SceneObjectState,\n SceneTimeRangeLike,\n} from '../core/types';\nimport { getDataSource } from '../utils/getDataSource';\nimport { VariableDependencyConfig } from '../variables/VariableDependencyConfig';\nimport { writeSceneLog } from '../utils/writeSceneLog';\nimport { VariableValueRecorder } from '../variables/VariableValueRecorder';\nimport { emptyPanelData } from '../core/SceneDataNode';\nimport { getClosest } from '../core/sceneGraph/utils';\nimport { isExtraQueryProvider, ExtraQueryDataProcessor, ExtraQueryProvider } from './ExtraQueryProvider';\nimport { passthroughProcessor, extraQueryProcessingOperator } from './extraQueryProcessingOperator';\nimport { filterAnnotations } from './layers/annotations/filterAnnotations';\nimport { getEnrichedDataRequest } from './getEnrichedDataRequest';\nimport { findActiveAdHocFilterVariableByUid } from '../variables/adhoc/patchGetAdhocFilters';\nimport { registerQueryWithController } from './registerQueryWithController';\nimport { findActiveGroupByVariablesByUid } from '../variables/groupby/findActiveGroupByVariablesByUid';\nimport { GroupByVariable } from '../variables/groupby/GroupByVariable';\nimport { AdHocFiltersVariable, isFilterComplete } from '../variables/adhoc/AdHocFiltersVariable';\nimport { SceneVariable } from '../variables/types';\nimport { DataLayersMerger } from './DataLayersMerger';\nimport { interpolate } from '../core/sceneGraph/sceneGraph';\nimport { wrapInSafeSerializableSceneObject } from '../utils/wrapInSafeSerializableSceneObject';\n\nlet counter = 100;\n\nexport function getNextRequestId() {\n return 'SQR' + counter++;\n}\n\nexport interface QueryRunnerState extends SceneObjectState {\n data?: PanelData;\n queries: SceneDataQuery[];\n datasource?: DataSourceRef;\n minInterval?: string;\n maxDataPoints?: number;\n liveStreaming?: boolean;\n maxDataPointsFromWidth?: boolean;\n cacheTimeout?: DataQueryRequest['cacheTimeout'];\n queryCachingTTL?: DataQueryRequest['queryCachingTTL'];\n /**\n * When set to auto (the default) query runner will issue queries on activate (when variable dependencies are ready) or when time range change.\n * Set to manual to have full manual control over when queries are issued. Try not to set this. This is mainly useful for unit tests, or special edge case workflows.\n */\n runQueriesMode?: 'auto' | 'manual';\n // Filters to be applied to data layer results before combining them with SQR results\n dataLayerFilter?: DataLayerFilter;\n // Private runtime state\n _hasFetchedData?: boolean;\n}\n\nexport interface DataQueryExtended extends DataQuery {\n [key: string]: any;\n\n // Opt this query out of time window comparison\n timeRangeCompare?: boolean;\n}\n\n// The requests that will be run by the query runner.\n//\n// Generally the query runner will run a single primary request.\n// If the scene graph contains implementations of\n// `ExtraQueryProvider`, the requests created by these\n// implementations will be added to the list of secondary requests,\n// and these will be executed at the same time as the primary request.\n//\n// The results of each secondary request will be passed to an associated\n// processor function (along with the results of the primary request),\n// which can transform the results as desired.\ninterface PreparedRequests {\n // The primary request to run.\n primary: DataQueryRequest;\n // A possibly empty list of secondary requests to run alongside\n // the primary request.\n secondaries: DataQueryRequest[];\n // A map from `requestId` of secondary requests to processors\n // for those requests. Provided by the `ExtraQueryProvider`.\n processors: Map<string, ExtraQueryDataProcessor>;\n}\n\nexport class SceneQueryRunner extends SceneObjectBase<QueryRunnerState> implements SceneDataProvider {\n private _querySub?: Unsubscribable;\n private _dataLayersSub?: Unsubscribable;\n private _dataLayersMerger = new DataLayersMerger();\n private _timeSub?: Unsubscribable;\n private _timeSubRange?: SceneTimeRangeLike;\n private _containerWidth?: number;\n private _variableValueRecorder = new VariableValueRecorder();\n private _results = new ReplaySubject<SceneDataProviderResult>(1);\n private _scopedVars = { __sceneObject: wrapInSafeSerializableSceneObject(this) };\n private _layerAnnotations?: DataFrame[];\n private _resultAnnotations?: DataFrame[];\n\n private _adhocFiltersVar?: AdHocFiltersVariable;\n private _groupByVar?: GroupByVariable;\n\n public getResultsStream() {\n return this._results;\n }\n\n protected _variableDependency: VariableDependencyConfig<QueryRunnerState> = new VariableDependencyConfig(this, {\n statePaths: ['queries', 'datasource'],\n onVariableUpdateCompleted: this.onVariableUpdatesCompleted.bind(this),\n onAnyVariableChanged: this.onAnyVariableChanged.bind(this),\n });\n\n public constructor(initialState: QueryRunnerState) {\n super(initialState);\n\n this.addActivationHandler(() => this._onActivate());\n }\n\n private _onActivate() {\n if (this.isQueryModeAuto()) {\n const timeRange = sceneGraph.getTimeRange(this);\n\n // Add subscriptions to any extra providers so that they rerun queries\n // when their state changes and they should rerun.\n const providers = this.getClosestExtraQueryProviders();\n for (const provider of providers) {\n this._subs.add(\n provider.subscribeToState((n, p) => {\n if (provider.shouldRerun(p, n, this.state.queries)) {\n this.runQueries();\n }\n }),\n );\n }\n\n this.subscribeToTimeRangeChanges(\n timeRange,\n );\n\n if (this.shouldRunQueriesOnActivate()) {\n this.runQueries();\n }\n }\n\n if (!this._dataLayersSub) {\n this._handleDataLayers();\n }\n\n return () => this._onDeactivate();\n }\n\n // This method subscribes to all SceneDataLayers up until the root, and combines the results into data provided from SceneQueryRunner\n private _handleDataLayers() {\n const dataLayers = sceneGraph.getDataLayers(this);\n\n if (dataLayers.length === 0) {\n return;\n }\n\n this._dataLayersSub = this._dataLayersMerger\n .getMergedStream(dataLayers)\n .subscribe(this._onLayersReceived.bind(this));\n }\n\n private _onLayersReceived(results: Iterable<SceneDataProviderResult>) {\n const timeRange = sceneGraph.getTimeRange(this);\n const { dataLayerFilter } = this.state;\n\n let annotations: DataFrame[] = [];\n let alertStates: DataFrame[] = [];\n let alertState: AlertStateInfo | undefined;\n\n for (const result of results) {\n for (let frame of result.data.series) {\n if (frame.meta?.dataTopic === DataTopic.Annotations) {\n annotations = annotations.concat(frame);\n }\n if (frame.meta?.dataTopic === DataTopic.AlertStates) {\n alertStates = alertStates.concat(frame);\n }\n }\n }\n\n if (dataLayerFilter?.panelId) {\n if (annotations.length > 0) {\n annotations = filterAnnotations(annotations, dataLayerFilter);\n }\n\n if (alertStates.length > 0) {\n for (const frame of alertStates) {\n const frameView = new DataFrameView<AlertStateInfo>(frame);\n\n for (const row of frameView) {\n if (row.panelId === dataLayerFilter.panelId) {\n alertState = row;\n break;\n }\n }\n }\n }\n }\n\n // Skip unnessary state updates\n if (\n allFramesEmpty(annotations) &&\n allFramesEmpty(this._layerAnnotations) &&\n isEqual(alertState, this.state.data?.alertState)\n ) {\n return;\n }\n\n this._layerAnnotations = annotations;\n\n const baseStateUpdate = this.state.data ? this.state.data : { ...emptyPanelData, timeRange: timeRange.state.value };\n\n this.setState({\n data: {\n ...baseStateUpdate,\n annotations: [...(this._resultAnnotations ?? []), ...annotations],\n alertState: alertState ?? this.state.data?.alertState,\n },\n });\n }\n\n /**\n * This tries to start a new query whenever a variable completes or is changed.\n *\n * We care about variable update completions even when the variable has not changed and even when it is not a direct dependency.\n * Example: Variables A and B (B depends on A). A update depends on time range. So when time change query runner will\n * find that variable A is loading which is a dependency on of variable B so will set _isWaitingForVariables to true and\n * not issue any query.\n *\n * When A completes it's loading (with no value change, so B never updates) it will cause a call of this function letting\n * the query runner know that A has completed, and in case _isWaitingForVariables we try to run the query. The query will\n * only run if all variables are in a non loading state so in other scenarios where a query depends on many variables this will\n * be called many times until all dependencies are in a non loading state. *\n */\n private onVariableUpdatesCompleted() {\n if(this.isQueryModeAuto()){\n this.runQueries();\n }\n }\n\n /**\n * Check if value changed is a adhoc filter o group by variable that did not exist when we issued the last query\n */\n private onAnyVariableChanged(variable: SceneVariable) {\n // If this variable has already been detected this variable as a dependency onVariableUpdatesCompleted above will handle value changes\n if (this._adhocFiltersVar === variable || this._groupByVar === variable || !this.isQueryModeAuto()) {\n return;\n }\n\n if (variable instanceof AdHocFiltersVariable && this._isRelevantAutoVariable(variable)) {\n this.runQueries();\n }\n\n if (variable instanceof GroupByVariable && this._isRelevantAutoVariable(variable)) {\n this.runQueries();\n }\n }\n\n private _isRelevantAutoVariable(variable: AdHocFiltersVariable | GroupByVariable) {\n const datasource = this.state.datasource ?? findFirstDatasource(this.state.queries);\n return variable.state.applyMode === 'auto' && datasource?.uid === variable.state.datasource?.uid;\n }\n\n private shouldRunQueriesOnActivate() {\n if (this._variableValueRecorder.hasDependenciesChanged(this)) {\n writeSceneLog(\n 'SceneQueryRunner',\n 'Variable dependency changed while inactive, shouldRunQueriesOnActivate returns true'\n );\n return true;\n }\n\n // If we don't have any data we should run queries\n if (!this.state.data) {\n return true;\n }\n\n // If time range is stale / different we should run queries\n if (this._isDataTimeRangeStale(this.state.data)) {\n return true;\n }\n\n return false;\n }\n\n private _isDataTimeRangeStale(data: PanelData) {\n const timeRange = sceneGraph.getTimeRange(this);\n\n const stateTimeRange = timeRange.state.value;\n const dataTimeRange = data.timeRange;\n\n if (\n stateTimeRange.from.unix() === dataTimeRange.from.unix() &&\n stateTimeRange.to.unix() === dataTimeRange.to.unix()\n ) {\n return false;\n }\n writeSceneLog('SceneQueryRunner', 'Data time range is stale');\n return true;\n }\n\n private _onDeactivate(): void {\n if (this._querySub) {\n this._querySub.unsubscribe();\n this._querySub = undefined;\n }\n\n if (this._dataLayersSub) {\n this._dataLayersSub.unsubscribe();\n this._dataLayersSub = undefined;\n }\n\n this._timeSub?.unsubscribe();\n this._timeSub = undefined;\n this._timeSubRange = undefined;\n this._adhocFiltersVar = undefined;\n this._groupByVar = undefined;\n this._variableValueRecorder.recordCurrentDependencyValuesForSceneObject(this);\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.state._hasFetchedData) {\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 isDataReadyToDisplay() {\n return Boolean(this.state._hasFetchedData);\n }\n\n private subscribeToTimeRangeChanges(timeRange: SceneTimeRangeLike) {\n if (this._timeSubRange === timeRange) {\n // Nothing to do, already subscribed\n return;\n }\n\n if (this._timeSub) {\n this._timeSub.unsubscribe();\n }\n\n this._timeSubRange = timeRange;\n this._timeSub = timeRange.subscribeToState(() => {\n this.runWithTimeRange(timeRange);\n });\n }\n\n public runQueries() {\n const timeRange = sceneGraph.getTimeRange(this);\n if(this.isQueryModeAuto()){\n this.subscribeToTimeRangeChanges(timeRange);\n }\n\n this.runWithTimeRange(timeRange);\n }\n\n private getMaxDataPoints() {\n if (this.state.maxDataPoints) {\n return this.state.maxDataPoints;\n }\n\n return this.state.maxDataPointsFromWidth ? this._containerWidth ?? 500 : 500;\n }\n\n public cancelQuery() {\n this._querySub?.unsubscribe();\n\n if (this._dataLayersSub) {\n this._dataLayersSub.unsubscribe();\n this._dataLayersSub = undefined;\n }\n\n this.setState({\n data: { ...this.state.data!, state: LoadingState.Done },\n });\n }\n\n private async runWithTimeRange(timeRange: SceneTimeRangeLike) {\n // If no maxDataPoints specified we might need to wait for container width to be set from the outside\n if (!this.state.maxDataPoints && this.state.maxDataPointsFromWidth && !this._containerWidth) {\n return;\n }\n\n // If data layers subscription doesn't exist, create one\n if (!this._dataLayersSub) {\n this._handleDataLayers();\n }\n\n // Cancel any running queries\n this._querySub?.unsubscribe();\n\n // Skip executing queries if variable dependency is in loading state\n if (this._variableDependency.hasDependencyInLoadingState()) {\n writeSceneLog('SceneQueryRunner', 'Variable dependency is in loading state, skipping query execution');\n this.setState({ data: { ...(this.state.data ?? emptyPanelData), state: LoadingState.Loading } });\n return;\n }\n\n const { queries } = this.state;\n\n // Simple path when no queries exist\n if (!queries?.length) {\n this._setNoDataState();\n return;\n }\n\n try {\n const datasource = this.state.datasource ?? findFirstDatasource(queries);\n const ds = await getDataSource(datasource, this._scopedVars);\n\n this.findAndSubscribeToAdHocFilters(datasource?.uid);\n\n const runRequest = getRunRequest();\n const { primary, secondaries, processors } = this.prepareRequests(timeRange, ds);\n\n writeSceneLog('SceneQueryRunner', 'Starting runRequest', this.state.key);\n\n let stream = runRequest(ds, primary);\n\n if (secondaries.length > 0) {\n // Submit all secondary requests in parallel.\n const secondaryStreams = secondaries.map((r) => runRequest(ds, r));\n // Create the rxjs operator which will combine the primary and secondary responses\n // by calling the correct processor functions provided by the\n // extra request providers.\n const op = extraQueryProcessingOperator(processors);\n // Combine the primary and secondary streams into a single stream, and apply the operator.\n stream = forkJoin([stream, ...secondaryStreams]).pipe(op);\n }\n\n stream = stream.pipe(\n registerQueryWithController({\n type: 'data',\n request: primary,\n origin: this,\n cancel: () => this.cancelQuery(),\n })\n );\n\n this._querySub = stream.subscribe(this.onDataReceived);\n } catch (err) {\n console.error('PanelQueryRunner Error', err);\n\n this.onDataReceived({\n ...emptyPanelData,\n ...this.state.data,\n state: LoadingState.Error,\n errors: [toDataQueryError(err)],\n });\n }\n }\n\n public clone(withState?: Partial<QueryRunnerState>) {\n const clone = super.clone(withState);\n\n if (this._resultAnnotations) {\n clone['_resultAnnotations'] = this._resultAnnotations.map((frame) => ({ ...frame }));\n }\n\n if (this._layerAnnotations) {\n clone['_layerAnnotations'] = this._layerAnnotations.map((frame) => ({ ...frame }));\n }\n\n clone['_variableValueRecorder'] = this._variableValueRecorder.cloneAndRecordCurrentValuesForSceneObject(this);\n clone['_containerWidth'] = this._containerWidth;\n clone['_results'].next({ origin: this, data: this.state.data ?? emptyPanelData });\n\n return clone;\n }\n\n private prepareRequests(timeRange: SceneTimeRangeLike, ds: DataSourceApi): PreparedRequests {\n const { minInterval, queries } = this.state;\n\n let request: DataQueryRequest<DataQueryExtended> = {\n app: 'scenes',\n requestId: getNextRequestId(),\n timezone: timeRange.getTimeZone(),\n range: timeRange.state.value,\n interval: '1s',\n intervalMs: 1000,\n targets: cloneDeep(queries),\n maxDataPoints: this.getMaxDataPoints(),\n scopedVars: this._scopedVars,\n startTime: Date.now(),\n liveStreaming: this.state.liveStreaming,\n rangeRaw: {\n from: timeRange.state.from,\n to: timeRange.state.to,\n },\n cacheTimeout: this.state.cacheTimeout,\n queryCachingTTL: this.state.queryCachingTTL,\n // This asks the scene root to provide context properties like app, panel and dashboardUID\n ...getEnrichedDataRequest(this),\n };\n\n if (this._adhocFiltersVar) {\n // only pass filters that have both key and value\n // @ts-ignore (Temporary ignore until we update @grafana/data)\n request.filters = this._adhocFiltersVar.state.filters.filter(isFilterComplete);\n }\n\n if (this._groupByVar) {\n // @ts-ignore (Temporary ignore until we update @grafana/data)\n request.groupByKeys = this._groupByVar.state.value;\n }\n\n request.targets = request.targets.map((query) => {\n if (\n !query.datasource ||\n (query.datasource.uid !== ds.uid &&\n !ds.meta?.mixed &&\n isExpressionReference /* TODO: Remove this check when isExpressionReference is properly exported from grafan runtime */ &&\n !isExpressionReference(query.datasource))\n ) {\n query.datasource = ds.getRef();\n }\n return query;\n });\n\n const lowerIntervalLimit = minInterval ? interpolate(this, minInterval) : ds.interval;\n const norm = rangeUtil.calculateInterval(timeRange.state.value, 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 // If there are any extra request providers, we need to add a new request for each\n // and map the request's ID to the processor function given by the provider, to ensure that\n // the processor is called with the correct response data.\n const primaryTimeRange = timeRange.state.value;\n let secondaryRequests: DataQueryRequest[] = [];\n let secondaryProcessors = new Map();\n for (const provider of this.getClosestExtraQueryProviders() ?? []) {\n for (const { req, processor } of provider.getExtraQueries(request)) {\n const requestId = getNextRequestId();\n secondaryRequests.push({ ...req, requestId });\n secondaryProcessors.set(requestId, processor ?? passthroughProcessor);\n }\n }\n request.range = primaryTimeRange;\n return { primary: request, secondaries: secondaryRequests, processors: secondaryProcessors };\n }\n\n private onDataReceived = (data: PanelData) => {\n // Will combine annotations from SQR queries (frames with meta.dataTopic === DataTopic.Annotations)\n const preProcessedData = preProcessPanelData(data, this.state.data);\n\n // Save query annotations\n this._resultAnnotations = data.annotations;\n\n // Will combine annotations & alert state from data layer providers\n const dataWithLayersApplied = this._combineDataLayers(preProcessedData);\n\n let hasFetchedData = this.state._hasFetchedData;\n\n if (!hasFetchedData && preProcessedData.state !== LoadingState.Loading) {\n hasFetchedData = true;\n }\n\n this.setState({ data: dataWithLayersApplied, _hasFetchedData: hasFetchedData });\n this._results.next({ origin: this, data: dataWithLayersApplied });\n };\n\n private _combineDataLayers(data: PanelData) {\n if (this._layerAnnotations && this._layerAnnotations.length > 0) {\n data.annotations = (data.annotations || []).concat(this._layerAnnotations);\n }\n\n if (this.state.data && this.state.data.alertState) {\n data.alertState = this.state.data.alertState;\n }\n\n return data;\n }\n\n private _setNoDataState() {\n if (this.state.data !== emptyPanelData) {\n this.setState({ data: emptyPanelData });\n }\n }\n\n /**\n * Walk up the scene graph and find any ExtraQueryProviders.\n *\n * This will return an array of the closest provider of each type.\n */\n private getClosestExtraQueryProviders(): Array<ExtraQueryProvider<any>> {\n // Maintain a map from provider constructor to provider object. The constructor\n // is used as a unique key for each class, to ensure we have no more than one\n // type of each type of provider.\n const found = new Map();\n if (!this.parent) {\n return [];\n }\n getClosest(this.parent, (s) => {\n if (isExtraQueryProvider(s) && !found.has(s.constructor)) {\n found.set(s.constructor, s);\n }\n s.forEachChild((child) => {\n if (isExtraQueryProvider(child) && !found.has(child.constructor)) {\n found.set(child.constructor, child);\n }\n });\n // Always return null so that the search continues to the top of\n // the scene graph.\n return null;\n });\n return Array.from(found.values());\n }\n\n /**\n * Walk up scene graph and find the closest filterset with matching data source\n */\n private findAndSubscribeToAdHocFilters(uid: string | undefined) {\n const filtersVar = findActiveAdHocFilterVariableByUid(uid);\n\n if (this._adhocFiltersVar !== filtersVar) {\n this._adhocFiltersVar = filtersVar;\n this._updateExplicitVariableDependencies();\n }\n\n const groupByVar = findActiveGroupByVariablesByUid(uid);\n if (this._groupByVar !== groupByVar) {\n this._groupByVar = groupByVar;\n this._updateExplicitVariableDependencies();\n }\n }\n\n private _updateExplicitVariableDependencies() {\n const explicitDependencies: string[] = [];\n\n if (this._adhocFiltersVar) {\n explicitDependencies.push(this._adhocFiltersVar.state.name);\n }\n\n if (this._groupByVar) {\n explicitDependencies.push(this._groupByVar.state.name);\n }\n\n this._variableDependency.setVariableNames(explicitDependencies);\n }\n\n private isQueryModeAuto(): boolean {\n return (this.state.runQueriesMode ?? 'auto') === 'auto'\n }\n}\n\nexport function findFirstDatasource(targets: DataQuery[]): DataSourceRef | undefined {\n return targets.find((t) => t.datasource !== null)?.datasource ?? undefined;\n}\n\nfunction allFramesEmpty(frames?: DataFrame[]) {\n if (!frames) {\n return true;\n }\n\n for (let i = 0; i < frames.length; i++) {\n if (frames[i].length > 0) {\n return false;\n }\n }\n\n return true;\n}\n"],"names":["_a"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAmDA,IAAI,OAAU,GAAA,GAAA,CAAA;AAEP,SAAS,gBAAmB,GAAA;AACjC,EAAA,OAAO,KAAQ,GAAA,OAAA,EAAA,CAAA;AACjB,CAAA;AAoDO,MAAM,yBAAyB,eAA+D,CAAA;AAAA,EA0B5F,YAAY,YAAgC,EAAA;AACjD,IAAA,KAAA,CAAM,YAAY,CAAA,CAAA;AAxBpB,IAAQ,IAAA,CAAA,iBAAA,GAAoB,IAAI,gBAAiB,EAAA,CAAA;AAIjD,IAAQ,IAAA,CAAA,sBAAA,GAAyB,IAAI,qBAAsB,EAAA,CAAA;AAC3D,IAAQ,IAAA,CAAA,QAAA,GAAW,IAAI,aAAA,CAAuC,CAAC,CAAA,CAAA;AAC/D,IAAA,IAAA,CAAQ,WAAc,GAAA,EAAE,aAAe,EAAA,iCAAA,CAAkC,IAAI,CAAE,EAAA,CAAA;AAW/E,IAAU,IAAA,CAAA,mBAAA,GAAkE,IAAI,wBAAA,CAAyB,IAAM,EAAA;AAAA,MAC7G,UAAA,EAAY,CAAC,SAAA,EAAW,YAAY,CAAA;AAAA,MACpC,yBAA2B,EAAA,IAAA,CAAK,0BAA2B,CAAA,IAAA,CAAK,IAAI,CAAA;AAAA,MACpE,oBAAsB,EAAA,IAAA,CAAK,oBAAqB,CAAA,IAAA,CAAK,IAAI,CAAA;AAAA,KAC1D,CAAA,CAAA;AAycD,IAAQ,IAAA,CAAA,cAAA,GAAiB,CAAC,IAAoB,KAAA;AAE5C,MAAA,MAAM,gBAAmB,GAAA,mBAAA,CAAoB,IAAM,EAAA,IAAA,CAAK,MAAM,IAAI,CAAA,CAAA;AAGlE,MAAA,IAAA,C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IAAK,IAAA,CAAA,mBAAA,CAAoB,iBAAiB,oBAAoB,CAAA,CAAA;AAAA,GAChE;AAAA,EAEQ,eAA2B,GAAA;AA/qBrC,IAAA,IAAA,EAAA,CAAA;AAgrBI,IAAA,OAAA,CAAA,CAAQ,EAAK,GAAA,IAAA,CAAA,KAAA,CAAM,cAAX,KAAA,IAAA,GAAA,EAAA,GAA6B,MAAY,MAAA,MAAA,CAAA;AAAA,GACnD;AACF,CAAA;AAEO,SAAS,oBAAoB,OAAiD,EAAA;AAprBrF,EAAA,IAAA,EAAA,EAAA,EAAA,CAAA;AAqrBE,EAAO,OAAA,CAAA,EAAA,GAAA,CAAA,EAAA,GAAA,OAAA,CAAQ,IAAK,CAAA,CAAC,CAAM,KAAA,CAAA,CAAE,eAAe,IAAI,CAAA,KAAzC,IAA4C,GAAA,KAAA,CAAA,GAAA,EAAA,CAAA,UAAA,KAA5C,IAA0D,GAAA,EAAA,GAAA,KAAA,CAAA,CAAA;AACnE,CAAA;AAEA,SAAS,eAAe,MAAsB,EAAA;AAC5C,EAAA,IAAI,CAAC,MAAQ,EAAA;AACX,IAAO,OAAA,IAAA,CAAA;AAAA,GACT;AAEA,EAAA,KAAA,IAAS,CAAI,GAAA,CAAA,EAAG,CAAI,GAAA,MAAA,CAAO,QAAQ,CAAK,EAAA,EAAA;AACtC,IAAI,IAAA,MAAA,CAAO,CAAG,CAAA,CAAA,MAAA,GAAS,CAAG,EAAA;AACxB,MAAO,OAAA,KAAA,CAAA;AAAA,KACT;AAAA,GACF;AAEA,EAAO,OAAA,IAAA,CAAA;AACT;;;;"}
@@ -1,4 +1,4 @@
1
- import { Observable, from, map, catchError } from 'rxjs';
1
+ import { Observable } from 'rxjs';
2
2
  import { LoadingState } from '@grafana/schema';
3
3
  import { sceneGraph } from '../core/sceneGraph/index.js';
4
4
 
@@ -36,23 +36,6 @@ function registerQueryWithController(entry) {
36
36
  });
37
37
  };
38
38
  }
39
- function wrapPromiseInStateObservable(promise) {
40
- console.log("wrapPromiseInStateObservable", promise);
41
- return new Observable((observer) => {
42
- observer.next({ state: LoadingState.Loading });
43
- const promiseObservable = from(promise);
44
- promiseObservable.pipe(
45
- map(() => ({ state: LoadingState.Done })),
46
- catchError(() => {
47
- observer.next({ state: LoadingState.Error });
48
- return [];
49
- })
50
- ).subscribe({
51
- next: (result) => observer.next(result),
52
- complete: () => observer.complete()
53
- });
54
- });
55
- }
56
39
 
57
- export { registerQueryWithController, wrapPromiseInStateObservable };
40
+ export { registerQueryWithController };
58
41
  //# sourceMappingURL=registerQueryWithController.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"registerQueryWithController.js","sources":["../../../src/querying/registerQueryWithController.ts"],"sourcesContent":["import { Observable, catchError, from, map } from 'rxjs';\nimport { LoadingState } from '@grafana/schema';\nimport { sceneGraph } from '../core/sceneGraph';\nimport { QueryResultWithState, SceneQueryControllerEntry } from '../behaviors/types';\n\n/**\n * Will look for a scene object with a behavior that is a SceneQueryController and register the query with it.\n */\nexport function registerQueryWithController<T extends QueryResultWithState>(entry: SceneQueryControllerEntry) {\n return (queryStream: Observable<T>) => {\n const queryControler = sceneGraph.getQueryController(entry.origin);\n if (!queryControler) {\n return queryStream;\n }\n\n return new Observable<T>((observer) => {\n if (!entry.cancel) {\n entry.cancel = () => observer.complete();\n }\n\n queryControler.queryStarted(entry);\n let markedAsCompleted = false;\n\n const sub = queryStream.subscribe({\n next: (v) => {\n if (!markedAsCompleted && v.state !== LoadingState.Loading) {\n markedAsCompleted = true;\n queryControler.queryCompleted(entry);\n }\n\n observer.next(v);\n },\n error: (e) => observer.error(e),\n complete: () => {\n observer.complete();\n },\n });\n\n return () => {\n sub.unsubscribe();\n\n if (!markedAsCompleted) {\n queryControler.queryCompleted(entry);\n }\n };\n });\n };\n}\n\n// Wraps an arbitrary Promise in an observble that emits Promise state\nexport function wrapPromiseInStateObservable(promise: Promise<any>): Observable<QueryResultWithState> {\n console.log('wrapPromiseInStateObservable', promise);\n return new Observable<QueryResultWithState>((observer) => {\n // Emit 'loading' state initially\n observer.next({ state: LoadingState.Loading });\n\n // Convert the promise to an observable\n const promiseObservable = from(promise);\n\n // Subscribe to the promise observable\n promiseObservable\n .pipe(\n map(() => ({ state: LoadingState.Done })),\n\n catchError(() => {\n observer.next({ state: LoadingState.Error });\n return [];\n })\n )\n .subscribe({\n next: (result) => observer.next(result),\n complete: () => observer.complete(),\n });\n });\n}\n"],"names":[],"mappings":";;;;AAQO,SAAS,4BAA4D,KAAkC,EAAA;AAC5G,EAAA,OAAO,CAAC,WAA+B,KAAA;AACrC,IAAA,MAAM,cAAiB,GAAA,UAAA,CAAW,kBAAmB,CAAA,KAAA,CAAM,MAAM,CAAA,CAAA;AACjE,IAAA,IAAI,CAAC,cAAgB,EAAA;AACnB,MAAO,OAAA,WAAA,CAAA;AAAA,KACT;AAEA,IAAO,OAAA,IAAI,UAAc,CAAA,CAAC,QAAa,KAAA;AACrC,MAAI,IAAA,CAAC,MAAM,MAAQ,EAAA;AACjB,QAAM,KAAA,CAAA,MAAA,GAAS,MAAM,QAAA,CAAS,QAAS,EAAA,CAAA;AAAA,OACzC;AAEA,MAAA,cAAA,CAAe,aAAa,KAAK,CAAA,CAAA;AACjC,MAAA,IAAI,iBAAoB,GAAA,KAAA,CAAA;AAExB,MAAM,MAAA,GAAA,GAAM,YAAY,SAAU,CAAA;AAAA,QAChC,IAAA,EAAM,CAAC,CAAM,KAAA;AACX,UAAA,IAAI,CAAC,iBAAA,IAAqB,CAAE,CAAA,KAAA,KAAU,aAAa,OAAS,EAAA;AAC1D,YAAoB,iBAAA,GAAA,IAAA,CAAA;AACpB,YAAA,cAAA,CAAe,eAAe,KAAK,CAAA,CAAA;AAAA,WACrC;AAEA,UAAA,QAAA,CAAS,KAAK,CAAC,CAAA,CAAA;AAAA,SACjB;AAAA,QACA,KAAO,EAAA,CAAC,CAAM,KAAA,QAAA,CAAS,MAAM,CAAC,CAAA;AAAA,QAC9B,UAAU,MAAM;AACd,UAAA,QAAA,CAAS,QAAS,EAAA,CAAA;AAAA,SACpB;AAAA,OACD,CAAA,CAAA;AAED,MAAA,OAAO,MAAM;AACX,QAAA,GAAA,CAAI,WAAY,EAAA,CAAA;AAEhB,QAAA,IAAI,CAAC,iBAAmB,EAAA;AACtB,UAAA,cAAA,CAAe,eAAe,KAAK,CAAA,CAAA;AAAA,SACrC;AAAA,OACF,CAAA;AAAA,KACD,CAAA,CAAA;AAAA,GACH,CAAA;AACF,CAAA;AAGO,SAAS,6BAA6B,OAAyD,EAAA;AACpG,EAAQ,OAAA,CAAA,GAAA,CAAI,gCAAgC,OAAO,CAAA,CAAA;AACnD,EAAO,OAAA,IAAI,UAAiC,CAAA,CAAC,QAAa,KAAA;AAExD,IAAA,QAAA,CAAS,IAAK,CAAA,EAAE,KAAO,EAAA,YAAA,CAAa,SAAS,CAAA,CAAA;AAG7C,IAAM,MAAA,iBAAA,GAAoB,KAAK,OAAO,CAAA,CAAA;AAGtC,IACG,iBAAA,CAAA,IAAA;AAAA,MACC,IAAI,OAAO,EAAE,KAAO,EAAA,YAAA,CAAa,MAAO,CAAA,CAAA;AAAA,MAExC,WAAW,MAAM;AACf,QAAA,QAAA,CAAS,IAAK,CAAA,EAAE,KAAO,EAAA,YAAA,CAAa,OAAO,CAAA,CAAA;AAC3C,QAAA,OAAO,EAAC,CAAA;AAAA,OACT,CAAA;AAAA,MAEF,SAAU,CAAA;AAAA,MACT,IAAM,EAAA,CAAC,MAAW,KAAA,QAAA,CAAS,KAAK,MAAM,CAAA;AAAA,MACtC,QAAA,EAAU,MAAM,QAAA,CAAS,QAAS,EAAA;AAAA,KACnC,CAAA,CAAA;AAAA,GACJ,CAAA,CAAA;AACH;;;;"}
1
+ {"version":3,"file":"registerQueryWithController.js","sources":["../../../src/querying/registerQueryWithController.ts"],"sourcesContent":["import { Observable } from 'rxjs';\nimport { LoadingState } from '@grafana/schema';\nimport { sceneGraph } from '../core/sceneGraph';\nimport { QueryResultWithState, SceneQueryControllerEntry } from '../behaviors/SceneQueryController';\n\n/**\n * Will look for a scene object with a behavior that is a SceneQueryController and register the query with it.\n */\nexport function registerQueryWithController<T extends QueryResultWithState>(entry: SceneQueryControllerEntry) {\n return (queryStream: Observable<T>) => {\n const queryControler = sceneGraph.getQueryController(entry.origin);\n if (!queryControler) {\n return queryStream;\n }\n\n return new Observable<T>((observer) => {\n if (!entry.cancel) {\n entry.cancel = () => observer.complete();\n }\n\n queryControler.queryStarted(entry);\n let markedAsCompleted = false;\n\n const sub = queryStream.subscribe({\n next: (v) => {\n if (!markedAsCompleted && v.state !== LoadingState.Loading) {\n markedAsCompleted = true;\n queryControler.queryCompleted(entry);\n }\n\n observer.next(v);\n },\n error: (e) => observer.error(e),\n complete: () => {\n observer.complete();\n },\n });\n\n return () => {\n sub.unsubscribe();\n\n if (!markedAsCompleted) {\n queryControler.queryCompleted(entry);\n }\n };\n });\n };\n}\n"],"names":[],"mappings":";;;;AAQO,SAAS,4BAA4D,KAAkC,EAAA;AAC5G,EAAA,OAAO,CAAC,WAA+B,KAAA;AACrC,IAAA,MAAM,cAAiB,GAAA,UAAA,CAAW,kBAAmB,CAAA,KAAA,CAAM,MAAM,CAAA,CAAA;AACjE,IAAA,IAAI,CAAC,cAAgB,EAAA;AACnB,MAAO,OAAA,WAAA,CAAA;AAAA,KACT;AAEA,IAAO,OAAA,IAAI,UAAc,CAAA,CAAC,QAAa,KAAA;AACrC,MAAI,IAAA,CAAC,MAAM,MAAQ,EAAA;AACjB,QAAM,KAAA,CAAA,MAAA,GAAS,MAAM,QAAA,CAAS,QAAS,EAAA,CAAA;AAAA,OACzC;AAEA,MAAA,cAAA,CAAe,aAAa,KAAK,CAAA,CAAA;AACjC,MAAA,IAAI,iBAAoB,GAAA,KAAA,CAAA;AAExB,MAAM,MAAA,GAAA,GAAM,YAAY,SAAU,CAAA;AAAA,QAChC,IAAA,EAAM,CAAC,CAAM,KAAA;AACX,UAAA,IAAI,CAAC,iBAAA,IAAqB,CAAE,CAAA,KAAA,KAAU,aAAa,OAAS,EAAA;AAC1D,YAAoB,iBAAA,GAAA,IAAA,CAAA;AACpB,YAAA,cAAA,CAAe,eAAe,KAAK,CAAA,CAAA;AAAA,WACrC;AAEA,UAAA,QAAA,CAAS,KAAK,CAAC,CAAA,CAAA;AAAA,SACjB;AAAA,QACA,KAAO,EAAA,CAAC,CAAM,KAAA,QAAA,CAAS,MAAM,CAAC,CAAA;AAAA,QAC9B,UAAU,MAAM;AACd,UAAA,QAAA,CAAS,QAAS,EAAA,CAAA;AAAA,SACpB;AAAA,OACD,CAAA,CAAA;AAED,MAAA,OAAO,MAAM;AACX,QAAA,GAAA,CAAI,WAAY,EAAA,CAAA;AAEhB,QAAA,IAAI,CAAC,iBAAmB,EAAA;AACtB,UAAA,cAAA,CAAe,eAAe,KAAK,CAAA,CAAA;AAAA,SACrC;AAAA,OACF,CAAA;AAAA,KACD,CAAA,CAAA;AAAA,GACH,CAAA;AACF;;;;"}
@@ -1 +1 @@
1
- {"version":3,"file":"useUrlSync.js","sources":["../../../src/services/useUrlSync.ts"],"sourcesContent":["import { SceneObject } from '../core/types';\nimport { useEffect, useState } from 'react';\nimport { useLocation } from 'react-router-dom';\nimport { getUrlSyncManager } from './UrlSyncManager';\nimport { locationService } from '@grafana/runtime';\nimport { writeSceneLog } from '../utils/writeSceneLog';\n\nexport function useUrlSync(sceneRoot: SceneObject): boolean {\n const urlSyncManager = getUrlSyncManager();\n const location = useLocation();\n const [isInitialized, setIsInitialized] = useState(false);\n\n useEffect(() => {\n urlSyncManager.initSync(sceneRoot);\n setIsInitialized(true);\n return () => urlSyncManager.cleanUp(sceneRoot);\n }, [sceneRoot, urlSyncManager]);\n\n useEffect(() => {\n // Use latest location, as by the time this effect runs, the location might have changed again\n const latestLocation = locationService.getLocation();\n const locationToHandle = latestLocation !== location ? latestLocation : location;\n\n if (latestLocation !== location) {\n writeSceneLog('useUrlSync', 'latestLocation different from location');\n }\n\n urlSyncManager.handleNewLocation(locationToHandle);\n }, [sceneRoot, urlSyncManager, location]);\n\n return isInitialized;\n}\n\nexport interface UrlSyncContextProviderProps {\n scene: SceneObject;\n children: React.ReactNode;\n}\n"],"names":[],"mappings":";;;;;;AAOO,SAAS,WAAW,SAAiC,EAAA;AAC1D,EAAA,MAAM,iBAAiB,iBAAkB,EAAA,CAAA;AACzC,EAAA,MAAM,WAAW,WAAY,EAAA,CAAA;AAC7B,EAAA,MAAM,CAAC,aAAA,EAAe,gBAAgB,CAAA,GAAI,SAAS,KAAK,CAAA,CAAA;AAExD,EAAA,SAAA,CAAU,MAAM;AACd,IAAA,cAAA,CAAe,SAAS,SAAS,CAAA,CAAA;AACjC,IAAA,gBAAA,CAAiB,IAAI,CAAA,CAAA;AACrB,IAAO,OAAA,MAAM,cAAe,CAAA,OAAA,CAAQ,SAAS,CAAA,CAAA;AAAA,GAC5C,EAAA,CAAC,SAAW,EAAA,cAAc,CAAC,CAAA,CAAA;AAE9B,EAAA,SAAA,CAAU,MAAM;AAEd,IAAM,MAAA,cAAA,GAAiB,gBAAgB,WAAY,EAAA,CAAA;AACnD,IAAM,MAAA,gBAAA,GAAmB,cAAmB,KAAA,QAAA,GAAW,cAAiB,GAAA,QAAA,CAAA;AAExE,IAAA,IAAI,mBAAmB,QAAU,EAAA;AAC/B,MAAA,aAAA,CAAc,cAAc,wCAAwC,CAAA,CAAA;AAAA,KACtE;AAEA,IAAA,cAAA,CAAe,kBAAkB,gBAAgB,CAAA,CAAA;AAAA,GAChD,EAAA,CAAC,SAAW,EAAA,cAAA,EAAgB,QAAQ,CAAC,CAAA,CAAA;AAExC,EAAO,OAAA,aAAA,CAAA;AACT;;;;"}
1
+ {"version":3,"file":"useUrlSync.js","sources":["../../../src/services/useUrlSync.ts"],"sourcesContent":["import { SceneObject } from '../core/types';\nimport { useEffect, useState } from 'react';\nimport { useLocation } from 'react-router-dom';\nimport { getUrlSyncManager } from './UrlSyncManager';\nimport { locationService } from '@grafana/runtime';\nimport { writeSceneLog } from '../utils/writeSceneLog';\n\nexport function useUrlSync(sceneRoot: SceneObject): boolean {\n const urlSyncManager = getUrlSyncManager();\n const location = useLocation();\n const [isInitialized, setIsInitialized] = useState(false);\n\n useEffect(() => {\n urlSyncManager.initSync(sceneRoot);\n setIsInitialized(true);\n return () => urlSyncManager.cleanUp(sceneRoot);\n }, [sceneRoot, urlSyncManager]);\n\n useEffect(() => {\n // Use latest location, as by the time this effect runs, the location might have changed again\n const latestLocation = locationService.getLocation();\n const locationToHandle = latestLocation !== location ? latestLocation : location;\n\n if (latestLocation !== location) {\n writeSceneLog('useUrlSync', 'latestLocation different from location')\n }\n\n urlSyncManager.handleNewLocation(locationToHandle);\n }, [sceneRoot, urlSyncManager, location]);\n\n return isInitialized;\n}\n\nexport interface UrlSyncContextProviderProps {\n scene: SceneObject;\n children: React.ReactNode;\n}\n"],"names":[],"mappings":";;;;;;AAOO,SAAS,WAAW,SAAiC,EAAA;AAC1D,EAAA,MAAM,iBAAiB,iBAAkB,EAAA,CAAA;AACzC,EAAA,MAAM,WAAW,WAAY,EAAA,CAAA;AAC7B,EAAA,MAAM,CAAC,aAAA,EAAe,gBAAgB,CAAA,GAAI,SAAS,KAAK,CAAA,CAAA;AAExD,EAAA,SAAA,CAAU,MAAM;AACd,IAAA,cAAA,CAAe,SAAS,SAAS,CAAA,CAAA;AACjC,IAAA,gBAAA,CAAiB,IAAI,CAAA,CAAA;AACrB,IAAO,OAAA,MAAM,cAAe,CAAA,OAAA,CAAQ,SAAS,CAAA,CAAA;AAAA,GAC5C,EAAA,CAAC,SAAW,EAAA,cAAc,CAAC,CAAA,CAAA;AAE9B,EAAA,SAAA,CAAU,MAAM;AAEd,IAAM,MAAA,cAAA,GAAiB,gBAAgB,WAAY,EAAA,CAAA;AACnD,IAAM,MAAA,gBAAA,GAAmB,cAAmB,KAAA,QAAA,GAAW,cAAiB,GAAA,QAAA,CAAA;AAExE,IAAA,IAAI,mBAAmB,QAAU,EAAA;AAC/B,MAAA,aAAA,CAAc,cAAc,wCAAwC,CAAA,CAAA;AAAA,KACtE;AAEA,IAAA,cAAA,CAAe,kBAAkB,gBAAgB,CAAA,CAAA;AAAA,GAChD,EAAA,CAAC,SAAW,EAAA,cAAA,EAAgB,QAAQ,CAAC,CAAA,CAAA;AAExC,EAAO,OAAA,aAAA,CAAA;AACT;;;;"}