@grafana/scenes 6.45.0 → 6.47.0--canary.1236.19298426344.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +1 -1
- package/dist/esm/variables/groupby/GroupByVariable.js.map +1 -1
- package/dist/esm/variables/types.js.map +1 -1
- package/dist/esm/variables/variants/CustomVariable.js +24 -1
- package/dist/esm/variables/variants/CustomVariable.js.map +1 -1
- package/dist/esm/variables/variants/MultiValueVariable.js +39 -18
- package/dist/esm/variables/variants/MultiValueVariable.js.map +1 -1
- package/dist/esm/variables/variants/query/toMetricFindValues.js +65 -42
- package/dist/esm/variables/variants/query/toMetricFindValues.js.map +1 -1
- package/dist/esm/variables/variants/query/utils.js +1 -1
- package/dist/esm/variables/variants/query/utils.js.map +1 -1
- package/dist/index.d.ts +16 -7
- package/dist/index.js +127 -60
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { getProcessedDataFrames, getFieldDisplayName, FieldType
|
|
1
|
+
import { isDataFrame, getProcessedDataFrames, getFieldDisplayName, FieldType } from '@grafana/data';
|
|
2
2
|
import { map } from 'rxjs';
|
|
3
3
|
|
|
4
|
-
function toMetricFindValues() {
|
|
4
|
+
function toMetricFindValues(valueProp, textProp) {
|
|
5
5
|
return (source) => source.pipe(
|
|
6
6
|
map((panelData) => {
|
|
7
7
|
const frames = panelData.series;
|
|
@@ -14,58 +14,81 @@ function toMetricFindValues() {
|
|
|
14
14
|
if (frames[0].fields.length === 0) {
|
|
15
15
|
return [];
|
|
16
16
|
}
|
|
17
|
-
const
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
let textIndex = -1;
|
|
21
|
-
let stringIndex = -1;
|
|
22
|
-
let expandableIndex = -1;
|
|
23
|
-
for (const frame of processedDataFrames) {
|
|
24
|
-
for (let index = 0; index < frame.fields.length; index++) {
|
|
25
|
-
const field = frame.fields[index];
|
|
26
|
-
const fieldName = getFieldDisplayName(field, frame, frames).toLowerCase();
|
|
27
|
-
if (field.type === FieldType.string && stringIndex === -1) {
|
|
28
|
-
stringIndex = index;
|
|
29
|
-
}
|
|
30
|
-
if (fieldName === "text" && field.type === FieldType.string && textIndex === -1) {
|
|
31
|
-
textIndex = index;
|
|
32
|
-
}
|
|
33
|
-
if (fieldName === "value" && field.type === FieldType.string && valueIndex === -1) {
|
|
34
|
-
valueIndex = index;
|
|
35
|
-
}
|
|
36
|
-
if (fieldName === "expandable" && (field.type === FieldType.boolean || field.type === FieldType.number) && expandableIndex === -1) {
|
|
37
|
-
expandableIndex = index;
|
|
38
|
-
}
|
|
39
|
-
}
|
|
17
|
+
const indices = findFieldsIndices(frames);
|
|
18
|
+
if (indices.value === -1 && indices.text === -1 && !indices.properties.length) {
|
|
19
|
+
throw new Error("Couldn't find any field of type string in the results");
|
|
40
20
|
}
|
|
41
|
-
if (
|
|
42
|
-
|
|
21
|
+
if (indices.value === -1 && indices.text === -1 && indices.properties.length === 1) {
|
|
22
|
+
indices.value = indices.properties[0].index;
|
|
23
|
+
indices.properties = [];
|
|
43
24
|
}
|
|
25
|
+
if (indices.value === -1 && indices.text === -1 && indices.properties.length && true && true) {
|
|
26
|
+
throw new Error("Properties found in series but missing valueProp and textProp");
|
|
27
|
+
}
|
|
28
|
+
const metrics = [];
|
|
44
29
|
for (const frame of frames) {
|
|
45
30
|
for (let index = 0; index < frame.length; index++) {
|
|
46
|
-
const
|
|
47
|
-
const
|
|
48
|
-
const
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
31
|
+
const value = indices.value !== -1 ? frame.fields[indices.value].values.get(index) : "";
|
|
32
|
+
const text = indices.text !== -1 ? frame.fields[indices.text].values.get(index) : "";
|
|
33
|
+
const expandable = indices.expandable !== -1 ? frame.fields[indices.expandable].values.get(index) : void 0;
|
|
34
|
+
if (!indices.properties.length) {
|
|
35
|
+
metrics.push({
|
|
36
|
+
value: value || text,
|
|
37
|
+
text: text || value,
|
|
38
|
+
expandable
|
|
39
|
+
});
|
|
52
40
|
continue;
|
|
53
41
|
}
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
42
|
+
const properties = indices.properties.reduce((acc, p) => {
|
|
43
|
+
acc[p.name] = frame.fields[p.index].values.get(index);
|
|
44
|
+
return acc;
|
|
45
|
+
}, {});
|
|
46
|
+
metrics.push({
|
|
47
|
+
value: value || valueProp || text || textProp,
|
|
48
|
+
text: text || textProp || value || valueProp,
|
|
49
|
+
properties,
|
|
50
|
+
expandable
|
|
51
|
+
});
|
|
63
52
|
}
|
|
64
53
|
}
|
|
65
54
|
return metrics;
|
|
66
55
|
})
|
|
67
56
|
);
|
|
68
57
|
}
|
|
58
|
+
function findFieldsIndices(frames) {
|
|
59
|
+
const indices = {
|
|
60
|
+
value: -1,
|
|
61
|
+
text: -1,
|
|
62
|
+
properties: [],
|
|
63
|
+
expandable: -1
|
|
64
|
+
};
|
|
65
|
+
for (const frame of getProcessedDataFrames(frames)) {
|
|
66
|
+
for (let index = 0; index < frame.fields.length; index++) {
|
|
67
|
+
const field = frame.fields[index];
|
|
68
|
+
const fieldName = getFieldDisplayName(field, frame, frames).toLowerCase();
|
|
69
|
+
if (field.type === FieldType.string) {
|
|
70
|
+
if (fieldName === "value") {
|
|
71
|
+
if (indices.value === -1) {
|
|
72
|
+
indices.value = index;
|
|
73
|
+
}
|
|
74
|
+
continue;
|
|
75
|
+
}
|
|
76
|
+
if (fieldName === "text") {
|
|
77
|
+
if (indices.text === -1) {
|
|
78
|
+
indices.text = index;
|
|
79
|
+
}
|
|
80
|
+
continue;
|
|
81
|
+
}
|
|
82
|
+
indices.properties.push({ name: fieldName, index });
|
|
83
|
+
continue;
|
|
84
|
+
}
|
|
85
|
+
if (fieldName === "expandable" && (field.type === FieldType.boolean || field.type === FieldType.number) && indices.expandable === -1) {
|
|
86
|
+
indices.expandable = index;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
return indices;
|
|
91
|
+
}
|
|
69
92
|
function areMetricFindValues(data) {
|
|
70
93
|
if (!data) {
|
|
71
94
|
return false;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"toMetricFindValues.js","sources":["../../../../../src/variables/variants/query/toMetricFindValues.ts"],"sourcesContent":["import {\n FieldType,\n getFieldDisplayName,\n isDataFrame,\n MetricFindValue,\n PanelData,\n
|
|
1
|
+
{"version":3,"file":"toMetricFindValues.js","sources":["../../../../../src/variables/variants/query/toMetricFindValues.ts"],"sourcesContent":["import {\n DataFrame,\n FieldType,\n getFieldDisplayName,\n getProcessedDataFrames,\n isDataFrame,\n MetricFindValue,\n PanelData,\n} from '@grafana/data';\nimport { map, OperatorFunction } from 'rxjs';\n\ninterface MetricFindValueWithOptionalProperties extends MetricFindValue {\n properties?: Record<string, any>;\n}\n\nexport function toMetricFindValues(\n valueProp?: string,\n textProp?: string\n): OperatorFunction<PanelData, MetricFindValueWithOptionalProperties[]> {\n return (source) =>\n source.pipe(\n map((panelData) => {\n const frames = panelData.series;\n if (!frames || !frames.length) {\n return [];\n }\n\n if (areMetricFindValues(frames)) {\n return frames;\n }\n\n if (frames[0].fields.length === 0) {\n return [];\n }\n\n const indices = findFieldsIndices(frames);\n\n if (indices.value === -1 && indices.text === -1 && !indices.properties.length) {\n throw new Error(\"Couldn't find any field of type string in the results\");\n }\n\n // a single field of type string that is neither named \"value\" nor \"text\" is considered as \"value\"\n if (indices.value === -1 && indices.text === -1 && indices.properties.length === 1) {\n indices.value = indices.properties[0].index;\n indices.properties = [];\n }\n\n if (indices.value === -1 && indices.text === -1 && indices.properties.length && !valueProp && !textProp) {\n throw new Error('Properties found in series but missing valueProp and textProp');\n }\n\n const metrics: MetricFindValueWithOptionalProperties[] = [];\n\n for (const frame of frames) {\n for (let index = 0; index < frame.length; index++) {\n const value = indices.value !== -1 ? frame.fields[indices.value].values.get(index) : '';\n const text = indices.text !== -1 ? frame.fields[indices.text].values.get(index) : '';\n const expandable =\n indices.expandable !== -1 ? frame.fields[indices.expandable].values.get(index) : undefined;\n\n if (!indices.properties.length) {\n metrics.push({\n value: value || text,\n text: text || value,\n expandable,\n });\n continue;\n }\n\n const properties = indices.properties.reduce((acc, p) => {\n acc[p.name] = frame.fields[p.index].values.get(index);\n return acc;\n }, {} as Record<string, string>);\n\n metrics.push({\n value:\n value ||\n (valueProp && properties[valueProp as string]) ||\n text ||\n (textProp && properties[textProp as string]),\n text:\n text ||\n (textProp && properties[textProp as string]) ||\n value ||\n (valueProp && properties[valueProp as string]),\n properties,\n expandable,\n });\n }\n }\n\n return metrics;\n })\n );\n}\n\ntype Indices = {\n value: number;\n text: number;\n properties: Array<{ name: string; index: number }>;\n expandable: number;\n};\n\nfunction findFieldsIndices(frames: DataFrame[]): Indices {\n const indices: Indices = {\n value: -1,\n text: -1,\n properties: [],\n expandable: -1,\n };\n\n for (const frame of getProcessedDataFrames(frames)) {\n for (let index = 0; index < frame.fields.length; index++) {\n const field = frame.fields[index];\n const fieldName = getFieldDisplayName(field, frame, frames).toLowerCase();\n\n if (field.type === FieldType.string) {\n if (fieldName === 'value') {\n if (indices.value === -1) {\n indices.value = index;\n }\n continue;\n }\n\n if (fieldName === 'text') {\n if (indices.text === -1) {\n indices.text = index;\n }\n continue;\n }\n\n indices.properties.push({ name: fieldName, index });\n continue;\n }\n\n if (\n fieldName === 'expandable' &&\n (field.type === FieldType.boolean || field.type === FieldType.number) &&\n indices.expandable === -1\n ) {\n indices.expandable = index;\n }\n }\n }\n\n return indices;\n}\n\nfunction areMetricFindValues(data: any[]): data is MetricFindValue[] {\n if (!data) {\n return false;\n }\n\n if (!data.length) {\n return true;\n }\n\n const firstValue: any = data[0];\n\n if (isDataFrame(firstValue)) {\n return false;\n }\n\n for (const firstValueKey in firstValue) {\n if (!firstValue.hasOwnProperty(firstValueKey)) {\n continue;\n }\n\n if (\n firstValue[firstValueKey] !== null &&\n typeof firstValue[firstValueKey] !== 'string' &&\n typeof firstValue[firstValueKey] !== 'number'\n ) {\n continue;\n }\n\n const key = firstValueKey.toLowerCase();\n\n if (key === 'text' || key === 'value') {\n return true;\n }\n }\n\n return false;\n}\n"],"names":[],"mappings":";;;AAegB,SAAA,kBAAA,CACd,WACA,QACsE,EAAA;AACtE,EAAO,OAAA,CAAC,WACN,MAAO,CAAA,IAAA;AAAA,IACL,GAAA,CAAI,CAAC,SAAc,KAAA;AACjB,MAAA,MAAM,SAAS,SAAU,CAAA,MAAA;AACzB,MAAA,IAAI,CAAC,MAAA,IAAU,CAAC,MAAA,CAAO,MAAQ,EAAA;AAC7B,QAAA,OAAO,EAAC;AAAA;AAGV,MAAI,IAAA,mBAAA,CAAoB,MAAM,CAAG,EAAA;AAC/B,QAAO,OAAA,MAAA;AAAA;AAGT,MAAA,IAAI,MAAO,CAAA,CAAC,CAAE,CAAA,MAAA,CAAO,WAAW,CAAG,EAAA;AACjC,QAAA,OAAO,EAAC;AAAA;AAGV,MAAM,MAAA,OAAA,GAAU,kBAAkB,MAAM,CAAA;AAExC,MAAI,IAAA,OAAA,CAAQ,UAAU,EAAM,IAAA,OAAA,CAAQ,SAAS,EAAM,IAAA,CAAC,OAAQ,CAAA,UAAA,CAAW,MAAQ,EAAA;AAC7E,QAAM,MAAA,IAAI,MAAM,uDAAuD,CAAA;AAAA;AAIzE,MAAI,IAAA,OAAA,CAAQ,UAAU,EAAM,IAAA,OAAA,CAAQ,SAAS,EAAM,IAAA,OAAA,CAAQ,UAAW,CAAA,MAAA,KAAW,CAAG,EAAA;AAClF,QAAA,OAAA,CAAQ,KAAQ,GAAA,OAAA,CAAQ,UAAW,CAAA,CAAC,CAAE,CAAA,KAAA;AACtC,QAAA,OAAA,CAAQ,aAAa,EAAC;AAAA;AAGxB,MAAA,IAAI,OAAQ,CAAA,KAAA,KAAU,EAAM,IAAA,OAAA,CAAQ,IAAS,KAAA,EAAA,IAAM,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|
42
42
|
}
|
|
43
43
|
}
|
|
44
|
-
options.push({ label: text, value });
|
|
44
|
+
options.push({ label: text, value, properties: item.properties });
|
|
45
45
|
}
|
|
46
46
|
options = uniqBy(options, "value");
|
|
47
47
|
return sortVariableValues(options, sort);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.js","sources":["../../../../../src/variables/variants/query/utils.ts"],"sourcesContent":["import { isNumber, sortBy, toLower, uniqBy } from 'lodash';\n\nimport { stringToJsRegex, VariableSort } from '@grafana/data';\n\nimport { VariableValueOption } from '../../types';\n\nexport function metricNamesToVariableValues(variableRegEx: string, sort: VariableSort, metricNames: any[]) {\n let regex;\n let options: VariableValueOption[] = [];\n\n if (variableRegEx) {\n regex = stringToJsRegex(variableRegEx);\n }\n\n for (let i = 0; i < metricNames.length; i++) {\n const item = metricNames[i];\n let text = item.text ?? item.value ?? '';\n let value = item.value ?? item.text ?? '';\n\n if (isNumber(value)) {\n value = value.toString();\n }\n\n if (isNumber(text)) {\n text = text.toString();\n }\n\n if (regex) {\n const matches = getAllMatches(value, regex);\n if (!matches.length) {\n continue;\n }\n\n const valueGroup = matches.find((m) => m.groups && m.groups.value);\n const textGroup = matches.find((m) => m.groups && m.groups.text);\n const firstMatch = matches.find((m) => m.length > 1);\n const manyMatches = matches.length > 1 && firstMatch;\n\n if (valueGroup || textGroup) {\n value = valueGroup?.groups?.value ?? textGroup?.groups?.text;\n text = textGroup?.groups?.text ?? valueGroup?.groups?.value;\n } else if (manyMatches) {\n for (let j = 0; j < matches.length; j++) {\n const match = matches[j];\n options.push({ label: match[1], value: match[1] });\n }\n continue;\n } else if (firstMatch) {\n text = firstMatch[1];\n value = firstMatch[1];\n }\n }\n\n options.push({ label: text, value: value });\n }\n\n options = uniqBy(options, 'value');\n return sortVariableValues(options, sort);\n}\n\nconst getAllMatches = (str: string, regex: RegExp): RegExpExecArray[] => {\n const results: RegExpExecArray[] = [];\n let matches = null;\n\n regex.lastIndex = 0;\n\n do {\n matches = regex.exec(str);\n if (matches) {\n results.push(matches);\n }\n } while (regex.global && matches && matches[0] !== '' && matches[0] !== undefined);\n\n return results;\n};\n\nexport const sortVariableValues = (options: VariableValueOption[], sortOrder: VariableSort) => {\n if (sortOrder === VariableSort.disabled) {\n return options;\n }\n\n switch (sortOrder) {\n case VariableSort.alphabeticalAsc:\n options = sortBy(options, 'label');\n break;\n case VariableSort.alphabeticalDesc:\n options = sortBy(options, 'label').reverse();\n break;\n case VariableSort.numericalAsc:\n options = sortBy(options, sortByNumeric);\n break;\n case VariableSort.numericalDesc:\n options = sortBy(options, sortByNumeric);\n options = options.reverse();\n break;\n case VariableSort.alphabeticalCaseInsensitiveAsc:\n options = sortBy(options, (opt) => {\n return toLower(opt.label);\n });\n break;\n case VariableSort.alphabeticalCaseInsensitiveDesc:\n options = sortBy(options, (opt) => {\n return toLower(opt.label);\n });\n options = options.reverse();\n break;\n case VariableSort.naturalAsc || 7:\n // Sort by natural sort\n options = sortByNaturalSort(options);\n break;\n case VariableSort.naturalDesc || 8:\n options = sortByNaturalSort(options);\n options = options.reverse();\n break;\n default:\n break;\n }\n return options;\n};\n\nfunction sortByNumeric(opt: VariableValueOption) {\n if (!opt.label) {\n return -1;\n }\n const matches = opt.label.match(/.*?(\\d+).*/);\n if (!matches || matches.length < 2) {\n return -1;\n } else {\n return parseInt(matches[1], 10);\n }\n}\n\nconst collator = new Intl.Collator(undefined, { sensitivity: 'accent', numeric: true });\n\nfunction sortByNaturalSort(options: VariableValueOption[]) {\n return options.slice().sort((a, b) => {\n return collator.compare(a.label, b.label);\n });\n}\n"],"names":[],"mappings":";;;AAMgB,SAAA,2BAAA,CAA4B,aAAuB,EAAA,IAAA,EAAoB,WAAoB,EAAA;AAN3G,EAAA,IAAA,EAAA,EAAA,EAAA,EAAA,EAAA,EAAA,EAAA,EAAA,EAAA,EAAA,EAAA,EAAA,EAAA,EAAA,EAAA,EAAA,EAAA,EAAA,EAAA;AAOE,EAAI,IAAA,KAAA;AACJ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A,CAAA,CAAE,SAAS,CAAC,CAAA;AACnD,MAAM,MAAA,WAAA,GAAc,OAAQ,CAAA,MAAA,GAAS,CAAK,IAAA,UAAA;AAE1C,MAAA,IAAI,cAAc,SAAW,EAAA;AAC3B,QAAA,KAAA,GAAA,CAAQ,oDAAY,MAAZ,KAAA,IAAA,GAAA,MAAA,GAAA,EAAA,CAAoB,UAApB,IAA6B,GAAA,EAAA,GAAA,CAAA,EAAA,GAAA,SAAA,IAAA,IAAA,GAAA,MAAA,GAAA,SAAA,CAAW,WAAX,IAAmB,GAAA,MAAA,GAAA,EAAA,CAAA,IAAA;AACxD,QAAA,IAAA,GAAA,CAAO,kDAAW,MAAX,KAAA,IAAA,GAAA,MAAA,GAAA,EAAA,CAAmB,SAAnB,IAA2B,GAAA,EAAA,GAAA,CAAA,EAAA,GAAA,UAAA,IAAA,IAAA,GAAA,MAAA,GAAA,UAAA,CAAY,WAAZ,IAAoB,GAAA,MAAA,GAAA,EAAA,CAAA,KAAA;AAAA,iBAC7C,WAAa,EAAA;AACtB,QAAA,KAAA,IAAS,CAAI,GAAA,CAAA,EAAG,CAAI,GAAA,OAAA,CAAQ,QAAQ,CAAK,EAAA,EAAA;AACvC,UAAM,MAAA,KAAA,GAAQ,QAAQ,CAAC,CAAA;AACvB,UAAQ,OAAA,CAAA,IAAA,CAAK,EAAE,KAAA,EAAO,KAAM,CAAA,CAAC,GAAG,KAAO,EAAA,KAAA,CAAM,CAAC,CAAA,EAAG,CAAA;AAAA;AAEnD,QAAA;AAAA,iBACS,UAAY,EAAA;AACrB,QAAA,IAAA,GAAO,WAAW,CAAC,CAAA;AACnB,QAAA,KAAA,GAAQ,WAAW,CAAC,CAAA;AAAA;AACtB;AAGF,
|
|
1
|
+
{"version":3,"file":"utils.js","sources":["../../../../../src/variables/variants/query/utils.ts"],"sourcesContent":["import { isNumber, sortBy, toLower, uniqBy } from 'lodash';\n\nimport { stringToJsRegex, VariableSort } from '@grafana/data';\n\nimport { VariableValueOption } from '../../types';\n\nexport function metricNamesToVariableValues(variableRegEx: string, sort: VariableSort, metricNames: any[]) {\n let regex;\n let options: VariableValueOption[] = [];\n\n if (variableRegEx) {\n regex = stringToJsRegex(variableRegEx);\n }\n\n for (let i = 0; i < metricNames.length; i++) {\n const item = metricNames[i];\n let text = item.text ?? item.value ?? '';\n let value = item.value ?? item.text ?? '';\n\n if (isNumber(value)) {\n value = value.toString();\n }\n\n if (isNumber(text)) {\n text = text.toString();\n }\n\n if (regex) {\n const matches = getAllMatches(value, regex);\n if (!matches.length) {\n continue;\n }\n\n const valueGroup = matches.find((m) => m.groups && m.groups.value);\n const textGroup = matches.find((m) => m.groups && m.groups.text);\n const firstMatch = matches.find((m) => m.length > 1);\n const manyMatches = matches.length > 1 && firstMatch;\n\n if (valueGroup || textGroup) {\n value = valueGroup?.groups?.value ?? textGroup?.groups?.text;\n text = textGroup?.groups?.text ?? valueGroup?.groups?.value;\n } else if (manyMatches) {\n for (let j = 0; j < matches.length; j++) {\n const match = matches[j];\n options.push({ label: match[1], value: match[1] });\n }\n continue;\n } else if (firstMatch) {\n text = firstMatch[1];\n value = firstMatch[1];\n }\n }\n\n options.push({ label: text, value: value, properties: item.properties });\n }\n\n options = uniqBy(options, 'value');\n return sortVariableValues(options, sort);\n}\n\nconst getAllMatches = (str: string, regex: RegExp): RegExpExecArray[] => {\n const results: RegExpExecArray[] = [];\n let matches = null;\n\n regex.lastIndex = 0;\n\n do {\n matches = regex.exec(str);\n if (matches) {\n results.push(matches);\n }\n } while (regex.global && matches && matches[0] !== '' && matches[0] !== undefined);\n\n return results;\n};\n\nexport const sortVariableValues = (options: VariableValueOption[], sortOrder: VariableSort) => {\n if (sortOrder === VariableSort.disabled) {\n return options;\n }\n\n switch (sortOrder) {\n case VariableSort.alphabeticalAsc:\n options = sortBy(options, 'label');\n break;\n case VariableSort.alphabeticalDesc:\n options = sortBy(options, 'label').reverse();\n break;\n case VariableSort.numericalAsc:\n options = sortBy(options, sortByNumeric);\n break;\n case VariableSort.numericalDesc:\n options = sortBy(options, sortByNumeric);\n options = options.reverse();\n break;\n case VariableSort.alphabeticalCaseInsensitiveAsc:\n options = sortBy(options, (opt) => {\n return toLower(opt.label);\n });\n break;\n case VariableSort.alphabeticalCaseInsensitiveDesc:\n options = sortBy(options, (opt) => {\n return toLower(opt.label);\n });\n options = options.reverse();\n break;\n case VariableSort.naturalAsc || 7:\n // Sort by natural sort\n options = sortByNaturalSort(options);\n break;\n case VariableSort.naturalDesc || 8:\n options = sortByNaturalSort(options);\n options = options.reverse();\n break;\n default:\n break;\n }\n return options;\n};\n\nfunction sortByNumeric(opt: VariableValueOption) {\n if (!opt.label) {\n return -1;\n }\n const matches = opt.label.match(/.*?(\\d+).*/);\n if (!matches || matches.length < 2) {\n return -1;\n } else {\n return parseInt(matches[1], 10);\n }\n}\n\nconst collator = new Intl.Collator(undefined, { sensitivity: 'accent', numeric: true });\n\nfunction sortByNaturalSort(options: VariableValueOption[]) {\n return options.slice().sort((a, b) => {\n return collator.compare(a.label, b.label);\n });\n}\n"],"names":[],"mappings":";;;AAMgB,SAAA,2BAAA,CAA4B,aAAuB,EAAA,IAAA,EAAoB,WAAoB,EAAA;AAN3G,EAAA,IAAA,EAAA,EAAA,EAAA,EAAA,EAAA,EAAA,EAAA,EAAA,EAAA,EAAA,EAAA,EAAA,EAAA,EAAA,EAAA,EAAA,EAAA,EAAA,EAAA;AAOE,EAAI,IAAA,KAAA;AACJ,EAAA,IAAI,UAAiC,EAAC;AAEtC,EAAA,IAAI,aAAe,EAAA;AACjB,IAAA,KAAA,GAAQ,gBAAgB,aAAa,CAAA;AAAA;AAGvC,EAAA,KAAA,IAAS,CAAI,GAAA,CAAA,EAAG,CAAI,GAAA,WAAA,CAAY,QAAQ,CAAK,EAAA,EAAA;AAC3C,IAAM,MAAA,IAAA,GAAO,YAAY,CAAC,CAAA;AAC1B,IAAA,IAAI,QAAO,EAAK,GAAA,CAAA,EAAA,GAAA,IAAA,CAAA,IAAA,KAAL,I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EAAA;AAC1B,MAAA;AAAA,IACF,MAAK,aAAa,UAAc,IAAA,CAAA;AAE9B,MAAA,OAAA,GAAU,kBAAkB,OAAO,CAAA;AACnC,MAAA;AAAA,IACF,MAAK,aAAa,WAAe,IAAA,CAAA;AAC/B,MAAA,OAAA,GAAU,kBAAkB,OAAO,CAAA;AACnC,MAAA,OAAA,GAAU,QAAQ,OAAQ,EAAA;AAC1B,MAAA;AAEA;AAEJ,EAAO,OAAA,OAAA;AACT;AAEA,SAAS,cAAc,GAA0B,EAAA;AAC/C,EAAI,IAAA,CAAC,IAAI,KAAO,EAAA;AACd,IAAO,OAAA,EAAA;AAAA;AAET,EAAA,MAAM,OAAU,GAAA,GAAA,CAAI,KAAM,CAAA,KAAA,CAAM,YAAY,CAAA;AAC5C,EAAA,IAAI,CAAC,OAAA,IAAW,OAAQ,CAAA,MAAA,GAAS,CAAG,EAAA;AAClC,IAAO,OAAA,EAAA;AAAA,GACF,MAAA;AACL,IAAA,OAAO,QAAS,CAAA,OAAA,CAAQ,CAAC,CAAA,EAAG,EAAE,CAAA;AAAA;AAElC;AAEA,MAAM,QAAA,GAAW,IAAI,IAAA,CAAK,QAAS,CAAA,MAAA,EAAW,EAAE,WAAa,EAAA,QAAA,EAAU,OAAS,EAAA,IAAA,EAAM,CAAA;AAEtF,SAAS,kBAAkB,OAAgC,EAAA;AACzD,EAAA,OAAO,QAAQ,KAAM,EAAA,CAAE,IAAK,CAAA,CAAC,GAAG,CAAM,KAAA;AACpC,IAAA,OAAO,QAAS,CAAA,OAAA,CAAQ,CAAE,CAAA,KAAA,EAAO,EAAE,KAAK,CAAA;AAAA,GACzC,CAAA;AACH;;;;"}
|
package/dist/index.d.ts
CHANGED
|
@@ -88,10 +88,13 @@ interface CustomVariableValue {
|
|
|
88
88
|
}
|
|
89
89
|
interface ValidateAndUpdateResult {
|
|
90
90
|
}
|
|
91
|
+
interface VariableValueOptionProperties extends Record<string, any> {
|
|
92
|
+
}
|
|
91
93
|
interface VariableValueOption {
|
|
92
94
|
label: string;
|
|
93
95
|
value: VariableValueSingle;
|
|
94
96
|
group?: string;
|
|
97
|
+
properties?: VariableValueOptionProperties;
|
|
95
98
|
}
|
|
96
99
|
interface SceneVariableSetState extends SceneObjectState {
|
|
97
100
|
variables: SceneVariable[];
|
|
@@ -1197,6 +1200,7 @@ interface VariableGetOptionsArgs {
|
|
|
1197
1200
|
searchFilter?: string;
|
|
1198
1201
|
}
|
|
1199
1202
|
declare abstract class MultiValueVariable<TState extends MultiValueVariableState = MultiValueVariableState> extends SceneObjectBase<TState> implements SceneVariable<TState> {
|
|
1203
|
+
private static fieldAccessorCache;
|
|
1200
1204
|
protected _urlSync: SceneObjectUrlSyncHandler;
|
|
1201
1205
|
/**
|
|
1202
1206
|
* Set to true to skip next value validation to maintain the current value even it it's not among the options (ie valid values)
|
|
@@ -1222,16 +1226,19 @@ declare abstract class MultiValueVariable<TState extends MultiValueVariableState
|
|
|
1222
1226
|
*/
|
|
1223
1227
|
protected interceptStateUpdateAfterValidation(stateUpdate: Partial<MultiValueVariableState>): void;
|
|
1224
1228
|
getValue(fieldPath?: string): VariableValue;
|
|
1229
|
+
private getFieldAccessor;
|
|
1225
1230
|
getValueText(): string;
|
|
1226
1231
|
hasAllValue(): boolean;
|
|
1227
1232
|
getDefaultMultiState(options: VariableValueOption[]): {
|
|
1233
|
+
value: string[];
|
|
1234
|
+
text: string[];
|
|
1235
|
+
properties?: undefined;
|
|
1236
|
+
} | {
|
|
1228
1237
|
value: VariableValueSingle[];
|
|
1229
1238
|
text: string[];
|
|
1239
|
+
properties: (VariableValueOptionProperties | undefined)[];
|
|
1230
1240
|
};
|
|
1231
|
-
protected getDefaultSingleState(options: VariableValueOption[]):
|
|
1232
|
-
value: VariableValueSingle;
|
|
1233
|
-
text: string;
|
|
1234
|
-
};
|
|
1241
|
+
protected getDefaultSingleState(options: VariableValueOption[]): VariableValueOption;
|
|
1235
1242
|
/**
|
|
1236
1243
|
* Change the value and publish SceneVariableValueChangedEvent event.
|
|
1237
1244
|
*/
|
|
@@ -1251,11 +1258,13 @@ declare abstract class MultiValueVariable<TState extends MultiValueVariableState
|
|
|
1251
1258
|
|
|
1252
1259
|
interface CustomVariableState extends MultiValueVariableState {
|
|
1253
1260
|
query: string;
|
|
1261
|
+
valuesFormat?: 'csv' | 'json';
|
|
1254
1262
|
}
|
|
1255
1263
|
declare class CustomVariable extends MultiValueVariable<CustomVariableState> {
|
|
1256
1264
|
protected _variableDependency: VariableDependencyConfig<CustomVariableState>;
|
|
1257
1265
|
constructor(initialState: Partial<CustomVariableState>);
|
|
1258
1266
|
transformCsvStringToOptions(str: string, interpolate?: boolean): VariableValueOption[];
|
|
1267
|
+
private transformJsonToOptions;
|
|
1259
1268
|
getValueOptions(args: VariableGetOptionsArgs): Observable<VariableValueOption[]>;
|
|
1260
1269
|
static Component: ({ model }: SceneComponentProps<MultiValueVariable>) => React__default.JSX.Element;
|
|
1261
1270
|
}
|
|
@@ -1412,8 +1421,8 @@ declare class GroupByVariable extends MultiValueVariable<GroupByVariableState> {
|
|
|
1412
1421
|
* Allows clearing the value of the variable to an empty value. Overrides default behavior of a MultiValueVariable
|
|
1413
1422
|
*/
|
|
1414
1423
|
getDefaultMultiState(options: VariableValueOption[]): {
|
|
1415
|
-
value:
|
|
1416
|
-
text:
|
|
1424
|
+
value: never[];
|
|
1425
|
+
text: never[];
|
|
1417
1426
|
};
|
|
1418
1427
|
}
|
|
1419
1428
|
declare function GroupByVariableRenderer({ model }: SceneComponentProps<GroupByVariable>): React__default.JSX.Element;
|
|
@@ -3589,4 +3598,4 @@ declare const sceneUtils: {
|
|
|
3589
3598
|
};
|
|
3590
3599
|
|
|
3591
3600
|
export { AdHocFiltersComboboxRenderer, AdHocFiltersVariable, AdHocFiltersVariableController, ConstantVariable, ControlsLabel, CustomVariable, DataProviderProxy, DataSourceVariable, EmbeddedScene, FieldConfigBuilder, FieldConfigBuilders, FieldConfigOverridesBuilder, GroupByVariable, IntervalVariable, LazyLoader, LocalValueVariable, MultiOrSingleValueSelect, MultiValueVariable, NestedScene, NewSceneObjectAddedEvent, PATH_ID_SEPARATOR, PanelBuilders, PanelOptionsBuilders, QueryVariable, RuntimeDataSource, SafeSerializableSceneObject, SceneApp, SceneAppPage, SceneByFrameRepeater, SceneByVariableRepeater, SceneCSSGridItem, SceneCSSGridLayout, SceneCanvasText, SceneControlsSpacer, SceneDataLayerBase, SceneDataLayerControls, SceneDataLayerSet, SceneDataLayerSetBase, SceneDataNode, SceneDataTransformer, SceneDebugger, SceneFlexItem, SceneFlexLayout, SceneGridItem, SceneGridLayout, SceneGridLayoutDragStartEvent, SceneGridRow, SceneObjectBase, SceneObjectRef, SceneObjectStateChangedEvent, SceneObjectUrlSyncConfig, SceneQueryRunner, SceneReactObject, SceneRefreshPicker, SceneTimePicker, SceneTimeRange, SceneTimeRangeCompare, SceneTimeRangeTransformerBase, SceneTimeZoneOverride, SceneToolbarButton, SceneToolbarInput, SceneVariableSet, SceneVariableValueChangedEvent, ScopesVariable, SplitLayout, SwitchVariable, TestVariable, TextBoxVariable, UrlSyncContextProvider, UrlSyncManager, UserActionEvent, VariableDependencyConfig, VariableValueControl, VariableValueSelectWrapper, VariableValueSelectors, VizConfigBuilder, VizConfigBuilders, VizPanel, VizPanelBuilder, VizPanelExploreButton, VizPanelMenu, index$2 as behaviors, index as dataLayers, escapeUrlPipeDelimiters, formatRegistry, getExploreURL, isCustomVariableValue, isDataLayer, isDataRequestEnricher, isFiltersRequestEnricher, isSceneObject, loadResources, index$1 as performanceUtils, registerQueryWithController, registerRuntimeDataSource, sceneGraph, sceneUtils, useSceneApp, useSceneObjectState, useUrlSync, writePerformanceLog };
|
|
3592
|
-
export type { AdHocFilterWithLabels, AdHocFiltersController, AdHocFiltersControllerState, CancelActivationHandler, ControlsLayout, CustomFormatterVariable, CustomTransformOperator, CustomTransformerDefinition, CustomVariableValue, DataLayerFilter, DataRequestEnricher, DeepPartial, EmbeddedSceneState, ExtraQueryDataProcessor, ExtraQueryDescriptor, ExtraQueryProvider, FiltersRequestEnricher, FormatVariable, InterpolationFormatParameter, MacroVariableConstructor, MultiValueVariableState, QueryRunnerState, SceneActivationHandler, SceneAppDrilldownView, SceneAppPageLike, SceneAppPageState, SceneAppRoute, SceneComponent, SceneComponentProps, SceneDataLayerProvider, SceneDataLayerProviderState, SceneDataProvider, SceneDataProviderResult, SceneDataQuery, SceneDataState, SceneDataTransformerState, SceneDeactivationHandler, SceneFlexItemLike, SceneFlexItemState, SceneGridItemLike, SceneGridItemStateLike, SceneLayout, SceneLayoutChildOptions, SceneLayoutState, SceneObject, SceneObjectState, SceneObjectStateChangedPayload, SceneObjectUrlSyncHandler, SceneObjectUrlValue, SceneObjectUrlValues, SceneObjectWithUrlSync, SceneQueryControllerEntry, SceneQueryControllerEntryType, SceneQueryControllerLike, SceneRefreshPickerState, SceneRouteMatch, SceneStateChangedHandler, SceneStatelessBehavior, SceneTimeRangeLike, SceneTimeRangeState, SceneUrlSyncOptions, SceneVariable, SceneVariableDependencyConfigLike, SceneVariableSetState, SceneVariableState, SceneVariables, UrlSyncManagerLike, UseStateHookOptions, ValidateAndUpdateResult, VariableCustomFormatterFn, VariableGetOptionsArgs, VariableValue, VariableValueOption, VariableValueSingle, VizConfig, VizPanelState };
|
|
3601
|
+
export type { AdHocFilterWithLabels, AdHocFiltersController, AdHocFiltersControllerState, CancelActivationHandler, ControlsLayout, CustomFormatterVariable, CustomTransformOperator, CustomTransformerDefinition, CustomVariableValue, DataLayerFilter, DataRequestEnricher, DeepPartial, EmbeddedSceneState, ExtraQueryDataProcessor, ExtraQueryDescriptor, ExtraQueryProvider, FiltersRequestEnricher, FormatVariable, InterpolationFormatParameter, MacroVariableConstructor, MultiValueVariableState, QueryRunnerState, SceneActivationHandler, SceneAppDrilldownView, SceneAppPageLike, SceneAppPageState, SceneAppRoute, SceneComponent, SceneComponentProps, SceneDataLayerProvider, SceneDataLayerProviderState, SceneDataProvider, SceneDataProviderResult, SceneDataQuery, SceneDataState, SceneDataTransformerState, SceneDeactivationHandler, SceneFlexItemLike, SceneFlexItemState, SceneGridItemLike, SceneGridItemStateLike, SceneLayout, SceneLayoutChildOptions, SceneLayoutState, SceneObject, SceneObjectState, SceneObjectStateChangedPayload, SceneObjectUrlSyncHandler, SceneObjectUrlValue, SceneObjectUrlValues, SceneObjectWithUrlSync, SceneQueryControllerEntry, SceneQueryControllerEntryType, SceneQueryControllerLike, SceneRefreshPickerState, SceneRouteMatch, SceneStateChangedHandler, SceneStatelessBehavior, SceneTimeRangeLike, SceneTimeRangeState, SceneUrlSyncOptions, SceneVariable, SceneVariableDependencyConfigLike, SceneVariableSetState, SceneVariableState, SceneVariables, UrlSyncManagerLike, UseStateHookOptions, ValidateAndUpdateResult, VariableCustomFormatterFn, VariableGetOptionsArgs, VariableValue, VariableValueOption, VariableValueOptionProperties, VariableValueSingle, VizConfig, VizPanelState };
|
package/dist/index.js
CHANGED
|
@@ -1774,7 +1774,7 @@ function isRepeatCloneOrChildOf(scene) {
|
|
|
1774
1774
|
return false;
|
|
1775
1775
|
}
|
|
1776
1776
|
|
|
1777
|
-
class
|
|
1777
|
+
const _MultiValueVariable = class _MultiValueVariable extends SceneObjectBase {
|
|
1778
1778
|
constructor() {
|
|
1779
1779
|
super(...arguments);
|
|
1780
1780
|
this._urlSync = new MultiValueUrlSyncHandler(this);
|
|
@@ -1865,7 +1865,7 @@ class MultiValueVariable extends SceneObjectBase {
|
|
|
1865
1865
|
} else {
|
|
1866
1866
|
const defaultState = this.getDefaultSingleState(options);
|
|
1867
1867
|
stateUpdate.value = defaultState.value;
|
|
1868
|
-
stateUpdate.text = defaultState.
|
|
1868
|
+
stateUpdate.text = defaultState.label;
|
|
1869
1869
|
}
|
|
1870
1870
|
return stateUpdate;
|
|
1871
1871
|
}
|
|
@@ -1887,16 +1887,35 @@ class MultiValueVariable extends SceneObjectBase {
|
|
|
1887
1887
|
if (this.state.allValue) {
|
|
1888
1888
|
return new CustomAllValue(this.state.allValue, this);
|
|
1889
1889
|
}
|
|
1890
|
-
value = this.state.options.map((
|
|
1890
|
+
value = this.state.options.map((o) => o.value);
|
|
1891
1891
|
}
|
|
1892
|
-
if (fieldPath != null
|
|
1893
|
-
|
|
1894
|
-
|
|
1895
|
-
|
|
1892
|
+
if (fieldPath != null) {
|
|
1893
|
+
if (Array.isArray(value)) {
|
|
1894
|
+
const index = parseInt(fieldPath, 10);
|
|
1895
|
+
if (!isNaN(index) && index >= 0 && index < value.length) {
|
|
1896
|
+
return value[index];
|
|
1897
|
+
}
|
|
1898
|
+
const accesor2 = this.getFieldAccessor(fieldPath);
|
|
1899
|
+
return value.map((v) => {
|
|
1900
|
+
const o2 = this.state.options.find((o3) => o3.value === v);
|
|
1901
|
+
return o2 ? accesor2(o2.properties) : v;
|
|
1902
|
+
});
|
|
1903
|
+
}
|
|
1904
|
+
const accesor = this.getFieldAccessor(fieldPath);
|
|
1905
|
+
const o = this.state.options.find((o2) => o2.value === value);
|
|
1906
|
+
if (o) {
|
|
1907
|
+
return accesor(o.properties);
|
|
1896
1908
|
}
|
|
1897
1909
|
}
|
|
1898
1910
|
return value;
|
|
1899
1911
|
}
|
|
1912
|
+
getFieldAccessor(fieldPath) {
|
|
1913
|
+
const accessor = _MultiValueVariable.fieldAccessorCache[fieldPath];
|
|
1914
|
+
if (accessor) {
|
|
1915
|
+
return accessor;
|
|
1916
|
+
}
|
|
1917
|
+
return _MultiValueVariable.fieldAccessorCache[fieldPath] = lodash.property(fieldPath);
|
|
1918
|
+
}
|
|
1900
1919
|
getValueText() {
|
|
1901
1920
|
if (this.hasAllValue()) {
|
|
1902
1921
|
return ALL_VARIABLE_TEXT;
|
|
@@ -1914,18 +1933,18 @@ class MultiValueVariable extends SceneObjectBase {
|
|
|
1914
1933
|
if (this.state.defaultToAll) {
|
|
1915
1934
|
return { value: [ALL_VARIABLE_VALUE], text: [ALL_VARIABLE_TEXT] };
|
|
1916
1935
|
} else if (options.length > 0) {
|
|
1917
|
-
return { value: [options[0].value], text: [options[0].label] };
|
|
1936
|
+
return { value: [options[0].value], text: [options[0].label], properties: [options[0].properties] };
|
|
1918
1937
|
} else {
|
|
1919
1938
|
return { value: [], text: [] };
|
|
1920
1939
|
}
|
|
1921
1940
|
}
|
|
1922
1941
|
getDefaultSingleState(options) {
|
|
1923
1942
|
if (this.state.defaultToAll) {
|
|
1924
|
-
return { value: ALL_VARIABLE_VALUE,
|
|
1943
|
+
return { value: ALL_VARIABLE_VALUE, label: ALL_VARIABLE_TEXT };
|
|
1925
1944
|
} else if (options.length > 0) {
|
|
1926
|
-
return { value: options[0].value,
|
|
1945
|
+
return { value: options[0].value, label: options[0].label, properties: options[0].properties };
|
|
1927
1946
|
} else {
|
|
1928
|
-
return { value: "",
|
|
1947
|
+
return { value: "", label: "" };
|
|
1929
1948
|
}
|
|
1930
1949
|
}
|
|
1931
1950
|
/**
|
|
@@ -2010,15 +2029,17 @@ class MultiValueVariable extends SceneObjectBase {
|
|
|
2010
2029
|
this.updateValueGivenNewOptions(options);
|
|
2011
2030
|
});
|
|
2012
2031
|
}
|
|
2013
|
-
}
|
|
2032
|
+
};
|
|
2033
|
+
_MultiValueVariable.fieldAccessorCache = {};
|
|
2034
|
+
let MultiValueVariable = _MultiValueVariable;
|
|
2014
2035
|
function findOptionMatchingCurrent(currentValue, currentText, options) {
|
|
2015
2036
|
let textMatch;
|
|
2016
|
-
for (const
|
|
2017
|
-
if (
|
|
2018
|
-
return
|
|
2037
|
+
for (const o of options) {
|
|
2038
|
+
if (o.value === currentValue) {
|
|
2039
|
+
return o;
|
|
2019
2040
|
}
|
|
2020
|
-
if (
|
|
2021
|
-
textMatch =
|
|
2041
|
+
if (o.label === currentText) {
|
|
2042
|
+
textMatch = o;
|
|
2022
2043
|
}
|
|
2023
2044
|
}
|
|
2024
2045
|
return textMatch;
|
|
@@ -9434,7 +9455,7 @@ function metricNamesToVariableValues(variableRegEx, sort, metricNames) {
|
|
|
9434
9455
|
value = firstMatch[1];
|
|
9435
9456
|
}
|
|
9436
9457
|
}
|
|
9437
|
-
options.push({ label: text, value });
|
|
9458
|
+
options.push({ label: text, value, properties: item.properties });
|
|
9438
9459
|
}
|
|
9439
9460
|
options = lodash.uniqBy(options, "value");
|
|
9440
9461
|
return sortVariableValues(options, sort);
|
|
@@ -9508,7 +9529,7 @@ function sortByNaturalSort(options) {
|
|
|
9508
9529
|
});
|
|
9509
9530
|
}
|
|
9510
9531
|
|
|
9511
|
-
function toMetricFindValues() {
|
|
9532
|
+
function toMetricFindValues(valueProp, textProp) {
|
|
9512
9533
|
return (source) => source.pipe(
|
|
9513
9534
|
rxjs.map((panelData) => {
|
|
9514
9535
|
const frames = panelData.series;
|
|
@@ -9521,58 +9542,81 @@ function toMetricFindValues() {
|
|
|
9521
9542
|
if (frames[0].fields.length === 0) {
|
|
9522
9543
|
return [];
|
|
9523
9544
|
}
|
|
9524
|
-
const
|
|
9525
|
-
|
|
9526
|
-
|
|
9527
|
-
|
|
9528
|
-
|
|
9529
|
-
|
|
9530
|
-
|
|
9531
|
-
for (let index = 0; index < frame.fields.length; index++) {
|
|
9532
|
-
const field = frame.fields[index];
|
|
9533
|
-
const fieldName = data.getFieldDisplayName(field, frame, frames).toLowerCase();
|
|
9534
|
-
if (field.type === data.FieldType.string && stringIndex === -1) {
|
|
9535
|
-
stringIndex = index;
|
|
9536
|
-
}
|
|
9537
|
-
if (fieldName === "text" && field.type === data.FieldType.string && textIndex === -1) {
|
|
9538
|
-
textIndex = index;
|
|
9539
|
-
}
|
|
9540
|
-
if (fieldName === "value" && field.type === data.FieldType.string && valueIndex === -1) {
|
|
9541
|
-
valueIndex = index;
|
|
9542
|
-
}
|
|
9543
|
-
if (fieldName === "expandable" && (field.type === data.FieldType.boolean || field.type === data.FieldType.number) && expandableIndex === -1) {
|
|
9544
|
-
expandableIndex = index;
|
|
9545
|
-
}
|
|
9546
|
-
}
|
|
9545
|
+
const indices = findFieldsIndices(frames);
|
|
9546
|
+
if (indices.value === -1 && indices.text === -1 && !indices.properties.length) {
|
|
9547
|
+
throw new Error("Couldn't find any field of type string in the results");
|
|
9548
|
+
}
|
|
9549
|
+
if (indices.value === -1 && indices.text === -1 && indices.properties.length === 1) {
|
|
9550
|
+
indices.value = indices.properties[0].index;
|
|
9551
|
+
indices.properties = [];
|
|
9547
9552
|
}
|
|
9548
|
-
if (
|
|
9549
|
-
throw new Error("
|
|
9553
|
+
if (indices.value === -1 && indices.text === -1 && indices.properties.length && true && true) {
|
|
9554
|
+
throw new Error("Properties found in series but missing valueProp and textProp");
|
|
9550
9555
|
}
|
|
9556
|
+
const metrics = [];
|
|
9551
9557
|
for (const frame of frames) {
|
|
9552
9558
|
for (let index = 0; index < frame.length; index++) {
|
|
9553
|
-
const
|
|
9554
|
-
const
|
|
9555
|
-
const
|
|
9556
|
-
|
|
9557
|
-
|
|
9558
|
-
|
|
9559
|
-
|
|
9560
|
-
|
|
9561
|
-
|
|
9562
|
-
metrics.push({ text, value: text, expandable });
|
|
9563
|
-
continue;
|
|
9564
|
-
}
|
|
9565
|
-
if (valueIndex !== -1 && textIndex === -1) {
|
|
9566
|
-
metrics.push({ text: value, value, expandable });
|
|
9559
|
+
const value = indices.value !== -1 ? frame.fields[indices.value].values.get(index) : "";
|
|
9560
|
+
const text = indices.text !== -1 ? frame.fields[indices.text].values.get(index) : "";
|
|
9561
|
+
const expandable = indices.expandable !== -1 ? frame.fields[indices.expandable].values.get(index) : void 0;
|
|
9562
|
+
if (!indices.properties.length) {
|
|
9563
|
+
metrics.push({
|
|
9564
|
+
value: value || text,
|
|
9565
|
+
text: text || value,
|
|
9566
|
+
expandable
|
|
9567
|
+
});
|
|
9567
9568
|
continue;
|
|
9568
9569
|
}
|
|
9569
|
-
|
|
9570
|
+
const properties = indices.properties.reduce((acc, p) => {
|
|
9571
|
+
acc[p.name] = frame.fields[p.index].values.get(index);
|
|
9572
|
+
return acc;
|
|
9573
|
+
}, {});
|
|
9574
|
+
metrics.push({
|
|
9575
|
+
value: value || valueProp || text || textProp,
|
|
9576
|
+
text: text || textProp || value || valueProp,
|
|
9577
|
+
properties,
|
|
9578
|
+
expandable
|
|
9579
|
+
});
|
|
9570
9580
|
}
|
|
9571
9581
|
}
|
|
9572
9582
|
return metrics;
|
|
9573
9583
|
})
|
|
9574
9584
|
);
|
|
9575
9585
|
}
|
|
9586
|
+
function findFieldsIndices(frames) {
|
|
9587
|
+
const indices = {
|
|
9588
|
+
value: -1,
|
|
9589
|
+
text: -1,
|
|
9590
|
+
properties: [],
|
|
9591
|
+
expandable: -1
|
|
9592
|
+
};
|
|
9593
|
+
for (const frame of data.getProcessedDataFrames(frames)) {
|
|
9594
|
+
for (let index = 0; index < frame.fields.length; index++) {
|
|
9595
|
+
const field = frame.fields[index];
|
|
9596
|
+
const fieldName = data.getFieldDisplayName(field, frame, frames).toLowerCase();
|
|
9597
|
+
if (field.type === data.FieldType.string) {
|
|
9598
|
+
if (fieldName === "value") {
|
|
9599
|
+
if (indices.value === -1) {
|
|
9600
|
+
indices.value = index;
|
|
9601
|
+
}
|
|
9602
|
+
continue;
|
|
9603
|
+
}
|
|
9604
|
+
if (fieldName === "text") {
|
|
9605
|
+
if (indices.text === -1) {
|
|
9606
|
+
indices.text = index;
|
|
9607
|
+
}
|
|
9608
|
+
continue;
|
|
9609
|
+
}
|
|
9610
|
+
indices.properties.push({ name: fieldName, index });
|
|
9611
|
+
continue;
|
|
9612
|
+
}
|
|
9613
|
+
if (fieldName === "expandable" && (field.type === data.FieldType.boolean || field.type === data.FieldType.number) && indices.expandable === -1) {
|
|
9614
|
+
indices.expandable = index;
|
|
9615
|
+
}
|
|
9616
|
+
}
|
|
9617
|
+
}
|
|
9618
|
+
return indices;
|
|
9619
|
+
}
|
|
9576
9620
|
function areMetricFindValues(data$1) {
|
|
9577
9621
|
if (!data$1) {
|
|
9578
9622
|
return false;
|
|
@@ -11807,6 +11851,7 @@ class CustomVariable extends MultiValueVariable {
|
|
|
11807
11851
|
super({
|
|
11808
11852
|
type: "custom",
|
|
11809
11853
|
query: "",
|
|
11854
|
+
valuesFormat: "csv",
|
|
11810
11855
|
value: "",
|
|
11811
11856
|
text: "",
|
|
11812
11857
|
options: [],
|
|
@@ -11835,8 +11880,30 @@ class CustomVariable extends MultiValueVariable {
|
|
|
11835
11880
|
}
|
|
11836
11881
|
});
|
|
11837
11882
|
}
|
|
11883
|
+
transformJsonToOptions(json) {
|
|
11884
|
+
const parsedOptions = JSON.parse(json);
|
|
11885
|
+
if (!Array.isArray(parsedOptions)) {
|
|
11886
|
+
throw new Error("Query must be a JSON array");
|
|
11887
|
+
}
|
|
11888
|
+
if (typeof parsedOptions[0] === "string") {
|
|
11889
|
+
return parsedOptions.map((value) => ({ label: value.trim(), value: value.trim() }));
|
|
11890
|
+
}
|
|
11891
|
+
if (typeof parsedOptions[0] !== "object" || parsedOptions[0] === null) {
|
|
11892
|
+
throw new Error("Query must be a JSON array of strings or objects");
|
|
11893
|
+
}
|
|
11894
|
+
const valueProp = "value";
|
|
11895
|
+
const textProp = "text";
|
|
11896
|
+
return parsedOptions.map((o) => {
|
|
11897
|
+
var _a;
|
|
11898
|
+
return {
|
|
11899
|
+
value: String(o[valueProp]).trim(),
|
|
11900
|
+
label: (_a = String(o[textProp] || o[valueProp])) == null ? void 0 : _a.trim(),
|
|
11901
|
+
properties: o
|
|
11902
|
+
};
|
|
11903
|
+
});
|
|
11904
|
+
}
|
|
11838
11905
|
getValueOptions(args) {
|
|
11839
|
-
const options = this.transformCsvStringToOptions(this.state.query);
|
|
11906
|
+
const options = this.state.valuesFormat === "csv" ? this.transformCsvStringToOptions(this.state.query) : this.transformJsonToOptions(this.state.query);
|
|
11840
11907
|
if (!options.length) {
|
|
11841
11908
|
this.skipNextValidation = true;
|
|
11842
11909
|
}
|