@grafana/scenes 5.11.0 → 5.11.1--canary.830.10618954979.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 +126 -0
- package/dist/esm/variables/adhoc/AdHocFiltersCombobox/AdHocFilterPill.js.map +1 -0
- package/dist/esm/variables/adhoc/AdHocFiltersCombobox/AdHocFiltersAlwaysWipCombobox.js +20 -0
- package/dist/esm/variables/adhoc/AdHocFiltersCombobox/AdHocFiltersAlwaysWipCombobox.js.map +1 -0
- package/dist/esm/variables/adhoc/AdHocFiltersCombobox/AdHocFiltersCombobox.js +371 -0
- package/dist/esm/variables/adhoc/AdHocFiltersCombobox/AdHocFiltersCombobox.js.map +1 -0
- package/dist/esm/variables/adhoc/AdHocFiltersCombobox/AdHocFiltersComboboxRenderer.js +64 -0
- package/dist/esm/variables/adhoc/AdHocFiltersCombobox/AdHocFiltersComboboxRenderer.js.map +1 -0
- package/dist/esm/variables/adhoc/AdHocFiltersCombobox/DropdownItem.js +102 -0
- package/dist/esm/variables/adhoc/AdHocFiltersCombobox/DropdownItem.js.map +1 -0
- package/dist/esm/variables/adhoc/AdHocFiltersCombobox/useFloatingInteractions.js +59 -0
- package/dist/esm/variables/adhoc/AdHocFiltersCombobox/useFloatingInteractions.js.map +1 -0
- package/dist/esm/variables/adhoc/AdHocFiltersCombobox/utils.js +111 -0
- package/dist/esm/variables/adhoc/AdHocFiltersCombobox/utils.js.map +1 -0
- package/dist/esm/variables/adhoc/AdHocFiltersVariable.js +44 -27
- package/dist/esm/variables/adhoc/AdHocFiltersVariable.js.map +1 -1
- package/dist/index.d.ts +3 -1
- package/dist/index.js +1063 -238
- package/dist/index.js.map +1 -1
- package/package.json +4 -2
@@ -0,0 +1,64 @@
|
|
1
|
+
import { cx, css } from '@emotion/css';
|
2
|
+
import { useStyles2, Icon } from '@grafana/ui';
|
3
|
+
import React, { memo, useRef } from 'react';
|
4
|
+
import { AdHocFilterPill } from './AdHocFilterPill.js';
|
5
|
+
import { AdHocFiltersAlwaysWipCombobox } from './AdHocFiltersAlwaysWipCombobox.js';
|
6
|
+
|
7
|
+
const AdHocFiltersComboboxRenderer = memo(function AdHocFiltersComboboxRenderer2({ model }) {
|
8
|
+
const { filters, readOnly } = model.useState();
|
9
|
+
const styles = useStyles2(getStyles);
|
10
|
+
const focusOnInputRef = useRef();
|
11
|
+
return /* @__PURE__ */ React.createElement("div", {
|
12
|
+
className: cx(styles.comboboxWrapper, { [styles.comboboxFocusOutline]: !readOnly }),
|
13
|
+
onClick: () => {
|
14
|
+
var _a;
|
15
|
+
(_a = focusOnInputRef.current) == null ? void 0 : _a.call(focusOnInputRef);
|
16
|
+
}
|
17
|
+
}, /* @__PURE__ */ React.createElement(Icon, {
|
18
|
+
name: "filter",
|
19
|
+
className: styles.filterIcon,
|
20
|
+
size: "lg"
|
21
|
+
}), filters.map((filter, index) => /* @__PURE__ */ React.createElement(AdHocFilterPill, {
|
22
|
+
key: index,
|
23
|
+
filter,
|
24
|
+
model,
|
25
|
+
readOnly
|
26
|
+
})), !readOnly ? /* @__PURE__ */ React.createElement(AdHocFiltersAlwaysWipCombobox, {
|
27
|
+
model,
|
28
|
+
ref: focusOnInputRef
|
29
|
+
}) : null);
|
30
|
+
});
|
31
|
+
const getStyles = (theme) => ({
|
32
|
+
comboboxWrapper: css({
|
33
|
+
display: "flex",
|
34
|
+
flexWrap: "wrap",
|
35
|
+
alignItems: "center",
|
36
|
+
columnGap: theme.spacing(1),
|
37
|
+
rowGap: theme.spacing(0.5),
|
38
|
+
minHeight: theme.spacing(4),
|
39
|
+
backgroundColor: theme.components.input.background,
|
40
|
+
border: `1px solid ${theme.colors.border.strong}`,
|
41
|
+
borderRadius: theme.shape.radius.default,
|
42
|
+
paddingInline: theme.spacing(1),
|
43
|
+
paddingBlock: theme.spacing(0.5),
|
44
|
+
flexGrow: 1
|
45
|
+
}),
|
46
|
+
comboboxFocusOutline: css({
|
47
|
+
"&:focus-within": {
|
48
|
+
outline: "2px dotted transparent",
|
49
|
+
outlineOffset: "2px",
|
50
|
+
boxShadow: `0 0 0 2px ${theme.colors.background.canvas}, 0 0 0px 4px ${theme.colors.primary.main}`,
|
51
|
+
transitionTimingFunction: `cubic-bezier(0.19, 1, 0.22, 1)`,
|
52
|
+
transitionDuration: "0.2s",
|
53
|
+
transitionProperty: "outline, outline-offset, box-shadow",
|
54
|
+
zIndex: 2
|
55
|
+
}
|
56
|
+
}),
|
57
|
+
filterIcon: css({
|
58
|
+
color: theme.colors.text.secondary,
|
59
|
+
alignSelf: "center"
|
60
|
+
})
|
61
|
+
});
|
62
|
+
|
63
|
+
export { AdHocFiltersComboboxRenderer };
|
64
|
+
//# sourceMappingURL=AdHocFiltersComboboxRenderer.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"AdHocFiltersComboboxRenderer.js","sources":["../../../../../src/variables/adhoc/AdHocFiltersCombobox/AdHocFiltersComboboxRenderer.tsx"],"sourcesContent":["import { css, cx } from '@emotion/css';\nimport { GrafanaTheme2 } from '@grafana/data';\nimport { Icon, useStyles2 } from '@grafana/ui';\nimport React, { memo, useRef } from 'react';\nimport { AdHocFiltersVariable } from '../AdHocFiltersVariable';\nimport { AdHocFilterPill } from './AdHocFilterPill';\nimport { AdHocFiltersAlwaysWipCombobox } from './AdHocFiltersAlwaysWipCombobox';\n\ninterface Props {\n model: AdHocFiltersVariable;\n}\n\nexport const AdHocFiltersComboboxRenderer = memo(function AdHocFiltersComboboxRenderer({ model }: Props) {\n const { filters, readOnly } = model.useState();\n const styles = useStyles2(getStyles);\n const focusOnInputRef = useRef<() => void>();\n\n return (\n <div\n className={cx(styles.comboboxWrapper, { [styles.comboboxFocusOutline]: !readOnly })}\n onClick={() => {\n focusOnInputRef.current?.();\n }}\n >\n <Icon name=\"filter\" className={styles.filterIcon} size=\"lg\" />\n\n {filters.map((filter, index) => (\n <AdHocFilterPill key={index} filter={filter} model={model} readOnly={readOnly} />\n ))}\n\n {!readOnly ? <AdHocFiltersAlwaysWipCombobox model={model} ref={focusOnInputRef} /> : null}\n </div>\n );\n});\n\nconst getStyles = (theme: GrafanaTheme2) => ({\n comboboxWrapper: css({\n display: 'flex',\n flexWrap: 'wrap',\n alignItems: 'center',\n columnGap: theme.spacing(1),\n rowGap: theme.spacing(0.5),\n minHeight: theme.spacing(4),\n backgroundColor: theme.components.input.background,\n border: `1px solid ${theme.colors.border.strong}`,\n borderRadius: theme.shape.radius.default,\n paddingInline: theme.spacing(1),\n paddingBlock: theme.spacing(0.5),\n flexGrow: 1,\n }),\n comboboxFocusOutline: css({\n '&:focus-within': {\n outline: '2px dotted transparent',\n outlineOffset: '2px',\n boxShadow: `0 0 0 2px ${theme.colors.background.canvas}, 0 0 0px 4px ${theme.colors.primary.main}`,\n transitionTimingFunction: `cubic-bezier(0.19, 1, 0.22, 1)`,\n transitionDuration: '0.2s',\n transitionProperty: 'outline, outline-offset, box-shadow',\n zIndex: 2,\n },\n }),\n filterIcon: css({\n color: theme.colors.text.secondary,\n alignSelf: 'center',\n }),\n});\n"],"names":["AdHocFiltersComboboxRenderer"],"mappings":";;;;;;AAYO,MAAM,+BAA+B,IAAK,CAAA,SAASA,6BAA6B,CAAA,EAAE,OAAgB,EAAA;AACvG,EAAA,MAAM,EAAE,OAAA,EAAS,QAAS,EAAA,GAAI,MAAM,QAAS,EAAA,CAAA;AAC7C,EAAM,MAAA,MAAA,GAAS,WAAW,SAAS,CAAA,CAAA;AACnC,EAAA,MAAM,kBAAkB,MAAmB,EAAA,CAAA;AAE3C,EAAA,uBACG,KAAA,CAAA,aAAA,CAAA,KAAA,EAAA;AAAA,IACC,SAAA,EAAW,EAAG,CAAA,MAAA,CAAO,eAAiB,EAAA,EAAE,CAAC,MAAO,CAAA,oBAAA,GAAuB,CAAC,QAAA,EAAU,CAAA;AAAA,IAClF,SAAS,MAAM;AApBrB,MAAA,IAAA,EAAA,CAAA;AAqBQ,MAAA,CAAA,EAAA,GAAA,eAAA,CAAgB,OAAhB,KA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KAAM,CAAA,OAAA,CAAQ,CAAC,CAAA;AAAA,IAC9B,YAAA,EAAc,KAAM,CAAA,OAAA,CAAQ,GAAG,CAAA;AAAA,IAC/B,QAAU,EAAA,CAAA;AAAA,GACX,CAAA;AAAA,EACD,sBAAsB,GAAI,CAAA;AAAA,IACxB,gBAAkB,EAAA;AAAA,MAChB,OAAS,EAAA,wBAAA;AAAA,MACT,aAAe,EAAA,KAAA;AAAA,MACf,SAAA,EAAW,aAAa,KAAM,CAAA,MAAA,CAAO,WAAW,MAAuB,CAAA,cAAA,EAAA,KAAA,CAAM,OAAO,OAAQ,CAAA,IAAA,CAAA,CAAA;AAAA,MAC5F,wBAA0B,EAAA,CAAA,8BAAA,CAAA;AAAA,MAC1B,kBAAoB,EAAA,MAAA;AAAA,MACpB,kBAAoB,EAAA,qCAAA;AAAA,MACpB,MAAQ,EAAA,CAAA;AAAA,KACV;AAAA,GACD,CAAA;AAAA,EACD,YAAY,GAAI,CAAA;AAAA,IACd,KAAA,EAAO,KAAM,CAAA,MAAA,CAAO,IAAK,CAAA,SAAA;AAAA,IACzB,SAAW,EAAA,QAAA;AAAA,GACZ,CAAA;AACH,CAAA,CAAA;;;;"}
|
@@ -0,0 +1,102 @@
|
|
1
|
+
import { cx, css } from '@emotion/css';
|
2
|
+
import { useStyles2 } from '@grafana/ui';
|
3
|
+
import React, { forwardRef, useId } from 'react';
|
4
|
+
|
5
|
+
var __defProp = Object.defineProperty;
|
6
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
8
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
9
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
10
|
+
var __spreadValues = (a, b) => {
|
11
|
+
for (var prop in b || (b = {}))
|
12
|
+
if (__hasOwnProp.call(b, prop))
|
13
|
+
__defNormalProp(a, prop, b[prop]);
|
14
|
+
if (__getOwnPropSymbols)
|
15
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
16
|
+
if (__propIsEnum.call(b, prop))
|
17
|
+
__defNormalProp(a, prop, b[prop]);
|
18
|
+
}
|
19
|
+
return a;
|
20
|
+
};
|
21
|
+
var __objRest = (source, exclude) => {
|
22
|
+
var target = {};
|
23
|
+
for (var prop in source)
|
24
|
+
if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
|
25
|
+
target[prop] = source[prop];
|
26
|
+
if (source != null && __getOwnPropSymbols)
|
27
|
+
for (var prop of __getOwnPropSymbols(source)) {
|
28
|
+
if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
|
29
|
+
target[prop] = source[prop];
|
30
|
+
}
|
31
|
+
return target;
|
32
|
+
};
|
33
|
+
const DropdownItem = forwardRef(
|
34
|
+
function DropdownItem2(_a, ref) {
|
35
|
+
var _b = _a, { children, active, addGroupBottomBorder } = _b, rest = __objRest(_b, ["children", "active", "addGroupBottomBorder"]);
|
36
|
+
const styles = useStyles2(getStyles);
|
37
|
+
const id = useId();
|
38
|
+
return /* @__PURE__ */ React.createElement("div", __spreadValues({
|
39
|
+
ref,
|
40
|
+
role: "option",
|
41
|
+
id,
|
42
|
+
"aria-selected": active,
|
43
|
+
className: cx(styles.option, active && styles.optionFocused, addGroupBottomBorder && styles.groupBottomBorder)
|
44
|
+
}, rest), /* @__PURE__ */ React.createElement("div", {
|
45
|
+
className: styles.optionBody,
|
46
|
+
"data-testid": `data-testid ad hoc filter option value ${children}`
|
47
|
+
}, /* @__PURE__ */ React.createElement("span", null, children)));
|
48
|
+
}
|
49
|
+
);
|
50
|
+
const getStyles = (theme) => ({
|
51
|
+
option: css({
|
52
|
+
label: "grafana-select-option",
|
53
|
+
top: 0,
|
54
|
+
left: 0,
|
55
|
+
width: "100%",
|
56
|
+
position: "absolute",
|
57
|
+
padding: theme.spacing(1),
|
58
|
+
display: "flex",
|
59
|
+
alignItems: "center",
|
60
|
+
flexDirection: "row",
|
61
|
+
flexShrink: 0,
|
62
|
+
whiteSpace: "nowrap",
|
63
|
+
cursor: "pointer",
|
64
|
+
"&:hover": {
|
65
|
+
background: theme.colors.action.hover,
|
66
|
+
"@media (forced-colors: active), (prefers-contrast: more)": {
|
67
|
+
border: `1px solid ${theme.colors.primary.border}`
|
68
|
+
}
|
69
|
+
}
|
70
|
+
}),
|
71
|
+
optionFocused: css({
|
72
|
+
label: "grafana-select-option-focused",
|
73
|
+
background: theme.colors.action.focus,
|
74
|
+
"@media (forced-colors: active), (prefers-contrast: more)": {
|
75
|
+
border: `1px solid ${theme.colors.primary.border}`
|
76
|
+
}
|
77
|
+
}),
|
78
|
+
optionBody: css({
|
79
|
+
label: "grafana-select-option-body",
|
80
|
+
display: "flex",
|
81
|
+
fontWeight: theme.typography.fontWeightMedium,
|
82
|
+
flexDirection: "column",
|
83
|
+
flexGrow: 1
|
84
|
+
}),
|
85
|
+
groupBottomBorder: css({
|
86
|
+
borderBottom: `1px solid ${theme.colors.border.weak}`
|
87
|
+
})
|
88
|
+
});
|
89
|
+
const LoadingOptionsPlaceholder = () => {
|
90
|
+
return /* @__PURE__ */ React.createElement(DropdownItem, null, "Loading options...");
|
91
|
+
};
|
92
|
+
const NoOptionsPlaceholder = () => {
|
93
|
+
return /* @__PURE__ */ React.createElement(DropdownItem, null, "No options found");
|
94
|
+
};
|
95
|
+
const OptionsErrorPlaceholder = ({ handleFetchOptions }) => {
|
96
|
+
return /* @__PURE__ */ React.createElement(DropdownItem, {
|
97
|
+
onClick: handleFetchOptions
|
98
|
+
}, "An error has occurred fetching labels. Click to retry");
|
99
|
+
};
|
100
|
+
|
101
|
+
export { DropdownItem, LoadingOptionsPlaceholder, NoOptionsPlaceholder, OptionsErrorPlaceholder };
|
102
|
+
//# sourceMappingURL=DropdownItem.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"DropdownItem.js","sources":["../../../../../src/variables/adhoc/AdHocFiltersCombobox/DropdownItem.tsx"],"sourcesContent":["import { css, cx } from '@emotion/css';\nimport { GrafanaTheme2 } from '@grafana/data';\nimport { useStyles2 } from '@grafana/ui';\nimport React, { forwardRef, useId } from 'react';\n\ninterface DropdownItemProps {\n children: React.ReactNode;\n active?: boolean;\n addGroupBottomBorder?: boolean;\n}\n\nexport const DropdownItem = forwardRef<HTMLDivElement, DropdownItemProps & React.HTMLProps<HTMLDivElement>>(\n function DropdownItem({ children, active, addGroupBottomBorder, ...rest }, ref) {\n const styles = useStyles2(getStyles);\n const id = useId();\n return (\n <div\n ref={ref}\n role=\"option\"\n id={id}\n aria-selected={active}\n className={cx(styles.option, active && styles.optionFocused, addGroupBottomBorder && styles.groupBottomBorder)}\n {...rest}\n >\n <div className={styles.optionBody} data-testid={`data-testid ad hoc filter option value ${children}`}>\n <span>{children}</span>\n </div>\n </div>\n );\n }\n);\n\nconst getStyles = (theme: GrafanaTheme2) => ({\n option: css({\n label: 'grafana-select-option',\n top: 0,\n left: 0,\n width: '100%',\n position: 'absolute',\n padding: theme.spacing(1),\n display: 'flex',\n alignItems: 'center',\n flexDirection: 'row',\n flexShrink: 0,\n whiteSpace: 'nowrap',\n cursor: 'pointer',\n '&:hover': {\n background: theme.colors.action.hover,\n '@media (forced-colors: active), (prefers-contrast: more)': {\n border: `1px solid ${theme.colors.primary.border}`,\n },\n },\n }),\n optionFocused: css({\n label: 'grafana-select-option-focused',\n background: theme.colors.action.focus,\n '@media (forced-colors: active), (prefers-contrast: more)': {\n border: `1px solid ${theme.colors.primary.border}`,\n },\n }),\n optionBody: css({\n label: 'grafana-select-option-body',\n display: 'flex',\n fontWeight: theme.typography.fontWeightMedium,\n flexDirection: 'column',\n flexGrow: 1,\n }),\n groupBottomBorder: css({\n borderBottom: `1px solid ${theme.colors.border.weak}`,\n }),\n});\n\nexport const LoadingOptionsPlaceholder = () => {\n return <DropdownItem>Loading options...</DropdownItem>;\n};\n\nexport const NoOptionsPlaceholder = () => {\n return <DropdownItem>No options found</DropdownItem>;\n};\n\nexport const OptionsErrorPlaceholder = ({ handleFetchOptions }: { handleFetchOptions: () => void }) => {\n return (\n <DropdownItem onClick={handleFetchOptions}>An error has occurred fetching labels. Click to retry</DropdownItem>\n );\n};\n"],"names":["DropdownItem"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAWO,MAAM,YAAe,GAAA,UAAA;AAAA,EAC1B,SAASA,aAAa,CAAA,EAAA,EAAqD,GAAK,EAAA;AAA1D,IAAE,IAAA,EAAA,GAAA,EAAA,EAAA,EAAA,QAAA,EAAU,QAAQ,oBAZ5C,EAAA,GAYwB,IAA6C,IAA7C,GAAA,SAAA,CAAA,EAAA,EAA6C,CAA3C,UAAA,EAAU,QAAQ,EAAA,sBAAA,CAAA,CAAA,CAAA;AACxC,IAAM,MAAA,MAAA,GAAS,WAAW,SAAS,CAAA,CAAA;AACnC,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,SAAA,EAAW,GAAG,MAAO,CAAA,MAAA,EAAQ,UAAU,MAAO,CAAA,aAAA,EAAe,oBAAwB,IAAA,MAAA,CAAO,iBAAiB,CAAA;AAAA,KAAA,EACzG,uBAEH,KAAA,CAAA,aAAA,CAAA,KAAA,EAAA;AAAA,MAAI,WAAW,MAAO,CAAA,UAAA;AAAA,MAAY,eAAa,CAA0C,uCAAA,EAAA,QAAA,CAAA,CAAA;AAAA,KAAA,kBACvF,KAAA,CAAA,aAAA,CAAA,MAAA,EAAA,IAAA,EAAM,QAAS,CAClB,CACF,CAAA,CAAA;AAAA,GAEJ;AACF,EAAA;AAEA,MAAM,SAAA,GAAY,CAAC,KAA0B,MAAA;AAAA,EAC3C,QAAQ,GAAI,CAAA;AAAA,IAC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AA,IAAA,CAAA,CAAA;AAAA,GAChD,CAAA;AACH,CAAA,CAAA,CAAA;AAEO,MAAM,4BAA4B,MAAM;AAC7C,EAAO,uBAAA,KAAA,CAAA,aAAA,CAAC,oBAAa,oBAAkB,CAAA,CAAA;AACzC,EAAA;AAEO,MAAM,uBAAuB,MAAM;AACxC,EAAO,uBAAA,KAAA,CAAA,aAAA,CAAC,oBAAa,kBAAgB,CAAA,CAAA;AACvC,EAAA;AAEO,MAAM,uBAA0B,GAAA,CAAC,EAAE,kBAAA,EAA6D,KAAA;AACrG,EAAA,uBACG,KAAA,CAAA,aAAA,CAAA,YAAA,EAAA;AAAA,IAAa,OAAS,EAAA,kBAAA;AAAA,GAAA,EAAoB,uDAAqD,CAAA,CAAA;AAEpG;;;;"}
|
@@ -0,0 +1,59 @@
|
|
1
|
+
import { useFloating, autoUpdate, offset, flip, size, useRole, useDismiss, useListNavigation, useInteractions } from '@floating-ui/react';
|
2
|
+
|
3
|
+
const MAX_MENU_HEIGHT = 300;
|
4
|
+
const useFloatingInteractions = ({
|
5
|
+
open,
|
6
|
+
onOpenChange,
|
7
|
+
activeIndex,
|
8
|
+
setActiveIndex,
|
9
|
+
operatorIdentifier,
|
10
|
+
listRef,
|
11
|
+
disabledIndicesRef
|
12
|
+
}) => {
|
13
|
+
const { refs, floatingStyles, context } = useFloating({
|
14
|
+
whileElementsMounted: autoUpdate,
|
15
|
+
open,
|
16
|
+
onOpenChange,
|
17
|
+
placement: "bottom-start",
|
18
|
+
middleware: [
|
19
|
+
offset(10),
|
20
|
+
flip({ padding: 10 }),
|
21
|
+
size({
|
22
|
+
apply({ availableHeight, availableWidth, elements }) {
|
23
|
+
elements.floating.style.maxHeight = `${Math.min(MAX_MENU_HEIGHT, availableHeight)}px`;
|
24
|
+
elements.floating.style.maxWidth = `${availableWidth}px`;
|
25
|
+
},
|
26
|
+
padding: 10
|
27
|
+
})
|
28
|
+
]
|
29
|
+
});
|
30
|
+
const role = useRole(context, { role: "listbox" });
|
31
|
+
const dismiss = useDismiss(context, {
|
32
|
+
outsidePress: (event) => {
|
33
|
+
if (event.currentTarget instanceof HTMLElement && event.currentTarget.id === operatorIdentifier) {
|
34
|
+
return false;
|
35
|
+
}
|
36
|
+
return true;
|
37
|
+
}
|
38
|
+
});
|
39
|
+
const listNav = useListNavigation(context, {
|
40
|
+
listRef,
|
41
|
+
activeIndex,
|
42
|
+
onNavigate: setActiveIndex,
|
43
|
+
virtual: true,
|
44
|
+
loop: true,
|
45
|
+
disabledIndices: disabledIndicesRef.current
|
46
|
+
});
|
47
|
+
const { getReferenceProps, getFloatingProps, getItemProps } = useInteractions([role, dismiss, listNav]);
|
48
|
+
return {
|
49
|
+
refs,
|
50
|
+
floatingStyles,
|
51
|
+
context,
|
52
|
+
getReferenceProps,
|
53
|
+
getFloatingProps,
|
54
|
+
getItemProps
|
55
|
+
};
|
56
|
+
};
|
57
|
+
|
58
|
+
export { useFloatingInteractions };
|
59
|
+
//# sourceMappingURL=useFloatingInteractions.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"useFloatingInteractions.js","sources":["../../../../../src/variables/adhoc/AdHocFiltersCombobox/useFloatingInteractions.ts"],"sourcesContent":["import {\n useFloating,\n autoUpdate,\n offset,\n useRole,\n useDismiss,\n useListNavigation,\n UseFloatingOptions,\n flip,\n size,\n UseListNavigationProps,\n useInteractions,\n} from '@floating-ui/react';\n\ntype useFloatingInteractionsProps = {\n open: UseFloatingOptions['open'];\n onOpenChange: UseFloatingOptions['onOpenChange'];\n activeIndex: UseListNavigationProps['activeIndex'];\n setActiveIndex: UseListNavigationProps['onNavigate'];\n operatorIdentifier: string;\n listRef: React.MutableRefObject<Array<HTMLElement | null>>;\n disabledIndicesRef: React.MutableRefObject<number[]>;\n};\n\nconst MAX_MENU_HEIGHT = 300;\n\nexport const useFloatingInteractions = ({\n open,\n onOpenChange,\n activeIndex,\n setActiveIndex,\n operatorIdentifier,\n listRef,\n disabledIndicesRef,\n}: useFloatingInteractionsProps) => {\n const { refs, floatingStyles, context } = useFloating<HTMLInputElement>({\n whileElementsMounted: autoUpdate,\n open,\n onOpenChange,\n placement: 'bottom-start',\n middleware: [\n offset(10),\n flip({ padding: 10 }),\n size({\n apply({ availableHeight, availableWidth, elements }) {\n // limit maxHeight and maxWidth of dropdown\n elements.floating.style.maxHeight = `${Math.min(MAX_MENU_HEIGHT, availableHeight)}px`;\n elements.floating.style.maxWidth = `${availableWidth}px`;\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 // if outside click lands on operator pill, then ignore outside click\n if (event.currentTarget instanceof HTMLElement && event.currentTarget.id === operatorIdentifier) {\n return false;\n }\n return true;\n },\n });\n const listNav = useListNavigation(context, {\n listRef,\n activeIndex,\n onNavigate: setActiveIndex,\n virtual: true,\n loop: true,\n disabledIndices: disabledIndicesRef.current,\n });\n\n const { getReferenceProps, getFloatingProps, getItemProps } = useInteractions([role, dismiss, listNav]);\n\n return {\n refs,\n floatingStyles,\n context,\n getReferenceProps,\n getFloatingProps,\n getItemProps,\n };\n};\n"],"names":[],"mappings":";;AAwBA,MAAM,eAAkB,GAAA,GAAA,CAAA;AAEjB,MAAM,0BAA0B,CAAC;AAAA,EACtC,IAAA;AAAA,EACA,YAAA;AAAA,EACA,WAAA;AAAA,EACA,cAAA;AAAA,EACA,kBAAA;AAAA,EACA,OAAA;AAAA,EACA,kBAAA;AACF,CAAoC,KAAA;AAClC,EAAA,MAAM,EAAE,IAAA,EAAM,cAAgB,EAAA,OAAA,KAAY,WAA8B,CAAA;AAAA,IACtE,oBAAsB,EAAA,UAAA;AAAA,IACtB,IAAA;AAAA,IACA,YAAA;AAAA,IACA,SAAW,EAAA,cAAA;AAAA,IACX,UAAY,EAAA;AAAA,MACV,OAAO,EAAE,CAAA;AAAA,MACT,IAAK,CAAA,EAAE,OAAS,EAAA,EAAA,EAAI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A;AAAA,IACA,iBAAA;AAAA,IACA,gBAAA;AAAA,IACA,YAAA;AAAA,GACF,CAAA;AACF;;;;"}
|
@@ -0,0 +1,111 @@
|
|
1
|
+
import uFuzzy from '@leeoniya/ufuzzy';
|
2
|
+
|
3
|
+
const VIRTUAL_LIST_WIDTH_ESTIMATE_MULTIPLIER = 8;
|
4
|
+
const VIRTUAL_LIST_PADDING = 8;
|
5
|
+
const VIRTUAL_LIST_OVERSCAN = 5;
|
6
|
+
const VIRTUAL_LIST_ITEM_HEIGHT = 38;
|
7
|
+
const ERROR_STATE_DROPDOWN_WIDTH = 366;
|
8
|
+
function fuzzySearchOptions(options) {
|
9
|
+
const ufuzzy = new uFuzzy();
|
10
|
+
const haystack = [];
|
11
|
+
const limit = 1e4;
|
12
|
+
return (search, filterInputType) => {
|
13
|
+
var _a;
|
14
|
+
if (search === "") {
|
15
|
+
if (options.length > limit) {
|
16
|
+
return options.slice(0, limit);
|
17
|
+
} else {
|
18
|
+
return options;
|
19
|
+
}
|
20
|
+
}
|
21
|
+
if (filterInputType === "operator") {
|
22
|
+
const filteredOperators = [];
|
23
|
+
for (let i = 0; i < options.length; i++) {
|
24
|
+
if ((_a = options[i].label || options[i].value) == null ? void 0 : _a.includes(search)) {
|
25
|
+
filteredOperators.push(options[i]);
|
26
|
+
if (filteredOperators.length > limit) {
|
27
|
+
return filteredOperators;
|
28
|
+
}
|
29
|
+
}
|
30
|
+
}
|
31
|
+
return filteredOperators;
|
32
|
+
}
|
33
|
+
if (haystack.length === 0) {
|
34
|
+
for (let i = 0; i < options.length; i++) {
|
35
|
+
haystack.push(options[i].label || options[i].value);
|
36
|
+
}
|
37
|
+
}
|
38
|
+
const idxs = ufuzzy.filter(haystack, search);
|
39
|
+
const filteredOptions = [];
|
40
|
+
if (idxs) {
|
41
|
+
for (let i = 0; i < idxs.length; i++) {
|
42
|
+
filteredOptions.push(options[idxs[i]]);
|
43
|
+
if (filteredOptions.length > limit) {
|
44
|
+
return filteredOptions;
|
45
|
+
}
|
46
|
+
}
|
47
|
+
return filteredOptions;
|
48
|
+
}
|
49
|
+
if (options.length > limit) {
|
50
|
+
return options.slice(0, limit);
|
51
|
+
}
|
52
|
+
return options;
|
53
|
+
};
|
54
|
+
}
|
55
|
+
const flattenOptionGroups = (options) => options.flatMap((option) => option.options ? [option, ...option.options] : [option]);
|
56
|
+
const setupDropdownAccessibility = (options, listRef, disabledIndicesRef) => {
|
57
|
+
var _a, _b, _c;
|
58
|
+
let maxOptionWidth = 182;
|
59
|
+
const listRefArr = [];
|
60
|
+
const disabledIndices = [];
|
61
|
+
for (let i = 0; i < options.length; i++) {
|
62
|
+
listRefArr.push(null);
|
63
|
+
if ((_a = options[i]) == null ? void 0 : _a.options) {
|
64
|
+
disabledIndices.push(i);
|
65
|
+
}
|
66
|
+
let label = (_c = (_b = options[i].label) != null ? _b : options[i].value) != null ? _c : "";
|
67
|
+
const widthEstimate = (options[i].isCustom ? label.length + 18 : label.length) * VIRTUAL_LIST_WIDTH_ESTIMATE_MULTIPLIER + VIRTUAL_LIST_PADDING * 2;
|
68
|
+
if (widthEstimate > maxOptionWidth) {
|
69
|
+
maxOptionWidth = widthEstimate;
|
70
|
+
}
|
71
|
+
}
|
72
|
+
listRef.current = [...listRefArr];
|
73
|
+
disabledIndicesRef.current = [...disabledIndices];
|
74
|
+
return maxOptionWidth;
|
75
|
+
};
|
76
|
+
const nextInputTypeMap = {
|
77
|
+
key: "operator",
|
78
|
+
operator: "value",
|
79
|
+
value: "key"
|
80
|
+
};
|
81
|
+
const switchToNextInputType = (filterInputType, setInputType, handleChangeViewMode, element) => switchInputType(
|
82
|
+
nextInputTypeMap[filterInputType],
|
83
|
+
setInputType,
|
84
|
+
filterInputType === "value" ? handleChangeViewMode : void 0,
|
85
|
+
element
|
86
|
+
);
|
87
|
+
const switchInputType = (filterInputType, setInputType, handleChangeViewMode, element) => {
|
88
|
+
setInputType(filterInputType);
|
89
|
+
handleChangeViewMode == null ? void 0 : handleChangeViewMode();
|
90
|
+
setTimeout(() => element == null ? void 0 : element.focus());
|
91
|
+
};
|
92
|
+
const generateFilterUpdatePayload = (filterInputType, item) => {
|
93
|
+
if (filterInputType === "key") {
|
94
|
+
return {
|
95
|
+
key: item.value,
|
96
|
+
keyLabel: item.label ? item.label : item.value
|
97
|
+
};
|
98
|
+
}
|
99
|
+
if (filterInputType === "value") {
|
100
|
+
return {
|
101
|
+
value: item.value,
|
102
|
+
valueLabels: [item.label ? item.label : item.value]
|
103
|
+
};
|
104
|
+
}
|
105
|
+
return {
|
106
|
+
[filterInputType]: item.value
|
107
|
+
};
|
108
|
+
};
|
109
|
+
|
110
|
+
export { ERROR_STATE_DROPDOWN_WIDTH, VIRTUAL_LIST_ITEM_HEIGHT, VIRTUAL_LIST_OVERSCAN, flattenOptionGroups, fuzzySearchOptions, generateFilterUpdatePayload, setupDropdownAccessibility, switchInputType, switchToNextInputType };
|
111
|
+
//# sourceMappingURL=utils.js.map
|
@@ -0,0 +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 { AdHocFiltersVariable, AdHocFilterWithLabels } from '../AdHocFiltersVariable';\nimport { UseFloatingReturn } from '@floating-ui/react';\n\nconst VIRTUAL_LIST_WIDTH_ESTIMATE_MULTIPLIER = 8;\nconst VIRTUAL_LIST_PADDING = 8;\nexport const VIRTUAL_LIST_OVERSCAN = 5;\nexport const VIRTUAL_LIST_ITEM_HEIGHT = 38;\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 = ufuzzy.filter(haystack, search);\n const filteredOptions: Array<SelectableValue<string>> = [];\n\n if (idxs) {\n for (let i = 0; i < idxs.length; i++) {\n filteredOptions.push(options[idxs[i]]);\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\n // rough widthEstimate\n const widthEstimate =\n (options[i].isCustom ? label.length + 18 : label.length) * VIRTUAL_LIST_WIDTH_ESTIMATE_MULTIPLIER +\n 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\n// WIP: POC for parsing key and operator values automatically\nexport const filterAutoParser = ({\n event,\n filterInputType,\n options,\n model,\n filter,\n setInputValue,\n setInputType,\n refs,\n}: {\n event: React.ChangeEvent<HTMLInputElement>;\n filterInputType: AdHocInputType;\n options: Array<SelectableValue<string>>;\n model: AdHocFiltersVariable;\n filter: AdHocFilterWithLabels | undefined;\n setInputValue: (value: React.SetStateAction<string>) => void;\n setInputType: (value: React.SetStateAction<AdHocInputType>) => void;\n refs: UseFloatingReturn<HTMLInputElement>['refs'];\n}) => {\n // // part of POC for seamless filter parser\n if (filterInputType === '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(filter!, generateFilterUpdatePayload(filterInputType, options[optionIndex]));\n setInputValue(lastChar);\n }\n switchInputType('operator', setInputType, undefined, refs.domReference.current);\n return;\n }\n }\n if (filterInputType === '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(filter!, generateFilterUpdatePayload(filterInputType, options[optionIndex]));\n setInputValue(lastChar);\n }\n switchInputType('value', setInputType, undefined, refs.domReference.current);\n return;\n }\n }\n }\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: (() => void) | undefined,\n element: HTMLInputElement | null\n) =>\n switchInputType(\n nextInputTypeMap[filterInputType],\n setInputType,\n filterInputType === 'value' ? handleChangeViewMode : undefined,\n element\n );\n\nexport const switchInputType = (\n filterInputType: AdHocInputType,\n setInputType: React.Dispatch<React.SetStateAction<AdHocInputType>>,\n handleChangeViewMode?: () => void,\n element?: HTMLInputElement | null\n) => {\n setInputType(filterInputType);\n\n handleChangeViewMode?.();\n\n setTimeout(() => element?.focus());\n};\n\nexport const generateFilterUpdatePayload = (\n filterInputType: AdHocInputType,\n item: SelectableValue<string>\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 return {\n [filterInputType]: item.value,\n };\n};\n"],"names":[],"mappings":";;AAMA,MAAM,sCAAyC,GAAA,CAAA,CAAA;AAC/C,MAAM,oBAAuB,GAAA,CAAA,CAAA;AACtB,MAAM,qBAAwB,GAAA,EAAA;AAC9B,MAAM,wBAA2B,GAAA,GAAA;AACjC,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;AAjB9D,IAAA,IAAA,EAAA,CAAA;AAkBI,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,CAAA,EA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Q,IAAK,CAAA,KAAA,GAAQ,KAAK,KAAM,CAAA;AAAA,KACrD,CAAA;AAAA,GACF;AAEA,EAAO,OAAA;AAAA,IACL,CAAC,kBAAkB,IAAK,CAAA,KAAA;AAAA,GAC1B,CAAA;AACF;;;;"}
|
@@ -11,6 +11,7 @@ import { getDataSourceSrv } from '@grafana/runtime';
|
|
11
11
|
import { AdHocFiltersVariableUrlSyncHandler } from './AdHocFiltersVariableUrlSyncHandler.js';
|
12
12
|
import { css } from '@emotion/css';
|
13
13
|
import { getEnrichedFiltersRequest } from '../getEnrichedFiltersRequest.js';
|
14
|
+
import { AdHocFiltersComboboxRenderer } from './AdHocFiltersCombobox/AdHocFiltersComboboxRenderer.js';
|
14
15
|
import { wrapInSafeSerializableSceneObject } from '../../utils/wrapInSafeSerializableSceneObject.js';
|
15
16
|
|
16
17
|
var __defProp = Object.defineProperty;
|
@@ -29,29 +30,38 @@ var __spreadValues = (a, b) => {
|
|
29
30
|
}
|
30
31
|
return a;
|
31
32
|
};
|
32
|
-
const OPERATORS = [
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
},
|
53
|
-
|
54
|
-
|
33
|
+
const OPERATORS = [
|
34
|
+
{
|
35
|
+
value: "="
|
36
|
+
},
|
37
|
+
{
|
38
|
+
value: "!="
|
39
|
+
},
|
40
|
+
{
|
41
|
+
value: "=|",
|
42
|
+
description: "Is one of. Use to filter on multiple values.",
|
43
|
+
isMulti: true
|
44
|
+
},
|
45
|
+
{
|
46
|
+
value: "!=|",
|
47
|
+
description: "Is not one of. Use to exclude multiple values.",
|
48
|
+
isMulti: true
|
49
|
+
},
|
50
|
+
{
|
51
|
+
value: "=~",
|
52
|
+
description: "Matches regex"
|
53
|
+
},
|
54
|
+
{
|
55
|
+
value: "!~",
|
56
|
+
description: "Does not match regex"
|
57
|
+
},
|
58
|
+
{
|
59
|
+
value: "<"
|
60
|
+
},
|
61
|
+
{
|
62
|
+
value: ">"
|
63
|
+
}
|
64
|
+
];
|
55
65
|
class AdHocFiltersVariable extends SceneObjectBase {
|
56
66
|
constructor(state) {
|
57
67
|
var _a, _b;
|
@@ -106,6 +116,12 @@ class AdHocFiltersVariable extends SceneObjectBase {
|
|
106
116
|
}
|
107
117
|
this.setState({ filters: this.state.filters.filter((f) => f !== filter) });
|
108
118
|
}
|
119
|
+
_removeLastFilter() {
|
120
|
+
const filterToRemove = this.state.filters.at(-1);
|
121
|
+
if (filterToRemove) {
|
122
|
+
this._removeFilter(filterToRemove);
|
123
|
+
}
|
124
|
+
}
|
109
125
|
async _getKeys(currentKey) {
|
110
126
|
var _a, _b, _c;
|
111
127
|
const override = await ((_b = (_a = this.state).getTagKeysProvider) == null ? void 0 : _b.call(_a, this, currentKey));
|
@@ -189,6 +205,11 @@ function renderExpression(builder, filters) {
|
|
189
205
|
function AdHocFiltersVariableRenderer({ model }) {
|
190
206
|
const { filters, readOnly, addFilterButtonText } = model.useState();
|
191
207
|
const styles = useStyles2(getStyles);
|
208
|
+
if (!model.state.supportsMultiValueOperators && model.state.layout === "combobox") {
|
209
|
+
return /* @__PURE__ */ React.createElement(AdHocFiltersComboboxRenderer, {
|
210
|
+
model
|
211
|
+
});
|
212
|
+
}
|
192
213
|
return /* @__PURE__ */ React.createElement("div", {
|
193
214
|
className: styles.wrapper
|
194
215
|
}, filters.map((filter, index) => /* @__PURE__ */ React.createElement(React.Fragment, {
|
@@ -209,10 +230,6 @@ const getStyles = (theme) => ({
|
|
209
230
|
alignItems: "flex-end",
|
210
231
|
columnGap: theme.spacing(2),
|
211
232
|
rowGap: theme.spacing(1)
|
212
|
-
}),
|
213
|
-
filterIcon: css({
|
214
|
-
color: theme.colors.text.secondary,
|
215
|
-
paddingRight: theme.spacing(0.5)
|
216
233
|
})
|
217
234
|
});
|
218
235
|
function toSelectableValue(input) {
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"AdHocFiltersVariable.js","sources":["../../../../src/variables/adhoc/AdHocFiltersVariable.tsx"],"sourcesContent":["import React from 'react';\n// @ts-expect-error Remove when 11.1.x is released\nimport { AdHocVariableFilter, GetTagResponse, GrafanaTheme2, MetricFindValue, SelectableValue } from '@grafana/data';\nimport { SceneObjectBase } from '../../core/SceneObjectBase';\nimport { SceneVariable, SceneVariableState, SceneVariableValueChangedEvent, VariableValue } from '../types';\nimport { ControlsLayout, SceneComponentProps } from '../../core/types';\nimport { DataSourceRef } from '@grafana/schema';\nimport { dataFromResponse, getQueriesForVariables, renderPrometheusLabelFilters, responseHasError } from '../utils';\nimport { patchGetAdhocFilters } from './patchGetAdhocFilters';\nimport { useStyles2 } from '@grafana/ui';\nimport { sceneGraph } from '../../core/sceneGraph';\nimport { AdHocFilterBuilder } from './AdHocFilterBuilder';\nimport { AdHocFilterRenderer } from './AdHocFilterRenderer';\nimport { getDataSourceSrv } from '@grafana/runtime';\nimport { AdHocFiltersVariableUrlSyncHandler } from './AdHocFiltersVariableUrlSyncHandler';\nimport { css } from '@emotion/css';\nimport { getEnrichedFiltersRequest } from '../getEnrichedFiltersRequest';\nimport { wrapInSafeSerializableSceneObject } from '../../utils/wrapInSafeSerializableSceneObject';\n\nexport interface AdHocFilterWithLabels extends AdHocVariableFilter {\n keyLabel?: string;\n valueLabels?: string[];\n}\nexport interface AdHocFiltersVariableState extends SceneVariableState {\n /** Optional text to display on the 'add filter' button */\n addFilterButtonText?: string;\n /** The visible filters */\n filters: AdHocFilterWithLabels[];\n /** Base filters to always apply when looking up keys*/\n baseFilters?: AdHocFilterWithLabels[];\n /** Datasource to use for getTagKeys and getTagValues and also controls which scene queries the filters should apply to */\n datasource: DataSourceRef | null;\n /** Controls if the filters can be changed */\n readOnly?: boolean;\n /**\n * @experimental\n * Controls the layout and design of the label.\n */\n layout?: ControlsLayout;\n /**\n * Defaults to automatic which means filters will automatically be applied to all queries with the same data source as this AdHocFilterSet.\n * In manual mode you either have to use the filters programmatically or as a variable inside query expressions.\n */\n applyMode: 'auto' | 'manual';\n /**\n * Filter out the keys that do not match the regex.\n */\n tagKeyRegexFilter?: RegExp;\n /**\n * Extension hook for customizing the key lookup.\n * Return replace: true if you want to override the default lookup\n * Return replace: false if you want to combine the results with the default lookup\n */\n getTagKeysProvider?: getTagKeysProvider;\n /**\n * Extension hook for customizing the value lookup.\n * Return replace: true if you want to override the default lookup.\n * Return replace: false if you want to combine the results with the default lookup\n */\n getTagValuesProvider?: getTagValuesProvider;\n\n /**\n * Optionally provide an array of static keys that override getTagKeys\n */\n defaultKeys?: MetricFindValue[];\n\n /**\n * This is the expression that the filters resulted in. Defaults to\n * Prometheus / Loki compatible label filter expression\n */\n filterExpression?: string;\n\n /**\n * The default builder creates a Prometheus/Loki compatible filter expression,\n * this can be overridden to create a different expression based on the current filters.\n */\n expressionBuilder?: AdHocVariableExpressionBuilderFn;\n\n /**\n * Whether the filter supports new multi-value operators like =| and !=|\n */\n supportsMultiValueOperators?: boolean;\n\n /**\n * When querying the datasource for label names and values to determine keys and values\n * for this ad hoc filter, consider the queries in the scene and use them as a filter.\n * This queries filter can be used to ensure that only ad hoc filter options that would\n * impact the current queries are presented to the user.\n */\n useQueriesAsFilterForOptions?: boolean;\n\n /**\n * @internal state of the new filter being added\n */\n _wip?: AdHocFilterWithLabels;\n}\n\nexport type AdHocVariableExpressionBuilderFn = (filters: AdHocFilterWithLabels[]) => string;\n\nexport type getTagKeysProvider = (\n variable: AdHocFiltersVariable,\n currentKey: string | null\n) => Promise<{ replace?: boolean; values: GetTagResponse | MetricFindValue[] }>;\n\nexport type getTagValuesProvider = (\n variable: AdHocFiltersVariable,\n filter: AdHocFilterWithLabels\n) => Promise<{ replace?: boolean; values: GetTagResponse | MetricFindValue[] }>;\n\nexport type AdHocFiltersVariableCreateHelperArgs = AdHocFiltersVariableState;\n\nexport type OperatorDefinition = {\n value: string;\n description?: string;\n isMulti?: Boolean;\n};\n\nconst OPERATORS: OperatorDefinition[] = [{\n value: '=',\n}, {\n value: '!='\n}, {\n value: '=|',\n description: 'Is one of. Use to filter on multiple values.',\n isMulti: true,\n}, {\n value: '!=|',\n description: 'Is not one of. Use to exclude multiple values.',\n isMulti: true\n}, {\n value: '=~',\n description: 'Matches regex',\n}, {\n value: '!~',\n description: 'Does not match regex',\n}, {\n value: '<'\n}, {\n value: '>'\n}];\n\nexport class AdHocFiltersVariable\n extends SceneObjectBase<AdHocFiltersVariableState>\n implements SceneVariable<AdHocFiltersVariableState>\n{\n static Component = AdHocFiltersVariableRenderer;\n\n private _scopedVars = { __sceneObject: wrapInSafeSerializableSceneObject(this) };\n private _dataSourceSrv = getDataSourceSrv();\n\n protected _urlSync = new AdHocFiltersVariableUrlSyncHandler(this);\n\n public constructor(state: Partial<AdHocFiltersVariableState>) {\n super({\n type: 'adhoc',\n name: state.name ?? 'Filters',\n filters: [],\n datasource: null,\n applyMode: 'auto',\n filterExpression: state.filterExpression ?? renderExpression(state.expressionBuilder, state.filters),\n ...state,\n });\n\n if (this.state.applyMode === 'auto') {\n patchGetAdhocFilters(this);\n }\n }\n\n public setState(update: Partial<AdHocFiltersVariableState>): void {\n let filterExpressionChanged = false;\n\n if (update.filters && update.filters !== this.state.filters && !update.filterExpression) {\n update.filterExpression = renderExpression(this.state.expressionBuilder, update.filters);\n filterExpressionChanged = update.filterExpression !== this.state.filterExpression;\n }\n\n super.setState(update);\n\n if (filterExpressionChanged) {\n this.publishEvent(new SceneVariableValueChangedEvent(this), true);\n }\n }\n\n public getValue(): VariableValue | undefined {\n return this.state.filterExpression;\n }\n\n public _updateFilter(\n filter: AdHocFilterWithLabels,\n update: Partial<AdHocFilterWithLabels>\n ) {\n const { filters, _wip } = this.state;\n\n if (filter === _wip) {\n // If we set value we are done with this \"work in progress\" filter and we can add it\n if ('value' in update && update['value'] !== '') {\n this.setState({ filters: [...filters, { ..._wip, ...update }], _wip: undefined });\n } else {\n this.setState({ _wip: { ...filter, ...update } });\n }\n return;\n }\n\n const updatedFilters = this.state.filters.map((f) => {\n return f === filter ? { ...f, ...update } : f;\n });\n\n this.setState({ filters: updatedFilters });\n }\n\n public _removeFilter(filter: AdHocFilterWithLabels) {\n if (filter === this.state._wip) {\n this.setState({ _wip: undefined });\n return;\n }\n\n this.setState({ filters: this.state.filters.filter((f) => f !== filter) });\n }\n\n /**\n * Get possible keys given current filters. Do not call from plugins directly\n */\n public async _getKeys(currentKey: string | null): Promise<Array<SelectableValue<string>>> {\n const override = await this.state.getTagKeysProvider?.(this, currentKey);\n\n if (override && override.replace) {\n return dataFromResponse(override.values).map(toSelectableValue);\n }\n\n if (this.state.defaultKeys) {\n return this.state.defaultKeys.map(toSelectableValue);\n }\n\n const ds = await this._dataSourceSrv.get(this.state.datasource, this._scopedVars);\n if (!ds || !ds.getTagKeys) {\n return [];\n }\n\n const otherFilters = this.state.filters.filter((f) => f.key !== currentKey).concat(this.state.baseFilters ?? []);\n const timeRange = sceneGraph.getTimeRange(this).state.value;\n const queries = this.state.useQueriesAsFilterForOptions ? getQueriesForVariables(this) : undefined;\n const response = await ds.getTagKeys({\n filters: otherFilters,\n queries,\n timeRange,\n ...getEnrichedFiltersRequest(this),\n });\n\n if (responseHasError(response)) {\n // @ts-expect-error Remove when 11.1.x is released\n this.setState({ error: response.error.message });\n }\n\n let keys = dataFromResponse(response);\n if (override) {\n keys = keys.concat(dataFromResponse(override.values));\n }\n\n const tagKeyRegexFilter = this.state.tagKeyRegexFilter;\n if (tagKeyRegexFilter) {\n // @ts-expect-error Remove when 11.1.x is released\n keys = keys.filter((f) => f.text.match(tagKeyRegexFilter));\n }\n\n return keys.map(toSelectableValue);\n }\n\n /**\n * Get possible key values for a specific key given current filters. Do not call from plugins directly\n */\n public async _getValuesFor(filter: AdHocFilterWithLabels): Promise<Array<SelectableValue<string>>> {\n const override = await this.state.getTagValuesProvider?.(this, filter);\n\n if (override && override.replace) {\n return dataFromResponse(override.values).map(toSelectableValue);\n }\n\n const ds = await this._dataSourceSrv.get(this.state.datasource, this._scopedVars);\n\n if (!ds || !ds.getTagValues) {\n return [];\n }\n\n // Filter out the current filter key from the list of all filters\n const otherFilters = this.state.filters.filter((f) => f.key !== filter.key).concat(this.state.baseFilters ?? []);\n\n const timeRange = sceneGraph.getTimeRange(this).state.value;\n const queries = this.state.useQueriesAsFilterForOptions ? getQueriesForVariables(this) : undefined;\n\n const response = await ds.getTagValues({\n key: filter.key,\n filters: otherFilters,\n timeRange, // @ts-expect-error TODO: remove this once 11.1.x is released\n queries,\n ...getEnrichedFiltersRequest(this),\n });\n\n if (responseHasError(response)) {\n // @ts-expect-error Remove when 11.1.x is released\n this.setState({ error: response.error.message });\n }\n\n let values = dataFromResponse(response);\n if (override) {\n values = values.concat(dataFromResponse(override.values));\n }\n\n return values.map(toSelectableValue);\n }\n\n public _addWip() {\n this.setState({\n _wip: { key: '', value: '', operator: '=', condition: '' },\n });\n }\n\n public _getOperators() {\n const filteredOperators = this.state.supportsMultiValueOperators ? OPERATORS : OPERATORS.filter((operator) => !operator.isMulti);\n return filteredOperators.map<SelectableValue<string>>(({ value, description }) => ({\n label: value,\n value,\n description,\n }));\n }\n}\n\nfunction renderExpression(\n builder: AdHocVariableExpressionBuilderFn | undefined,\n filters: AdHocFilterWithLabels[] | undefined\n) {\n return (builder ?? renderPrometheusLabelFilters)(filters ?? []);\n}\n\nexport function AdHocFiltersVariableRenderer({ model }: SceneComponentProps<AdHocFiltersVariable>) {\n const { filters, readOnly, addFilterButtonText } = model.useState();\n const styles = useStyles2(getStyles);\n\n return (\n <div className={styles.wrapper}>\n {filters.map((filter, index) => (\n <React.Fragment key={index}>\n <AdHocFilterRenderer filter={filter} model={model} />\n </React.Fragment>\n ))}\n\n {!readOnly && <AdHocFilterBuilder model={model} key=\"'builder\" addFilterButtonText={addFilterButtonText} />}\n </div>\n );\n}\n\nconst getStyles = (theme: GrafanaTheme2) => ({\n wrapper: css({\n display: 'flex',\n flexWrap: 'wrap',\n alignItems: 'flex-end',\n columnGap: theme.spacing(2),\n rowGap: theme.spacing(1),\n }),\n filterIcon: css({\n color: theme.colors.text.secondary,\n paddingRight: theme.spacing(0.5),\n }),\n});\n\nexport function toSelectableValue(input: MetricFindValue): SelectableValue<string> {\n const { text, value } = input;\n const result: SelectableValue<string> = {\n label: text,\n value: String(value ?? text),\n };\n\n if ('group' in input) {\n result.group = input.group;\n }\n\n return result;\n}\n\nexport function isFilterComplete(filter: AdHocFilterWithLabels): boolean {\n return filter.key !== '' && filter.operator !== '' && filter.value !== '';\n}\n\nexport function isMultiValueOperator(operatorValue: string): boolean {\n const operator = OPERATORS.find((o) => o.value === operatorValue);\n if (!operator) {\n throw new Error('Unknown operator');\n }\n return Boolean(operator.isMulti);\n}\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAqHA,MAAM,YAAkC,CAAC;AAAA,EACvC,KAAO,EAAA,GAAA;AACT,CAAG,EAAA;AAAA,EACD,KAAO,EAAA,IAAA;AACT,CAAG,EAAA;AAAA,EACD,KAAO,EAAA,IAAA;AAAA,EACP,WAAa,EAAA,8CAAA;AAAA,EACb,OAAS,EAAA,IAAA;AACX,CAAG,EAAA;AAAA,EACD,KAAO,EAAA,KAAA;AAAA,EACP,WAAa,EAAA,gDAAA;AAAA,EACb,OAAS,EAAA,IAAA;AACX,CAAG,EAAA;AAAA,EACD,KAAO,EAAA,IAAA;AAAA,EACP,WAAa,EAAA,eAAA;AACf,CAAG,EAAA;AAAA,EACD,KAAO,EAAA,IAAA;AAAA,EACP,WAAa,EAAA,sBAAA;AACf,CAAG,EAAA;AAAA,EACD,KAAO,EAAA,GAAA;AACT,CAAG,EAAA;AAAA,EACD,KAAO,EAAA,GAAA;AACT,CAAC,CAAA,CAAA;AAEM,MAAM,6BACH,eAEV,CAAA;AAAA,EAQS,YAAY,KAA2C,EAAA;AAxJhE,IAAA,IAAA,EAAA,EAAA,E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A,GAChC,CAAA;AACH,CAAA,CAAA,CAAA;AAEO,SAAS,kBAAkB,KAAiD,EAAA;AACjF,EAAM,MAAA,EAAE,IAAM,EAAA,KAAA,EAAU,GAAA,KAAA,CAAA;AACxB,EAAA,MAAM,MAAkC,GAAA;AAAA,IACtC,KAAO,EAAA,IAAA;AAAA,IACP,KAAA,EAAO,MAAO,CAAA,KAAA,IAAA,IAAA,GAAA,KAAA,GAAS,IAAI,CAAA;AAAA,GAC7B,CAAA;AAEA,EAAA,IAAI,WAAW,KAAO,EAAA;AACpB,IAAA,MAAA,CAAO,QAAQ,KAAM,CAAA,KAAA,CAAA;AAAA,GACvB;AAEA,EAAO,OAAA,MAAA,CAAA;AACT,CAAA;AAEO,SAAS,iBAAiB,MAAwC,EAAA;AACvE,EAAA,OAAO,OAAO,GAAQ,KAAA,EAAA,IAAM,OAAO,QAAa,KAAA,EAAA,IAAM,OAAO,KAAU,KAAA,EAAA,CAAA;AACzE,CAAA;AAEO,SAAS,qBAAqB,aAAgC,EAAA;AACnE,EAAA,MAAM,WAAW,SAAU,CAAA,IAAA,CAAK,CAAC,CAAM,KAAA,CAAA,CAAE,UAAU,aAAa,CAAA,CAAA;AAChE,EAAA,IAAI,CAAC,QAAU,EAAA;AACb,IAAM,MAAA,IAAI,MAAM,kBAAkB,CAAA,CAAA;AAAA,GACpC;AACA,EAAO,OAAA,OAAA,CAAQ,SAAS,OAAO,CAAA,CAAA;AACjC;;;;"}
|
1
|
+
{"version":3,"file":"AdHocFiltersVariable.js","sources":["../../../../src/variables/adhoc/AdHocFiltersVariable.tsx"],"sourcesContent":["import React from 'react';\n// @ts-expect-error Remove when 11.1.x is released\nimport { AdHocVariableFilter, GetTagResponse, GrafanaTheme2, MetricFindValue, SelectableValue } from '@grafana/data';\nimport { SceneObjectBase } from '../../core/SceneObjectBase';\nimport { SceneVariable, SceneVariableState, SceneVariableValueChangedEvent, VariableValue } from '../types';\nimport { ControlsLayout, SceneComponentProps } from '../../core/types';\nimport { DataSourceRef } from '@grafana/schema';\nimport { dataFromResponse, getQueriesForVariables, renderPrometheusLabelFilters, responseHasError } from '../utils';\nimport { patchGetAdhocFilters } from './patchGetAdhocFilters';\nimport { useStyles2 } from '@grafana/ui';\nimport { sceneGraph } from '../../core/sceneGraph';\nimport { AdHocFilterBuilder } from './AdHocFilterBuilder';\nimport { AdHocFilterRenderer } from './AdHocFilterRenderer';\nimport { getDataSourceSrv } from '@grafana/runtime';\nimport { AdHocFiltersVariableUrlSyncHandler } from './AdHocFiltersVariableUrlSyncHandler';\nimport { css } from '@emotion/css';\nimport { getEnrichedFiltersRequest } from '../getEnrichedFiltersRequest';\nimport { AdHocFiltersComboboxRenderer } from './AdHocFiltersCombobox/AdHocFiltersComboboxRenderer';\nimport { wrapInSafeSerializableSceneObject } from '../../utils/wrapInSafeSerializableSceneObject';\n\nexport interface AdHocFilterWithLabels extends AdHocVariableFilter {\n keyLabel?: string;\n valueLabels?: string[];\n}\n\nexport type AdHocControlsLayout = ControlsLayout | 'combobox';\n\nexport interface AdHocFiltersVariableState extends SceneVariableState {\n /** Optional text to display on the 'add filter' button */\n addFilterButtonText?: string;\n /** The visible filters */\n filters: AdHocFilterWithLabels[];\n /** Base filters to always apply when looking up keys*/\n baseFilters?: AdHocFilterWithLabels[];\n /** Datasource to use for getTagKeys and getTagValues and also controls which scene queries the filters should apply to */\n datasource: DataSourceRef | null;\n /** Controls if the filters can be changed */\n readOnly?: boolean;\n /**\n * @experimental\n * Controls the layout and design of the label.\n */\n layout?: AdHocControlsLayout;\n /**\n * Defaults to automatic which means filters will automatically be applied to all queries with the same data source as this AdHocFilterSet.\n * In manual mode you either have to use the filters programmatically or as a variable inside query expressions.\n */\n applyMode: 'auto' | 'manual';\n /**\n * Filter out the keys that do not match the regex.\n */\n tagKeyRegexFilter?: RegExp;\n /**\n * Extension hook for customizing the key lookup.\n * Return replace: true if you want to override the default lookup\n * Return replace: false if you want to combine the results with the default lookup\n */\n getTagKeysProvider?: getTagKeysProvider;\n /**\n * Extension hook for customizing the value lookup.\n * Return replace: true if you want to override the default lookup.\n * Return replace: false if you want to combine the results with the default lookup\n */\n getTagValuesProvider?: getTagValuesProvider;\n\n /**\n * Optionally provide an array of static keys that override getTagKeys\n */\n defaultKeys?: MetricFindValue[];\n\n /**\n * This is the expression that the filters resulted in. Defaults to\n * Prometheus / Loki compatible label filter expression\n */\n filterExpression?: string;\n\n /**\n * The default builder creates a Prometheus/Loki compatible filter expression,\n * this can be overridden to create a different expression based on the current filters.\n */\n expressionBuilder?: AdHocVariableExpressionBuilderFn;\n\n /**\n * Whether the filter supports new multi-value operators like =| and !=|\n */\n supportsMultiValueOperators?: boolean;\n\n /**\n * When querying the datasource for label names and values to determine keys and values\n * for this ad hoc filter, consider the queries in the scene and use them as a filter.\n * This queries filter can be used to ensure that only ad hoc filter options that would\n * impact the current queries are presented to the user.\n */\n useQueriesAsFilterForOptions?: boolean;\n\n /**\n * @internal state of the new filter being added\n */\n _wip?: AdHocFilterWithLabels;\n}\n\nexport type AdHocVariableExpressionBuilderFn = (filters: AdHocFilterWithLabels[]) => string;\n\nexport type getTagKeysProvider = (\n variable: AdHocFiltersVariable,\n currentKey: string | null\n) => Promise<{ replace?: boolean; values: GetTagResponse | MetricFindValue[] }>;\n\nexport type getTagValuesProvider = (\n variable: AdHocFiltersVariable,\n filter: AdHocFilterWithLabels\n) => Promise<{ replace?: boolean; values: GetTagResponse | MetricFindValue[] }>;\n\nexport type AdHocFiltersVariableCreateHelperArgs = AdHocFiltersVariableState;\n\nexport type OperatorDefinition = {\n value: string;\n description?: string;\n isMulti?: Boolean;\n};\n\nconst OPERATORS: OperatorDefinition[] = [\n {\n value: '=',\n },\n {\n value: '!=',\n },\n {\n value: '=|',\n description: 'Is one of. Use to filter on multiple values.',\n isMulti: true,\n },\n {\n value: '!=|',\n description: 'Is not one of. Use to exclude multiple values.',\n isMulti: true,\n },\n {\n value: '=~',\n description: 'Matches regex',\n },\n {\n value: '!~',\n description: 'Does not match regex',\n },\n {\n value: '<',\n },\n {\n value: '>',\n },\n];\n\nexport class AdHocFiltersVariable\n extends SceneObjectBase<AdHocFiltersVariableState>\n implements SceneVariable<AdHocFiltersVariableState>\n{\n static Component = AdHocFiltersVariableRenderer;\n\n private _scopedVars = { __sceneObject: wrapInSafeSerializableSceneObject(this) };\n private _dataSourceSrv = getDataSourceSrv();\n\n protected _urlSync = new AdHocFiltersVariableUrlSyncHandler(this);\n\n public constructor(state: Partial<AdHocFiltersVariableState>) {\n super({\n type: 'adhoc',\n name: state.name ?? 'Filters',\n filters: [],\n datasource: null,\n applyMode: 'auto',\n filterExpression: state.filterExpression ?? renderExpression(state.expressionBuilder, state.filters),\n ...state,\n });\n\n if (this.state.applyMode === 'auto') {\n patchGetAdhocFilters(this);\n }\n }\n\n public setState(update: Partial<AdHocFiltersVariableState>): void {\n let filterExpressionChanged = false;\n\n if (update.filters && update.filters !== this.state.filters && !update.filterExpression) {\n update.filterExpression = renderExpression(this.state.expressionBuilder, update.filters);\n filterExpressionChanged = update.filterExpression !== this.state.filterExpression;\n }\n\n super.setState(update);\n\n if (filterExpressionChanged) {\n this.publishEvent(new SceneVariableValueChangedEvent(this), true);\n }\n }\n\n public getValue(): VariableValue | undefined {\n return this.state.filterExpression;\n }\n\n public _updateFilter(filter: AdHocFilterWithLabels, update: Partial<AdHocFilterWithLabels>) {\n const { filters, _wip } = this.state;\n\n if (filter === _wip) {\n // If we set value we are done with this \"work in progress\" filter and we can add it\n if ('value' in update && update['value'] !== '') {\n this.setState({ filters: [...filters, { ..._wip, ...update }], _wip: undefined });\n } else {\n this.setState({ _wip: { ...filter, ...update } });\n }\n return;\n }\n\n const updatedFilters = this.state.filters.map((f) => {\n return f === filter ? { ...f, ...update } : f;\n });\n\n this.setState({ filters: updatedFilters });\n }\n\n public _removeFilter(filter: AdHocFilterWithLabels) {\n if (filter === this.state._wip) {\n this.setState({ _wip: undefined });\n return;\n }\n\n this.setState({ filters: this.state.filters.filter((f) => f !== filter) });\n }\n\n public _removeLastFilter() {\n const filterToRemove = this.state.filters.at(-1);\n\n if (filterToRemove) {\n this._removeFilter(filterToRemove);\n }\n }\n\n /**\n * Get possible keys given current filters. Do not call from plugins directly\n */\n public async _getKeys(currentKey: string | null): Promise<Array<SelectableValue<string>>> {\n const override = await this.state.getTagKeysProvider?.(this, currentKey);\n\n if (override && override.replace) {\n return dataFromResponse(override.values).map(toSelectableValue);\n }\n\n if (this.state.defaultKeys) {\n return this.state.defaultKeys.map(toSelectableValue);\n }\n\n const ds = await this._dataSourceSrv.get(this.state.datasource, this._scopedVars);\n if (!ds || !ds.getTagKeys) {\n return [];\n }\n\n const otherFilters = this.state.filters.filter((f) => f.key !== currentKey).concat(this.state.baseFilters ?? []);\n const timeRange = sceneGraph.getTimeRange(this).state.value;\n const queries = this.state.useQueriesAsFilterForOptions ? getQueriesForVariables(this) : undefined;\n const response = await ds.getTagKeys({\n filters: otherFilters,\n queries,\n timeRange,\n ...getEnrichedFiltersRequest(this),\n });\n\n if (responseHasError(response)) {\n // @ts-expect-error Remove when 11.1.x is released\n this.setState({ error: response.error.message });\n }\n\n let keys = dataFromResponse(response);\n if (override) {\n keys = keys.concat(dataFromResponse(override.values));\n }\n\n const tagKeyRegexFilter = this.state.tagKeyRegexFilter;\n if (tagKeyRegexFilter) {\n // @ts-expect-error Remove when 11.1.x is released\n keys = keys.filter((f) => f.text.match(tagKeyRegexFilter));\n }\n\n return keys.map(toSelectableValue);\n }\n\n /**\n * Get possible key values for a specific key given current filters. Do not call from plugins directly\n */\n public async _getValuesFor(filter: AdHocFilterWithLabels): Promise<Array<SelectableValue<string>>> {\n const override = await this.state.getTagValuesProvider?.(this, filter);\n\n if (override && override.replace) {\n return dataFromResponse(override.values).map(toSelectableValue);\n }\n\n const ds = await this._dataSourceSrv.get(this.state.datasource, this._scopedVars);\n\n if (!ds || !ds.getTagValues) {\n return [];\n }\n\n // Filter out the current filter key from the list of all filters\n const otherFilters = this.state.filters.filter((f) => f.key !== filter.key).concat(this.state.baseFilters ?? []);\n\n const timeRange = sceneGraph.getTimeRange(this).state.value;\n const queries = this.state.useQueriesAsFilterForOptions ? getQueriesForVariables(this) : undefined;\n\n const response = await ds.getTagValues({\n key: filter.key,\n filters: otherFilters,\n timeRange, // @ts-expect-error TODO: remove this once 11.1.x is released\n queries,\n ...getEnrichedFiltersRequest(this),\n });\n\n if (responseHasError(response)) {\n // @ts-expect-error Remove when 11.1.x is released\n this.setState({ error: response.error.message });\n }\n\n let values = dataFromResponse(response);\n if (override) {\n values = values.concat(dataFromResponse(override.values));\n }\n\n return values.map(toSelectableValue);\n }\n\n public _addWip() {\n this.setState({\n _wip: { key: '', value: '', operator: '=', condition: '' },\n });\n }\n\n public _getOperators() {\n const filteredOperators = this.state.supportsMultiValueOperators\n ? OPERATORS\n : OPERATORS.filter((operator) => !operator.isMulti);\n return filteredOperators.map<SelectableValue<string>>(({ value, description }) => ({\n label: value,\n value,\n description,\n }));\n }\n}\n\nfunction renderExpression(\n builder: AdHocVariableExpressionBuilderFn | undefined,\n filters: AdHocFilterWithLabels[] | undefined\n) {\n return (builder ?? renderPrometheusLabelFilters)(filters ?? []);\n}\n\nexport function AdHocFiltersVariableRenderer({ model }: SceneComponentProps<AdHocFiltersVariable>) {\n const { filters, readOnly, addFilterButtonText } = model.useState();\n const styles = useStyles2(getStyles);\n\n if (!model.state.supportsMultiValueOperators && model.state.layout === 'combobox') {\n return <AdHocFiltersComboboxRenderer model={model} />;\n }\n\n return (\n <div className={styles.wrapper}>\n {filters.map((filter, index) => (\n <React.Fragment key={index}>\n <AdHocFilterRenderer filter={filter} model={model} />\n </React.Fragment>\n ))}\n\n {!readOnly && <AdHocFilterBuilder model={model} key=\"'builder\" addFilterButtonText={addFilterButtonText} />}\n </div>\n );\n}\n\nconst getStyles = (theme: GrafanaTheme2) => ({\n wrapper: css({\n display: 'flex',\n flexWrap: 'wrap',\n alignItems: 'flex-end',\n columnGap: theme.spacing(2),\n rowGap: theme.spacing(1),\n }),\n});\n\nexport function toSelectableValue(input: MetricFindValue): SelectableValue<string> {\n const { text, value } = input;\n const result: SelectableValue<string> = {\n label: text,\n value: String(value ?? text),\n };\n\n if ('group' in input) {\n result.group = input.group;\n }\n\n return result;\n}\n\nexport function isFilterComplete(filter: AdHocFilterWithLabels): boolean {\n return filter.key !== '' && filter.operator !== '' && filter.value !== '';\n}\n\nexport function isMultiValueOperator(operatorValue: string): boolean {\n const operator = OPERATORS.find((o) => o.value === operatorValue);\n if (!operator) {\n throw new Error('Unknown operator');\n }\n return Boolean(operator.isMulti);\n}\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAyHA,MAAM,SAAkC,GAAA;AAAA,EACtC;AAAA,IACE,KAAO,EAAA,GAAA;AAAA,GACT;AAAA,EACA;AAAA,IACE,KAAO,EAAA,IAAA;AAAA,GACT;AAAA,EACA;AAAA,IACE,KAAO,EAAA,IAAA;AAAA,IACP,WAAa,EAAA,8CAAA;AAAA,IACb,OAAS,EAAA,IAAA;AAAA,GACX;AAAA,EACA;AAAA,IACE,KAAO,EAAA,KAAA;AAAA,IACP,WAAa,EAAA,gDAAA;AAAA,IACb,OAAS,EAAA,IAAA;AAAA,GACX;AAAA,EACA;AAAA,IACE,KAAO,EAAA,IAAA;AAAA,IACP,WAAa,EAAA,eAAA;AAAA,GACf;AAAA,EACA;AAAA,IACE,KAAO,EAAA,IAAA;AAAA,IACP,WAAa,EAAA,sBAAA;AAAA,GACf;AAAA,EACA;AAAA,IACE,KAAO,EAAA,GAAA;AAAA,GACT;AAAA,EACA;AAAA,IACE,KAAO,EAAA,GAAA;AAAA,GACT;AACF,CAAA,CAAA;AAEO,MAAM,6BACH,eAEV,CAAA;AAAA,EAQS,YAAY,KAA2C,EAAA;AArKhE,IAAA,IAAA,EAAA,EAAA,EAAA,CAAA;AAsKI,IAAM,KAAA,CAAA,cAAA,CAAA;AAAA,MACJ,IAAM,EAAA,OAAA;AAAA,MACN,IAAA,EAAA,CAAM,E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AAA;AAAA,IACV,UAAY,EAAA,UAAA;AAAA,IACZ,SAAA,EAAW,KAAM,CAAA,OAAA,CAAQ,CAAC,CAAA;AAAA,IAC1B,MAAA,EAAQ,KAAM,CAAA,OAAA,CAAQ,CAAC,CAAA;AAAA,GACxB,CAAA;AACH,CAAA,CAAA,CAAA;AAEO,SAAS,kBAAkB,KAAiD,EAAA;AACjF,EAAM,MAAA,EAAE,IAAM,EAAA,KAAA,EAAU,GAAA,KAAA,CAAA;AACxB,EAAA,MAAM,MAAkC,GAAA;AAAA,IACtC,KAAO,EAAA,IAAA;AAAA,IACP,KAAA,EAAO,MAAO,CAAA,KAAA,IAAA,IAAA,GAAA,KAAA,GAAS,IAAI,CAAA;AAAA,GAC7B,CAAA;AAEA,EAAA,IAAI,WAAW,KAAO,EAAA;AACpB,IAAA,MAAA,CAAO,QAAQ,KAAM,CAAA,KAAA,CAAA;AAAA,GACvB;AAEA,EAAO,OAAA,MAAA,CAAA;AACT,CAAA;AAEO,SAAS,iBAAiB,MAAwC,EAAA;AACvE,EAAA,OAAO,OAAO,GAAQ,KAAA,EAAA,IAAM,OAAO,QAAa,KAAA,EAAA,IAAM,OAAO,KAAU,KAAA,EAAA,CAAA;AACzE,CAAA;AAEO,SAAS,qBAAqB,aAAgC,EAAA;AACnE,EAAA,MAAM,WAAW,SAAU,CAAA,IAAA,CAAK,CAAC,CAAM,KAAA,CAAA,CAAE,UAAU,aAAa,CAAA,CAAA;AAChE,EAAA,IAAI,CAAC,QAAU,EAAA;AACb,IAAM,MAAA,IAAI,MAAM,kBAAkB,CAAA,CAAA;AAAA,GACpC;AACA,EAAO,OAAA,OAAA,CAAQ,SAAS,OAAO,CAAA,CAAA;AACjC;;;;"}
|
package/dist/index.d.ts
CHANGED
@@ -513,6 +513,7 @@ interface AdHocFilterWithLabels extends AdHocVariableFilter {
|
|
513
513
|
keyLabel?: string;
|
514
514
|
valueLabels?: string[];
|
515
515
|
}
|
516
|
+
type AdHocControlsLayout = ControlsLayout | 'combobox';
|
516
517
|
interface AdHocFiltersVariableState extends SceneVariableState {
|
517
518
|
/** Optional text to display on the 'add filter' button */
|
518
519
|
addFilterButtonText?: string;
|
@@ -528,7 +529,7 @@ interface AdHocFiltersVariableState extends SceneVariableState {
|
|
528
529
|
* @experimental
|
529
530
|
* Controls the layout and design of the label.
|
530
531
|
*/
|
531
|
-
layout?:
|
532
|
+
layout?: AdHocControlsLayout;
|
532
533
|
/**
|
533
534
|
* Defaults to automatic which means filters will automatically be applied to all queries with the same data source as this AdHocFilterSet.
|
534
535
|
* In manual mode you either have to use the filters programmatically or as a variable inside query expressions.
|
@@ -599,6 +600,7 @@ declare class AdHocFiltersVariable extends SceneObjectBase<AdHocFiltersVariableS
|
|
599
600
|
getValue(): VariableValue | undefined;
|
600
601
|
_updateFilter(filter: AdHocFilterWithLabels, update: Partial<AdHocFilterWithLabels>): void;
|
601
602
|
_removeFilter(filter: AdHocFilterWithLabels): void;
|
603
|
+
_removeLastFilter(): void;
|
602
604
|
/**
|
603
605
|
* Get possible keys given current filters. Do not call from plugins directly
|
604
606
|
*/
|