@grafana/scenes 5.23.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/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/index.js +402 -282
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
@@ -0,0 +1,114 @@
|
|
1
|
+
import { cx, css } from '@emotion/css';
|
2
|
+
import { useStyles2, Button, Icon } from '@grafana/ui';
|
3
|
+
import React, { useCallback } from 'react';
|
4
|
+
|
5
|
+
var __defProp = Object.defineProperty;
|
6
|
+
var __defProps = Object.defineProperties;
|
7
|
+
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
8
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
9
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
10
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
11
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
12
|
+
var __spreadValues = (a, b) => {
|
13
|
+
for (var prop in b || (b = {}))
|
14
|
+
if (__hasOwnProp.call(b, prop))
|
15
|
+
__defNormalProp(a, prop, b[prop]);
|
16
|
+
if (__getOwnPropSymbols)
|
17
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
18
|
+
if (__propIsEnum.call(b, prop))
|
19
|
+
__defNormalProp(a, prop, b[prop]);
|
20
|
+
}
|
21
|
+
return a;
|
22
|
+
};
|
23
|
+
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
24
|
+
const MultiValuePill = ({
|
25
|
+
item,
|
26
|
+
handleRemoveMultiValue,
|
27
|
+
index,
|
28
|
+
handleEditMultiValuePill
|
29
|
+
}) => {
|
30
|
+
var _a, _b;
|
31
|
+
const styles = useStyles2(getStyles);
|
32
|
+
const editMultiValuePill = useCallback(
|
33
|
+
(e) => {
|
34
|
+
e.stopPropagation();
|
35
|
+
e.preventDefault();
|
36
|
+
handleEditMultiValuePill(item);
|
37
|
+
},
|
38
|
+
[handleEditMultiValuePill, item]
|
39
|
+
);
|
40
|
+
const editMultiValuePillWithKeyboard = useCallback(
|
41
|
+
(e) => {
|
42
|
+
if (e.key === "Enter") {
|
43
|
+
editMultiValuePill(e);
|
44
|
+
}
|
45
|
+
},
|
46
|
+
[editMultiValuePill]
|
47
|
+
);
|
48
|
+
const removePillHandler = useCallback(
|
49
|
+
(e) => {
|
50
|
+
e.stopPropagation();
|
51
|
+
e.preventDefault();
|
52
|
+
handleRemoveMultiValue(item);
|
53
|
+
},
|
54
|
+
[handleRemoveMultiValue, item]
|
55
|
+
);
|
56
|
+
const removePillHandlerWithKeyboard = useCallback(
|
57
|
+
(e) => {
|
58
|
+
if (e.key === "Enter") {
|
59
|
+
removePillHandler(e);
|
60
|
+
}
|
61
|
+
},
|
62
|
+
[removePillHandler]
|
63
|
+
);
|
64
|
+
return /* @__PURE__ */ React.createElement("div", {
|
65
|
+
className: cx(styles.basePill, styles.valuePill),
|
66
|
+
onClick: editMultiValuePill,
|
67
|
+
onKeyDown: editMultiValuePillWithKeyboard,
|
68
|
+
tabIndex: 0,
|
69
|
+
id: `${item.value}-${index}`
|
70
|
+
}, (_a = item.label) != null ? _a : item.value, /* @__PURE__ */ React.createElement(Button, {
|
71
|
+
onClick: removePillHandler,
|
72
|
+
onKeyDownCapture: removePillHandlerWithKeyboard,
|
73
|
+
fill: "text",
|
74
|
+
size: "sm",
|
75
|
+
variant: "secondary",
|
76
|
+
className: styles.removeButton,
|
77
|
+
tooltip: `Remove filter value - ${(_b = item.label) != null ? _b : item.value}`
|
78
|
+
}, /* @__PURE__ */ React.createElement(Icon, {
|
79
|
+
name: "times",
|
80
|
+
size: "md",
|
81
|
+
id: `${item.value}-${index}-close-icon`
|
82
|
+
})));
|
83
|
+
};
|
84
|
+
const getStyles = (theme) => ({
|
85
|
+
basePill: css(__spreadProps(__spreadValues({
|
86
|
+
display: "flex",
|
87
|
+
alignItems: "center",
|
88
|
+
background: theme.colors.action.disabledBackground,
|
89
|
+
border: `1px solid ${theme.colors.border.weak}`,
|
90
|
+
padding: theme.spacing(0.125, 1, 0.125, 1),
|
91
|
+
color: theme.colors.text.primary,
|
92
|
+
overflow: "hidden",
|
93
|
+
whiteSpace: "nowrap",
|
94
|
+
minHeight: theme.spacing(2.75)
|
95
|
+
}, theme.typography.bodySmall), {
|
96
|
+
cursor: "pointer"
|
97
|
+
})),
|
98
|
+
valuePill: css({
|
99
|
+
background: theme.colors.action.selected,
|
100
|
+
padding: theme.spacing(0.125, 0, 0.125, 1)
|
101
|
+
}),
|
102
|
+
removeButton: css({
|
103
|
+
marginInline: theme.spacing(0.5),
|
104
|
+
height: "100%",
|
105
|
+
padding: 0,
|
106
|
+
cursor: "pointer",
|
107
|
+
"&:hover": {
|
108
|
+
color: theme.colors.text.primary
|
109
|
+
}
|
110
|
+
})
|
111
|
+
});
|
112
|
+
|
113
|
+
export { MultiValuePill };
|
114
|
+
//# sourceMappingURL=MultiValuePill.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"MultiValuePill.js","sources":["../../../../../src/variables/adhoc/AdHocFiltersCombobox/MultiValuePill.tsx"],"sourcesContent":["import { cx, css } from '@emotion/css';\nimport { SelectableValue, GrafanaTheme2 } from '@grafana/data';\nimport { useStyles2, Button, Icon } from '@grafana/ui';\nimport React, { useCallback } from 'react';\n\ninterface MultiValuePillProps {\n item: SelectableValue<string>;\n handleRemoveMultiValue: (item: SelectableValue<string>) => void;\n index: number;\n handleEditMultiValuePill: (value: SelectableValue<string>) => void;\n}\nexport const MultiValuePill = ({\n item,\n handleRemoveMultiValue,\n index,\n handleEditMultiValuePill,\n}: MultiValuePillProps) => {\n const styles = useStyles2(getStyles);\n\n const editMultiValuePill = useCallback(\n (e: React.SyntheticEvent) => {\n e.stopPropagation();\n e.preventDefault();\n handleEditMultiValuePill(item);\n },\n [handleEditMultiValuePill, item]\n );\n\n const editMultiValuePillWithKeyboard = useCallback(\n (e: React.KeyboardEvent) => {\n if (e.key === 'Enter') {\n editMultiValuePill(e);\n }\n },\n [editMultiValuePill]\n );\n\n const removePillHandler = useCallback(\n (e: React.SyntheticEvent) => {\n e.stopPropagation();\n e.preventDefault();\n handleRemoveMultiValue(item);\n },\n [handleRemoveMultiValue, item]\n );\n\n const removePillHandlerWithKeyboard = useCallback(\n (e: React.KeyboardEvent) => {\n if (e.key === 'Enter') {\n removePillHandler(e);\n }\n },\n [removePillHandler]\n );\n\n return (\n <div\n className={cx(styles.basePill, styles.valuePill)}\n onClick={editMultiValuePill}\n onKeyDown={editMultiValuePillWithKeyboard}\n tabIndex={0}\n id={`${item.value}-${index}`}\n >\n {item.label ?? item.value}\n <Button\n onClick={removePillHandler}\n onKeyDownCapture={removePillHandlerWithKeyboard}\n fill=\"text\"\n size=\"sm\"\n variant=\"secondary\"\n className={styles.removeButton}\n tooltip={`Remove filter value - ${item.label ?? item.value}`}\n >\n <Icon name=\"times\" size=\"md\" id={`${item.value}-${index}-close-icon`} />\n </Button>\n </div>\n );\n};\n\nconst getStyles = (theme: GrafanaTheme2) => ({\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: theme.spacing(2.75),\n ...theme.typography.bodySmall,\n cursor: 'pointer',\n }),\n valuePill: css({\n background: theme.colors.action.selected,\n padding: theme.spacing(0.125, 0, 0.125, 1),\n }),\n removeButton: css({\n marginInline: theme.spacing(0.5),\n height: '100%',\n padding: 0,\n cursor: 'pointer',\n '&:hover': {\n color: theme.colors.text.primary,\n },\n }),\n});\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAWO,MAAM,iBAAiB,CAAC;AAAA,EAC7B,IAAA;AAAA,EACA,sBAAA;AAAA,EACA,KAAA;AAAA,EACA,wBAAA;AACF,CAA2B,KAAA;AAhB3B,EAAA,IAAA,EAAA,EAAA,EAAA,CAAA;AAiBE,EAAM,MAAA,MAAA,GAAS,WAAW,SAAS,CAAA,CAAA;AAEnC,EAAA,MAAM,kBAAqB,GAAA,WAAA;AAAA,IACzB,CAAC,CAA4B,KAAA;AAC3B,MAAA,CAAA,CAAE,eAAgB,EAAA,CAAA;AAClB,MAAA,CAAA,CAAE,cAAe,EAAA,CAAA;AACjB,MAAA,wBAAA,CAAyB,IAAI,CAAA,CAAA;AAAA,KAC/B;AAAA,IACA,CAAC,0BAA0B,IAAI,CAAA;AAAA,GACjC,CAAA;AAEA,EAAA,MAAM,8BAAiC,GAAA,WAAA;AAAA,IACrC,CAAC,CAA2B,KAAA;AAC1B,MAAI,IAAA,CAAA,CAAE,QAAQ,OAAS,EAAA;AACrB,QAAA,kBAAA,CAAmB,CAAC,CAAA,CAAA;AAAA,OACtB;AAAA,KACF;AAAA,IACA,CAAC,kBAAkB,CAAA;AAAA,GACrB,CAAA;AAEA,EAAA,MAAM,iBAAoB,GAAA,WAAA;AAAA,IACxB,CAAC,CAA4B,KAAA;AAC3B,MAAA,CAAA,CAAE,eAAgB,EAAA,CAAA;AAClB,MAAA,CAAA,CAAE,cAAe,EAAA,CAAA;AACjB,MAAA,sBAAA,CAAuB,IAAI,CAAA,CAAA;AAAA,K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AA,MAAA,CAAO,IAAK,CAAA,OAAA;AAAA,KAC3B;AAAA,GACD,CAAA;AACH,CAAA,CAAA;;;;"}
|
@@ -167,6 +167,19 @@ const generatePlaceholder = (filter, filterInputType, isMultiValueEdit, isAlways
|
|
167
167
|
}
|
168
168
|
return filter[filterInputType] && !isAlwaysWip ? `${filter[filterInputType]}` : INPUT_PLACEHOLDER;
|
169
169
|
};
|
170
|
+
const populateInputValueOnInputTypeSwitch = ({
|
171
|
+
populateInputOnEdit,
|
172
|
+
item,
|
173
|
+
filterInputType,
|
174
|
+
setInputValue,
|
175
|
+
filter
|
176
|
+
}) => {
|
177
|
+
if (populateInputOnEdit && !isMultiValueOperator(item.value || "") && nextInputTypeMap[filterInputType] === "value") {
|
178
|
+
setInputValue((filter == null ? void 0 : filter.value) || "");
|
179
|
+
} else {
|
180
|
+
setInputValue("");
|
181
|
+
}
|
182
|
+
};
|
170
183
|
|
171
|
-
export { ERROR_STATE_DROPDOWN_WIDTH, VIRTUAL_LIST_ITEM_HEIGHT, VIRTUAL_LIST_ITEM_HEIGHT_WITH_DESCRIPTION, VIRTUAL_LIST_OVERSCAN, flattenOptionGroups, fuzzySearchOptions, generateFilterUpdatePayload, generatePlaceholder, setupDropdownAccessibility, switchInputType, switchToNextInputType };
|
184
|
+
export { ERROR_STATE_DROPDOWN_WIDTH, VIRTUAL_LIST_ITEM_HEIGHT, VIRTUAL_LIST_ITEM_HEIGHT_WITH_DESCRIPTION, VIRTUAL_LIST_OVERSCAN, flattenOptionGroups, fuzzySearchOptions, generateFilterUpdatePayload, generatePlaceholder, populateInputValueOnInputTypeSwitch, setupDropdownAccessibility, switchInputType, switchToNextInputType };
|
172
185
|
//# sourceMappingURL=utils.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"utils.js","sources":["../../../../../src/variables/adhoc/AdHocFiltersCombobox/utils.ts"],"sourcesContent":["import { SelectableValue } from '@grafana/data';\nimport uFuzzy from '@leeoniya/ufuzzy';\nimport { AdHocInputType } from './AdHocFiltersCombobox';\nimport { AdHocFilterWithLabels, isMultiValueOperator } from '../AdHocFiltersVariable';\n\nconst VIRTUAL_LIST_WIDTH_ESTIMATE_MULTIPLIER = 8;\nconst VIRTUAL_LIST_DESCRIPTION_WIDTH_ESTIMATE_MULTIPLIER = 6;\nconst VIRTUAL_LIST_PADDING = 8;\nexport const VIRTUAL_LIST_OVERSCAN = 5;\nexport const VIRTUAL_LIST_ITEM_HEIGHT = 38;\nexport const VIRTUAL_LIST_ITEM_HEIGHT_WITH_DESCRIPTION = 60;\nexport const ERROR_STATE_DROPDOWN_WIDTH = 366;\n\nexport function fuzzySearchOptions(options: Array<SelectableValue<string>>) {\n const ufuzzy = new uFuzzy();\n const haystack: string[] = [];\n const limit = 10000;\n\n return (search: string, filterInputType: AdHocInputType) => {\n if (search === '') {\n if (options.length > limit) {\n return options.slice(0, limit);\n } else {\n return options;\n }\n }\n\n if (filterInputType === 'operator') {\n const filteredOperators = [];\n for (let i = 0; i < options.length; i++) {\n if ((options[i].label || options[i].value)?.includes(search)) {\n filteredOperators.push(options[i]);\n if (filteredOperators.length > limit) {\n return filteredOperators;\n }\n }\n }\n return filteredOperators;\n }\n\n if (haystack.length === 0) {\n for (let i = 0; i < options.length; i++) {\n haystack.push(options[i].label || options[i].value!);\n }\n }\n const [idxs, info, order] = ufuzzy.search(haystack, search);\n const filteredOptions: Array<SelectableValue<string>> = [];\n\n if (idxs) {\n for (let i = 0; i < idxs.length; i++) {\n if (info && order) {\n const idx = order[i];\n filteredOptions.push(options[idxs[idx]]);\n } else {\n filteredOptions.push(options[idxs[i]]);\n }\n\n if (filteredOptions.length > limit) {\n return filteredOptions;\n }\n }\n return filteredOptions;\n }\n\n if (options.length > limit) {\n return options.slice(0, limit);\n }\n\n return options;\n };\n}\nexport const flattenOptionGroups = (options: Array<SelectableValue<string>>) =>\n options.flatMap<SelectableValue<string>>((option) => (option.options ? [option, ...option.options] : [option]));\n\nexport const setupDropdownAccessibility = (\n options: Array<SelectableValue<string>>,\n listRef: React.MutableRefObject<Array<HTMLElement | null>>,\n disabledIndicesRef: React.MutableRefObject<number[]>\n) => {\n let maxOptionWidth = 182;\n const listRefArr = [];\n const disabledIndices = [];\n\n for (let i = 0; i < options.length; i++) {\n // listRefArr should be filled with nulls for amount of dropdown items so that\n // useNavigationList sets activeIndex correctly when navigating with arrow keys\n listRefArr.push(null);\n\n // disabledIndices are used to skip unselectable group items in dropdown when\n // navigating with arrow keys\n if (options[i]?.options) {\n disabledIndices.push(i);\n }\n let label = options[i].label ?? options[i].value ?? '';\n let multiplierToUse = VIRTUAL_LIST_WIDTH_ESTIMATE_MULTIPLIER;\n if (\n label.length * VIRTUAL_LIST_WIDTH_ESTIMATE_MULTIPLIER <\n (options[i].description?.length || 0) * VIRTUAL_LIST_DESCRIPTION_WIDTH_ESTIMATE_MULTIPLIER\n ) {\n label = options[i].description!;\n multiplierToUse = VIRTUAL_LIST_DESCRIPTION_WIDTH_ESTIMATE_MULTIPLIER;\n }\n\n // rough widthEstimate\n const widthEstimate =\n (options[i].isCustom ? label.length + 18 : label.length) * multiplierToUse + VIRTUAL_LIST_PADDING * 2;\n if (widthEstimate > maxOptionWidth) {\n maxOptionWidth = widthEstimate;\n }\n }\n\n listRef.current = [...listRefArr];\n disabledIndicesRef.current = [...disabledIndices];\n return maxOptionWidth;\n};\n\nconst nextInputTypeMap = {\n key: 'operator',\n operator: 'value',\n value: 'key',\n} as const;\n\nexport const switchToNextInputType = (\n filterInputType: AdHocInputType,\n setInputType: React.Dispatch<React.SetStateAction<AdHocInputType>>,\n handleChangeViewMode: ((event?: React.MouseEvent, shouldFocusOnFilterPill?: boolean) => void) | undefined,\n element: HTMLInputElement | null,\n shouldFocusOnPillWrapperOverride?: boolean\n) =>\n switchInputType(\n nextInputTypeMap[filterInputType],\n setInputType,\n filterInputType === 'value' ? handleChangeViewMode : undefined,\n element,\n shouldFocusOnPillWrapperOverride\n );\n\nexport const switchInputType = (\n filterInputType: AdHocInputType,\n setInputType: React.Dispatch<React.SetStateAction<AdHocInputType>>,\n handleChangeViewMode?: (event?: React.MouseEvent, shouldFocusOnFilterPill?: boolean) => void,\n element?: HTMLInputElement | null,\n shouldFocusOnPillWrapperOverride?: boolean\n) => {\n setInputType(filterInputType);\n\n handleChangeViewMode?.(undefined, shouldFocusOnPillWrapperOverride);\n\n setTimeout(() => element?.focus());\n};\n\nexport const generateFilterUpdatePayload = ({\n filterInputType,\n item,\n filter,\n setFilterMultiValues,\n}: {\n filterInputType: AdHocInputType;\n item: SelectableValue<string>;\n filter: AdHocFilterWithLabels;\n setFilterMultiValues: (value: React.SetStateAction<Array<SelectableValue<string>>>) => void;\n}): Partial<AdHocFilterWithLabels> => {\n if (filterInputType === 'key') {\n return {\n key: item.value,\n keyLabel: item.label ? item.label : item.value,\n };\n }\n if (filterInputType === 'value') {\n return {\n value: item.value,\n valueLabels: [item.label ? item.label : item.value!],\n };\n }\n\n if (filterInputType === 'operator') {\n // handle values/valueLabels when switching from multi to single value operator\n if (isMultiValueOperator(filter.operator) && !isMultiValueOperator(item.value!)) {\n // reset local multi values state\n setFilterMultiValues([]);\n // update operator and reset values and valueLabels\n return {\n operator: item.value,\n // TODO remove when we're on the latest version of @grafana/data\n //@ts-expect-error\n valueLabels: [filter.valueLabels?.[0] || filter.values?.[0] || filter.value],\n //@ts-expect-error\n values: undefined,\n };\n }\n\n // handle values/valueLabels when switching from single to multi value operator\n if (isMultiValueOperator(item.value!) && !isMultiValueOperator(filter.operator)) {\n // TODO remove when we're on the latest version of @grafana/data\n //@ts-expect-error\n const valueLabels = [filter.valueLabels?.[0] || filter.values?.[0] || filter.value];\n const values = [filter.value];\n\n // populate local multi values state\n if (values[0]) {\n setFilterMultiValues([\n {\n value: values[0],\n label: valueLabels?.[0] ?? values[0],\n },\n ]);\n }\n\n // update operator and default values and valueLabels\n return {\n operator: item.value,\n valueLabels: valueLabels,\n //@ts-expect-error\n values: values,\n };\n }\n }\n\n // default operator update of same multi/single type\n return {\n [filterInputType]: item.value,\n };\n};\n\nconst INPUT_PLACEHOLDER = 'Filter by label values';\n\nexport const generatePlaceholder = (\n filter: AdHocFilterWithLabels,\n filterInputType: AdHocInputType,\n isMultiValueEdit: boolean,\n isAlwaysWip?: boolean\n) => {\n if (filterInputType === 'key') {\n return INPUT_PLACEHOLDER;\n }\n if (filterInputType === 'value') {\n if (isMultiValueEdit) {\n return 'Edit values';\n }\n return filter.valueLabels?.[0] || '';\n }\n\n return filter[filterInputType] && !isAlwaysWip ? `${filter[filterInputType]}` : INPUT_PLACEHOLDER;\n};\n"],"names":[],"mappings":";;;AAKA,MAAM,sCAAyC,GAAA,CAAA,CAAA;AAC/C,MAAM,kDAAqD,GAAA,CAAA,CAAA;AAC3D,MAAM,oBAAuB,GAAA,CAAA,CAAA;AACtB,MAAM,qBAAwB,GAAA,EAAA;AAC9B,MAAM,wBAA2B,GAAA,GAAA;AACjC,MAAM,yCAA4C,GAAA,GAAA;AAClD,MAAM,0BAA6B,GAAA,IAAA;AAEnC,SAAS,mBAAmB,OAAyC,EAAA;AAC1E,EAAM,MAAA,MAAA,GAAS,IAAI,MAAO,EAAA,CAAA;AAC1B,EAAA,MAAM,WAAqB,EAAC,CAAA;AAC5B,EAAA,MAAM,KAAQ,GAAA,GAAA,CAAA;AAEd,EAAO,OAAA,CAAC,QAAgB,eAAoC,KAAA;AAlB9D,IAAA,IAAA,EAAA,CAAA;AAmBI,IAAA,IAAI,WAAW,EAAI,EAAA;AACjB,MAAI,IAAA,OAAA,CAAQ,SAAS,KAAO,EAAA;AAC1B,QAAO,OAAA,OAAA,CAAQ,KAAM,CAAA,CAAA,EAAG,KAAK,CAAA,CAAA;AAAA,OACxB,MAAA;AACL,QAAO,OAAA,OAAA,CAAA;AAAA,OACT;AAAA,KACF;AAEA,IAAA,IAAI,oBAAoB,UAAY,EAAA;AAClC,MAAA,MAAM,oBAAoB,EAAC,CAAA;AAC3B,MAAA,KAAA,IAAS,CAAI,GAAA,CAAA,EAAG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;AAAA,IACL,CAAC,kBAAkB,IAAK,CAAA,KAAA;AAAA,GAC1B,CAAA;AACF,EAAA;AAEA,MAAM,iBAAoB,GAAA,wBAAA,CAAA;AAEnB,MAAM,mBAAsB,GAAA,CACjC,MACA,EAAA,eAAA,EACA,kBACA,WACG,KAAA;AAvOL,EAAA,IAAA,EAAA,CAAA;AAwOE,EAAA,IAAI,oBAAoB,KAAO,EAAA;AAC7B,IAAO,OAAA,iBAAA,CAAA;AAAA,GACT;AACA,EAAA,IAAI,oBAAoB,OAAS,EAAA;AAC/B,IAAA,IAAI,gBAAkB,EAAA;AACpB,MAAO,OAAA,aAAA,CAAA;AAAA,KACT;AACA,IAAO,OAAA,CAAA,CAAA,EAAA,GAAA,MAAA,CAAO,WAAP,KAAA,IAAA,GAAA,KAAA,CAAA,GAAA,EAAA,CAAqB,CAAM,CAAA,KAAA,EAAA,CAAA;AAAA,GACpC;AAEA,EAAA,OAAO,OAAO,eAAoB,CAAA,IAAA,CAAC,WAAc,GAAA,CAAA,EAAG,OAAO,eAAqB,CAAA,CAAA,CAAA,GAAA,iBAAA,CAAA;AAClF;;;;"}
|
1
|
+
{"version":3,"file":"utils.js","sources":["../../../../../src/variables/adhoc/AdHocFiltersCombobox/utils.ts"],"sourcesContent":["import { SelectableValue } from '@grafana/data';\nimport uFuzzy from '@leeoniya/ufuzzy';\nimport { AdHocInputType } from './AdHocFiltersCombobox';\nimport { AdHocFilterWithLabels, isMultiValueOperator } from '../AdHocFiltersVariable';\n\nconst VIRTUAL_LIST_WIDTH_ESTIMATE_MULTIPLIER = 8;\nconst VIRTUAL_LIST_DESCRIPTION_WIDTH_ESTIMATE_MULTIPLIER = 6;\nconst VIRTUAL_LIST_PADDING = 8;\nexport const VIRTUAL_LIST_OVERSCAN = 5;\nexport const VIRTUAL_LIST_ITEM_HEIGHT = 38;\nexport const VIRTUAL_LIST_ITEM_HEIGHT_WITH_DESCRIPTION = 60;\nexport const ERROR_STATE_DROPDOWN_WIDTH = 366;\n\nexport function fuzzySearchOptions(options: Array<SelectableValue<string>>) {\n const ufuzzy = new uFuzzy();\n const haystack: string[] = [];\n const limit = 10000;\n\n return (search: string, filterInputType: AdHocInputType) => {\n if (search === '') {\n if (options.length > limit) {\n return options.slice(0, limit);\n } else {\n return options;\n }\n }\n\n if (filterInputType === 'operator') {\n const filteredOperators = [];\n for (let i = 0; i < options.length; i++) {\n if ((options[i].label || options[i].value)?.includes(search)) {\n filteredOperators.push(options[i]);\n if (filteredOperators.length > limit) {\n return filteredOperators;\n }\n }\n }\n return filteredOperators;\n }\n\n if (haystack.length === 0) {\n for (let i = 0; i < options.length; i++) {\n haystack.push(options[i].label || options[i].value!);\n }\n }\n const [idxs, info, order] = ufuzzy.search(haystack, search);\n const filteredOptions: Array<SelectableValue<string>> = [];\n\n if (idxs) {\n for (let i = 0; i < idxs.length; i++) {\n if (info && order) {\n const idx = order[i];\n filteredOptions.push(options[idxs[idx]]);\n } else {\n filteredOptions.push(options[idxs[i]]);\n }\n\n if (filteredOptions.length > limit) {\n return filteredOptions;\n }\n }\n return filteredOptions;\n }\n\n if (options.length > limit) {\n return options.slice(0, limit);\n }\n\n return options;\n };\n}\nexport const flattenOptionGroups = (options: Array<SelectableValue<string>>) =>\n options.flatMap<SelectableValue<string>>((option) => (option.options ? [option, ...option.options] : [option]));\n\nexport const setupDropdownAccessibility = (\n options: Array<SelectableValue<string>>,\n listRef: React.MutableRefObject<Array<HTMLElement | null>>,\n disabledIndicesRef: React.MutableRefObject<number[]>\n) => {\n let maxOptionWidth = 182;\n const listRefArr = [];\n const disabledIndices = [];\n\n for (let i = 0; i < options.length; i++) {\n // listRefArr should be filled with nulls for amount of dropdown items so that\n // useNavigationList sets activeIndex correctly when navigating with arrow keys\n listRefArr.push(null);\n\n // disabledIndices are used to skip unselectable group items in dropdown when\n // navigating with arrow keys\n if (options[i]?.options) {\n disabledIndices.push(i);\n }\n let label = options[i].label ?? options[i].value ?? '';\n let multiplierToUse = VIRTUAL_LIST_WIDTH_ESTIMATE_MULTIPLIER;\n if (\n label.length * VIRTUAL_LIST_WIDTH_ESTIMATE_MULTIPLIER <\n (options[i].description?.length || 0) * VIRTUAL_LIST_DESCRIPTION_WIDTH_ESTIMATE_MULTIPLIER\n ) {\n label = options[i].description!;\n multiplierToUse = VIRTUAL_LIST_DESCRIPTION_WIDTH_ESTIMATE_MULTIPLIER;\n }\n\n // rough widthEstimate\n const widthEstimate =\n (options[i].isCustom ? label.length + 18 : label.length) * multiplierToUse + VIRTUAL_LIST_PADDING * 2;\n if (widthEstimate > maxOptionWidth) {\n maxOptionWidth = widthEstimate;\n }\n }\n\n listRef.current = [...listRefArr];\n disabledIndicesRef.current = [...disabledIndices];\n return maxOptionWidth;\n};\n\nconst nextInputTypeMap = {\n key: 'operator',\n operator: 'value',\n value: 'key',\n} as const;\n\nexport const switchToNextInputType = (\n filterInputType: AdHocInputType,\n setInputType: React.Dispatch<React.SetStateAction<AdHocInputType>>,\n handleChangeViewMode: ((event?: React.MouseEvent, shouldFocusOnFilterPill?: boolean) => void) | undefined,\n element: HTMLInputElement | null,\n shouldFocusOnPillWrapperOverride?: boolean\n) =>\n switchInputType(\n nextInputTypeMap[filterInputType],\n setInputType,\n filterInputType === 'value' ? handleChangeViewMode : undefined,\n element,\n shouldFocusOnPillWrapperOverride\n );\n\nexport const switchInputType = (\n filterInputType: AdHocInputType,\n setInputType: React.Dispatch<React.SetStateAction<AdHocInputType>>,\n handleChangeViewMode?: (event?: React.MouseEvent, shouldFocusOnFilterPill?: boolean) => void,\n element?: HTMLInputElement | null,\n shouldFocusOnPillWrapperOverride?: boolean\n) => {\n setInputType(filterInputType);\n\n handleChangeViewMode?.(undefined, shouldFocusOnPillWrapperOverride);\n\n setTimeout(() => element?.focus());\n};\n\nexport const generateFilterUpdatePayload = ({\n filterInputType,\n item,\n filter,\n setFilterMultiValues,\n}: {\n filterInputType: AdHocInputType;\n item: SelectableValue<string>;\n filter: AdHocFilterWithLabels;\n setFilterMultiValues: (value: React.SetStateAction<Array<SelectableValue<string>>>) => void;\n}): Partial<AdHocFilterWithLabels> => {\n if (filterInputType === 'key') {\n return {\n key: item.value,\n keyLabel: item.label ? item.label : item.value,\n };\n }\n if (filterInputType === 'value') {\n return {\n value: item.value,\n valueLabels: [item.label ? item.label : item.value!],\n };\n }\n\n if (filterInputType === 'operator') {\n // handle values/valueLabels when switching from multi to single value operator\n if (isMultiValueOperator(filter.operator) && !isMultiValueOperator(item.value!)) {\n // reset local multi values state\n setFilterMultiValues([]);\n // update operator and reset values and valueLabels\n return {\n operator: item.value,\n // TODO remove when we're on the latest version of @grafana/data\n //@ts-expect-error\n valueLabels: [filter.valueLabels?.[0] || filter.values?.[0] || filter.value],\n //@ts-expect-error\n values: undefined,\n };\n }\n\n // handle values/valueLabels when switching from single to multi value operator\n if (isMultiValueOperator(item.value!) && !isMultiValueOperator(filter.operator)) {\n // TODO remove when we're on the latest version of @grafana/data\n //@ts-expect-error\n const valueLabels = [filter.valueLabels?.[0] || filter.values?.[0] || filter.value];\n const values = [filter.value];\n\n // populate local multi values state\n if (values[0]) {\n setFilterMultiValues([\n {\n value: values[0],\n label: valueLabels?.[0] ?? values[0],\n },\n ]);\n }\n\n // update operator and default values and valueLabels\n return {\n operator: item.value,\n valueLabels: valueLabels,\n //@ts-expect-error\n values: values,\n };\n }\n }\n\n // default operator update of same multi/single type\n return {\n [filterInputType]: item.value,\n };\n};\n\nconst INPUT_PLACEHOLDER = 'Filter by label values';\n\nexport const generatePlaceholder = (\n filter: AdHocFilterWithLabels,\n filterInputType: AdHocInputType,\n isMultiValueEdit: boolean,\n isAlwaysWip?: boolean\n) => {\n if (filterInputType === 'key') {\n return INPUT_PLACEHOLDER;\n }\n if (filterInputType === 'value') {\n if (isMultiValueEdit) {\n return 'Edit values';\n }\n return filter.valueLabels?.[0] || '';\n }\n\n return filter[filterInputType] && !isAlwaysWip ? `${filter[filterInputType]}` : INPUT_PLACEHOLDER;\n};\n\nexport const populateInputValueOnInputTypeSwitch = ({\n populateInputOnEdit,\n item,\n filterInputType,\n setInputValue,\n filter,\n}: {\n populateInputOnEdit: boolean | undefined;\n item: SelectableValue<string>;\n filterInputType: AdHocInputType;\n setInputValue: (value: React.SetStateAction<string>) => void;\n filter: AdHocFilterWithLabels | undefined;\n}) => {\n if (populateInputOnEdit && !isMultiValueOperator(item.value || '') && nextInputTypeMap[filterInputType] === 'value') {\n setInputValue(filter?.value || '');\n } else {\n setInputValue('');\n }\n};\n"],"names":[],"mappings":";;;AAKA,MAAM,sCAAyC,GAAA,CAAA,CAAA;AAC/C,MAAM,kDAAqD,GAAA,CAAA,CAAA;AAC3D,MAAM,oBAAuB,GAAA,CAAA,CAAA;AACtB,MAAM,qBAAwB,GAAA,EAAA;AAC9B,MAAM,wBAA2B,GAAA,GAAA;AACjC,MAAM,yCAA4C,GAAA,GAAA;AAClD,MAAM,0BAA6B,GAAA,IAAA;AAEnC,SAAS,mBAAmB,OAAyC,EAAA;AAC1E,EAAM,MAAA,MAAA,GAAS,IAAI,MAAO,EAAA,CAAA;AAC1B,EAAA,MAAM,WAAqB,EAAC,CAAA;AAC5B,EAAA,MAAM,KAAQ,GAAA,GAAA,CAAA;AAEd,EAAO,OAAA,CAAC,QAAgB,eAAoC,KAAA;AAlB9D,IAAA,IAAA,EAAA,CAAA;AAmBI,IAAA,IAAI,WAAW,EAAI,EAAA;AACjB,MAAI,IAAA,OAAA,CAAQ,SAAS,KAAO,EAAA;AAC1B,QAAO,OAAA,OAAA,CAAQ,KAAM,CAAA,CAAA,EAAG,KAAK,CAAA,CAAA;AAAA,OACxB,MAAA;AACL,QAAO,OAAA,OAAA,CAAA;AAAA,OACT;AAAA,KACF;AAEA,IAAA,IAAI,oBAAoB,UAAY,EAAA;AAClC,MAAA,MAAM,oBAAoB,EAAC,CAAA;AAC3B,MAAA,KAAA,IAAS,CAAI,GAAA,CAAA,EAAG,CAAI,GAAA,OAAA,CAAQ,QAAQ,CAAK,EAAA,EAAA;AACvC,QAAK,IAAA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