@grafana/scenes 5.25.1--canary.967.11837797508.0 → 5.25.1

Sign up to get free protection for your applications and to get access to all the features.
package/CHANGELOG.md CHANGED
@@ -1,3 +1,19 @@
1
+ # v5.25.1 (Wed Nov 20 2024)
2
+
3
+ #### 🐛 Bug Fix
4
+
5
+ - Annotations: Fix issue where dashboard annotations weren't rendering [#964](https://github.com/grafana/scenes/pull/964) ([@kaydelaney](https://github.com/kaydelaney))
6
+ - Variables: Fix search result ordering to use match quality [#969](https://github.com/grafana/scenes/pull/969) ([@leeoniya](https://github.com/leeoniya))
7
+ - SceneVariableSet: Notify scene objects that use time macros when time changes [#966](https://github.com/grafana/scenes/pull/966) ([@torkelo](https://github.com/torkelo))
8
+
9
+ #### Authors: 3
10
+
11
+ - kay delaney ([@kaydelaney](https://github.com/kaydelaney))
12
+ - Leon Sorokin ([@leeoniya](https://github.com/leeoniya))
13
+ - Torkel Ödegaard ([@torkelo](https://github.com/torkelo))
14
+
15
+ ---
16
+
1
17
  # v5.25.0 (Wed Nov 13 2024)
2
18
 
3
19
  #### 🚀 Enhancement
@@ -41,8 +41,6 @@ function cloneSceneObjectState(sceneState, withState) {
41
41
  for (const child of propValue) {
42
42
  if (child instanceof SceneObjectBase) {
43
43
  newArray.push(child.clone());
44
- } else if (typeof child === "object") {
45
- newArray.push(__spreadValues({}, child));
46
44
  } else {
47
45
  newArray.push(child);
48
46
  }
@@ -1 +1 @@
1
- {"version":3,"file":"utils.js","sources":["../../../../src/core/sceneGraph/utils.ts"],"sourcesContent":["import { SceneObject, SceneObjectState } from '../types';\n\nimport { SceneObjectBase } from '../SceneObjectBase';\nimport { SceneObjectRef } from '../SceneObjectRef';\n\n/**\n * Will create new SceneItem with shalled cloned state, but all states items of type SceneObject are deep cloned\n */\nexport function cloneSceneObject<T extends SceneObjectBase<TState>, TState extends SceneObjectState>(\n sceneObject: SceneObjectBase<TState>,\n withState?: Partial<TState>\n): T {\n const clonedState = cloneSceneObjectState(sceneObject.state, withState);\n return new (sceneObject.constructor as any)(clonedState);\n}\n\nexport function cloneSceneObjectState<TState extends SceneObjectState>(\n sceneState: TState,\n withState?: Partial<TState>\n): TState {\n const clonedState = { ...sceneState };\n\n Object.assign(clonedState, withState);\n\n // Clone any SceneItems in state\n for (const key in clonedState) {\n // Do not clone if was part of withState\n if (withState && withState[key] !== undefined) {\n continue;\n }\n\n const propValue = clonedState[key];\n if (propValue instanceof SceneObjectBase) {\n clonedState[key] = propValue.clone();\n }\n\n if (propValue instanceof SceneObjectRef) {\n console.warn('Cloning object with SceneObjectRef');\n continue;\n }\n\n // Clone scene objects in arrays\n if (Array.isArray(propValue)) {\n const newArray: any = [];\n for (const child of propValue) {\n if (child instanceof SceneObjectBase) {\n newArray.push(child.clone());\n } else if (typeof child === 'object') {\n newArray.push({ ...child });\n } else {\n newArray.push(child);\n }\n }\n clonedState[key] = newArray;\n }\n }\n\n return clonedState;\n}\n\n/** Walks up the scene graph, returning the first non-undefined result of `extract` */\nexport function getClosest<T>(sceneObject: SceneObject, extract: (s: SceneObject) => T | undefined): T | undefined {\n let curSceneObject: SceneObject | undefined = sceneObject;\n let extracted: T | undefined = undefined;\n\n while (curSceneObject && !extracted) {\n extracted = extract(curSceneObject);\n curSceneObject = curSceneObject.parent;\n }\n\n return extracted;\n}\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;AAQgB,SAAA,gBAAA,CACd,aACA,SACG,EAAA;AACH,EAAA,MAAM,WAAc,GAAA,qBAAA,CAAsB,WAAY,CAAA,KAAA,EAAO,SAAS,CAAA,CAAA;AACtE,EAAO,OAAA,IAAK,WAAY,CAAA,WAAA,CAAoB,WAAW,CAAA,CAAA;AACzD,CAAA;AAEgB,SAAA,qBAAA,CACd,YACA,SACQ,EAAA;AACR,EAAA,MAAM,cAAc,cAAK,CAAA,EAAA,EAAA,UAAA,CAAA,CAAA;AAEzB,EAAO,MAAA,CAAA,MAAA,CAAO,aAAa,SAAS,CAAA,CAAA;AAGpC,EAAA,KAAA,MAAW,OAAO,WA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A;AAClC,IAAA,cAAA,GAAiB,cAAe,CAAA,MAAA,CAAA;AAAA,GAClC;AAEA,EAAO,OAAA,SAAA,CAAA;AACT;;;;"}
1
+ {"version":3,"file":"utils.js","sources":["../../../../src/core/sceneGraph/utils.ts"],"sourcesContent":["import { SceneObject, SceneObjectState } from '../types';\n\nimport { SceneObjectBase } from '../SceneObjectBase';\nimport { SceneObjectRef } from '../SceneObjectRef';\n\n/**\n * Will create new SceneItem with shalled cloned state, but all states items of type SceneObject are deep cloned\n */\nexport function cloneSceneObject<T extends SceneObjectBase<TState>, TState extends SceneObjectState>(\n sceneObject: SceneObjectBase<TState>,\n withState?: Partial<TState>\n): T {\n const clonedState = cloneSceneObjectState(sceneObject.state, withState);\n return new (sceneObject.constructor as any)(clonedState);\n}\n\nexport function cloneSceneObjectState<TState extends SceneObjectState>(\n sceneState: TState,\n withState?: Partial<TState>\n): TState {\n const clonedState = { ...sceneState };\n\n Object.assign(clonedState, withState);\n\n // Clone any SceneItems in state\n for (const key in clonedState) {\n // Do not clone if was part of withState\n if (withState && withState[key] !== undefined) {\n continue;\n }\n\n const propValue = clonedState[key];\n if (propValue instanceof SceneObjectBase) {\n clonedState[key] = propValue.clone();\n }\n\n if (propValue instanceof SceneObjectRef) {\n console.warn('Cloning object with SceneObjectRef');\n continue;\n }\n\n // Clone scene objects in arrays\n if (Array.isArray(propValue)) {\n const newArray: any = [];\n for (const child of propValue) {\n if (child instanceof SceneObjectBase) {\n newArray.push(child.clone());\n } else {\n newArray.push(child);\n }\n }\n clonedState[key] = newArray;\n }\n }\n\n return clonedState;\n}\n\n/** Walks up the scene graph, returning the first non-undefined result of `extract` */\nexport function getClosest<T>(sceneObject: SceneObject, extract: (s: SceneObject) => T | undefined): T | undefined {\n let curSceneObject: SceneObject | undefined = sceneObject;\n let extracted: T | undefined = undefined;\n\n while (curSceneObject && !extracted) {\n extracted = extract(curSceneObject);\n curSceneObject = curSceneObject.parent;\n }\n\n return extracted;\n}\n"],"names":[],"mapp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AA,CAAA;AAAA,KACrB;AAAA,GACF;AAEA,EAAO,OAAA,WAAA,CAAA;AACT,CAAA;AAGgB,SAAA,UAAA,CAAc,aAA0B,OAA2D,EAAA;AACjH,EAAA,IAAI,cAA0C,GAAA,WAAA,CAAA;AAC9C,EAAA,IAAI,SAA2B,GAAA,KAAA,CAAA,CAAA;AAE/B,EAAO,OAAA,cAAA,IAAkB,CAAC,SAAW,EAAA;AACnC,IAAA,SAAA,GAAY,QAAQ,cAAc,CAAA,CAAA;AAClC,IAAA,cAAA,GAAiB,cAAe,CAAA,MAAA,CAAA;AAAA,GAClC;AAEA,EAAO,OAAA,SAAA,CAAA;AACT;;;;"}
@@ -17,6 +17,7 @@ var __spreadValues = (a, b) => {
17
17
  return a;
18
18
  };
19
19
  var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
20
+ const GLOBAL_ANNOTATION_ID = 0;
20
21
  function filterAnnotations(data, filters) {
21
22
  var _a;
22
23
  if (!Array.isArray(data) || data.length === 0) {
@@ -34,11 +35,11 @@ function filterAnnotations(data, filters) {
34
35
  const sourceField = frame.fields.find((f) => f.name === "source");
35
36
  if (sourceField) {
36
37
  if (panelIdField && sourceField.values[index].type === "dashboard") {
37
- matching = panelIdField.values[index] === filters.panelId;
38
+ matching = [filters.panelId, GLOBAL_ANNOTATION_ID].includes(panelIdField.values[index]);
38
39
  }
39
40
  const sourceFilter = sourceField.values[index].filter;
40
41
  if (sourceFilter) {
41
- const includes = ((_a = sourceFilter.ids) != null ? _a : []).includes(filters.panelId);
42
+ const includes = [...(_a = sourceFilter.ids) != null ? _a : [], GLOBAL_ANNOTATION_ID].includes(filters.panelId);
42
43
  if (sourceFilter.exclude) {
43
44
  if (includes) {
44
45
  matching = false;
@@ -1 +1 @@
1
- {"version":3,"file":"filterAnnotations.js","sources":["../../../../../src/querying/layers/annotations/filterAnnotations.ts"],"sourcesContent":["import { DataFrame, Field } from '@grafana/data';\nimport { DataLayerFilter } from '../../../core/types';\n\n// Provided SceneDataLayerProviderResult is an array of DataFrames.\nexport function filterAnnotations(data: DataFrame[], filters: DataLayerFilter) {\n if (!Array.isArray(data) || data.length === 0) {\n return data;\n }\n\n const rows = Array.from({ length: data.length }, () => new Set<number>());\n\n let frameIdx = 0;\n for (const frame of data) {\n for (let index = 0; index < frame.length; index++) {\n if (rows[frameIdx].has(index)) {\n continue;\n }\n let matching = true;\n\n // Let's call those standard fields that annotations data frame has.\n // panelId is a standard field, but it's not always present. It's added to annotations that were added to a particular panel.\n const panelIdField = frame.fields.find((f) => f.name === 'panelId');\n // Source field contains annotation definition, with type and filters included.\n const sourceField = frame.fields.find((f) => f.name === 'source');\n\n if (sourceField) {\n // Here we are filtering Grafana annotations that were added to a particular panel.\n if (panelIdField && sourceField.values[index].type === 'dashboard') {\n matching = panelIdField.values[index] === filters.panelId;\n }\n\n const sourceFilter = sourceField.values[index].filter;\n\n // Here we are filtering based on annotation filter definition.\n // Those fitlers are: Show annotation in selected panels, Exclude annotation from selected panels.\n if (sourceFilter) {\n const includes = (sourceFilter.ids ?? []).includes(filters.panelId);\n if (sourceFilter.exclude) {\n if (includes) {\n matching = false;\n }\n } else if (!includes) {\n matching = false;\n }\n }\n }\n\n if (matching) {\n rows[frameIdx].add(index);\n }\n }\n frameIdx++;\n }\n\n const processed: DataFrame[] = [];\n\n frameIdx = 0;\n for (const frame of data) {\n const frameLength = rows[frameIdx].size;\n const fields: Field[] = [];\n\n for (const field of frame.fields) {\n const buffer = [];\n\n for (let index = 0; index < frame.length; index++) {\n if (rows[frameIdx].has(index)) {\n buffer.push(field.values[index]);\n continue;\n }\n }\n\n fields.push({\n ...field,\n values: buffer,\n });\n }\n\n processed.push({\n ...frame,\n fields: fields,\n length: frameLength,\n });\n frameIdx++;\n }\n return processed;\n}\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;AAIgB,SAAA,iBAAA,CAAkB,MAAmB,OAA0B,EAAA;AAJ/E,EAAA,IAAA,EAAA,CAAA;AAKE,EAAA,IA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,CAAK,iCACV,KADU,CAAA,EAAA;AAAA,MAEb,MAAA;AAAA,MACA,MAAQ,EAAA,WAAA;AAAA,KACT,CAAA,CAAA,CAAA;AACD,IAAA,QAAA,EAAA,CAAA;AAAA,GACF;AACA,EAAO,OAAA,SAAA,CAAA;AACT;;;;"}
1
+ {"version":3,"file":"filterAnnotations.js","sources":["../../../../../src/querying/layers/annotations/filterAnnotations.ts"],"sourcesContent":["import { DataFrame, Field } from '@grafana/data';\nimport { DataLayerFilter } from '../../../core/types';\n\nconst GLOBAL_ANNOTATION_ID = 0;\n\n// Provided SceneDataLayerProviderResult is an array of DataFrames.\nexport function filterAnnotations(data: DataFrame[], filters: DataLayerFilter) {\n if (!Array.isArray(data) || data.length === 0) {\n return data;\n }\n\n const rows = Array.from({ length: data.length }, () => new Set<number>());\n\n let frameIdx = 0;\n for (const frame of data) {\n for (let index = 0; index < frame.length; index++) {\n if (rows[frameIdx].has(index)) {\n continue;\n }\n let matching = true;\n\n // Let's call those standard fields that annotations data frame has.\n // panelId is a standard field, but it's not always present. It's added to annotations that were added to a particular panel.\n const panelIdField = frame.fields.find((f) => f.name === 'panelId');\n // Source field contains annotation definition, with type and filters included.\n const sourceField = frame.fields.find((f) => f.name === 'source');\n\n if (sourceField) {\n // Here we are filtering Grafana annotations that were added to a particular panel.\n if (panelIdField && sourceField.values[index].type === 'dashboard') {\n matching = [filters.panelId, GLOBAL_ANNOTATION_ID].includes(panelIdField.values[index]);\n }\n\n const sourceFilter = sourceField.values[index].filter;\n\n // Here we are filtering based on annotation filter definition.\n // Those filters are: Show annotation in selected panels, Exclude annotation from selected panels.\n if (sourceFilter) {\n const includes = ([...(sourceFilter.ids ?? []), GLOBAL_ANNOTATION_ID]).includes(filters.panelId);\n if (sourceFilter.exclude) {\n if (includes) {\n matching = false;\n }\n } else if (!includes) {\n matching = false;\n }\n }\n }\n\n if (matching) {\n rows[frameIdx].add(index);\n }\n }\n frameIdx++;\n }\n\n const processed: DataFrame[] = [];\n\n frameIdx = 0;\n for (const frame of data) {\n const frameLength = rows[frameIdx].size;\n const fields: Field[] = [];\n\n for (const field of frame.fields) {\n const buffer = [];\n\n for (let index = 0; index < frame.length; index++) {\n if (rows[frameIdx].has(index)) {\n buffer.push(field.values[index]);\n continue;\n }\n }\n\n fields.push({\n ...field,\n values: buffer,\n });\n }\n\n processed.push({\n ...frame,\n fields: fields,\n length: frameLength,\n });\n frameIdx++;\n }\n\n return processed;\n}\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;AAGA,MAAM,oBAAuB,GAAA,CAAA,CAAA;AAGb,SAAA,iBAAA,CAAkB,MAAmB,OAA0B,EAAA;AAN/E,EAAA,IAAA,EAAA,CAAA;AAOE,EAAA,IAAI,CAAC,KAAM,CAAA,OAAA,CAAQ,IAAI,CAAK,IAAA,IAAA,CAAK,WAAW,CAAG,EAAA;AAC7C,IAAO,OAAA,IAAA,CAAA;AAAA,GACT;AAEA,EAAM,MAAA,IAAA,GAAO,KAAM,CAAA,IAAA,CAAK,EAAE,MAAA,EAAQ,IAAK,CAAA,MAAA,EAAU,EAAA,sBAAU,IAAA,GAAA,EAAa,CAAA,CAAA;AAExE,EAAA,IAAI,QAAW,GAAA,CAAA,CAAA;AACf,EAAA,KAAA,MAAW,SAAS,IAAM,EAAA;AACxB,IAAA,KAAA,IAAS,KAAQ,GAAA,CAAA,EAAG,KAAQ,GAAA,KAAA,CAAM,QAAQ,KAAS,EAAA,EAAA;AACjD,MAAA,IAAI,IAAK,CAAA,QAAA,CAAA,CAAU,GAAI,CAAA,KAAK,CAAG,EAAA;AAC7B,QAAA,SAAA;AAAA,OACF;AACA,MAAA,IAAI,QAAW,GAAA,IAAA,CAAA;AAIf,MAAM,MAAA,YAAA,GAAe,MAAM,MAAO,CAAA,IAAA,CAAK,CAAC,CAAM,KAAA,CAAA,CAAE,SAAS,SAAS,CAAA,CAAA;AAElE,MAAM,MAAA,WAAA,GAAc,MAAM,MAAO,CAAA,IAAA,CAAK,CAAC,CAA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,IAAS,MAAM,MAAQ,EAAA;AAChC,MAAA,MAAM,SAAS,EAAC,CAAA;AAEhB,MAAA,KAAA,IAAS,KAAQ,GAAA,CAAA,EAAG,KAAQ,GAAA,KAAA,CAAM,QAAQ,KAAS,EAAA,EAAA;AACjD,QAAA,IAAI,IAAK,CAAA,QAAA,CAAA,CAAU,GAAI,CAAA,KAAK,CAAG,EAAA;AAC7B,UAAO,MAAA,CAAA,IAAA,CAAK,KAAM,CAAA,MAAA,CAAO,KAAM,CAAA,CAAA,CAAA;AAC/B,UAAA,SAAA;AAAA,SACF;AAAA,OACF;AAEA,MAAO,MAAA,CAAA,IAAA,CAAK,iCACP,KADO,CAAA,EAAA;AAAA,QAEV,MAAQ,EAAA,MAAA;AAAA,OACT,CAAA,CAAA,CAAA;AAAA,KACH;AAEA,IAAU,SAAA,CAAA,IAAA,CAAK,iCACV,KADU,CAAA,EAAA;AAAA,MAEb,MAAA;AAAA,MACA,MAAQ,EAAA,WAAA;AAAA,KACT,CAAA,CAAA,CAAA;AACD,IAAA,QAAA,EAAA,CAAA;AAAA,GACF;AAEA,EAAO,OAAA,SAAA,CAAA;AACT;;;;"}
@@ -1,5 +1,5 @@
1
- import uFuzzy from '@leeoniya/ufuzzy';
2
1
  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,GAAA,GAAA;AAClD,MAAM,0BAA6B,GAAA,IAAA;AAEnC,SAAS,mBAAmB,OAAyC,EAAA;AAC1E,EAAM,MAAA,MAAA,GAAS,IAAI,MAAO,EAAA,CAAA;AAC1B,EAAA,MAAM,WAAqB,EAAC,CAAA;AAC5B,EAAA,MAAM,KAAQ,GAAA,GAAA,CAAA;AAEd,EAAO,OAAA,CAAC,QAAgB,eAAoC,KAAA;AAlB9D,IAAA,IAAA,EAAA,CAAA;AAmBI,IAAA,IAAI,WAAW,EAAI,EAAA;AACjB,MAAI,IAAA,OAAA,CAAQ,SAAS,KAAO,EAAA;AAC1B,QAAO,OAAA,OAAA,CAAQ,KAAM,CAAA,CAAA,EAAG,KAAK,CAAA,CAAA;AAA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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,QAAW,GAAA,OAAA,CAAQ,GAAI,CAAA,CAAC,CAAG,KAAA;AAdnC,IAAA,IAAA,EAAA,CAAA;AAcsC,IAAE,OAAA,CAAA,EAAA,GAAA,CAAA,CAAA,KAAA,KAAF,YAAW,CAAE,CAAA,KAAA,CAAA;AAAA,GAAM,CAAA,CAAA;AACvD,EAAM,MAAA,WAAA,GAAc,iBAAiB,QAAQ,CAAA,CAAA;AAE7C,EAAO,OAAA,CAAC,QAAgB,eAAoC,KAAA;AAC1D,IAAI,IAAA,eAAA,KAAoB,UAAc,IAAA,MAAA,KAAW,EAAI,EAAA;AAEnD,MAAA,MAAA,GAAS,CAAI,CAAA,EAAA,MAAA,CAAA,CAAA,CAAA,CAAA;AAAA,KACf;AAE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A,CAAA;AAAA,GACT;AACA,EAAA,IAAI,oBAAoB,OAAS,EAAA;AAC/B,IAAA,IAAI,gBAAkB,EAAA;AACpB,MAAO,OAAA,aAAA,CAAA;AAAA,KACT;AACA,IAAO,OAAA,CAAA,CAAA,EAAA,GAAA,MAAA,CAAO,WAAP,KAAA,IAAA,GAAA,KAAA,CAAA,GAAA,EAAA,CAAqB,CAAM,CAAA,KAAA,EAAA,CAAA;AAAA,GACpC;AAEA,EAAA,OAAO,OAAO,eAAoB,CAAA,IAAA,CAAC,WAAc,GAAA,CAAA,EAAG,OAAO,eAAqB,CAAA,CAAA,CAAA,GAAA,iBAAA,CAAA;AAClF,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,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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AA,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;;;;"}
@@ -1,48 +1,14 @@
1
- import uFuzzy from '@leeoniya/ufuzzy';
2
1
  import { ALL_VARIABLE_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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A,GACT,CAAA;AACF;;;;"}
1
+ {"version":3,"file":"getOptionSearcher.js","sources":["../../../../src/variables/components/getOptionSearcher.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;;;;"}
@@ -1,6 +1,7 @@
1
1
  import { isEqual } from 'lodash';
2
2
  import { sceneGraph } from '../core/sceneGraph/index.js';
3
3
  import { SceneQueryRunner } from '../querying/SceneQueryRunner.js';
4
+ import uFuzzy from '@leeoniya/ufuzzy';
4
5
 
5
6
  function isVariableValueEqual(a, b) {
6
7
  if (a === b) {
@@ -145,6 +146,27 @@ function handleOptionGroups(values) {
145
146
  }
146
147
  return result;
147
148
  }
149
+ function getFuzzySearcher(haystack, limit = 1e4) {
150
+ const ufuzzy = new uFuzzy();
151
+ const FIRST = Array.from({ length: Math.min(limit, haystack.length) }, (_, i) => i);
152
+ return (search) => {
153
+ if (search === "") {
154
+ return FIRST;
155
+ }
156
+ const [idxs, info, order] = ufuzzy.search(haystack, search);
157
+ if (idxs) {
158
+ if (info && order) {
159
+ const outIdxs = Array(Math.min(order.length, limit));
160
+ for (let i = 0; i < outIdxs.length; i++) {
161
+ outIdxs[i] = info.idx[order[i]];
162
+ }
163
+ return outIdxs;
164
+ }
165
+ return idxs.slice(0, limit);
166
+ }
167
+ return [];
168
+ };
169
+ }
148
170
 
149
- export { dataFromResponse, escapeLabelValueInExactSelector, escapeLabelValueInRegexSelector, escapeUrlCommaDelimiters, escapeUrlPipeDelimiters, getQueriesForVariables, handleOptionGroups, isVariableValueEqual, renderPrometheusLabelFilters, responseHasError, safeStringifyValue, toUrlCommaDelimitedString, unescapeUrlDelimiters };
171
+ export { dataFromResponse, escapeLabelValueInExactSelector, escapeLabelValueInRegexSelector, escapeUrlCommaDelimiters, escapeUrlPipeDelimiters, getFuzzySearcher, getQueriesForVariables, handleOptionGroups, isVariableValueEqual, renderPrometheusLabelFilters, responseHasError, safeStringifyValue, toUrlCommaDelimitedString, unescapeUrlDelimiters };
150
172
  //# sourceMappingURL=utils.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"utils.js","sources":["../../../src/variables/utils.ts"],"sourcesContent":["import { isEqual } from 'lodash';\nimport { VariableValue } from './types';\n// @ts-expect-error Remove when 11.1.x is released\nimport { AdHocVariableFilter, DataQueryError, GetTagResponse, MetricFindValue, SelectableValue } from '@grafana/data';\nimport { sceneGraph } from '../core/sceneGraph';\nimport { SceneDataQuery, SceneObject, SceneObjectState } from '../core/types';\nimport { SceneQueryRunner } from '../querying/SceneQueryRunner';\nimport { DataSourceRef } from '@grafana/schema';\n\nexport function isVariableValueEqual(a: VariableValue | null | undefined, b: VariableValue | null | undefined) {\n if (a === b) {\n return true;\n }\n\n return isEqual(a, b);\n}\n\nexport function safeStringifyValue(value: unknown) {\n // Avoid circular references ignoring those references\n const getCircularReplacer = () => {\n const seen = new WeakSet();\n return (_: string, value: object | null) => {\n if (typeof value === 'object' && value !== null) {\n if (seen.has(value)) {\n return;\n }\n seen.add(value);\n }\n return value;\n };\n };\n\n try {\n return JSON.stringify(value, getCircularReplacer());\n } catch (error) {\n console.error(error);\n }\n\n return '';\n}\n\nexport function renderPrometheusLabelFilters(filters: AdHocVariableFilter[]) {\n return filters.map((filter) => renderFilter(filter)).join(',');\n}\n\nfunction renderFilter(filter: AdHocVariableFilter) {\n let value = '';\n let operator = filter.operator;\n\n // map \"one of\" operator to regex\n if (operator === '=|') {\n operator = '=~'\n // TODO remove when we're on the latest version of @grafana/data\n // @ts-expect-error\n value = filter.values?.map(escapeLabelValueInRegexSelector).join('|');\n } else if (operator === '!=|') {\n operator = '!~'\n // TODO remove when we're on the latest version of @grafana/data\n // @ts-expect-error\n value = filter.values?.map(escapeLabelValueInRegexSelector).join('|');\n } else if (operator === '=~' || operator === '!~') {\n value = escapeLabelValueInRegexSelector(filter.value);\n } else {\n value = escapeLabelValueInExactSelector(filter.value);\n }\n\n return `${filter.key}${operator}\"${value}\"`;\n}\n\n// based on the openmetrics-documentation, the 3 symbols we have to handle are:\n// - \\n ... the newline character\n// - \\ ... the backslash character\n// - \" ... the double-quote character\nexport function escapeLabelValueInExactSelector(labelValue: string): string {\n return labelValue.replace(/\\\\/g, '\\\\\\\\').replace(/\\n/g, '\\\\n').replace(/\"/g, '\\\\\"');\n}\n\nexport function escapeLabelValueInRegexSelector(labelValue: string): string {\n return escapeLabelValueInExactSelector(escapeLokiRegexp(labelValue));\n}\n\nexport function isRegexSelector(selector?: string) {\n if (selector && (selector.includes('=~') || selector.includes('!~'))) {\n return true;\n }\n return false;\n}\n\n// Loki regular-expressions use the RE2 syntax (https://github.com/google/re2/wiki/Syntax),\n// so every character that matches something in that list has to be escaped.\n// the list of meta characters is: *+?()|\\.[]{}^$\n// we make a javascript regular expression that matches those characters:\nconst RE2_METACHARACTERS = /[*+?()|\\\\.\\[\\]{}^$]/g;\nfunction escapeLokiRegexp(value: string): string {\n return value.replace(RE2_METACHARACTERS, '\\\\$&');\n}\n\n/**\n * Get all queries in the scene that have the same datasource as provided source object\n */\nexport function getQueriesForVariables(\n sourceObject: SceneObject<SceneObjectState & { datasource: DataSourceRef | null }>\n) {\n const runners = sceneGraph.findAllObjects(\n sourceObject.getRoot(),\n (o) => o instanceof SceneQueryRunner\n ) as SceneQueryRunner[];\n\n const applicableRunners = filterOutInactiveRunnerDuplicates(runners).filter((r) => {\n return r.state.datasource?.uid === sourceObject.state.datasource?.uid;\n });\n\n if (applicableRunners.length === 0) {\n return [];\n }\n\n const result: SceneDataQuery[] = [];\n applicableRunners.forEach((r) => {\n result.push(...r.state.queries);\n });\n\n return result;\n}\n\n// Filters out inactive runner duplicates, keeping only the ones that are currently active.\n// This is needed for scnearios whan a query runner is cloned and the original is not removed but de-activated.\n// Can happen i.e. when editing a panel in Grafana Core dashboards.\nfunction filterOutInactiveRunnerDuplicates(runners: SceneQueryRunner[]) {\n // Group items by key\n const groupedItems: { [key: string]: SceneQueryRunner[] } = {};\n\n for (const item of runners) {\n if (item.state.key) {\n if (!(item.state.key in groupedItems)) {\n groupedItems[item.state.key] = [];\n }\n groupedItems[item.state.key].push(item);\n }\n }\n\n // Filter out inactive items and concatenate active items\n return Object.values(groupedItems).flatMap((group) => {\n const activeItems = group.filter((item) => item.isActive);\n // Keep inactive items if there's only one item with the key\n if (activeItems.length === 0 && group.length === 1) {\n return group;\n }\n return activeItems;\n });\n}\n\nexport function escapeUrlPipeDelimiters(value: string | undefined): string {\n if (value === null || value === undefined) {\n return '';\n }\n\n // Replace the pipe due to using it as a filter separator\n return (value = /\\|/g[Symbol.replace](value, '__gfp__'));\n}\n\nexport function escapeUrlCommaDelimiters(value: string | undefined): string {\n if (value === null || value === undefined) {\n return '';\n }\n\n // Replace the comma due to using it as a value/label separator\n return /,/g[Symbol.replace](value, '__gfc__');\n}\n\nexport function unescapeUrlDelimiters(value: string | undefined): string {\n if (value === null || value === undefined) {\n return '';\n }\n\n value = /__gfp__/g[Symbol.replace](value, '|');\n value = /__gfc__/g[Symbol.replace](value, ',');\n\n return value;\n}\n\nexport function toUrlCommaDelimitedString(key: string, label?: string): string {\n // Omit for identical key/label or when label is not set at all\n if (!label || key === label) {\n return escapeUrlCommaDelimiters(key);\n }\n\n return [key, label].map(escapeUrlCommaDelimiters).join(',');\n}\n\nexport function dataFromResponse(response: GetTagResponse | MetricFindValue[]) {\n return Array.isArray(response) ? response : response.data;\n}\n\nexport function responseHasError(response: GetTagResponse | MetricFindValue[]): response is GetTagResponse & { error: DataQueryError } {\n return !Array.isArray(response) && Boolean(response.error);\n}\n\n// Collect a flat list of SelectableValues with a `group` property into a hierarchical list with groups\nexport function handleOptionGroups(values: SelectableValue[]): Array<SelectableValue<string>> {\n const result: Array<SelectableValue<string>> = [];\n const groupedResults = new Map<string, Array<SelectableValue<string>>>();\n\n for (const value of values) {\n const groupLabel = value.group;\n if (groupLabel) {\n let group = groupedResults.get(groupLabel);\n\n if (!group) {\n group = [];\n groupedResults.set(groupLabel, group);\n result.push({ label: groupLabel, options: group });\n }\n\n group.push(value);\n } else {\n result.push(value);\n }\n }\n\n return result;\n}\n"],"names":["value"],"mappings":";;;;AASgB,SAAA,oBAAA,CAAqB,GAAqC,CAAqC,EAAA;AAC7G,EAAA,IAAI,MAAM,CAAG,EAAA;AACX,IAAO,OAAA,IAAA,CAAA;AAAA,GACT;AAEA,EAAO,OAAA,OAAA,CAAQ,GAAG,CAAC,CAAA,CAAA;AACrB,CAAA;AAEO,SAAS,mBAAmB,KAAgB,EAAA;AAEjD,EAAA,MAAM,sBAAsB,MAAM;AAChC,IAAM,MAAA,IAAA,uBAAW,OAAQ,EAAA,CAAA;AACzB,IAAO,OAAA,CA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Equal } from 'lodash';\nimport { VariableValue } from './types';\n// @ts-expect-error Remove when 11.1.x is released\nimport { AdHocVariableFilter, DataQueryError, GetTagResponse, MetricFindValue, SelectableValue } from '@grafana/data';\nimport { sceneGraph } from '../core/sceneGraph';\nimport { SceneDataQuery, SceneObject, SceneObjectState } from '../core/types';\nimport { SceneQueryRunner } from '../querying/SceneQueryRunner';\nimport { DataSourceRef } from '@grafana/schema';\nimport uFuzzy from '@leeoniya/ufuzzy';\n\nexport function isVariableValueEqual(a: VariableValue | null | undefined, b: VariableValue | null | undefined) {\n if (a === b) {\n return true;\n }\n\n return isEqual(a, b);\n}\n\nexport function safeStringifyValue(value: unknown) {\n // Avoid circular references ignoring those references\n const getCircularReplacer = () => {\n const seen = new WeakSet();\n return (_: string, value: object | null) => {\n if (typeof value === 'object' && value !== null) {\n if (seen.has(value)) {\n return;\n }\n seen.add(value);\n }\n return value;\n };\n };\n\n try {\n return JSON.stringify(value, getCircularReplacer());\n } catch (error) {\n console.error(error);\n }\n\n return '';\n}\n\nexport function renderPrometheusLabelFilters(filters: AdHocVariableFilter[]) {\n return filters.map((filter) => renderFilter(filter)).join(',');\n}\n\nfunction renderFilter(filter: AdHocVariableFilter) {\n let value = '';\n let operator = filter.operator;\n\n // map \"one of\" operator to regex\n if (operator === '=|') {\n operator = '=~';\n // TODO remove when we're on the latest version of @grafana/data\n // @ts-expect-error\n value = filter.values?.map(escapeLabelValueInRegexSelector).join('|');\n } else if (operator === '!=|') {\n operator = '!~';\n // TODO remove when we're on the latest version of @grafana/data\n // @ts-expect-error\n value = filter.values?.map(escapeLabelValueInRegexSelector).join('|');\n } else if (operator === '=~' || operator === '!~') {\n value = escapeLabelValueInRegexSelector(filter.value);\n } else {\n value = escapeLabelValueInExactSelector(filter.value);\n }\n\n return `${filter.key}${operator}\"${value}\"`;\n}\n\n// based on the openmetrics-documentation, the 3 symbols we have to handle are:\n// - \\n ... the newline character\n// - \\ ... the backslash character\n// - \" ... the double-quote character\nexport function escapeLabelValueInExactSelector(labelValue: string): string {\n return labelValue.replace(/\\\\/g, '\\\\\\\\').replace(/\\n/g, '\\\\n').replace(/\"/g, '\\\\\"');\n}\n\nexport function escapeLabelValueInRegexSelector(labelValue: string): string {\n return escapeLabelValueInExactSelector(escapeLokiRegexp(labelValue));\n}\n\nexport function isRegexSelector(selector?: string) {\n if (selector && (selector.includes('=~') || selector.includes('!~'))) {\n return true;\n }\n return false;\n}\n\n// Loki regular-expressions use the RE2 syntax (https://github.com/google/re2/wiki/Syntax),\n// so every character that matches something in that list has to be escaped.\n// the list of meta characters is: *+?()|\\.[]{}^$\n// we make a javascript regular expression that matches those characters:\nconst RE2_METACHARACTERS = /[*+?()|\\\\.\\[\\]{}^$]/g;\nfunction escapeLokiRegexp(value: string): string {\n return value.replace(RE2_METACHARACTERS, '\\\\$&');\n}\n\n/**\n * Get all queries in the scene that have the same datasource as provided source object\n */\nexport function getQueriesForVariables(\n sourceObject: SceneObject<SceneObjectState & { datasource: DataSourceRef | null }>\n) {\n const runners = sceneGraph.findAllObjects(\n sourceObject.getRoot(),\n (o) => o instanceof SceneQueryRunner\n ) as SceneQueryRunner[];\n\n const applicableRunners = filterOutInactiveRunnerDuplicates(runners).filter((r) => {\n return r.state.datasource?.uid === sourceObject.state.datasource?.uid;\n });\n\n if (applicableRunners.length === 0) {\n return [];\n }\n\n const result: SceneDataQuery[] = [];\n applicableRunners.forEach((r) => {\n result.push(...r.state.queries);\n });\n\n return result;\n}\n\n// Filters out inactive runner duplicates, keeping only the ones that are currently active.\n// This is needed for scnearios whan a query runner is cloned and the original is not removed but de-activated.\n// Can happen i.e. when editing a panel in Grafana Core dashboards.\nfunction filterOutInactiveRunnerDuplicates(runners: SceneQueryRunner[]) {\n // Group items by key\n const groupedItems: { [key: string]: SceneQueryRunner[] } = {};\n\n for (const item of runners) {\n if (item.state.key) {\n if (!(item.state.key in groupedItems)) {\n groupedItems[item.state.key] = [];\n }\n groupedItems[item.state.key].push(item);\n }\n }\n\n // Filter out inactive items and concatenate active items\n return Object.values(groupedItems).flatMap((group) => {\n const activeItems = group.filter((item) => item.isActive);\n // Keep inactive items if there's only one item with the key\n if (activeItems.length === 0 && group.length === 1) {\n return group;\n }\n return activeItems;\n });\n}\n\nexport function escapeUrlPipeDelimiters(value: string | undefined): string {\n if (value === null || value === undefined) {\n return '';\n }\n\n // Replace the pipe due to using it as a filter separator\n return (value = /\\|/g[Symbol.replace](value, '__gfp__'));\n}\n\nexport function escapeUrlCommaDelimiters(value: string | undefined): string {\n if (value === null || value === undefined) {\n return '';\n }\n\n // Replace the comma due to using it as a value/label separator\n return /,/g[Symbol.replace](value, '__gfc__');\n}\n\nexport function unescapeUrlDelimiters(value: string | undefined): string {\n if (value === null || value === undefined) {\n return '';\n }\n\n value = /__gfp__/g[Symbol.replace](value, '|');\n value = /__gfc__/g[Symbol.replace](value, ',');\n\n return value;\n}\n\nexport function toUrlCommaDelimitedString(key: string, label?: string): string {\n // Omit for identical key/label or when label is not set at all\n if (!label || key === label) {\n return escapeUrlCommaDelimiters(key);\n }\n\n return [key, label].map(escapeUrlCommaDelimiters).join(',');\n}\n\nexport function dataFromResponse(response: GetTagResponse | MetricFindValue[]) {\n return Array.isArray(response) ? response : response.data;\n}\n\nexport function responseHasError(\n response: GetTagResponse | MetricFindValue[]\n): response is GetTagResponse & { error: DataQueryError } {\n return !Array.isArray(response) && Boolean(response.error);\n}\n\n// Collect a flat list of SelectableValues with a `group` property into a hierarchical list with groups\nexport function handleOptionGroups(values: SelectableValue[]): Array<SelectableValue<string>> {\n const result: Array<SelectableValue<string>> = [];\n const groupedResults = new Map<string, Array<SelectableValue<string>>>();\n\n for (const value of values) {\n const groupLabel = value.group;\n if (groupLabel) {\n let group = groupedResults.get(groupLabel);\n\n if (!group) {\n group = [];\n groupedResults.set(groupLabel, group);\n result.push({ label: groupLabel, options: group });\n }\n\n group.push(value);\n } else {\n result.push(value);\n }\n }\n\n return result;\n}\n\nexport function getFuzzySearcher(haystack: string[], limit = 10_000) {\n const ufuzzy = new uFuzzy();\n\n const FIRST = Array.from({ length: Math.min(limit, haystack.length) }, (_, i) => i);\n\n // returns matched indices by quality\n return (search: string): number[] => {\n if (search === '') {\n return FIRST;\n }\n\n const [idxs, info, order] = ufuzzy.search(haystack, search);\n\n if (idxs) {\n if (info && order) {\n const outIdxs = Array(Math.min(order.length, limit));\n\n for (let i = 0; i < outIdxs.length; i++) {\n outIdxs[i] = info.idx[order[i]];\n }\n\n return outIdxs;\n }\n\n return idxs.slice(0, limit);\n }\n\n return [];\n };\n}\n"],"names":["value"],"mappings":";;;;;AAUgB,SAAA,oBAAA,CAAqB,GAAqC,CAAqC,EAAA;AAC7G,EAAA,IAAI,MAAM,CAAG,EAAA;AACX,IAAO,OAAA,IAAA,CAAA;AAAA,GACT;AAEA,EAAO,OAAA,OAAA,CAAQ,GAAG,CAAC,CAAA,CAAA;AACrB,CAAA;AAEO,SAAS,mBAAmB,KAAgB,EAAA;AAEjD,EAAA,MAAM,sBAAsB,MAAM;AAChC,IAAM,MAAA,IAAA,uBAAW,OAAQ,EAAA,CAAA;AACzB,IAAO,OAAA,CAAC,GAAWA,MAAyB,KAAA;AAC1C,MAAA,IAAI,OAAOA,MAAAA,KAAU,QAAYA,IAAAA,MAAAA,KAAU,IAAM,EAAA;AAC/C,QAAI,IAAA,IAAA,CAAK,GAAIA,CAAAA,MAAK,CAAG,EAAA;AACnB,UAAA,OAAA;AAAA,SACF;AACA,QAAA,IAAA,CAAK,IAAIA,MAAK,CAAA,CAAA;AAAA,OAChB;AACA,MAAOA,OAAAA,MAAAA,CAAAA;AAAA,KACT,CAAA;AAAA,GACF,CAAA;AAEA,EAAI,IAAA;AACF,IAAA,OAAO,IAAK,CAAA,SAAA,CAAU,KAAO,EAAA,mBAAA,EAAqB,CAAA,CAAA;AAAA,WAC3C,KAAP,EAAA;AACA,IAAA,OAAA,CAAQ,MAAM,KAAK,CAAA,CAAA;AAAA,GACrB;AAEA,EAAO,OAAA,EAAA,CAAA;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