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

Sign up to get free protection for your applications and to get access to all the features.
@@ -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 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,EAAA,CAAA;AAErE,IAAQ,IAAA,CAAA,sBAAA,GAAyB,IAAI,qBAAsB,EAAA,CAAA;AAK3D,IAAA,IAAA,CAAU,sBAAsB,IAAI,yCAAA;AAAA,MAClC,IAAA,CAAK,qCAAsC,CAAA,IAAA,CAAK,IAAI,CAAA;AAAA,KACtD,CAAA;AAgBA,IAAA,IAAA,CAAQ,cAAc,MAAM;AAC1B,MAAM,MAAA,SAAA,GAAY,UAAW,CAAA,YAAA,CAAa,IAAI,CAAA,CAAA;AAE9C,MAAA,IAAA,CAAK,KAAM,CAAA,GAAA;AAAA,QACT,IAAA,CAAK,iBAAiB,8BAAgC,EAAA,CAAC,UAAU,IAAK,CAAA,2BAAA,CAA4B,KAAM,CAAA,OAAO,CAAC,CAAA;AAAA,OAClH,CAAA;AAGA,MAAA,IAAA,CAAK,KAAM,CAAA,GAAA;AAAA,QACT,IAAA,CAAK,iBAAiB,gCAAkC,EAAA,CAAC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A,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 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;AAK3D,IAAA,IAAA,CAAU,sBAAsB,IAAI,yCAAA;AAAA,MAClC,IAAA,CAAK,qCAAsC,CAAA,IAAA,CAAK,IAAI,CAAA;AAAA,KACtD,CAAA;AAgBA,IAAA,IAAA,CAAQ,cAAc,MAAM;AAC1B,MAAM,MAAA,SAAA,GAAY,UAAW,CAAA,YAAA,CAAa,IAAI,CAAA,CAAA;AAE9C,MAAA,IAAA,CAAK,KAAM,CAAA,GAAA;AAAA,QACT,IAAA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BAAA,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,12 +3,9 @@ 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";
9
6
  function isCustomVariableValue(value) {
10
7
  return typeof value === "object" && "formatter" in value;
11
8
  }
12
9
 
13
- export { SceneVariableOptionsRefreshEvent, SceneVariableValueChangedEvent, isCustomVariableValue };
10
+ export { SceneVariableValueChangedEvent, isCustomVariableValue };
14
11
  //# 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 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;;;;"}
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;;;;"}
@@ -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, SceneVariableOptionsRefreshEvent } from '../types.js';
5
+ import { SceneVariableValueChangedEvent } 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,9 +200,6 @@ class MultiValueVariable extends SceneObjectBase {
200
200
  }
201
201
  return options;
202
202
  }
203
- refreshOptions() {
204
- this.publishEvent(new SceneVariableOptionsRefreshEvent(this), true);
205
- }
206
203
  }
207
204
  function findOptionMatchingCurrent(currentValue, currentText, options) {
208
205
  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 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,GAC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EAAA;AACzD,EAAA,IAAI,OAAQ,CAAA,KAAK,CAAK,IAAA,KAAA,CAAM,OAAO,iBAAmB,EAAA;AACpD,IAAA,OAAO,CAAC,kBAAkB,CAAA,CAAA;AAAA,GAC5B,MAAA,IAAW,UAAU,iBAAmB,EAAA;AACtC,IAAO,OAAA,kBAAA,CAAA;AAAA,GACT;AAEA,EAAO,OAAA,KAAA,CAAA;AACT,CAAA;AAMO,MAAM,cAA8C,CAAA;AAAA,EAClD,WAAA,CAAoB,QAAwB,SAA0B,EAAA;AAAlD,IAAA,IAAA,CAAA,MAAA,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 } = 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,CA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,IAAA,KAAA,CAAM,OAAO,iBAAmB,EAAA;AACpD,IAAA,OAAO,CAAC,kBAAkB,CAAA,CAAA;AAAA,GAC5B,MAAA,IAAW,UAAU,iBAAmB,EAAA;AACtC,IAAO,OAAA,kBAAA,CAAA;AAAA,GACT;AAEA,EAAO,OAAA,KAAA,CAAA;AACT,CAAA;AAMO,MAAM,cAA8C,CAAA;AAAA,EAClD,WAAA,CAAoB,QAAwB,SAA0B,EAAA;AAAlD,IAAA,IAAA,CAAA,MAAA,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;;;;"}
package/dist/index.d.ts CHANGED
@@ -104,9 +104,6 @@ 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
- }
110
107
  interface SceneVariableDependencyConfigLike {
111
108
  /** Return all variable names this object depend on */
112
109
  getNames(): Set<string>;
@@ -723,7 +720,6 @@ declare abstract class MultiValueVariable<TState extends MultiValueVariableState
723
720
  */
724
721
  private setStateHelper;
725
722
  getOptionsForSelect(): VariableValueOption[];
726
- refreshOptions(): void;
727
723
  /**
728
724
  * Can be used by subclasses to do custom handling of option search based on search input
729
725
  */
@@ -1489,7 +1485,6 @@ declare class SceneVariableSet extends SceneObjectBase<SceneVariableSetState> im
1489
1485
  private _validateAndUpdateCompleted;
1490
1486
  cancel(variable: SceneVariable): void;
1491
1487
  private _handleVariableError;
1492
- private _handleVariableOptionsUpdate;
1493
1488
  private _handleVariableValueChanged;
1494
1489
  /**
1495
1490
  * This is called by any parent level variable set to notify scene that an update batch is completed.
@@ -1569,6 +1564,11 @@ declare class LocalValueVariable extends SceneObjectBase<LocalValueVariableState
1569
1564
  isAncestorLoading(): boolean;
1570
1565
  }
1571
1566
 
1567
+ declare class AdHocFiltersVariableV2 extends AdHocFiltersVariable {
1568
+ static Component: typeof AdHocFiltersVariableRendererV2;
1569
+ }
1570
+ declare function AdHocFiltersVariableRendererV2({ model }: SceneComponentProps<AdHocFiltersVariable>): React__default.JSX.Element;
1571
+
1572
1572
  interface UrlSyncManagerLike {
1573
1573
  initSync(root: SceneObject): void;
1574
1574
  cleanUp(root: SceneObject): void;
@@ -2660,4 +2660,4 @@ declare const sceneUtils: {
2660
2660
  isGroupByVariable: typeof isGroupByVariable;
2661
2661
  };
2662
2662
 
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 };
2663
+ export { AdHocFiltersVariable, AdHocFiltersVariableV2, 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 };