@grafana/scenes 5.5.1--canary.830.9992215493.0 → 5.5.2--canary.830.10005065313.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.5.1 (Thu Jul 18 2024)
2
+
3
+ #### 🐛 Bug Fix
4
+
5
+ - Add triggering RefreshEvent on time range refresh [#838](https://github.com/grafana/scenes/pull/838) ([@asimonok](https://github.com/asimonok))
6
+
7
+ #### Authors: 1
8
+
9
+ - Alex Simonok ([@asimonok](https://github.com/asimonok))
10
+
11
+ ---
12
+
1
13
  # v5.5.0 (Thu Jul 18 2024)
2
14
 
3
15
  #### 🚀 Enhancement
@@ -4,7 +4,7 @@ import { SceneObjectBase } from './SceneObjectBase.js';
4
4
  import { getClosest } from './sceneGraph/utils.js';
5
5
  import { parseUrlParam } from '../utils/parseUrlParam.js';
6
6
  import { evaluateTimeRange } from '../utils/evaluateTimeRange.js';
7
- import { config } from '@grafana/runtime';
7
+ import { RefreshEvent, config } from '@grafana/runtime';
8
8
 
9
9
  var __defProp = Object.defineProperty;
10
10
  var __getOwnPropSymbols = Object.getOwnPropertySymbols;
@@ -78,6 +78,7 @@ class SceneTimeRange extends SceneObjectBase {
78
78
  this.state.UNSAFE_nowDelay
79
79
  )
80
80
  });
81
+ this.publishEvent(new RefreshEvent());
81
82
  };
82
83
  this.addActivationHandler(this._onActivate.bind(this));
83
84
  }
