@grafana/scenes 5.25.1--canary.858.11930656504.0 → 5.26.0--canary.974.11969404553.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (47) hide show
  1. package/CHANGELOG.md +22 -6
  2. package/dist/esm/behaviors/SceneQueryController.js +5 -60
  3. package/dist/esm/behaviors/SceneQueryController.js.map +1 -1
  4. package/dist/esm/components/SceneRefreshPicker.js +1 -6
  5. package/dist/esm/components/SceneRefreshPicker.js.map +1 -1
  6. package/dist/esm/components/VizPanel/VizPanel.js +6 -9
  7. package/dist/esm/components/VizPanel/VizPanel.js.map +1 -1
  8. package/dist/esm/core/SceneTimeRange.js +0 -3
  9. package/dist/esm/core/SceneTimeRange.js.map +1 -1
  10. package/dist/esm/core/sceneGraph/index.js +3 -3
  11. package/dist/esm/core/sceneGraph/index.js.map +1 -1
  12. package/dist/esm/core/sceneGraph/sceneGraph.js +26 -1
  13. package/dist/esm/core/sceneGraph/sceneGraph.js.map +1 -1
  14. package/dist/esm/index.js.map +1 -1
  15. package/dist/esm/querying/SceneQueryRunner.js +3 -1
  16. package/dist/esm/querying/SceneQueryRunner.js.map +1 -1
  17. package/dist/esm/querying/layers/annotations/filterAnnotations.js +3 -2
  18. package/dist/esm/querying/layers/annotations/filterAnnotations.js.map +1 -1
  19. package/dist/esm/querying/registerQueryWithController.js +2 -18
  20. package/dist/esm/querying/registerQueryWithController.js.map +1 -1
  21. package/dist/esm/utils/getDataSource.js +1 -17
  22. package/dist/esm/utils/getDataSource.js.map +1 -1
  23. package/dist/esm/variables/adhoc/AdHocFilterRenderer.js +8 -12
  24. package/dist/esm/variables/adhoc/AdHocFilterRenderer.js.map +1 -1
  25. package/dist/esm/variables/adhoc/AdHocFiltersCombobox/utils.js +9 -48
  26. package/dist/esm/variables/adhoc/AdHocFiltersCombobox/utils.js.map +1 -1
  27. package/dist/esm/variables/adhoc/AdHocFiltersVariableUrlSyncHandler.js +4 -1
  28. package/dist/esm/variables/adhoc/AdHocFiltersVariableUrlSyncHandler.js.map +1 -1
  29. package/dist/esm/variables/adhoc/getAdhocOptionSearcher.js +6 -38
  30. package/dist/esm/variables/adhoc/getAdhocOptionSearcher.js.map +1 -1
  31. package/dist/esm/variables/components/VariableValueSelect.js +0 -5
  32. package/dist/esm/variables/components/VariableValueSelect.js.map +1 -1
  33. package/dist/esm/variables/components/getOptionSearcher.js +5 -39
  34. package/dist/esm/variables/components/getOptionSearcher.js.map +1 -1
  35. package/dist/esm/variables/groupby/GroupByVariable.js +2 -2
  36. package/dist/esm/variables/groupby/GroupByVariable.js.map +1 -1
  37. package/dist/esm/variables/utils.js +23 -1
  38. package/dist/esm/variables/utils.js.map +1 -1
  39. package/dist/esm/variables/variants/TestVariable.js.map +1 -1
  40. package/dist/index.d.ts +32 -44
  41. package/dist/index.js +289 -622
  42. package/dist/index.js.map +1 -1
  43. package/package.json +3 -3
  44. package/dist/esm/behaviors/SceneRenderProfiler.js +0 -169
  45. package/dist/esm/behaviors/SceneRenderProfiler.js.map +0 -1
  46. package/dist/esm/core/sceneGraph/getQueryController.js +0 -19
  47. package/dist/esm/core/sceneGraph/getQueryController.js.map +0 -1
