@grafana/scenes 5.3.8 → 5.3.9--canary.827.9887483180.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -2,6 +2,7 @@ import React, { useState, useRef, useImperativeHandle } from 'react';
2
2
  import { useEffectOnce } from 'react-use';
3
3
  import { uniqueId } from 'lodash';
4
4
  import { css } from '@emotion/css';
5
+ import { useStyles2 } from '@grafana/ui';
5
6
 
6
7
  var __defProp = Object.defineProperty;
7
8
  var __getOwnPropSymbols = Object.getOwnPropertySymbols;
@@ -41,7 +42,7 @@ const LazyLoader = React.forwardRef(
41
42
  (_a, ref) => {
42
43
  var _b = _a, { children, onLoad, onChange, className } = _b, rest = __objRest(_b, ["children", "onLoad", "onChange", "className"]);
43
44
  const id = useUniqueId();
44
- const style = useStyle();
45
+ const { hideEmpty } = useStyles2(getStyles);
45
46
  const [loaded, setLoaded] = useState(false);
46
47
  const [isInView, setIsInView] = useState(false);
47
48
  const innerRef = useRef(null);
@@ -67,19 +68,22 @@ const LazyLoader = React.forwardRef(
67
68
  }
68
69
  };
69
70
  });
71
+ const classes = `${loaded ? hideEmpty : ""} ${className}`;
70
72
  return /* @__PURE__ */ React.createElement("div", __spreadValues({
71
73
  id,
72
74
  ref: innerRef,
73
- className: `${loaded ? style : ""} ${className}`
75
+ className: classes
74
76
  }, rest), loaded && (typeof children === "function" ? children({ isInView }) : children));
75
77
  }
76
78
  );