@@ -1 +1 @@
1
- {"version":3,"file":"SceneTimeRange.js","sources":["../../../src/core/SceneTimeRange.tsx"],"sourcesContent":["import { getTimeZone, setWeekStart, TimeRange } from '@grafana/data';\nimport { TimeZone } from '@grafana/schema';\n\nimport { SceneObjectUrlSyncConfig } from '../services/SceneObjectUrlSyncConfig';\n\nimport { SceneObjectBase } from './SceneObjectBase';\nimport { SceneTimeRangeLike, SceneTimeRangeState, SceneObjectUrlValues } from './types';\nimport { getClosest } from './sceneGraph/utils';\nimport { parseUrlParam } from '../utils/parseUrlParam';\nimport { evaluateTimeRange } from '../utils/evaluateTimeRange';\nimport { config } from '@grafana/runtime';\n\nexport class SceneTimeRange extends SceneObjectBase<SceneTimeRangeState> implements SceneTimeRangeLike {\n protected _urlSync = new SceneObjectUrlSyncConfig(this, { keys: ['from', 'to', 'timezone'] });\n\n public constructor(state: Partial<SceneTimeRangeState> = {}) {\n const from = state.from ?? 'now-6h';\n const to = state.to ?? 'now';\n const timeZone = state.timeZone;\n const value = evaluateTimeRange(\n from,\n to,\n timeZone || getTimeZone(),\n state.fiscalYearStartMonth,\n state.UNSAFE_nowDelay\n );\n super({ from, to, timeZone, value, ...state });\n\n this.addActivationHandler(this._onActivate.bind(this));\n }\n\n private _onActivate() {\n // When SceneTimeRange has no time zone provided, find closest source of time zone and subscribe to it\n if (!this.state.timeZone) {\n const timeZoneSource = this.getTimeZoneSource();\n if (timeZoneSource !== this) {\n this._subs.add(\n timeZoneSource.subscribeToState((n, p) => {\n if (n.timeZone !== undefined && n.timeZone !== p.timeZone) {\n this.setState({\n value: evaluateTimeRange(\n this.state.from,\n this.state.to,\n timeZoneSource.getTimeZone(),\n this.state.fiscalYearStartMonth,\n this.state.UNSAFE_nowDelay\n ),\n });\n }\n })\n );\n }\n }\n\n if (this.state.weekStart) {\n setWeekStart(this.state.weekStart);\n }\n\n // Deactivation handler that restore weekStart if it was changed\n return () => {\n if (this.state.weekStart) {\n setWeekStart(config.bootData.user.weekStart);\n }\n };\n }\n\n /**\n * Will traverse up the scene graph to find the closest SceneTimeRangeLike with time zone set\n */\n private getTimeZoneSource() {\n if (!this.parent || !this.parent.parent) {\n return this;\n }\n // Find the closest source of time zone\n const source = getClosest<SceneTimeRangeLike>(this.parent.parent, (o) => {\n if (o.state.$timeRange && o.state.$timeRange.state.timeZone) {\n return o.state.$timeRange;\n }\n return undefined;\n });\n\n if (!source) {\n return this;\n }\n\n return source;\n }\n\n public getTimeZone(): TimeZone {\n // Return local time zone if provided\n if (this.state.timeZone) {\n return this.state.timeZone;\n }\n\n // Resolve higher level time zone source\n const timeZoneSource = this.getTimeZoneSource();\n if (timeZoneSource !== this) {\n return timeZoneSource.state.timeZone!;\n }\n\n // Return default time zone\n return getTimeZone();\n }\n\n public onTimeRangeChange = (timeRange: TimeRange) => {\n const update: Partial<SceneTimeRangeState> = {};\n const updateToEval: Partial<SceneTimeRangeState> = {};\n\n if (typeof timeRange.raw.from === 'string') {\n update.from = timeRange.raw.from;\n updateToEval.from = timeRange.raw.from;\n } else {\n update.from = timeRange.raw.from.toISOString();\n updateToEval.from = timeRange.raw.from.toISOString(true);\n }\n\n if (typeof timeRange.raw.to === 'string') {\n update.to = timeRange.raw.to;\n updateToEval.to = timeRange.raw.to;\n } else {\n update.to = timeRange.raw.to.toISOString();\n updateToEval.to = timeRange.raw.to.toISOString(true);\n }\n\n update.value = evaluateTimeRange(\n updateToEval.from,\n updateToEval.to,\n this.getTimeZone(),\n this.state.fiscalYearStartMonth,\n this.state.UNSAFE_nowDelay\n );\n\n // Only update if time range actually changed\n if (update.from !== this.state.from || update.to !== this.state.to) {\n this.setState(update);\n }\n };\n\n public onTimeZoneChange = (timeZone: TimeZone) => {\n this.setState({ timeZone });\n };\n\n public onRefresh = () => {\n this.setState({\n value: evaluateTimeRange(\n this.state.from,\n this.state.to,\n this.getTimeZone(),\n this.state.fiscalYearStartMonth,\n this.state.UNSAFE_nowDelay\n ),\n });\n };\n\n public getUrlState() {\n const urlValues: SceneObjectUrlValues = { from: this.state.from, to: this.state.to };\n if (this.state.timeZone) {\n urlValues.timezone = this.state.timeZone;\n }\n\n return urlValues;\n }\n\n public updateFromUrl(values: SceneObjectUrlValues) {\n // ignore if both are missing\n if (!values.to && !values.from) {\n return;\n }\n\n const update: Partial<SceneTimeRangeState> = {};\n const from = parseUrlParam(values.from);\n\n if (from) {\n update.from = from;\n }\n\n const to = parseUrlParam(values.to);\n if (to) {\n update.to = to;\n }\n\n if (typeof values.timezone === 'string') {\n update.timeZone = values.timezone !== '' ? values.timezone : undefined;\n }\n\n update.value = evaluateTimeRange(\n update.from ?? this.state.from,\n update.to ?? this.state.to,\n update.timeZone ?? this.getTimeZone(),\n this.state.fiscalYearStartMonth,\n this.state.UNSAFE_nowDelay\n );\n\n this.setState(update);\n }\n}\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AAYO,MAAM,uBAAuB,eAAmE,CAAA;AAAA,EAG9F,WAAA,CAAY,KAAsC,GAAA,EAAI,EAAA;AAf/D,IAAA,IAAA,EAAA,EAAA,EAAA,CAAA;AAgBI,IAAM,MAAA,IAAA,GAAA,CAAO,EAAM,GAAA,KAAA,CAAA,IAAA,KAAN,IAAc,GAAA,EAAA,GAAA,QAAA,CAAA;AAC3B,IAAM,MAAA,EAAA,GAAA,CAAK,EAAM,GAAA,KAAA,CAAA,EAAA,KAAN,IAAY,GAAA,EAAA,GAAA,KAAA,CAAA;AACvB,IAAA,MAAM,WAAW,KAAM,CAAA,QAAA,CAAA;AACvB,IAAA,MAAM,KAAQ,GAAA,iBAAA;AAAA,MACZ,IAAA;AAAA,MACA,EAAA;AAAA,MACA,YAAY,WAAY,EAAA;AAAA,MACxB,KAAM,CAAA,oBAAA;AAAA,MACN,KAAM,CAAA,eAAA;AAAA,KACR,CAAA;AACA,IAAA,KAAA,CAAM,cAAE,CAAA,EAAA,IAAA,EAAM,EAAI,EAAA,QAAA,EAAU,SAAU,KAAO,CAAA,CAAA,CAAA;AAb/C,IAAU,IAAA,CAAA,QAAA,GAAW,IAAI,wBAAA,CAAyB,IAAM,EAAA,EAAE,IAAM,EAAA,CAAC,MAAQ,EAAA,IAAA,EAAM,UAAU,CAAA,EAAG,CAAA,CAAA;AA2F5F,IAAO,IAAA,CAAA,iBAAA,GAAoB,CAAC,SAAyB,KAAA;AACnD,MAAA,MAAM,SAAuC,EAAC,CAAA;AAC9C,MAAA,MAAM,eAA6C,EAAC,CAAA;AAEpD,MAAA,IAAI,OAAO,SAAA,CAAU,GAAI,CAAA,IAAA,KAAS,QAAU,EAAA;AAC1C,QAAO,MAAA,CAA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CAAA,IAAA;AAAA,MAAA,CAC1B,EAAO,GAAA,MAAA,CAAA,EAAA,KAAP,IAAa,GAAA,EAAA,GAAA,IAAA,CAAK,KAAM,CAAA,EAAA;AAAA,MAAA,CACxB,EAAO,GAAA,MAAA,CAAA,QAAA,KAAP,IAAmB,GAAA,EAAA,GAAA,IAAA,CAAK,WAAY,EAAA;AAAA,MACpC,KAAK,KAAM,CAAA,oBAAA;AAAA,MACX,KAAK,KAAM,CAAA,eAAA;AAAA,KACb,CAAA;AAEA,IAAA,IAAA,CAAK,SAAS,MAAM,CAAA,CAAA;AAAA,GACtB;AACF;;;;"}
1
+ {"version":3,"file":"SceneTimeRange.js","sources":["../../../src/core/SceneTimeRange.tsx"],"sourcesContent":["import { getTimeZone, setWeekStart, TimeRange } from '@grafana/data';\nimport { TimeZone } from '@grafana/schema';\n\nimport { SceneObjectUrlSyncConfig } from '../services/SceneObjectUrlSyncConfig';\n\nimport { SceneObjectBase } from './SceneObjectBase';\nimport { SceneTimeRangeLike, SceneTimeRangeState, SceneObjectUrlValues } from './types';\nimport { getClosest } from './sceneGraph/utils';\nimport { parseUrlParam } from '../utils/parseUrlParam';\nimport { evaluateTimeRange } from '../utils/evaluateTimeRange';\nimport { config, RefreshEvent } from '@grafana/runtime';\n\nexport class SceneTimeRange extends SceneObjectBase<SceneTimeRangeState> implements SceneTimeRangeLike {\n protected _urlSync = new SceneObjectUrlSyncConfig(this, { keys: ['from', 'to', 'timezone'] });\n\n public constructor(state: Partial<SceneTimeRangeState> = {}) {\n const from = state.from ?? 'now-6h';\n const to = state.to ?? 'now';\n const timeZone = state.timeZone;\n const value = evaluateTimeRange(\n from,\n to,\n timeZone || getTimeZone(),\n state.fiscalYearStartMonth,\n state.UNSAFE_nowDelay\n );\n super({ from, to, timeZone, value, ...state });\n\n this.addActivationHandler(this._onActivate.bind(this));\n }\n\n private _onActivate() {\n // When SceneTimeRange has no time zone provided, find closest source of time zone and subscribe to it\n if (!this.state.timeZone) {\n const timeZoneSource = this.getTimeZoneSource();\n if (timeZoneSource !== this) {\n this._subs.add(\n timeZoneSource.subscribeToState((n, p) => {\n if (n.timeZone !== undefined && n.timeZone !== p.timeZone) {\n this.setState({\n value: evaluateTimeRange(\n this.state.from,\n this.state.to,\n timeZoneSource.getTimeZone(),\n this.state.fiscalYearStartMonth,\n this.state.UNSAFE_nowDelay\n ),\n });\n }\n })\n );\n }\n }\n\n if (this.state.weekStart) {\n setWeekStart(this.state.weekStart);\n }\n\n // Deactivation handler that restore weekStart if it was changed\n return () => {\n if (this.state.weekStart) {\n setWeekStart(config.bootData.user.weekStart);\n }\n };\n }\n\n /**\n * Will traverse up the scene graph to find the closest SceneTimeRangeLike with time zone set\n */\n private getTimeZoneSource() {\n if (!this.parent || !this.parent.parent) {\n return this;\n }\n // Find the closest source of time zone\n const source = getClosest<SceneTimeRangeLike>(this.parent.parent, (o) => {\n if (o.state.$timeRange && o.state.$timeRange.state.timeZone) {\n return o.state.$timeRange;\n }\n return undefined;\n });\n\n if (!source) {\n return this;\n }\n\n return source;\n }\n\n public getTimeZone(): TimeZone {\n // Return local time zone if provided\n if (this.state.timeZone) {\n return this.state.timeZone;\n }\n\n // Resolve higher level time zone source\n const timeZoneSource = this.getTimeZoneSource();\n if (timeZoneSource !== this) {\n return timeZoneSource.state.timeZone!;\n }\n\n // Return default time zone\n return getTimeZone();\n }\n\n public onTimeRangeChange = (timeRange: TimeRange) => {\n const update: Partial<SceneTimeRangeState> = {};\n const updateToEval: Partial<SceneTimeRangeState> = {};\n\n if (typeof timeRange.raw.from === 'string') {\n update.from = timeRange.raw.from;\n updateToEval.from = timeRange.raw.from;\n } else {\n update.from = timeRange.raw.from.toISOString();\n updateToEval.from = timeRange.raw.from.toISOString(true);\n }\n\n if (typeof timeRange.raw.to === 'string') {\n update.to = timeRange.raw.to;\n updateToEval.to = timeRange.raw.to;\n } else {\n update.to = timeRange.raw.to.toISOString();\n updateToEval.to = timeRange.raw.to.toISOString(true);\n }\n\n update.value = evaluateTimeRange(\n updateToEval.from,\n updateToEval.to,\n this.getTimeZone(),\n this.state.fiscalYearStartMonth,\n this.state.UNSAFE_nowDelay\n );\n\n // Only update if time range actually changed\n if (update.from !== this.state.from || update.to !== this.state.to) {\n this.setState(update);\n }\n };\n\n public onTimeZoneChange = (timeZone: TimeZone) => {\n this.setState({ timeZone });\n };\n\n public onRefresh = () => {\n this.setState({\n value: evaluateTimeRange(\n this.state.from,\n this.state.to,\n this.getTimeZone(),\n this.state.fiscalYearStartMonth,\n this.state.UNSAFE_nowDelay\n ),\n });\n\n this.publishEvent(new RefreshEvent());\n };\n\n public getUrlState() {\n const urlValues: SceneObjectUrlValues = { from: this.state.from, to: this.state.to };\n if (this.state.timeZone) {\n urlValues.timezone = this.state.timeZone;\n }\n\n return urlValues;\n }\n\n public updateFromUrl(values: SceneObjectUrlValues) {\n // ignore if both are missing\n if (!values.to && !values.from) {\n return;\n }\n\n const update: Partial<SceneTimeRangeState> = {};\n const from = parseUrlParam(values.from);\n\n if (from) {\n update.from = from;\n }\n\n const to = parseUrlParam(values.to);\n if (to) {\n update.to = to;\n }\n\n if (typeof values.timezone === 'string') {\n update.timeZone = values.timezone !== '' ? values.timezone : undefined;\n }\n\n update.value = evaluateTimeRange(\n update.from ?? this.state.from,\n update.to ?? this.state.to,\n update.timeZone ?? this.getTimeZone(),\n this.state.fiscalYearStartMonth,\n this.state.UNSAFE_nowDelay\n );\n\n this.setState(update);\n }\n}\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AAYO,MAAM,uBAAuB,eAAmE,CAAA;AAAA,EAG9F,WAAA,CAAY,KAAsC,GAAA,EAAI,EAAA;AAf/D,IAAA,IAAA,EAAA,EAAA,EAAA,CAAA;AAgBI,IAAM,MAAA,IAAA,GAAA,CAAO,EAAM,GAAA,KAAA,CAAA,IAAA,KAAN,IAAc,GAAA,EAAA,GAAA,QAAA,CAAA;AAC3B,IAAM,MAAA,EAAA,GAAA,CAAK,EAAM,GAAA,KAA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 +57,8 @@ const AdHocCombobox = forwardRef(function AdHocCombobox2({ filter, model, wip, h
57
57
  var _a;
58
58
  const [open, setOpen] = useState(false);
59
59
  const [options, setOptions] = useState([]);
60
+ const [optionsLoading, setOptionsLoading] = useState(false);
61
+ const [optionsError, setOptionsError] = useState(false);
60
62
  const [inputValue, setInputValue] = useState("");
61
63
  const [activeIndex, setActiveIndex] = useState(null);
62
64
  const [inputType, setInputType] = useState(!wip ? "value" : "key");
@@ -178,22 +180,33 @@ const AdHocCombobox = forwardRef(function AdHocCombobox2({ filter, model, wip, h
178
180
  refs.domReference.current.focus();
179
181
  }
180
182
  }, []);
181
- const handleFetchOptions = useCallback(async () => {
182
- let options2 = [];
183
- if (inputType === "key") {
184
- options2 = await model._getKeys(null);
185
- } else if (inputType === "operator") {
186
- options2 = model._getOperators();
187
- } else if (inputType === "value") {
188
- options2 = await model._getValuesFor(filterToUse);
189
- }
190
- setOptions(options2);
191
- }, [filterToUse, inputType, model]);
183
+ const handleFetchOptions = useCallback(
184
+ async (inputType2) => {
185
+ setOptionsError(false);
186
+ setOptionsLoading(true);
187
+ setOptions([]);
188
+ let options2 = [];
189
+ try {
190
+ if (inputType2 === "key") {
191
+ options2 = await model._getKeys(null);
192
+ } else if (inputType2 === "operator") {
193
+ options2 = model._getOperators();
194
+ } else if (inputType2 === "value") {
195
+ options2 = await model._getValuesFor(filterToUse);
196
+ }
197
+ setOptions(options2);
198
+ } catch (e) {
199
+ setOptionsError(true);
200
+ }
201
+ setOptionsLoading(false);
202
+ },
203
+ [filterToUse, model]
204
+ );
192
205
  const handleBackspaceInput = useCallback(
193
206
  (event) => {
194
207
  if (event.key === "Backspace" && !inputValue && inputType === "key") {
195
208
  model._removeLastFilter();
196
- setOpen(false);
209
+ handleFetchOptions(inputType);
197
210
  }
198
211
  },
199
212
  [inputValue, inputType]
@@ -216,6 +229,7 @@ const AdHocCombobox = forwardRef(function AdHocCombobox2({ filter, model, wip, h
216
229
  if (event.key === "Enter" && activeIndex != null && items[activeIndex]) {
217
230
  model._updateFilter(filterToUse, inputType, items[activeIndex]);
218
231
  setInputValue("");
232
+ setActiveIndex(0);
219
233
  if (inputType === "key") {
220
234
  flushInputType("operator");
221
235
  } else if (inputType === "operator") {
@@ -231,7 +245,7 @@ const AdHocCombobox = forwardRef(function AdHocCombobox2({ filter, model, wip, h
231
245
  );
232
246
  useEffect(() => {
233
247
  if (open) {
234
- handleFetchOptions();
248
+ handleFetchOptions(inputType);
235
249
  }
236
250
  }, [open, inputType]);
237
251
  return /* @__PURE__ */ React.createElement("div", {
@@ -296,7 +310,9 @@ const AdHocCombobox = forwardRef(function AdHocCombobox2({ filter, model, wip, h
296
310
  })
297
311
  })), {
298
312
  className: styles.dropdownWrapper
299
- }), items.map((item, index) => {
313
+ }), optionsLoading ? /* @__PURE__ */ React.createElement(LoadingOptionsPlaceholder, null) : optionsError ? /* @__PURE__ */ React.createElement(OptionsErrorPlaceholder, {
314
+ handleFetchOptions: () => handleFetchOptions(inputType)
315
+ }) : !items.length ? /* @__PURE__ */ React.createElement(NoOptionsPlaceholder, null) : items.map((item, index) => {
300
316
  var _a2;
301
317
  return /* @__PURE__ */ React.createElement(Item, __spreadProps(__spreadValues({}, getItemProps({
302
318
  key: item.value,
@@ -322,6 +338,22 @@ const AdHocCombobox = forwardRef(function AdHocCombobox2({ filter, model, wip, h
322
338
  }), (_a2 = item.label) != null ? _a2 : item.value);
323
339
  })))));
324
340
  });
341
+ const LoadingOptionsPlaceholder = () => {
342
+ return /* @__PURE__ */ React.createElement(Item, {
343
+ active: false
344
+ }, "Loading options...");
345
+ };
346
+ const NoOptionsPlaceholder = () => {
347
+ return /* @__PURE__ */ React.createElement(Item, {
348
+ active: false
349
+ }, "No options found");
350
+ };
351
+ const OptionsErrorPlaceholder = ({ handleFetchOptions }) => {
352
+ return /* @__PURE__ */ React.createElement(Item, {
353
+ active: false,
354
+ onClick: handleFetchOptions
355
+ }, "Error. Click to try again!");
356
+ };
325
357
  const getStyles2 = (theme) => ({
326
358
  comboboxWrapper: css({
327
359
  display: "flex",
@@ -1 +1 @@
1
- {"version":3,"file":"AdHocFiltersCombobox.js","sources":["../../../../../src/variables/adhoc/AdHocFiltersCombobox/AdHocFiltersCombobox.tsx"],"sourcesContent":["import React, { forwardRef, useCallback, useEffect, useImperativeHandle, useRef, useState } from 'react';\nimport {\n autoUpdate,\n size,\n flip,\n useId,\n useDismiss,\n useFloating,\n useInteractions,\n useListNavigation,\n useRole,\n FloatingFocusManager,\n FloatingPortal,\n} from '@floating-ui/react';\nimport { getSelectStyles, useStyles2, useTheme2 } from '@grafana/ui';\nimport { GrafanaTheme2, SelectableValue } from '@grafana/data';\nimport { css, cx } from '@emotion/css';\nimport { AdHocFilterWithLabels, AdHocFiltersVariable } from '../AdHocFiltersVariable';\nimport { flushSync } from 'react-dom';\n\ninterface ItemProps {\n children: React.ReactNode;\n active: boolean;\n}\n\n// eslint-disable-next-line react/display-name\nconst Item = forwardRef<HTMLDivElement, ItemProps & React.HTMLProps<HTMLDivElement>>(\n ({ children, active, ...rest }, ref) => {\n const theme = useTheme2();\n const selectStyles = getSelectStyles(theme);\n const id = useId();\n return (\n <div\n ref={ref}\n role=\"option\"\n id={id}\n aria-selected={active}\n className={cx(selectStyles.option, active && selectStyles.optionFocused)}\n {...rest}\n >\n <div className={selectStyles.optionBody} data-testid={`data-testid ad hoc filter option value ${children}`}>\n <span>{children}</span>\n </div>\n </div>\n );\n }\n);\n\ninterface AdHocComboboxProps {\n filter?: AdHocFilterWithLabels;\n wip?: boolean;\n model: AdHocFiltersVariable;\n handleChangeViewMode?: () => void;\n}\n\ntype AdHocInputType = 'key' | 'operator' | 'value';\n\nexport const AdHocCombobox = forwardRef(function AdHocCombobox(\n { filter, model, wip, handleChangeViewMode }: AdHocComboboxProps,\n parentRef\n) {\n const [open, setOpen] = useState(false);\n // const [optionsLoading, setOptionsLoading] = useState<boolean>(false);\n const [options, setOptions] = useState<Array<SelectableValue<string>>>([]);\n const [inputValue, setInputValue] = useState('');\n const [activeIndex, setActiveIndex] = useState<number | null>(null);\n const [inputType, setInputType] = useState<AdHocInputType>(!wip ? 'value' : 'key');\n const styles = useStyles2(getStyles2);\n\n const listRef = useRef<Array<HTMLElement | null>>([]);\n const { _wip } = model.useState();\n\n const handleResetWip = useCallback(() => {\n if (wip) {\n model._addWip();\n setInputType('key');\n setInputValue('');\n }\n }, [model, wip]);\n\n const filterToUse = filter || _wip;\n\n const operatorIdentifier = `${filterToUse?.key ?? ''}-operator`;\n\n const { refs, floatingStyles, context } = useFloating<HTMLInputElement>({\n whileElementsMounted: autoUpdate,\n open,\n onOpenChange: (nextOpen, _, reason) => {\n setOpen(nextOpen);\n // change from filter edit mode to filter view mode when clicked\n // outside input or dropdown\n if (['outside-press', 'escape-key'].includes(reason || '')) {\n handleResetWip();\n handleChangeViewMode?.();\n }\n },\n middleware: [\n flip({ padding: 10 }),\n size({\n apply({ rects, availableHeight, elements }) {\n Object.assign(elements.floating.style, {\n width: `${rects.reference.width}px`,\n // limit the maxHeight of dropdown\n maxHeight: `${availableHeight > 256 ? 256 : availableHeight}px`,\n });\n },\n padding: 10,\n }),\n ],\n });\n\n const role = useRole(context, { role: 'listbox' });\n const dismiss = useDismiss(context, {\n // if outside click lands on operator pill, then ignore outside click\n outsidePress: (event) => {\n return !(event as unknown as React.MouseEvent<HTMLElement, MouseEvent>).currentTarget.classList.contains(\n operatorIdentifier\n );\n },\n });\n const listNav = useListNavigation(context, {\n listRef,\n activeIndex,\n onNavigate: setActiveIndex,\n virtual: true,\n loop: true,\n });\n\n const { getReferenceProps, getFloatingProps, getItemProps } = useInteractions([role, dismiss, listNav]);\n\n // pass ability to focus on input element back to parent\n useImperativeHandle(parentRef, () => () => refs.domReference.current?.focus(), [refs.domReference]);\n\n function onChange(event: React.ChangeEvent<HTMLInputElement>) {\n // part of POC for seamless filter parser\n if (inputType === 'key') {\n const lastChar = event.target.value.slice(-1);\n if (['=', '!', '<', '>'].includes(lastChar)) {\n const key = event.target.value.slice(0, -1);\n const optionIndex = options.findIndex((option) => option.value === key);\n if (optionIndex >= 0) {\n model._updateFilter(filterToUse!, inputType, options[optionIndex]);\n setInputValue(lastChar);\n }\n flushSync(() => {\n setInputType('operator');\n });\n refs.domReference.current?.focus();\n return;\n }\n }\n if (inputType === 'operator') {\n const lastChar = event.target.value.slice(-1);\n if (/\\w/.test(lastChar)) {\n const operator = event.target.value.slice(0, -1);\n if (!/\\w/.test(operator)) {\n const optionIndex = options.findIndex((option) => option.value === operator);\n if (optionIndex >= 0) {\n model._updateFilter(filterToUse!, inputType, options[optionIndex]);\n setInputValue(lastChar);\n }\n flushSync(() => {\n setInputType('value');\n });\n refs.domReference.current?.focus();\n return;\n }\n }\n }\n\n const value = event.target.value;\n setInputValue(value);\n setActiveIndex(0);\n }\n\n const items = options.filter((item) =>\n (item.label ?? item.value)?.toLocaleLowerCase().startsWith(inputValue.toLowerCase())\n );\n\n const flushInputType = useCallback((inputType: AdHocInputType) => {\n flushSync(() => {\n setInputType(inputType);\n });\n }, []);\n\n // when combobox is in wip mode then check and add _wip if its missing\n // needed on first render and when _wip is reset on filter value commit\n useEffect(() => {\n if (wip && !_wip) {\n model._addWip();\n }\n\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [_wip]);\n\n // when not in wip mode this is the point of switching from view to edit mode\n // and in this case we default to 'value' input type and focus input\n useEffect(() => {\n if (!wip && refs.domReference.current) {\n setInputType('value');\n setInputValue('');\n\n refs.domReference.current.focus();\n }\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, []);\n\n const handleFetchOptions = useCallback(async () => {\n let options: Array<SelectableValue<string>> = [];\n // TODO: missing async placeholder while options load\n if (inputType === 'key') {\n options = await model._getKeys(null);\n } else if (inputType === 'operator') {\n options = model._getOperators();\n } else if (inputType === 'value') {\n options = await model._getValuesFor(filterToUse!);\n }\n setOptions(options);\n }, [filterToUse, inputType, model]);\n\n const handleBackspaceInput = useCallback(\n (event: React.KeyboardEvent) => {\n if (event.key === 'Backspace' && !inputValue && inputType === 'key') {\n model._removeLastFilter();\n setOpen(false);\n }\n },\n // eslint-disable-next-line react-hooks/exhaustive-deps\n [inputValue, inputType]\n );\n\n const handleTabInput = useCallback((event: React.KeyboardEvent) => {\n // change filter to view mode when navigating away with Tab key\n // this is needed because useDismiss only reacts to mousedown\n if (event.key === 'Tab' && !event.shiftKey) {\n handleChangeViewMode?.();\n handleResetWip();\n }\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, []);\n\n const handleShiftTabInput = useCallback((event: React.KeyboardEvent) => {\n if (event.key === 'Tab' && event.shiftKey) {\n handleChangeViewMode?.();\n handleResetWip();\n }\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, []);\n\n const handleEnterInput = useCallback(\n (event: React.KeyboardEvent) => {\n if (event.key === 'Enter' && activeIndex != null && items[activeIndex]) {\n model._updateFilter(filterToUse!, inputType, items[activeIndex]);\n setInputValue('');\n\n if (inputType === 'key') {\n flushInputType('operator');\n } else if (inputType === 'operator') {\n flushInputType('value');\n } else if (inputType === 'value') {\n flushInputType('key');\n\n handleChangeViewMode?.();\n }\n\n refs.domReference.current?.focus();\n }\n },\n // eslint-disable-next-line react-hooks/exhaustive-deps\n [activeIndex, filterToUse, inputType, items, model]\n );\n\n useEffect(() => {\n if (open) {\n handleFetchOptions();\n }\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [open, inputType]);\n\n return (\n <div className={styles.comboboxWrapper}>\n {filterToUse ? (\n <div className={styles.pillWrapper}>\n {filterToUse?.key ? <div className={cx(styles.basePill, styles.keyPill)}>{filterToUse.key}</div> : null}\n {filterToUse?.key && filterToUse?.operator && inputType !== 'operator' ? (\n <div\n className={cx(styles.basePill, styles.operatorPill, operatorIdentifier)}\n role=\"button\"\n aria-label=\"Edit filter operator\"\n tabIndex={0}\n onClick={(event) => {\n event.stopPropagation();\n flushInputType('operator');\n\n refs.domReference.current?.focus();\n }}\n onKeyDown={(event) => {\n handleShiftTabInput(event);\n if (event.key === 'Enter') {\n flushInputType('operator');\n refs.domReference.current?.focus();\n }\n }}\n >\n {filterToUse.operator}\n </div>\n ) : null}\n {filterToUse?.key &&\n filterToUse?.operator &&\n filterToUse?.value &&\n !['operator', 'value'].includes(inputType) ? (\n <div className={cx(styles.basePill, styles.valuePill)}>{filterToUse.value}</div>\n ) : null}\n </div>\n ) : null}\n\n <input\n {...getReferenceProps({\n ref: refs.setReference,\n onChange,\n value: inputValue,\n // dynamic placeholder to display operator and/or value in filter edit mode\n placeholder: !wip\n ? inputType === 'operator'\n ? `${filterToUse![inputType]} ${filterToUse!.value || ''}`\n : filterToUse![inputType]\n : 'Filter by label values',\n 'aria-autocomplete': 'list',\n onKeyDown(event) {\n if (inputType === 'operator') {\n handleShiftTabInput(event);\n }\n handleBackspaceInput(event);\n handleTabInput(event);\n handleEnterInput(event);\n },\n })}\n className={styles.inputStyle}\n onClick={(event) => {\n event.stopPropagation();\n setOpen(true);\n }}\n onFocus={() => {\n setActiveIndex(0);\n setOpen(true);\n }}\n />\n <FloatingPortal>\n {open && (\n <FloatingFocusManager context={context} initialFocus={-1} visuallyHiddenDismiss>\n <div\n {...getFloatingProps({\n ref: refs.setFloating,\n style: {\n ...floatingStyles,\n overflowY: 'auto',\n },\n })}\n className={styles.dropdownWrapper}\n >\n {items.map((item, index) => (\n // eslint-disable-next-line react/jsx-key\n <Item\n {...getItemProps({\n key: item.value!,\n ref(node) {\n listRef.current[index] = node;\n },\n onClick() {\n model._updateFilter(filterToUse!, inputType, item);\n setInputValue('');\n\n if (inputType === 'key') {\n flushInputType('operator');\n } else if (inputType === 'operator') {\n flushInputType('value');\n } else if (inputType === 'value') {\n flushInputType('key');\n handleChangeViewMode?.();\n }\n\n refs.domReference.current?.focus();\n },\n })}\n active={activeIndex === index}\n >\n {item.label ?? item.value}\n </Item>\n ))}\n </div>\n </FloatingFocusManager>\n )}\n </FloatingPortal>\n </div>\n );\n});\n\nconst getStyles2 = (theme: GrafanaTheme2) => ({\n comboboxWrapper: css({\n display: 'flex',\n flexWrap: 'nowrap',\n }),\n pillWrapper: css({\n display: 'flex',\n alignItems: 'center',\n whiteSpace: 'nowrap',\n }),\n basePill: css({\n display: 'flex',\n alignItems: 'center',\n background: theme.colors.action.disabledBackground,\n border: `1px solid ${theme.colors.border.weak}`,\n padding: theme.spacing(0.125, 1, 0.125, 1),\n color: theme.colors.text.primary,\n overflow: 'hidden',\n whiteSpace: 'nowrap',\n minHeight: '22px',\n ...theme.typography.bodySmall,\n cursor: 'pointer',\n }),\n keyPill: css({\n fontWeight: theme.typography.fontWeightBold,\n cursor: 'default',\n }),\n operatorPill: css({\n '&:hover': {\n background: theme.colors.action.hover,\n },\n }),\n valuePill: css({\n background: theme.colors.action.selected,\n }),\n dropdownWrapper: css({\n backgroundColor: theme.colors.background.primary,\n color: theme.colors.text.primary,\n boxShadow: theme.shadows.z2,\n }),\n inputStyle: css({\n paddingBlock: 0,\n '&:focus': {\n outline: 'none',\n },\n }),\n});\n"],"names":["AdHocCombobox","_a","inputType","options"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA0BA,MAAM,IAAO,GAAA,UAAA;AAAA,EACX,CAAC,IAA+B,GAAQ,KAAA;AAAvC,IAAA,IAAA,EAAA,GAAA,EAAA,EAAE,YAAU,MA3Bf,EAAA,GA2BG,IAAuB,IAAvB,GAAA,SAAA,CAAA,EAAA,EAAuB,CAArB,UAAU,EAAA,QAAA,CAAA,CAAA,CAAA;AACX,IAAA,MAAM,QAAQ,SAAU,EAAA,CAAA;AACxB,IAAM,MAAA,YAAA,GAAe,gBAAgB,KAAK,CAAA,CAAA;AAC1C,IAAA,MAAM,KAAK,KAAM,EAAA,CAAA;AACjB,IAAA,uBACG,KAAA,CAAA,aAAA,CAAA,KAAA,EAAA,cAAA,CAAA;AAAA,MACC,GAAA;AAAA,MACA,IAAK,EAAA,QAAA;AAAA,MACL,EAAA;AAAA,MACA,eAAe,EAAA,MAAA;AAAA,MACf,WAAW,EA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ACT,UAAA,EAAY,KAAM,CAAA,MAAA,CAAO,MAAO,CAAA,KAAA;AAAA,KAClC;AAAA,GACD,CAAA;AAAA,EACD,WAAW,GAAI,CAAA;AAAA,IACb,UAAA,EAAY,KAAM,CAAA,MAAA,CAAO,MAAO,CAAA,QAAA;AAAA,GACjC,CAAA;AAAA,EACD,iBAAiB,GAAI,CAAA;AAAA,IACnB,eAAA,EAAiB,KAAM,CAAA,MAAA,CAAO,UAAW,CAAA,OAAA;AAAA,IACzC,KAAA,EAAO,KAAM,CAAA,MAAA,CAAO,IAAK,CAAA,OAAA;AAAA,IACzB,SAAA,EAAW,MAAM,OAAQ,CAAA,EAAA;AAAA,GAC1B,CAAA;AAAA,EACD,YAAY,GAAI,CAAA;AAAA,IACd,YAAc,EAAA,CAAA;AAAA,IACd,SAAW,EAAA;AAAA,MACT,OAAS,EAAA,MAAA;AAAA,KACX;AAAA,GACD,CAAA;AACH,CAAA,CAAA;;;;"}
1
+ {"version":3,"file":"AdHocFiltersCombobox.js","sources":["../../../../../src/variables/adhoc/AdHocFiltersCombobox/AdHocFiltersCombobox.tsx"],"sourcesContent":["import React, { forwardRef, useCallback, useEffect, useImperativeHandle, useRef, useState } from 'react';\nimport {\n autoUpdate,\n size,\n flip,\n useId,\n useDismiss,\n useFloating,\n useInteractions,\n useListNavigation,\n useRole,\n FloatingFocusManager,\n FloatingPortal,\n} from '@floating-ui/react';\nimport { getSelectStyles, useStyles2, useTheme2 } from '@grafana/ui';\nimport { GrafanaTheme2, SelectableValue } from '@grafana/data';\nimport { css, cx } from '@emotion/css';\nimport { AdHocFilterWithLabels, AdHocFiltersVariable } from '../AdHocFiltersVariable';\nimport { flushSync } from 'react-dom';\n\ninterface ItemProps {\n children: React.ReactNode;\n active: boolean;\n}\n\n// eslint-disable-next-line react/display-name\nconst Item = forwardRef<HTMLDivElement, ItemProps & React.HTMLProps<HTMLDivElement>>(\n ({ children, active, ...rest }, ref) => {\n const theme = useTheme2();\n const selectStyles = getSelectStyles(theme);\n const id = useId();\n return (\n <div\n ref={ref}\n role=\"option\"\n id={id}\n aria-selected={active}\n className={cx(selectStyles.option, active && selectStyles.optionFocused)}\n {...rest}\n >\n <div className={selectStyles.optionBody} data-testid={`data-testid ad hoc filter option value ${children}`}>\n <span>{children}</span>\n </div>\n </div>\n );\n }\n);\n\ninterface AdHocComboboxProps {\n filter?: AdHocFilterWithLabels;\n wip?: boolean;\n model: AdHocFiltersVariable;\n handleChangeViewMode?: () => void;\n}\n\ntype AdHocInputType = 'key' | 'operator' | 'value';\n\nexport const AdHocCombobox = forwardRef(function AdHocCombobox(\n { filter, model, wip, handleChangeViewMode }: AdHocComboboxProps,\n parentRef\n) {\n const [open, setOpen] = useState(false);\n\n const [options, setOptions] = useState<Array<SelectableValue<string>>>([]);\n const [optionsLoading, setOptionsLoading] = useState<boolean>(false);\n const [optionsError, setOptionsError] = useState<boolean>(false);\n const [inputValue, setInputValue] = useState('');\n const [activeIndex, setActiveIndex] = useState<number | null>(null);\n const [inputType, setInputType] = useState<AdHocInputType>(!wip ? 'value' : 'key');\n const styles = useStyles2(getStyles2);\n\n const listRef = useRef<Array<HTMLElement | null>>([]);\n const { _wip } = model.useState();\n\n const handleResetWip = useCallback(() => {\n if (wip) {\n model._addWip();\n setInputType('key');\n setInputValue('');\n }\n }, [model, wip]);\n\n const filterToUse = filter || _wip;\n\n const operatorIdentifier = `${filterToUse?.key ?? ''}-operator`;\n\n const { refs, floatingStyles, context } = useFloating<HTMLInputElement>({\n whileElementsMounted: autoUpdate,\n open,\n onOpenChange: (nextOpen, _, reason) => {\n setOpen(nextOpen);\n // change from filter edit mode to filter view mode when clicked\n // outside input or dropdown\n if (['outside-press', 'escape-key'].includes(reason || '')) {\n handleResetWip();\n handleChangeViewMode?.();\n }\n },\n middleware: [\n flip({ padding: 10 }),\n size({\n apply({ rects, availableHeight, elements }) {\n Object.assign(elements.floating.style, {\n width: `${rects.reference.width}px`,\n // limit the maxHeight of dropdown\n maxHeight: `${availableHeight > 256 ? 256 : availableHeight}px`,\n });\n },\n padding: 10,\n }),\n ],\n });\n\n const role = useRole(context, { role: 'listbox' });\n const dismiss = useDismiss(context, {\n // if outside click lands on operator pill, then ignore outside click\n outsidePress: (event) => {\n return !(event as unknown as React.MouseEvent<HTMLElement, MouseEvent>).currentTarget.classList.contains(\n operatorIdentifier\n );\n },\n });\n const listNav = useListNavigation(context, {\n listRef,\n activeIndex,\n onNavigate: setActiveIndex,\n virtual: true,\n loop: true,\n });\n\n const { getReferenceProps, getFloatingProps, getItemProps } = useInteractions([role, dismiss, listNav]);\n\n // pass ability to focus on input element back to parent\n useImperativeHandle(parentRef, () => () => refs.domReference.current?.focus(), [refs.domReference]);\n\n function onChange(event: React.ChangeEvent<HTMLInputElement>) {\n // part of POC for seamless filter parser\n if (inputType === 'key') {\n const lastChar = event.target.value.slice(-1);\n if (['=', '!', '<', '>'].includes(lastChar)) {\n const key = event.target.value.slice(0, -1);\n const optionIndex = options.findIndex((option) => option.value === key);\n if (optionIndex >= 0) {\n model._updateFilter(filterToUse!, inputType, options[optionIndex]);\n setInputValue(lastChar);\n }\n flushSync(() => {\n setInputType('operator');\n });\n refs.domReference.current?.focus();\n return;\n }\n }\n if (inputType === 'operator') {\n const lastChar = event.target.value.slice(-1);\n if (/\\w/.test(lastChar)) {\n const operator = event.target.value.slice(0, -1);\n if (!/\\w/.test(operator)) {\n const optionIndex = options.findIndex((option) => option.value === operator);\n if (optionIndex >= 0) {\n model._updateFilter(filterToUse!, inputType, options[optionIndex]);\n setInputValue(lastChar);\n }\n flushSync(() => {\n setInputType('value');\n });\n refs.domReference.current?.focus();\n return;\n }\n }\n }\n\n const value = event.target.value;\n setInputValue(value);\n setActiveIndex(0);\n }\n\n const items = options.filter((item) =>\n (item.label ?? item.value)?.toLocaleLowerCase().startsWith(inputValue.toLowerCase())\n );\n\n const flushInputType = useCallback((inputType: AdHocInputType) => {\n flushSync(() => {\n setInputType(inputType);\n });\n }, []);\n\n // when combobox is in wip mode then check and add _wip if its missing\n // needed on first render and when _wip is reset on filter value commit\n useEffect(() => {\n if (wip && !_wip) {\n model._addWip();\n }\n\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [_wip]);\n\n // when not in wip mode this is the point of switching from view to edit mode\n // and in this case we default to 'value' input type and focus input\n useEffect(() => {\n if (!wip && refs.domReference.current) {\n setInputType('value');\n setInputValue('');\n\n refs.domReference.current.focus();\n }\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, []);\n\n const handleFetchOptions = useCallback(\n async (inputType: AdHocInputType) => {\n setOptionsError(false);\n setOptionsLoading(true);\n setOptions([]);\n let options: Array<SelectableValue<string>> = [];\n try {\n if (inputType === 'key') {\n options = await model._getKeys(null);\n } else if (inputType === 'operator') {\n options = model._getOperators();\n } else if (inputType === 'value') {\n options = await model._getValuesFor(filterToUse!);\n }\n setOptions(options);\n } catch (e) {\n setOptionsError(true);\n }\n setOptionsLoading(false);\n },\n [filterToUse, model]\n );\n\n const handleBackspaceInput = useCallback(\n (event: React.KeyboardEvent) => {\n if (event.key === 'Backspace' && !inputValue && inputType === 'key') {\n model._removeLastFilter();\n handleFetchOptions(inputType);\n }\n },\n // eslint-disable-next-line react-hooks/exhaustive-deps\n [inputValue, inputType]\n );\n\n const handleTabInput = useCallback((event: React.KeyboardEvent) => {\n // change filter to view mode when navigating away with Tab key\n // this is needed because useDismiss only reacts to mousedown\n if (event.key === 'Tab' && !event.shiftKey) {\n handleChangeViewMode?.();\n handleResetWip();\n }\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, []);\n\n const handleShiftTabInput = useCallback((event: React.KeyboardEvent) => {\n if (event.key === 'Tab' && event.shiftKey) {\n handleChangeViewMode?.();\n handleResetWip();\n }\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, []);\n\n const handleEnterInput = useCallback(\n (event: React.KeyboardEvent) => {\n if (event.key === 'Enter' && activeIndex != null && items[activeIndex]) {\n model._updateFilter(filterToUse!, inputType, items[activeIndex]);\n setInputValue('');\n setActiveIndex(0);\n\n if (inputType === 'key') {\n flushInputType('operator');\n } else if (inputType === 'operator') {\n flushInputType('value');\n } else if (inputType === 'value') {\n flushInputType('key');\n\n handleChangeViewMode?.();\n }\n\n refs.domReference.current?.focus();\n }\n },\n // eslint-disable-next-line react-hooks/exhaustive-deps\n [activeIndex, filterToUse, inputType, items, model]\n );\n\n useEffect(() => {\n if (open) {\n handleFetchOptions(inputType);\n }\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [open, inputType]);\n\n return (\n <div className={styles.comboboxWrapper}>\n {filterToUse ? (\n <div className={styles.pillWrapper}>\n {filterToUse?.key ? <div className={cx(styles.basePill, styles.keyPill)}>{filterToUse.key}</div> : null}\n {filterToUse?.key && filterToUse?.operator && inputType !== 'operator' ? (\n <div\n className={cx(styles.basePill, styles.operatorPill, operatorIdentifier)}\n role=\"button\"\n aria-label=\"Edit filter operator\"\n tabIndex={0}\n onClick={(event) => {\n event.stopPropagation();\n flushInputType('operator');\n\n refs.domReference.current?.focus();\n }}\n onKeyDown={(event) => {\n handleShiftTabInput(event);\n if (event.key === 'Enter') {\n flushInputType('operator');\n refs.domReference.current?.focus();\n }\n }}\n >\n {filterToUse.operator}\n </div>\n ) : null}\n {filterToUse?.key &&\n filterToUse?.operator &&\n filterToUse?.value &&\n !['operator', 'value'].includes(inputType) ? (\n <div className={cx(styles.basePill, styles.valuePill)}>{filterToUse.value}</div>\n ) : null}\n </div>\n ) : null}\n\n <input\n {...getReferenceProps({\n ref: refs.setReference,\n onChange,\n value: inputValue,\n // dynamic placeholder to display operator and/or value in filter edit mode\n placeholder: !wip\n ? inputType === 'operator'\n ? `${filterToUse![inputType]} ${filterToUse!.value || ''}`\n : filterToUse![inputType]\n : 'Filter by label values',\n 'aria-autocomplete': 'list',\n onKeyDown(event) {\n if (inputType === 'operator') {\n handleShiftTabInput(event);\n }\n handleBackspaceInput(event);\n handleTabInput(event);\n handleEnterInput(event);\n },\n })}\n className={styles.inputStyle}\n onClick={(event) => {\n event.stopPropagation();\n setOpen(true);\n }}\n onFocus={() => {\n setActiveIndex(0);\n setOpen(true);\n }}\n />\n <FloatingPortal>\n {open && (\n <FloatingFocusManager context={context} initialFocus={-1} visuallyHiddenDismiss>\n <div\n {...getFloatingProps({\n ref: refs.setFloating,\n style: {\n ...floatingStyles,\n overflowY: 'auto',\n },\n })}\n className={styles.dropdownWrapper}\n >\n {optionsLoading ? (\n <LoadingOptionsPlaceholder />\n ) : optionsError ? (\n <OptionsErrorPlaceholder handleFetchOptions={() => handleFetchOptions(inputType)} />\n ) : !items.length ? (\n <NoOptionsPlaceholder />\n ) : (\n items.map((item, index) => (\n // eslint-disable-next-line react/jsx-key\n <Item\n {...getItemProps({\n key: item.value!,\n ref(node) {\n listRef.current[index] = node;\n },\n onClick() {\n model._updateFilter(filterToUse!, inputType, item);\n setInputValue('');\n\n if (inputType === 'key') {\n flushInputType('operator');\n } else if (inputType === 'operator') {\n flushInputType('value');\n } else if (inputType === 'value') {\n flushInputType('key');\n handleChangeViewMode?.();\n }\n\n refs.domReference.current?.focus();\n },\n })}\n active={activeIndex === index}\n >\n {item.label ?? item.value}\n </Item>\n ))\n )}\n </div>\n </FloatingFocusManager>\n )}\n </FloatingPortal>\n </div>\n );\n});\n\nconst LoadingOptionsPlaceholder = () => {\n return <Item active={false}>Loading options...</Item>;\n};\n\nconst NoOptionsPlaceholder = () => {\n return <Item active={false}>No options found</Item>;\n};\n\nconst OptionsErrorPlaceholder = ({ handleFetchOptions }: { handleFetchOptions: () => void }) => {\n return (\n <Item active={false} onClick={handleFetchOptions}>\n Error. Click to try again!\n </Item>\n );\n};\n\nconst getStyles2 = (theme: GrafanaTheme2) => ({\n comboboxWrapper: css({\n display: 'flex',\n flexWrap: 'nowrap',\n }),\n pillWrapper: css({\n display: 'flex',\n alignItems: 'center',\n whiteSpace: 'nowrap',\n }),\n basePill: css({\n display: 'flex',\n alignItems: 'center',\n background: theme.colors.action.disabledBackground,\n border: `1px solid ${theme.colors.border.weak}`,\n padding: theme.spacing(0.125, 1, 0.125, 1),\n color: theme.colors.text.primary,\n overflow: 'hidden',\n whiteSpace: 'nowrap',\n minHeight: '22px',\n ...theme.typography.bodySmall,\n cursor: 'pointer',\n }),\n keyPill: css({\n fontWeight: theme.typography.fontWeightBold,\n cursor: 'default',\n }),\n operatorPill: css({\n '&:hover': {\n background: theme.colors.action.hover,\n },\n }),\n valuePill: css({\n background: theme.colors.action.selected,\n }),\n dropdownWrapper: css({\n backgroundColor: theme.colors.background.primary,\n color: theme.colors.text.primary,\n boxShadow: theme.shadows.z2,\n }),\n inputStyle: css({\n paddingBlock: 0,\n '&:focus': {\n outline: 'none',\n },\n }),\n});\n"],"names":["AdHocCombobox","_a","inputType","options"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA0BA,MAAM,IAAO,GAAA,UAAA;AAAA,EACX,CAAC,IAA+B,GAAQ,KAAA;AAAvC,IAAA,IAAA,EAAA,GAAA,EAAA,EAAE,YAAU,MA3Bf,EAAA,GA2BG,IAAuB,IAAvB,GAAA,SAAA,CAAA,EAAA,EAAuB,CAArB,UAAU,EAAA,QAAA,CAAA,CAAA,CAAA;AACX,IAAA,MAAM,QAAQ,SAAU,EAAA,CAAA;AACxB,IAAM,MAAA,YAAA,GAAe,gBAAgB,KAAK,CAAA,CAAA;AAC1C,IAAA,MAAM,KAAK,KAAM,EAAA,CAAA;AACjB,IAAA,uBACG,KAAA,CAAA,aAAA,CAAA,KAAA,EAAA,cAAA,CAAA;AAAA,MACC,GAAA;AAAA,MACA,IAAK,EAAA,QAAA;AAAA,MACL,EAAA;AAAA,MACA,eAAe,EAAA,MAAA;AAAA,MACf,WAAW,EAAG,CAAA,YAAA,CAAa,MAAQ,EAAA,MAAA,IAAU,aAAa,aAAa,CAAA;AAAA,KAAA,EACnE,uBAEH,KAAA,CAAA,aAAA,CAAA,KAAA,EAAA;AAAA,MAAI,WAAW,YAAa,CAAA,UAAA;AAAA,MAAY,e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AO,MAAO,CAAA,KAAA;AAAA,KAClC;AAAA,GACD,CAAA;AAAA,EACD,WAAW,GAAI,CAAA;AAAA,IACb,UAAA,EAAY,KAAM,CAAA,MAAA,CAAO,MAAO,CAAA,QAAA;AAAA,GACjC,CAAA;AAAA,EACD,iBAAiB,GAAI,CAAA;AAAA,IACnB,eAAA,EAAiB,KAAM,CAAA,MAAA,CAAO,UAAW,CAAA,OAAA;AAAA,IACzC,KAAA,EAAO,KAAM,CAAA,MAAA,CAAO,IAAK,CAAA,OAAA;AAAA,IACzB,SAAA,EAAW,MAAM,OAAQ,CAAA,EAAA;AAAA,GAC1B,CAAA;AAAA,EACD,YAAY,GAAI,CAAA;AAAA,IACd,YAAc,EAAA,CAAA;AAAA,IACd,SAAW,EAAA;AAAA,MACT,OAAS,EAAA,MAAA;AAAA,KACX;AAAA,GACD,CAAA;AACH,CAAA,CAAA;;;;"}
package/dist/index.js CHANGED
@@ -777,6 +777,7 @@ class SceneTimeRange extends SceneObjectBase {
777
777
  this.state.UNSAFE_nowDelay
778
778
  )
779
779
  });
780
+ this.publishEvent(new runtime.RefreshEvent());
780
781
  };
781
782
  this.addActivationHandler(this._onActivate.bind(this));
782
783
  }
@@ -3804,6 +3805,8 @@ const AdHocCombobox = React.forwardRef(function AdHocCombobox2({ filter, model,
3804
3805
  var _a;
3805
3806
  const [open, setOpen] = React.useState(false);
3806
3807
  const [options, setOptions] = React.useState([]);
3808
+ const [optionsLoading, setOptionsLoading] = React.useState(false);
3809
+ const [optionsError, setOptionsError] = React.useState(false);
3807
3810
  const [inputValue, setInputValue] = React.useState("");
3808
3811
  const [activeIndex, setActiveIndex] = React.useState(null);
3809
3812
  const [inputType, setInputType] = React.useState(!wip ? "value" : "key");
@@ -3925,22 +3928,33 @@ const AdHocCombobox = React.forwardRef(function AdHocCombobox2({ filter, model,
3925
3928
  refs.domReference.current.focus();
3926
3929
  }
3927
3930
  }, []);
3928
- const handleFetchOptions = React.useCallback(async () => {
3929
- let options2 = [];
3930
- if (inputType === "key") {
3931
- options2 = await model._getKeys(null);
3932
- } else if (inputType === "operator") {
3933
- options2 = model._getOperators();
3934
- } else if (inputType === "value") {
3935
- options2 = await model._getValuesFor(filterToUse);
3936
- }
3937
- setOptions(options2);
3938
- }, [filterToUse, inputType, model]);
3931
+ const handleFetchOptions = React.useCallback(
3932
+ async (inputType2) => {
3933
+ setOptionsError(false);
3934
+ setOptionsLoading(true);
3935
+ setOptions([]);
3936
+ let options2 = [];
3937
+ try {
3938
+ if (inputType2 === "key") {
3939
+ options2 = await model._getKeys(null);
3940
+ } else if (inputType2 === "operator") {
3941
+ options2 = model._getOperators();
3942
+ } else if (inputType2 === "value") {
3943
+ options2 = await model._getValuesFor(filterToUse);
3944
+ }
3945
+ setOptions(options2);
3946
+ } catch (e) {
3947
+ setOptionsError(true);
3948
+ }
3949
+ setOptionsLoading(false);
3950
+ },
3951
+ [filterToUse, model]
3952
+ );
3939
3953
  const handleBackspaceInput = React.useCallback(
3940
3954
  (event) => {
3941
3955
  if (event.key === "Backspace" && !inputValue && inputType === "key") {
3942
3956
  model._removeLastFilter();
3943
- setOpen(false);
3957
+ handleFetchOptions(inputType);
3944
3958
  }
3945
3959
  },
3946
3960
  [inputValue, inputType]
@@ -3963,6 +3977,7 @@ const AdHocCombobox = React.forwardRef(function AdHocCombobox2({ filter, model,
3963
3977
  if (event.key === "Enter" && activeIndex != null && items[activeIndex]) {
3964
3978
  model._updateFilter(filterToUse, inputType, items[activeIndex]);
3965
3979
  setInputValue("");
3980
+ setActiveIndex(0);
3966
3981
  if (inputType === "key") {
3967
3982
  flushInputType("operator");
3968
3983
  } else if (inputType === "operator") {
@@ -3978,7 +3993,7 @@ const AdHocCombobox = React.forwardRef(function AdHocCombobox2({ filter, model,
3978
3993
  );
3979
3994
  React.useEffect(() => {
3980
3995
  if (open) {
3981
- handleFetchOptions();
3996
+ handleFetchOptions(inputType);
3982
3997
  }
3983
3998
  }, [open, inputType]);
3984
3999
  return /* @__PURE__ */ React__default["default"].createElement("div", {
@@ -4043,7 +4058,9 @@ const AdHocCombobox = React.forwardRef(function AdHocCombobox2({ filter, model,
4043
4058
  })
4044
4059
  })), {
4045
4060
  className: styles.dropdownWrapper
4046
- }), items.map((item, index) => {
4061
+ }), optionsLoading ? /* @__PURE__ */ React__default["default"].createElement(LoadingOptionsPlaceholder, null) : optionsError ? /* @__PURE__ */ React__default["default"].createElement(OptionsErrorPlaceholder, {
4062
+ handleFetchOptions: () => handleFetchOptions(inputType)
4063
+ }) : !items.length ? /* @__PURE__ */ React__default["default"].createElement(NoOptionsPlaceholder, null) : items.map((item, index) => {
4047
4064
  var _a2;
4048
4065
  return /* @__PURE__ */ React__default["default"].createElement(Item, __spreadProps$o(__spreadValues$A({}, getItemProps({
4049
4066
  key: item.value,
@@ -4069,6 +4086,22 @@ const AdHocCombobox = React.forwardRef(function AdHocCombobox2({ filter, model,
4069
4086
  }), (_a2 = item.label) != null ? _a2 : item.value);
4070
4087
  })))));
4071
4088
  });
4089
+ const LoadingOptionsPlaceholder = () => {
4090
+ return /* @__PURE__ */ React__default["default"].createElement(Item, {
4091
+ active: false
4092
+ }, "Loading options...");
4093
+ };
4094
+ const NoOptionsPlaceholder = () => {
4095
+ return /* @__PURE__ */ React__default["default"].createElement(Item, {
4096
+ active: false
4097
+ }, "No options found");
4098
+ };
4099
+ const OptionsErrorPlaceholder = ({ handleFetchOptions }) => {
4100
+ return /* @__PURE__ */ React__default["default"].createElement(Item, {
4101
+ active: false,
4102
+ onClick: handleFetchOptions
4103
+ }, "Error. Click to try again!");
4104
+ };
4072
4105
  const getStyles2 = (theme) => ({
4073
4106
  comboboxWrapper: css.css({
4074
4107
  display: "flex",