@grafana/scenes 5.1.0--canary.790.9497828604.0 β†’ 5.1.1--canary.797.9563223394.0

Sign up to get free protection for your applications and to get access to all the features.
package/CHANGELOG.md CHANGED
@@ -1,3 +1,32 @@
1
+ # v5.1.0 (Fri Jun 14 2024)
2
+
3
+ #### πŸš€ Enhancement
4
+
5
+ - Add support for new getTagKeys/getTagValues interface [#790](https://github.com/grafana/scenes/pull/790) ([@kaydelaney](https://github.com/kaydelaney))
6
+
7
+ #### πŸ› Bug Fix
8
+
9
+ - ScenesReact: Use new react components and hooks from inside existing EmbeddedScenes [#777](https://github.com/grafana/scenes/pull/777) ([@torkelo](https://github.com/torkelo))
10
+
11
+ #### Authors: 2
12
+
13
+ - kay delaney ([@kaydelaney](https://github.com/kaydelaney))
14
+ - Torkel Γ–degaard ([@torkelo](https://github.com/torkelo))
15
+
16
+ ---
17
+
18
+ # v5.0.3 (Thu Jun 13 2024)
19
+
20
+ #### πŸ› Bug Fix
21
+
22
+ - Data layers: Don't run layer on activation if disabled [#795](https://github.com/grafana/scenes/pull/795) ([@dprokop](https://github.com/dprokop))
23
+
24
+ #### Authors: 1
25
+
26
+ - Dominik Prokop ([@dprokop](https://github.com/dprokop))
27
+
28
+ ---
29
+
1
30
  # v5.0.2 (Thu Jun 13 2024)
2
31
 
3
32
  #### πŸ› Bug Fix
@@ -1 +1 @@
1
- {"version":3,"file":"EmbeddedScene.js","sources":["../../../src/components/EmbeddedScene.tsx"],"sourcesContent":["import { css } from '@emotion/css';\nimport { GrafanaTheme2 } from '@grafana/data';\nimport { useStyles2 } from '@grafana/ui';\nimport React from 'react';\n\nimport { SceneObjectBase } from '../core/SceneObjectBase';\nimport { SceneComponentProps, SceneObjectState, SceneObject } from '../core/types';\nimport { setWindowGrafanaSceneContext } from '../utils/compatibility/setWindowGrafanaSceneContext';\n\nexport interface EmbeddedSceneState extends SceneObjectState {\n /**\n * The main content of the scene (usually a SceneFlexLayout)\n */\n body: SceneObject;\n /**\n * Top row of variable selectors, filters, time pickers and custom actions.\n */\n controls?: SceneObject[];\n}\n\nexport class EmbeddedScene extends SceneObjectBase<EmbeddedSceneState> {\n public static Component = EmbeddedSceneRenderer;\n\n public constructor(state: EmbeddedSceneState) {\n super(state);\n\n this.addActivationHandler(() => {\n // This function is setting window.__grafanaSceneContext which is used from Grafana core in the old services TimeSrv and TemplateSrv.\n // This works as a backward compatability method to support accessing scene time range and variables from those old services.\n const unsetGlobalScene = setWindowGrafanaSceneContext(this);\n return () => {\n unsetGlobalScene();\n };\n });\n }\n}\n\nfunction EmbeddedSceneRenderer({ model }: SceneComponentProps<EmbeddedScene>) {\n const { body, controls } = model.useState();\n const styles = useStyles2(getStyles);\n\n return (\n <div className={styles.container}>\n {controls && (\n <div className={styles.controls}>\n {controls.map((control) => (\n <control.Component key={control.state.key} model={control} />\n ))}\n </div>\n )}\n <div className={styles.body}>\n <body.Component model={body} />\n </div>\n </div>\n );\n}\n\nconst getStyles = (theme: GrafanaTheme2) => {\n return {\n container: css({\n flexGrow: 1,\n display: 'flex',\n gap: theme.spacing(2),\n minHeight: '100%',\n flexDirection: 'column',\n }),\n body: css({\n flexGrow: 1,\n display: 'flex',\n gap: theme.spacing(1),\n }),\n controls: css({\n display: 'flex',\n gap: theme.spacing(2),\n alignItems: 'flex-end',\n flexWrap: 'wrap',\n }),\n };\n};\n"],"names":[],"mappings":";;;;;;AAoBO,MAAM,sBAAsB,eAAoC,CAAA;AAAA,EAG9D,YAAY,KAA2B,EAAA;AAC5C,IAAA,KAAA,CAAM,KAAK,CAAA,CAAA;AAEX,IAAA,IAAA,CAAK,qBAAqB,MAAM;AAG9B,MAAM,MAAA,gBAAA,GAAmB,6BAA6B,IAAI,CAAA,CAAA;AAC1D,MAAA,OAAO,MAAM;AACX,QAAiB,gBAAA,EAAA,CAAA;AAAA,OACnB,CAAA;AAAA,KACD,CAAA,CAAA;AAAA,GACH;AACF,CAAA;AAfa,aAAA,CACG,SAAY,GAAA,qBAAA,CAAA;AAgB5B,SAAS,qBAAA,C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AAAA,IACD,UAAU,GAAI,CAAA;AAAA,MACZ,OAAS,EAAA,MAAA;AAAA,MACT,GAAA,EAAK,KAAM,CAAA,OAAA,CAAQ,CAAC,CAAA;AAAA,MACpB,UAAY,EAAA,UAAA;AAAA,MACZ,QAAU,EAAA,MAAA;AAAA,KACX,CAAA;AAAA,GACH,CAAA;AACF,CAAA;;;;"}
1
+ {"version":3,"file":"EmbeddedScene.js","sources":["../../../src/components/EmbeddedScene.tsx"],"sourcesContent":["import { css } from '@emotion/css';\nimport { GrafanaTheme2 } from '@grafana/data';\nimport { useStyles2 } from '@grafana/ui';\nimport React from 'react';\n\nimport { SceneObjectBase } from '../core/SceneObjectBase';\nimport { SceneComponentProps, SceneObjectState, SceneObject } from '../core/types';\nimport { setWindowGrafanaSceneContext } from '../utils/compatibility/setWindowGrafanaSceneContext';\n\nexport interface EmbeddedSceneState extends SceneObjectState {\n /**\n * The main content of the scene (usually a SceneFlexLayout)\n */\n body: SceneObject;\n /**\n * Top row of variable selectors, filters, time pickers and custom actions.\n */\n controls?: SceneObject[];\n /**\n * For interoperability (used from EmbeddedSceneWithContext)\n */\n context?: SceneObject;\n}\n\nexport class EmbeddedScene extends SceneObjectBase<EmbeddedSceneState> {\n public static Component = EmbeddedSceneRenderer;\n\n public constructor(state: EmbeddedSceneState) {\n super(state);\n\n this.addActivationHandler(() => {\n // This function is setting window.__grafanaSceneContext which is used from Grafana core in the old services TimeSrv and TemplateSrv.\n // This works as a backward compatability method to support accessing scene time range and variables from those old services.\n const unsetGlobalScene = setWindowGrafanaSceneContext(this);\n return () => {\n unsetGlobalScene();\n };\n });\n }\n}\n\nfunction EmbeddedSceneRenderer({ model }: SceneComponentProps<EmbeddedScene>) {\n const { body, controls } = model.useState();\n const styles = useStyles2(getStyles);\n\n return (\n <div className={styles.container}>\n {controls && (\n <div className={styles.controls}>\n {controls.map((control) => (\n <control.Component key={control.state.key} model={control} />\n ))}\n </div>\n )}\n <div className={styles.body}>\n <body.Component model={body} />\n </div>\n </div>\n );\n}\n\nconst getStyles = (theme: GrafanaTheme2) => {\n return {\n container: css({\n flexGrow: 1,\n display: 'flex',\n gap: theme.spacing(2),\n minHeight: '100%',\n flexDirection: 'column',\n }),\n body: css({\n flexGrow: 1,\n display: 'flex',\n gap: theme.spacing(1),\n }),\n controls: css({\n display: 'flex',\n gap: theme.spacing(2),\n alignItems: 'flex-end',\n flexWrap: 'wrap',\n }),\n };\n};\n"],"names":[],"mappings":";;;;;;AAwBO,MAAM,sBAAsB,eAAoC,CAAA;AAAA,EAG9D,YAAY,KAA2B,EAAA;AAC5C,IAAA,KAAA,CAAM,KAAK,CAAA,CAAA;AAEX,IAAA,IAAA,CAAK,qBAAqB,MAAM;AAG9B,MAAM,MAAA,gBAAA,GAAmB,6BAA6B,IAAI,CAAA,CAAA;AAC1D,MAAA,OAAO,MAAM;AACX,QAAiB,gBAAA,EAAA,CAAA;AAAA,OACnB,CAAA;AAAA,KACD,CAAA,CAAA;AAAA,GACH;AACF,CAAA;AAfa,aAAA,CACG,SAAY,GAAA,qBAAA,CAAA;AAgB5B,SAAS,qBAAA,CAAsB,EAAE,KAAA,EAA6C,EAAA;AAC5E,EAAA,MAAM,EAAE,IAAA,EAAM,QAAS,EAAA,GAAI,MAAM,QAAS,EAAA,CAAA;AAC1C,EAAM,MAAA,MAAA,GAAS,WAAW,SAAS,CAAA,CAAA;AAEnC,EAAA,uBACG,KAAA,CAAA,aAAA,CAAA,KAAA,EAAA;AAAA,IAAI,WAAW,MAAO,CAAA,SAAA;AAAA,GAAA,EACpB,4BACE,KAAA,CAAA,aAAA,CAAA,KAAA,EAAA;AAAA,IAAI,WAAW,MAAO,CAAA,QAAA;AAAA,GAAA,EACpB,SAAS,GAAI,CAAA,CAAC,OACb,qBAAA,KAAA,CAAA,aAAA,CAAC,QAAQ,SAAR,EAAA;AAAA,IAAkB,GAAA,EAAK,QAAQ,KAAM,CAAA,GAAA;AAAA,IAAK,KAAO,EAAA,OAAA;AAAA,GAAS,CAC5D,CACH,CAAA,kBAED,KAAA,CAAA,aAAA,CAAA,KAAA,EAAA;AAAA,IAAI,WAAW,MAAO,CAAA,IAAA;AAAA,GACrB,kBAAA,KAAA,CAAA,aAAA,CAAC,KAAK,SAAL,EAAA;AAAA,IAAe,KAAO,EAAA,IAAA;AAAA,GAAM,CAC/B,CACF,CAAA,CAAA;AAEJ,CAAA;AAEA,MAAM,SAAA,GAAY,CAAC,KAAyB,KAAA;AAC1C,EAAO,OAAA;AAAA,IACL,WAAW,GAAI,CAAA;AAAA,MACb,QAAU,EAAA,CAAA;AAAA,MACV,OAAS,EAAA,MAAA;AAAA,MACT,GAAA,EAAK,KAAM,CAAA,OAAA,CAAQ,CAAC,CAAA;AAAA,MACpB,SAAW,EAAA,MAAA;AAAA,MACX,aAAe,EAAA,QAAA;AAAA,KAChB,CAAA;AAAA,IACD,MAAM,GAAI,CAAA;AAAA,MACR,QAAU,EAAA,CAAA;AAAA,MACV,OAAS,EAAA,MAAA;AAAA,MACT,GAAA,EAAK,KAAM,CAAA,OAAA,CAAQ,CAAC,CAAA;AAAA,KACrB,CAAA;AAAA,IACD,UAAU,GAAI,CAAA;AAAA,MACZ,OAAS,EAAA,MAAA;AAAA,MACT,GAAA,EAAK,KAAM,CAAA,OAAA,CAAQ,CAAC,CAAA;AAAA,MACpB,UAAY,EAAA,UAAA;AAAA,MACZ,QAAU,EAAA,MAAA;AAAA,KACX,CAAA;AAAA,GACH,CAAA;AACF,CAAA;;;;"}
@@ -88,6 +88,9 @@ class SceneDataLayerBase extends SceneObjectBase {
88
88
  return this._results;
89
89
  }
90
90
  shouldRunLayerOnActivate() {
91
+ if (!this.state.isEnabled) {
92
+ return false;
93
+ }
91
94
  if (this._variableValueRecorder.hasDependenciesChanged(this)) {
92
95
  writeSceneLog(
93
96
  "SceneDataLayerBase",
@@ -1 +1 @@
1
- {"version":3,"file":"SceneDataLayerBase.js","sources":["../../../../src/querying/layers/SceneDataLayerBase.ts"],"sourcesContent":["import { PanelData } from '@grafana/data';\nimport { ReplaySubject, Unsubscribable } from 'rxjs';\nimport { emptyPanelData } from '../../core/SceneDataNode';\nimport { SceneObjectBase } from '../../core/SceneObjectBase';\nimport {\n CancelActivationHandler,\n SceneDataLayerProvider,\n SceneDataProviderResult,\n SceneDataLayerProviderState,\n} from '../../core/types';\nimport { setBaseClassState } from '../../utils/utils';\nimport { writeSceneLog } from '../../utils/writeSceneLog';\nimport { VariableDependencyConfig } from '../../variables/VariableDependencyConfig';\nimport { VariableValueRecorder } from '../../variables/VariableValueRecorder';\n\n/**\n * Base class for data layer. Handles common implementation including enabling/disabling layer and publishing results.\n */\nexport abstract class SceneDataLayerBase<T extends SceneDataLayerProviderState>\n extends SceneObjectBase<T>\n implements SceneDataLayerProvider\n{\n /**\n * Subscription to query results. Should be set when layer runs a query.\n */\n protected querySub?: Unsubscribable;\n\n /**\n * Subject to emit results to.\n */\n private _results = new ReplaySubject<SceneDataProviderResult>(1);\n\n /**\n * Implement logic for enabling the layer. This is called when layer is enabled or when layer is enabled when activated.\n * Use i.e. to setup subscriptions that will trigger layer updates.\n */\n public abstract onEnable(): void;\n\n /**\n * Implement logic for disabling the layer. This is called when layer is disabled.\n * Use i.e. to unsubscribe from subscriptions that trigger layer updates.\n */\n public abstract onDisable(): void;\n\n /**\n * Implement logic running the layer and setting up the querySub subscription.\n */\n protected abstract runLayer(): void;\n\n /**\n * Mark data provider as data layer\n */\n public isDataLayer: true = true;\n\n private _variableValueRecorder = new VariableValueRecorder();\n\n protected _variableDependency: VariableDependencyConfig<T> = new VariableDependencyConfig(this, {\n onVariableUpdateCompleted: this.onVariableUpdateCompleted.bind(this),\n });\n\n /**\n * For variables support in data layer provide variableDependencyStatePaths with keys of the state to be scanned for variables.\n */\n public constructor(initialState: T, variableDependencyStatePaths: Array<keyof T> = []) {\n super({\n isEnabled: true,\n ...initialState,\n });\n\n this._variableDependency.setPaths(variableDependencyStatePaths);\n this.addActivationHandler(() => this.onActivate());\n }\n\n protected onActivate(): CancelActivationHandler {\n if (this.state.isEnabled) {\n this.onEnable();\n }\n\n if (this.shouldRunLayerOnActivate()) {\n this.runLayer();\n }\n\n // Subscribe to layer state changes and enable/disable layer accordingly.\n this.subscribeToState((n, p) => {\n if (!n.isEnabled && this.querySub) {\n // When layer disabled, cancel query and call onDisable that should publish empty results.\n this.querySub.unsubscribe();\n this.querySub = undefined;\n this.onDisable();\n\n // Manually publishing the results to state and results stream as publishPublish results has a guard for the layer to be enabled.\n this._results.next({ origin: this, data: emptyPanelData });\n\n this.setStateHelper({ data: emptyPanelData });\n }\n\n if (n.isEnabled && !p.isEnabled) {\n // When layer enabled, run queries.\n this.onEnable();\n this.runLayer();\n }\n });\n\n return () => {\n this.onDeactivate();\n };\n }\n\n protected onDeactivate(): void {\n if (this.querySub) {\n this.querySub.unsubscribe();\n this.querySub = undefined;\n }\n\n this.onDisable();\n\n this._variableValueRecorder.recordCurrentDependencyValuesForSceneObject(this);\n }\n\n protected onVariableUpdateCompleted(): void {\n this.runLayer();\n }\n\n public cancelQuery() {\n if (this.querySub) {\n this.querySub.unsubscribe();\n this.querySub = undefined;\n\n this.publishResults(emptyPanelData);\n }\n }\n\n protected publishResults(data: PanelData) {\n if (this.state.isEnabled) {\n this._results.next({ origin: this, data });\n this.setStateHelper({ data });\n }\n }\n\n public getResultsStream() {\n return this._results;\n }\n\n private shouldRunLayerOnActivate() {\n if (this._variableValueRecorder.hasDependenciesChanged(this)) {\n writeSceneLog(\n 'SceneDataLayerBase',\n 'Variable dependency changed while inactive, shouldRunLayerOnActivate returns true'\n );\n return true;\n }\n\n if (!this.state.data) {\n return true;\n }\n\n return false;\n }\n\n /**\n * This helper function is to counter the contravariance of setState\n */\n private setStateHelper(state: Partial<SceneDataLayerProviderState>) {\n setBaseClassState<SceneDataLayerProviderState>(this, state);\n }\n}\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AAkBO,MAAe,2BACZ,eAEV,CAAA;AAAA,EA0CS,WAAY,CAAA,YA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IAAA,CAAA,cAAA,CAAe,EAAE,IAAA,EAAM,CAAA,CAAA;AAAA,KAC9B;AAAA,GACF;AAAA,EAEO,gBAAmB,GAAA;AACxB,IAAA,OAAO,IAAK,CAAA,QAAA,CAAA;AAAA,GACd;AAAA,EAEQ,wBAA2B,GAAA;AACjC,IAAA,IAAI,IAAK,CAAA,sBAAA,CAAuB,sBAAuB,CAAA,IAAI,CAAG,EAAA;AAC5D,MAAA,aAAA;AAAA,QACE,oBAAA;AAAA,QACA,mFAAA;AAAA,OACF,CAAA;AACA,MAAO,OAAA,IAAA,CAAA;AAAA,KACT;AAEA,IAAI,IAAA,CAAC,IAAK,CAAA,KAAA,CAAM,IAAM,EAAA;AACpB,MAAO,OAAA,IAAA,CAAA;AAAA,KACT;AAEA,IAAO,OAAA,KAAA,CAAA;AAAA,GACT;AAAA,EAKQ,eAAe,KAA6C,EAAA;AAClE,IAAA,iBAAA,CAA+C,MAAM,KAAK,CAAA,CAAA;AAAA,GAC5D;AACF;;;;"}
1
+ {"version":3,"file":"SceneDataLayerBase.js","sources":["../../../../src/querying/layers/SceneDataLayerBase.ts"],"sourcesContent":["import { PanelData } from '@grafana/data';\nimport { ReplaySubject, Unsubscribable } from 'rxjs';\nimport { emptyPanelData } from '../../core/SceneDataNode';\nimport { SceneObjectBase } from '../../core/SceneObjectBase';\nimport {\n CancelActivationHandler,\n SceneDataLayerProvider,\n SceneDataProviderResult,\n SceneDataLayerProviderState,\n} from '../../core/types';\nimport { setBaseClassState } from '../../utils/utils';\nimport { writeSceneLog } from '../../utils/writeSceneLog';\nimport { VariableDependencyConfig } from '../../variables/VariableDependencyConfig';\nimport { VariableValueRecorder } from '../../variables/VariableValueRecorder';\n\n/**\n * Base class for data layer. Handles common implementation including enabling/disabling layer and publishing results.\n */\nexport abstract class SceneDataLayerBase<T extends SceneDataLayerProviderState>\n extends SceneObjectBase<T>\n implements SceneDataLayerProvider\n{\n /**\n * Subscription to query results. Should be set when layer runs a query.\n */\n protected querySub?: Unsubscribable;\n\n /**\n * Subject to emit results to.\n */\n private _results = new ReplaySubject<SceneDataProviderResult>(1);\n\n /**\n * Implement logic for enabling the layer. This is called when layer is enabled or when layer is enabled when activated.\n * Use i.e. to setup subscriptions that will trigger layer updates.\n */\n public abstract onEnable(): void;\n\n /**\n * Implement logic for disabling the layer. This is called when layer is disabled.\n * Use i.e. to unsubscribe from subscriptions that trigger layer updates.\n */\n public abstract onDisable(): void;\n\n /**\n * Implement logic running the layer and setting up the querySub subscription.\n */\n protected abstract runLayer(): void;\n\n /**\n * Mark data provider as data layer\n */\n public isDataLayer: true = true;\n\n private _variableValueRecorder = new VariableValueRecorder();\n\n protected _variableDependency: VariableDependencyConfig<T> = new VariableDependencyConfig(this, {\n onVariableUpdateCompleted: this.onVariableUpdateCompleted.bind(this),\n });\n\n /**\n * For variables support in data layer provide variableDependencyStatePaths with keys of the state to be scanned for variables.\n */\n public constructor(initialState: T, variableDependencyStatePaths: Array<keyof T> = []) {\n super({\n isEnabled: true,\n ...initialState,\n });\n\n this._variableDependency.setPaths(variableDependencyStatePaths);\n this.addActivationHandler(() => this.onActivate());\n }\n\n protected onActivate(): CancelActivationHandler {\n if (this.state.isEnabled) {\n this.onEnable();\n }\n\n if (this.shouldRunLayerOnActivate()) {\n this.runLayer();\n }\n\n // Subscribe to layer state changes and enable/disable layer accordingly.\n this.subscribeToState((n, p) => {\n if (!n.isEnabled && this.querySub) {\n // When layer disabled, cancel query and call onDisable that should publish empty results.\n this.querySub.unsubscribe();\n this.querySub = undefined;\n this.onDisable();\n\n // Manually publishing the results to state and results stream as publishPublish results has a guard for the layer to be enabled.\n this._results.next({ origin: this, data: emptyPanelData });\n\n this.setStateHelper({ data: emptyPanelData });\n }\n\n if (n.isEnabled && !p.isEnabled) {\n // When layer enabled, run queries.\n this.onEnable();\n this.runLayer();\n }\n });\n\n return () => {\n this.onDeactivate();\n };\n }\n\n protected onDeactivate(): void {\n if (this.querySub) {\n this.querySub.unsubscribe();\n this.querySub = undefined;\n }\n\n this.onDisable();\n\n this._variableValueRecorder.recordCurrentDependencyValuesForSceneObject(this);\n }\n\n protected onVariableUpdateCompleted(): void {\n this.runLayer();\n }\n\n public cancelQuery() {\n if (this.querySub) {\n this.querySub.unsubscribe();\n this.querySub = undefined;\n\n this.publishResults(emptyPanelData);\n }\n }\n\n protected publishResults(data: PanelData) {\n if (this.state.isEnabled) {\n this._results.next({ origin: this, data });\n this.setStateHelper({ data });\n }\n }\n\n public getResultsStream() {\n return this._results;\n }\n\n private shouldRunLayerOnActivate() {\n if (!this.state.isEnabled) {\n return false;\n }\n\n if (this._variableValueRecorder.hasDependenciesChanged(this)) {\n writeSceneLog(\n 'SceneDataLayerBase',\n 'Variable dependency changed while inactive, shouldRunLayerOnActivate returns true'\n );\n return true;\n }\n\n if (!this.state.data) {\n return true;\n }\n\n return false;\n }\n\n /**\n * This helper function is to counter the contravariance of setState\n */\n private setStateHelper(state: Partial<SceneDataLayerProviderState>) {\n setBaseClassState<SceneDataLayerProviderState>(this, state);\n }\n}\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AAkBO,MAAe,2BACZ,eAEV,CAAA;AAAA,EA0CS,WAAY,CAAA,YAAA,EAAiB,4BAA+C,GAAA,EAAI,EAAA;AACrF,IAAM,KAAA,CAAA,cAAA,CAAA;AAAA,MACJ,SAAW,EAAA,IAAA;AAAA,KAAA,EACR,YACJ,CAAA,CAAA,CAAA;AArCH,IAAQ,IAAA,CAAA,QAAA,GAAW,IAAI,aAAA,CAAuC,CAAC,CAAA,CAAA;AAsB/D,IAAA,IAAA,CAAO,WAAoB,GAAA,IAAA,CAAA;AAE3B,IAAQ,IAAA,CAAA,sBAAA,GAAyB,IAAI,qBAAsB,EAAA,CAAA;AAE3D,IAAU,IAAA,CAAA,mBAAA,GAAmD,IAAI,wBAAA,CAAyB,IAAM,EAAA;AAAA,MAC9F,yBAA2B,EAAA,IAAA,CAAK,yBAA0B,CAAA,IAAA,CAAK,IAAI,CAAA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IAAA,CAAC,IAAK,CAAA,KAAA,CAAM,IAAM,EAAA;AACpB,MAAO,OAAA,IAAA,CAAA;AAAA,KACT;AAEA,IAAO,OAAA,KAAA,CAAA;AAAA,GACT;AAAA,EAKQ,eAAe,KAA6C,EAAA;AAClE,IAAA,iBAAA,CAA+C,MAAM,KAAK,CAAA,CAAA;AAAA,GAC5D;AACF;;;;"}
package/dist/index.d.ts CHANGED
@@ -1609,6 +1609,10 @@ interface EmbeddedSceneState extends SceneObjectState {
1609
1609
  * Top row of variable selectors, filters, time pickers and custom actions.
1610
1610
  */
1611
1611
  controls?: SceneObject[];
1612
+ /**
1613
+ * For interoperability (used from EmbeddedSceneWithContext)
1614
+ */
1615
+ context?: SceneObject;
1612
1616
  }
1613
1617
  declare class EmbeddedScene extends SceneObjectBase<EmbeddedSceneState> {
1614
1618
  static Component: typeof EmbeddedSceneRenderer;
package/dist/index.js CHANGED
@@ -5564,6 +5564,9 @@ class SceneDataLayerBase extends SceneObjectBase {
5564
5564
  return this._results;
5565
5565
  }
5566
5566
  shouldRunLayerOnActivate() {
5567
+ if (!this.state.isEnabled) {
5568
+ return false;
5569
+ }
5567
5570
  if (this._variableValueRecorder.hasDependenciesChanged(this)) {
5568
5571
  writeSceneLog(
5569
5572
  "SceneDataLayerBase",