77
- function useStyle() {
78
- return css({
79
- "&:empty": {
80
- display: "none"
81
- }
82
- });
79
+ function getStyles() {
80
+ return {
81
+ hideEmpty: css({
82
+ "&:empty": {
83
+ display: "none"
84
+ }
85
+ })
86
+ };
83
87
  }
84
88
  LazyLoader.displayName = "LazyLoader";
85
89
  LazyLoader.callbacks = {};
@@ -1 +1 @@
1
- {"version":3,"file":"LazyLoader.js","sources":["../../../../src/components/layout/LazyLoader.tsx"],"sourcesContent":["import React, { ForwardRefExoticComponent, useImperativeHandle, useRef, useState } from 'react';\nimport { useEffectOnce } from 'react-use';\n\nimport { uniqueId } from 'lodash';\nimport { css } from '@emotion/css';\n\nexport function useUniqueId(): string {\n const idRefLazy = useRef<string | undefined>(undefined);\n idRefLazy.current ??= uniqueId();\n return idRefLazy.current;\n}\n\nexport interface Props extends Omit<React.HTMLProps<HTMLDivElement>, 'onChange' | 'children'> {\n children: React.ReactNode | (({ isInView }: { isInView: boolean }) => React.ReactNode);\n key: string;\n onLoad?: () => void;\n onChange?: (isInView: boolean) => void;\n}\n\nexport interface LazyLoaderType extends ForwardRefExoticComponent<Props> {\n addCallback: (id: string, c: (e: IntersectionObserverEntry) => void) => void;\n callbacks: Record<string, (e: IntersectionObserverEntry) => void>;\n observer: IntersectionObserver;\n}\n\nexport const LazyLoader: LazyLoaderType = React.forwardRef<HTMLDivElement, Props>(\n ({ children, onLoad, onChange, className, ...rest }, ref) => {\n const id = useUniqueId();\n const style = useStyle();\n const [loaded, setLoaded] = useState(false);\n const [isInView, setIsInView] = useState(false);\n const innerRef = useRef<HTMLDivElement>(null);\n\n useImperativeHandle(ref, () => innerRef.current!);\n\n useEffectOnce(() => {\n LazyLoader.addCallback(id, (entry) => {\n if (!loaded && entry.isIntersecting) {\n setLoaded(true);\n onLoad?.();\n }\n\n setIsInView(entry.isIntersecting);\n onChange?.(entry.isIntersecting);\n });\n\n const wrapperEl = innerRef.current;\n\n if (wrapperEl) {\n LazyLoader.observer.observe(wrapperEl);\n }\n\n return () => {\n delete LazyLoader.callbacks[id];\n wrapperEl && LazyLoader.observer.unobserve(wrapperEl);\n if (Object.keys(LazyLoader.callbacks).length === 0) {\n LazyLoader.observer.disconnect();\n }\n };\n });\n\n return (\n <div id={id} ref={innerRef} className={`${loaded ? style : ''} ${className}`} {...rest}>\n {loaded && (typeof children === 'function' ? children({ isInView }) : children)}\n </div>\n );\n }\n) as LazyLoaderType;\n\nfunction useStyle() {\n return css({\n '&:empty': {\n display: 'none',\n },\n });\n}\n\nLazyLoader.displayName = 'LazyLoader';\nLazyLoader.callbacks = {} as Record<string, (e: IntersectionObserverEntry) => void>;\nLazyLoader.addCallback = (id: string, c: (e: IntersectionObserverEntry) => void) => (LazyLoader.callbacks[id] = c);\nLazyLoader.observer = new IntersectionObserver(\n (entries) => {\n for (const entry of entries) {\n LazyLoader.callbacks[entry.target.id](entry);\n }\n },\n { rootMargin: '100px' }\n);\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAMO,SAAS,WAAsB,GAAA;AANtC,EAAA,IAAA,EAAA,CAAA;AAOE,EAAM,MAAA,SAAA,GAAY,OAA2B,KAAS,CAAA,CAAA,CAAA;AACtD,EAAU,CAAA,EAAA,GAAA,SAAA,CAAA,OAAA,KAAV,IAAU,GAAA,EAAA,GAAA,SAAA,CAAA,OAAA,GAAY,QAAS,EAAA,CAAA;AAC/B,EAAA,OAAO,SAAU,CAAA,OAAA,CAAA;AACnB,CAAA;AAeO,MAAM,aAA6B,KAAM,CAAA,UAAA;AAAA,EAC9C,CAAC,IAAoD,GAAQ,KAAA;AAA5D,IAAE,IAAA,EAAA,GAAA,EAAA,EAAA,EAAA,QAAA,EAAU,MAAQ,EAAA,QAAA,EAAU,SA1BjC,EAAA,GA0BG,EAA4C,EAAA,IAAA,GAAA,SAAA,CAA5C,EAA4C,EAAA,CAA1C,UAAU,EAAA,QAAA,EAAQ,UAAU,EAAA,WAAA,CAAA,CAAA,CAAA;AAC7B,IAAA,MAAM,KAAK,WAAY,EAAA,CAAA;AACvB,IAAA,MAAM,QAAQ,QAAS,EAAA,CAAA;AACvB,IAAA,MAAM,CAAC,MAAA,EAAQ,SAAS,CAAA,GAAI,SAAS,KAAK,CAAA,CAAA;AAC1C,IAAA,MAAM,CAAC,QAAA,EAAU,WAAW,CAAA,GAAI,SAAS,KAAK,CAAA,CAAA;AAC9C,IAAM,MAAA,QAAA,GAAW,OAAuB,IAAI,CAAA,CAAA;AAE5C,IAAoB,mBAAA,CAAA,GAAA,EAAK,MAAM,QAAA,CAAS,OAAQ,CAAA,CAAA;AAEhD,IAAA,aAAA,CAAc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A,EAAU,CAAA,GAAI,QACxE,CAAA,CAAA,CAAA;AAAA,GAEJ;AACF,EAAA;AAEA,SAAS,QAAW,GAAA;AAClB,EAAA,OAAO,GAAI,CAAA;AAAA,IACT,SAAW,EAAA;AAAA,MACT,OAAS,EAAA,MAAA;AAAA,KACX;AAAA,GACD,CAAA,CAAA;AACH,CAAA;AAEA,UAAA,CAAW,WAAc,GAAA,YAAA,CAAA;AACzB,UAAA,CAAW,YAAY,EAAC,CAAA;AACxB,UAAA,CAAW,cAAc,CAAC,EAAA,EAAY,CAA+C,KAAA,UAAA,CAAW,UAAU,EAAM,CAAA,GAAA,CAAA,CAAA;AAChH,UAAA,CAAW,WAAW,IAAI,oBAAA;AAAA,EACxB,CAAC,OAAY,KAAA;AACX,IAAA,KAAA,MAAW,SAAS,OAAS,EAAA;AAC3B,MAAA,UAAA,CAAW,SAAU,CAAA,KAAA,CAAM,MAAO,CAAA,EAAA,CAAA,CAAI,KAAK,CAAA,CAAA;AAAA,KAC7C;AAAA,GACF;AAAA,EACA,EAAE,YAAY,OAAQ,EAAA;AACxB,CAAA;;;;"}
1
+ {"version":3,"file":"LazyLoader.js","sources":["../../../../src/components/layout/LazyLoader.tsx"],"sourcesContent":["import React, { ForwardRefExoticComponent, useImperativeHandle, useRef, useState } from 'react';\nimport { useEffectOnce } from 'react-use';\n\nimport { uniqueId } from 'lodash';\nimport { css } from '@emotion/css';\nimport { useStyles2 } from '@grafana/ui';\n\nexport function useUniqueId(): string {\n const idRefLazy = useRef<string | undefined>(undefined);\n idRefLazy.current ??= uniqueId();\n return idRefLazy.current;\n}\n\nexport interface Props extends Omit<React.HTMLProps<HTMLDivElement>, 'onChange' | 'children'> {\n children: React.ReactNode | (({ isInView }: { isInView: boolean }) => React.ReactNode);\n key: string;\n onLoad?: () => void;\n onChange?: (isInView: boolean) => void;\n}\n\nexport interface LazyLoaderType extends ForwardRefExoticComponent<Props> {\n addCallback: (id: string, c: (e: IntersectionObserverEntry) => void) => void;\n callbacks: Record<string, (e: IntersectionObserverEntry) => void>;\n observer: IntersectionObserver;\n}\n\nexport const LazyLoader: LazyLoaderType = React.forwardRef<HTMLDivElement, Props>(\n ({ children, onLoad, onChange, className, ...rest }, ref) => {\n const id = useUniqueId();\n const { hideEmpty } = useStyles2(getStyles);\n const [loaded, setLoaded] = useState(false);\n const [isInView, setIsInView] = useState(false);\n const innerRef = useRef<HTMLDivElement>(null);\n\n useImperativeHandle(ref, () => innerRef.current!);\n\n useEffectOnce(() => {\n LazyLoader.addCallback(id, (entry) => {\n if (!loaded && entry.isIntersecting) {\n setLoaded(true);\n onLoad?.();\n }\n\n setIsInView(entry.isIntersecting);\n onChange?.(entry.isIntersecting);\n });\n\n const wrapperEl = innerRef.current;\n\n if (wrapperEl) {\n LazyLoader.observer.observe(wrapperEl);\n }\n\n return () => {\n delete LazyLoader.callbacks[id];\n wrapperEl && LazyLoader.observer.unobserve(wrapperEl);\n if (Object.keys(LazyLoader.callbacks).length === 0) {\n LazyLoader.observer.disconnect();\n }\n };\n });\n\n // If the element was loaded, we add the `hideEmpty` class to potentially\n // hide the LazyLoader if it does not have any children. This is the case\n // when children have the `isHidden` property set. \n // We always include the `className` class, as this is coming from the \n // caller of the `LazyLoader` component.\n const classes = `${loaded ? hideEmpty : ''} ${className}`;\n return (\n <div id={id} ref={innerRef} className={classes} {...rest}>\n {loaded && (typeof children === 'function' ? children({ isInView }) : children)}\n </div>\n );\n }\n) as LazyLoaderType;\n\nfunction getStyles() {\n return {\n hideEmpty: css({\n '&:empty': {\n display: 'none',\n },\n }),\n };\n}\n\nLazyLoader.displayName = 'LazyLoader';\nLazyLoader.callbacks = {} as Record<string, (e: IntersectionObserverEntry) => void>;\nLazyLoader.addCallback = (id: string, c: (e: IntersectionObserverEntry) => void) => (LazyLoader.callbacks[id] = c);\nLazyLoader.observer = new IntersectionObserver(\n (entries) => {\n for (const entry of entries) {\n LazyLoader.callbacks[entry.target.id](entry);\n }\n },\n { rootMargin: '100px' }\n);\n"],"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AA;AAAA,IACL,WAAW,GAAI,CAAA;AAAA,MACb,SAAW,EAAA;AAAA,QACT,OAAS,EAAA,MAAA;AAAA,OACX;AAAA,KACD,CAAA;AAAA,GACH,CAAA;AACF,CAAA;AAEA,UAAA,CAAW,WAAc,GAAA,YAAA,CAAA;AACzB,UAAA,CAAW,YAAY,EAAC,CAAA;AACxB,UAAA,CAAW,cAAc,CAAC,EAAA,EAAY,CAA+C,KAAA,UAAA,CAAW,UAAU,EAAM,CAAA,GAAA,CAAA,CAAA;AAChH,UAAA,CAAW,WAAW,IAAI,oBAAA;AAAA,EACxB,CAAC,OAAY,KAAA;AACX,IAAA,KAAA,MAAW,SAAS,OAAS,EAAA;AAC3B,MAAA,UAAA,CAAW,SAAU,CAAA,KAAA,CAAM,MAAO,CAAA,EAAA,CAAA,CAAI,KAAK,CAAA,CAAA;AAAA,KAC7C;AAAA,GACF;AAAA,EACA,EAAE,YAAY,OAAQ,EAAA;AACxB,CAAA;;;;"}
package/dist/esm/index.js CHANGED
@@ -24,7 +24,7 @@ export { SceneDataLayerBase } from './querying/layers/SceneDataLayerBase.js';
24
24
  export { SceneDataLayerControls } from './querying/layers/SceneDataLayerControls.js';
25
25
  export { SceneDataTransformer } from './querying/SceneDataTransformer.js';
26
26
  export { registerQueryWithController } from './querying/registerQueryWithController.js';
27
- export { SceneVariableValueChangedEvent, isCustomVariableValue } from './variables/types.js';
27
+ export { SceneVariableOptionsRefreshEvent, SceneVariableValueChangedEvent, isCustomVariableValue } from './variables/types.js';
28
28
  export { VariableDependencyConfig } from './variables/VariableDependencyConfig.js';
29
29
  export { formatRegistry } from './variables/interpolation/formatRegistry.js';
30
30
  export { VariableValueSelectWrapper, VariableValueSelectors } from './variables/components/VariableValueSelectors.js';
@@ -2,7 +2,7 @@ import { VariableRefresh } from '@grafana/data';
2
2
  import { sceneGraph } from '../../core/sceneGraph/index.js';
3
3
  import { SceneObjectBase } from '../../core/SceneObjectBase.js';
4
4
  import { writeSceneLog } from '../../utils/writeSceneLog.js';
5
- import { SceneVariableValueChangedEvent } from '../types.js';
5
+ import { SceneVariableValueChangedEvent, SceneVariableOptionsRefreshEvent } from '../types.js';
6
6
  import { VariableValueRecorder } from '../VariableValueRecorder.js';
7
7
 
8
8
  class SceneVariableSet extends SceneObjectBase {
@@ -20,6 +20,9 @@ class SceneVariableSet extends SceneObjectBase {
20
20
  this._subs.add(
21
21
  this.subscribeToEvent(SceneVariableValueChangedEvent, (event) => this._handleVariableValueChanged(event.payload))
22
22
  );
23
+ this._subs.add(
24
+ this.subscribeToEvent(SceneVariableOptionsRefreshEvent, (event) => this._handleVariableOptionsUpdate(event.payload))
25
+ );
23
26
  this._subs.add(
24
27
  timeRange.subscribeToState(() => {
25
28
  this._refreshTimeRangeBasedVariables();
@@ -161,6 +164,10 @@ class SceneVariableSet extends SceneObjectBase {
161
164
  console.error("SceneVariableSet updateAndValidate error", err);
162
165
  writeVariableTraceLog(variable, "updateAndValidate error", err);
163
166
  }
167
+ _handleVariableOptionsUpdate(variable) {
168
+ this._variablesToUpdate.add(variable);
169
+ this._updateNextBatch();
170
+ }
164
171
  _handleVariableValueChanged(variableThatChanged) {
165
172
  this._variablesThatHaveChanged.add(variableThatChanged);
166
173
  this._addDependentVariablesToUpdateQueue(variableThatChanged);
@@ -1 +1 @@
1
- {"version":3,"file":"SceneVariableSet.js","sources":["../../../../src/variables/sets/SceneVariableSet.ts"],"sourcesContent":["import { VariableRefresh } from '@grafana/data';\nimport { Unsubscribable } from 'rxjs';\nimport { sceneGraph } from '../../core/sceneGraph';\n\nimport { SceneObjectBase } from '../../core/SceneObjectBase';\nimport { SceneObject } from '../../core/types';\nimport { writeSceneLog } from '../../utils/writeSceneLog';\nimport {\n SceneVariable,\n SceneVariableDependencyConfigLike,\n SceneVariables,\n SceneVariableSetState,\n SceneVariableValueChangedEvent,\n} from '../types';\nimport { VariableValueRecorder } from '../VariableValueRecorder';\n\nexport class SceneVariableSet extends SceneObjectBase<SceneVariableSetState> implements SceneVariables {\n /** Variables that have changed in since the activation or since the first manual value change */\n private _variablesThatHaveChanged = new Set<SceneVariable>();\n\n /** Variables that are scheduled to be validated and updated */\n private _variablesToUpdate = new Set<SceneVariable>();\n\n /** Variables currently updating */\n private _updating = new Map<SceneVariable, VariableUpdateInProgress>();\n\n private _variableValueRecorder = new VariableValueRecorder();\n\n /**\n * This makes sure SceneVariableSet's higher up in the chain notify us when parent level variables complete update batches.\n **/\n protected _variableDependency = new SceneVariableSetVariableDependencyHandler(\n this._handleParentVariableUpdatesCompleted.bind(this)\n );\n\n public getByName(name: string): SceneVariable | undefined {\n // TODO: Replace with index\n return this.state.variables.find((x) => x.state.name === name);\n }\n\n public constructor(state: SceneVariableSetState) {\n super(state);\n\n this.addActivationHandler(this._onActivate);\n }\n\n /**\n * Subscribes to child variable value changes, and starts the variable value validation process\n */\n private _onActivate = () => {\n const timeRange = sceneGraph.getTimeRange(this);\n // Subscribe to changes to child variables\n this._subs.add(\n this.subscribeToEvent(SceneVariableValueChangedEvent, (event) => this._handleVariableValueChanged(event.payload))\n );\n\n this._subs.add(\n timeRange.subscribeToState(() => {\n this._refreshTimeRangeBasedVariables();\n })\n );\n\n // Subscribe to state changes\n this._subs.add(this.subscribeToState(this._onStateChanged));\n\n this._checkForVariablesThatChangedWhileInactive();\n\n // Add all variables that need updating to queue\n for (const variable of this.state.variables) {\n if (this._variableNeedsUpdate(variable)) {\n this._variablesToUpdate.add(variable);\n }\n }\n\n this._updateNextBatch();\n\n // Return deactivation handler;\n return this._onDeactivate;\n };\n\n /**\n * Add all variables that depend on the changed variable to the update queue\n */\n private _refreshTimeRangeBasedVariables() {\n for (const variable of this.state.variables) {\n if ('refresh' in variable.state && variable.state.refresh === VariableRefresh.onTimeRangeChanged) {\n this._variablesToUpdate.add(variable);\n }\n }\n\n this._updateNextBatch();\n }\n\n /**\n * Cancel all currently running updates\n */\n private _onDeactivate = () => {\n for (const update of this._updating.values()) {\n update.subscription?.unsubscribe();\n }\n\n // Remember current variable values\n for (const variable of this.state.variables) {\n // if the current variable is not in queue to update and validate and not being actively updated then the value is ok\n if (!this._variablesToUpdate.has(variable) && !this._updating.has(variable)) {\n this._variableValueRecorder.recordCurrentValue(variable);\n }\n }\n\n this._variablesToUpdate.clear();\n this._updating.clear();\n };\n\n /**\n * Look for new variables that need to be initialized\n */\n private _onStateChanged = (newState: SceneVariableSetState, oldState: SceneVariableSetState) => {\n const variablesToUpdateCountStart = this._variablesToUpdate.size;\n\n // Check for removed variables\n for (const variable of oldState.variables) {\n if (!newState.variables.includes(variable)) {\n const updating = this._updating.get(variable);\n if (updating?.subscription) {\n updating.subscription.unsubscribe();\n }\n this._updating.delete(variable);\n this._variablesToUpdate.delete(variable);\n }\n }\n\n // Check for new variables\n for (const variable of newState.variables) {\n if (!oldState.variables.includes(variable)) {\n if (this._variableNeedsUpdate(variable)) {\n this._variablesToUpdate.add(variable);\n }\n }\n }\n\n // Only start a new batch if there was no batch already running\n if (variablesToUpdateCountStart === 0 && this._variablesToUpdate.size > 0) {\n this._updateNextBatch();\n }\n };\n\n /**\n * If variables changed while in in-active state we don't get any change events, so we need to check for that here.\n */\n private _checkForVariablesThatChangedWhileInactive() {\n if (!this._variableValueRecorder.hasValues()) {\n return;\n }\n\n for (const variable of this.state.variables) {\n if (this._variableValueRecorder.hasValueChanged(variable)) {\n writeVariableTraceLog(variable, 'Changed while in-active');\n this._addDependentVariablesToUpdateQueue(variable);\n }\n }\n }\n\n private _variableNeedsUpdate(variable: SceneVariable): boolean {\n if (variable.isLazy) {\n return false;\n }\n\n if (!variable.validateAndUpdate) {\n return false;\n }\n\n // If we have recorded valid value (even if it has changed since we do not need to re-validate this variable)\n if (this._variableValueRecorder.hasRecordedValue(variable)) {\n writeVariableTraceLog(variable, 'Skipping updateAndValidate current value valid');\n return false;\n }\n\n return true;\n }\n\n /**\n * This loops through variablesToUpdate and update all that can.\n * If one has a dependency that is currently in variablesToUpdate it will be skipped for now.\n */\n private _updateNextBatch() {\n for (const variable of this._variablesToUpdate) {\n if (!variable.validateAndUpdate) {\n throw new Error('Variable added to variablesToUpdate but does not have validateAndUpdate');\n }\n\n // Ignore it if it's already started\n if (this._updating.has(variable)) {\n continue;\n }\n\n // Wait for variables that has dependencies that also needs updates\n if (sceneGraph.hasVariableDependencyInLoadingState(variable)) {\n continue;\n }\n\n const variableToUpdate: VariableUpdateInProgress = {\n variable,\n };\n\n this._updating.set(variable, variableToUpdate);\n writeVariableTraceLog(variable, 'updateAndValidate started');\n\n variableToUpdate.subscription = variable.validateAndUpdate().subscribe({\n next: () => this._validateAndUpdateCompleted(variable),\n complete: () => this._validateAndUpdateCompleted(variable),\n error: (err) => this._handleVariableError(variable, err),\n });\n }\n }\n\n /**\n * A variable has completed its update process. This could mean that variables that depend on it can now be updated in turn.\n */\n private _validateAndUpdateCompleted(variable: SceneVariable) {\n if (!this._updating.has(variable)) {\n return;\n }\n\n const update = this._updating.get(variable);\n update?.subscription?.unsubscribe();\n\n this._updating.delete(variable);\n this._variablesToUpdate.delete(variable);\n\n writeVariableTraceLog(variable, 'updateAndValidate completed');\n\n this._notifyDependentSceneObjects(variable);\n this._updateNextBatch();\n }\n\n public cancel(variable: SceneVariable) {\n const update = this._updating.get(variable);\n update?.subscription?.unsubscribe();\n\n this._updating.delete(variable);\n this._variablesToUpdate.delete(variable);\n }\n\n private _handleVariableError(variable: SceneVariable, err: Error) {\n const update = this._updating.get(variable);\n update?.subscription?.unsubscribe();\n\n this._updating.delete(variable);\n this._variablesToUpdate.delete(variable);\n\n variable.setState({ loading: false, error: err.message });\n\n console.error('SceneVariableSet updateAndValidate error', err);\n\n writeVariableTraceLog(variable, 'updateAndValidate error', err);\n }\n\n private _handleVariableValueChanged(variableThatChanged: SceneVariable) {\n this._variablesThatHaveChanged.add(variableThatChanged);\n this._addDependentVariablesToUpdateQueue(variableThatChanged);\n\n // Ignore this change if it is currently updating\n if (!this._updating.has(variableThatChanged)) {\n this._updateNextBatch();\n this._notifyDependentSceneObjects(variableThatChanged);\n }\n }\n\n /**\n * This is called by any parent level variable set to notify scene that an update batch is completed.\n * This is the main mechanism lower level variable set's react to changes on higher levels.\n */\n private _handleParentVariableUpdatesCompleted(variable: SceneVariable, hasChanged: boolean) {\n // First loop through changed variables and add any of our variables that depend on the higher level variable to the update queue\n if (hasChanged) {\n this._addDependentVariablesToUpdateQueue(variable);\n }\n\n // If we have variables to update but none are currently updating kick of a new update batch\n if (this._variablesToUpdate.size > 0 && this._updating.size === 0) {\n this._updateNextBatch();\n }\n }\n\n private _addDependentVariablesToUpdateQueue(variableThatChanged: SceneVariable) {\n for (const otherVariable of this.state.variables) {\n if (otherVariable.variableDependency) {\n if (otherVariable.variableDependency.hasDependencyOn(variableThatChanged.state.name)) {\n writeVariableTraceLog(otherVariable, 'Added to update queue, dependant variable value changed');\n\n if (this._updating.has(otherVariable) && otherVariable.onCancel) {\n otherVariable.onCancel();\n }\n\n this._variablesToUpdate.add(otherVariable);\n }\n }\n }\n }\n\n /**\n * Walk scene object graph and update all objects that depend on variables that have changed\n */\n private _notifyDependentSceneObjects(variable: SceneVariable) {\n if (!this.parent) {\n return;\n }\n\n this._traverseSceneAndNotify(this.parent, variable, this._variablesThatHaveChanged.has(variable));\n this._variablesThatHaveChanged.delete(variable);\n }\n\n /**\n * Recursivly walk the full scene object graph and notify all objects with dependencies that include any of changed variables\n */\n private _traverseSceneAndNotify(sceneObject: SceneObject, variable: SceneVariable, hasChanged: boolean) {\n // No need to notify variables under this SceneVariableSet\n if (this === sceneObject) {\n return;\n }\n\n // Skip non active scene objects\n if (!sceneObject.isActive) {\n return;\n }\n\n // If we find a nested SceneVariableSet that has a variable with the same name we stop the traversal\n if (sceneObject.state.$variables && sceneObject.state.$variables !== this) {\n const localVar = sceneObject.state.$variables.getByName(variable.state.name);\n if (localVar) {\n return;\n }\n }\n\n if (sceneObject.variableDependency) {\n sceneObject.variableDependency.variableUpdateCompleted(variable, hasChanged);\n }\n\n sceneObject.forEachChild((child) => this._traverseSceneAndNotify(child, variable, hasChanged));\n }\n\n /**\n * Return true if variable is waiting to update or currently updating.\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 */\n public isVariableLoadingOrWaitingToUpdate(variable: SceneVariable) {\n if (variable.isAncestorLoading && variable.isAncestorLoading()) {\n return true;\n }\n\n if (this._variablesToUpdate.has(variable) || this._updating.has(variable)) {\n return true;\n }\n\n // Last scenario is to check the variable's own dependencies as well\n return sceneGraph.hasVariableDependencyInLoadingState(variable);\n }\n}\n\nexport interface VariableUpdateInProgress {\n variable: SceneVariable;\n subscription?: Unsubscribable;\n}\n\nfunction writeVariableTraceLog(variable: SceneVariable, message: string, err?: Error) {\n if (err) {\n writeSceneLog('SceneVariableSet', `Variable[${variable.state.name}]: ${message}`, err);\n } else {\n writeSceneLog('SceneVariableSet', `Variable[${variable.state.name}]: ${message}`);\n }\n}\n\nclass SceneVariableSetVariableDependencyHandler implements SceneVariableDependencyConfigLike {\n public constructor(private _variableUpdatesCompleted: (variable: SceneVariable, hasChanged: boolean) => void) {}\n\n private _emptySet = new Set<string>();\n\n public getNames(): Set<string> {\n return this._emptySet;\n }\n\n public hasDependencyOn(name: string): boolean {\n return false;\n }\n\n public variableUpdateCompleted(variable: SceneVariable, hasChanged: boolean): void {\n this._variableUpdatesCompleted(variable, hasChanged);\n }\n}\n"],"names":[],"mappings":";;;;;;;AAgBO,MAAM,yBAAyB,eAAiE,CAAA;AAAA,EAwB9F,YAAY,KAA8B,EAAA;AAC/C,IAAA,KAAA,CAAM,KAAK,CAAA,CAAA;AAvBb,IAAQ,IAAA,CAAA,yBAAA,uBAAgC,GAAmB,EAAA,CAAA;AAG3D,IAAQ,IAAA,CAAA,kBAAA,uBAAyB,GAAmB,EAAA,CAAA;AAGpD,IAAQ,IAAA,CAAA,SAAA,uBAAgB,GAA6C,EAAA,CAAA;AAErE,IAAQ,IAAA,CAAA,sBAAA,GAAyB,IAAI,qBAAsB,EAAA,CAAA;AAK3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A,IAAA,CAAA,GAAA,EAAU,WAAW,GAAG,CAAA,CAAA;AAAA,GAChF,MAAA;AACL,IAAA,aAAA,CAAc,kBAAoB,EAAA,CAAA,SAAA,EAAY,QAAS,CAAA,KAAA,CAAM,UAAU,OAAS,CAAA,CAAA,CAAA,CAAA;AAAA,GAClF;AACF,CAAA;AAEA,MAAM,yCAAuF,CAAA;AAAA,EACpF,YAAoB,yBAAmF,EAAA;AAAnF,IAAA,IAAA,CAAA,yBAAA,GAAA,yBAAA,CAAA;AAE3B,IAAQ,IAAA,CAAA,SAAA,uBAAgB,GAAY,EAAA,CAAA;AAAA,GAF2E;AAAA,EAIxG,QAAwB,GAAA;AAC7B,IAAA,OAAO,IAAK,CAAA,SAAA,CAAA;AAAA,GACd;AAAA,EAEO,gBAAgB,IAAuB,EAAA;AAC5C,IAAO,OAAA,KAAA,CAAA;AAAA,GACT;AAAA,EAEO,uBAAA,CAAwB,UAAyB,UAA2B,EAAA;AACjF,IAAK,IAAA,CAAA,yBAAA,CAA0B,UAAU,UAAU,CAAA,CAAA;AAAA,GACrD;AACF;;;;"}
1
+ {"version":3,"file":"SceneVariableSet.js","sources":["../../../../src/variables/sets/SceneVariableSet.ts"],"sourcesContent":["import { VariableRefresh } from '@grafana/data';\nimport { Unsubscribable } from 'rxjs';\nimport { sceneGraph } from '../../core/sceneGraph';\n\nimport { SceneObjectBase } from '../../core/SceneObjectBase';\nimport { SceneObject } from '../../core/types';\nimport { writeSceneLog } from '../../utils/writeSceneLog';\nimport {\n SceneVariable,\n SceneVariableDependencyConfigLike,\n SceneVariableOptionsRefreshEvent,\n SceneVariables,\n SceneVariableSetState,\n SceneVariableValueChangedEvent,\n} from '../types';\nimport { VariableValueRecorder } from '../VariableValueRecorder';\n\nexport class SceneVariableSet extends SceneObjectBase<SceneVariableSetState> implements SceneVariables {\n /** Variables that have changed in since the activation or since the first manual value change */\n private _variablesThatHaveChanged = new Set<SceneVariable>();\n\n /** Variables that are scheduled to be validated and updated */\n private _variablesToUpdate = new Set<SceneVariable>();\n\n /** Variables currently updating */\n private _updating = new Map<SceneVariable, VariableUpdateInProgress>();\n\n private _variableValueRecorder = new VariableValueRecorder();\n\n /**\n * This makes sure SceneVariableSet's higher up in the chain notify us when parent level variables complete update batches.\n **/\n protected _variableDependency = new SceneVariableSetVariableDependencyHandler(\n this._handleParentVariableUpdatesCompleted.bind(this)\n );\n\n public getByName(name: string): SceneVariable | undefined {\n // TODO: Replace with index\n return this.state.variables.find((x) => x.state.name === name);\n }\n\n public constructor(state: SceneVariableSetState) {\n super(state);\n\n this.addActivationHandler(this._onActivate);\n }\n\n /**\n * Subscribes to child variable value changes, and starts the variable value validation process\n */\n private _onActivate = () => {\n const timeRange = sceneGraph.getTimeRange(this);\n // Subscribe to changes to child variables\n this._subs.add(\n this.subscribeToEvent(SceneVariableValueChangedEvent, (event) => this._handleVariableValueChanged(event.payload))\n );\n\n // Subscribe to variable options changes\n this._subs.add(\n this.subscribeToEvent(SceneVariableOptionsRefreshEvent, (event) => this._handleVariableOptionsUpdate(event.payload))\n );\n\n this._subs.add(\n timeRange.subscribeToState(() => {\n this._refreshTimeRangeBasedVariables();\n })\n );\n\n // Subscribe to state changes\n this._subs.add(this.subscribeToState(this._onStateChanged));\n\n this._checkForVariablesThatChangedWhileInactive();\n\n // Add all variables that need updating to queue\n for (const variable of this.state.variables) {\n if (this._variableNeedsUpdate(variable)) {\n this._variablesToUpdate.add(variable);\n }\n }\n\n this._updateNextBatch();\n\n // Return deactivation handler;\n return this._onDeactivate;\n };\n\n /**\n * Add all variables that depend on the changed variable to the update queue\n */\n private _refreshTimeRangeBasedVariables() {\n for (const variable of this.state.variables) {\n if ('refresh' in variable.state && variable.state.refresh === VariableRefresh.onTimeRangeChanged) {\n this._variablesToUpdate.add(variable);\n }\n }\n\n this._updateNextBatch();\n }\n\n /**\n * Cancel all currently running updates\n */\n private _onDeactivate = () => {\n for (const update of this._updating.values()) {\n update.subscription?.unsubscribe();\n }\n\n // Remember current variable values\n for (const variable of this.state.variables) {\n // if the current variable is not in queue to update and validate and not being actively updated then the value is ok\n if (!this._variablesToUpdate.has(variable) && !this._updating.has(variable)) {\n this._variableValueRecorder.recordCurrentValue(variable);\n }\n }\n\n this._variablesToUpdate.clear();\n this._updating.clear();\n };\n\n /**\n * Look for new variables that need to be initialized\n */\n private _onStateChanged = (newState: SceneVariableSetState, oldState: SceneVariableSetState) => {\n const variablesToUpdateCountStart = this._variablesToUpdate.size;\n\n // Check for removed variables\n for (const variable of oldState.variables) {\n if (!newState.variables.includes(variable)) {\n const updating = this._updating.get(variable);\n if (updating?.subscription) {\n updating.subscription.unsubscribe();\n }\n this._updating.delete(variable);\n this._variablesToUpdate.delete(variable);\n }\n }\n\n // Check for new variables\n for (const variable of newState.variables) {\n if (!oldState.variables.includes(variable)) {\n if (this._variableNeedsUpdate(variable)) {\n this._variablesToUpdate.add(variable);\n }\n }\n }\n\n // Only start a new batch if there was no batch already running\n if (variablesToUpdateCountStart === 0 && this._variablesToUpdate.size > 0) {\n this._updateNextBatch();\n }\n };\n\n /**\n * If variables changed while in in-active state we don't get any change events, so we need to check for that here.\n */\n private _checkForVariablesThatChangedWhileInactive() {\n if (!this._variableValueRecorder.hasValues()) {\n return;\n }\n\n for (const variable of this.state.variables) {\n if (this._variableValueRecorder.hasValueChanged(variable)) {\n writeVariableTraceLog(variable, 'Changed while in-active');\n this._addDependentVariablesToUpdateQueue(variable);\n }\n }\n }\n\n private _variableNeedsUpdate(variable: SceneVariable): boolean {\n if (variable.isLazy) {\n return false;\n }\n\n if (!variable.validateAndUpdate) {\n return false;\n }\n\n // If we have recorded valid value (even if it has changed since we do not need to re-validate this variable)\n if (this._variableValueRecorder.hasRecordedValue(variable)) {\n writeVariableTraceLog(variable, 'Skipping updateAndValidate current value valid');\n return false;\n }\n\n return true;\n }\n\n /**\n * This loops through variablesToUpdate and update all that can.\n * If one has a dependency that is currently in variablesToUpdate it will be skipped for now.\n */\n private _updateNextBatch() {\n for (const variable of this._variablesToUpdate) {\n if (!variable.validateAndUpdate) {\n throw new Error('Variable added to variablesToUpdate but does not have validateAndUpdate');\n }\n\n // Ignore it if it's already started\n if (this._updating.has(variable)) {\n continue;\n }\n\n // Wait for variables that has dependencies that also needs updates\n if (sceneGraph.hasVariableDependencyInLoadingState(variable)) {\n continue;\n }\n\n const variableToUpdate: VariableUpdateInProgress = {\n variable,\n };\n\n this._updating.set(variable, variableToUpdate);\n writeVariableTraceLog(variable, 'updateAndValidate started');\n\n variableToUpdate.subscription = variable.validateAndUpdate().subscribe({\n next: () => this._validateAndUpdateCompleted(variable),\n complete: () => this._validateAndUpdateCompleted(variable),\n error: (err) => this._handleVariableError(variable, err),\n });\n }\n }\n\n /**\n * A variable has completed its update process. This could mean that variables that depend on it can now be updated in turn.\n */\n private _validateAndUpdateCompleted(variable: SceneVariable) {\n if (!this._updating.has(variable)) {\n return;\n }\n\n const update = this._updating.get(variable);\n update?.subscription?.unsubscribe();\n\n this._updating.delete(variable);\n this._variablesToUpdate.delete(variable);\n\n writeVariableTraceLog(variable, 'updateAndValidate completed');\n\n this._notifyDependentSceneObjects(variable);\n this._updateNextBatch();\n }\n\n public cancel(variable: SceneVariable) {\n const update = this._updating.get(variable);\n update?.subscription?.unsubscribe();\n\n this._updating.delete(variable);\n this._variablesToUpdate.delete(variable);\n }\n\n private _handleVariableError(variable: SceneVariable, err: Error) {\n const update = this._updating.get(variable);\n update?.subscription?.unsubscribe();\n\n this._updating.delete(variable);\n this._variablesToUpdate.delete(variable);\n\n variable.setState({ loading: false, error: err.message });\n\n console.error('SceneVariableSet updateAndValidate error', err);\n\n writeVariableTraceLog(variable, 'updateAndValidate error', err);\n }\n\n private _handleVariableOptionsUpdate(variable: SceneVariable) {\n this._variablesToUpdate.add(variable);\n\n this._updateNextBatch();\n }\n\n private _handleVariableValueChanged(variableThatChanged: SceneVariable) {\n this._variablesThatHaveChanged.add(variableThatChanged);\n this._addDependentVariablesToUpdateQueue(variableThatChanged);\n\n // Ignore this change if it is currently updating\n if (!this._updating.has(variableThatChanged)) {\n this._updateNextBatch();\n this._notifyDependentSceneObjects(variableThatChanged);\n }\n }\n\n /**\n * This is called by any parent level variable set to notify scene that an update batch is completed.\n * This is the main mechanism lower level variable set's react to changes on higher levels.\n */\n private _handleParentVariableUpdatesCompleted(variable: SceneVariable, hasChanged: boolean) {\n // First loop through changed variables and add any of our variables that depend on the higher level variable to the update queue\n if (hasChanged) {\n this._addDependentVariablesToUpdateQueue(variable);\n }\n\n // If we have variables to update but none are currently updating kick of a new update batch\n if (this._variablesToUpdate.size > 0 && this._updating.size === 0) {\n this._updateNextBatch();\n }\n }\n\n private _addDependentVariablesToUpdateQueue(variableThatChanged: SceneVariable) {\n for (const otherVariable of this.state.variables) {\n if (otherVariable.variableDependency) {\n if (otherVariable.variableDependency.hasDependencyOn(variableThatChanged.state.name)) {\n writeVariableTraceLog(otherVariable, 'Added to update queue, dependant variable value changed');\n\n if (this._updating.has(otherVariable) && otherVariable.onCancel) {\n otherVariable.onCancel();\n }\n\n this._variablesToUpdate.add(otherVariable);\n }\n }\n }\n }\n\n /**\n * Walk scene object graph and update all objects that depend on variables that have changed\n */\n private _notifyDependentSceneObjects(variable: SceneVariable) {\n if (!this.parent) {\n return;\n }\n\n this._traverseSceneAndNotify(this.parent, variable, this._variablesThatHaveChanged.has(variable));\n this._variablesThatHaveChanged.delete(variable);\n }\n\n /**\n * Recursivly walk the full scene object graph and notify all objects with dependencies that include any of changed variables\n */\n private _traverseSceneAndNotify(sceneObject: SceneObject, variable: SceneVariable, hasChanged: boolean) {\n // No need to notify variables under this SceneVariableSet\n if (this === sceneObject) {\n return;\n }\n\n // Skip non active scene objects\n if (!sceneObject.isActive) {\n return;\n }\n\n // If we find a nested SceneVariableSet that has a variable with the same name we stop the traversal\n if (sceneObject.state.$variables && sceneObject.state.$variables !== this) {\n const localVar = sceneObject.state.$variables.getByName(variable.state.name);\n if (localVar) {\n return;\n }\n }\n\n if (sceneObject.variableDependency) {\n sceneObject.variableDependency.variableUpdateCompleted(variable, hasChanged);\n }\n\n sceneObject.forEachChild((child) => this._traverseSceneAndNotify(child, variable, hasChanged));\n }\n\n /**\n * Return true if variable is waiting to update or currently updating.\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 */\n public isVariableLoadingOrWaitingToUpdate(variable: SceneVariable) {\n if (variable.isAncestorLoading && variable.isAncestorLoading()) {\n return true;\n }\n\n if (this._variablesToUpdate.has(variable) || this._updating.has(variable)) {\n return true;\n }\n\n // Last scenario is to check the variable's own dependencies as well\n return sceneGraph.hasVariableDependencyInLoadingState(variable);\n }\n}\n\nexport interface VariableUpdateInProgress {\n variable: SceneVariable;\n subscription?: Unsubscribable;\n}\n\nfunction writeVariableTraceLog(variable: SceneVariable, message: string, err?: Error) {\n if (err) {\n writeSceneLog('SceneVariableSet', `Variable[${variable.state.name}]: ${message}`, err);\n } else {\n writeSceneLog('SceneVariableSet', `Variable[${variable.state.name}]: ${message}`);\n }\n}\n\nclass SceneVariableSetVariableDependencyHandler implements SceneVariableDependencyConfigLike {\n public constructor(private _variableUpdatesCompleted: (variable: SceneVariable, hasChanged: boolean) => void) {}\n\n private _emptySet = new Set<string>();\n\n public getNames(): Set<string> {\n return this._emptySet;\n }\n\n public hasDependencyOn(name: string): boolean {\n return false;\n }\n\n public variableUpdateCompleted(variable: SceneVariable, hasChanged: boolean): void {\n this._variableUpdatesCompleted(variable, hasChanged);\n }\n}\n"],"names":[],"mappings":";;;;;;;AAiBO,MAAM,yBAAyB,eAAiE,CAAA;AAAA,EAwB9F,YAAY,KAA8B,EAAA;AAC/C,IAAA,KAAA,CAAM,KAAK,CAAA,CAAA;AAvBb,IAAQ,IAAA,CAAA,yBAAA,uBAAgC,GAAmB,EAAA,CAAA;AAG3D,IAAQ,IAAA,CAAA,kBAAA,uBAAyB,GAAmB,EAAA,CAAA;AAGpD,IAAQ,IAAA,CAAA,SAAA,uBAAgB,GAA6C,EA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A,KACT;AAEA,IAAI,IAAA,IAAA,CAAK,mBAAmB,GAAI,CAAA,QAAQ,KAAK,IAAK,CAAA,SAAA,CAAU,GAAI,CAAA,QAAQ,CAAG,EAAA;AACzE,MAAO,OAAA,IAAA,CAAA;AAAA,KACT;AAGA,IAAO,OAAA,UAAA,CAAW,oCAAoC,QAAQ,CAAA,CAAA;AAAA,GAChE;AACF,CAAA;AAOA,SAAS,qBAAA,CAAsB,QAAyB,EAAA,OAAA,EAAiB,GAAa,EAAA;AACpF,EAAA,IAAI,GAAK,EAAA;AACP,IAAA,aAAA,CAAc,oBAAoB,CAAY,SAAA,EAAA,QAAA,CAAS,KAAM,CAAA,IAAA,CAAA,GAAA,EAAU,WAAW,GAAG,CAAA,CAAA;AAAA,GAChF,MAAA;AACL,IAAA,aAAA,CAAc,kBAAoB,EAAA,CAAA,SAAA,EAAY,QAAS,CAAA,KAAA,CAAM,UAAU,OAAS,CAAA,CAAA,CAAA,CAAA;AAAA,GAClF;AACF,CAAA;AAEA,MAAM,yCAAuF,CAAA;AAAA,EACpF,YAAoB,yBAAmF,EAAA;AAAnF,IAAA,IAAA,CAAA,yBAAA,GAAA,yBAAA,CAAA;AAE3B,IAAQ,IAAA,CAAA,SAAA,uBAAgB,GAAY,EAAA,CAAA;AAAA,GAF2E;AAAA,EAIxG,QAAwB,GAAA;AAC7B,IAAA,OAAO,IAAK,CAAA,SAAA,CAAA;AAAA,GACd;AAAA,EAEO,gBAAgB,IAAuB,EAAA;AAC5C,IAAO,OAAA,KAAA,CAAA;AAAA,GACT;AAAA,EAEO,uBAAA,CAAwB,UAAyB,UAA2B,EAAA;AACjF,IAAK,IAAA,CAAA,yBAAA,CAA0B,UAAU,UAAU,CAAA,CAAA;AAAA,GACrD;AACF;;;;"}
@@ -3,9 +3,12 @@ import { BusEventWithPayload } from '@grafana/data';
3
3
  class SceneVariableValueChangedEvent extends BusEventWithPayload {
4
4
  }
5
5
  SceneVariableValueChangedEvent.type = "scene-variable-changed-value";
6
+ class SceneVariableOptionsRefreshEvent extends BusEventWithPayload {
7
+ }
8
+ SceneVariableOptionsRefreshEvent.type = "scene-variable-options-refresh";
6
9
  function isCustomVariableValue(value) {
7
10
  return typeof value === "object" && "formatter" in value;
8
11
  }
9
12
 
10
- export { SceneVariableValueChangedEvent, isCustomVariableValue };
13
+ export { SceneVariableOptionsRefreshEvent, SceneVariableValueChangedEvent, isCustomVariableValue };
11
14
  //# sourceMappingURL=types.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"types.js","sources":["../../../src/variables/types.ts"],"sourcesContent":["import { Observable } from 'rxjs';\n\nimport { BusEventWithPayload } from '@grafana/data';\nimport { VariableType, VariableHide } from '@grafana/schema';\n\nimport { SceneObject, SceneObjectState } from '../core/types';\n\nexport interface SceneVariableState extends SceneObjectState {\n type: VariableType;\n name: string;\n label?: string;\n hide?: VariableHide;\n skipUrlSync?: boolean;\n loading?: boolean;\n error?: any | null;\n description?: string | null;\n}\n\nexport interface SceneVariable<TState extends SceneVariableState = SceneVariableState> extends SceneObject<TState> {\n /**\n * This function is called on activation or when a dependency changes.\n */\n validateAndUpdate?(): Observable<ValidateAndUpdateResult>;\n\n /**\n * Should return the value for the given field path\n */\n getValue(fieldPath?: string): VariableValue | undefined | null;\n\n /**\n * Should return the value display text, used by the \"text\" formatter\n * Example: ${podId:text}\n * Useful for variables that have non user friendly values but friendly display text names.\n */\n getValueText?(fieldPath?: string): string;\n\n /**\n * A special function that locally scoped variables can implement\n **/\n isAncestorLoading?(): boolean;\n\n /**\n * Allows cancelling variable execution.\n */\n onCancel?(): void;\n\n /**\n * @experimental\n * Indicates that a variable loads values lazily when user interacts with the variable dropdown.\n */\n isLazy?: boolean;\n}\n\nexport type VariableValue = VariableValueSingle | VariableValueSingle[];\n\nexport type VariableValueSingle = string | boolean | number | CustomVariableValue;\n\n/**\n * This is for edge case values like the custom \"allValue\" that should not be escaped/formatted like other values\n * The custom all value usually contain wildcards that should not be escaped.\n */\nexport interface CustomVariableValue {\n /**\n * The format name or function used in the expression\n */\n formatter(formatNameOrFn?: string | VariableCustomFormatterFn): string;\n}\n\nexport interface ValidateAndUpdateResult {}\nexport interface VariableValueOption {\n label: string;\n value: VariableValueSingle;\n}\n\nexport interface SceneVariableSetState extends SceneObjectState {\n variables: SceneVariable[];\n}\n\nexport interface SceneVariables extends SceneObject<SceneVariableSetState> {\n /**\n * Will look for and return variable matching name\n */\n getByName(name: string): SceneVariable | undefined;\n /**\n * Will return true if the variable is loading or waiting for an update to complete.\n */\n isVariableLoadingOrWaitingToUpdate(variable: SceneVariable): boolean;\n}\n\nexport class SceneVariableValueChangedEvent extends BusEventWithPayload<SceneVariable> {\n public static type = 'scene-variable-changed-value';\n}\n\nexport interface SceneVariableDependencyConfigLike {\n /** Return all variable names this object depend on */\n getNames(): Set<string>;\n\n /** Used to check for dependency on a specific variable */\n hasDependencyOn(name: string): boolean;\n\n /**\n * Will be called when the VariableSet have completed an update process or when a variable has changed value.\n **/\n variableUpdateCompleted(variable: SceneVariable, hasChanged: boolean): void;\n}\n\n/**\n * Used in CustomFormatterFn\n */\nexport interface CustomFormatterVariable {\n name: string;\n type: VariableType;\n multi?: boolean;\n includeAll?: boolean;\n}\n\nexport type VariableCustomFormatterFn = (\n value: unknown,\n legacyVariableModel: Partial<CustomFormatterVariable>,\n legacyDefaultFormatter?: VariableCustomFormatterFn\n) => string;\n\nexport type InterpolationFormatParameter = string | VariableCustomFormatterFn | undefined;\n\nexport function isCustomVariableValue(value: VariableValue): value is CustomVariableValue {\n return typeof value === 'object' && 'formatter' in value;\n}\n"],"names":[],"mappings":";;AAyFO,MAAM,uCAAuC,mBAAmC,CAAA;AAEvF,CAAA;AAFa,8BAAA,CACG,IAAO,GAAA,8BAAA,CAAA;AAkChB,SAAS,sBAAsB,KAAoD,EAAA;AACxF,EAAO,OAAA,OAAO,KAAU,KAAA,QAAA,IAAY,WAAe,IAAA,KAAA,CAAA;AACrD;;;;"}
1
+ {"version":3,"file":"types.js","sources":["../../../src/variables/types.ts"],"sourcesContent":["import { Observable } from 'rxjs';\n\nimport { BusEventWithPayload } from '@grafana/data';\nimport { VariableType, VariableHide } from '@grafana/schema';\n\nimport { SceneObject, SceneObjectState } from '../core/types';\n\nexport interface SceneVariableState extends SceneObjectState {\n type: VariableType;\n name: string;\n label?: string;\n hide?: VariableHide;\n skipUrlSync?: boolean;\n loading?: boolean;\n error?: any | null;\n description?: string | null;\n}\n\nexport interface SceneVariable<TState extends SceneVariableState = SceneVariableState> extends SceneObject<TState> {\n /**\n * This function is called on activation or when a dependency changes.\n */\n validateAndUpdate?(): Observable<ValidateAndUpdateResult>;\n\n /**\n * Should return the value for the given field path\n */\n getValue(fieldPath?: string): VariableValue | undefined | null;\n\n /**\n * Should return the value display text, used by the \"text\" formatter\n * Example: ${podId:text}\n * Useful for variables that have non user friendly values but friendly display text names.\n */\n getValueText?(fieldPath?: string): string;\n\n /**\n * A special function that locally scoped variables can implement\n **/\n isAncestorLoading?(): boolean;\n\n /**\n * Allows cancelling variable execution.\n */\n onCancel?(): void;\n\n /**\n * @experimental\n * Indicates that a variable loads values lazily when user interacts with the variable dropdown.\n */\n isLazy?: boolean;\n}\n\nexport type VariableValue = VariableValueSingle | VariableValueSingle[];\n\nexport type VariableValueSingle = string | boolean | number | CustomVariableValue;\n\n/**\n * This is for edge case values like the custom \"allValue\" that should not be escaped/formatted like other values\n * The custom all value usually contain wildcards that should not be escaped.\n */\nexport interface CustomVariableValue {\n /**\n * The format name or function used in the expression\n */\n formatter(formatNameOrFn?: string | VariableCustomFormatterFn): string;\n}\n\nexport interface ValidateAndUpdateResult {}\nexport interface VariableValueOption {\n label: string;\n value: VariableValueSingle;\n}\n\nexport interface SceneVariableSetState extends SceneObjectState {\n variables: SceneVariable[];\n}\n\nexport interface SceneVariables extends SceneObject<SceneVariableSetState> {\n /**\n * Will look for and return variable matching name\n */\n getByName(name: string): SceneVariable | undefined;\n /**\n * Will return true if the variable is loading or waiting for an update to complete.\n */\n isVariableLoadingOrWaitingToUpdate(variable: SceneVariable): boolean;\n}\n\nexport class SceneVariableValueChangedEvent extends BusEventWithPayload<SceneVariable> {\n public static type = 'scene-variable-changed-value';\n}\n\nexport class SceneVariableOptionsRefreshEvent extends BusEventWithPayload<SceneVariable> {\n public static type = 'scene-variable-options-refresh';\n}\n\nexport interface SceneVariableDependencyConfigLike {\n /** Return all variable names this object depend on */\n getNames(): Set<string>;\n\n /** Used to check for dependency on a specific variable */\n hasDependencyOn(name: string): boolean;\n\n /**\n * Will be called when the VariableSet have completed an update process or when a variable has changed value.\n **/\n variableUpdateCompleted(variable: SceneVariable, hasChanged: boolean): void;\n}\n\n/**\n * Used in CustomFormatterFn\n */\nexport interface CustomFormatterVariable {\n name: string;\n type: VariableType;\n multi?: boolean;\n includeAll?: boolean;\n}\n\nexport type VariableCustomFormatterFn = (\n value: unknown,\n legacyVariableModel: Partial<CustomFormatterVariable>,\n legacyDefaultFormatter?: VariableCustomFormatterFn\n) => string;\n\nexport type InterpolationFormatParameter = string | VariableCustomFormatterFn | undefined;\n\nexport function isCustomVariableValue(value: VariableValue): value is CustomVariableValue {\n return typeof value === 'object' && 'formatter' in value;\n}\n"],"names":[],"mappings":";;AAyFO,MAAM,uCAAuC,mBAAmC,CAAA;AAEvF,CAAA;AAFa,8BAAA,CACG,IAAO,GAAA,8BAAA,CAAA;AAGhB,MAAM,yCAAyC,mBAAmC,CAAA;AAEzF,CAAA;AAFa,gCAAA,CACG,IAAO,GAAA,gCAAA,CAAA;AAkChB,SAAS,sBAAsB,KAAoD,EAAA;AACxF,EAAO,OAAA,OAAO,KAAU,KAAA,QAAA,IAAY,WAAe,IAAA,KAAA,CAAA;AACrD;;;;"}
@@ -2,7 +2,7 @@ import { isEqual, isArray } from 'lodash';
2
2
  import { map } from 'rxjs';
3
3
  import { ALL_VARIABLE_VALUE, ALL_VARIABLE_TEXT } from '../constants.js';
4
4
  import { SceneObjectBase } from '../../core/SceneObjectBase.js';
5
- import { SceneVariableValueChangedEvent } from '../types.js';
5
+ import { SceneVariableValueChangedEvent, SceneVariableOptionsRefreshEvent } from '../types.js';
6
6
  import { formatRegistry } from '../interpolation/formatRegistry.js';
7
7
  import { VariableFormatID } from '@grafana/schema';
8
8
  import { setBaseClassState } from '../../utils/utils.js';
@@ -200,6 +200,9 @@ class MultiValueVariable extends SceneObjectBase {
200
200
  }
201
201
  return options;
202
202
  }
203
+ refreshOptions() {
204
+ this.publishEvent(new SceneVariableOptionsRefreshEvent(this), true);
205
+ }
203
206
  }
204
207
  function findOptionMatchingCurrent(currentValue, currentText, options) {
205
208
  let textMatch;
@@ -1 +1 @@
1
- {"version":3,"file":"MultiValueVariable.js","sources":["../../../../src/variables/variants/MultiValueVariable.ts"],"sourcesContent":["import { isArray, isEqual } from 'lodash';\nimport { map, Observable } from 'rxjs';\n\nimport { ALL_VARIABLE_TEXT, ALL_VARIABLE_VALUE } from '../constants';\n\nimport { SceneObjectBase } from '../../core/SceneObjectBase';\nimport { SceneObjectUrlSyncHandler, SceneObjectUrlValues } from '../../core/types';\nimport {\n SceneVariable,\n SceneVariableValueChangedEvent,\n SceneVariableState,\n ValidateAndUpdateResult,\n VariableValue,\n VariableValueOption,\n VariableValueSingle,\n CustomVariableValue,\n VariableCustomFormatterFn,\n} from '../types';\nimport { formatRegistry } from '../interpolation/formatRegistry';\nimport { VariableFormatID } from '@grafana/schema';\nimport { SceneVariableSet } from '../sets/SceneVariableSet';\nimport { setBaseClassState } from '../../utils/utils';\n\nexport interface MultiValueVariableState extends SceneVariableState {\n value: VariableValue; // old current.text\n text: VariableValue; // old current.value\n options: VariableValueOption[];\n isMulti?: boolean;\n includeAll?: boolean;\n defaultToAll?: boolean;\n allValue?: string;\n placeholder?: string;\n /**\n * For multi value variables, this option controls how many values to show before they are collapsed into +N.\n * Defaults to 5\n */\n maxVisibleValues?: number;\n noValueOnClear?: boolean;\n isReadOnly?: boolean;\n}\n\nexport interface VariableGetOptionsArgs {\n searchFilter?: string;\n}\n\nexport abstract class MultiValueVariable<TState extends MultiValueVariableState = MultiValueVariableState>\n extends SceneObjectBase<TState>\n implements SceneVariable<TState>\n{\n protected _urlSync: SceneObjectUrlSyncHandler = new MultiValueUrlSyncHandler(this);\n\n /**\n * Set to true to skip next value validation to maintain the current value even it it's not among the options (ie valid values)\n */\n public skipNextValidation?: boolean;\n\n /**\n * The source of value options.\n */\n public abstract getValueOptions(args: VariableGetOptionsArgs): Observable<VariableValueOption[]>;\n\n /**\n * This function is called on when SceneVariableSet is activated or when a dependency changes.\n */\n public validateAndUpdate(): Observable<ValidateAndUpdateResult> {\n return this.getValueOptions({}).pipe(\n map((options) => {\n this.updateValueGivenNewOptions(options);\n return {};\n })\n );\n }\n\n public onCancel(): void {\n this.setStateHelper({ loading: false });\n const sceneVarSet = this.parent as SceneVariableSet;\n sceneVarSet?.cancel(this);\n }\n\n /**\n * Check if current value is valid given new options. If not update the value.\n */\n private updateValueGivenNewOptions(options: VariableValueOption[]) {\n // Remember current value and text\n const { value: currentValue, text: currentText } = this.state;\n\n const stateUpdate = this.getStateUpdateGivenNewOptions(options, currentValue, currentText);\n\n this.interceptStateUpdateAfterValidation(stateUpdate);\n\n // Perform state change\n this.setStateHelper(stateUpdate);\n\n // Publish value changed event only if value changed\n if (stateUpdate.value !== currentValue || stateUpdate.text !== currentText || this.hasAllValue()) {\n this.publishEvent(new SceneVariableValueChangedEvent(this), true);\n }\n }\n\n private getStateUpdateGivenNewOptions(\n options: VariableValueOption[],\n currentValue: VariableValue,\n currentText: VariableValue\n ): Partial<MultiValueVariableState> {\n const stateUpdate: Partial<MultiValueVariableState> = {\n options,\n loading: false,\n value: currentValue,\n text: currentText,\n };\n\n if (options.length === 0) {\n if (this.state.defaultToAll || this.state.includeAll) {\n stateUpdate.value = ALL_VARIABLE_VALUE;\n stateUpdate.text = ALL_VARIABLE_TEXT;\n } else if (this.state.isMulti) {\n stateUpdate.value = [];\n stateUpdate.text = [];\n } else {\n stateUpdate.value = '';\n stateUpdate.text = '';\n }\n\n return stateUpdate;\n }\n\n if (this.hasAllValue()) {\n if (!this.state.includeAll) {\n stateUpdate.value = options[0].value;\n stateUpdate.text = options[0].label;\n // If multi switch to arrays\n if (this.state.isMulti) {\n stateUpdate.value = [stateUpdate.value];\n stateUpdate.text = [stateUpdate.text];\n }\n }\n return stateUpdate;\n }\n\n if (this.state.isMulti) {\n // If we are a multi valued variable validate the current values are among the options\n const currentValues = Array.isArray(currentValue) ? currentValue : [currentValue];\n const validValues = currentValues.filter((v) => options.find((o) => o.value === v));\n const validTexts = validValues.map((v) => options.find((o) => o.value === v)!.label);\n\n // If no valid values pick the first option\n if (validValues.length === 0) {\n const defaultState = this.getDefaultMultiState(options);\n stateUpdate.value = defaultState.value;\n stateUpdate.text = defaultState.text;\n } else {\n // We have valid values, if it's different from current valid values update current values\n if (!isEqual(validValues, currentValue)) {\n stateUpdate.value = validValues;\n }\n if (!isEqual(validTexts, currentText)) {\n stateUpdate.text = validTexts;\n }\n }\n return stateUpdate;\n }\n\n // Single value variable validation\n\n // Try find by value then text\n let matchingOption = findOptionMatchingCurrent(currentValue, currentText, options);\n if (matchingOption) {\n // When updating the initial state from URL the text property is set the same as value\n // Here we can correct the text value state\n stateUpdate.text = matchingOption.label;\n stateUpdate.value = matchingOption.value;\n } else {\n // Current value is found in options\n if (this.state.defaultToAll) {\n stateUpdate.value = ALL_VARIABLE_VALUE;\n stateUpdate.text = ALL_VARIABLE_TEXT;\n } else {\n // Current value is not valid. Set to first of the available options\n stateUpdate.value = options[0].value;\n stateUpdate.text = options[0].label;\n }\n }\n\n return stateUpdate;\n }\n\n /**\n * Values set by initial URL sync needs to survive the next validation and update.\n * This function can intercept and make sure those values are preserved.\n */\n protected interceptStateUpdateAfterValidation(stateUpdate: Partial<MultiValueVariableState>): void {\n // If the validation wants to fix the all value (All ==> $__all) then we should let that pass\n const isAllValueFix = stateUpdate.value === ALL_VARIABLE_VALUE && this.state.text === ALL_VARIABLE_TEXT;\n\n if (this.skipNextValidation && stateUpdate.value !== this.state.value && !isAllValueFix) {\n stateUpdate.value = this.state.value;\n stateUpdate.text = this.state.text;\n }\n\n this.skipNextValidation = false;\n }\n\n public getValue(): VariableValue {\n if (this.hasAllValue()) {\n if (this.state.allValue) {\n return new CustomAllValue(this.state.allValue, this);\n }\n\n return this.state.options.map((x) => x.value);\n }\n\n return this.state.value;\n }\n\n public getValueText(): string {\n if (this.hasAllValue()) {\n return ALL_VARIABLE_TEXT;\n }\n\n if (Array.isArray(this.state.text)) {\n return this.state.text.join(' + ');\n }\n\n return String(this.state.text);\n }\n\n public hasAllValue() {\n const value = this.state.value;\n return value === ALL_VARIABLE_VALUE || (Array.isArray(value) && value[0] === ALL_VARIABLE_VALUE);\n }\n\n public getDefaultMultiState(options: VariableValueOption[]) {\n if (this.state.defaultToAll) {\n return { value: [ALL_VARIABLE_VALUE], text: [ALL_VARIABLE_TEXT] };\n } else if (options.length > 0) {\n return { value: [options[0].value], text: [options[0].label] };\n } else {\n return { value: [], text: [] };\n }\n }\n\n /**\n * Change the value and publish SceneVariableValueChangedEvent event.\n */\n public changeValueTo(value: VariableValue, text?: VariableValue) {\n // Ignore if there is no change\n if (value === this.state.value && text === this.state.text) {\n return;\n }\n\n if (!text) {\n if (Array.isArray(value)) {\n text = value.map((v) => this.findLabelTextForValue(v));\n } else {\n text = this.findLabelTextForValue(value);\n }\n }\n\n if (Array.isArray(value)) {\n // If we are a multi valued variable is cleared (empty array) we need to set the default empty state\n if (value.length === 0) {\n const state = this.getDefaultMultiState(this.state.options);\n value = state.value;\n text = state.text;\n }\n\n // If last value is the All value then replace all with it\n if (value[value.length - 1] === ALL_VARIABLE_VALUE) {\n value = [ALL_VARIABLE_VALUE];\n text = [ALL_VARIABLE_TEXT];\n }\n // If the first value is the ALL value and we have other values, then remove the All value\n else if (value[0] === ALL_VARIABLE_VALUE && value.length > 1) {\n value.shift();\n if (Array.isArray(text)) {\n text.shift();\n }\n }\n }\n\n // Do nothing if value and text are the same\n if (isEqual(value, this.state.value) && isEqual(text, this.state.text)) {\n return;\n }\n\n this.setStateHelper({ value, text, loading: false });\n this.publishEvent(new SceneVariableValueChangedEvent(this), true);\n }\n\n private findLabelTextForValue(value: VariableValueSingle): VariableValueSingle {\n if (value === ALL_VARIABLE_VALUE) {\n return ALL_VARIABLE_TEXT;\n }\n\n const option = this.state.options.find((x) => x.value === value);\n if (option) {\n return option.label;\n }\n\n const optionByLabel = this.state.options.find((x) => x.label === value);\n if (optionByLabel) {\n return optionByLabel.label;\n }\n\n return value;\n }\n\n /**\n * This helper function is to counter the contravariance of setState\n */\n private setStateHelper(state: Partial<MultiValueVariableState>) {\n setBaseClassState<MultiValueVariableState>(this, state);\n }\n\n public getOptionsForSelect(): VariableValueOption[] {\n let options = this.state.options;\n\n if (this.state.includeAll) {\n options = [{ value: ALL_VARIABLE_VALUE, label: ALL_VARIABLE_TEXT }, ...options];\n }\n\n if (!Array.isArray(this.state.value)) {\n const current = options.find((x) => x.value === this.state.value);\n if (!current) {\n options = [{ value: this.state.value, label: String(this.state.text) }, ...options];\n }\n }\n\n return options;\n }\n\n /**\n * Can be used by subclasses to do custom handling of option search based on search input\n */\n public onSearchChange?(searchFilter: string): void;\n}\n\n/**\n * Looks for matching option, first by value but as a fallback by text (label).\n */\nfunction findOptionMatchingCurrent(\n currentValue: VariableValue,\n currentText: VariableValue,\n options: VariableValueOption[]\n) {\n let textMatch: VariableValueOption | undefined;\n\n for (const item of options) {\n if (item.value === currentValue) {\n return item;\n }\n\n // No early return here as want to continue to look a value match\n if (item.label === currentText) {\n textMatch = item;\n }\n }\n\n return textMatch;\n}\n\nexport class MultiValueUrlSyncHandler<TState extends MultiValueVariableState = MultiValueVariableState>\n implements SceneObjectUrlSyncHandler\n{\n public constructor(private _sceneObject: MultiValueVariable<TState>) {}\n\n private getKey(): string {\n return `var-${this._sceneObject.state.name}`;\n }\n\n public getKeys(): string[] {\n if (this._sceneObject.state.skipUrlSync) {\n return [];\n }\n\n return [this.getKey()];\n }\n\n public getUrlState(): SceneObjectUrlValues {\n if (this._sceneObject.state.skipUrlSync) {\n return {};\n }\n\n let urlValue: string | string[] | null = null;\n let value = this._sceneObject.state.value;\n\n if (Array.isArray(value)) {\n urlValue = value.map(String);\n } else if ((this, this._sceneObject.state.isMulti)) {\n // If we are inMulti mode we must return an array here as otherwise UrlSyncManager will not pass all values (in an array) in updateFromUrl\n urlValue = [String(value)];\n } else {\n urlValue = String(value);\n }\n\n return { [this.getKey()]: urlValue };\n }\n\n public updateFromUrl(values: SceneObjectUrlValues): void {\n let urlValue = values[this.getKey()];\n\n if (urlValue != null) {\n // This is to be backwards compatible with old url all value\n if (this._sceneObject.state.includeAll) {\n urlValue = handleLegacyUrlAllValue(urlValue);\n }\n\n // For edge cases where data links include variables with custom all value.\n // We want the variable to maintain the \"All\" meta value not the actual custom vall value. (Fixes https://github.com/grafana/grafana/issues/28635)\n if (this._sceneObject.state.allValue && this._sceneObject.state.allValue === urlValue) {\n urlValue = ALL_VARIABLE_VALUE;\n }\n\n /**\n * Initial URL Sync happens before scene objects are activated.\n * We need to skip validation in this case to make sure values set via URL are maintained.\n */\n if (!this._sceneObject.isActive) {\n this._sceneObject.skipNextValidation = true;\n }\n\n this._sceneObject.changeValueTo(urlValue);\n }\n }\n}\n\nfunction handleLegacyUrlAllValue(value: string | string[]) {\n if (isArray(value) && value[0] === ALL_VARIABLE_TEXT) {\n return [ALL_VARIABLE_VALUE];\n } else if (value === ALL_VARIABLE_TEXT) {\n return ALL_VARIABLE_VALUE;\n }\n\n return value;\n}\n\n/**\n * Variable getValue can return this to skip any subsequent formatting.\n * This is useful for custom all values that should not be escaped/formatted.\n */\nexport class CustomAllValue implements CustomVariableValue {\n public constructor(private _value: string, private _variable: SceneVariable) {}\n\n public formatter(formatNameOrFn?: string | VariableCustomFormatterFn): string {\n if (formatNameOrFn === VariableFormatID.Text) {\n return ALL_VARIABLE_TEXT;\n }\n\n if (formatNameOrFn === VariableFormatID.PercentEncode) {\n return formatRegistry.get(VariableFormatID.PercentEncode).formatter(this._value, [], this._variable);\n }\n\n if (formatNameOrFn === VariableFormatID.QueryParam) {\n return formatRegistry.get(VariableFormatID.QueryParam).formatter(ALL_VARIABLE_TEXT, [], this._variable);\n }\n\n return this._value;\n }\n}\n"],"names":[],"mappings":";;;;;;;;;AA6CO,MAAe,2BACZ,eAEV,CAAA;AAAA,EAHO,WAAA,GAAA;AAAA,IAAA,KAAA,CAAA,GAAA,SAAA,CAAA,CAAA;AAIL,IAAU,IAAA,CAAA,QAAA,GAAsC,IAAI,wBAAA,CAAyB,IAAI,CAAA,CAAA;AAAA,GAAA;AAAA,EAe1E,iBAAyD,GAAA;AAC9D,IAAA,OAAO,IAAK,CAAA,eAAA,CAAgB,EAAE,CAAE,CAAA,IAAA;AAAA,MAC9B,GAAA,CAAI,CAAC,OAAY,KAAA;AACf,QAAA,IAAA,CAAK,2BAA2B,OAAO,CAAA,CAAA;AACvC,QAAA,OAAO,EAAC,CAAA;AAAA,OACT,CAAA;AAAA,KACH,CAAA;AAAA,GACF;AAAA,EAEO,QAAiB,GAAA;AACtB,IAAA,IAAA,CAAK,cAAe,CAAA,EAAE,OAAS,EAAA,KAAA,EAAO,CAAA,CAAA;AACtC,IAAA,MAAM,cAAc,IAAK,CAAA,MAAA,CAAA;AACzB,IAAA,WAAA,IAAA,IAAA,GAAA,KAAA,CAAA,GAAA,WAAA,CAAa,MAAO,CAAA,IAAA,CAAA,CAAA;AAAA,GACtB;AAAA,EAKQ,2BAA2B,OAAgC,EAAA;AAEjE,IAAA,MAAM,EAAE,KAAO,EAAA,YAAA,EAAc,IAAM,EAAA,WAAA,KAAgB,IAAK,CAAA,KAAA,CAAA;AAExD,IAAA,MAAM,WAAc,GAAA,IAAA,CAAK,6BAA8B,CAAA,OAAA,EAAS,cAAc,WAAW,CAAA,CAAA;AAEzF,IAAA,IAAA,CAAK,oCAAoC,WAAW,CAAA,CAAA;AAGpD,IAAA,IAAA,CAAK,eAAe,WAAW,CAAA,CAAA;AAG/B,IAA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AAQ,EAAA,EAAI,EAAA,IAAA,CAAK,SAAS,CAAA,CAAA;AAAA,KACrG;AAEA,IAAI,IAAA,cAAA,KAAmB,iBAAiB,UAAY,EAAA;AAClD,MAAO,OAAA,cAAA,CAAe,GAAI,CAAA,gBAAA,CAAiB,UAAU,CAAA,CAAE,UAAU,iBAAmB,EAAA,EAAI,EAAA,IAAA,CAAK,SAAS,CAAA,CAAA;AAAA,KACxG;AAEA,IAAA,OAAO,IAAK,CAAA,MAAA,CAAA;AAAA,GACd;AACF;;;;"}
1
+ {"version":3,"file":"MultiValueVariable.js","sources":["../../../../src/variables/variants/MultiValueVariable.ts"],"sourcesContent":["import { isArray, isEqual } from 'lodash';\nimport { map, Observable } from 'rxjs';\n\nimport { ALL_VARIABLE_TEXT, ALL_VARIABLE_VALUE } from '../constants';\n\nimport { SceneObjectBase } from '../../core/SceneObjectBase';\nimport { SceneObjectUrlSyncHandler, SceneObjectUrlValues } from '../../core/types';\nimport {\n SceneVariable,\n SceneVariableValueChangedEvent,\n SceneVariableState,\n ValidateAndUpdateResult,\n VariableValue,\n VariableValueOption,\n VariableValueSingle,\n CustomVariableValue,\n VariableCustomFormatterFn,\n SceneVariableOptionsRefreshEvent,\n} from '../types';\nimport { formatRegistry } from '../interpolation/formatRegistry';\nimport { VariableFormatID } from '@grafana/schema';\nimport { SceneVariableSet } from '../sets/SceneVariableSet';\nimport { setBaseClassState } from '../../utils/utils';\n\nexport interface MultiValueVariableState extends SceneVariableState {\n value: VariableValue; // old current.text\n text: VariableValue; // old current.value\n options: VariableValueOption[];\n isMulti?: boolean;\n includeAll?: boolean;\n defaultToAll?: boolean;\n allValue?: string;\n placeholder?: string;\n /**\n * For multi value variables, this option controls how many values to show before they are collapsed into +N.\n * Defaults to 5\n */\n maxVisibleValues?: number;\n noValueOnClear?: boolean;\n isReadOnly?: boolean;\n}\n\nexport interface VariableGetOptionsArgs {\n searchFilter?: string;\n}\n\nexport abstract class MultiValueVariable<TState extends MultiValueVariableState = MultiValueVariableState>\n extends SceneObjectBase<TState>\n implements SceneVariable<TState>\n{\n protected _urlSync: SceneObjectUrlSyncHandler = new MultiValueUrlSyncHandler(this);\n\n /**\n * Set to true to skip next value validation to maintain the current value even it it's not among the options (ie valid values)\n */\n public skipNextValidation?: boolean;\n\n /**\n * The source of value options.\n */\n public abstract getValueOptions(args: VariableGetOptionsArgs): Observable<VariableValueOption[]>;\n\n /**\n * This function is called on when SceneVariableSet is activated or when a dependency changes.\n */\n public validateAndUpdate(): Observable<ValidateAndUpdateResult> {\n return this.getValueOptions({}).pipe(\n map((options) => {\n this.updateValueGivenNewOptions(options);\n return {};\n })\n );\n }\n\n public onCancel(): void {\n this.setStateHelper({ loading: false });\n const sceneVarSet = this.parent as SceneVariableSet;\n sceneVarSet?.cancel(this);\n }\n\n /**\n * Check if current value is valid given new options. If not update the value.\n */\n private updateValueGivenNewOptions(options: VariableValueOption[]) {\n // Remember current value and text\n const { value: currentValue, text: currentText } = this.state;\n\n const stateUpdate = this.getStateUpdateGivenNewOptions(options, currentValue, currentText);\n\n this.interceptStateUpdateAfterValidation(stateUpdate);\n\n // Perform state change\n this.setStateHelper(stateUpdate);\n\n // Publish value changed event only if value changed\n if (stateUpdate.value !== currentValue || stateUpdate.text !== currentText || this.hasAllValue()) {\n this.publishEvent(new SceneVariableValueChangedEvent(this), true);\n }\n }\n\n private getStateUpdateGivenNewOptions(\n options: VariableValueOption[],\n currentValue: VariableValue,\n currentText: VariableValue\n ): Partial<MultiValueVariableState> {\n const stateUpdate: Partial<MultiValueVariableState> = {\n options,\n loading: false,\n value: currentValue,\n text: currentText,\n };\n\n if (options.length === 0) {\n if (this.state.defaultToAll || this.state.includeAll) {\n stateUpdate.value = ALL_VARIABLE_VALUE;\n stateUpdate.text = ALL_VARIABLE_TEXT;\n } else if (this.state.isMulti) {\n stateUpdate.value = [];\n stateUpdate.text = [];\n } else {\n stateUpdate.value = '';\n stateUpdate.text = '';\n }\n\n return stateUpdate;\n }\n\n if (this.hasAllValue()) {\n if (!this.state.includeAll) {\n stateUpdate.value = options[0].value;\n stateUpdate.text = options[0].label;\n // If multi switch to arrays\n if (this.state.isMulti) {\n stateUpdate.value = [stateUpdate.value];\n stateUpdate.text = [stateUpdate.text];\n }\n }\n return stateUpdate;\n }\n\n if (this.state.isMulti) {\n // If we are a multi valued variable validate the current values are among the options\n const currentValues = Array.isArray(currentValue) ? currentValue : [currentValue];\n const validValues = currentValues.filter((v) => options.find((o) => o.value === v));\n const validTexts = validValues.map((v) => options.find((o) => o.value === v)!.label);\n\n // If no valid values pick the first option\n if (validValues.length === 0) {\n const defaultState = this.getDefaultMultiState(options);\n stateUpdate.value = defaultState.value;\n stateUpdate.text = defaultState.text;\n } else {\n // We have valid values, if it's different from current valid values update current values\n if (!isEqual(validValues, currentValue)) {\n stateUpdate.value = validValues;\n }\n if (!isEqual(validTexts, currentText)) {\n stateUpdate.text = validTexts;\n }\n }\n return stateUpdate;\n }\n\n // Single value variable validation\n\n // Try find by value then text\n let matchingOption = findOptionMatchingCurrent(currentValue, currentText, options);\n if (matchingOption) {\n // When updating the initial state from URL the text property is set the same as value\n // Here we can correct the text value state\n stateUpdate.text = matchingOption.label;\n stateUpdate.value = matchingOption.value;\n } else {\n // Current value is found in options\n if (this.state.defaultToAll) {\n stateUpdate.value = ALL_VARIABLE_VALUE;\n stateUpdate.text = ALL_VARIABLE_TEXT;\n } else {\n // Current value is not valid. Set to first of the available options\n stateUpdate.value = options[0].value;\n stateUpdate.text = options[0].label;\n }\n }\n\n return stateUpdate;\n }\n\n /**\n * Values set by initial URL sync needs to survive the next validation and update.\n * This function can intercept and make sure those values are preserved.\n */\n protected interceptStateUpdateAfterValidation(stateUpdate: Partial<MultiValueVariableState>): void {\n // If the validation wants to fix the all value (All ==> $__all) then we should let that pass\n const isAllValueFix = stateUpdate.value === ALL_VARIABLE_VALUE && this.state.text === ALL_VARIABLE_TEXT;\n\n if (this.skipNextValidation && stateUpdate.value !== this.state.value && !isAllValueFix) {\n stateUpdate.value = this.state.value;\n stateUpdate.text = this.state.text;\n }\n\n this.skipNextValidation = false;\n }\n\n public getValue(): VariableValue {\n if (this.hasAllValue()) {\n if (this.state.allValue) {\n return new CustomAllValue(this.state.allValue, this);\n }\n\n return this.state.options.map((x) => x.value);\n }\n\n return this.state.value;\n }\n\n public getValueText(): string {\n if (this.hasAllValue()) {\n return ALL_VARIABLE_TEXT;\n }\n\n if (Array.isArray(this.state.text)) {\n return this.state.text.join(' + ');\n }\n\n return String(this.state.text);\n }\n\n public hasAllValue() {\n const value = this.state.value;\n return value === ALL_VARIABLE_VALUE || (Array.isArray(value) && value[0] === ALL_VARIABLE_VALUE);\n }\n\n public getDefaultMultiState(options: VariableValueOption[]) {\n if (this.state.defaultToAll) {\n return { value: [ALL_VARIABLE_VALUE], text: [ALL_VARIABLE_TEXT] };\n } else if (options.length > 0) {\n return { value: [options[0].value], text: [options[0].label] };\n } else {\n return { value: [], text: [] };\n }\n }\n\n /**\n * Change the value and publish SceneVariableValueChangedEvent event.\n */\n public changeValueTo(value: VariableValue, text?: VariableValue) {\n // Ignore if there is no change\n if (value === this.state.value && text === this.state.text) {\n return;\n }\n\n if (!text) {\n if (Array.isArray(value)) {\n text = value.map((v) => this.findLabelTextForValue(v));\n } else {\n text = this.findLabelTextForValue(value);\n }\n }\n\n if (Array.isArray(value)) {\n // If we are a multi valued variable is cleared (empty array) we need to set the default empty state\n if (value.length === 0) {\n const state = this.getDefaultMultiState(this.state.options);\n value = state.value;\n text = state.text;\n }\n\n // If last value is the All value then replace all with it\n if (value[value.length - 1] === ALL_VARIABLE_VALUE) {\n value = [ALL_VARIABLE_VALUE];\n text = [ALL_VARIABLE_TEXT];\n }\n // If the first value is the ALL value and we have other values, then remove the All value\n else if (value[0] === ALL_VARIABLE_VALUE && value.length > 1) {\n value.shift();\n if (Array.isArray(text)) {\n text.shift();\n }\n }\n }\n\n // Do nothing if value and text are the same\n if (isEqual(value, this.state.value) && isEqual(text, this.state.text)) {\n return;\n }\n\n this.setStateHelper({ value, text, loading: false });\n this.publishEvent(new SceneVariableValueChangedEvent(this), true);\n }\n\n private findLabelTextForValue(value: VariableValueSingle): VariableValueSingle {\n if (value === ALL_VARIABLE_VALUE) {\n return ALL_VARIABLE_TEXT;\n }\n\n const option = this.state.options.find((x) => x.value === value);\n if (option) {\n return option.label;\n }\n\n const optionByLabel = this.state.options.find((x) => x.label === value);\n if (optionByLabel) {\n return optionByLabel.label;\n }\n\n return value;\n }\n\n /**\n * This helper function is to counter the contravariance of setState\n */\n private setStateHelper(state: Partial<MultiValueVariableState>) {\n setBaseClassState<MultiValueVariableState>(this, state);\n }\n\n public getOptionsForSelect(): VariableValueOption[] {\n let options = this.state.options;\n\n if (this.state.includeAll) {\n options = [{ value: ALL_VARIABLE_VALUE, label: ALL_VARIABLE_TEXT }, ...options];\n }\n\n if (!Array.isArray(this.state.value)) {\n const current = options.find((x) => x.value === this.state.value);\n if (!current) {\n options = [{ value: this.state.value, label: String(this.state.text) }, ...options];\n }\n }\n\n return options;\n }\n\n public refreshOptions() {\n this.publishEvent(new SceneVariableOptionsRefreshEvent(this), true);\n }\n\n /**\n * Can be used by subclasses to do custom handling of option search based on search input\n */\n public onSearchChange?(searchFilter: string): void;\n}\n\n/**\n * Looks for matching option, first by value but as a fallback by text (label).\n */\nfunction findOptionMatchingCurrent(\n currentValue: VariableValue,\n currentText: VariableValue,\n options: VariableValueOption[]\n) {\n let textMatch: VariableValueOption | undefined;\n\n for (const item of options) {\n if (item.value === currentValue) {\n return item;\n }\n\n // No early return here as want to continue to look a value match\n if (item.label === currentText) {\n textMatch = item;\n }\n }\n\n return textMatch;\n}\n\nexport class MultiValueUrlSyncHandler<TState extends MultiValueVariableState = MultiValueVariableState>\n implements SceneObjectUrlSyncHandler\n{\n public constructor(private _sceneObject: MultiValueVariable<TState>) {}\n\n private getKey(): string {\n return `var-${this._sceneObject.state.name}`;\n }\n\n public getKeys(): string[] {\n if (this._sceneObject.state.skipUrlSync) {\n return [];\n }\n\n return [this.getKey()];\n }\n\n public getUrlState(): SceneObjectUrlValues {\n if (this._sceneObject.state.skipUrlSync) {\n return {};\n }\n\n let urlValue: string | string[] | null = null;\n let value = this._sceneObject.state.value;\n\n if (Array.isArray(value)) {\n urlValue = value.map(String);\n } else if ((this, this._sceneObject.state.isMulti)) {\n // If we are inMulti mode we must return an array here as otherwise UrlSyncManager will not pass all values (in an array) in updateFromUrl\n urlValue = [String(value)];\n } else {\n urlValue = String(value);\n }\n\n return { [this.getKey()]: urlValue };\n }\n\n public updateFromUrl(values: SceneObjectUrlValues): void {\n let urlValue = values[this.getKey()];\n\n if (urlValue != null) {\n // This is to be backwards compatible with old url all value\n if (this._sceneObject.state.includeAll) {\n urlValue = handleLegacyUrlAllValue(urlValue);\n }\n\n // For edge cases where data links include variables with custom all value.\n // We want the variable to maintain the \"All\" meta value not the actual custom vall value. (Fixes https://github.com/grafana/grafana/issues/28635)\n if (this._sceneObject.state.allValue && this._sceneObject.state.allValue === urlValue) {\n urlValue = ALL_VARIABLE_VALUE;\n }\n\n /**\n * Initial URL Sync happens before scene objects are activated.\n * We need to skip validation in this case to make sure values set via URL are maintained.\n */\n if (!this._sceneObject.isActive) {\n this._sceneObject.skipNextValidation = true;\n }\n\n this._sceneObject.changeValueTo(urlValue);\n }\n }\n}\n\nfunction handleLegacyUrlAllValue(value: string | string[]) {\n if (isArray(value) && value[0] === ALL_VARIABLE_TEXT) {\n return [ALL_VARIABLE_VALUE];\n } else if (value === ALL_VARIABLE_TEXT) {\n return ALL_VARIABLE_VALUE;\n }\n\n return value;\n}\n\n/**\n * Variable getValue can return this to skip any subsequent formatting.\n * This is useful for custom all values that should not be escaped/formatted.\n */\nexport class CustomAllValue implements CustomVariableValue {\n public constructor(private _value: string, private _variable: SceneVariable) {}\n\n public formatter(formatNameOrFn?: string | VariableCustomFormatterFn): string {\n if (formatNameOrFn === VariableFormatID.Text) {\n return ALL_VARIABLE_TEXT;\n }\n\n if (formatNameOrFn === VariableFormatID.PercentEncode) {\n return formatRegistry.get(VariableFormatID.PercentEncode).formatter(this._value, [], this._variable);\n }\n\n if (formatNameOrFn === VariableFormatID.QueryParam) {\n return formatRegistry.get(VariableFormatID.QueryParam).formatter(ALL_VARIABLE_TEXT, [], this._variable);\n }\n\n return this._value;\n }\n}\n"],"names":[],"mappings":";;;;;;;;;AA8CO,MAAe,2BACZ,eAEV,CAAA;AAAA,EAHO,WAAA,GAAA;AAAA,IAAA,KAAA,CAAA,GAAA,SAAA,CAAA,CAAA;AAIL,IAAU,IAAA,CAAA,QAAA,GAAsC,IAAI,wBAAA,CAAyB,IAAI,CAAA,CAAA;AAAA,GAAA;AAAA,EAe1E,iBAAyD,GAAA;AAC9D,IAAA,OAAO,IAAK,CAAA,eAAA,CAAgB,EAAE,CAAE,CAAA,IAAA;AAAA,MAC9B,GAAA,CAAI,CAAC,OAAY,KAAA;AACf,QAAA,IAAA,CAAK,2BAA2B,OAAO,CAAA,CAAA;AACvC,QAAA,OAAO,EAAC,CAAA;AAAA,OACT,CAAA;AAAA,KACH,CAAA;AAAA,GACF;AAAA,EAEO,QAAiB,GAAA;AACtB,IAAA,IAAA,CAAK,cAAe,CAAA,EAAE,OAAS,EAAA,KAAA,EAAO,CAAA,CAAA;AACtC,IAAA,MAAM,cAAc,IAAK,CAAA,MAAA,CAAA;AACzB,IAAA,WAAA,IAAA,IAAA,GAAA,KAAA,CAAA,GAAA,WAAA,CAAa,MAAO,CAAA,IAAA,CAAA,CAAA;AAAA,GACtB;AAAA,EAKQ,2BAA2B,OAAgC,EAAA;AAEjE,IAAA,MAAM,EAAE,KAAO,EAAA,YAAA,EAAc,IAAM,EAAA,WAAA,KAAgB,IAAK,CAAA,KAAA,CAAA;AAExD,IAAA,MAAM,WAAc,GAAA,IAAA,CAAK,6BAA8B,CAAA,OAAA,EAAS,cAAc,WAAW,CAAA,CAAA;AAEzF,IAAA,IAAA,CAAK,oCAAoC,WAAW,CAAA,CAAA;AAGpD,IAAA,IAAA,CAAK,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A,KACT;AAEA,IAAI,IAAA,cAAA,KAAmB,iBAAiB,aAAe,EAAA;AACrD,MAAO,OAAA,cAAA,CAAe,GAAI,CAAA,gBAAA,CAAiB,aAAa,CAAA,CAAE,SAAU,CAAA,IAAA,CAAK,MAAQ,EAAA,EAAI,EAAA,IAAA,CAAK,SAAS,CAAA,CAAA;AAAA,KACrG;AAEA,IAAI,IAAA,cAAA,KAAmB,iBAAiB,UAAY,EAAA;AAClD,MAAO,OAAA,cAAA,CAAe,GAAI,CAAA,gBAAA,CAAiB,UAAU,CAAA,CAAE,UAAU,iBAAmB,EAAA,EAAI,EAAA,IAAA,CAAK,SAAS,CAAA,CAAA;AAAA,KACxG;AAEA,IAAA,OAAO,IAAK,CAAA,MAAA,CAAA;AAAA,GACd;AACF;;;;"}
package/dist/index.d.ts CHANGED
@@ -104,6 +104,9 @@ interface SceneVariables extends SceneObject<SceneVariableSetState> {
104
104
  declare class SceneVariableValueChangedEvent extends BusEventWithPayload<SceneVariable> {
105
105
  static type: string;
106
106
  }
107
+ declare class SceneVariableOptionsRefreshEvent extends BusEventWithPayload<SceneVariable> {
108
+ static type: string;
109
+ }
107
110
  interface SceneVariableDependencyConfigLike {
108
111
  /** Return all variable names this object depend on */
109
112
  getNames(): Set<string>;
@@ -720,6 +723,7 @@ declare abstract class MultiValueVariable<TState extends MultiValueVariableState
720
723
  */
721
724
  private setStateHelper;
722
725
  getOptionsForSelect(): VariableValueOption[];
726
+ refreshOptions(): void;
723
727
  /**
724
728
  * Can be used by subclasses to do custom handling of option search based on search input
725
729
  */
@@ -1485,6 +1489,7 @@ declare class SceneVariableSet extends SceneObjectBase<SceneVariableSetState> im
1485
1489
  private _validateAndUpdateCompleted;
1486
1490
  cancel(variable: SceneVariable): void;
1487
1491
  private _handleVariableError;
1492
+ private _handleVariableOptionsUpdate;
1488
1493
  private _handleVariableValueChanged;
1489
1494
  /**
1490
1495
  * This is called by any parent level variable set to notify scene that an update batch is completed.
@@ -2655,4 +2660,4 @@ declare const sceneUtils: {
2655
2660
  isGroupByVariable: typeof isGroupByVariable;
2656
2661
  };
2657
2662
 
2658
- export { AdHocFiltersVariable, CancelActivationHandler, ConstantVariable, ControlsLayout, CustomFormatterVariable, CustomTransformOperator, CustomTransformerDefinition, CustomVariable, CustomVariableValue, DataLayerFilter, DataRequestEnricher, DataSourceVariable, DeepPartial, EmbeddedScene, EmbeddedSceneState, ExtraQueryDataProcessor, ExtraQueryDescriptor, ExtraQueryProvider, FieldConfigBuilder, FieldConfigBuilders, FieldConfigOverridesBuilder, FiltersRequestEnricher, FormatVariable, GroupByVariable, InterpolationFormatParameter, IntervalVariable, LocalValueVariable, MacroVariableConstructor, MultiValueVariable, MultiValueVariableState, NestedScene, PanelBuilders, PanelOptionsBuilders, QueryRunnerState, QueryVariable, RuntimeDataSource, SceneActivationHandler, SceneApp, SceneAppDrilldownView, SceneAppPage, SceneAppPageLike, SceneAppPageState, SceneAppRoute, SceneByFrameRepeater, SceneByVariableRepeater, SceneCSSGridItem, SceneCSSGridLayout, SceneCanvasText, SceneComponent, SceneComponentProps, SceneControlsSpacer, SceneDataLayerBase, SceneDataLayerControls, SceneDataLayerProvider, SceneDataLayerProviderState, SceneDataLayerSet, SceneDataLayerSetBase, SceneDataNode, SceneDataProvider, SceneDataProviderResult, SceneDataQuery, SceneDataState, SceneDataTransformer, SceneDeactivationHandler, SceneDebugger, SceneFlexItem, SceneFlexItemLike, SceneFlexItemState, SceneFlexLayout, SceneGridItem, SceneGridItemLike, SceneGridItemStateLike, SceneGridLayout, SceneGridRow, SceneLayout, SceneLayoutChildOptions, SceneLayoutState, SceneObject, SceneObjectBase, SceneObjectRef, SceneObjectState, SceneObjectStateChangedEvent, SceneObjectStateChangedPayload, SceneObjectUrlSyncConfig, SceneObjectUrlSyncHandler, SceneObjectUrlValue, SceneObjectUrlValues, SceneObjectWithUrlSync, SceneQueryControllerEntry, SceneQueryControllerEntryType, SceneQueryControllerLike, SceneQueryRunner, SceneReactObject, SceneRefreshPicker, SceneRefreshPickerState, SceneRouteMatch, SceneStateChangedHandler, SceneStatelessBehavior, SceneTimePicker, SceneTimeRange, SceneTimeRangeCompare, SceneTimeRangeLike, SceneTimeRangeState, SceneTimeRangeTransformerBase, SceneTimeZoneOverride, SceneToolbarButton, SceneToolbarInput, SceneVariable, SceneVariableDependencyConfigLike, SceneVariableSet, SceneVariableSetState, SceneVariableState, SceneVariableValueChangedEvent, SceneVariables, SplitLayout, TestVariable, TextBoxVariable, UrlSyncContextProvider, UrlSyncManager, UrlSyncManagerLike, UseStateHookOptions, UserActionEvent, ValidateAndUpdateResult, VariableCustomFormatterFn, VariableDependencyConfig, VariableGetOptionsArgs, VariableValue, VariableValueControl, VariableValueOption, VariableValueSelectWrapper, VariableValueSelectors, VariableValueSingle, VizConfig, VizConfigBuilder, VizConfigBuilders, VizPanel, VizPanelBuilder, VizPanelMenu, VizPanelState, index$1 as behaviors, index as dataLayers, formatRegistry, getUrlSyncManager, isCustomVariableValue, isDataLayer, isDataRequestEnricher, isFiltersRequestEnricher, isSceneObject, registerQueryWithController, registerRuntimeDataSource, renderSelectForVariable, sceneGraph, sceneUtils, useSceneApp, useSceneObjectState, useUrlSync };
2663
+ export { AdHocFiltersVariable, CancelActivationHandler, ConstantVariable, ControlsLayout, CustomFormatterVariable, CustomTransformOperator, CustomTransformerDefinition, CustomVariable, CustomVariableValue, DataLayerFilter, DataRequestEnricher, DataSourceVariable, DeepPartial, EmbeddedScene, EmbeddedSceneState, ExtraQueryDataProcessor, ExtraQueryDescriptor, ExtraQueryProvider, FieldConfigBuilder, FieldConfigBuilders, FieldConfigOverridesBuilder, FiltersRequestEnricher, FormatVariable, GroupByVariable, InterpolationFormatParameter, IntervalVariable, LocalValueVariable, MacroVariableConstructor, MultiValueVariable, MultiValueVariableState, NestedScene, PanelBuilders, PanelOptionsBuilders, QueryRunnerState, QueryVariable, RuntimeDataSource, SceneActivationHandler, SceneApp, SceneAppDrilldownView, SceneAppPage, SceneAppPageLike, SceneAppPageState, SceneAppRoute, SceneByFrameRepeater, SceneByVariableRepeater, SceneCSSGridItem, SceneCSSGridLayout, SceneCanvasText, SceneComponent, SceneComponentProps, SceneControlsSpacer, SceneDataLayerBase, SceneDataLayerControls, SceneDataLayerProvider, SceneDataLayerProviderState, SceneDataLayerSet, SceneDataLayerSetBase, SceneDataNode, SceneDataProvider, SceneDataProviderResult, SceneDataQuery, SceneDataState, SceneDataTransformer, SceneDeactivationHandler, SceneDebugger, SceneFlexItem, SceneFlexItemLike, SceneFlexItemState, SceneFlexLayout, SceneGridItem, SceneGridItemLike, SceneGridItemStateLike, SceneGridLayout, SceneGridRow, SceneLayout, SceneLayoutChildOptions, SceneLayoutState, SceneObject, SceneObjectBase, SceneObjectRef, SceneObjectState, SceneObjectStateChangedEvent, SceneObjectStateChangedPayload, SceneObjectUrlSyncConfig, SceneObjectUrlSyncHandler, SceneObjectUrlValue, SceneObjectUrlValues, SceneObjectWithUrlSync, SceneQueryControllerEntry, SceneQueryControllerEntryType, SceneQueryControllerLike, SceneQueryRunner, SceneReactObject, SceneRefreshPicker, SceneRefreshPickerState, SceneRouteMatch, SceneStateChangedHandler, SceneStatelessBehavior, SceneTimePicker, SceneTimeRange, SceneTimeRangeCompare, SceneTimeRangeLike, SceneTimeRangeState, SceneTimeRangeTransformerBase, SceneTimeZoneOverride, SceneToolbarButton, SceneToolbarInput, SceneVariable, SceneVariableDependencyConfigLike, SceneVariableOptionsRefreshEvent, SceneVariableSet, SceneVariableSetState, SceneVariableState, SceneVariableValueChangedEvent, SceneVariables, SplitLayout, TestVariable, TextBoxVariable, UrlSyncContextProvider, UrlSyncManager, UrlSyncManagerLike, UseStateHookOptions, UserActionEvent, ValidateAndUpdateResult, VariableCustomFormatterFn, VariableDependencyConfig, VariableGetOptionsArgs, VariableValue, VariableValueControl, VariableValueOption, VariableValueSelectWrapper, VariableValueSelectors, VariableValueSingle, VizConfig, VizConfigBuilder, VizConfigBuilders, VizPanel, VizPanelBuilder, VizPanelMenu, VizPanelState, index$1 as behaviors, index as dataLayers, formatRegistry, getUrlSyncManager, isCustomVariableValue, isDataLayer, isDataRequestEnricher, isFiltersRequestEnricher, isSceneObject, registerQueryWithController, registerRuntimeDataSource, renderSelectForVariable, sceneGraph, sceneUtils, useSceneApp, useSceneObjectState, useUrlSync };
package/dist/index.js CHANGED
@@ -891,6 +891,9 @@ function getTimeRange(sceneObject) {
891
891
  class SceneVariableValueChangedEvent extends data.BusEventWithPayload {
892
892
  }
893
893
  SceneVariableValueChangedEvent.type = "scene-variable-changed-value";
894
+ class SceneVariableOptionsRefreshEvent extends data.BusEventWithPayload {
895
+ }
896
+ SceneVariableOptionsRefreshEvent.type = "scene-variable-options-refresh";
894
897
  function isCustomVariableValue(value) {
895
898
  return typeof value === "object" && "formatter" in value;
896
899
  }
@@ -2699,6 +2702,9 @@ class MultiValueVariable extends SceneObjectBase {
2699
2702
  }
2700
2703
  return options;
2701
2704
  }
2705
+ refreshOptions() {
2706
+ this.publishEvent(new SceneVariableOptionsRefreshEvent(this), true);
2707
+ }
2702
2708
  }
2703
2709
  function findOptionMatchingCurrent(currentValue, currentText, options) {
2704
2710
  let textMatch;
@@ -3311,7 +3317,7 @@ function LoadingIndicator(props) {
3311
3317
  }
3312
3318
 
3313
3319
  function ControlsLabel(props) {
3314
- const styles = ui.useStyles2(getStyles$9);
3320
+ const styles = ui.useStyles2(getStyles$a);
3315
3321
  const theme = ui.useTheme2();
3316
3322
  const isVertical = props.layout === "vertical";
3317
3323
  const loadingIndicator = Boolean(props.isLoading) ? /* @__PURE__ */ React__default["default"].createElement("div", {
@@ -3374,7 +3380,7 @@ function ControlsLabel(props) {
3374
3380
  }
3375
3381
  return labelElement;
3376
3382
  }
3377
- const getStyles$9 = (theme) => ({
3383
+ const getStyles$a = (theme) => ({
3378
3384
  horizontalLabel: css.css({
3379
3385
  background: theme.isDark ? theme.colors.background.primary : theme.colors.background.secondary,
3380
3386
  display: `flex`,
@@ -3473,7 +3479,7 @@ function keyLabelToOption(key, label) {
3473
3479
  const filterNoOp = () => true;
3474
3480
  function AdHocFilterRenderer({ filter, model }) {
3475
3481
  var _a, _b;
3476
- const styles = ui.useStyles2(getStyles$8);
3482
+ const styles = ui.useStyles2(getStyles$9);
3477
3483
  const [keys, setKeys] = React.useState([]);
3478
3484
  const [values, setValues] = React.useState([]);
3479
3485
  const [isKeysLoading, setIsKeysLoading] = React.useState(false);
@@ -3617,7 +3623,7 @@ function AdHocFilterRenderer({ filter, model }) {
3617
3623
  onClick: () => model._removeFilter(filter)
3618
3624
  }));
3619
3625
  }
3620
- const getStyles$8 = (theme) => ({
3626
+ const getStyles$9 = (theme) => ({
3621
3627
  field: css.css({
3622
3628
  marginBottom: 0
3623
3629
  }),
@@ -3916,7 +3922,7 @@ function renderExpression(builder, filters) {
3916
3922
  }
3917
3923
  function AdHocFiltersVariableRenderer({ model }) {
3918
3924
  const { filters, readOnly, addFilterButtonText } = model.useState();
3919
- const styles = ui.useStyles2(getStyles$7);
3925
+ const styles = ui.useStyles2(getStyles$8);
3920
3926
  return /* @__PURE__ */ React__default["default"].createElement("div", {
3921
3927
  className: styles.wrapper
3922
3928
  }, filters.map((filter, index) => /* @__PURE__ */ React__default["default"].createElement(React__default["default"].Fragment, {
@@ -3930,7 +3936,7 @@ function AdHocFiltersVariableRenderer({ model }) {
3930
3936
  addFilterButtonText
3931
3937
  }));
3932
3938
  }
3933
- const getStyles$7 = (theme) => ({
3939
+ const getStyles$8 = (theme) => ({
3934
3940
  wrapper: css.css({
3935
3941
  display: "flex",
3936
3942
  flexWrap: "wrap",
@@ -6600,6 +6606,9 @@ class SceneVariableSet extends SceneObjectBase {
6600
6606
  this._subs.add(
6601
6607
  this.subscribeToEvent(SceneVariableValueChangedEvent, (event) => this._handleVariableValueChanged(event.payload))
6602
6608
  );
6609
+ this._subs.add(
6610
+ this.subscribeToEvent(SceneVariableOptionsRefreshEvent, (event) => this._handleVariableOptionsUpdate(event.payload))
6611
+ );
6603
6612
  this._subs.add(
6604
6613
  timeRange.subscribeToState(() => {
6605
6614
  this._refreshTimeRangeBasedVariables();
@@ -6741,6 +6750,10 @@ class SceneVariableSet extends SceneObjectBase {
6741
6750
  console.error("SceneVariableSet updateAndValidate error", err);
6742
6751
  writeVariableTraceLog(variable, "updateAndValidate error", err);
6743
6752
  }
6753
+ _handleVariableOptionsUpdate(variable) {
6754
+ this._variablesToUpdate.add(variable);
6755
+ this._updateNextBatch();
6756
+ }
6744
6757
  _handleVariableValueChanged(variableThatChanged) {
6745
6758
  this._variablesThatHaveChanged.add(variableThatChanged);
6746
6759
  this._addDependentVariablesToUpdateQueue(variableThatChanged);
@@ -8032,7 +8045,7 @@ class EmbeddedScene extends SceneObjectBase {
8032
8045
  EmbeddedScene.Component = EmbeddedSceneRenderer;
8033
8046
  function EmbeddedSceneRenderer({ model }) {
8034
8047
  const { body, controls } = model.useState();
8035
- const styles = ui.useStyles2(getStyles$6);
8048
+ const styles = ui.useStyles2(getStyles$7);
8036
8049
  return /* @__PURE__ */ React__default["default"].createElement("div", {
8037
8050
  className: styles.container
8038
8051
  }, controls && /* @__PURE__ */ React__default["default"].createElement("div", {
@@ -8046,7 +8059,7 @@ function EmbeddedSceneRenderer({ model }) {
8046
8059
  model: body
8047
8060
  })));
8048
8061
  }
8049
- const getStyles$6 = (theme) => {
8062
+ const getStyles$7 = (theme) => {
8050
8063
  return {
8051
8064
  container: css.css({
8052
8065
  flexGrow: 1,
@@ -8187,7 +8200,7 @@ const LazyLoader = React__default["default"].forwardRef(
8187
8200
  (_a, ref) => {
8188
8201
  var _b = _a, { children, onLoad, onChange, className } = _b, rest = __objRest$1(_b, ["children", "onLoad", "onChange", "className"]);
8189
8202
  const id = useUniqueId();
8190
- const style = useStyle();
8203
+ const { hideEmpty } = ui.useStyles2(getStyles$6);
8191
8204
  const [loaded, setLoaded] = React.useState(false);
8192
8205
  const [isInView, setIsInView] = React.useState(false);
8193
8206
  const innerRef = React.useRef(null);
@@ -8213,19 +8226,22 @@ const LazyLoader = React__default["default"].forwardRef(
8213
8226
  }
8214
8227
  };
8215
8228
  });
8229
+ const classes = `${loaded ? hideEmpty : ""} ${className}`;
8216
8230
  return /* @__PURE__ */ React__default["default"].createElement("div", __spreadValues$b({
8217
8231
  id,
8218
8232
  ref: innerRef,
8219
- className: `${loaded ? style : ""} ${className}`
8233
+ className: classes
8220
8234
  }, rest), loaded && (typeof children === "function" ? children({ isInView }) : children));
8221
8235
  }
8222
8236
  );
8223
- function useStyle() {
8224
- return css.css({
8225
- "&:empty": {
8226
- display: "none"
8227
- }
8228
- });
8237
+ function getStyles$6() {
8238
+ return {
8239
+ hideEmpty: css.css({
8240
+ "&:empty": {
8241
+ display: "none"
8242
+ }
8243
+ })
8244
+ };
8229
8245
  }
8230
8246
  LazyLoader.displayName = "LazyLoader";
8231
8247
  LazyLoader.callbacks = {};
@@ -11584,6 +11600,7 @@ exports.SceneTimeRangeTransformerBase = SceneTimeRangeTransformerBase;
11584
11600
  exports.SceneTimeZoneOverride = SceneTimeZoneOverride;
11585
11601
  exports.SceneToolbarButton = SceneToolbarButton;
11586
11602
  exports.SceneToolbarInput = SceneToolbarInput;
11603
+ exports.SceneVariableOptionsRefreshEvent = SceneVariableOptionsRefreshEvent;
11587
11604
  exports.SceneVariableSet = SceneVariableSet;
11588
11605
  exports.SceneVariableValueChangedEvent = SceneVariableValueChangedEvent;
11589
11606
  exports.SplitLayout = SplitLayout;