@grafana/scenes 5.23.0--canary.954.11668840775.0 → 5.23.1--canary.955.11689118589.0
Sign up to get free protection for your applications and to get access to all the features.
- package/CHANGELOG.md +24 -0
- package/dist/esm/core/SceneTimeRange.js +1 -4
- package/dist/esm/core/SceneTimeRange.js.map +1 -1
- package/dist/esm/variables/adhoc/AdHocFiltersCombobox/AdHocFilterPill.js +14 -2
- package/dist/esm/variables/adhoc/AdHocFiltersCombobox/AdHocFilterPill.js.map +1 -1
- package/dist/esm/variables/adhoc/AdHocFiltersCombobox/AdHocFiltersCombobox.js +46 -58
- package/dist/esm/variables/adhoc/AdHocFiltersCombobox/AdHocFiltersCombobox.js.map +1 -1
- package/dist/esm/variables/adhoc/AdHocFiltersCombobox/MultiValuePill.js +114 -0
- package/dist/esm/variables/adhoc/AdHocFiltersCombobox/MultiValuePill.js.map +1 -0
- package/dist/esm/variables/adhoc/AdHocFiltersCombobox/utils.js +14 -1
- package/dist/esm/variables/adhoc/AdHocFiltersCombobox/utils.js.map +1 -1
- package/dist/esm/variables/macros/timeMacros.js +3 -0
- package/dist/esm/variables/macros/timeMacros.js.map +1 -1
- package/dist/index.js +406 -286
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
@@ -1,3 +1,27 @@
|
|
1
|
+
# v5.23.0 (Tue Nov 05 2024)
|
2
|
+
|
3
|
+
#### 🚀 Enhancement
|
4
|
+
|
5
|
+
- VizPanel: Adjust forceRender logic [#954](https://github.com/grafana/scenes/pull/954) ([@kaydelaney](https://github.com/kaydelaney))
|
6
|
+
|
7
|
+
#### Authors: 1
|
8
|
+
|
9
|
+
- kay delaney ([@kaydelaney](https://github.com/kaydelaney))
|
10
|
+
|
11
|
+
---
|
12
|
+
|
13
|
+
# v5.22.2 (Tue Nov 05 2024)
|
14
|
+
|
15
|
+
#### 🐛 Bug Fix
|
16
|
+
|
17
|
+
- SceneTimeRange: Fix passing timezone URL parameter [#947](https://github.com/grafana/scenes/pull/947) ([@bfmatei](https://github.com/bfmatei))
|
18
|
+
|
19
|
+
#### Authors: 1
|
20
|
+
|
21
|
+
- Bogdan Matei ([@bfmatei](https://github.com/bfmatei))
|
22
|
+
|
23
|
+
---
|
24
|
+
|
1
25
|
# v5.22.1 (Mon Nov 04 2024)
|
2
26
|
|
3
27
|
#### 🐛 Bug Fix
|
@@ -168,10 +168,7 @@ class SceneTimeRange extends SceneObjectBase {
|
|
168
168
|
}
|
169
169
|
getUrlState() {
|
170
170
|
const params = locationService.getSearchObject();
|
171
|
-
const urlValues = { from: this.state.from, to: this.state.to };
|
172
|
-
if (this.state.timeZone) {
|
173
|
-
urlValues.timezone = this.state.timeZone;
|
174
|
-
}
|
171
|
+
const urlValues = { from: this.state.from, to: this.state.to, timezone: this.getTimeZone() };
|
175
172
|
if (params.time && params["time.window"]) {
|
176
173
|
urlValues.time = null;
|
177
174
|
urlValues["time.window"] = null;
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"SceneTimeRange.js","sources":["../../../src/core/SceneTimeRange.tsx"],"sourcesContent":["import { getTimeZone, rangeUtil, TimeRange, toUtc } 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 { locationService, RefreshEvent } from '@grafana/runtime';\nimport { isValid } from '../utils/date';\n\nexport class SceneTimeRange extends SceneObjectBase<SceneTimeRangeState> implements SceneTimeRangeLike {\n protected _urlSync = new SceneObjectUrlSyncConfig(this, { keys: ['from', 'to', 'timezone', 'time', 'time.window'] });\n\n public constructor(state: Partial<SceneTimeRangeState> = {}) {\n const from = state.from && isValid(state.from) ? state.from : 'now-6h';\n const to = state.to && isValid(state.to) ? state.to : 'now';\n\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 const refreshOnActivate = state.refreshOnActivate ?? { percent: 10 };\n super({ from, to, timeZone, value, refreshOnActivate, ...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 (rangeUtil.isRelativeTimeRange(this.state.value.raw)) {\n this.refreshIfStale();\n }\n }\n\n private refreshIfStale() {\n let ms;\n if (this.state?.refreshOnActivate?.percent !== undefined) {\n ms = this.calculatePercentOfInterval(this.state.refreshOnActivate.percent);\n }\n if (this.state?.refreshOnActivate?.afterMs !== undefined) {\n ms = Math.min(this.state.refreshOnActivate.afterMs, ms ?? Infinity);\n }\n if (ms !== undefined) {\n this.refreshRange(ms);\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 /**\n * Refreshes time range if it is older than the invalidation interval\n * @param refreshAfterMs invalidation interval (milliseconds)\n * @private\n */\n private refreshRange(refreshAfterMs: number) {\n const value = evaluateTimeRange(\n this.state.from,\n this.state.to,\n this.state.timeZone ?? getTimeZone(),\n this.state.fiscalYearStartMonth,\n this.state.UNSAFE_nowDelay\n );\n\n const diff = value.to.diff(this.state.value.to, 'milliseconds');\n if (diff >= refreshAfterMs) {\n this.setState({\n value,\n });\n }\n }\n\n private calculatePercentOfInterval(percent: number): number {\n const intervalMs = this.state.value.to.diff(this.state.value.from, 'milliseconds');\n return Math.ceil(intervalMs / percent);\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\n if (typeof timeRange.raw.from === 'string') {\n update.from = timeRange.raw.from;\n } else {\n update.from = timeRange.raw.from.toISOString();\n }\n\n if (typeof timeRange.raw.to === 'string') {\n update.to = timeRange.raw.to;\n } else {\n update.to = timeRange.raw.to.toISOString();\n }\n\n update.value = evaluateTimeRange(\n update.from,\n update.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._urlSync.performBrowserHistoryAction(() => {\n this.setState(update);\n });\n }\n };\n\n public onTimeZoneChange = (timeZone: TimeZone) => {\n this._urlSync.performBrowserHistoryAction(() => {\n this.setState({ timeZone });\n });\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(), true);\n };\n\n public getUrlState() {\n const params = locationService.getSearchObject();\n const urlValues: SceneObjectUrlValues = { from: this.state.from, to: this.state.to };\n\n if (this.state.timeZone) {\n urlValues.timezone = this.state.timeZone;\n }\n\n // Clear time and time.window once they are converted to from and to\n if (params.time && params['time.window']) {\n urlValues.time = null;\n urlValues['time.window'] = null;\n }\n\n return urlValues;\n }\n\n public updateFromUrl(values: SceneObjectUrlValues) {\n const update: Partial<SceneTimeRangeState> = {};\n\n let from = parseUrlParam(values.from);\n let to = parseUrlParam(values.to);\n\n if (values.time && values['time.window']) {\n const time = Array.isArray(values.time) ? values.time[0] : values.time;\n const timeWindow = Array.isArray(values['time.window']) ? values['time.window'][0] : values['time.window'];\n const timeRange = getTimeWindow(time, timeWindow);\n if (timeRange.from && isValid(timeRange.from)) {\n from = timeRange.from;\n }\n\n if (timeRange.to && isValid(timeRange.to)) {\n to = timeRange.to;\n }\n }\n\n if (from && isValid(from)) {\n update.from = from;\n }\n\n if (to && isValid(to)) {\n update.to = to;\n }\n\n if (typeof values.timezone === 'string') {\n update.timeZone = values.timezone !== '' ? values.timezone : undefined;\n }\n\n if (Object.keys(update).length === 0) {\n return;\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 return this.setState(update);\n }\n}\n\n/**\n * Calculates the duration of the time range from time-time.window/2 to time+time.window/2. Both be specified in ms. For example ?time=1500000000000&time.window=10000 results in a 10-second time range from 1499999995000 to 1500000005000`.\n * @param time - time in ms\n * @param timeWindow - time window in ms or interval string\n */\nfunction getTimeWindow(time: string, timeWindow: string) {\n // Parse the time, assuming it could be an ISO string or a number in milliseconds\n const valueTime = isNaN(Date.parse(time)) ? parseInt(time, 10) : Date.parse(time);\n\n let timeWindowMs;\n\n if (timeWindow.match(/^\\d+$/) && parseInt(timeWindow, 10)) {\n // when time window is specified in ms\n timeWindowMs = parseInt(timeWindow, 10);\n } else {\n timeWindowMs = rangeUtil.intervalToMs(timeWindow);\n }\n\n return {\n from: toUtc(valueTime - time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imeRange.js","sources":["../../../src/core/SceneTimeRange.tsx"],"sourcesContent":["import { getTimeZone, rangeUtil, TimeRange, toUtc } 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 { locationService, RefreshEvent } from '@grafana/runtime';\nimport { isValid } from '../utils/date';\n\nexport class SceneTimeRange extends SceneObjectBase<SceneTimeRangeState> implements SceneTimeRangeLike {\n protected _urlSync = new SceneObjectUrlSyncConfig(this, { keys: ['from', 'to', 'timezone', 'time', 'time.window'] });\n\n public constructor(state: Partial<SceneTimeRangeState> = {}) {\n const from = state.from && isValid(state.from) ? state.from : 'now-6h';\n const to = state.to && isValid(state.to) ? state.to : 'now';\n\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 const refreshOnActivate = state.refreshOnActivate ?? { percent: 10 };\n super({ from, to, timeZone, value, refreshOnActivate, ...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 (rangeUtil.isRelativeTimeRange(this.state.value.raw)) {\n this.refreshIfStale();\n }\n }\n\n private refreshIfStale() {\n let ms;\n if (this.state?.refreshOnActivate?.percent !== undefined) {\n ms = this.calculatePercentOfInterval(this.state.refreshOnActivate.percent);\n }\n if (this.state?.refreshOnActivate?.afterMs !== undefined) {\n ms = Math.min(this.state.refreshOnActivate.afterMs, ms ?? Infinity);\n }\n if (ms !== undefined) {\n this.refreshRange(ms);\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 /**\n * Refreshes time range if it is older than the invalidation interval\n * @param refreshAfterMs invalidation interval (milliseconds)\n * @private\n */\n private refreshRange(refreshAfterMs: number) {\n const value = evaluateTimeRange(\n this.state.from,\n this.state.to,\n this.state.timeZone ?? getTimeZone(),\n this.state.fiscalYearStartMonth,\n this.state.UNSAFE_nowDelay\n );\n\n const diff = value.to.diff(this.state.value.to, 'milliseconds');\n if (diff >= refreshAfterMs) {\n this.setState({\n value,\n });\n }\n }\n\n private calculatePercentOfInterval(percent: number): number {\n const intervalMs = this.state.value.to.diff(this.state.value.from, 'milliseconds');\n return Math.ceil(intervalMs / percent);\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\n if (typeof timeRange.raw.from === 'string') {\n update.from = timeRange.raw.from;\n } else {\n update.from = timeRange.raw.from.toISOString();\n }\n\n if (typeof timeRange.raw.to === 'string') {\n update.to = timeRange.raw.to;\n } else {\n update.to = timeRange.raw.to.toISOString();\n }\n\n update.value = evaluateTimeRange(\n update.from,\n update.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._urlSync.performBrowserHistoryAction(() => {\n this.setState(update);\n });\n }\n };\n\n public onTimeZoneChange = (timeZone: TimeZone) => {\n this._urlSync.performBrowserHistoryAction(() => {\n this.setState({ timeZone });\n });\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(), true);\n };\n\n public getUrlState() {\n const params = locationService.getSearchObject();\n const urlValues: SceneObjectUrlValues = { from: this.state.from, to: this.state.to, timezone: this.getTimeZone() };\n\n // Clear time and time.window once they are converted to from and to\n if (params.time && params['time.window']) {\n urlValues.time = null;\n urlValues['time.window'] = null;\n }\n\n return urlValues;\n }\n\n public updateFromUrl(values: SceneObjectUrlValues) {\n const update: Partial<SceneTimeRangeState> = {};\n\n let from = parseUrlParam(values.from);\n let to = parseUrlParam(values.to);\n\n if (values.time && values['time.window']) {\n const time = Array.isArray(values.time) ? values.time[0] : values.time;\n const timeWindow = Array.isArray(values['time.window']) ? values['time.window'][0] : values['time.window'];\n const timeRange = getTimeWindow(time, timeWindow);\n if (timeRange.from && isValid(timeRange.from)) {\n from = timeRange.from;\n }\n\n if (timeRange.to && isValid(timeRange.to)) {\n to = timeRange.to;\n }\n }\n\n if (from && isValid(from)) {\n update.from = from;\n }\n\n if (to && isValid(to)) {\n update.to = to;\n }\n\n if (typeof values.timezone === 'string') {\n update.timeZone = values.timezone !== '' ? values.timezone : undefined;\n }\n\n if (Object.keys(update).length === 0) {\n return;\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 return this.setState(update);\n }\n}\n\n/**\n * Calculates the duration of the time range from time-time.window/2 to time+time.window/2. Both be specified in ms. For example ?time=1500000000000&time.window=10000 results in a 10-second time range from 1499999995000 to 1500000005000`.\n * @param time - time in ms\n * @param timeWindow - time window in ms or interval string\n */\nfunction getTimeWindow(time: string, timeWindow: string) {\n // Parse the time, assuming it could be an ISO string or a number in milliseconds\n const valueTime = isNaN(Date.parse(time)) ? parseInt(time, 10) : Date.parse(time);\n\n let timeWindowMs;\n\n if (timeWindow.match(/^\\d+$/) && parseInt(timeWindow, 10)) {\n // when time window is specified in ms\n timeWindowMs = parseInt(timeWindow, 10);\n } else {\n timeWindowMs = rangeUtil.intervalToMs(timeWindow);\n }\n\n return {\n from: toUtc(valueTime - timeWindowMs / 2).toISOString(),\n to: toUtc(valueTime + timeWindowMs / 2).toISOString(),\n };\n}\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAaO,MAAM,uBAAuB,eAAmE,CAAA;AAAA,EAG9F,WAAA,CAAY,KAAsC,GAAA,EAAI,EAAA;AAhB/D,IAAA,IAAA,EAAA,CAAA;AAiBI,IAAM,MAAA,IAAA,GAAO,MAAM,IAAQ,IAAA,OAAA,CAAQ,MAAM,IAAI,CAAA,GAAI,MAAM,IAAO,GAAA,QAAA,CAAA;AAC9D,IAAM,MAAA,EAAA,GAAK,MAAM,EAAM,IAAA,OAAA,CAAQ,MAAM,EAAE,CAAA,GAAI,MAAM,EAAK,GAAA,KAAA,CAAA;AAEtD,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,KA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IAAI,CAAA,CAAA;AAEhF,EAAI,IAAA,YAAA,CAAA;AAEJ,EAAA,IAAI,WAAW,KAAM,CAAA,OAAO,KAAK,QAAS,CAAA,UAAA,EAAY,EAAE,CAAG,EAAA;AAEzD,IAAe,YAAA,GAAA,QAAA,CAAS,YAAY,EAAE,CAAA,CAAA;AAAA,GACjC,MAAA;AACL,IAAe,YAAA,GAAA,SAAA,CAAU,aAAa,UAAU,CAAA,CAAA;AAAA,GAClD;AAEA,EAAO,OAAA;AAAA,IACL,MAAM,KAAM,CAAA,SAAA,GAAY,YAAe,GAAA,CAAC,EAAE,WAAY,EAAA;AAAA,IACtD,IAAI,KAAM,CAAA,SAAA,GAAY,YAAe,GAAA,CAAC,EAAE,WAAY,EAAA;AAAA,GACtD,CAAA;AACF;;;;"}
|
@@ -28,6 +28,7 @@ function AdHocFilterPill({ filter, model, readOnly, focusOnWipInputRef }) {
|
|
28
28
|
const [viewMode, setViewMode] = useState(true);
|
29
29
|
const [shouldFocusOnPillWrapper, setShouldFocusOnPillWrapper] = useState(false);
|
30
30
|
const pillWrapperRef = useRef(null);
|
31
|
+
const [populateInputOnEdit, setPopulateInputOnEdit] = useState(false);
|
31
32
|
const keyLabel = (_a = filter.keyLabel) != null ? _a : filter.key;
|
32
33
|
const valueLabel = ((_b = filter.valueLabels) == null ? void 0 : _b.join(", ")) || ((_c = filter.values) == null ? void 0 : _c.join(", ")) || filter.value;
|
33
34
|
const handleChangeViewMode = useCallback(
|
@@ -54,15 +55,25 @@ function AdHocFilterPill({ filter, model, readOnly, focusOnWipInputRef }) {
|
|
54
55
|
model._updateFilter(filter, { forceEdit: void 0 });
|
55
56
|
}
|
56
57
|
}, [filter, model, viewMode]);
|
58
|
+
useEffect(() => {
|
59
|
+
if (populateInputOnEdit && viewMode) {
|
60
|
+
setPopulateInputOnEdit(false);
|
61
|
+
}
|
62
|
+
}, [viewMode]);
|
57
63
|
if (viewMode) {
|
58
64
|
const pillText = /* @__PURE__ */ React.createElement("span", {
|
59
65
|
className: styles.pillText
|
60
66
|
}, keyLabel, " ", filter.operator, " ", valueLabel);
|
61
67
|
return /* @__PURE__ */ React.createElement("div", {
|
62
68
|
className: cx(styles.combinedFilterPill, { [styles.readOnlyCombinedFilter]: readOnly }),
|
63
|
-
onClick:
|
69
|
+
onClick: (e) => {
|
70
|
+
e.stopPropagation();
|
71
|
+
setPopulateInputOnEdit(true);
|
72
|
+
handleChangeViewMode();
|
73
|
+
},
|
64
74
|
onKeyDown: (e) => {
|
65
75
|
if (e.key === "Enter") {
|
76
|
+
setPopulateInputOnEdit(true);
|
66
77
|
handleChangeViewMode();
|
67
78
|
}
|
68
79
|
},
|
@@ -99,7 +110,8 @@ function AdHocFilterPill({ filter, model, readOnly, focusOnWipInputRef }) {
|
|
99
110
|
filter,
|
100
111
|
model,
|
101
112
|
handleChangeViewMode,
|
102
|
-
focusOnWipInputRef
|
113
|
+
focusOnWipInputRef,
|
114
|
+
populateInputOnEdit
|
103
115
|
});
|
104
116
|
}
|
105
117
|
const getStyles = (theme) => ({
|
@@ -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, Tooltip } 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 focusOnWipInputRef?: () => void;\n}\n\nexport function AdHocFilterPill({ filter, model, readOnly, focusOnWipInputRef }: Props) {\n const styles = useStyles2(getStyles);\n const [viewMode, setViewMode] = useState(true);\n const [shouldFocusOnPillWrapper, setShouldFocusOnPillWrapper] = useState(false);\n const pillWrapperRef = useRef<HTMLDivElement>(null);\n\n const keyLabel = filter.keyLabel ?? filter.key;\n // TODO remove when we're on the latest version of @grafana/data\n //@ts-expect-error\n const valueLabel = filter.valueLabels?.join(', ') || filter.values?.join(', ') || filter.value;\n\n const handleChangeViewMode = useCallback(\n (event?: React.MouseEvent, shouldFocusOnPillWrapperOverride?: boolean) => {\n event?.stopPropagation();\n if (readOnly) {\n return;\n }\n\n setShouldFocusOnPillWrapper(shouldFocusOnPillWrapperOverride ?? !viewMode);\n setViewMode(!viewMode);\n },\n [readOnly, viewMode]\n );\n\n useEffect(() => {\n if (shouldFocusOnPillWrapper) {\n pillWrapperRef.current?.focus();\n setShouldFocusOnPillWrapper(false);\n }\n }, [shouldFocusOnPillWrapper]);\n\n // set viewMode to false when filter.forceEdit is defined\n useEffect(() => {\n if (filter.forceEdit && viewMode) {\n setViewMode(false);\n // immediately set forceEdit back to undefined as a clean up\n model._updateFilter(filter, { forceEdit: undefined });\n }\n }, [filter, model, viewMode]);\n\n if (viewMode) {\n const pillText = (\n <span className={styles.pillText}>\n {keyLabel} {filter.operator} {valueLabel}\n </span>\n );\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 {valueLabel.length < 20 ? (\n pillText\n ) : (\n <Tooltip content={<div className={styles.tooltipText}>{valueLabel}</div>} placement=\"top\">\n {pillText}\n </Tooltip>\n )}\n\n {!readOnly ? (\n <IconButton\n onClick={(e) => {\n e.stopPropagation();\n model._removeFilter(filter);\n setTimeout(() => focusOnWipInputRef?.());\n }}\n onKeyDownCapture={(e) => {\n if (e.key === 'Enter') {\n e.preventDefault();\n e.stopPropagation();\n model._removeFilter(filter);\n setTimeout(() => focusOnWipInputRef?.());\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 (\n <AdHocCombobox\n filter={filter}\n model={model}\n handleChangeViewMode={handleChangeViewMode}\n focusOnWipInputRef={focusOnWipInputRef}\n />\n );\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 maxWidth: '200px',\n width: '100%',\n textOverflow: 'ellipsis',\n overflow: 'hidden',\n }),\n tooltipText: css({\n textAlign: 'center',\n }),\n});\n"],"names":["_a"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AAcO,SAAS,gBAAgB,EAAE,MAAA,EAAQ,KAAO,EAAA,QAAA,EAAU,oBAA6B,EAAA;AAdxF,EAAA,IAAA,EAAA,EAAA,EAAA,EAAA,EAAA,CAAA;AAeE,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,wBAAA,EAA0B,2BAA2B,CAAA,GAAI,SAAS,KAAK,CAAA,CAAA;AAC9E,EA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ACD,UAAU,GAAI,CAAA;AAAA,IACZ,QAAU,EAAA,OAAA;AAAA,IACV,KAAO,EAAA,MAAA;AAAA,IACP,YAAc,EAAA,UAAA;AAAA,IACd,QAAU,EAAA,QAAA;AAAA,GACX,CAAA;AAAA,EACD,aAAa,GAAI,CAAA;AAAA,IACf,SAAW,EAAA,QAAA;AAAA,GACZ,CAAA;AACH,CAAA,CAAA;;;;"}
|
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, Tooltip } 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 focusOnWipInputRef?: () => void;\n}\n\nexport function AdHocFilterPill({ filter, model, readOnly, focusOnWipInputRef }: Props) {\n const styles = useStyles2(getStyles);\n const [viewMode, setViewMode] = useState(true);\n const [shouldFocusOnPillWrapper, setShouldFocusOnPillWrapper] = useState(false);\n const pillWrapperRef = useRef<HTMLDivElement>(null);\n const [populateInputOnEdit, setPopulateInputOnEdit] = useState(false);\n\n const keyLabel = filter.keyLabel ?? filter.key;\n // TODO remove when we're on the latest version of @grafana/data\n //@ts-expect-error\n const valueLabel = filter.valueLabels?.join(', ') || filter.values?.join(', ') || filter.value;\n\n const handleChangeViewMode = useCallback(\n (event?: React.MouseEvent, shouldFocusOnPillWrapperOverride?: boolean) => {\n event?.stopPropagation();\n if (readOnly) {\n return;\n }\n\n setShouldFocusOnPillWrapper(shouldFocusOnPillWrapperOverride ?? !viewMode);\n setViewMode(!viewMode);\n },\n [readOnly, viewMode]\n );\n\n useEffect(() => {\n if (shouldFocusOnPillWrapper) {\n pillWrapperRef.current?.focus();\n setShouldFocusOnPillWrapper(false);\n }\n }, [shouldFocusOnPillWrapper]);\n\n // set viewMode to false when filter.forceEdit is defined\n useEffect(() => {\n if (filter.forceEdit && viewMode) {\n setViewMode(false);\n // immediately set forceEdit back to undefined as a clean up\n model._updateFilter(filter, { forceEdit: undefined });\n }\n }, [filter, model, viewMode]);\n\n // reset populateInputOnEdit when pill goes into view mode\n useEffect(() => {\n if (populateInputOnEdit && viewMode) {\n setPopulateInputOnEdit(false);\n }\n // excluding populateInputOnEdit dependency because we only care to reset it on viewMode change\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [viewMode]);\n\n if (viewMode) {\n const pillText = (\n <span className={styles.pillText}>\n {keyLabel} {filter.operator} {valueLabel}\n </span>\n );\n return (\n <div\n className={cx(styles.combinedFilterPill, { [styles.readOnlyCombinedFilter]: readOnly })}\n onClick={(e) => {\n e.stopPropagation();\n setPopulateInputOnEdit(true);\n handleChangeViewMode();\n }}\n onKeyDown={(e) => {\n if (e.key === 'Enter') {\n setPopulateInputOnEdit(true);\n handleChangeViewMode();\n }\n }}\n role=\"button\"\n aria-label={`Edit filter with key ${keyLabel}`}\n tabIndex={0}\n ref={pillWrapperRef}\n >\n {valueLabel.length < 20 ? (\n pillText\n ) : (\n <Tooltip content={<div className={styles.tooltipText}>{valueLabel}</div>} placement=\"top\">\n {pillText}\n </Tooltip>\n )}\n\n {!readOnly ? (\n <IconButton\n onClick={(e) => {\n e.stopPropagation();\n model._removeFilter(filter);\n setTimeout(() => focusOnWipInputRef?.());\n }}\n onKeyDownCapture={(e) => {\n if (e.key === 'Enter') {\n e.preventDefault();\n e.stopPropagation();\n model._removeFilter(filter);\n setTimeout(() => focusOnWipInputRef?.());\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 (\n <AdHocCombobox\n filter={filter}\n model={model}\n handleChangeViewMode={handleChangeViewMode}\n focusOnWipInputRef={focusOnWipInputRef}\n populateInputOnEdit={populateInputOnEdit}\n />\n );\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 maxWidth: '200px',\n width: '100%',\n textOverflow: 'ellipsis',\n overflow: 'hidden',\n }),\n tooltipText: css({\n textAlign: 'center',\n }),\n});\n"],"names":["_a"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AAcO,SAAS,gBAAgB,EAAE,MAAA,EAAQ,KAAO,EAAA,QAAA,EAAU,oBAA6B,EAAA;AAdxF,EAAA,IAAA,EAAA,EAAA,EAAA,EAAA,EAAA,CAAA;AAeE,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,wBAAA,EAA0B,2BAA2B,CAAA,GAAI,SAAS,KAAK,CAAA,CAAA;AAC9E,EAAM,MAAA,cAAA,GAAiB,OAAuB,IAAI,CAAA,CAAA;AAClD,EAAA,MAAM,CAAC,mBAAA,EAAqB,sBAAsB,CAAA,GA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AA,IACR,SAAW,EAAA;AAAA,MACT,UAAA,EAAY,KAAM,CAAA,MAAA,CAAO,MAAO,CAAA,QAAA;AAAA,KAClC;AAAA,GACD,CAAA;AAAA,EACD,cAAc,GAAI,CAAA;AAAA,IAChB,YAAA,EAAc,KAAM,CAAA,OAAA,CAAQ,GAAG,CAAA;AAAA,IAC/B,MAAQ,EAAA,SAAA;AAAA,IACR,SAAW,EAAA;AAAA,MACT,KAAA,EAAO,KAAM,CAAA,MAAA,CAAO,IAAK,CAAA,OAAA;AAAA,KAC3B;AAAA,GACD,CAAA;AAAA,EACD,UAAU,GAAI,CAAA;AAAA,IACZ,QAAU,EAAA,OAAA;AAAA,IACV,KAAO,EAAA,MAAA;AAAA,IACP,YAAc,EAAA,UAAA;AAAA,IACd,QAAU,EAAA,QAAA;AAAA,GACX,CAAA;AAAA,EACD,aAAa,GAAI,CAAA;AAAA,IACf,SAAW,EAAA,QAAA;AAAA,GACZ,CAAA;AACH,CAAA,CAAA;;;;"}
|
@@ -1,13 +1,14 @@
|
|
1
1
|
import React, { forwardRef, useState, useRef, useId, useMemo, useCallback, useImperativeHandle, useEffect, useLayoutEffect } from 'react';
|
2
2
|
import { FloatingPortal, FloatingFocusManager } from '@floating-ui/react';
|
3
|
-
import { useStyles2, Spinner, Text
|
3
|
+
import { useStyles2, Spinner, Text } from '@grafana/ui';
|
4
4
|
import { cx, css } from '@emotion/css';
|
5
5
|
import { isMultiValueOperator } from '../AdHocFiltersVariable.js';
|
6
6
|
import { useVirtualizer } from '@tanstack/react-virtual';
|
7
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, generatePlaceholder, ERROR_STATE_DROPDOWN_WIDTH } from './utils.js';
|
8
|
+
import { fuzzySearchOptions, flattenOptionGroups, setupDropdownAccessibility, VIRTUAL_LIST_ITEM_HEIGHT_WITH_DESCRIPTION, VIRTUAL_LIST_ITEM_HEIGHT, VIRTUAL_LIST_OVERSCAN, generateFilterUpdatePayload, populateInputValueOnInputTypeSwitch, switchToNextInputType, switchInputType, generatePlaceholder, ERROR_STATE_DROPDOWN_WIDTH } from './utils.js';
|
9
9
|
import { handleOptionGroups } from '../../utils.js';
|
10
10
|
import { useFloatingInteractions, MAX_MENU_HEIGHT } from './useFloatingInteractions.js';
|
11
|
+
import { MultiValuePill } from './MultiValuePill.js';
|
11
12
|
|
12
13
|
var __defProp = Object.defineProperty;
|
13
14
|
var __defProps = Object.defineProperties;
|
@@ -28,7 +29,7 @@ var __spreadValues = (a, b) => {
|
|
28
29
|
return a;
|
29
30
|
};
|
30
31
|
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
31
|
-
const AdHocCombobox = forwardRef(function AdHocCombobox2({ filter, model, isAlwaysWip, handleChangeViewMode, focusOnWipInputRef }, parentRef) {
|
32
|
+
const AdHocCombobox = forwardRef(function AdHocCombobox2({ filter, model, isAlwaysWip, handleChangeViewMode, focusOnWipInputRef, populateInputOnEdit }, parentRef) {
|
32
33
|
var _a, _b, _c;
|
33
34
|
const [open, setOpen] = useState(false);
|
34
35
|
const [options, setOptions] = useState([]);
|
@@ -115,7 +116,13 @@ const AdHocCombobox = forwardRef(function AdHocCombobox2({ filter, model, isAlwa
|
|
115
116
|
]
|
116
117
|
);
|
117
118
|
const outsidePressIdsToIgnore = useMemo(() => {
|
118
|
-
return [
|
119
|
+
return [
|
120
|
+
operatorIdentifier,
|
121
|
+
...filterMultiValues.reduce(
|
122
|
+
(acc, item, i) => [...acc, `${item.value}-${i}`, `${item.value}-${i}-close-icon`],
|
123
|
+
[]
|
124
|
+
)
|
125
|
+
];
|
119
126
|
}, [operatorIdentifier, filterMultiValues]);
|
120
127
|
const { refs, floatingStyles, context, getReferenceProps, getFloatingProps, getItemProps } = useFloatingInteractions({
|
121
128
|
open,
|
@@ -268,6 +275,7 @@ const AdHocCombobox = forwardRef(function AdHocCombobox2({ filter, model, isAlwa
|
|
268
275
|
const selectedItem = filteredDropDownItems[activeIndex];
|
269
276
|
if (multiValueEdit) {
|
270
277
|
handleLocalMultiValueChange(selectedItem);
|
278
|
+
setInputValue("");
|
271
279
|
} else {
|
272
280
|
model._updateFilter(
|
273
281
|
filter,
|
@@ -278,6 +286,13 @@ const AdHocCombobox = forwardRef(function AdHocCombobox2({ filter, model, isAlwa
|
|
278
286
|
setFilterMultiValues
|
279
287
|
})
|
280
288
|
);
|
289
|
+
populateInputValueOnInputTypeSwitch({
|
290
|
+
populateInputOnEdit,
|
291
|
+
item: selectedItem,
|
292
|
+
filterInputType,
|
293
|
+
setInputValue,
|
294
|
+
filter
|
295
|
+
});
|
281
296
|
switchToNextInputType(
|
282
297
|
filterInputType,
|
283
298
|
setInputType,
|
@@ -290,7 +305,6 @@ const AdHocCombobox = forwardRef(function AdHocCombobox2({ filter, model, isAlwa
|
|
290
305
|
focusOnWipInputRef == null ? void 0 : focusOnWipInputRef();
|
291
306
|
}
|
292
307
|
}
|
293
|
-
setInputValue("");
|
294
308
|
}
|
295
309
|
},
|
296
310
|
[
|
@@ -300,12 +314,23 @@ const AdHocCombobox = forwardRef(function AdHocCombobox2({ filter, model, isAlwa
|
|
300
314
|
model,
|
301
315
|
filter,
|
302
316
|
filterInputType,
|
317
|
+
populateInputOnEdit,
|
303
318
|
handleChangeViewMode,
|
304
319
|
refs.domReference,
|
305
320
|
isLastFilter,
|
306
321
|
focusOnWipInputRef
|
307
322
|
]
|
308
323
|
);
|
324
|
+
const handleEditMultiValuePill = useCallback(
|
325
|
+
(value) => {
|
326
|
+
var _a2;
|
327
|
+
const valueLabel = value.label || value.value;
|
328
|
+
setFilterMultiValues((prev) => prev.filter((item) => item.value !== value.value));
|
329
|
+
setInputValue(valueLabel);
|
330
|
+
(_a2 = refs.domReference.current) == null ? void 0 : _a2.focus();
|
331
|
+
},
|
332
|
+
[refs.domReference]
|
333
|
+
);
|
309
334
|
useEffect(() => {
|
310
335
|
if (open) {
|
311
336
|
handleFetchOptions(filterInputType);
|
@@ -314,8 +339,6 @@ const AdHocCombobox = forwardRef(function AdHocCombobox2({ filter, model, isAlwa
|
|
314
339
|
useEffect(() => {
|
315
340
|
var _a2, _b2;
|
316
341
|
if (!isAlwaysWip) {
|
317
|
-
setInputType("value");
|
318
|
-
setInputValue("");
|
319
342
|
if (hasMultiValueOperator && ((_a2 = filter == null ? void 0 : filter.values) == null ? void 0 : _a2.length)) {
|
320
343
|
const multiValueOptions = filter.values.reduce(
|
321
344
|
(acc, value, i) => {
|
@@ -332,6 +355,9 @@ const AdHocCombobox = forwardRef(function AdHocCombobox2({ filter, model, isAlwa
|
|
332
355
|
);
|
333
356
|
setFilterMultiValues(multiValueOptions);
|
334
357
|
}
|
358
|
+
if (!hasMultiValueOperator && populateInputOnEdit) {
|
359
|
+
setInputValue((filter == null ? void 0 : filter.value) || "");
|
360
|
+
}
|
335
361
|
(_b2 = refs.domReference.current) == null ? void 0 : _b2.focus();
|
336
362
|
}
|
337
363
|
}, []);
|
@@ -361,11 +387,13 @@ const AdHocCombobox = forwardRef(function AdHocCombobox2({ filter, model, isAlwa
|
|
361
387
|
tabIndex: 0,
|
362
388
|
onClick: (event) => {
|
363
389
|
event.stopPropagation();
|
390
|
+
setInputValue("");
|
364
391
|
switchInputType("operator", setInputType, void 0, refs.domReference.current);
|
365
392
|
},
|
366
393
|
onKeyDown: (event) => {
|
367
394
|
handleShiftTabInput(event, hasMultiValueOperator);
|
368
395
|
if (event.key === "Enter") {
|
396
|
+
setInputValue("");
|
369
397
|
switchInputType("operator", setInputType, void 0, refs.domReference.current);
|
370
398
|
}
|
371
399
|
}
|
@@ -375,7 +403,8 @@ const AdHocCombobox = forwardRef(function AdHocCombobox2({ filter, model, isAlwa
|
|
375
403
|
key: `${item.value}-${i}`,
|
376
404
|
item,
|
377
405
|
index: i,
|
378
|
-
handleRemoveMultiValue
|
406
|
+
handleRemoveMultiValue,
|
407
|
+
handleEditMultiValuePill
|
379
408
|
})) : null) : null, /* @__PURE__ */ React.createElement("input", __spreadProps(__spreadValues({}, getReferenceProps({
|
380
409
|
ref: refs.setReference,
|
381
410
|
onChange,
|
@@ -462,6 +491,7 @@ const AdHocCombobox = forwardRef(function AdHocCombobox2({ filter, model, isAlwa
|
|
462
491
|
event.preventDefault();
|
463
492
|
event.stopPropagation();
|
464
493
|
handleLocalMultiValueChange(item);
|
494
|
+
setInputValue("");
|
465
495
|
(_a3 = refs.domReference.current) == null ? void 0 : _a3.focus();
|
466
496
|
} else {
|
467
497
|
model._updateFilter(
|
@@ -473,7 +503,13 @@ const AdHocCombobox = forwardRef(function AdHocCombobox2({ filter, model, isAlwa
|
|
473
503
|
setFilterMultiValues
|
474
504
|
})
|
475
505
|
);
|
476
|
-
|
506
|
+
populateInputValueOnInputTypeSwitch({
|
507
|
+
populateInputOnEdit,
|
508
|
+
item,
|
509
|
+
filterInputType,
|
510
|
+
setInputValue,
|
511
|
+
filter
|
512
|
+
});
|
477
513
|
switchToNextInputType(
|
478
514
|
filterInputType,
|
479
515
|
setInputType,
|
@@ -506,35 +542,6 @@ const AdHocCombobox = forwardRef(function AdHocCombobox2({ filter, model, isAlwa
|
|
506
542
|
menuHeight: Math.min(rowVirtualizer.getTotalSize(), MAX_MENU_HEIGHT)
|
507
543
|
}) : null))));
|
508
544
|
});
|
509
|
-
const MultiValuePill = ({ item, handleRemoveMultiValue, index }) => {
|
510
|
-
var _a, _b;
|
511
|
-
const styles = useStyles2(getStyles);
|
512
|
-
return /* @__PURE__ */ React.createElement("div", {
|
513
|
-
className: cx(styles.basePill, styles.valuePill)
|
514
|
-
}, /* @__PURE__ */ React.createElement("span", null, " ", (_a = item.label) != null ? _a : item.value), /* @__PURE__ */ React.createElement(Button, {
|
515
|
-
onClick: (e) => {
|
516
|
-
e.stopPropagation();
|
517
|
-
e.preventDefault();
|
518
|
-
handleRemoveMultiValue(item);
|
519
|
-
},
|
520
|
-
onKeyDownCapture: (e) => {
|
521
|
-
if (e.key === "Enter") {
|
522
|
-
e.preventDefault();
|
523
|
-
e.stopPropagation();
|
524
|
-
handleRemoveMultiValue(item);
|
525
|
-
}
|
526
|
-
},
|
527
|
-
fill: "text",
|
528
|
-
size: "sm",
|
529
|
-
variant: "secondary",
|
530
|
-
className: styles.removeButton,
|
531
|
-
tooltip: `Remove filter value - ${(_b = item.label) != null ? _b : item.value}`
|
532
|
-
}, /* @__PURE__ */ React.createElement(Icon, {
|
533
|
-
name: "times",
|
534
|
-
size: "md",
|
535
|
-
id: `${item.value}-${index}`
|
536
|
-
})));
|
537
|
-
};
|
538
545
|
const getStyles = (theme) => ({
|
539
546
|
comboboxWrapper: css({
|
540
547
|
display: "flex",
|
@@ -567,10 +574,6 @@ const getStyles = (theme) => ({
|
|
567
574
|
background: theme.colors.action.hover
|
568
575
|
}
|
569
576
|
}),
|
570
|
-
valuePill: css({
|
571
|
-
background: theme.colors.action.selected,
|
572
|
-
padding: theme.spacing(0.125, 0, 0.125, 1)
|
573
|
-
}),
|
574
577
|
dropdownWrapper: css({
|
575
578
|
backgroundColor: theme.colors.background.primary,
|
576
579
|
color: theme.colors.text.primary,
|
@@ -603,25 +606,10 @@ const getStyles = (theme) => ({
|
|
603
606
|
borderTop: `1px solid ${theme.colors.border.weak}`
|
604
607
|
}
|
605
608
|
}),
|
606
|
-
removeButton: css({
|
607
|
-
marginInline: theme.spacing(0.5),
|
608
|
-
height: "100%",
|
609
|
-
padding: 0,
|
610
|
-
cursor: "pointer",
|
611
|
-
"&:hover": {
|
612
|
-
color: theme.colors.text.primary
|
613
|
-
}
|
614
|
-
}),
|
615
609
|
descriptionText: css(__spreadProps(__spreadValues({}, theme.typography.bodySmall), {
|
616
610
|
color: theme.colors.text.secondary,
|
617
611
|
paddingTop: theme.spacing(0.5)
|
618
|
-
}))
|
619
|
-
multiValueApply: css({
|
620
|
-
position: "absolute",
|
621
|
-
top: 0,
|
622
|
-
left: 0,
|
623
|
-
display: "flex"
|
624
|
-
})
|
612
|
+
}))
|
625
613
|
});
|
626
614
|
|
627
615
|
export { AdHocCombobox };
|