@grafana/scenes 5.13.1--canary.889.10720020573.0 → 5.14.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.0 (Thu Sep 05 2024)
2
+
3
+ #### 🚀 Enhancement
4
+
5
+ - SceneObjectBase: Support rendering a child out of context [#887](https://github.com/grafana/scenes/pull/887) ([@torkelo](https://github.com/torkelo))
6
+
7
+ #### Authors: 1
8
+
9
+ - Torkel Ödegaard ([@torkelo](https://github.com/torkelo))
10
+
11
+ ---
12
+
1
13
  # v5.13.0 (Wed Sep 04 2024)
2
14
 
3
15
  ### Release Notes
@@ -30,6 +30,7 @@ class SceneObjectBase {
30
30
  this._deactivationHandlers = /* @__PURE__ */ new Map();
31
31
  this._subs = new Subscription();
32
32
  this._refCount = 0;
33
+ this._UNSAFE_PARENT_ACTIVATION = false;
33
34
  if (!state.key) {
34
35
  state.key = v4();
35
36
  }
@@ -186,12 +187,19 @@ class SceneObjectBase {
186
187
  }
187
188
  }
188
189
  activate() {
190
+ let parentDeactivate;
191
+ if (this.parent && !this.parent.isActive && this._UNSAFE_PARENT_ACTIVATION) {
192
+ parentDeactivate = this.parent.activate();
193
+ }
189
194
  if (!this.isActive) {
190
195
  this._internalActivate();
191
196
  }
192
197
  this._refCount++;
193
198
  let called = false;
194
199
  return () => {
200
+ if (parentDeactivate) {
201
+ parentDeactivate();
202
+ }
195
203
  this._refCount--;
196
204
  if (called) {
197
205
  const msg = `SceneObject cancelation handler returned by activate() called a second time`;
@@ -1 +1 @@
1
- {"version":3,"file":"SceneObjectBase.js","sources":["../../../src/core/SceneObjectBase.tsx"],"sourcesContent":["import { useEffect, useState } from 'react';\nimport { Subscription, Unsubscribable } from 'rxjs';\nimport { v4 as uuidv4 } from 'uuid';\n\nimport { BusEvent, BusEventHandler, BusEventType, EventBus, EventBusSrv } from '@grafana/data';\nimport {\n SceneObject,\n SceneComponent,\n SceneObjectUrlSyncHandler,\n SceneStateChangedHandler,\n SceneActivationHandler,\n SceneDeactivationHandler,\n CancelActivationHandler,\n SceneObjectState,\n UseStateHookOptions,\n SceneStatelessBehavior,\n} from './types';\n\nimport { SceneComponentWrapper } from './SceneComponentWrapper';\nimport { SceneObjectStateChangedEvent } from './events';\nimport { cloneSceneObject } from './sceneGraph/utils';\nimport { SceneVariableDependencyConfigLike } from '../variables/types';\nimport { SceneObjectRef } from './SceneObjectRef';\n\nexport abstract class SceneObjectBase<TState extends SceneObjectState = SceneObjectState>\n implements SceneObject<TState>\n{\n private _isActive = false;\n private _state: TState;\n private _activationHandlers: SceneActivationHandler[] = [];\n private _deactivationHandlers = new Map<object, SceneDeactivationHandler>();\n private _ref?: SceneObjectRef<this>;\n\n protected _events?: EventBus;\n protected _parent?: SceneObject;\n protected _subs = new Subscription();\n protected _refCount = 0;\n\n protected _variableDependency: SceneVariableDependencyConfigLike | undefined;\n protected _urlSync: SceneObjectUrlSyncHandler | undefined;\n\n public constructor(state: TState) {\n if (!state.key) {\n state.key = uuidv4();\n }\n\n this._events = new EventBusSrv();\n\n this._state = Object.freeze(state);\n this._setParent(this._state);\n }\n\n /** Current state */\n public get state(): TState {\n return this._state;\n }\n\n /** True if currently being active (ie displayed for visual objects) */\n public get isActive(): boolean {\n return this._isActive;\n }\n\n /** Returns the parent, undefined for root object */\n public get parent(): SceneObject | undefined {\n return this._parent;\n }\n\n /** Returns variable dependency config */\n public get variableDependency(): SceneVariableDependencyConfigLike | undefined {\n return this._variableDependency;\n }\n\n /** Returns url sync config */\n public get urlSync(): SceneObjectUrlSyncHandler | undefined {\n return this._urlSync;\n }\n\n /**\n * Used in render functions when rendering a SceneObject.\n * Wraps the component in an EditWrapper that handles edit mode\n */\n public get Component(): SceneComponent<this> {\n return SceneComponentWrapper as SceneComponent<this>;\n }\n\n private _setParent(state: Partial<TState>) {\n forEachChild(state, (child) => {\n // If we already have a parent and it's not this, then we likely have a bug\n if (child._parent && child._parent !== this) {\n console.warn(\n 'SceneObject already has a parent set that is different from the new parent. You cannot share the same SceneObject instance in multiple scenes or in multiple different places of the same scene graph. Use SceneObject.clone() to duplicate a SceneObject or store a state key reference and use sceneGraph.findObject to locate it.',\n child,\n this\n );\n }\n child._parent = this;\n });\n }\n\n /**\n * Subscribe to the scene state subject\n **/\n public subscribeToState(handler: SceneStateChangedHandler<TState>): Unsubscribable {\n return this._events!.subscribe(SceneObjectStateChangedEvent, (event) => {\n if (event.payload.changedObject === this) {\n handler(event.payload.newState as TState, event.payload.prevState as TState);\n }\n });\n }\n\n /**\n * Subscribe to the scene event\n **/\n public subscribeToEvent<T extends BusEvent>(eventType: BusEventType<T>, handler: BusEventHandler<T>): Unsubscribable {\n return this._events!.subscribe(eventType, handler);\n }\n\n public setState(update: Partial<TState>) {\n const prevState = this._state;\n const newState: TState = {\n ...this._state,\n ...update,\n };\n\n this._state = Object.freeze(newState);\n this._setParent(update);\n\n // Handles cases when $data, $timeRange, or $variables are changed\n this._handleActivationOfChangedStateProps(prevState, newState);\n\n // Bubble state change event. This is event is subscribed to by UrlSyncManager and UndoManager\n this.publishEvent(\n new SceneObjectStateChangedEvent({\n prevState,\n newState,\n partialUpdate: update,\n changedObject: this,\n }),\n true\n );\n }\n\n /**\n * This handles activation and deactivation of $data, $timeRange and $variables when they change\n * during the active phase of the scene object.\n */\n private _handleActivationOfChangedStateProps(prevState: TState, newState: TState) {\n if (!this.isActive) {\n return;\n }\n\n if (prevState.$behaviors !== newState.$behaviors) {\n this._handleChangedBehaviors(prevState.$behaviors, newState.$behaviors);\n }\n\n if (prevState.$data !== newState.$data) {\n this._handleChangedStateActivation(prevState.$data, newState.$data);\n }\n\n if (prevState.$variables !== newState.$variables) {\n this._handleChangedStateActivation(prevState.$variables, newState.$variables);\n }\n\n if (prevState.$timeRange !== newState.$timeRange) {\n this._handleChangedStateActivation(prevState.$timeRange, newState.$timeRange);\n }\n }\n\n private _handleChangedStateActivation(oldValue: SceneObject | undefined, newValue: SceneObject | undefined) {\n if (oldValue) {\n const deactivationHandler = this._deactivationHandlers.get(oldValue);\n if (deactivationHandler) {\n deactivationHandler();\n this._deactivationHandlers.delete(oldValue);\n }\n }\n\n if (newValue) {\n this._deactivationHandlers.set(newValue, newValue.activate());\n }\n }\n\n private _handleChangedBehaviors(\n oldValue: Array<SceneObject | SceneStatelessBehavior> | undefined,\n newValue: Array<SceneObject | SceneStatelessBehavior> | undefined\n ) {\n // Handle removed behaviors\n if (oldValue) {\n for (const oldBehavior of oldValue) {\n if (!newValue || !newValue.includes(oldBehavior)) {\n const deactivationHandler = this._deactivationHandlers.get(oldBehavior);\n if (deactivationHandler) {\n deactivationHandler();\n this._deactivationHandlers.delete(oldBehavior);\n }\n }\n }\n }\n\n // Handle new behaviors\n if (newValue) {\n for (const newBehavior of newValue) {\n if (!oldValue || !oldValue.includes(newBehavior)) {\n this._activateBehavior(newBehavior);\n }\n }\n }\n }\n\n /*\n * Publish an event and optionally bubble it up the scene\n **/\n public publishEvent(event: BusEvent, bubble?: boolean) {\n this._events!.publish(event);\n\n if (bubble && this.parent) {\n this.parent.publishEvent(event, bubble);\n }\n }\n\n public getRoot(): SceneObject {\n return !this._parent ? this : this._parent.getRoot();\n }\n\n private _internalActivate() {\n this._isActive = true;\n\n const { $data, $variables, $timeRange, $behaviors } = this.state;\n\n this._activationHandlers.forEach((handler) => {\n const result = handler();\n if (result) {\n this._deactivationHandlers.set(result, result);\n }\n });\n\n if ($timeRange && !$timeRange.isActive) {\n this._deactivationHandlers.set($timeRange, $timeRange.activate());\n }\n\n if ($variables && !$variables.isActive) {\n this._deactivationHandlers.set($variables, $variables.activate());\n }\n\n if ($data && !$data.isActive) {\n this._deactivationHandlers.set($data, $data.activate());\n }\n\n if ($behaviors) {\n for (const behavior of $behaviors) {\n this._activateBehavior(behavior);\n }\n }\n }\n\n private _activateBehavior(behavior: SceneObject | SceneStatelessBehavior): SceneDeactivationHandler | void {\n if (behavior instanceof SceneObjectBase) {\n this._deactivationHandlers.set(behavior, behavior.activate());\n } else if (typeof behavior === 'function') {\n const deactivate = behavior(this);\n if (deactivate) {\n this._deactivationHandlers.set(behavior, deactivate);\n }\n }\n }\n\n /**\n * This is primarily called from SceneComponentWrapper when the SceneObject's Component is mounted.\n * But in some scenarios this can also be called directly from another scene object. When called manually from another scene object\n * make sure to call the returned function when the source scene object is deactivated.\n */\n public activate(): CancelActivationHandler {\n if (!this.isActive) {\n this._internalActivate();\n }\n\n this._refCount++;\n\n let called = false;\n\n return () => {\n this._refCount--;\n\n if (called) {\n const msg = `SceneObject cancelation handler returned by activate() called a second time`;\n throw new Error(msg);\n }\n\n called = true;\n\n if (this._refCount === 0) {\n this._internalDeactivate();\n }\n };\n }\n\n /**\n * Called by the SceneComponentWrapper when the react component is unmounted.\n * Don't override this, instead use addActivationHandler. The activation handler can return a deactivation handler.\n */\n private _internalDeactivate(): void {\n this._isActive = false;\n\n for (let handler of this._deactivationHandlers.values()) {\n handler();\n }\n\n this._deactivationHandlers.clear();\n\n // Clear subscriptions and listeners\n this._events!.removeAllListeners();\n this._subs.unsubscribe();\n this._subs = new Subscription();\n }\n\n /**\n * Utility hook to get and subscribe to state\n */\n public useState(): TState {\n // eslint-disable-next-line react-hooks/rules-of-hooks\n return useSceneObjectState(this);\n }\n\n /** Force a re-render, should only be needed when variable values change */\n public forceRender(): void {\n this.setState({});\n }\n\n /**\n * Will create new SceneObject with shallow-cloned state, but all state items of type SceneObject are deep cloned\n */\n public clone(withState?: Partial<TState>): this {\n return cloneSceneObject(this, withState);\n }\n\n /**\n * Allows external code to register code that is executed on activate and deactivate. This allow you\n * to wire up scene objects that need to respond to state changes in other objects from the outside.\n **/\n public addActivationHandler(handler: SceneActivationHandler) {\n this._activationHandlers.push(handler);\n }\n\n /**\n * Loop through state and call callback for each direct child scene object.\n * Checks 1 level deep properties and arrays. So a scene object hidden in a nested plain object will not be detected.\n */\n public forEachChild(callback: (child: SceneObjectBase) => void) {\n forEachChild(this.state, callback);\n }\n\n /** Returns a SceneObjectRef that will resolve to this object */\n public getRef(): SceneObjectRef<this> {\n if (!this._ref) {\n this._ref = new SceneObjectRef(this);\n }\n\n return this._ref;\n }\n}\n\n/**\n * This hook is always returning model.state instead of a useState that remembers the last state emitted on the subject\n * The reason for this is so that if the model instance change this function will always return the latest state.\n */\nexport function useSceneObjectState<TState extends SceneObjectState>(\n model: SceneObject<TState>,\n options?: UseStateHookOptions\n): TState {\n const [_, setState] = useState<TState>(model.state);\n const stateAtFirstRender = model.state;\n const shouldActivateOrKeepAlive = options?.shouldActivateOrKeepAlive ?? false;\n\n useEffect(() => {\n let unactivate: CancelActivationHandler | undefined;\n\n if (shouldActivateOrKeepAlive) {\n unactivate = model.activate();\n }\n\n const s = model.subscribeToState((state) => {\n setState(state);\n });\n\n // Re-render component if the state changed between first render and useEffect (mount)\n if (model.state !== stateAtFirstRender) {\n setState(model.state);\n }\n\n return () => {\n s.unsubscribe();\n\n if (unactivate) {\n unactivate();\n }\n };\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [model, shouldActivateOrKeepAlive]);\n\n return model.state;\n}\n\nfunction forEachChild<T extends object>(state: T, callback: (child: SceneObjectBase) => void) {\n for (const propValue of Object.values(state)) {\n if (propValue instanceof SceneObjectBase) {\n callback(propValue);\n }\n\n if (Array.isArray(propValue)) {\n for (const child of propValue) {\n if (child instanceof SceneObjectBase) {\n callback(child);\n }\n }\n }\n }\n}\n"],"names":["uuidv4"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAwBO,MAAe,eAEtB,CAAA;AAAA,EAeS,YAAY,KAAe,EAAA;AAdlC,IAAA,IAAA,CAAQ,SAAY,GAAA,KAAA,CAAA;AAEpB,IAAA,IAAA,CAAQ,sBAAgD,EAAC,CAAA;AACzD,IAAQ,IAAA,CAAA,qBAAA,uBAA4B,GAAsC,EAAA,CAAA;AAK1E,IAAU,IAAA,CAAA,KAAA,GAAQ,IAAI,YAAa,EAAA,CAAA;AACnC,IAAA,IAAA,CAAU,SAAY,GAAA,CAAA,CAAA;AAMpB,IAAI,IAA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CAAA;AAAA,KACtB;AAEA,IAAA,OAAO,MAAM;AACX,MAAA,CAAA,CAAE,WAAY,EAAA,CAAA;AAEd,MAAA,IAAI,UAAY,EAAA;AACd,QAAW,UAAA,EAAA,CAAA;AAAA,OACb;AAAA,KACF,CAAA;AAAA,GAEC,EAAA,CAAC,KAAO,EAAA,yBAAyB,CAAC,CAAA,CAAA;AAErC,EAAA,OAAO,KAAM,CAAA,KAAA,CAAA;AACf,CAAA;AAEA,SAAS,YAAA,CAA+B,OAAU,QAA4C,EAAA;AAC5F,EAAA,KAAA,MAAW,SAAa,IAAA,MAAA,CAAO,MAAO,CAAA,KAAK,CAAG,EAAA;AAC5C,IAAA,IAAI,qBAAqB,eAAiB,EAAA;AACxC,MAAA,QAAA,CAAS,SAAS,CAAA,CAAA;AAAA,KACpB;AAEA,IAAI,IAAA,KAAA,CAAM,OAAQ,CAAA,SAAS,CAAG,EAAA;AAC5B,MAAA,KAAA,MAAW,SAAS,SAAW,EAAA;AAC7B,QAAA,IAAI,iBAAiB,eAAiB,EAAA;AACpC,UAAA,QAAA,CAAS,KAAK,CAAA,CAAA;AAAA,SAChB;AAAA,OACF;AAAA,KACF;AAAA,GACF;AACF;;;;"}
1
+ {"version":3,"file":"SceneObjectBase.js","sources":["../../../src/core/SceneObjectBase.tsx"],"sourcesContent":["import { useEffect, useState } from 'react';\nimport { Subscription, Unsubscribable } from 'rxjs';\nimport { v4 as uuidv4 } from 'uuid';\n\nimport { BusEvent, BusEventHandler, BusEventType, EventBus, EventBusSrv } from '@grafana/data';\nimport {\n SceneObject,\n SceneComponent,\n SceneObjectUrlSyncHandler,\n SceneStateChangedHandler,\n SceneActivationHandler,\n SceneDeactivationHandler,\n CancelActivationHandler,\n SceneObjectState,\n UseStateHookOptions,\n SceneStatelessBehavior,\n} from './types';\n\nimport { SceneComponentWrapper } from './SceneComponentWrapper';\nimport { SceneObjectStateChangedEvent } from './events';\nimport { cloneSceneObject } from './sceneGraph/utils';\nimport { SceneVariableDependencyConfigLike } from '../variables/types';\nimport { SceneObjectRef } from './SceneObjectRef';\n\nexport abstract class SceneObjectBase<TState extends SceneObjectState = SceneObjectState>\n implements SceneObject<TState>\n{\n private _isActive = false;\n private _state: TState;\n private _activationHandlers: SceneActivationHandler[] = [];\n private _deactivationHandlers = new Map<object, SceneDeactivationHandler>();\n private _ref?: SceneObjectRef<this>;\n\n protected _events?: EventBus;\n protected _parent?: SceneObject;\n protected _subs = new Subscription();\n protected _refCount = 0;\n\n protected _variableDependency: SceneVariableDependencyConfigLike | undefined;\n protected _urlSync: SceneObjectUrlSyncHandler | undefined;\n\n /**\n * @experimental feature to support rendering a child scene object without it's parent being rendered.\n * This flag will make it so that the parent is activated (if it's inactive) when this object is activated.\n */\n public _UNSAFE_PARENT_ACTIVATION = false;\n\n public constructor(state: TState) {\n if (!state.key) {\n state.key = uuidv4();\n }\n\n this._events = new EventBusSrv();\n\n this._state = Object.freeze(state);\n this._setParent(this._state);\n }\n\n /** Current state */\n public get state(): TState {\n return this._state;\n }\n\n /** True if currently being active (ie displayed for visual objects) */\n public get isActive(): boolean {\n return this._isActive;\n }\n\n /** Returns the parent, undefined for root object */\n public get parent(): SceneObject | undefined {\n return this._parent;\n }\n\n /** Returns variable dependency config */\n public get variableDependency(): SceneVariableDependencyConfigLike | undefined {\n return this._variableDependency;\n }\n\n /** Returns url sync config */\n public get urlSync(): SceneObjectUrlSyncHandler | undefined {\n return this._urlSync;\n }\n\n /**\n * Used in render functions when rendering a SceneObject.\n * Wraps the component in an EditWrapper that handles edit mode\n */\n public get Component(): SceneComponent<this> {\n return SceneComponentWrapper as SceneComponent<this>;\n }\n\n private _setParent(state: Partial<TState>) {\n forEachChild(state, (child) => {\n // If we already have a parent and it's not this, then we likely have a bug\n if (child._parent && child._parent !== this) {\n console.warn(\n 'SceneObject already has a parent set that is different from the new parent. You cannot share the same SceneObject instance in multiple scenes or in multiple different places of the same scene graph. Use SceneObject.clone() to duplicate a SceneObject or store a state key reference and use sceneGraph.findObject to locate it.',\n child,\n this\n );\n }\n child._parent = this;\n });\n }\n\n /**\n * Subscribe to the scene state subject\n **/\n public subscribeToState(handler: SceneStateChangedHandler<TState>): Unsubscribable {\n return this._events!.subscribe(SceneObjectStateChangedEvent, (event) => {\n if (event.payload.changedObject === this) {\n handler(event.payload.newState as TState, event.payload.prevState as TState);\n }\n });\n }\n\n /**\n * Subscribe to the scene event\n **/\n public subscribeToEvent<T extends BusEvent>(eventType: BusEventType<T>, handler: BusEventHandler<T>): Unsubscribable {\n return this._events!.subscribe(eventType, handler);\n }\n\n public setState(update: Partial<TState>) {\n const prevState = this._state;\n const newState: TState = {\n ...this._state,\n ...update,\n };\n\n this._state = Object.freeze(newState);\n this._setParent(update);\n\n // Handles cases when $data, $timeRange, or $variables are changed\n this._handleActivationOfChangedStateProps(prevState, newState);\n\n // Bubble state change event. This is event is subscribed to by UrlSyncManager and UndoManager\n this.publishEvent(\n new SceneObjectStateChangedEvent({\n prevState,\n newState,\n partialUpdate: update,\n changedObject: this,\n }),\n true\n );\n }\n\n /**\n * This handles activation and deactivation of $data, $timeRange and $variables when they change\n * during the active phase of the scene object.\n */\n private _handleActivationOfChangedStateProps(prevState: TState, newState: TState) {\n if (!this.isActive) {\n return;\n }\n\n if (prevState.$behaviors !== newState.$behaviors) {\n this._handleChangedBehaviors(prevState.$behaviors, newState.$behaviors);\n }\n\n if (prevState.$data !== newState.$data) {\n this._handleChangedStateActivation(prevState.$data, newState.$data);\n }\n\n if (prevState.$variables !== newState.$variables) {\n this._handleChangedStateActivation(prevState.$variables, newState.$variables);\n }\n\n if (prevState.$timeRange !== newState.$timeRange) {\n this._handleChangedStateActivation(prevState.$timeRange, newState.$timeRange);\n }\n }\n\n private _handleChangedStateActivation(oldValue: SceneObject | undefined, newValue: SceneObject | undefined) {\n if (oldValue) {\n const deactivationHandler = this._deactivationHandlers.get(oldValue);\n if (deactivationHandler) {\n deactivationHandler();\n this._deactivationHandlers.delete(oldValue);\n }\n }\n\n if (newValue) {\n this._deactivationHandlers.set(newValue, newValue.activate());\n }\n }\n\n private _handleChangedBehaviors(\n oldValue: Array<SceneObject | SceneStatelessBehavior> | undefined,\n newValue: Array<SceneObject | SceneStatelessBehavior> | undefined\n ) {\n // Handle removed behaviors\n if (oldValue) {\n for (const oldBehavior of oldValue) {\n if (!newValue || !newValue.includes(oldBehavior)) {\n const deactivationHandler = this._deactivationHandlers.get(oldBehavior);\n if (deactivationHandler) {\n deactivationHandler();\n this._deactivationHandlers.delete(oldBehavior);\n }\n }\n }\n }\n\n // Handle new behaviors\n if (newValue) {\n for (const newBehavior of newValue) {\n if (!oldValue || !oldValue.includes(newBehavior)) {\n this._activateBehavior(newBehavior);\n }\n }\n }\n }\n\n /*\n * Publish an event and optionally bubble it up the scene\n **/\n public publishEvent(event: BusEvent, bubble?: boolean) {\n this._events!.publish(event);\n\n if (bubble && this.parent) {\n this.parent.publishEvent(event, bubble);\n }\n }\n\n public getRoot(): SceneObject {\n return !this._parent ? this : this._parent.getRoot();\n }\n\n private _internalActivate() {\n this._isActive = true;\n\n const { $data, $variables, $timeRange, $behaviors } = this.state;\n\n this._activationHandlers.forEach((handler) => {\n const result = handler();\n if (result) {\n this._deactivationHandlers.set(result, result);\n }\n });\n\n if ($timeRange && !$timeRange.isActive) {\n this._deactivationHandlers.set($timeRange, $timeRange.activate());\n }\n\n if ($variables && !$variables.isActive) {\n this._deactivationHandlers.set($variables, $variables.activate());\n }\n\n if ($data && !$data.isActive) {\n this._deactivationHandlers.set($data, $data.activate());\n }\n\n if ($behaviors) {\n for (const behavior of $behaviors) {\n this._activateBehavior(behavior);\n }\n }\n }\n\n private _activateBehavior(behavior: SceneObject | SceneStatelessBehavior): SceneDeactivationHandler | void {\n if (behavior instanceof SceneObjectBase) {\n this._deactivationHandlers.set(behavior, behavior.activate());\n } else if (typeof behavior === 'function') {\n const deactivate = behavior(this);\n if (deactivate) {\n this._deactivationHandlers.set(behavior, deactivate);\n }\n }\n }\n\n /**\n * This is primarily called from SceneComponentWrapper when the SceneObject's Component is mounted.\n * But in some scenarios this can also be called directly from another scene object. When called manually from another scene object\n * make sure to call the returned function when the source scene object is deactivated.\n */\n public activate(): CancelActivationHandler {\n // If parent is not active, activate parent first\n let parentDeactivate: CancelActivationHandler | undefined;\n if (this.parent && !this.parent.isActive && this._UNSAFE_PARENT_ACTIVATION) {\n parentDeactivate = this.parent.activate();\n }\n\n if (!this.isActive) {\n this._internalActivate();\n }\n\n this._refCount++;\n\n let called = false;\n\n return () => {\n if (parentDeactivate) {\n parentDeactivate();\n }\n\n this._refCount--;\n\n if (called) {\n const msg = `SceneObject cancelation handler returned by activate() called a second time`;\n throw new Error(msg);\n }\n\n called = true;\n\n if (this._refCount === 0) {\n this._internalDeactivate();\n }\n };\n }\n\n /**\n * Called by the SceneComponentWrapper when the react component is unmounted.\n * Don't override this, instead use addActivationHandler. The activation handler can return a deactivation handler.\n */\n private _internalDeactivate(): void {\n this._isActive = false;\n\n for (let handler of this._deactivationHandlers.values()) {\n handler();\n }\n\n this._deactivationHandlers.clear();\n\n // Clear subscriptions and listeners\n this._events!.removeAllListeners();\n this._subs.unsubscribe();\n this._subs = new Subscription();\n }\n\n /**\n * Utility hook to get and subscribe to state\n */\n public useState(): TState {\n // eslint-disable-next-line react-hooks/rules-of-hooks\n return useSceneObjectState(this);\n }\n\n /** Force a re-render, should only be needed when variable values change */\n public forceRender(): void {\n this.setState({});\n }\n\n /**\n * Will create new SceneObject with shallow-cloned state, but all state items of type SceneObject are deep cloned\n */\n public clone(withState?: Partial<TState>): this {\n return cloneSceneObject(this, withState);\n }\n\n /**\n * Allows external code to register code that is executed on activate and deactivate. This allow you\n * to wire up scene objects that need to respond to state changes in other objects from the outside.\n **/\n public addActivationHandler(handler: SceneActivationHandler) {\n this._activationHandlers.push(handler);\n }\n\n /**\n * Loop through state and call callback for each direct child scene object.\n * Checks 1 level deep properties and arrays. So a scene object hidden in a nested plain object will not be detected.\n */\n public forEachChild(callback: (child: SceneObjectBase) => void) {\n forEachChild(this.state, callback);\n }\n\n /** Returns a SceneObjectRef that will resolve to this object */\n public getRef(): SceneObjectRef<this> {\n if (!this._ref) {\n this._ref = new SceneObjectRef(this);\n }\n\n return this._ref;\n }\n}\n\n/**\n * This hook is always returning model.state instead of a useState that remembers the last state emitted on the subject\n * The reason for this is so that if the model instance change this function will always return the latest state.\n */\nexport function useSceneObjectState<TState extends SceneObjectState>(\n model: SceneObject<TState>,\n options?: UseStateHookOptions\n): TState {\n const [_, setState] = useState<TState>(model.state);\n const stateAtFirstRender = model.state;\n const shouldActivateOrKeepAlive = options?.shouldActivateOrKeepAlive ?? false;\n\n useEffect(() => {\n let unactivate: CancelActivationHandler | undefined;\n\n if (shouldActivateOrKeepAlive) {\n unactivate = model.activate();\n }\n\n const s = model.subscribeToState((state) => {\n setState(state);\n });\n\n // Re-render component if the state changed between first render and useEffect (mount)\n if (model.state !== stateAtFirstRender) {\n setState(model.state);\n }\n\n return () => {\n s.unsubscribe();\n\n if (unactivate) {\n unactivate();\n }\n };\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [model, shouldActivateOrKeepAlive]);\n\n return model.state;\n}\n\nfunction forEachChild<T extends object>(state: T, callback: (child: SceneObjectBase) => void) {\n for (const propValue of Object.values(state)) {\n if (propValue instanceof SceneObjectBase) {\n callback(propValue);\n }\n\n if (Array.isArray(propValue)) {\n for (const child of propValue) {\n if (child instanceof SceneObjectBase) {\n callback(child);\n }\n }\n }\n }\n}\n"],"names":["uuidv4"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAwBO,MAAe,eAEtB,CAAA;AAAA,EAqBS,YAAY,KAAe,EAAA;AApBlC,IAAA,IAAA,CAAQ,SAAY,GAAA,KAAA,CAAA;AAEpB,IAAA,IAAA,CAAQ,sBAAgD,EAAC,CAAA;AACzD,IAAQ,IAAA,CAAA,qBAAA,uBAA4B,GAAsC,EAAA,CAAA;AAK1E,IAAU,IAAA,CAAA,KAAA,GAAQ,IAAI,YAAa,EAAA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);
30
30
  const pillWrapperRef = useRef(null);
31
31
  const keyLabel = (_a = filter.keyLabel) != null ? _a : filter.key;
32
- const valueLabel = ((_b = filter.valueLabels) == null ? void 0 : _b.join(", ")) || ((_c = filter.values) == null ? void 0 : _c.join(", ")) || filter.value;
32
+ const valueLabel = (_c = (_b = filter.valueLabels) == null ? void 0 : _b[0]) != null ? _c : filter.value;
33
33
  const handleChangeViewMode = useCallback(
34
34
  (event) => {
35
35
  event == null ? void 0 : event.stopPropagation();
@@ -61,9 +61,7 @@ function AdHocFilterPill({ filter, model, readOnly }) {
61
61
  "aria-label": `Edit filter with key ${keyLabel}`,
62
62
  tabIndex: 0,
63
63
  ref: pillWrapperRef
64
- }, /* @__PURE__ */ React.createElement("span", {
65
- className: styles.pillText
66
- }, keyLabel, " ", filter.operator, " ", valueLabel), !readOnly ? /* @__PURE__ */ React.createElement(IconButton, {
64
+ }, /* @__PURE__ */ React.createElement("span", null, keyLabel, " ", filter.operator, " ", valueLabel), !readOnly ? /* @__PURE__ */ React.createElement(IconButton, {
67
65
  onClick: (e) => {
68
66
  e.stopPropagation();
69
67
  model._removeFilter(filter);
@@ -119,9 +117,6 @@ const getStyles = (theme) => ({
119
117
  "&:hover": {
120
118
  color: theme.colors.text.primary
121
119
  }
122
- }),
123
- pillText: css({
124
- whiteSpace: "break-spaces"
125
120
  })
126
121
  });
127
122
 
@@ -1 +1 @@
1
- {"version":3,"file":"AdHocFilterPill.js","sources":["../../../../../src/variables/adhoc/AdHocFiltersCombobox/AdHocFilterPill.tsx"],"sourcesContent":["import { css, cx } from '@emotion/css';\nimport { GrafanaTheme2 } from '@grafana/data';\nimport { useStyles2, IconButton } from '@grafana/ui';\nimport React, { useState, useRef, useCallback, useEffect } from 'react';\nimport { AdHocCombobox } from './AdHocFiltersCombobox';\nimport { AdHocFilterWithLabels, AdHocFiltersVariable } from '../AdHocFiltersVariable';\n\ninterface Props {\n filter: AdHocFilterWithLabels;\n model: AdHocFiltersVariable;\n readOnly?: boolean;\n}\n\nexport function AdHocFilterPill({ filter, model, readOnly }: Props) {\n const styles = useStyles2(getStyles);\n const [viewMode, setViewMode] = useState(true);\n const [shouldFocus, setShouldFocus] = useState(false);\n const pillWrapperRef = useRef<HTMLDivElement>(null);\n\n const keyLabel = filter.keyLabel ?? filter.key;\n //@ts-expect-error\n const valueLabel = filter.valueLabels?.join(', ') || filter.values?.join(', ') || filter.value;\n\n const handleChangeViewMode = useCallback(\n (event?: React.MouseEvent) => {\n event?.stopPropagation();\n if (readOnly) {\n return;\n }\n\n setShouldFocus(!viewMode);\n setViewMode(!viewMode);\n },\n [readOnly, viewMode]\n );\n\n useEffect(() => {\n if (shouldFocus) {\n pillWrapperRef.current?.focus();\n setShouldFocus(false);\n }\n }, [shouldFocus]);\n\n if (viewMode) {\n return (\n <div\n className={cx(styles.combinedFilterPill, { [styles.readOnlyCombinedFilter]: readOnly })}\n onClick={handleChangeViewMode}\n onKeyDown={(e) => {\n if (e.key === 'Enter') {\n handleChangeViewMode();\n }\n }}\n role=\"button\"\n aria-label={`Edit filter with key ${keyLabel}`}\n tabIndex={0}\n ref={pillWrapperRef}\n >\n <span className={styles.pillText}>\n {keyLabel} {filter.operator} {valueLabel}\n </span>\n {!readOnly ? (\n <IconButton\n onClick={(e) => {\n e.stopPropagation();\n model._removeFilter(filter);\n }}\n onKeyDownCapture={(e) => {\n if (e.key === 'Enter') {\n e.preventDefault();\n e.stopPropagation();\n model._removeFilter(filter);\n }\n }}\n name=\"times\"\n size=\"md\"\n className={styles.removeButton}\n tooltip={`Remove filter with key ${keyLabel}`}\n />\n ) : null}\n </div>\n );\n }\n\n return <AdHocCombobox filter={filter} model={model} handleChangeViewMode={handleChangeViewMode} />;\n}\n\nconst getStyles = (theme: GrafanaTheme2) => ({\n combinedFilterPill: css({\n display: 'flex',\n alignItems: 'center',\n background: theme.colors.action.selected,\n borderRadius: theme.shape.radius.default,\n border: `1px solid ${theme.colors.border.weak}`,\n padding: theme.spacing(0.125, 0, 0.125, 1),\n color: theme.colors.text.primary,\n overflow: 'hidden',\n whiteSpace: 'nowrap',\n minHeight: theme.spacing(2.75),\n ...theme.typography.bodySmall,\n fontWeight: theme.typography.fontWeightBold,\n cursor: 'pointer',\n\n '&:hover': {\n background: theme.colors.action.hover,\n },\n }),\n readOnlyCombinedFilter: css({\n paddingRight: theme.spacing(1),\n cursor: 'text',\n '&:hover': {\n background: theme.colors.action.selected,\n },\n }),\n removeButton: css({\n marginInline: theme.spacing(0.5),\n cursor: 'pointer',\n '&:hover': {\n color: theme.colors.text.primary,\n },\n }),\n pillText: css({\n whiteSpace: 'break-spaces',\n }),\n});\n"],"names":["_a"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AAaO,SAAS,eAAgB,CAAA,EAAE,MAAQ,EAAA,KAAA,EAAO,UAAmB,EAAA;AAbpE,EAAA,IAAA,EAAA,EAAA,EAAA,EAAA,EAAA,CAAA;AAcE,EAAM,MAAA,MAAA,GAAS,WAAW,SAAS,CAAA,CAAA;AACnC,EAAA,MAAM,CAAC,QAAA,EAAU,WAAW,CAAA,GAAI,SAAS,IAAI,CAAA,CAAA;AAC7C,EAAA,MAAM,CAAC,WAAA,EAAa,cAAc,CAAA,GAAI,SAAS,KAAK,CAAA,CAAA;AACpD,EAAM,MAAA,cAAA,GAAiB,OAAuB,IAAI,CAAA,CAAA;AAElD,EAAA,MAAM,QAAW,GAAA,CAAA,EAAA,GAAA,MAAA,CAAO,QAAP,KAAA,IAAA,GAAA,EAAA,GAAmB,MAAO,CAAA,GAAA,CAAA;AAE3C,EAAM,MAAA,UAAA,GAAA,CAAA,CAAa,EAAO,GAAA,MAAA,CAAA,WAAA,KAAP,IAAoB,GAAA,KAAA,CAAA,GAAA,EAAA,CAAA,IAAA,CAAK,IAAS,CAAA,MAAA,CAAA,EAAA,GAAA,MAAA,CAAO,MAAP,KAAA,IAAA,GAAA,KAAA,CAAA,GAAA,EAAA,CAAe,IAAK,CAAA,IAAA,CAAA,CAAA,IAAS,MAAO,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A;;;;"}
1
+ {"version":3,"file":"AdHocFilterPill.js","sources":["../../../../../src/variables/adhoc/AdHocFiltersCombobox/AdHocFilterPill.tsx"],"sourcesContent":["import { css, cx } from '@emotion/css';\nimport { GrafanaTheme2 } from '@grafana/data';\nimport { useStyles2, IconButton } from '@grafana/ui';\nimport React, { useState, useRef, useCallback, useEffect } from 'react';\nimport { AdHocCombobox } from './AdHocFiltersCombobox';\nimport { AdHocFilterWithLabels, AdHocFiltersVariable } from '../AdHocFiltersVariable';\n\ninterface Props {\n filter: AdHocFilterWithLabels;\n model: AdHocFiltersVariable;\n readOnly?: boolean;\n}\n\nexport function AdHocFilterPill({ filter, model, readOnly }: Props) {\n const styles = useStyles2(getStyles);\n const [viewMode, setViewMode] = useState(true);\n const [shouldFocus, setShouldFocus] = useState(false);\n const pillWrapperRef = useRef<HTMLDivElement>(null);\n\n const keyLabel = filter.keyLabel ?? filter.key;\n const valueLabel = filter.valueLabels?.[0] ?? filter.value;\n\n const handleChangeViewMode = useCallback(\n (event?: React.MouseEvent) => {\n event?.stopPropagation();\n if (readOnly) {\n return;\n }\n\n setShouldFocus(!viewMode);\n setViewMode(!viewMode);\n },\n [readOnly, viewMode]\n );\n\n useEffect(() => {\n if (shouldFocus) {\n pillWrapperRef.current?.focus();\n setShouldFocus(false);\n }\n }, [shouldFocus]);\n\n if (viewMode) {\n return (\n <div\n className={cx(styles.combinedFilterPill, { [styles.readOnlyCombinedFilter]: readOnly })}\n onClick={handleChangeViewMode}\n onKeyDown={(e) => {\n if (e.key === 'Enter') {\n handleChangeViewMode();\n }\n }}\n role=\"button\"\n aria-label={`Edit filter with key ${keyLabel}`}\n tabIndex={0}\n ref={pillWrapperRef}\n >\n <span>\n {keyLabel} {filter.operator} {valueLabel}\n </span>\n {!readOnly ? (\n <IconButton\n onClick={(e) => {\n e.stopPropagation();\n model._removeFilter(filter);\n }}\n onKeyDownCapture={(e) => {\n if (e.key === 'Enter') {\n e.preventDefault();\n e.stopPropagation();\n model._removeFilter(filter);\n }\n }}\n name=\"times\"\n size=\"md\"\n className={styles.removeButton}\n tooltip={`Remove filter with key ${keyLabel}`}\n />\n ) : null}\n </div>\n );\n }\n\n return <AdHocCombobox filter={filter} model={model} handleChangeViewMode={handleChangeViewMode} />;\n}\n\nconst getStyles = (theme: GrafanaTheme2) => ({\n combinedFilterPill: css({\n display: 'flex',\n alignItems: 'center',\n background: theme.colors.action.selected,\n borderRadius: theme.shape.radius.default,\n border: `1px solid ${theme.colors.border.weak}`,\n padding: theme.spacing(0.125, 0, 0.125, 1),\n color: theme.colors.text.primary,\n overflow: 'hidden',\n whiteSpace: 'nowrap',\n minHeight: theme.spacing(2.75),\n ...theme.typography.bodySmall,\n fontWeight: theme.typography.fontWeightBold,\n cursor: 'pointer',\n\n '&:hover': {\n background: theme.colors.action.hover,\n },\n }),\n readOnlyCombinedFilter: css({\n paddingRight: theme.spacing(1),\n cursor: 'text',\n '&:hover': {\n background: theme.colors.action.selected,\n },\n }),\n removeButton: css({\n marginInline: theme.spacing(0.5),\n cursor: 'pointer',\n '&:hover': {\n color: theme.colors.text.primary,\n },\n }),\n});\n"],"names":["_a"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AAaO,SAAS,eAAgB,CAAA,EAAE,MAAQ,EAAA,KAAA,EAAO,UAAmB,EAAA;AAbpE,EAAA,IAAA,EAAA,EAAA,EAAA,EAAA,EAAA,CAAA;AAcE,EAAM,MAAA,MAAA,GAAS,WAAW,SAAS,CAAA,CAAA;AACnC,EAAA,MAAM,CAAC,QAAA,EAAU,WAAW,CAAA,GAAI,SAAS,IAAI,CAAA,CAAA;AAC7C,EAAA,MAAM,CAAC,WAAA,EAAa,cAAc,CAAA,GAAI,SAAS,KAAK,CAAA,CAAA;AACpD,EAAM,MAAA,cAAA,GAAiB,OAAuB,IAAI,CAAA,CAAA;AAElD,EAAA,MAAM,QAAW,GAAA,CAAA,EAAA,GAAA,MAAA,CAAO,QAAP,KAAA,IAAA,GAAA,EAAA,GAAm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AA,CAAO,IAAK,CAAA,OAAA;AAAA,KAC3B;AAAA,GACD,CAAA;AACH,CAAA,CAAA;;;;"}
@@ -1,11 +1,10 @@
1
- import React, { forwardRef, useState, useMemo, useId, useRef, useCallback, useImperativeHandle, useEffect, useLayoutEffect } from 'react';
1
+ import React, { forwardRef, useState, useId, useRef, useMemo, useCallback, useImperativeHandle, useEffect, useLayoutEffect } from 'react';
2
2
  import { FloatingPortal, FloatingFocusManager } from '@floating-ui/react';
3
- import { useStyles2, Spinner, Text, Button, Icon } from '@grafana/ui';
3
+ import { useStyles2, Spinner, Text } from '@grafana/ui';
4
4
  import { cx, css } from '@emotion/css';
5
- import { OPERATORS } from '../AdHocFiltersVariable.js';
6
5
  import { useVirtualizer } from '@tanstack/react-virtual';
7
- import { LoadingOptionsPlaceholder, OptionsErrorPlaceholder, NoOptionsPlaceholder, DropdownItem, MultiValueApplyButton } from './DropdownItem.js';
8
- import { fuzzySearchOptions, flattenOptionGroups, setupDropdownAccessibility, VIRTUAL_LIST_ITEM_HEIGHT_WITH_DESCRIPTION, VIRTUAL_LIST_ITEM_HEIGHT, VIRTUAL_LIST_OVERSCAN, generateFilterUpdatePayload, switchToNextInputType, switchInputType, ERROR_STATE_DROPDOWN_WIDTH } from './utils.js';
6
+ import { LoadingOptionsPlaceholder, OptionsErrorPlaceholder, NoOptionsPlaceholder, DropdownItem } from './DropdownItem.js';
7
+ import { fuzzySearchOptions, flattenOptionGroups, setupDropdownAccessibility, VIRTUAL_LIST_ITEM_HEIGHT, VIRTUAL_LIST_OVERSCAN, generateFilterUpdatePayload, switchToNextInputType, switchInputType, ERROR_STATE_DROPDOWN_WIDTH } from './utils.js';
9
8
  import { handleOptionGroups } from '../../utils.js';
10
9
  import { useFloatingInteractions } from './useFloatingInteractions.js';
11
10
 
@@ -38,14 +37,6 @@ const AdHocCombobox = forwardRef(function AdHocCombobox2({ filter, model, isAlwa
38
37
  const [activeIndex, setActiveIndex] = useState(null);
39
38
  const [filterInputType, setInputType] = useState(!isAlwaysWip ? "value" : "key");
40
39
  const styles = useStyles2(getStyles);
41
- const [filterMultiValues, setFilterMultiValues] = useState([]);
42
- const [_, setForceRefresh] = useState({});
43
- const multiValueOperators = useMemo(
44
- () => OPERATORS.reduce((acc, operator) => operator.isMulti ? [...acc, operator.value] : acc, []),
45
- []
46
- );
47
- const hasMultiValueOperator = multiValueOperators.includes((filter == null ? void 0 : filter.operator) || "");
48
- const isMultiValueEdit = hasMultiValueOperator && filterInputType === "value";
49
40
  const operatorIdentifier = useId();
50
41
  const listRef = useRef([]);
51
42
  const disabledIndicesRef = useRef([]);
@@ -57,60 +48,22 @@ const AdHocCombobox = forwardRef(function AdHocCombobox2({ filter, model, isAlwa
57
48
  setInputValue("");
58
49
  }
59
50
  }, [model, isAlwaysWip]);
60
- const handleMultiValueUpdate = useCallback(
61
- (model2, filter2, filterMultiValues2) => {
62
- if (filterMultiValues2.length) {
63
- const valueLabels = [];
64
- const values = [];
65
- filterMultiValues2.forEach((item) => {
66
- var _a2;
67
- valueLabels.push((_a2 = item.label) != null ? _a2 : item.value);
68
- values.push(item.value);
69
- });
70
- model2._updateFilter(filter2, { valueLabels, values, value: values[0] });
71
- setFilterMultiValues([]);
72
- }
73
- setTimeout(() => {
74
- var _a2;
75
- return (_a2 = refs.domReference.current) == null ? void 0 : _a2.focus();
76
- });
77
- },
78
- []
79
- );
80
- const handleAddMultiValue = useCallback((selectedItem) => {
81
- setFilterMultiValues((items) => {
82
- if (items.some((item) => item.value === selectedItem.value)) {
83
- return items.filter((item) => item.value !== selectedItem.value);
84
- }
85
- return [...items, selectedItem];
86
- });
87
- }, []);
88
- const handleRemoveMultiValue = useCallback(
89
- (item) => setFilterMultiValues((selected) => selected.filter((option) => option.value !== item.value)),
90
- []
91
- );
92
51
  const onOpenChange = useCallback(
93
- (nextOpen, _2, reason) => {
52
+ (nextOpen, _, reason) => {
94
53
  setOpen(nextOpen);
95
54
  if (reason && ["outside-press", "escape-key"].includes(reason)) {
96
- if (isMultiValueEdit) {
97
- handleMultiValueUpdate(model, filter, filterMultiValues);
98
- }
99
55
  handleResetWip();
100
56
  handleChangeViewMode == null ? void 0 : handleChangeViewMode();
101
57
  }
102
58
  },
103
- [filter, filterMultiValues, handleChangeViewMode, handleMultiValueUpdate, handleResetWip, isMultiValueEdit, model]
59
+ [handleChangeViewMode, handleResetWip]
104
60
  );
105
- const outsidePressIdsToIgnore = useMemo(() => {
106
- return [operatorIdentifier, ...filterMultiValues.map((item, i) => `${item.value}-${i}`)];
107
- }, [operatorIdentifier, filterMultiValues]);
108
61
  const { refs, floatingStyles, context, getReferenceProps, getFloatingProps, getItemProps } = useFloatingInteractions({
109
62
  open,
110
63
  onOpenChange,
111
64
  activeIndex,
112
65
  setActiveIndex,
113
- outsidePressIdsToIgnore,
66
+ operatorIdentifier,
114
67
  listRef,
115
68
  disabledIndicesRef
116
69
  });
@@ -161,41 +114,24 @@ const AdHocCombobox = forwardRef(function AdHocCombobox2({ filter, model, isAlwa
161
114
  const rowVirtualizer = useVirtualizer({
162
115
  count: filteredDropDownItems.length,
163
116
  getScrollElement: () => refs.floating.current,
164
- estimateSize: (index) => filteredDropDownItems[index].description ? VIRTUAL_LIST_ITEM_HEIGHT_WITH_DESCRIPTION : VIRTUAL_LIST_ITEM_HEIGHT,
117
+ estimateSize: () => VIRTUAL_LIST_ITEM_HEIGHT,
165
118
  overscan: VIRTUAL_LIST_OVERSCAN
166
119
  });
167
120
  const handleBackspaceInput = useCallback(
168
- (event, multiValueEdit) => {
169
- if (event.key === "Backspace" && !inputValue) {
170
- if (multiValueEdit) {
171
- setFilterMultiValues((items) => {
172
- const updated = [...items];
173
- updated.splice(-1, 1);
174
- return updated;
175
- });
176
- } else if (filterInputType === "key") {
177
- model._removeLastFilter();
178
- handleFetchOptions(filterInputType);
179
- }
121
+ (event) => {
122
+ if (event.key === "Backspace" && !inputValue && filterInputType === "key") {
123
+ model._removeLastFilter();
124
+ handleFetchOptions(filterInputType);
180
125
  }
181
126
  },
182
- [inputValue, filterInputType, model, handleFetchOptions]
183
- );
184
- const handleTabInput = useCallback(
185
- (event, multiValueEdit) => {
186
- var _a2;
187
- if (event.key === "Tab" && !event.shiftKey) {
188
- if (multiValueEdit) {
189
- event.preventDefault();
190
- handleMultiValueUpdate(model, filter, filterMultiValues);
191
- (_a2 = refs.domReference.current) == null ? void 0 : _a2.focus();
192
- }
193
- handleChangeViewMode == null ? void 0 : handleChangeViewMode();
194
- handleResetWip();
195
- }
196
- },
197
- [filter, filterMultiValues, handleChangeViewMode, handleMultiValueUpdate, handleResetWip, model, refs.domReference]
127
+ [inputValue, filterInputType]
198
128
  );
129
+ const handleTabInput = useCallback((event) => {
130
+ if (event.key === "Tab" && !event.shiftKey) {
131
+ handleChangeViewMode == null ? void 0 : handleChangeViewMode();
132
+ handleResetWip();
133
+ }
134
+ }, []);
199
135
  const handleShiftTabInput = useCallback((event) => {
200
136
  if (event.key === "Tab" && event.shiftKey) {
201
137
  handleChangeViewMode == null ? void 0 : handleChangeViewMode();
@@ -203,32 +139,18 @@ const AdHocCombobox = forwardRef(function AdHocCombobox2({ filter, model, isAlwa
203
139
  }
204
140
  }, []);
205
141
  const handleEnterInput = useCallback(
206
- (event, multiValueEdit) => {
142
+ (event) => {
207
143
  if (event.key === "Enter" && activeIndex != null) {
208
144
  if (!filteredDropDownItems[activeIndex]) {
209
145
  return;
210
146
  }
211
- const selectedItem = filteredDropDownItems[activeIndex];
212
- if (multiValueEdit) {
213
- handleAddMultiValue(selectedItem);
214
- } else {
215
- model._updateFilter(filter, generateFilterUpdatePayload(filterInputType, selectedItem));
216
- switchToNextInputType(filterInputType, setInputType, handleChangeViewMode, refs.domReference.current);
217
- setActiveIndex(0);
218
- }
147
+ model._updateFilter(filter, generateFilterUpdatePayload(filterInputType, filteredDropDownItems[activeIndex]));
219
148
  setInputValue("");
149
+ setActiveIndex(0);
150
+ switchToNextInputType(filterInputType, setInputType, handleChangeViewMode, refs.domReference.current);
220
151
  }
221
152
  },
222
- [
223
- activeIndex,
224
- filter,
225
- filterInputType,
226
- filteredDropDownItems,
227
- handleAddMultiValue,
228
- handleChangeViewMode,
229
- model,
230
- refs.domReference
231
- ]
153
+ [activeIndex, filter, filterInputType, filteredDropDownItems, model]
232
154
  );
233
155
  useEffect(() => {
234
156
  if (open) {
@@ -236,34 +158,13 @@ const AdHocCombobox = forwardRef(function AdHocCombobox2({ filter, model, isAlwa
236
158
  }
237
159
  }, [open, filterInputType]);
238
160
  useEffect(() => {
239
- var _a2, _b2;
161
+ var _a2;
240
162
  if (!isAlwaysWip) {
241
163
  setInputType("value");
242
164
  setInputValue("");
243
- if (hasMultiValueOperator && ((_a2 = filter == null ? void 0 : filter.values) == null ? void 0 : _a2.length)) {
244
- const multiValueOptions = filter.values.reduce(
245
- (acc, value, i) => {
246
- var _a3;
247
- return [
248
- ...acc,
249
- {
250
- label: ((_a3 = filter.valueLabels) == null ? void 0 : _a3[i]) || value,
251
- value
252
- }
253
- ];
254
- },
255
- []
256
- );
257
- setFilterMultiValues(multiValueOptions);
258
- }
259
- (_b2 = refs.domReference.current) == null ? void 0 : _b2.focus();
165
+ (_a2 = refs.domReference.current) == null ? void 0 : _a2.focus();
260
166
  }
261
167
  }, []);
262
- useEffect(() => {
263
- if (isMultiValueEdit && filterMultiValues) {
264
- setTimeout(() => setForceRefresh({}));
265
- }
266
- }, [filterMultiValues, isMultiValueEdit]);
267
168
  useLayoutEffect(() => {
268
169
  var _a2, _b2;
269
170
  if (activeIndex !== null && rowVirtualizer.range && (activeIndex > ((_a2 = rowVirtualizer.range) == null ? void 0 : _a2.endIndex) || activeIndex < ((_b2 = rowVirtualizer.range) == null ? void 0 : _b2.startIndex))) {
@@ -294,12 +195,9 @@ const AdHocCombobox = forwardRef(function AdHocCombobox2({ filter, model, isAlwa
294
195
  switchInputType("operator", setInputType, void 0, refs.domReference.current);
295
196
  }
296
197
  }
297
- }, filter.operator) : null, isMultiValueEdit ? filterMultiValues.map((item, i) => /* @__PURE__ */ React.createElement(MultiValuePill, {
298
- key: `${item.value}-${i}`,
299
- item,
300
- index: i,
301
- handleRemoveMultiValue
302
- })) : null) : null, /* @__PURE__ */ React.createElement("input", __spreadProps(__spreadValues({}, getReferenceProps({
198
+ }, filter.operator) : null, (filter == null ? void 0 : filter.key) && (filter == null ? void 0 : filter.operator) && (filter == null ? void 0 : filter.value) && !["operator", "value"].includes(filterInputType) ? /* @__PURE__ */ React.createElement("div", {
199
+ className: cx(styles.basePill, styles.valuePill)
200
+ }, valueLabel) : null) : null, /* @__PURE__ */ React.createElement("input", __spreadProps(__spreadValues({}, getReferenceProps({
303
201
  ref: refs.setReference,
304
202
  onChange,
305
203
  value: inputValue,
@@ -313,9 +211,9 @@ const AdHocCombobox = forwardRef(function AdHocCombobox2({ filter, model, isAlwa
313
211
  if (filterInputType === "operator") {
314
212
  handleShiftTabInput(event);
315
213
  }
316
- handleBackspaceInput(event, isMultiValueEdit);
317
- handleTabInput(event, isMultiValueEdit);
318
- handleEnterInput(event, isMultiValueEdit);
214
+ handleBackspaceInput(event);
215
+ handleTabInput(event);
216
+ handleEnterInput(event);
319
217
  }
320
218
  })), {
321
219
  className: cx(styles.inputStyle, { [styles.loadingInputPadding]: !optionsLoading }),
@@ -335,7 +233,7 @@ const AdHocCombobox = forwardRef(function AdHocCombobox2({ filter, model, isAlwa
335
233
  initialFocus: -1,
336
234
  visuallyHiddenDismiss: true,
337
235
  modal: false
338
- }, /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement("div", {
236
+ }, /* @__PURE__ */ React.createElement("div", {
339
237
  style: __spreadProps(__spreadValues({}, floatingStyles), {
340
238
  width: `${optionsError ? ERROR_STATE_DROPDOWN_WIDTH : maxOptionWidth}px`
341
239
  }),
@@ -376,24 +274,17 @@ const AdHocCombobox = forwardRef(function AdHocCombobox2({ filter, model, isAlwa
376
274
  listRef.current[index] = node;
377
275
  },
378
276
  onClick(event) {
379
- var _a3;
380
277
  if (filterInputType !== "value") {
381
278
  event.stopPropagation();
382
279
  }
383
- if (isMultiValueEdit) {
384
- event.stopPropagation();
385
- handleAddMultiValue(item);
386
- (_a3 = refs.domReference.current) == null ? void 0 : _a3.focus();
387
- } else {
388
- model._updateFilter(filter, generateFilterUpdatePayload(filterInputType, item));
389
- setInputValue("");
390
- switchToNextInputType(
391
- filterInputType,
392
- setInputType,
393
- handleChangeViewMode,
394
- refs.domReference.current
395
- );
396
- }
280
+ model._updateFilter(filter, generateFilterUpdatePayload(filterInputType, item));
281
+ setInputValue("");
282
+ switchToNextInputType(
283
+ filterInputType,
284
+ setInputType,
285
+ handleChangeViewMode,
286
+ refs.domReference.current
287
+ );
397
288
  }
398
289
  })), {
399
290
  active: activeIndex === index,
@@ -403,56 +294,19 @@ const AdHocCombobox = forwardRef(function AdHocCombobox2({ filter, model, isAlwa
403
294
  transform: `translateY(${virtualItem.start}px)`
404
295
  },
405
296
  "aria-setsize": filteredDropDownItems.length,
406
- "aria-posinset": virtualItem.index + 1,
407
- isMultiValueEdit,
408
- checked: filterMultiValues.some((val) => val.value === item.value)
409
- }), /* @__PURE__ */ React.createElement("span", null, item.isCustom ? "Use custom value: " : "", " ", (_a2 = item.label) != null ? _a2 : item.value), item.description ? /* @__PURE__ */ React.createElement("div", {
410
- className: styles.descriptionText
411
- }, item.description) : null);
412
- }))), isMultiValueEdit && !optionsLoading && !optionsError && filteredDropDownItems.length ? /* @__PURE__ */ React.createElement(MultiValueApplyButton, {
413
- onClick: () => handleMultiValueUpdate(model, filter, filterMultiValues),
414
- floatingElement: refs.floating.current,
415
- maxOptionWidth
416
- }) : null))));
297
+ "aria-posinset": virtualItem.index + 1
298
+ }), item.isCustom ? "Use custom value: " : "", " ", (_a2 = item.label) != null ? _a2 : item.value);
299
+ }))))));
417
300
  });
418
- const MultiValuePill = ({ item, handleRemoveMultiValue, index }) => {
419
- var _a, _b;
420
- const styles = useStyles2(getStyles);
421
- return /* @__PURE__ */ React.createElement("div", {
422
- className: cx(styles.basePill, styles.valuePill)
423
- }, /* @__PURE__ */ React.createElement("span", null, " ", (_a = item.label) != null ? _a : item.value), /* @__PURE__ */ React.createElement(Button, {
424
- onClick: (e) => {
425
- e.stopPropagation();
426
- e.preventDefault();
427
- handleRemoveMultiValue(item);
428
- },
429
- onKeyDownCapture: (e) => {
430
- if (e.key === "Enter") {
431
- e.preventDefault();
432
- e.stopPropagation();
433
- handleRemoveMultiValue(item);
434
- }
435
- },
436
- fill: "text",
437
- size: "sm",
438
- variant: "secondary",
439
- className: styles.removeButton,
440
- tooltip: `Remove filter value - ${(_b = item.label) != null ? _b : item.value}`
441
- }, /* @__PURE__ */ React.createElement(Icon, {
442
- name: "times",
443
- size: "md",
444
- id: `${item.value}-${index}`
445
- })));
446
- };
447
301
  const getStyles = (theme) => ({
448
302
  comboboxWrapper: css({
449
303
  display: "flex",
450
- flexWrap: "wrap"
304
+ flexWrap: "nowrap"
451
305
  }),
452
306
  pillWrapper: css({
453
307
  display: "flex",
454
308
  alignItems: "center",
455
- flexWrap: "wrap"
309
+ whiteSpace: "nowrap"
456
310
  }),
457
311
  basePill: css(__spreadProps(__spreadValues({
458
312
  display: "flex",
@@ -477,8 +331,7 @@ const getStyles = (theme) => ({
477
331
  }
478
332
  }),
479
333
  valuePill: css({
480
- background: theme.colors.action.selected,
481
- padding: theme.spacing(0.125, 0, 0.125, 1)
334
+ background: theme.colors.action.selected
482
335
  }),
483
336
  dropdownWrapper: css({
484
337
  backgroundColor: theme.colors.background.primary,
@@ -511,25 +364,6 @@ const getStyles = (theme) => ({
511
364
  "&:not(:first-child)": {
512
365
  borderTop: `1px solid ${theme.colors.border.weak}`
513
366
  }
514
- }),
515
- removeButton: css({
516
- marginInline: theme.spacing(0.5),
517
- height: "100%",
518
- padding: 0,
519
- cursor: "pointer",
520
- "&:hover": {
521
- color: theme.colors.text.primary
522
- }
523
- }),
524
- descriptionText: css(__spreadProps(__spreadValues({}, theme.typography.bodySmall), {
525
- color: theme.colors.text.secondary,
526
- paddingTop: theme.spacing(0.5)
527
- })),
528
- multiValueApply: css({
529
- position: "absolute",
530
- top: 0,
531
- left: 0,
532
- display: "flex"
533
367
  })
534
368
  });
535
369