@@ -1 +1 @@
1
- {"version":3,"file":"AdHocFilterRenderer.js","sources":["../../../../src/variables/adhoc/AdHocFilterRenderer.tsx"],"sourcesContent":["import React, { useMemo, useState } from 'react';\n\nimport { AdHocFiltersVariable, AdHocFilterWithLabels, isMultiValueOperator } from './AdHocFiltersVariable';\nimport { GrafanaTheme2, SelectableValue } from '@grafana/data';\nimport { Button, Field, InputActionMeta, Select, useStyles2 } from '@grafana/ui';\nimport { css, cx } from '@emotion/css';\nimport { ControlsLabel } from '../../utils/ControlsLabel';\nimport { getAdhocOptionSearcher } from './getAdhocOptionSearcher';\nimport { handleOptionGroups } from '../utils';\nimport { OptionWithCheckbox } from '../components/VariableValueSelect';\n\ninterface Props {\n filter: AdHocFilterWithLabels;\n model: AdHocFiltersVariable;\n}\n\nfunction keyLabelToOption(key: string, label?: string): SelectableValue | null {\n return key !== ''\n ? {\n value: key,\n label: label || key,\n }\n : null;\n}\n\nconst filterNoOp = () => true;\n\nexport function AdHocFilterRenderer({ filter, model }: Props) {\n const styles = useStyles2(getStyles);\n\n const [keys, setKeys] = useState<SelectableValue[]>([]);\n const [values, setValues] = useState<SelectableValue[]>([]);\n const [isKeysLoading, setIsKeysLoading] = useState(false);\n const [isValuesLoading, setIsValuesLoading] = useState(false);\n const [isKeysOpen, setIsKeysOpen] = useState(false);\n const [isValuesOpen, setIsValuesOpen] = useState(false);\n const [isOperatorOpen, setIsOperatorOpen] = useState(false);\n const [valueInputValue, setValueInputValue] = useState('');\n const [valueHasCustomValue, setValueHasCustomValue] = useState(false);\n // To not trigger queries on every selection we store this state locally here and only update the variable onBlur\n // TODO remove expect-error when we're on the latest version of @grafana/data\n const [uncommittedValue, setUncommittedValue] = useState<SelectableValue>(\n // @ts-expect-error\n filter.values ? filter.values.map((value, index) => keyLabelToOption(value, filter.valueLabels?.[index])) : []\n );\n const isMultiValue = isMultiValueOperator(filter.operator);\n\n const keyValue = keyLabelToOption(filter.key, filter.keyLabel);\n const valueValue = keyLabelToOption(filter.value, filter.valueLabels?.[0]);\n\n const optionSearcher = useMemo(() => getAdhocOptionSearcher(values), [values]);\n\n const onValueInputChange = (value: string, { action }: InputActionMeta) => {\n if (action === 'input-change') {\n setValueInputValue(value);\n }\n return value;\n };\n\n const onOperatorChange = (v: SelectableValue) => {\n const existingOperator = filter.operator;\n const newOperator = v.value;\n\n const update: Partial<AdHocFilterWithLabels> = { operator: newOperator };\n // clear value if operator has changed from multi to single\n if (isMultiValueOperator(existingOperator) && !isMultiValueOperator(newOperator)) {\n update.value = '';\n update.valueLabels = [''];\n // TODO remove expect-error when we're on the latest version of @grafana/data\n // @ts-expect-error\n update.values = undefined;\n setUncommittedValue([]);\n // set values if operator has changed from single to multi\n } else if (!isMultiValueOperator(existingOperator) && isMultiValueOperator(newOperator) && filter.value) {\n // TODO remove expect-error when we're on the latest version of @grafana/data\n // @ts-expect-error\n update.values = [filter.value];\n setUncommittedValue([\n {\n value: filter.value,\n label: filter.valueLabels?.[0] ?? filter.value,\n },\n ]);\n }\n model._updateFilter(filter, update);\n };\n\n const filteredValueOptions = useMemo(\n () => handleOptionGroups(optionSearcher(valueInputValue)),\n [optionSearcher, valueInputValue]\n );\n\n const multiValueProps = {\n isMulti: true,\n value: uncommittedValue,\n components: {\n Option: OptionWithCheckbox,\n },\n hideSelectedOptions: false,\n closeMenuOnSelect: false,\n openMenuOnFocus: false,\n onChange: (v: SelectableValue) => {\n setUncommittedValue(v);\n // clear input value when creating a new custom multi value\n if (v.some((value: SelectableValue) => value.__isNew__)) {\n setValueInputValue('');\n }\n },\n onBlur: () => {\n model._updateFilter(filter, {\n value: uncommittedValue[0]?.value ?? '',\n // TODO remove expect-error when we're on the latest version of @grafana/data\n // @ts-expect-error\n values: uncommittedValue.map((option: SelectableValue<string>) => option.value),\n valueLabels: uncommittedValue.map((option: SelectableValue<string>) => option.label),\n });\n },\n };\n\n const valueSelect = (\n <Select\n virtualized\n allowCustomValue={model.state.allowCustomValue ?? true}\n isValidNewOption={(inputValue) => inputValue.trim().length > 0}\n allowCreateWhileLoading\n formatCreateLabel={(inputValue) => `Use custom value: ${inputValue}`}\n disabled={model.state.readOnly}\n className={cx(styles.value, isValuesOpen ? styles.widthWhenOpen : undefined)}\n width=\"auto\"\n value={valueValue}\n filterOption={filterNoOp}\n placeholder={'Select value'}\n options={filteredValueOptions}\n inputValue={valueInputValue}\n onInputChange={onValueInputChange}\n onChange={(v) => {\n model._updateFilter(filter, {\n value: v.value,\n valueLabels: v.label ? [v.label] : [v.value],\n });\n\n if (valueHasCustomValue !== v.__isNew__) {\n setValueHasCustomValue(v.__isNew__);\n }\n }}\n // there's a bug in react-select where the menu doesn't recalculate its position when the options are loaded asynchronously\n // see https://github.com/grafana/grafana/issues/63558\n // instead, we explicitly control the menu visibility and prevent showing it until the options have fully loaded\n isOpen={isValuesOpen && !isValuesLoading}\n isLoading={isValuesLoading}\n openMenuOnFocus={true}\n onOpenMenu={async () => {\n setIsValuesLoading(true);\n setIsValuesOpen(true);\n const values = await model._getValuesFor(filter);\n setIsValuesLoading(false);\n setValues(values);\n if (valueHasCustomValue) {\n setValueInputValue(valueValue?.label ?? '');\n }\n }}\n onCloseMenu={() => {\n setIsValuesOpen(false);\n setValueInputValue('');\n }}\n {...(isMultiValue && multiValueProps)}\n />\n );\n\n const keySelect = (\n <Select\n // By changing the key, we reset the Select component,\n // to ensure that the loaded values are shown after they are loaded\n key={`${isValuesLoading ? 'loading' : 'loaded'}`}\n disabled={model.state.readOnly}\n className={cx(styles.key, isKeysOpen ? styles.widthWhenOpen : undefined)}\n width=\"auto\"\n allowCustomValue={model.state.allowCustomValue ?? true}\n value={keyValue}\n placeholder={'Select label'}\n options={handleOptionGroups(keys)}\n onChange={(v) => {\n model._updateFilter(filter, {\n key: v.value,\n keyLabel: v.label,\n // clear value if key has changed\n value: '',\n valueLabels: [''],\n // TODO remove expect-error when we're on the latest version of @grafana/data\n // @ts-expect-error\n values: undefined,\n });\n setUncommittedValue([]);\n }}\n autoFocus={filter.key === ''}\n // there's a bug in react-select where the menu doesn't recalculate its position when the options are loaded asynchronously\n // see https://github.com/grafana/grafana/issues/63558\n // instead, we explicitly control the menu visibility and prevent showing it until the options have fully loaded\n isOpen={isKeysOpen && !isKeysLoading}\n isLoading={isKeysLoading}\n onOpenMenu={async () => {\n setIsKeysOpen(true);\n setIsKeysLoading(true);\n const keys = await model._getKeys(filter.key);\n setIsKeysLoading(false);\n setKeys(keys);\n }}\n onCloseMenu={() => {\n setIsKeysOpen(false);\n }}\n onBlur={() => {\n if (filter.key === '') {\n model._removeFilter(filter);\n }\n }}\n openMenuOnFocus={true}\n />\n );\n\n const operatorSelect = (\n <Select\n className={cx(styles.operator, {\n [styles.widthWhenOpen]: isOperatorOpen,\n })}\n value={filter.operator}\n disabled={model.state.readOnly}\n options={model._getOperators()}\n onChange={onOperatorChange}\n onOpenMenu={() => {\n setIsOperatorOpen(true);\n }}\n onCloseMenu={() => {\n setIsOperatorOpen(false);\n }}\n />\n );\n\n if (model.state.layout === 'vertical') {\n if (filter.key) {\n const label = (\n <ControlsLabel layout=\"vertical\" label={filter.key ?? ''} onRemove={() => model._removeFilter(filter)} />\n );\n\n return (\n <Field label={label} data-testid={`AdHocFilter-${filter.key}`} className={styles.field}>\n <div className={styles.wrapper}>\n {operatorSelect}\n {valueSelect}\n </div>\n </Field>\n );\n } else {\n return (\n <Field label={'Select label'} data-testid={`AdHocFilter-${filter.key}`} className={styles.field}>\n {keySelect}\n </Field>\n );\n }\n }\n\n return (\n <div className={styles.wrapper} data-testid={`AdHocFilter-${filter.key}`}>\n {keySelect}\n {operatorSelect}\n {valueSelect}\n <Button\n variant=\"secondary\"\n aria-label=\"Remove filter\"\n title=\"Remove filter\"\n className={styles.removeButton}\n icon=\"times\"\n data-testid={`AdHocFilter-remove-${filter.key ?? ''}`}\n onClick={() => model._removeFilter(filter)}\n />\n </div>\n );\n}\n\nconst getStyles = (theme: GrafanaTheme2) => ({\n field: css({\n marginBottom: 0,\n }),\n wrapper: css({\n display: 'flex',\n '> *': {\n '&:not(:first-child)': {\n // Negative margin hides the double-border on adjacent selects\n marginLeft: -1,\n },\n\n '&:first-child': {\n borderTopRightRadius: 0,\n borderBottomRightRadius: 0,\n },\n\n '&:last-child': {\n borderTopLeftRadius: 0,\n borderBottomLeftRadius: 0,\n },\n\n '&:not(:first-child):not(:last-child)': {\n borderRadius: 0,\n },\n\n // Fix focus state zIndex issues\n position: 'relative',\n zIndex: 0,\n\n // Adjacent borders are overlapping, so raise children up when hovering etc\n // so all that child's borders are visible.\n '&:hover': {\n zIndex: 1,\n },\n\n '&:focus-within': {\n zIndex: 2,\n },\n },\n }),\n widthWhenOpen: css({\n minWidth: theme.spacing(16),\n }),\n value: css({\n flexBasis: 'content',\n flexShrink: 1,\n minWidth: '90px',\n }),\n key: css({\n flexBasis: 'content',\n minWidth: '90px',\n flexShrink: 1,\n }),\n operator: css({\n flexShrink: 0,\n flexBasis: 'content',\n }),\n removeButton: css({\n paddingLeft: theme.spacing(3 / 2),\n paddingRight: theme.spacing(3 / 2),\n borderLeft: 'none',\n width: theme.spacing(3),\n marginRight: theme.spacing(1),\n boxSizing: 'border-box',\n // To not have button background and last select border intersect\n position: 'relative',\n left: '1px',\n }),\n});\n"],"names":["_a","_b","values","keys"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAgBA,SAAS,gBAAA,CAAiB,KAAa,KAAwC,EAAA;AAC7E,EAAA,OAAO,QAAQ,EACX,GAAA;AAAA,IACE,KAAO,EAAA,GAAA;AAAA,IACP,OAAO,KAAS,IAAA,GAAA;AAAA,GAElB,GAAA,IAAA,CAAA;AACN,CAAA;AAEA,MAAM,aAAa,MAAM,IAAA,CAAA;AAElB,SAAS,mBAAoB,CAAA,EAAE,MAAQ,EAAA,KAAA,EAAgB,EAAA;AA3B9D,EAAA,IAAA,EAAA,EAAA,EAAA,EAAA,EAAA,EAAA,EAAA,EAAA,EAAA,CAAA;AA4BE,EAAM,MAAA,MAAA,GAAS,WAAW,SAAS,CAAA,CAAA;AAEnC,EAAA,MAAM,CAAC,IAAM,EAAA,OAAO,CAAI,GAAA,QAAA,CAA4B,EAAE,CAAA,CAAA;AACtD,EAAA,MAAM,CAAC,MAAQ,EAAA,SAAS,CAAI,GAAA,QAAA,CAA4B,EAAE,CAAA,CAAA;AAC1D,EAAA,MAAM,CAAC,aAAA,EAAe,gBAAgB,CAAA,GAAI,SAAS,KAAK,CAAA,CAAA;AACxD,EAAA,MAAM,CAAC,eAAA,EAAiB,kBAAkB,CAAA,GAAI,SAAS,KAAK,CAAA,CAAA;AAC5D,EAAA,MAAM,CAAC,UAAA,EAAY,aAAa,CAAA,GAAI,SAAS,KAAK,CAAA,CAAA;AAClD,EAAA,MAAM,CAAC,YAAA,EAAc,eAAe,CAAA,GAAI,SAAS,KAAK,CAAA,CAAA;AACtD,EAAA,MAAM,CAAC,cAAA,EAAgB,iBAAiB,CA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AAA,EACD,eAAe,GAAI,CAAA;AAAA,IACjB,QAAA,EAAU,KAAM,CAAA,OAAA,CAAQ,EAAE,CAAA;AAAA,GAC3B,CAAA;AAAA,EACD,OAAO,GAAI,CAAA;AAAA,IACT,SAAW,EAAA,SAAA;AAAA,IACX,UAAY,EAAA,CAAA;AAAA,IACZ,QAAU,EAAA,MAAA;AAAA,GACX,CAAA;AAAA,EACD,KAAK,GAAI,CAAA;AAAA,IACP,SAAW,EAAA,SAAA;AAAA,IACX,QAAU,EAAA,MAAA;AAAA,IACV,UAAY,EAAA,CAAA;AAAA,GACb,CAAA;AAAA,EACD,UAAU,GAAI,CAAA;AAAA,IACZ,UAAY,EAAA,CAAA;AAAA,IACZ,SAAW,EAAA,SAAA;AAAA,GACZ,CAAA;AAAA,EACD,cAAc,GAAI,CAAA;AAAA,IAChB,WAAa,EAAA,KAAA,CAAM,OAAQ,CAAA,CAAA,GAAI,CAAC,CAAA;AAAA,IAChC,YAAc,EAAA,KAAA,CAAM,OAAQ,CAAA,CAAA,GAAI,CAAC,CAAA;AAAA,IACjC,UAAY,EAAA,MAAA;AAAA,IACZ,KAAA,EAAO,KAAM,CAAA,OAAA,CAAQ,CAAC,CAAA;AAAA,IACtB,WAAA,EAAa,KAAM,CAAA,OAAA,CAAQ,CAAC,CAAA;AAAA,IAC5B,SAAW,EAAA,YAAA;AAAA,IAEX,QAAU,EAAA,UAAA;AAAA,IACV,IAAM,EAAA,KAAA;AAAA,GACP,CAAA;AACH,CAAA,CAAA;;;;"}
1
+ {"version":3,"file":"AdHocFilterRenderer.js","sources":["../../../../src/variables/adhoc/AdHocFilterRenderer.tsx"],"sourcesContent":["import React, { useMemo, useState } from 'react';\n\nimport { AdHocFiltersVariable, AdHocFilterWithLabels, isMultiValueOperator } from './AdHocFiltersVariable';\nimport { GrafanaTheme2, SelectableValue } from '@grafana/data';\nimport { Button, Field, InputActionMeta, Select, useStyles2 } from '@grafana/ui';\nimport { css, cx } from '@emotion/css';\nimport { ControlsLabel } from '../../utils/ControlsLabel';\nimport { getAdhocOptionSearcher } from './getAdhocOptionSearcher';\nimport { handleOptionGroups } from '../utils';\nimport { OptionWithCheckbox } from '../components/VariableValueSelect';\n\ninterface Props {\n filter: AdHocFilterWithLabels;\n model: AdHocFiltersVariable;\n}\n\nfunction keyLabelToOption(key: string, label?: string): SelectableValue | null {\n return key !== ''\n ? {\n value: key,\n label: label || key,\n }\n : null;\n}\n\nconst filterNoOp = () => true;\n\nexport function AdHocFilterRenderer({ filter, model }: Props) {\n const styles = useStyles2(getStyles);\n\n const [keys, setKeys] = useState<SelectableValue[]>([]);\n const [values, setValues] = useState<SelectableValue[]>([]);\n const [isKeysLoading, setIsKeysLoading] = useState(false);\n const [isValuesLoading, setIsValuesLoading] = useState(false);\n const [isKeysOpen, setIsKeysOpen] = useState(false);\n const [isValuesOpen, setIsValuesOpen] = useState(false);\n const [isOperatorOpen, setIsOperatorOpen] = useState(false);\n const [valueInputValue, setValueInputValue] = useState('');\n const [valueHasCustomValue, setValueHasCustomValue] = useState(false);\n // To not trigger queries on every selection we store this state locally here and only update the variable onBlur\n // TODO remove expect-error when we're on the latest version of @grafana/data\n // @ts-expect-error\n const [uncommittedValue, setUncommittedValue] = useState<SelectableValue>(filter.values ? filter.values.map((value, index) => keyLabelToOption(value, filter.valueLabels?.[index])) : []);\n const isMultiValue = isMultiValueOperator(filter.operator);\n\n const keyValue = keyLabelToOption(filter.key, filter.keyLabel);\n const valueValue = keyLabelToOption(filter.value, filter.valueLabels?.[0]);\n\n const optionSearcher = useMemo(() => getAdhocOptionSearcher(values), [values]);\n\n const onValueInputChange = (value: string, { action }: InputActionMeta) => {\n if (action === 'input-change') {\n setValueInputValue(value);\n }\n return value;\n };\n\n const onOperatorChange = (v: SelectableValue) => {\n const existingOperator = filter.operator;\n const newOperator = v.value;\n\n const update: Partial<AdHocFilterWithLabels> = { operator: newOperator };\n // clear value if operator has changed from multi to single\n if (isMultiValueOperator(existingOperator) && !isMultiValueOperator(newOperator)) {\n update.value = '';\n update.valueLabels = [''];\n // TODO remove expect-error when we're on the latest version of @grafana/data\n // @ts-expect-error\n update.values = undefined;\n setUncommittedValue([]);\n // set values if operator has changed from single to multi\n } else if (!isMultiValueOperator(existingOperator) && isMultiValueOperator(newOperator) && filter.value) {\n // TODO remove expect-error when we're on the latest version of @grafana/data\n // @ts-expect-error\n update.values = [filter.value];\n setUncommittedValue([{\n value: filter.value,\n label: filter.valueLabels?.[0] ?? filter.value,\n }]);\n }\n model._updateFilter(filter, update);\n }\n\n const filteredValueOptions = useMemo(\n () => handleOptionGroups(optionSearcher(valueInputValue)),\n [optionSearcher, valueInputValue]\n );\n\n const multiValueProps = {\n isMulti: true,\n value: uncommittedValue,\n components: {\n Option: OptionWithCheckbox,\n },\n hideSelectedOptions: false,\n closeMenuOnSelect: false,\n openMenuOnFocus: false,\n onChange: (v: SelectableValue) => {\n setUncommittedValue(v);\n // clear input value when creating a new custom multi value\n if (v.some((value: SelectableValue) => value.__isNew__)) {\n setValueInputValue('');\n }\n },\n onBlur: () => {\n model._updateFilter(filter, {\n value: uncommittedValue[0]?.value ?? '',\n // TODO remove expect-error when we're on the latest version of @grafana/data\n // @ts-expect-error\n values: uncommittedValue.map((option: SelectableValue<string>) => option.value),\n valueLabels: uncommittedValue.map((option: SelectableValue<string>) => option.label),\n });\n }\n }\n\n const valueSelect = (\n <Select\n virtualized\n allowCustomValue={model.state.allowCustomValue ?? true}\n isValidNewOption={(inputValue) => inputValue.trim().length > 0}\n allowCreateWhileLoading\n formatCreateLabel={(inputValue) => `Use custom value: ${inputValue}`}\n disabled={model.state.readOnly}\n className={cx(styles.value, isValuesOpen ? styles.widthWhenOpen : undefined)}\n width=\"auto\"\n value={valueValue}\n filterOption={filterNoOp}\n placeholder={'Select value'}\n options={filteredValueOptions}\n inputValue={valueInputValue}\n onInputChange={onValueInputChange}\n onChange={(v) => {\n model._updateFilter(filter, {\n value: v.value,\n valueLabels: v.label ? [v.label] : [v.value]\n });\n\n if (valueHasCustomValue !== v.__isNew__) {\n setValueHasCustomValue(v.__isNew__);\n }\n }}\n // there's a bug in react-select where the menu doesn't recalculate its position when the options are loaded asynchronously\n // see https://github.com/grafana/grafana/issues/63558\n // instead, we explicitly control the menu visibility and prevent showing it until the options have fully loaded\n isOpen={isValuesOpen && !isValuesLoading}\n isLoading={isValuesLoading}\n openMenuOnFocus={true}\n onOpenMenu={async () => {\n setIsValuesLoading(true);\n setIsValuesOpen(true);\n const values = await model._getValuesFor(filter);\n setIsValuesLoading(false);\n setValues(values);\n if (valueHasCustomValue) {\n setValueInputValue(valueValue?.label ?? '');\n }\n }}\n onCloseMenu={() => {\n setIsValuesOpen(false);\n setValueInputValue('');\n }}\n {...(isMultiValue && multiValueProps)}\n />\n );\n\n const keySelect = (\n <Select\n // By changing the key, we reset the Select component,\n // to ensure that the loaded values are shown after they are loaded\n key={`${isValuesLoading ? 'loading' : 'loaded'}`}\n disabled={model.state.readOnly}\n className={cx(styles.key, isKeysOpen ? styles.widthWhenOpen : undefined)}\n width=\"auto\"\n allowCustomValue={model.state.allowCustomValue ?? true}\n value={keyValue}\n placeholder={'Select label'}\n options={handleOptionGroups(keys)}\n onChange={(v) => {\n model._updateFilter(filter, {\n key: v.value,\n keyLabel: v.label,\n // clear value if key has changed\n value: '',\n valueLabels: [''],\n // TODO remove expect-error when we're on the latest version of @grafana/data\n // @ts-expect-error\n values: undefined\n })\n setUncommittedValue([]);\n }}\n autoFocus={filter.key === ''}\n // there's a bug in react-select where the menu doesn't recalculate its position when the options are loaded asynchronously\n // see https://github.com/grafana/grafana/issues/63558\n // instead, we explicitly control the menu visibility and prevent showing it until the options have fully loaded\n isOpen={isKeysOpen && !isKeysLoading}\n isLoading={isKeysLoading}\n onOpenMenu={async () => {\n setIsKeysOpen(true);\n setIsKeysLoading(true);\n const keys = await model._getKeys(filter.key);\n setIsKeysLoading(false);\n setKeys(keys);\n }}\n onCloseMenu={() => {\n setIsKeysOpen(false);\n }}\n onBlur={() => {\n if (filter.key === '') {\n model._removeFilter(filter);\n }\n }}\n openMenuOnFocus={true}\n />\n );\n\n const operatorSelect = (\n <Select\n className={cx(styles.operator, {\n [styles.widthWhenOpen]: isOperatorOpen,\n })}\n value={filter.operator}\n disabled={model.state.readOnly}\n options={model._getOperators()}\n onChange={onOperatorChange}\n onOpenMenu={() => {\n setIsOperatorOpen(true)\n }}\n onCloseMenu={() => {\n setIsOperatorOpen(false)\n }}\n />\n );\n\n if (model.state.layout === 'vertical') {\n if (filter.key) {\n const label = (\n <ControlsLabel layout=\"vertical\" label={filter.key ?? ''} onRemove={() => model._removeFilter(filter)} />\n );\n\n return (\n <Field label={label} data-testid={`AdHocFilter-${filter.key}`} className={styles.field}>\n <div className={styles.wrapper}>\n {operatorSelect}\n {valueSelect}\n </div>\n </Field>\n );\n } else {\n return (\n <Field label={'Select label'} data-testid={`AdHocFilter-${filter.key}`} className={styles.field}>\n {keySelect}\n </Field>\n );\n }\n }\n\n return (\n <div className={styles.wrapper} data-testid={`AdHocFilter-${filter.key}`}>\n {keySelect}\n {operatorSelect}\n {valueSelect}\n <Button\n variant=\"secondary\"\n aria-label=\"Remove filter\"\n title=\"Remove filter\"\n className={styles.removeButton}\n icon=\"times\"\n data-testid={`AdHocFilter-remove-${filter.key ?? ''}`}\n onClick={() => model._removeFilter(filter)}\n />\n </div>\n );\n}\n\nconst getStyles = (theme: GrafanaTheme2) => ({\n field: css({\n marginBottom: 0,\n }),\n wrapper: css({\n display: 'flex',\n '> *': {\n '&:not(:first-child)': {\n // Negative margin hides the double-border on adjacent selects\n marginLeft: -1,\n },\n\n '&:first-child': {\n borderTopRightRadius: 0,\n borderBottomRightRadius: 0,\n },\n\n '&:last-child': {\n borderTopLeftRadius: 0,\n borderBottomLeftRadius: 0,\n },\n\n '&:not(:first-child):not(:last-child)': {\n borderRadius: 0,\n },\n\n // Fix focus state zIndex issues\n position: 'relative',\n zIndex: 0,\n\n // Adjacent borders are overlapping, so raise children up when hovering etc\n // so all that child's borders are visible.\n '&:hover': {\n zIndex: 1,\n },\n\n '&:focus-within': {\n zIndex: 2,\n },\n },\n }),\n widthWhenOpen: css({\n minWidth: theme.spacing(16),\n }),\n value: css({\n flexBasis: 'content',\n flexShrink: 1,\n minWidth: '90px',\n }),\n key: css({\n flexBasis: 'content',\n minWidth: '90px',\n flexShrink: 1,\n }),\n operator: css({\n flexShrink: 0,\n flexBasis: 'content',\n }),\n removeButton: css({\n paddingLeft: theme.spacing(3 / 2),\n paddingRight: theme.spacing(3 / 2),\n borderLeft: 'none',\n width: theme.spacing(3),\n marginRight: theme.spacing(1),\n boxSizing: 'border-box',\n // To not have button background and last select border intersect\n position: 'relative',\n left: '1px',\n }),\n});\n"],"names":["_a","_b","values","keys"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAgBA,SAAS,gBAAA,CAAiB,KAAa,KAAwC,EAAA;AAC7E,EAAA,OAAO,QAAQ,EACX,GAAA;AAAA,IACE,KAAO,EAAA,GAAA;AAAA,IACP,OAAO,KAAS,IAAA,GAAA;AAAA,GAElB,GAAA,IAAA,CAAA;AACN,CAAA;AAEA,MAAM,aAAa,MAAM,IAAA,CAAA;AAElB,SAAS,mBAAoB,CAAA,EAAE,MAAQ,EAAA,KAAA,EAAgB,EAAA;AA3B9D,EAAA,IAAA,EAAA,EAAA,EAAA,EAAA,EAAA,EAAA,EAAA,EAAA,EAAA,CAAA;AA4BE,EAAM,MAAA,MAAA,GAAS,WAAW,SAAS,CAAA,CAAA;AAEnC,EAAA,MAAM,CAAC,IAAM,EAAA,OAAO,CAAI,GAAA,QAAA,CAA4B,EAAE,CAAA,CAAA;AACtD,EAAA,MAAM,CAAC,MAAQ,EAAA,SAAS,CAAI,GAAA,QAAA,CAA4B,EAAE,CAAA,CAAA;AAC1D,EAAA,MAAM,CAAC,aAAA,EAAe,gBAAgB,CAAA,GAAI,SAAS,KAAK,CAAA,CAAA;AACxD,EAAA,MAAM,CAAC,eAAA,EAAiB,kBAAkB,CAAA,GAAI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  import { isMultiValueOperator } from '../AdHocFiltersVariable.js';
2
+ import { getFuzzySearcher } from '../../utils.js';
3
3
 
4
4
  const VIRTUAL_LIST_WIDTH_ESTIMATE_MULTIPLIER = 8;
5
5
  const VIRTUAL_LIST_DESCRIPTION_WIDTH_ESTIMATE_MULTIPLIER = 6;
@@ -9,55 +9,16 @@ const VIRTUAL_LIST_ITEM_HEIGHT = 38;
9
9
  const VIRTUAL_LIST_ITEM_HEIGHT_WITH_DESCRIPTION = 60;
10
10
  const ERROR_STATE_DROPDOWN_WIDTH = 366;
11
11
  function fuzzySearchOptions(options) {
12
- const ufuzzy = new uFuzzy();
13
- const haystack = [];
14
- const limit = 1e4;
15
- return (search, filterInputType) => {
12
+ const haystack = options.map((o) => {
16
13
  var _a;
17
- if (search === "") {
18
- if (options.length > limit) {
19
- return options.slice(0, limit);
20
- } else {
21
- return options;
22
- }
23
- }
24
- if (filterInputType === "operator") {
25
- const filteredOperators = [];
26
- for (let i = 0; i < options.length; i++) {
27
- if ((_a = options[i].label || options[i].value) == null ? void 0 : _a.includes(search)) {
28
- filteredOperators.push(options[i]);
29
- if (filteredOperators.length > limit) {
30
- return filteredOperators;
31
- }
32
- }
33
- }
34
- return filteredOperators;
35
- }
36
- if (haystack.length === 0) {
37
- for (let i = 0; i < options.length; i++) {
38
- haystack.push(options[i].label || options[i].value);
39
- }
40
- }
41
- const [idxs, info, order] = ufuzzy.search(haystack, search);
42
- const filteredOptions = [];
43
- if (idxs) {
44
- for (let i = 0; i < idxs.length; i++) {
45
- if (info && order) {
46
- const idx = order[i];
47
- filteredOptions.push(options[idxs[idx]]);
48
- } else {
49
- filteredOptions.push(options[idxs[i]]);
50
- }
51
- if (filteredOptions.length > limit) {
52
- return filteredOptions;
53
- }
54
- }
55
- return filteredOptions;
56
- }
57
- if (options.length > limit) {
58
- return options.slice(0, limit);
14
+ return (_a = o.label) != null ? _a : o.value;
15
+ });
16
+ const fuzzySearch = getFuzzySearcher(haystack);
17
+ return (search, filterInputType) => {
18
+ if (filterInputType === "operator" && search !== "") {
19
+ search = `"${search}"`;
59
20
  }
60
- return options;
21
+ return fuzzySearch(search).map((i) => options[i]);
61
22
  };
62
23
  }
63
24
  const flattenOptionGroups = (options) => options.flatMap((option) => option.options ? [option, ...option.options] : [option]);
@@ -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\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,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AAO,eAAoB,CAAA,IAAA,CAAC,WAAc,GAAA,CAAA,EAAG,OAAO,eAAqB,CAAA,CAAA,CAAA,GAAA,iBAAA,CAAA;AAClF,EAAA;AAEO,MAAM,sCAAsC,CAAC;AAAA,EAClD,mBAAA;AAAA,EACA,IAAA;AAAA,EACA,eAAA;AAAA,EACA,aAAA;AAAA,EACA,MAAA;AACF,CAMM,KAAA;AACJ,EAAI,IAAA,mBAAA,IAAuB,CAAC,oBAAqB,CAAA,IAAA,CAAK,SAAS,EAAE,CAAA,IAAK,gBAAiB,CAAA,eAAA,CAAA,KAAqB,OAAS,EAAA;AACnH,IAAc,aAAA,CAAA,CAAA,MAAA,IAAA,IAAA,GAAA,KAAA,CAAA,GAAA,MAAA,CAAQ,UAAS,EAAE,CAAA,CAAA;AAAA,GAC5B,MAAA;AACL,IAAA,aAAA,CAAc,EAAE,CAAA,CAAA;AAAA,GAClB;AACF;;;;"}
1
+ {"version":3,"file":"utils.js","sources":["../../../../../src/variables/adhoc/AdHocFiltersCombobox/utils.ts"],"sourcesContent":["import { SelectableValue } from '@grafana/data';\nimport { AdHocInputType } from './AdHocFiltersCombobox';\nimport { AdHocFilterWithLabels, isMultiValueOperator } from '../AdHocFiltersVariable';\nimport { getFuzzySearcher } from '../../utils';\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 haystack = options.map((o) => o.label ?? o.value!);\n const fuzzySearch = getFuzzySearcher(haystack);\n\n return (search: string, filterInputType: AdHocInputType) => {\n if (filterInputType === 'operator' && search !== '') {\n // uFuzzy can only match non-alphanum chars if quoted\n search = `\"${search}\"`;\n }\n\n return fuzzySearch(search).map((i) => options[i]);\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,EAAA,MAAM,QA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,EAAE,CAAA,CAAA;AAAA,GAC5B,MAAA;AACL,IAAA,aAAA,CAAc,EAAE,CAAA,CAAA;AAAA,GAClB;AACF;;;;"}
@@ -38,7 +38,10 @@ function deserializeUrlToFilters(value) {
38
38
  }
39
39
  function toArray(filter) {
40
40
  var _a;
41
- const result = [toUrlCommaDelimitedString(filter.key, filter.keyLabel), filter.operator];
41
+ const result = [
42
+ toUrlCommaDelimitedString(filter.key, filter.keyLabel),
43
+ filter.operator
44
+ ];
42
45
  if (isMultiValueOperator(filter.operator)) {
43
46
  filter.values.forEach((value, index) => {
44
47
  var _a2;
@@ -1 +1 @@
1
- {"version":3,"file":"AdHocFiltersVariableUrlSyncHandler.js","sources":["../../../../src/variables/adhoc/AdHocFiltersVariableUrlSyncHandler.ts"],"sourcesContent":["import { SceneObjectUrlSyncHandler, SceneObjectUrlValue, SceneObjectUrlValues } from '../../core/types';\nimport {\n AdHocFiltersVariable,\n AdHocFilterWithLabels,\n isFilterComplete,\n isMultiValueOperator,\n} from './AdHocFiltersVariable';\nimport { escapeUrlPipeDelimiters, toUrlCommaDelimitedString, unescapeUrlDelimiters } from '../utils';\n\nexport class AdHocFiltersVariableUrlSyncHandler implements SceneObjectUrlSyncHandler {\n public constructor(private _variable: AdHocFiltersVariable) {}\n\n private getKey(): string {\n return `var-${this._variable.state.name}`;\n }\n\n public getKeys(): string[] {\n return [this.getKey()];\n }\n\n public getUrlState(): SceneObjectUrlValues {\n const filters = this._variable.state.filters;\n\n if (filters.length === 0) {\n return { [this.getKey()]: [''] };\n }\n\n const value = filters\n .filter(isFilterComplete)\n .map((filter) => toArray(filter).map(escapeUrlPipeDelimiters).join('|'));\n return { [this.getKey()]: value };\n }\n\n public updateFromUrl(values: SceneObjectUrlValues): void {\n const urlValue = values[this.getKey()];\n\n if (urlValue == null) {\n return;\n }\n\n const filters = deserializeUrlToFilters(urlValue);\n this._variable.setState({ filters });\n }\n}\n\nfunction deserializeUrlToFilters(value: SceneObjectUrlValue): AdHocFilterWithLabels[] {\n if (Array.isArray(value)) {\n const values = value;\n return values.map(toFilter).filter(isFilter);\n }\n\n const filter = toFilter(value);\n return filter === null ? [] : [filter];\n}\n\nfunction toArray(filter: AdHocFilterWithLabels): string[] {\n const result = [toUrlCommaDelimitedString(filter.key, filter.keyLabel), filter.operator];\n if (isMultiValueOperator(filter.operator)) {\n // TODO remove expect-error when we're on the latest version of @grafana/data\n // @ts-expect-error\n filter.values.forEach((value, index) => {\n result.push(toUrlCommaDelimitedString(value, filter.valueLabels?.[index]));\n });\n } else {\n result.push(toUrlCommaDelimitedString(filter.value, filter.valueLabels?.[0]));\n }\n return result;\n}\n\nfunction toFilter(urlValue: string | number | boolean | undefined | null): AdHocFilterWithLabels | null {\n if (typeof urlValue !== 'string' || urlValue.length === 0) {\n return null;\n }\n\n const [key, keyLabel, operator, _operatorLabel, ...values] = urlValue\n .split('|')\n .reduce<string[]>((acc, v) => {\n const [key, label] = v.split(',');\n\n acc.push(key, label ?? key);\n\n return acc;\n }, [])\n .map(unescapeUrlDelimiters);\n\n return {\n key,\n keyLabel,\n operator,\n value: values[0],\n // TODO remove expect-error when we're on the latest version of @grafana/data\n // @ts-expect-error\n values: isMultiValueOperator(operator) ? values.filter((_, index) => index % 2 === 0) : undefined,\n valueLabels: values.filter((_, index) => index % 2 === 1),\n condition: '',\n };\n}\n\nfunction isFilter(filter: AdHocFilterWithLabels | null): filter is AdHocFilterWithLabels {\n return filter !== null && typeof filter.key === 'string' && typeof filter.value === 'string';\n}\n"],"names":["_a","key"],"mappings":";;;AASO,MAAM,kCAAwE,CAAA;AAAA,EAC5E,YAAoB,SAAiC,EAAA;AAAjC,IAAA,IAAA,CAAA,SAAA,GAAA,SAAA,CAAA;AAAA,GAAkC;AAAA,EAErD,MAAiB,GAAA;AACvB,IAAO,OAAA,CAAA,IAAA,EAAO,IAAK,CAAA,SAAA,CAAU,KAAM,CAAA,IAAA,CAAA,CAAA,CAAA;AAAA,GACrC;AAAA,EAEO,OAAoB,GA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K,EAAA,KAAK,CAAI,GAAA,CAAA,CAAE,MAAM,GAAG,CAAA,CAAA;AAEhC,IAAI,GAAA,CAAA,IAAA,CAAKA,IAAK,EAAA,KAAA,IAAA,IAAA,GAAA,KAAA,GAASA,IAAG,CAAA,CAAA;AAE1B,IAAO,OAAA,GAAA,CAAA;AAAA,GACN,EAAA,EAAE,CAAA,CACJ,IAAI,qBAAqB,CAAA,CAAA;AAE5B,EAAO,OAAA;AAAA,IACL,GAAA;AAAA,IACA,QAAA;AAAA,IACA,QAAA;AAAA,IACA,OAAO,MAAO,CAAA,CAAA,CAAA;AAAA,IAGd,MAAQ,EAAA,oBAAA,CAAqB,QAAQ,CAAA,GAAI,MAAO,CAAA,MAAA,CAAO,CAAC,CAAA,EAAG,KAAU,KAAA,KAAA,GAAQ,CAAM,KAAA,CAAC,CAAI,GAAA,KAAA,CAAA;AAAA,IACxF,WAAA,EAAa,OAAO,MAAO,CAAA,CAAC,GAAG,KAAU,KAAA,KAAA,GAAQ,MAAM,CAAC,CAAA;AAAA,IACxD,SAAW,EAAA,EAAA;AAAA,GACb,CAAA;AACF,CAAA;AAEA,SAAS,SAAS,MAAuE,EAAA;AACvF,EAAO,OAAA,MAAA,KAAW,QAAQ,OAAO,MAAA,CAAO,QAAQ,QAAY,IAAA,OAAO,OAAO,KAAU,KAAA,QAAA,CAAA;AACtF;;;;"}
1
+ {"version":3,"file":"AdHocFiltersVariableUrlSyncHandler.js","sources":["../../../../src/variables/adhoc/AdHocFiltersVariableUrlSyncHandler.ts"],"sourcesContent":["import { SceneObjectUrlSyncHandler, SceneObjectUrlValue, SceneObjectUrlValues } from '../../core/types';\nimport { AdHocFiltersVariable, AdHocFilterWithLabels, isFilterComplete, isMultiValueOperator } from './AdHocFiltersVariable';\nimport { escapeUrlPipeDelimiters, toUrlCommaDelimitedString, unescapeUrlDelimiters } from '../utils';\n\nexport class AdHocFiltersVariableUrlSyncHandler implements SceneObjectUrlSyncHandler {\n public constructor(private _variable: AdHocFiltersVariable) {}\n\n private getKey(): string {\n return `var-${this._variable.state.name}`;\n }\n\n public getKeys(): string[] {\n return [this.getKey()];\n }\n\n public getUrlState(): SceneObjectUrlValues {\n const filters = this._variable.state.filters;\n\n if (filters.length === 0) {\n return { [this.getKey()]: [''] };\n }\n\n const value = filters.filter(isFilterComplete).map((filter) => toArray(filter).map(escapeUrlPipeDelimiters).join('|'));\n return { [this.getKey()]: value };\n }\n\n public updateFromUrl(values: SceneObjectUrlValues): void {\n const urlValue = values[this.getKey()];\n\n if (urlValue == null) {\n return;\n }\n\n const filters = deserializeUrlToFilters(urlValue);\n this._variable.setState({ filters });\n }\n}\n\nfunction deserializeUrlToFilters(value: SceneObjectUrlValue): AdHocFilterWithLabels[] {\n if (Array.isArray(value)) {\n const values = value;\n return values.map(toFilter).filter(isFilter);\n }\n\n const filter = toFilter(value);\n return filter === null ? [] : [filter];\n}\n\nfunction toArray(filter: AdHocFilterWithLabels): string[] {\n const result = [\n toUrlCommaDelimitedString(filter.key, filter.keyLabel),\n filter.operator,\n ];\n if (isMultiValueOperator(filter.operator)) {\n // TODO remove expect-error when we're on the latest version of @grafana/data\n // @ts-expect-error\n filter.values.forEach((value, index) => {\n result.push(toUrlCommaDelimitedString(value, filter.valueLabels?.[index]));\n });\n } else {\n result.push(toUrlCommaDelimitedString(filter.value, filter.valueLabels?.[0]));\n }\n return result;\n}\n\nfunction toFilter(urlValue: string | number | boolean | undefined | null): AdHocFilterWithLabels | null {\n if (typeof urlValue !== 'string' || urlValue.length === 0) {\n return null;\n }\n\n const [key, keyLabel, operator, _operatorLabel, ...values] = urlValue\n .split('|')\n .reduce<string[]>((acc, v) => {\n const [key, label] = v.split(',');\n\n acc.push(key, label ?? key);\n\n return acc;\n }, [])\n .map(unescapeUrlDelimiters);\n\n return {\n key,\n keyLabel,\n operator,\n value: values[0],\n // TODO remove expect-error when we're on the latest version of @grafana/data\n // @ts-expect-error\n values: isMultiValueOperator(operator) ? values.filter((_, index) => index % 2 === 0) : undefined,\n valueLabels: values.filter((_, index) => index % 2 === 1),\n condition: '',\n };\n}\n\nfunction isFilter(filter: AdHocFilterWithLabels | null): filter is AdHocFilterWithLabels {\n return filter !== null && typeof filter.key === 'string' && typeof filter.value === 'string';\n}\n"],"names":["_a","key"],"mappings":";;;AAIO,MAAM,kCAAwE,CAAA;AAAA,EAC5E,YAAoB,SAAiC,EAAA;AAAjC,IAAA,IAAA,CAAA,SAAA,GAAA,SAAA,CAAA;AAAA,GAAkC;AAAA,EAErD,MAAiB,GAAA;AACvB,IAAO,OAAA,CAAA,IAAA,EAAO,IAAK,CAAA,SAAA,CAAU,KAAM,CAAA,IAAA,CAAA,CAAA,CAAA;AAAA,GACrC;AAAA,EAEO,OAAoB,GAAA;AACzB,IAAO,OAAA,CAAC,IAAK,CAAA,MAAA,EAAQ,CAAA,CAAA;AAAA,GACvB;AAAA,EAEO,WAAoC,GAAA;AACzC,IAAM,MAAA,OAAA,GAAU,IAAK,CAAA,SAAA,CAAU,KAAM,CAAA,OAAA,CAAA;AAErC,IAAI,IAAA,OAAA,CAAQ,WAAW,CAAG,EAAA;AACxB,MAAA,OAAO,EAAE,CAAC,IAAA,CAAK,QAAW,GAAA,CAAC,EAAE,CAAE,EAAA,CAAA;AAAA,KACjC;AAEA,IAAA,MAAM,QAAQ,OAAQ,CAAA,MAAA,CAAO,gBAAgB,CAAA,CAAE,IAAI,CAAC,MAAA,KAAW,OAAQ,CAAA,MAAM,EAAE,GAAI,CAAA,uBAAuB,CAAE,CAAA,IAAA,CAAK,GAAG,CAAC,CAAA,CAAA;AACrH,IAAA,OAAO,EAAE,CAAC,IAAK,CAAA,MAAA,KAAW,KAAM,EAAA,CAAA;AAAA,GAClC;AAAA,EAEO,cAAc,MAAoC,EAAA;AACvD,IAAM,MAAA,QAAA,GAAW,MAAO,CAAA,IAAA,CAAK,MAAO,EAAA,CAAA,CAAA;AAEpC,IAAA,IAAI,YAAY,IAAM,EAAA;AACpB,MAAA,OAAA;AAAA,KACF;AA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QAAQ,OAAO,MAAA,CAAO,QAAQ,QAAY,IAAA,OAAO,OAAO,KAAU,KAAA,QAAA,CAAA;AACtF;;;;"}
@@ -1,44 +1,12 @@
1
- import uFuzzy from '@leeoniya/ufuzzy';
1
+ import { getFuzzySearcher } from '../utils.js';
2
2
 
3
3
  function getAdhocOptionSearcher(options) {
4
- const ufuzzy = new uFuzzy();
5
- const haystack = [];
6
- const limit = 1e4;
7
- return (search) => {
4
+ const haystack = options.map((o) => {
8
5
  var _a;
9
- if (search === "") {
10
- if (options.length > limit) {
11
- return options.slice(0, limit);
12
- } else {
13
- return options;
14
- }
15
- }
16
- if (haystack.length === 0) {
17
- for (let i = 0; i < options.length; i++) {
18
- haystack.push((_a = options[i].label) != null ? _a : String(options[i].value));
19
- }
20
- }
21
- const [idxs, info, order] = ufuzzy.search(haystack, search);
22
- const filteredOptions = [];
23
- if (idxs) {
24
- for (let i = 0; i < idxs.length; i++) {
25
- if (info && order) {
26
- const idx = order[i];
27
- filteredOptions.push(options[idxs[idx]]);
28
- } else {
29
- filteredOptions.push(options[idxs[i]]);
30
- }
31
- if (filteredOptions.length > limit) {
32
- return filteredOptions;
33
- }
34
- }
35
- return filteredOptions;
36
- }
37
- if (options.length > limit) {
38
- return options.slice(0, limit);
39
- }
40
- return options;
41
- };
6
+ return (_a = o.label) != null ? _a : String(o.value);
7
+ });
8
+ const fuzzySearch = getFuzzySearcher(haystack);
9
+ return (search) => fuzzySearch(search).map((i) => options[i]);
42
10
  }
43
11
 
44
12
  export { getAdhocOptionSearcher };
@@ -1 +1 @@
1
- {"version":3,"file":"getAdhocOptionSearcher.js","sources":["../../../../src/variables/adhoc/getAdhocOptionSearcher.ts"],"sourcesContent":["import uFuzzy from '@leeoniya/ufuzzy';\nimport { SelectableValue } from '@grafana/data';\n\nexport function getAdhocOptionSearcher(\n options: SelectableValue[],\n) {\n const ufuzzy = new uFuzzy();\n const haystack: string[] = [];\n const limit = 10000;\n\n return (search: string) => {\n if (search === '') {\n if (options.length > limit) {\n return options.slice(0, limit);\n } else {\n return options;\n }\n }\n\n if (haystack.length === 0) {\n for (let i = 0; i < options.length; i++) {\n haystack.push(options[i].label ?? String(options[i].value));\n }\n }\n\n const [idxs, info, order] = ufuzzy.search(haystack, search);\n const filteredOptions: SelectableValue[] = [];\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\n return filteredOptions;\n }\n\n if (options.length > limit) {\n return options.slice(0, limit);\n }\n\n return options;\n };\n}\n"],"names":[],"mappings":";;AAGO,SAAS,uBACd,OACA,EAAA;AACA,EAAM,MAAA,MAAA,GAAS,IAAI,MAAO,EAAA,CAAA;AAC1B,EAAA,MAAM,WAAqB,EAAC,CAAA;AAC5B,EAAA,MAAM,KAAQ,GAAA,GAAA,CAAA;AAEd,EAAA,OAAO,CAAC,MAAmB,KAAA;AAV7B,IAAA,IAAA,EAAA,CAAA;AAWI,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,IAAI,IAAA,QAAA,CAAS,WAAW,CAAG,EAAA;AACzB,MAAA,KAAA,IAAS,CAAI,GAAA,CAAA,EAAG,CAAI,GAAA,OAAA,CAAQ,QAAQ,CAAK,EAAA,EAAA;AACvC,QAAS,QAAA,CAAA,IAAA,CAAA,CAAK,aAAQ,CAAG,CAAA,CAAA,KAAA,KAAX,YAAoB,MAAO,CAAA,OAAA,CAAQ,CAAG,CAAA,CAAA,KAAK,CAAC,CAAA,CAAA;AAAA,OAC5D;AAAA,KACF;AAEA,IAAM,MAAA,CAAC,MAAM,IAAM,EAAA,KAAK,IAAI,MAAO,CAAA,MAAA,CAAO,UAAU,MAAM,CAAA,CAAA;AAC1D,IAAA,MAAM,kBAAqC,EAAC,CAAA;AAE5C,IAAA,IAAI,IAAM,EAAA;AACR,MAAA,KAAA,IAAS,CAAI,GAAA,CAAA,EAAG,CAAI,GAAA,IAAA,CAAK,QAAQ,CAAK,EAAA,EAAA;AACpC,QAAA,IAAI,QAAQ,KAAO,EAAA;AACjB,UAAA,MAAM,MAAM,KAAM,CAAA,CAAA,CAAA,CAAA;AAClB,UAAgB,eAAA,CAAA,IAAA,CAAK,OAAQ,CAAA,IAAA,CAAK,GAAK,CAAA,CAAA,CAAA,CAAA;AAAA,SAClC,MAAA;AACL,UAAgB,eAAA,CAAA,IAAA,CAAK,OAAQ,CAAA,IAAA,CAAK,CAAG,CAAA,CAAA,CAAA,CAAA;AAAA,SACvC;AAEA,QAAI,IAAA,eAAA,CAAgB,SAAS,KAAO,EAAA;AAClC,UAAO,OAAA,eAAA,CAAA;AAAA,SACT;AAAA,OACF;AAEA,MAAO,OAAA,eAAA,CAAA;AAAA,KACT;AAEA,IAAI,IAAA,OAAA,CAAQ,SAAS,KAAO,EAAA;AAC1B,MAAO,OAAA,OAAA,CAAQ,KAAM,CAAA,CAAA,EAAG,KAAK,CAAA,CAAA;AAAA,KAC/B;AAEA,IAAO,OAAA,OAAA,CAAA;AAAA,GACT,CAAA;AACF;;;;"}
1
+ {"version":3,"file":"getAdhocOptionSearcher.js","sources":["../../../../src/variables/adhoc/getAdhocOptionSearcher.ts"],"sourcesContent":["import { SelectableValue } from '@grafana/data';\nimport { getFuzzySearcher } from '../utils';\n\nexport function getAdhocOptionSearcher(options: SelectableValue[]) {\n const haystack = options.map((o) => o.label ?? String(o.value));\n const fuzzySearch = getFuzzySearcher(haystack);\n\n return (search: string) => fuzzySearch(search).map((i) => options[i]);\n}\n"],"names":[],"mappings":";;AAGO,SAAS,uBAAuB,OAA4B,EAAA;AACjE,EAAA,MAAM,QAAW,GAAA,OAAA,CAAQ,GAAI,CAAA,CAAC,CAAG,KAAA;AAJnC,IAAA,IAAA,EAAA,CAAA;AAIsC,IAAA,OAAA,CAAA,EAAA,GAAA,CAAA,CAAE,KAAF,KAAA,IAAA,GAAA,EAAA,GAAW,MAAO,CAAA,CAAA,CAAE,KAAK,CAAA,CAAA;AAAA,GAAC,CAAA,CAAA;AAC9D,EAAM,MAAA,WAAA,GAAc,iBAAiB,QAAQ,CAAA,CAAA;AAE7C,EAAO,OAAA,CAAC,WAAmB,WAAY,CAAA,MAAM,EAAE,GAAI,CAAA,CAAC,CAAM,KAAA,OAAA,CAAQ,CAAE,CAAA,CAAA,CAAA;AACtE;;;;"}
@@ -4,7 +4,6 @@ import { Select, MultiSelect, useTheme2, getSelectStyles, useStyles2, Checkbox,
4
4
  import { selectors } from '@grafana/e2e-selectors';
5
5
  import { cx, css } from '@emotion/css';
6
6
  import { getOptionSearcher } from './getOptionSearcher.js';
7
- import { sceneGraph } from '../../core/sceneGraph/index.js';
8
7
 
9
8
  var __defProp = Object.defineProperty;
10
9
  var __defProps = Object.defineProperties;
@@ -59,7 +58,6 @@ function VariableValueSelect({ model }) {
59
58
  const [inputValue, setInputValue] = useState("");
60
59
  const [hasCustomValue, setHasCustomValue] = useState(false);
61
60
  const selectValue = toSelectableValue(value, String(text));
62
- const queryController = sceneGraph.getQueryController(model);
63
61
  const optionSearcher = useMemo(() => getOptionSearcher(options, includeAll), [options, includeAll]);
64
62
  const onInputChange = (value2, { action }) => {
65
63
  if (action === "input-change") {
@@ -99,7 +97,6 @@ function VariableValueSelect({ model }) {
99
97
  "data-testid": selectors.pages.Dashboard.SubMenu.submenuItemValueDropDownValueLinkTexts(`${value}`),
100
98
  onChange: (newValue) => {
101
99
  model.changeValueTo(newValue.value, newValue.label);
102
- queryController == null ? void 0 : queryController.startProfile(model);
103
100
  if (hasCustomValue !== newValue.__isNew__) {
104
101
  setHasCustomValue(newValue.__isNew__);
105
102
  }
@@ -111,7 +108,6 @@ function VariableValueSelectMulti({ model }) {
111
108
  const arrayValue = useMemo(() => isArray(value) ? value : [value], [value]);
112
109
  const [uncommittedValue, setUncommittedValue] = useState(arrayValue);
113
110
  const [inputValue, setInputValue] = useState("");
114
- const queryController = sceneGraph.getQueryController(model);
115
111
  const optionSearcher = useMemo(() => getOptionSearcher(options, includeAll), [options, includeAll]);
116
112
  useEffect(() => {
117
113
  setUncommittedValue(arrayValue);
@@ -157,7 +153,6 @@ function VariableValueSelectMulti({ model }) {
157
153
  onInputChange,
158
154
  onBlur: () => {
159
155
  model.changeValueTo(uncommittedValue);
160
- queryController == null ? void 0 : queryController.startProfile(model);
161
156
  },
162
157
  filterOption: filterNoOp,
163
158
  "data-testid": selectors.pages.Dashboard.SubMenu.submenuItemValueDropDownValueLinkTexts(`${uncommittedValue}`),
@@ -1 +1 @@
1
- {"version":3,"file":"VariableValueSelect.js","sources":["../../../../src/variables/components/VariableValueSelect.tsx"],"sourcesContent":["import { isArray } from 'lodash';\nimport React, { RefCallback, useEffect, useMemo, useState } from 'react';\nimport {\n Checkbox,\n InputActionMeta,\n MultiSelect,\n Select,\n //@ts-ignore\n ToggleAllState,\n getSelectStyles,\n useStyles2,\n useTheme2,\n} from '@grafana/ui';\n\nimport { SceneComponentProps } from '../../core/types';\nimport { MultiValueVariable } from '../variants/MultiValueVariable';\nimport { VariableValue, VariableValueSingle } from '../types';\nimport { selectors } from '@grafana/e2e-selectors';\nimport { GrafanaTheme2, SelectableValue } from '@grafana/data';\nimport { css, cx } from '@emotion/css';\nimport { getOptionSearcher } from './getOptionSearcher';\nimport { sceneGraph } from '../../core/sceneGraph';\n\nconst filterNoOp = () => true;\n\nconst filterAll = (v: SelectableValue<VariableValueSingle>) => v.value !== '$__all';\n\nconst determineToggleAllState = (\n selectedValues: Array<SelectableValue<VariableValueSingle>>,\n options: Array<SelectableValue<VariableValueSingle>>\n) => {\n if (selectedValues.length === options.filter(filterAll).length) {\n return ToggleAllState.allSelected;\n } else if (\n selectedValues.length === 0 ||\n (selectedValues.length === 1 && selectedValues[0] && selectedValues[0].value === '$__all')\n ) {\n return ToggleAllState.noneSelected;\n } else {\n return ToggleAllState.indeterminate;\n }\n};\n\nexport function toSelectableValue<T>(value: T, label?: string): SelectableValue<T> {\n return {\n value,\n label: label ?? String(value),\n };\n}\n\nexport function VariableValueSelect({ model }: SceneComponentProps<MultiValueVariable>) {\n const { value, text, key, options, includeAll, isReadOnly, allowCustomValue = true } = model.useState();\n const [inputValue, setInputValue] = useState('');\n const [hasCustomValue, setHasCustomValue] = useState(false);\n const selectValue = toSelectableValue(value, String(text));\n const queryController = sceneGraph.getQueryController(model);\n const optionSearcher = useMemo(() => getOptionSearcher(options, includeAll), [options, includeAll]);\n\n const onInputChange = (value: string, { action }: InputActionMeta) => {\n if (action === 'input-change') {\n setInputValue(value);\n if (model.onSearchChange) {\n model.onSearchChange!(value);\n }\n return value;\n }\n\n return value;\n };\n\n const filteredOptions = optionSearcher(inputValue);\n\n const onOpenMenu = () => {\n if (hasCustomValue) {\n setInputValue(String(text));\n }\n };\n\n const onCloseMenu = () => {\n setInputValue('');\n };\n\n return (\n <Select<VariableValue>\n id={key}\n isValidNewOption={(inputValue) => inputValue.trim().length > 0}\n placeholder=\"Select value\"\n width=\"auto\"\n disabled={isReadOnly}\n value={selectValue}\n inputValue={inputValue}\n allowCustomValue={allowCustomValue}\n virtualized\n filterOption={filterNoOp}\n tabSelectsValue={false}\n onInputChange={onInputChange}\n onOpenMenu={onOpenMenu}\n onCloseMenu={onCloseMenu}\n options={filteredOptions}\n data-testid={selectors.pages.Dashboard.SubMenu.submenuItemValueDropDownValueLinkTexts(`${value}`)}\n onChange={(newValue) => {\n model.changeValueTo(newValue.value!, newValue.label!);\n queryController?.startProfile(model);\n\n if (hasCustomValue !== newValue.__isNew__) {\n setHasCustomValue(newValue.__isNew__);\n }\n }}\n />\n );\n}\n\nexport function VariableValueSelectMulti({ model }: SceneComponentProps<MultiValueVariable>) {\n const { value, options, key, maxVisibleValues, noValueOnClear, includeAll, isReadOnly, allowCustomValue = true } = model.useState();\n const arrayValue = useMemo(() => (isArray(value) ? value : [value]), [value]);\n // To not trigger queries on every selection we store this state locally here and only update the variable onBlur\n const [uncommittedValue, setUncommittedValue] = useState(arrayValue);\n const [inputValue, setInputValue] = useState('');\n const queryController = sceneGraph.getQueryController(model);\n\n const optionSearcher = useMemo(() => getOptionSearcher(options, includeAll), [options, includeAll]);\n\n // Detect value changes outside\n useEffect(() => {\n setUncommittedValue(arrayValue);\n }, [arrayValue]);\n\n const onInputChange = (value: string, { action }: InputActionMeta) => {\n if (action === 'input-change') {\n setInputValue(value);\n if (model.onSearchChange) {\n model.onSearchChange!(value);\n }\n return value;\n }\n\n if (action === 'input-blur') {\n setInputValue('');\n return '';\n }\n\n return inputValue;\n };\n\n const placeholder = options.length > 0 ? 'Select value' : '';\n const filteredOptions = optionSearcher(inputValue);\n\n return (\n <MultiSelect<VariableValueSingle>\n id={key}\n placeholder={placeholder}\n width=\"auto\"\n inputValue={inputValue}\n disabled={isReadOnly}\n value={uncommittedValue}\n noMultiValueWrap={true}\n maxVisibleValues={maxVisibleValues ?? 5}\n tabSelectsValue={false}\n virtualized\n allowCustomValue={allowCustomValue}\n //@ts-ignore\n toggleAllOptions={{\n enabled: true,\n optionsFilter: filterAll,\n determineToggleAllState: determineToggleAllState,\n }}\n options={filteredOptions}\n closeMenuOnSelect={false}\n components={{ Option: OptionWithCheckbox }}\n isClearable={true}\n hideSelectedOptions={false}\n onInputChange={onInputChange}\n onBlur={() => {\n model.changeValueTo(uncommittedValue);\n queryController?.startProfile(model);\n }}\n filterOption={filterNoOp}\n data-testid={selectors.pages.Dashboard.SubMenu.submenuItemValueDropDownValueLinkTexts(`${uncommittedValue}`)}\n onChange={(newValue, action) => {\n if (action.action === 'clear' && noValueOnClear) {\n model.changeValueTo([]);\n }\n setUncommittedValue(newValue.map((x) => x.value!));\n }}\n />\n );\n}\n\ninterface SelectMenuOptionProps<T> {\n isDisabled: boolean;\n isFocused: boolean;\n isSelected: boolean;\n innerProps: JSX.IntrinsicElements['div'];\n innerRef: RefCallback<HTMLDivElement>;\n renderOptionLabel?: (value: SelectableValue<T>) => JSX.Element;\n data: SelectableValue<T>;\n indeterminate: boolean;\n}\n\nexport const OptionWithCheckbox = ({\n children,\n data,\n innerProps,\n innerRef,\n isFocused,\n isSelected,\n indeterminate,\n renderOptionLabel,\n}: React.PropsWithChildren<SelectMenuOptionProps<unknown>>) => {\n // We are removing onMouseMove and onMouseOver from innerProps because they cause the whole\n // list to re-render everytime the user hovers over an option. This is a performance issue.\n // See https://github.com/JedWatson/react-select/issues/3128#issuecomment-451936743\n const { onMouseMove, onMouseOver, ...rest } = innerProps;\n const theme = useTheme2();\n const selectStyles = getSelectStyles(theme);\n const optionStyles = useStyles2(getOptionStyles);\n\n return (\n <div\n ref={innerRef}\n className={cx(selectStyles.option, isFocused && selectStyles.optionFocused)}\n {...rest}\n // TODO: use below selector once we update grafana dependencies to ^11.1.0\n // data-testid={selectors.components.Select.option}\n data-testid=\"data-testid Select option\"\n title={data.title}\n >\n <div className={optionStyles.checkbox}>\n <Checkbox indeterminate={indeterminate} value={isSelected} />\n </div>\n <div\n className={selectStyles.optionBody}\n data-testid={selectors.pages.Dashboard.SubMenu.submenuItemValueDropDownOptionTexts(\n data.label ?? String(data.value)\n )}\n >\n <span>{children}</span>\n </div>\n </div>\n );\n};\n\nOptionWithCheckbox.displayName = 'SelectMenuOptions';\n\nconst getOptionStyles = (theme: GrafanaTheme2) => ({\n checkbox: css({\n marginRight: theme.spacing(2),\n }),\n});\n\nexport function renderSelectForVariable(model: MultiValueVariable) {\n if (model.state.isMulti) {\n return <VariableValueSelectMulti model={model} />;\n } else {\n return <VariableValueSelect model={model} />;\n }\n}\n"],"names":["value","inputValue"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAuBA,MAAM,aAAa,MAAM,IAAA,CAAA;AA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B,CAAC,KAA0B,MAAA;AAAA,EACjD,UAAU,GAAI,CAAA;AAAA,IACZ,WAAA,EAAa,KAAM,CAAA,OAAA,CAAQ,CAAC,CAAA;AAAA,GAC7B,CAAA;AACH,CAAA,CAAA,CAAA;AAEO,SAAS,wBAAwB,KAA2B,EAAA;AACjE,EAAI,IAAA,KAAA,CAAM,MAAM,OAAS,EAAA;AACvB,IAAA,uBAAQ,KAAA,CAAA,aAAA,CAAA,wBAAA,EAAA;AAAA,MAAyB,KAAA;AAAA,KAAc,CAAA,CAAA;AAAA,GAC1C,MAAA;AACL,IAAA,uBAAQ,KAAA,CAAA,aAAA,CAAA,mBAAA,EAAA;AAAA,MAAoB,KAAA;AAAA,KAAc,CAAA,CAAA;AAAA,GAC5C;AACF;;;;"}
1
+ {"version":3,"file":"VariableValueSelect.js","sources":["../../../../src/variables/components/VariableValueSelect.tsx"],"sourcesContent":["import { isArray } from 'lodash';\nimport React, { RefCallback, useEffect, useMemo, useState } from 'react';\n\n//@ts-ignore\nimport { Checkbox, InputActionMeta, MultiSelect, Select, ToggleAllState, getSelectStyles, useStyles2, useTheme2 } from '@grafana/ui';\n\nimport { SceneComponentProps } from '../../core/types';\nimport { MultiValueVariable } from '../variants/MultiValueVariable';\nimport { VariableValue, VariableValueSingle } from '../types';\nimport { selectors } from '@grafana/e2e-selectors';\nimport { GrafanaTheme2, SelectableValue } from '@grafana/data';\nimport { css, cx } from '@emotion/css';\nimport { getOptionSearcher } from './getOptionSearcher';\n\nconst filterNoOp = () => true;\n\nconst filterAll = (v: SelectableValue<VariableValueSingle>) => v.value !== '$__all'\n\nconst determineToggleAllState = (\n selectedValues: Array<SelectableValue<VariableValueSingle>>,\n options: Array<SelectableValue<VariableValueSingle>>\n) => {\n if (selectedValues.length === options.filter(filterAll).length) {\n return ToggleAllState.allSelected;\n } else if (\n selectedValues.length === 0 ||\n (selectedValues.length === 1 && selectedValues[0] && selectedValues[0].value === '$__all')\n ) {\n return ToggleAllState.noneSelected;\n } else {\n return ToggleAllState.indeterminate;\n }\n};\n\nexport function toSelectableValue<T>(value: T, label?: string): SelectableValue<T> {\n return {\n value,\n label: label ?? String(value),\n };\n}\n\nexport function VariableValueSelect({ model }: SceneComponentProps<MultiValueVariable>) {\n const { value, text, key, options, includeAll, isReadOnly, allowCustomValue = true } = model.useState();\n const [inputValue, setInputValue] = useState('');\n const [hasCustomValue, setHasCustomValue] = useState(false);\n const selectValue = toSelectableValue(value, String(text));\n\n const optionSearcher = useMemo(() => getOptionSearcher(options, includeAll), [options, includeAll]);\n\n const onInputChange = (value: string, { action }: InputActionMeta) => {\n if (action === 'input-change') {\n setInputValue(value);\n if (model.onSearchChange) {\n model.onSearchChange!(value);\n }\n return value;\n }\n\n return value;\n };\n\n const filteredOptions = optionSearcher(inputValue);\n\n const onOpenMenu = () => {\n if (hasCustomValue) {\n setInputValue(String(text));\n }\n };\n\n const onCloseMenu = () => {\n setInputValue('');\n };\n\n return (\n <Select<VariableValue>\n id={key}\n isValidNewOption={(inputValue) => inputValue.trim().length > 0}\n placeholder=\"Select value\"\n width=\"auto\"\n disabled={isReadOnly}\n value={selectValue}\n inputValue={inputValue}\n allowCustomValue={allowCustomValue}\n virtualized\n filterOption={filterNoOp}\n tabSelectsValue={false}\n onInputChange={onInputChange}\n onOpenMenu={onOpenMenu}\n onCloseMenu={onCloseMenu}\n options={filteredOptions}\n data-testid={selectors.pages.Dashboard.SubMenu.submenuItemValueDropDownValueLinkTexts(`${value}`)}\n onChange={(newValue) => {\n model.changeValueTo(newValue.value!, newValue.label!);\n\n if (hasCustomValue !== newValue.__isNew__) {\n setHasCustomValue(newValue.__isNew__);\n }\n }}\n />\n );\n}\n\nexport function VariableValueSelectMulti({ model }: SceneComponentProps<MultiValueVariable>) {\n const { value, options, key, maxVisibleValues, noValueOnClear, includeAll, isReadOnly, allowCustomValue = true } = model.useState();\n const arrayValue = useMemo(() => (isArray(value) ? value : [value]), [value]);\n // To not trigger queries on every selection we store this state locally here and only update the variable onBlur\n const [uncommittedValue, setUncommittedValue] = useState(arrayValue);\n const [inputValue, setInputValue] = useState('');\n\n const optionSearcher = useMemo(() => getOptionSearcher(options, includeAll), [options, includeAll]);\n\n // Detect value changes outside\n useEffect(() => {\n setUncommittedValue(arrayValue);\n }, [arrayValue]);\n\n const onInputChange = (value: string, { action }: InputActionMeta) => {\n if (action === 'input-change') {\n setInputValue(value);\n if (model.onSearchChange) {\n model.onSearchChange!(value);\n }\n return value;\n }\n\n if (action === 'input-blur') {\n setInputValue('');\n return '';\n }\n\n return inputValue;\n };\n\n const placeholder = options.length > 0 ? 'Select value' : '';\n const filteredOptions = optionSearcher(inputValue);\n\n return (\n <MultiSelect<VariableValueSingle>\n id={key}\n placeholder={placeholder}\n width=\"auto\"\n inputValue={inputValue}\n disabled={isReadOnly}\n value={uncommittedValue}\n noMultiValueWrap={true}\n maxVisibleValues={maxVisibleValues ?? 5}\n tabSelectsValue={false}\n virtualized\n allowCustomValue={allowCustomValue}\n //@ts-ignore\n toggleAllOptions={{\n enabled: true,\n optionsFilter: filterAll,\n determineToggleAllState: determineToggleAllState,\n }}\n options={filteredOptions}\n closeMenuOnSelect={false}\n components={{ Option: OptionWithCheckbox }}\n isClearable={true}\n hideSelectedOptions={false}\n onInputChange={onInputChange}\n onBlur={() => {\n model.changeValueTo(uncommittedValue);\n }}\n filterOption={filterNoOp}\n data-testid={selectors.pages.Dashboard.SubMenu.submenuItemValueDropDownValueLinkTexts(`${uncommittedValue}`)}\n onChange={(newValue, action) => {\n if (action.action === 'clear' && noValueOnClear) {\n model.changeValueTo([]);\n }\n setUncommittedValue(newValue.map((x) => x.value!));\n }}\n />\n );\n}\n\ninterface SelectMenuOptionProps<T> {\n isDisabled: boolean;\n isFocused: boolean;\n isSelected: boolean;\n innerProps: JSX.IntrinsicElements['div'];\n innerRef: RefCallback<HTMLDivElement>;\n renderOptionLabel?: (value: SelectableValue<T>) => JSX.Element;\n data: SelectableValue<T>;\n indeterminate: boolean; \n}\n\nexport const OptionWithCheckbox = ({\n children,\n data,\n innerProps,\n innerRef,\n isFocused,\n isSelected,\n indeterminate,\n renderOptionLabel,\n}: React.PropsWithChildren<SelectMenuOptionProps<unknown>>) => {\n // We are removing onMouseMove and onMouseOver from innerProps because they cause the whole\n // list to re-render everytime the user hovers over an option. This is a performance issue.\n // See https://github.com/JedWatson/react-select/issues/3128#issuecomment-451936743\n const { onMouseMove, onMouseOver, ...rest } = innerProps;\n const theme = useTheme2();\n const selectStyles = getSelectStyles(theme);\n const optionStyles = useStyles2(getOptionStyles);\n\n return (\n <div\n ref={innerRef}\n className={cx(selectStyles.option, isFocused && selectStyles.optionFocused)}\n {...rest}\n // TODO: use below selector once we update grafana dependencies to ^11.1.0\n // data-testid={selectors.components.Select.option}\n data-testid=\"data-testid Select option\"\n title={data.title}\n >\n <div className={optionStyles.checkbox}>\n <Checkbox indeterminate={indeterminate} value={isSelected} />\n </div>\n <div\n className={selectStyles.optionBody}\n data-testid={selectors.pages.Dashboard.SubMenu.submenuItemValueDropDownOptionTexts(\n data.label ?? String(data.value)\n )}\n >\n <span>{children}</span>\n </div>\n </div>\n );\n};\n\nOptionWithCheckbox.displayName = 'SelectMenuOptions';\n\nconst getOptionStyles = (theme: GrafanaTheme2) => ({\n checkbox: css({\n marginRight: theme.spacing(2),\n }),\n});\n\nexport function renderSelectForVariable(model: MultiValueVariable) {\n if (model.state.isMulti) {\n return <VariableValueSelectMulti model={model} />;\n } else {\n return <VariableValueSelect model={model} />;\n }\n}\n"],"names":["value","inputValue"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAcA,MAAM,aAAa,MAAM,IAAA,CAAA;AAEzB,MAAM,SAAY,GAAA,CAAC,CAA4C,KAAA,CAAA,CAAE,KAAU,KAAA,QAAA,CAAA;AAE3E,MAAM,uBAAA,GAA0B,CAC9B,cAAA,EACA,OACG,KAAA;AACH,EAAA,IAAI,eAAe,MAAW,KAAA,OAAA,CAAQ,MAAO,CAAA,SAAS,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ABLE_VALUE, ALL_VARIABLE_TEXT } from '../constants.js';
2
+ import { getFuzzySearcher } from '../utils.js';
3
3
 
4
- function getOptionSearcher(options, includeAll) {
5
- const ufuzzy = new uFuzzy();
4
+ function getOptionSearcher(options, includeAll = false) {
6
5
  let allOptions = options;
7
- const haystack = [];
8
- const limit = 1e4;
9
6
  if (includeAll) {
10
7
  allOptions = [{ value: ALL_VARIABLE_VALUE, label: ALL_VARIABLE_TEXT }, ...allOptions];
11
8
  }
12
- return (search) => {
13
- if (search === "") {
14
- if (allOptions.length > limit) {
15
- return allOptions.slice(0, limit);
16
- } else {
17
- return allOptions;
18
- }
19
- }
20
- if (haystack.length === 0) {
21
- for (let i = 0; i < allOptions.length; i++) {
22
- haystack.push(allOptions[i].label);
23
- }
24
- }
25
- const [idxs, info, order] = ufuzzy.search(haystack, search);
26
- const filteredOptions = [];
27
- if (idxs) {
28
- for (let i = 0; i < idxs.length; i++) {
29
- if (info && order) {
30
- const idx = order[i];
31
- filteredOptions.push(allOptions[idxs[idx]]);
32
- } else {
33
- filteredOptions.push(allOptions[idxs[i]]);
34
- }
35
- if (filteredOptions.length > limit) {
36
- return filteredOptions;
37
- }
38
- }
39
- return filteredOptions;
40
- }
41
- if (allOptions.length > limit) {
42
- return allOptions.slice(0, limit);
43
- }
44
- return allOptions;
45
- };
9
+ const haystack = allOptions.map((o) => o.label);
10
+ const fuzzySearch = getFuzzySearcher(haystack);
11
+ return (search) => fuzzySearch(search).map((i) => allOptions[i]);
46
12
  }
47
13
 
48
14
  export { getOptionSearcher };
@@ -1 +1 @@
1
- {"version":3,"file":"getOptionSearcher.js","sources":["../../../../src/variables/components/getOptionSearcher.ts"],"sourcesContent":["import { VariableValueOption } from '../types';\nimport uFuzzy from '@leeoniya/ufuzzy';\nimport { ALL_VARIABLE_TEXT, ALL_VARIABLE_VALUE } from '../constants';\n\nexport function getOptionSearcher(\n options: VariableValueOption[],\n includeAll: boolean | undefined,\n) {\n const ufuzzy = new uFuzzy();\n let allOptions = options;\n const haystack: string[] = [];\n const limit = 10000;\n\n if (includeAll) {\n allOptions = [{ value: ALL_VARIABLE_VALUE, label: ALL_VARIABLE_TEXT }, ...allOptions];\n }\n\n return (search: string) => {\n if (search === '') {\n if (allOptions.length > limit) {\n return allOptions.slice(0, limit);\n } else {\n return allOptions;\n }\n }\n\n if (haystack.length === 0) {\n for (let i = 0; i < allOptions.length; i++) {\n haystack.push(allOptions[i].label);\n }\n }\n\n const [idxs, info, order] = ufuzzy.search(haystack, search);\n const filteredOptions: VariableValueOption[] = [];\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(allOptions[idxs[idx]]);\n } else {\n filteredOptions.push(allOptions[idxs[i]]);\n }\n\n if (filteredOptions.length > limit) {\n return filteredOptions;\n }\n }\n\n return filteredOptions;\n }\n\n if (allOptions.length > limit) {\n return allOptions.slice(0, limit);\n }\n\n return allOptions;\n };\n}\n"],"names":[],"mappings":";;;AAIgB,SAAA,iBAAA,CACd,SACA,UACA,EAAA;AACA,EAAM,MAAA,MAAA,GAAS,IAAI,MAAO,EAAA,CAAA;AAC1B,EAAA,IAAI,UAAa,GAAA,OAAA,CAAA;AACjB,EAAA,MAAM,WAAqB,EAAC,CAAA;AAC5B,EAAA,MAAM,KAAQ,GAAA,GAAA,CAAA;AAEd,EAAA,IAAI,UAAY,EAAA;AACd,IAAa,UAAA,GAAA,CAAC,EAAE,KAAO,EAAA,kBAAA,EAAoB,OAAO,iBAAkB,EAAA,EAAG,GAAG,UAAU,CAAA,CAAA;AAAA,GACtF;AAEA,EAAA,OAAO,CAAC,MAAmB,KAAA;AACzB,IAAA,IAAI,WAAW,EAAI,EAAA;AACjB,MAAI,IAAA,UAAA,CAAW,SAAS,KAAO,EAAA;AAC7B,QAAO,OAAA,UAAA,CAAW,KAAM,CAAA,CAAA,EAAG,KAAK,CAAA,CAAA;AAAA,OAC3B,MAAA;AACL,QAAO,OAAA,UAAA,CAAA;A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OptionSearcher.ts"],"sourcesContent":["import { VariableValueOption } from '../types';\nimport { ALL_VARIABLE_TEXT, ALL_VARIABLE_VALUE } from '../constants';\nimport { getFuzzySearcher } from '../utils';\n\nexport function getOptionSearcher(options: VariableValueOption[], includeAll = false) {\n let allOptions = options;\n\n if (includeAll) {\n allOptions = [{ value: ALL_VARIABLE_VALUE, label: ALL_VARIABLE_TEXT }, ...allOptions];\n }\n\n const haystack = allOptions.map((o) => o.label);\n const fuzzySearch = getFuzzySearcher(haystack);\n\n return (search: string) => fuzzySearch(search).map((i) => allOptions[i]);\n}\n"],"names":[],"mappings":";;;AAIgB,SAAA,iBAAA,CAAkB,OAAgC,EAAA,UAAA,GAAa,KAAO,EAAA;AACpF,EAAA,IAAI,UAAa,GAAA,OAAA,CAAA;AAEjB,EAAA,IAAI,UAAY,EAAA;AACd,IAAa,UAAA,GAAA,CAAC,EAAE,KAAO,EAAA,kBAAA,EAAoB,OAAO,iBAAkB,EAAA,EAAG,GAAG,UAAU,CAAA,CAAA;AAAA,GACtF;AAEA,EAAA,MAAM,WAAW,UAAW,CAAA,GAAA,CAAI,CAAC,CAAA,KAAM,EAAE,KAAK,CAAA,CAAA;AAC9C,EAAM,MAAA,WAAA,GAAc,iBAAiB,QAAQ,CAAA,CAAA;AAE7C,EAAO,OAAA,CAAC,WAAmB,WAAY,CAAA,MAAM,EAAE,GAAI,CAAA,CAAC,CAAM,KAAA,UAAA,CAAW,CAAE,CAAA,CAAA,CAAA;AACzE;;;;"}
@@ -151,7 +151,7 @@ class GroupByVariable extends MultiValueVariable {
151
151
  }
152
152
  GroupByVariable.Component = GroupByVariableRenderer;
153
153
  function GroupByVariableRenderer({ model }) {
154
- const { value, text, key, maxVisibleValues, noValueOnClear, options, includeAll } = model.useState();
154
+ const { value, text, key, maxVisibleValues, noValueOnClear, options, includeAll, allowCustomValue } = model.useState();
155
155
  const values = useMemo(() => {
156
156
  const arrayValue = isArray(value) ? value : [value];
157
157
  const arrayText = isArray(text) ? text : [text];
@@ -194,7 +194,7 @@ function GroupByVariableRenderer({ model }) {
194
194
  id: key,
195
195
  placeholder: "Select value",
196
196
  width: "auto",
197
- allowCustomValue: true,
197
+ allowCustomValue: allowCustomValue != null ? allowCustomValue : true,
198
198
  inputValue,
199
199
  value: uncommittedValue,
200
200
  noMultiValueWrap: true,