@grafana/scenes 5.14.3--canary.892.10793378428.0 → 5.14.4--canary.896.10848324548.0

Sign up to get free protection for your applications and to get access to all the features.
package/CHANGELOG.md CHANGED
@@ -1,3 +1,15 @@
1
+ # v5.14.3 (Wed Sep 11 2024)
2
+
3
+ #### 🐛 Bug Fix
4
+
5
+ - SceneObjectBase: add clearParent [#892](https://github.com/grafana/scenes/pull/892) ([@torkelo](https://github.com/torkelo))
6
+
7
+ #### Authors: 1
8
+
9
+ - Torkel Ödegaard ([@torkelo](https://github.com/torkelo))
10
+
11
+ ---
12
+
1
13
  # v5.14.2 (Mon Sep 09 2024)
2
14
 
3
15
  #### 🐛 Bug Fix
@@ -1,6 +1,6 @@
1
1
  import { lookupVariable } from '../../variables/lookupVariable.js';
2
2
  import { getTimeRange } from './getTimeRange.js';
3
- import { getVariables, getData, getLayout, getDataLayers, interpolate, hasVariableDependencyInLoadingState, findByKey, findByKeyAndType, findObject, findAllObjects, getAncestor, getQueryController, getUrlSyncManager } from './sceneGraph.js';
3
+ import { getVariables, getData, getLayout, getDataLayers, interpolate, hasVariableDependencyInLoadingState, findByKey, findByKeyAndType, findObject, findAllObjects, getAncestor, findDescendents, getQueryController, getUrlSyncManager } from './sceneGraph.js';
4
4
 
5
5
  const sceneGraph = {
6
6
  getVariables,
@@ -16,6 +16,7 @@ const sceneGraph = {
16
16
  findObject,
17
17
  findAllObjects,
18
18
  getAncestor,
19
+ findDescendents,
19
20
  getQueryController,
20
21
  getUrlSyncManager
21
22
  };
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":["../../../../src/core/sceneGraph/index.ts"],"sourcesContent":["import { lookupVariable } from '../../variables/lookupVariable';\nimport { getTimeRange } from './getTimeRange';\nimport {\n findByKey,\n findByKeyAndType,\n findObject,\n findAllObjects,\n getData,\n getLayout,\n getVariables,\n getDataLayers,\n hasVariableDependencyInLoadingState,\n interpolate,\n getAncestor,\n getQueryController,\n getUrlSyncManager,\n} from './sceneGraph';\n\nexport const sceneGraph = {\n getVariables,\n getData,\n getTimeRange,\n getLayout,\n getDataLayers,\n interpolate,\n lookupVariable,\n hasVariableDependencyInLoadingState,\n findByKey,\n findByKeyAndType,\n findObject,\n findAllObjects,\n getAncestor,\n getQueryController,\n getUrlSyncManager,\n};\n"],"names":[],"mappings":";;;;AAkBO,MAAM,UAAa,GAAA;AAAA,EACxB,YAAA;AAAA,EACA,OAAA;AAAA,EACA,YAAA;AAAA,EACA,SAAA;AAAA,EACA,aAAA;AAAA,EACA,WAAA;AAAA,EACA,cAAA;AAAA,EACA,mCAAA;AAAA,EACA,SAAA;AAAA,EACA,gBAAA;AAAA,EACA,UAAA;AAAA,EACA,cAAA;AAAA,EACA,WAAA;AAAA,EACA,kBAAA;AAAA,EACA,iBAAA;AACF;;;;"}
1
+ {"version":3,"file":"index.js","sources":["../../../../src/core/sceneGraph/index.ts"],"sourcesContent":["import { lookupVariable } from '../../variables/lookupVariable';\nimport { getTimeRange } from './getTimeRange';\nimport {\n findByKey,\n findByKeyAndType,\n findObject,\n findAllObjects,\n getData,\n getLayout,\n getVariables,\n getDataLayers,\n hasVariableDependencyInLoadingState,\n interpolate,\n getAncestor,\n findDescendents,\n getQueryController,\n getUrlSyncManager,\n} from './sceneGraph';\n\nexport const sceneGraph = {\n getVariables,\n getData,\n getTimeRange,\n getLayout,\n getDataLayers,\n interpolate,\n lookupVariable,\n hasVariableDependencyInLoadingState,\n findByKey,\n findByKeyAndType,\n findObject,\n findAllObjects,\n getAncestor,\n findDescendents,\n getQueryController,\n getUrlSyncManager,\n};\n"],"names":[],"mappings":";;;;AAmBO,MAAM,UAAa,GAAA;AAAA,EACxB,YAAA;AAAA,EACA,OAAA;AAAA,EACA,YAAA;AAAA,EACA,SAAA;AAAA,EACA,aAAA;AAAA,EACA,WAAA;AAAA,EACA,cAAA;AAAA,EACA,mCAAA;AAAA,EACA,SAAA;AAAA,EACA,gBAAA;AAAA,EACA,UAAA;AAAA,EACA,cAAA;AAAA,EACA,WAAA;AAAA,EACA,eAAA;AAAA,EACA,kBAAA;AAAA,EACA,iBAAA;AACF;;;;"}
@@ -142,6 +142,13 @@ function getAncestor(sceneObject, ancestorType) {
142
142
  }
143
143
  return parent;
144
144
  }
145
+ function findDescendents(scene, descendentType) {
146
+ function isDescendentType(scene2) {
147
+ return scene2 instanceof descendentType;
148
+ }
149
+ const targetScenes = findAllObjects(scene, isDescendentType);
150
+ return targetScenes.filter(isDescendentType);
151
+ }
145
152
  function getQueryController(sceneObject) {
146
153
  let parent = sceneObject;
147
154
  while (parent) {
@@ -167,5 +174,5 @@ function getUrlSyncManager(sceneObject) {
167
174
  return void 0;
168
175
  }
169
176
 
170
- export { findAllObjects, findByKey, findByKeyAndType, findObject, getAncestor, getData, getDataLayers, getLayout, getQueryController, getUrlSyncManager, getVariables, hasVariableDependencyInLoadingState, interpolate };
177
+ export { findAllObjects, findByKey, findByKeyAndType, findDescendents, findObject, getAncestor, getData, getDataLayers, getLayout, getQueryController, getUrlSyncManager, getVariables, hasVariableDependencyInLoadingState, interpolate };
171
178
  //# sourceMappingURL=sceneGraph.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"sceneGraph.js","sources":["../../../../src/core/sceneGraph/sceneGraph.ts"],"sourcesContent":["import { ScopedVars } from '@grafana/data';\nimport { EmptyDataNode, EmptyVariableSet } from '../../variables/interpolation/defaults';\n\nimport { sceneInterpolator } from '../../variables/interpolation/sceneInterpolator';\nimport { VariableCustomFormatterFn, SceneVariables } from '../../variables/types';\n\nimport { isDataLayer, SceneDataLayerProvider, SceneDataProvider, SceneLayout, SceneObject } from '../types';\nimport { lookupVariable } from '../../variables/lookupVariable';\nimport { getClosest } from './utils';\nimport { SceneQueryControllerLike, isQueryController } from '../../behaviors/SceneQueryController';\nimport { VariableInterpolation } from '@grafana/runtime';\nimport { QueryVariable } from '../../variables/variants/query/QueryVariable';\nimport { UrlSyncManagerLike } from '../../services/UrlSyncManager';\n\n/**\n * Get the closest node with variables\n */\nexport function getVariables(sceneObject: SceneObject): SceneVariables {\n return getClosest(sceneObject, (s) => s.state.$variables) ?? EmptyVariableSet;\n}\n\n/**\n * Will walk up the scene object graph to the closest $data scene object\n */\nexport function getData(sceneObject: SceneObject): SceneDataProvider {\n return getClosest(sceneObject, (s) => s.state.$data) ?? EmptyDataNode;\n}\n\nfunction isSceneLayout(s: SceneObject): s is SceneLayout {\n return 'isDraggable' in s;\n}\n\n/**\n * Will walk up the scene object graph to the closest $layout scene object\n */\nexport function getLayout(scene: SceneObject): SceneLayout | null {\n const parent = getClosest(scene, (s) => (isSceneLayout(s) ? s : undefined));\n if (parent) {\n return parent;\n }\n\n return null;\n}\n\n/**\n * Interpolates the given string using the current scene object as context. *\n *\n * Note: the interpolations array will be mutated by adding information about variables that\n * have been interpolated during replacement. Variables that were specified in the target but not found in\n * the list of available variables are also added to the array. See {@link VariableInterpolation} for more details.\n *\n * @param {VariableInterpolation[]} interpolations an optional array that is updated with interpolated variables.\n */\nexport function interpolate(\n sceneObject: SceneObject,\n value: string | undefined | null,\n scopedVars?: ScopedVars,\n format?: string | VariableCustomFormatterFn,\n interpolations?: VariableInterpolation[]\n): string {\n if (value === '' || value == null) {\n return '';\n }\n\n return sceneInterpolator(sceneObject, value, scopedVars, format, interpolations);\n}\n\n/**\n * Checks if the variable is currently loading or waiting to update.\n * It also returns true if a dependency of the variable is loading.\n *\n * For example if C depends on variable B which depends on variable A and A is loading this returns true for variable C and B.\n */\nexport function hasVariableDependencyInLoadingState(sceneObject: SceneObject) {\n if (!sceneObject.variableDependency) {\n return false;\n }\n\n for (const name of sceneObject.variableDependency.getNames()) {\n // This is for backwards compability. In the old architecture query variables could reference itself in a query without breaking.\n if (sceneObject instanceof QueryVariable && sceneObject.state.name === name) {\n console.warn('Query variable is referencing itself');\n continue;\n }\n\n const variable = lookupVariable(name, sceneObject);\n if (!variable) {\n continue;\n }\n\n const set = variable.parent as SceneVariables;\n if (set.isVariableLoadingOrWaitingToUpdate(variable)) {\n return true;\n }\n }\n\n return false;\n}\n\nfunction findObjectInternal(\n scene: SceneObject,\n check: (obj: SceneObject) => boolean,\n alreadySearchedChild?: SceneObject,\n shouldSearchUp?: boolean\n): SceneObject | null {\n if (check(scene)) {\n return scene;\n }\n\n let found: SceneObject | null = null;\n\n scene.forEachChild((child) => {\n if (child === alreadySearchedChild) {\n return;\n }\n\n let maybe = findObjectInternal(child, check);\n if (maybe) {\n found = maybe;\n }\n });\n\n if (found) {\n return found;\n }\n\n if (shouldSearchUp && scene.parent) {\n return findObjectInternal(scene.parent, check, scene, true);\n }\n\n return null;\n}\n\n/**\n * Returns a scene object from the scene graph with the requested key.\n *\n * Throws error if no key-matching scene object found.\n */\nexport function findByKey(sceneObject: SceneObject, key: string) {\n const found = findObject(sceneObject, (sceneToCheck) => {\n return sceneToCheck.state.key === key;\n });\n if (!found) {\n throw new Error('Unable to find scene with key ' + key);\n }\n return found;\n}\n\n/**\n * Returns a scene object from the scene graph with the requested key and type.\n *\n * Throws error if no key-matching scene object found.\n * Throws error if the given type does not match.\n */\nexport function findByKeyAndType<TargetType extends SceneObject>(\n sceneObject: SceneObject,\n key: string,\n targetType: { new (...args: never[]): TargetType }\n) {\n const found = findObject(sceneObject, (sceneToCheck) => {\n return sceneToCheck.state.key === key;\n });\n if (!found) {\n throw new Error('Unable to find scene with key ' + key);\n }\n if (!(found instanceof targetType)) {\n throw new Error(`Found scene object with key ${key} does not match type ${targetType.name}`);\n }\n return found;\n}\n\n/**\n * This will search the full scene graph, starting with the scene node passed in, then walking up the parent chain. *\n */\nexport function findObject(scene: SceneObject, check: (obj: SceneObject) => boolean): SceneObject | null {\n return findObjectInternal(scene, check, undefined, true);\n}\n\n/**\n * This will search down the full scene graph, looking for objects that match the provided predicate.\n */\nexport function findAllObjects(scene: SceneObject, check: (obj: SceneObject) => boolean): SceneObject[] {\n const found: SceneObject[] = [];\n\n scene.forEachChild((child) => {\n if (check(child)) {\n found.push(child);\n }\n\n found.push(...findAllObjects(child, check));\n });\n\n return found;\n}\n\n/**\n * Will walk up the scene object graph up until the root and collect all SceneDataLayerProvider objects.\n * When localOnly set to true, it will only collect the closest layers.\n */\nexport function getDataLayers(sceneObject: SceneObject, localOnly = false): SceneDataLayerProvider[] {\n let currentLevel: SceneObject | undefined = sceneObject;\n let collected: SceneDataLayerProvider[] = [];\n\n while (currentLevel) {\n const dataProvider = currentLevel.state.$data;\n if (!dataProvider) {\n currentLevel = currentLevel.parent;\n continue;\n }\n\n // Check if data layer exists nested inside another data provider\n if (isDataLayer(dataProvider)) {\n collected = collected.concat(dataProvider);\n } else {\n if (dataProvider.state.$data && isDataLayer(dataProvider.state.$data)) {\n collected = collected.concat(dataProvider.state.$data);\n }\n }\n\n if (localOnly && collected.length > 0) {\n break;\n }\n\n currentLevel = currentLevel.parent;\n }\n\n return collected;\n}\n\n/**\n * A utility function to find the closest ancestor of a given type. This function expects\n * to find it and will throw an error if it does not.\n */\nexport function getAncestor<ParentType>(\n sceneObject: SceneObject,\n ancestorType: { new (...args: never[]): ParentType }\n): ParentType {\n let parent: SceneObject | undefined = sceneObject;\n\n while (parent) {\n if (parent instanceof ancestorType) {\n return parent;\n }\n parent = parent.parent;\n }\n\n if (!parent) {\n throw new Error('Unable to find parent of type ' + ancestorType.name);\n }\n\n return parent as ParentType;\n}\n\n/**\n * Returns the closest query controller undefined if none found\n */\nexport function getQueryController(sceneObject: SceneObject): SceneQueryControllerLike | undefined {\n let parent: SceneObject | undefined = sceneObject;\n\n while (parent) {\n if (parent.state.$behaviors) {\n for (const behavior of parent.state.$behaviors) {\n if (isQueryController(behavior)) {\n return behavior;\n }\n }\n }\n parent = parent.parent;\n }\n\n return undefined;\n}\n\n/**\n * Returns the closest SceneObject that has a state property with the\n * name urlSyncManager that is of type UrlSyncManager\n */\nexport function getUrlSyncManager(sceneObject: SceneObject): UrlSyncManagerLike | undefined {\n let parent: SceneObject | undefined = sceneObject;\n\n while (parent) {\n if ('urlSyncManager' in parent.state) {\n return parent.state.urlSyncManager as UrlSyncManagerLike;\n }\n parent = parent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;;;"}
1
+ {"version":3,"file":"sceneGraph.js","sources":["../../../../src/core/sceneGraph/sceneGraph.ts"],"sourcesContent":["import { ScopedVars } from '@grafana/data';\nimport { EmptyDataNode, EmptyVariableSet } from '../../variables/interpolation/defaults';\n\nimport { sceneInterpolator } from '../../variables/interpolation/sceneInterpolator';\nimport { VariableCustomFormatterFn, SceneVariables } from '../../variables/types';\n\nimport { isDataLayer, SceneDataLayerProvider, SceneDataProvider, SceneLayout, SceneObject } from '../types';\nimport { lookupVariable } from '../../variables/lookupVariable';\nimport { getClosest } from './utils';\nimport { SceneQueryControllerLike, isQueryController } from '../../behaviors/SceneQueryController';\nimport { VariableInterpolation } from '@grafana/runtime';\nimport { QueryVariable } from '../../variables/variants/query/QueryVariable';\nimport { UrlSyncManagerLike } from '../../services/UrlSyncManager';\n\n/**\n * Get the closest node with variables\n */\nexport function getVariables(sceneObject: SceneObject): SceneVariables {\n return getClosest(sceneObject, (s) => s.state.$variables) ?? EmptyVariableSet;\n}\n\n/**\n * Will walk up the scene object graph to the closest $data scene object\n */\nexport function getData(sceneObject: SceneObject): SceneDataProvider {\n return getClosest(sceneObject, (s) => s.state.$data) ?? EmptyDataNode;\n}\n\nfunction isSceneLayout(s: SceneObject): s is SceneLayout {\n return 'isDraggable' in s;\n}\n\n/**\n * Will walk up the scene object graph to the closest $layout scene object\n */\nexport function getLayout(scene: SceneObject): SceneLayout | null {\n const parent = getClosest(scene, (s) => (isSceneLayout(s) ? s : undefined));\n if (parent) {\n return parent;\n }\n\n return null;\n}\n\n/**\n * Interpolates the given string using the current scene object as context. *\n *\n * Note: the interpolations array will be mutated by adding information about variables that\n * have been interpolated during replacement. Variables that were specified in the target but not found in\n * the list of available variables are also added to the array. See {@link VariableInterpolation} for more details.\n *\n * @param {VariableInterpolation[]} interpolations an optional array that is updated with interpolated variables.\n */\nexport function interpolate(\n sceneObject: SceneObject,\n value: string | undefined | null,\n scopedVars?: ScopedVars,\n format?: string | VariableCustomFormatterFn,\n interpolations?: VariableInterpolation[]\n): string {\n if (value === '' || value == null) {\n return '';\n }\n\n return sceneInterpolator(sceneObject, value, scopedVars, format, interpolations);\n}\n\n/**\n * Checks if the variable is currently loading or waiting to update.\n * It also returns true if a dependency of the variable is loading.\n *\n * For example if C depends on variable B which depends on variable A and A is loading this returns true for variable C and B.\n */\nexport function hasVariableDependencyInLoadingState(sceneObject: SceneObject) {\n if (!sceneObject.variableDependency) {\n return false;\n }\n\n for (const name of sceneObject.variableDependency.getNames()) {\n // This is for backwards compability. In the old architecture query variables could reference itself in a query without breaking.\n if (sceneObject instanceof QueryVariable && sceneObject.state.name === name) {\n console.warn('Query variable is referencing itself');\n continue;\n }\n\n const variable = lookupVariable(name, sceneObject);\n if (!variable) {\n continue;\n }\n\n const set = variable.parent as SceneVariables;\n if (set.isVariableLoadingOrWaitingToUpdate(variable)) {\n return true;\n }\n }\n\n return false;\n}\n\nfunction findObjectInternal(\n scene: SceneObject,\n check: (obj: SceneObject) => boolean,\n alreadySearchedChild?: SceneObject,\n shouldSearchUp?: boolean\n): SceneObject | null {\n if (check(scene)) {\n return scene;\n }\n\n let found: SceneObject | null = null;\n\n scene.forEachChild((child) => {\n if (child === alreadySearchedChild) {\n return;\n }\n\n let maybe = findObjectInternal(child, check);\n if (maybe) {\n found = maybe;\n }\n });\n\n if (found) {\n return found;\n }\n\n if (shouldSearchUp && scene.parent) {\n return findObjectInternal(scene.parent, check, scene, true);\n }\n\n return null;\n}\n\n/**\n * Returns a scene object from the scene graph with the requested key.\n *\n * Throws error if no key-matching scene object found.\n */\nexport function findByKey(sceneObject: SceneObject, key: string) {\n const found = findObject(sceneObject, (sceneToCheck) => {\n return sceneToCheck.state.key === key;\n });\n if (!found) {\n throw new Error('Unable to find scene with key ' + key);\n }\n return found;\n}\n\n/**\n * Returns a scene object from the scene graph with the requested key and type.\n *\n * Throws error if no key-matching scene object found.\n * Throws error if the given type does not match.\n */\nexport function findByKeyAndType<TargetType extends SceneObject>(\n sceneObject: SceneObject,\n key: string,\n targetType: { new (...args: never[]): TargetType }\n) {\n const found = findObject(sceneObject, (sceneToCheck) => {\n return sceneToCheck.state.key === key;\n });\n if (!found) {\n throw new Error('Unable to find scene with key ' + key);\n }\n if (!(found instanceof targetType)) {\n throw new Error(`Found scene object with key ${key} does not match type ${targetType.name}`);\n }\n return found;\n}\n\n/**\n * This will search the full scene graph, starting with the scene node passed in, then walking up the parent chain. *\n */\nexport function findObject(scene: SceneObject, check: (obj: SceneObject) => boolean): SceneObject | null {\n return findObjectInternal(scene, check, undefined, true);\n}\n\n/**\n * This will search down the full scene graph, looking for objects that match the provided predicate.\n */\nexport function findAllObjects(scene: SceneObject, check: (obj: SceneObject) => boolean): SceneObject[] {\n const found: SceneObject[] = [];\n\n scene.forEachChild((child) => {\n if (check(child)) {\n found.push(child);\n }\n\n found.push(...findAllObjects(child, check));\n });\n\n return found;\n}\n\n/**\n * Will walk up the scene object graph up until the root and collect all SceneDataLayerProvider objects.\n * When localOnly set to true, it will only collect the closest layers.\n */\nexport function getDataLayers(sceneObject: SceneObject, localOnly = false): SceneDataLayerProvider[] {\n let currentLevel: SceneObject | undefined = sceneObject;\n let collected: SceneDataLayerProvider[] = [];\n\n while (currentLevel) {\n const dataProvider = currentLevel.state.$data;\n if (!dataProvider) {\n currentLevel = currentLevel.parent;\n continue;\n }\n\n // Check if data layer exists nested inside another data provider\n if (isDataLayer(dataProvider)) {\n collected = collected.concat(dataProvider);\n } else {\n if (dataProvider.state.$data && isDataLayer(dataProvider.state.$data)) {\n collected = collected.concat(dataProvider.state.$data);\n }\n }\n\n if (localOnly && collected.length > 0) {\n break;\n }\n\n currentLevel = currentLevel.parent;\n }\n\n return collected;\n}\n\ninterface SceneType<T> extends Function {\n new (...args: never[]): T;\n}\n\n/**\n * A utility function to find the closest ancestor of a given type. This function expects\n * to find it and will throw an error if it does not.\n */\nexport function getAncestor<ParentType>(\n sceneObject: SceneObject,\n ancestorType: SceneType<ParentType>\n): ParentType {\n let parent: SceneObject | undefined = sceneObject;\n\n while (parent) {\n if (parent instanceof ancestorType) {\n return parent;\n }\n parent = parent.parent;\n }\n\n if (!parent) {\n throw new Error('Unable to find parent of type ' + ancestorType.name);\n }\n\n return parent as ParentType;\n}\n\n/**\n * This will search down the full scene graph, looking for objects that match the provided descendentType type.\n */\nexport function findDescendents<T extends SceneObject>(scene: SceneObject, descendentType: SceneType<T>) {\n function isDescendentType(scene: SceneObject): scene is T {\n return scene instanceof descendentType;\n }\n\n const targetScenes = findAllObjects(scene, isDescendentType);\n return targetScenes.filter(isDescendentType);\n}\n\n/**\n * Returns the closest query controller undefined if none found\n */\nexport function getQueryController(sceneObject: SceneObject): SceneQueryControllerLike | undefined {\n let parent: SceneObject | undefined = sceneObject;\n\n while (parent) {\n if (parent.state.$behaviors) {\n for (const behavior of parent.state.$behaviors) {\n if (isQueryController(behavior)) {\n return behavior;\n }\n }\n }\n parent = parent.parent;\n }\n\n return undefined;\n}\n\n/**\n * Returns the closest SceneObject that has a state property with the\n * name urlSyncManager that is of type UrlSyncManager\n */\nexport function getUrlSyncManager(sceneObject: SceneObject): UrlSyncManagerLike | undefined {\n let parent: SceneObject | undefined = sceneObject;\n\n while (parent) {\n if ('urlSyncManager' in parent.state) {\n return parent.state.urlSyncManager as UrlSyncManagerLike;\n }\n parent = parent.parent;\n }\n\n return undefined;\n}\n"],"names":["scene"],"mappings":";;;;;;;;AAiBO,SAAS,aAAa,WAA0C,EAAA;AAjBvE,EAAA,IAAA,EAAA,CAAA;AAkBE,EAAO,OAAA,CAAA,EAAA,GAAA,UAAA,CAAW,aAAa,CAAC,CAAA,KAAM,EAAE,KAAM,CAAA,UAAU,MAAjD,IAAsD,GAAA,EAAA,GAAA,gBAAA,CAAA;AAC/D,CAAA;AAKO,SAAS,QAAQ,WAA6C,EAAA;AAxBrE,EAAA,IAAA,EAAA,CAAA;AAyBE,EAAO,OAAA,CAAA,EAAA,GAAA,UAAA,CAAW,aAAa,CAAC,CAAA,KAAM,EAAE,KAAM,CA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,EAAO,OAAA,MAAA,CAAA;AACT,CAAA;AAKgB,SAAA,eAAA,CAAuC,OAAoB,cAA8B,EAAA;AACvG,EAAA,SAAS,iBAAiBA,MAAgC,EAAA;AACxD,IAAA,OAAOA,MAAiB,YAAA,cAAA,CAAA;AAAA,GAC1B;AAEA,EAAM,MAAA,YAAA,GAAe,cAAe,CAAA,KAAA,EAAO,gBAAgB,CAAA,CAAA;AAC3D,EAAO,OAAA,YAAA,CAAa,OAAO,gBAAgB,CAAA,CAAA;AAC7C,CAAA;AAKO,SAAS,mBAAmB,WAAgE,EAAA;AACjG,EAAA,IAAI,MAAkC,GAAA,WAAA,CAAA;AAEtC,EAAA,OAAO,MAAQ,EAAA;AACb,IAAI,IAAA,MAAA,CAAO,MAAM,UAAY,EAAA;AAC3B,MAAW,KAAA,MAAA,QAAA,IAAY,MAAO,CAAA,KAAA,CAAM,UAAY,EAAA;AAC9C,QAAI,IAAA,iBAAA,CAAkB,QAAQ,CAAG,EAAA;AAC/B,UAAO,OAAA,QAAA,CAAA;AAAA,SACT;AAAA,OACF;AAAA,KACF;AACA,IAAA,MAAA,GAAS,MAAO,CAAA,MAAA,CAAA;AAAA,GAClB;AAEA,EAAO,OAAA,KAAA,CAAA,CAAA;AACT,CAAA;AAMO,SAAS,kBAAkB,WAA0D,EAAA;AAC1F,EAAA,IAAI,MAAkC,GAAA,WAAA,CAAA;AAEtC,EAAA,OAAO,MAAQ,EAAA;AACb,IAAI,IAAA,gBAAA,IAAoB,OAAO,KAAO,EAAA;AACpC,MAAA,OAAO,OAAO,KAAM,CAAA,cAAA,CAAA;AAAA,KACtB;AACA,IAAA,MAAA,GAAS,MAAO,CAAA,MAAA,CAAA;AAAA,GAClB;AAEA,EAAO,OAAA,KAAA,CAAA,CAAA;AACT;;;;"}
@@ -26,11 +26,11 @@ class MultiValueVariable extends SceneObjectBase {
26
26
  sceneVarSet == null ? void 0 : sceneVarSet.cancel(this);
27
27
  }
28
28
  updateValueGivenNewOptions(options) {
29
- const { value: currentValue, text: currentText } = this.state;
29
+ const { value: currentValue, text: currentText, options: oldOptions } = this.state;
30
30
  const stateUpdate = this.getStateUpdateGivenNewOptions(options, currentValue, currentText);
31
31
  this.interceptStateUpdateAfterValidation(stateUpdate);
32
32
  this.setStateHelper(stateUpdate);
33
- if (stateUpdate.value !== currentValue || stateUpdate.text !== currentText || this.hasAllValue()) {
33
+ if (stateUpdate.value !== currentValue || stateUpdate.text !== currentText || this.hasAllValue() && !isEqual(options, oldOptions)) {
34
34
  this.publishEvent(new SceneVariableValueChangedEvent(this), true);
35
35
  }
36
36
  }
@@ -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 && stateUpdate.text !== this.state.text && !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.getValueOptions({}).subscribe((options) => {\n this.updateValueGivenNewOptions(options);\n });\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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,GAAA,MAAA,CAAA;AAAwB,IAAA,IAAA,CAAA,SAAA,GAAA,SAAA,CAAA;AAAA,GAA2B;AAAA,EAEvE,UAAU,cAA6D,EAAA;AAC5E,IAAI,IAAA,cAAA,KAAmB,iBAAiB,IAAM,EAAA;AAC5C,MAAO,OAAA,iBAAA,CAAA;AAAA,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;;;;"}
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, options: oldOptions } = 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() && !isEqual(options, oldOptions))) {\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 && stateUpdate.text !== this.state.text && !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.getValueOptions({}).subscribe((options) => {\n this.updateValueGivenNewOptions(options);\n });\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,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refresh: VariableRefresh.onDashboardLoad,
37
+ updateOptions: true
37
38
  }, initialState));
38
39
  this.completeUpdate = new Subject();
39
40
  this.isGettingValues = true;
@@ -65,7 +66,11 @@ class TestVariable extends MultiValueVariable {
65
66
  const options = this.getOptions(interpolatedQuery);
66
67
  const sub = this.completeUpdate.subscribe({
67
68
  next: () => {
68
- this.setState({ issuedQuery: interpolatedQuery, options, loading: false });
69
+ const newState = { issuedQuery: interpolatedQuery, loading: false };
70
+ if (this.state.updateOptions) {
71
+ newState.options = options;
72
+ }
73
+ this.setState(newState);
69
74
  observer.next(options);
70
75
  observer.complete();
71
76
  }
@@ -1 +1 @@
1
- {"version":3,"file":"TestVariable.js","sources":["../../../../src/variables/variants/TestVariable.tsx"],"sourcesContent":["import { Observable, Subject } from 'rxjs';\n\nimport { sceneGraph } from '../../core/sceneGraph';\nimport { SceneComponentProps } from '../../core/types';\nimport { queryMetricTree } from '../../utils/metricTree';\nimport { VariableDependencyConfig } from '../VariableDependencyConfig';\nimport { renderSelectForVariable } from '../components/VariableValueSelect';\nimport { VariableValueOption } from '../types';\n\nimport { MultiValueVariable, MultiValueVariableState, VariableGetOptionsArgs } from './MultiValueVariable';\nimport { VariableRefresh } from '@grafana/data';\nimport { getClosest } from '../../core/sceneGraph/utils';\nimport { SceneVariableSet } from '../sets/SceneVariableSet';\nimport { SceneQueryControllerEntry } from '../../behaviors/SceneQueryController';\n\nexport interface TestVariableState extends MultiValueVariableState {\n query: string;\n delayMs?: number;\n issuedQuery?: string;\n refresh?: VariableRefresh;\n throwError?: string;\n optionsToReturn?: VariableValueOption[];\n}\n\n/**\n * This variable is only designed for unit tests and potentially e2e tests.\n */\nexport class TestVariable extends MultiValueVariable<TestVariableState> {\n private completeUpdate = new Subject<number>();\n public isGettingValues = true;\n public getValueOptionsCount = 0;\n isLazy = false;\n\n protected _variableDependency = new VariableDependencyConfig(this, {\n statePaths: ['query'],\n });\n\n public constructor(initialState: Partial<TestVariableState>, isLazy = false) {\n super({\n type: 'custom',\n name: 'Test',\n value: 'Value',\n text: 'Text',\n query: 'Query',\n options: [],\n refresh: VariableRefresh.onDashboardLoad,\n ...initialState,\n });\n this.isLazy = isLazy;\n }\n\n public getValueOptions(args: VariableGetOptionsArgs): Observable<VariableValueOption[]> {\n const { delayMs } = this.state;\n\n this.getValueOptionsCount += 1;\n\n const queryController = sceneGraph.getQueryController(this);\n\n return new Observable<VariableValueOption[]>((observer) => {\n const queryEntry: SceneQueryControllerEntry = {\n type: 'variable',\n origin: this,\n cancel: () => observer.complete(),\n };\n\n if (queryController) {\n queryController.queryStarted(queryEntry);\n }\n\n this.setState({ loading: true });\n\n if (this.state.throwError) {\n throw new Error(this.state.throwError);\n }\n\n const interpolatedQuery = sceneGraph.interpolate(this, this.state.query);\n const options = this.getOptions(interpolatedQuery);\n\n const sub = this.completeUpdate.subscribe({\n next: () => {\n this.setState({ issuedQuery: interpolatedQuery, options, loading: false });\n observer.next(options);\n observer.complete();\n },\n });\n\n let timeout: number | undefined;\n if (delayMs) {\n timeout = window.setTimeout(() => this.signalUpdateCompleted(), delayMs);\n } else if (delayMs === 0) {\n this.signalUpdateCompleted();\n }\n\n this.isGettingValues = true;\n\n return () => {\n sub.unsubscribe();\n window.clearTimeout(timeout);\n this.isGettingValues = false;\n\n if (this.state.loading) {\n this.setState({ loading: false });\n }\n\n if (queryController) {\n queryController.queryCompleted(queryEntry);\n }\n };\n });\n }\n\n public cancel() {\n const sceneVarSet = getClosest(this, (s) => (s instanceof SceneVariableSet ? s : undefined));\n sceneVarSet?.cancel(this);\n }\n\n private getOptions(interpolatedQuery: string) {\n if (this.state.optionsToReturn) {\n return this.state.optionsToReturn;\n }\n\n return queryMetricTree(interpolatedQuery).map((x) => ({ label: x.name, value: x.name }));\n }\n\n /** Useful from tests */\n public signalUpdateCompleted() {\n this.completeUpdate.next(1);\n }\n\n public static Component = ({ model }: SceneComponentProps<MultiValueVariable>) => {\n return renderSelectForVariable(model);\n };\n}\n"],"names":[],"mappings":";;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"],"sourcesContent":["import { Observable, Subject } from 'rxjs';\n\nimport { sceneGraph } from '../../core/sceneGraph';\nimport { SceneComponentProps } from '../../core/types';\nimport { queryMetricTree } from '../../utils/metricTree';\nimport { VariableDependencyConfig } from '../VariableDependencyConfig';\nimport { renderSelectForVariable } from '../components/VariableValueSelect';\nimport { VariableValueOption } from '../types';\n\nimport { MultiValueVariable, MultiValueVariableState, VariableGetOptionsArgs } from './MultiValueVariable';\nimport { VariableRefresh } from '@grafana/data';\nimport { getClosest } from '../../core/sceneGraph/utils';\nimport { SceneVariableSet } from '../sets/SceneVariableSet';\nimport { SceneQueryControllerEntry } from '../../behaviors/SceneQueryController';\n\nexport interface TestVariableState extends MultiValueVariableState {\n query: string;\n delayMs?: number;\n issuedQuery?: string;\n refresh?: VariableRefresh;\n throwError?: string;\n optionsToReturn?: VariableValueOption[];\n updateOptions?: boolean;\n}\n\n/**\n * This variable is only designed for unit tests and potentially e2e tests.\n */\nexport class TestVariable extends MultiValueVariable<TestVariableState> {\n private completeUpdate = new Subject<number>();\n public isGettingValues = true;\n public getValueOptionsCount = 0;\n isLazy = false;\n\n protected _variableDependency = new VariableDependencyConfig(this, {\n statePaths: ['query'],\n });\n\n public constructor(initialState: Partial<TestVariableState>, isLazy = false) {\n super({\n type: 'custom',\n name: 'Test',\n value: 'Value',\n text: 'Text',\n query: 'Query',\n options: [],\n refresh: VariableRefresh.onDashboardLoad,\n updateOptions: true,\n ...initialState,\n });\n this.isLazy = isLazy;\n }\n\n public getValueOptions(args: VariableGetOptionsArgs): Observable<VariableValueOption[]> {\n const { delayMs } = this.state;\n\n this.getValueOptionsCount += 1;\n\n const queryController = sceneGraph.getQueryController(this);\n\n return new Observable<VariableValueOption[]>((observer) => {\n const queryEntry: SceneQueryControllerEntry = {\n type: 'variable',\n origin: this,\n cancel: () => observer.complete(),\n };\n\n if (queryController) {\n queryController.queryStarted(queryEntry);\n }\n\n this.setState({ loading: true });\n\n if (this.state.throwError) {\n throw new Error(this.state.throwError);\n }\n\n const interpolatedQuery = sceneGraph.interpolate(this, this.state.query);\n const options = this.getOptions(interpolatedQuery);\n\n const sub = this.completeUpdate.subscribe({\n next: () => {\n const newState: Partial<TestVariableState> = { issuedQuery: interpolatedQuery, loading: false };\n\n if (this.state.updateOptions) {\n newState.options = options;\n }\n\n this.setState(newState);\n observer.next(options);\n observer.complete();\n },\n });\n\n let timeout: number | undefined;\n if (delayMs) {\n timeout = window.setTimeout(() => this.signalUpdateCompleted(), delayMs);\n } else if (delayMs === 0) {\n this.signalUpdateCompleted();\n }\n\n this.isGettingValues = true;\n\n return () => {\n sub.unsubscribe();\n window.clearTimeout(timeout);\n this.isGettingValues = false;\n\n if (this.state.loading) {\n this.setState({ loading: false });\n }\n\n if (queryController) {\n queryController.queryCompleted(queryEntry);\n }\n };\n });\n }\n\n public cancel() {\n const sceneVarSet = getClosest(this, (s) => (s instanceof SceneVariableSet ? s : undefined));\n sceneVarSet?.cancel(this);\n }\n\n private getOptions(interpolatedQuery: string) {\n if (this.state.optionsToReturn) {\n return this.state.optionsToReturn;\n }\n\n return queryMetricTree(interpolatedQuery).map((x) => ({ label: x.name, value: x.name }));\n }\n\n /** Useful from tests */\n public signalUpdateCompleted() {\n this.completeUpdate.next(1);\n }\n\n public static Component = ({ model }: SceneComponentProps<MultiValueVariable>) => {\n return renderSelectForVariable(model);\n };\n}\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AA4BO,MAAM,qBAAqB,kBAAsC,CAAA;AAAA,EAU/D,WAAA,CAAY,YAA0C,EAAA,MAAA,GAAS,KAAO,EAAA;AAC3E,IAAM,KAAA,CAAA,cAAA,CAAA;AAAA,MACJ,IAAM,EAAA,QAAA;AAAA,MACN,IAAM,EAAA,MAAA;AAAA,MACN,KAAO,EAAA,OAAA;AAAA,MACP,IAAM,EAAA,MAAA;AAAA,MACN,KAAO,EAAA,OAAA;AAAA,MACP,SAAS,EAAC;AAAA,MACV,SAAS,eAAgB,CAAA,eAAA;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A,CAAA;AAAA,SAClC;AAEA,QAAA,IAAI,eAAiB,EAAA;AACnB,UAAA,eAAA,CAAgB,eAAe,UAAU,CAAA,CAAA;AAAA,SAC3C;AAAA,OACF,CAAA;AAAA,KACD,CAAA,CAAA;AAAA,GACH;AAAA,EAEO,MAAS,GAAA;AACd,IAAM,MAAA,WAAA,GAAc,WAAW,IAAM,EAAA,CAAC,MAAO,CAAa,YAAA,gBAAA,GAAmB,IAAI,KAAU,CAAA,CAAA,CAAA;AAC3F,IAAA,WAAA,IAAA,IAAA,GAAA,KAAA,CAAA,GAAA,WAAA,CAAa,MAAO,CAAA,IAAA,CAAA,CAAA;AAAA,GACtB;AAAA,EAEQ,WAAW,iBAA2B,EAAA;AAC5C,IAAI,IAAA,IAAA,CAAK,MAAM,eAAiB,EAAA;AAC9B,MAAA,OAAO,KAAK,KAAM,CAAA,eAAA,CAAA;AAAA,KACpB;AAEA,IAAA,OAAO,eAAgB,CAAA,iBAAiB,CAAE,CAAA,GAAA,CAAI,CAAC,CAAA,MAAO,EAAE,KAAA,EAAO,CAAE,CAAA,IAAA,EAAM,KAAO,EAAA,CAAA,CAAE,MAAO,CAAA,CAAA,CAAA;AAAA,GACzF;AAAA,EAGO,qBAAwB,GAAA;AAC7B,IAAK,IAAA,CAAA,cAAA,CAAe,KAAK,CAAC,CAAA,CAAA;AAAA,GAC5B;AAKF,CAAA;AAhHa,YAAA,CA6GG,SAAY,GAAA,CAAC,EAAE,KAAA,EAAqD,KAAA;AAChF,EAAA,OAAO,wBAAwB,KAAK,CAAA,CAAA;AACtC,CAAA;;;;"}
package/dist/index.d.ts CHANGED
@@ -1068,13 +1068,18 @@ declare function findAllObjects(scene: SceneObject, check: (obj: SceneObject) =>
1068
1068
  * When localOnly set to true, it will only collect the closest layers.
1069
1069
  */
1070
1070
  declare function getDataLayers(sceneObject: SceneObject, localOnly?: boolean): SceneDataLayerProvider[];
1071
+ interface SceneType<T> extends Function {
1072
+ new (...args: never[]): T;
1073
+ }
1071
1074
  /**
1072
1075
  * A utility function to find the closest ancestor of a given type. This function expects
1073
1076
  * to find it and will throw an error if it does not.
1074
1077
  */
1075
- declare function getAncestor<ParentType>(sceneObject: SceneObject, ancestorType: {
1076
- new (...args: never[]): ParentType;
1077
- }): ParentType;
1078
+ declare function getAncestor<ParentType>(sceneObject: SceneObject, ancestorType: SceneType<ParentType>): ParentType;
1079
+ /**
1080
+ * This will search down the full scene graph, looking for objects that match the provided descendentType type.
1081
+ */
1082
+ declare function findDescendents<T extends SceneObject>(scene: SceneObject, descendentType: SceneType<T>): T[];
1078
1083
  /**
1079
1084
  * Returns the closest query controller undefined if none found
1080
1085
  */
@@ -1099,6 +1104,7 @@ declare const sceneGraph: {
1099
1104
  findObject: typeof findObject;
1100
1105
  findAllObjects: typeof findAllObjects;
1101
1106
  getAncestor: typeof getAncestor;
1107
+ findDescendents: typeof findDescendents;
1102
1108
  getQueryController: typeof getQueryController;
1103
1109
  getUrlSyncManager: typeof getUrlSyncManager;
1104
1110
  };
@@ -1618,6 +1624,7 @@ interface TestVariableState extends MultiValueVariableState {
1618
1624
  refresh?: VariableRefresh$1;
1619
1625
  throwError?: string;
1620
1626
  optionsToReturn?: VariableValueOption[];
1627
+ updateOptions?: boolean;
1621
1628
  }
1622
1629
  /**
1623
1630
  * This variable is only designed for unit tests and potentially e2e tests.
package/dist/index.js CHANGED
@@ -2216,11 +2216,11 @@ class MultiValueVariable extends SceneObjectBase {
2216
2216
  sceneVarSet == null ? void 0 : sceneVarSet.cancel(this);
2217
2217
  }
2218
2218
  updateValueGivenNewOptions(options) {
2219
- const { value: currentValue, text: currentText } = this.state;
2219
+ const { value: currentValue, text: currentText, options: oldOptions } = this.state;
2220
2220
  const stateUpdate = this.getStateUpdateGivenNewOptions(options, currentValue, currentText);
2221
2221
  this.interceptStateUpdateAfterValidation(stateUpdate);
2222
2222
  this.setStateHelper(stateUpdate);
2223
- if (stateUpdate.value !== currentValue || stateUpdate.text !== currentText || this.hasAllValue()) {
2223
+ if (stateUpdate.value !== currentValue || stateUpdate.text !== currentText || this.hasAllValue() && !lodash.isEqual(options, oldOptions)) {
2224
2224
  this.publishEvent(new SceneVariableValueChangedEvent(this), true);
2225
2225
  }
2226
2226
  }
@@ -6289,6 +6289,13 @@ function getAncestor(sceneObject, ancestorType) {
6289
6289
  }
6290
6290
  return parent;
6291
6291
  }
6292
+ function findDescendents(scene, descendentType) {
6293
+ function isDescendentType(scene2) {
6294
+ return scene2 instanceof descendentType;
6295
+ }
6296
+ const targetScenes = findAllObjects(scene, isDescendentType);
6297
+ return targetScenes.filter(isDescendentType);
6298
+ }
6292
6299
  function getQueryController(sceneObject) {
6293
6300
  let parent = sceneObject;
6294
6301
  while (parent) {
@@ -6328,6 +6335,7 @@ const sceneGraph = {
6328
6335
  findObject,
6329
6336
  findAllObjects,
6330
6337
  getAncestor,
6338
+ findDescendents,
6331
6339
  getQueryController,
6332
6340
  getUrlSyncManager
6333
6341
  };
@@ -8999,7 +9007,8 @@ class TestVariable extends MultiValueVariable {
8999
9007
  text: "Text",
9000
9008
  query: "Query",
9001
9009
  options: [],
9002
- refresh: data.VariableRefresh.onDashboardLoad
9010
+ refresh: data.VariableRefresh.onDashboardLoad,
9011
+ updateOptions: true
9003
9012
  }, initialState));
9004
9013
  this.completeUpdate = new rxjs.Subject();
9005
9014
  this.isGettingValues = true;
@@ -9031,7 +9040,11 @@ class TestVariable extends MultiValueVariable {
9031
9040
  const options = this.getOptions(interpolatedQuery);
9032
9041
  const sub = this.completeUpdate.subscribe({
9033
9042
  next: () => {
9034
- this.setState({ issuedQuery: interpolatedQuery, options, loading: false });
9043
+ const newState = { issuedQuery: interpolatedQuery, loading: false };
9044
+ if (this.state.updateOptions) {
9045
+ newState.options = options;
9046
+ }
9047
+ this.setState(newState);
9035
9048
  observer.next(options);
9036
9049
  observer.complete();
9037
9050
  }