@grafana/scenes 6.50.0 → 6.51.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 +13 -0
- package/dist/esm/packages/scenes/src/variables/variants/query/toMetricFindValues.js +19 -31
- package/dist/esm/packages/scenes/src/variables/variants/query/toMetricFindValues.js.map +1 -1
- package/dist/index.js +19 -31
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,16 @@
|
|
|
1
|
+
# v6.51.0 (Thu Dec 18 2025)
|
|
2
|
+
|
|
3
|
+
#### 🚀 Enhancement
|
|
4
|
+
|
|
5
|
+
- Variables: Fix breaking behavior in toMetricFindValues [#1319](https://github.com/grafana/scenes/pull/1319) ([@torkelo](https://github.com/torkelo) [@grafakus](https://github.com/grafakus))
|
|
6
|
+
|
|
7
|
+
#### Authors: 2
|
|
8
|
+
|
|
9
|
+
- Marc M. ([@grafakus](https://github.com/grafakus))
|
|
10
|
+
- Torkel Ödegaard ([@torkelo](https://github.com/torkelo))
|
|
11
|
+
|
|
12
|
+
---
|
|
13
|
+
|
|
1
14
|
# v6.50.0 (Wed Dec 17 2025)
|
|
2
15
|
|
|
3
16
|
#### 🚀 Enhancement
|
|
@@ -22,31 +22,22 @@ function toMetricFindValues(valueProp, textProp) {
|
|
|
22
22
|
const value = fieldValue(indices.value);
|
|
23
23
|
const text = fieldValue(indices.text);
|
|
24
24
|
const expandable = fieldValue(indices.expandable);
|
|
25
|
-
if (!indices.properties.length) {
|
|
26
|
-
metrics.push({
|
|
27
|
-
value: value || text,
|
|
28
|
-
text: text || value,
|
|
29
|
-
expandable
|
|
30
|
-
});
|
|
31
|
-
continue;
|
|
32
|
-
}
|
|
33
25
|
const properties = {};
|
|
34
26
|
for (const p of indices.properties) {
|
|
35
27
|
properties[p.name] = fieldValue(p.index);
|
|
36
28
|
}
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
});
|
|
29
|
+
const result = { value, text, properties };
|
|
30
|
+
if (expandable !== void 0) {
|
|
31
|
+
result.expandable = Boolean(expandable);
|
|
32
|
+
}
|
|
33
|
+
metrics.push(result);
|
|
43
34
|
}
|
|
44
35
|
}
|
|
45
36
|
return metrics;
|
|
46
37
|
})
|
|
47
38
|
);
|
|
48
39
|
}
|
|
49
|
-
function findFieldsIndices(frames) {
|
|
40
|
+
function findFieldsIndices(frames, valueProp, textProp) {
|
|
50
41
|
const indices = {
|
|
51
42
|
value: -1,
|
|
52
43
|
text: -1,
|
|
@@ -58,17 +49,11 @@ function findFieldsIndices(frames) {
|
|
|
58
49
|
const field = frame.fields[index];
|
|
59
50
|
const fieldName = getFieldDisplayName(field, frame, frames).toLowerCase();
|
|
60
51
|
if (field.type === FieldType.string) {
|
|
61
|
-
if (fieldName === "value") {
|
|
62
|
-
|
|
63
|
-
indices.value = index;
|
|
64
|
-
}
|
|
65
|
-
continue;
|
|
52
|
+
if (fieldName === "value" && indices.value === -1) {
|
|
53
|
+
indices.value = index;
|
|
66
54
|
}
|
|
67
|
-
if (fieldName === "text") {
|
|
68
|
-
|
|
69
|
-
indices.text = index;
|
|
70
|
-
}
|
|
71
|
-
continue;
|
|
55
|
+
if (fieldName === "text" && indices.text === -1) {
|
|
56
|
+
indices.text = index;
|
|
72
57
|
}
|
|
73
58
|
indices.properties.push({ name: fieldName, index });
|
|
74
59
|
continue;
|
|
@@ -80,17 +65,20 @@ function findFieldsIndices(frames) {
|
|
|
80
65
|
}
|
|
81
66
|
return indices;
|
|
82
67
|
}
|
|
83
|
-
function validateIndices(indices
|
|
68
|
+
function validateIndices(indices) {
|
|
84
69
|
const hasNoValueOrText = indices.value === -1 && indices.text === -1;
|
|
85
|
-
if (
|
|
70
|
+
if (!indices.properties.length) {
|
|
86
71
|
throw new Error("Couldn't find any field of type string in the results");
|
|
87
72
|
}
|
|
88
|
-
if (hasNoValueOrText
|
|
73
|
+
if (hasNoValueOrText) {
|
|
89
74
|
indices.value = indices.properties[0].index;
|
|
90
|
-
indices.
|
|
75
|
+
indices.text = indices.properties[0].index;
|
|
76
|
+
}
|
|
77
|
+
if (indices.value === -1 && indices.text !== -1) {
|
|
78
|
+
indices.value = indices.text;
|
|
91
79
|
}
|
|
92
|
-
if (
|
|
93
|
-
|
|
80
|
+
if (indices.text === -1 && indices.value !== -1) {
|
|
81
|
+
indices.text = indices.value;
|
|
94
82
|
}
|
|
95
83
|
return indices;
|
|
96
84
|
}
|
|
@@ -1 +1 @@
|
|
|
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, string>;\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 = validateIndices(findFieldsIndices(frames
|
|
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, string>;\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 = validateIndices(findFieldsIndices(frames, valueProp, textProp));\n\n const metrics: MetricFindValueWithOptionalProperties[] = [];\n\n for (const frame of frames) {\n for (let index = 0; index < frame.length; index++) {\n const fieldValue = (fieldIndex: number) =>\n fieldIndex !== -1 ? frame.fields[fieldIndex].values.get(index) : undefined;\n\n const value = fieldValue(indices.value);\n const text = fieldValue(indices.text);\n const expandable = fieldValue(indices.expandable);\n\n const properties: MetricFindValueWithOptionalProperties['properties'] = {};\n\n for (const p of indices.properties) {\n properties[p.name] = fieldValue(p.index);\n }\n\n const result: MetricFindValueWithOptionalProperties = { value, text, properties: properties };\n\n if (expandable !== undefined) {\n result.expandable = Boolean(expandable);\n }\n\n metrics.push(result);\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[], valueProp?: string, textProp?: string): Indices {\n const indices: Indices = {\n value: -1,\n text: -1,\n expandable: -1,\n properties: [],\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 (valueProp && fieldName === valueProp) {\n indices.value = index;\n }\n\n if (textProp && fieldName === textProp) {\n indices.text = index;\n }\n\n if (fieldName === 'value' && indices.value === -1) {\n indices.value = index;\n }\n\n if (fieldName === 'text' && indices.text === -1) {\n indices.text = index;\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 validateIndices(indices: Indices): Indices {\n const hasNoValueOrText = indices.value === -1 && indices.text === -1;\n\n if (!indices.properties.length) {\n throw new Error(\"Couldn't find any field of type string in the results\");\n }\n\n if (hasNoValueOrText) {\n indices.value = indices.properties[0].index;\n indices.text = indices.properties[0].index;\n }\n\n if (indices.value === -1 && indices.text !== -1) {\n indices.value = indices.text;\n }\n\n if (indices.text === -1 && indices.value !== -1) {\n indices.text = indices.value;\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 const value = firstValue[firstValueKey];\n if (value !== null && typeof value !== 'string' && typeof value !== 'number') {\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,MAAA,MAAM,UAAU,eAAgB,CAAA,iBAAA,CAAkB,MAA2B,CAAC,CAAA;AAE9E,MAAA,MAAM,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,KAAQ,OAAS,EAAA;AACrC,MAAO,OAAA,IAAA;AAAA;AACT;AAGF,EAAO,OAAA,KAAA;AACT;;;;"}
|
package/dist/index.js
CHANGED
|
@@ -10278,31 +10278,22 @@ function toMetricFindValues(valueProp, textProp) {
|
|
|
10278
10278
|
const value = fieldValue(indices.value);
|
|
10279
10279
|
const text = fieldValue(indices.text);
|
|
10280
10280
|
const expandable = fieldValue(indices.expandable);
|
|
10281
|
-
if (!indices.properties.length) {
|
|
10282
|
-
metrics.push({
|
|
10283
|
-
value: value || text,
|
|
10284
|
-
text: text || value,
|
|
10285
|
-
expandable
|
|
10286
|
-
});
|
|
10287
|
-
continue;
|
|
10288
|
-
}
|
|
10289
10281
|
const properties = {};
|
|
10290
10282
|
for (const p of indices.properties) {
|
|
10291
10283
|
properties[p.name] = fieldValue(p.index);
|
|
10292
10284
|
}
|
|
10293
|
-
|
|
10294
|
-
|
|
10295
|
-
|
|
10296
|
-
|
|
10297
|
-
|
|
10298
|
-
});
|
|
10285
|
+
const result = { value, text, properties };
|
|
10286
|
+
if (expandable !== void 0) {
|
|
10287
|
+
result.expandable = Boolean(expandable);
|
|
10288
|
+
}
|
|
10289
|
+
metrics.push(result);
|
|
10299
10290
|
}
|
|
10300
10291
|
}
|
|
10301
10292
|
return metrics;
|
|
10302
10293
|
})
|
|
10303
10294
|
);
|
|
10304
10295
|
}
|
|
10305
|
-
function findFieldsIndices(frames) {
|
|
10296
|
+
function findFieldsIndices(frames, valueProp, textProp) {
|
|
10306
10297
|
const indices = {
|
|
10307
10298
|
value: -1,
|
|
10308
10299
|
text: -1,
|
|
@@ -10314,17 +10305,11 @@ function findFieldsIndices(frames) {
|
|
|
10314
10305
|
const field = frame.fields[index];
|
|
10315
10306
|
const fieldName = data.getFieldDisplayName(field, frame, frames).toLowerCase();
|
|
10316
10307
|
if (field.type === data.FieldType.string) {
|
|
10317
|
-
if (fieldName === "value") {
|
|
10318
|
-
|
|
10319
|
-
indices.value = index;
|
|
10320
|
-
}
|
|
10321
|
-
continue;
|
|
10308
|
+
if (fieldName === "value" && indices.value === -1) {
|
|
10309
|
+
indices.value = index;
|
|
10322
10310
|
}
|
|
10323
|
-
if (fieldName === "text") {
|
|
10324
|
-
|
|
10325
|
-
indices.text = index;
|
|
10326
|
-
}
|
|
10327
|
-
continue;
|
|
10311
|
+
if (fieldName === "text" && indices.text === -1) {
|
|
10312
|
+
indices.text = index;
|
|
10328
10313
|
}
|
|
10329
10314
|
indices.properties.push({ name: fieldName, index });
|
|
10330
10315
|
continue;
|
|
@@ -10336,17 +10321,20 @@ function findFieldsIndices(frames) {
|
|
|
10336
10321
|
}
|
|
10337
10322
|
return indices;
|
|
10338
10323
|
}
|
|
10339
|
-
function validateIndices(indices
|
|
10324
|
+
function validateIndices(indices) {
|
|
10340
10325
|
const hasNoValueOrText = indices.value === -1 && indices.text === -1;
|
|
10341
|
-
if (
|
|
10326
|
+
if (!indices.properties.length) {
|
|
10342
10327
|
throw new Error("Couldn't find any field of type string in the results");
|
|
10343
10328
|
}
|
|
10344
|
-
if (hasNoValueOrText
|
|
10329
|
+
if (hasNoValueOrText) {
|
|
10345
10330
|
indices.value = indices.properties[0].index;
|
|
10346
|
-
indices.
|
|
10331
|
+
indices.text = indices.properties[0].index;
|
|
10332
|
+
}
|
|
10333
|
+
if (indices.value === -1 && indices.text !== -1) {
|
|
10334
|
+
indices.value = indices.text;
|
|
10347
10335
|
}
|
|
10348
|
-
if (
|
|
10349
|
-
|
|
10336
|
+
if (indices.text === -1 && indices.value !== -1) {
|
|
10337
|
+
indices.text = indices.value;
|
|
10350
10338
|
}
|
|
10351
10339
|
return indices;
|
|
10352
10340
|
}
|