@grafana/scenes 6.51.0--canary.1316.20309633325.0 β†’ 6.52.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 CHANGED
@@ -1,3 +1,29 @@
1
+ # v6.52.0 (Thu Dec 18 2025)
2
+
3
+ #### πŸš€ Enhancement
4
+
5
+ - AdHocVariable: Add collapse button and clear all option [#1316](https://github.com/grafana/scenes/pull/1316) ([@harisrozajac](https://github.com/harisrozajac) [@mdvictor](https://github.com/mdvictor))
6
+
7
+ #### Authors: 2
8
+
9
+ - Haris Rozajac ([@harisrozajac](https://github.com/harisrozajac))
10
+ - Victor Marin ([@mdvictor](https://github.com/mdvictor))
11
+
12
+ ---
13
+
14
+ # v6.51.0 (Thu Dec 18 2025)
15
+
16
+ #### πŸš€ Enhancement
17
+
18
+ - Variables: Fix breaking behavior in toMetricFindValues [#1319](https://github.com/grafana/scenes/pull/1319) ([@torkelo](https://github.com/torkelo) [@grafakus](https://github.com/grafakus))
19
+
20
+ #### Authors: 2
21
+
22
+ - Marc M. ([@grafakus](https://github.com/grafakus))
23
+ - Torkel Γ–degaard ([@torkelo](https://github.com/torkelo))
24
+
25
+ ---
26
+
1
27
  # v6.50.0 (Wed Dec 17 2025)
2
28
 
3
29
  #### πŸš€ 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
- metrics.push({
38
- value: value || valueProp || text || textProp,
39
- text: text || textProp || value || valueProp,
40
- properties,
41
- expandable
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
- if (indices.value === -1) {
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
- if (indices.text === -1) {
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, valueProp, textProp) {
68
+ function validateIndices(indices) {
84
69
  const hasNoValueOrText = indices.value === -1 && indices.text === -1;
85
- if (hasNoValueOrText && !indices.properties.length) {
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 && indices.properties.length === 1) {
73
+ if (hasNoValueOrText) {
89
74
  indices.value = indices.properties[0].index;
90
- indices.properties = [];
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 (hasNoValueOrText && indices.properties.length && true && true) {
93
- throw new Error("Properties found in series but missing valueProp and textProp");
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), 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 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: MetricFindValueWithOptionalProperties['properties'] = {};\n for (const p of indices.properties) {\n properties[p.name] = fieldValue(p.index);\n }\n\n metrics.push({\n value: value || (valueProp && properties[valueProp]) || text || (textProp && properties[textProp]),\n text: text || (textProp && properties[textProp]) || value || (valueProp && properties[valueProp]),\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 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 (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 validateIndices(indices: Indices, valueProp?: string, textProp?: string): Indices {\n const hasNoValueOrText = indices.value === -1 && indices.text === -1;\n\n if (hasNoValueOrText && !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 (hasNoValueOrText && indices.properties.length === 1) {\n indices.value = indices.properties[0].index;\n indices.properties = [];\n }\n\n if (hasNoValueOrText && indices.properties.length && !valueProp && !textProp) {\n throw new Error('Properties found in series but missing valueProp and textProp');\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,MAA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CAAC,CAAA;AAE9B,EAAI,IAAA,WAAA,CAAY,UAAU,CAAG,EAAA;AAC3B,IAAO,OAAA,KAAA;AAAA;AAGT,EAAA,KAAA,MAAW,iBAAiB,UAAY,EAAA;AACtC,IAAA,IAAI,CAAC,UAAA,CAAW,cAAe,CAAA,aAAa,CAAG,EAAA;AAC7C,MAAA;AAAA;AAGF,IAAM,MAAA,KAAA,GAAQ,WAAW,aAAa,CAAA;AACtC,IAAA,IAAI,UAAU,IAAQ,IAAA,OAAO,UAAU,QAAY,IAAA,OAAO,UAAU,QAAU,EAAA;AAC5E,MAAA;AAAA;AAGF,IAAM,MAAA,GAAA,GAAM,cAAc,WAAY,EAAA;AAEtC,IAAI,IAAA,GAAA,KAAQ,MAAU,IAAA,GAAA,KAAQ,OAAS,EAAA;AACrC,MAAO,OAAA,IAAA;AAAA;AACT;AAGF,EAAO,OAAA,KAAA;AACT;;;;"}
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,UAAmD,EAAC;AAE1D,MAAA,KAAA,MAAW,SAAS,MAAQ,EAAA;AAC1B,QAAA,KAAA,IAAS,KAAQ,GAAA,CAAA,EAAG,KAAQ,GAAA,KAAA,CAAM,QAAQ,KAAS,EAAA,EAAA;AACjD,UAAA,MAAM,UAAa,GAAA,CAAC,UAClB,KAAA,UAAA,KAAe,EAAK,GAAA,KAAA,CAAM,MAAO,CAAA,UAAU,CAAE,CAAA,MAAA,CAAO,GAAI,CAAA,KAAK,CAAI,GAAA,MAAA;AAE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A,OAAA,CAAQ,QAAQ,OAAQ,CAAA,IAAA;AAAA;AAG1B,EAAA,IAAI,OAAQ,CAAA,IAAA,KAAS,EAAM,IAAA,OAAA,CAAQ,UAAU,EAAI,EAAA;AAC/C,IAAA,OAAA,CAAQ,OAAO,OAAQ,CAAA,KAAA;AAAA;AAGzB,EAAO,OAAA,OAAA;AACT;AAEA,SAAS,oBAAoB,IAAwC,EAAA;AACnE,EAAA,IAAI,CAAC,IAAM,EAAA;AACT,IAAO,OAAA,KAAA;AAAA;AAGT,EAAI,IAAA,CAAC,KAAK,MAAQ,EAAA;AAChB,IAAO,OAAA,IAAA;AAAA;AAGT,EAAM,MAAA,UAAA,GAAkB,KAAK,CAAC,CAAA;AAE9B,EAAI,IAAA,WAAA,CAAY,UAAU,CAAG,EAAA;AAC3B,IAAO,OAAA,KAAA;AAAA;AAGT,EAAA,KAAA,MAAW,iBAAiB,UAAY,EAAA;AACtC,IAAA,IAAI,CAAC,UAAA,CAAW,cAAe,CAAA,aAAa,CAAG,EAAA;AAC7C,MAAA;AAAA;AAGF,IAAM,MAAA,KAAA,GAAQ,WAAW,aAAa,CAAA;AACtC,IAAA,IAAI,UAAU,IAAQ,IAAA,OAAO,UAAU,QAAY,IAAA,OAAO,UAAU,QAAU,EAAA;AAC5E,MAAA;AAAA;AAGF,IAAM,MAAA,GAAA,GAAM,cAAc,WAAY,EAAA;AAEtC,IAAI,IAAA,GAAA,KAAQ,MAAU,IAAA,GAAA,KAAQ,OAAS,EAAA;AACrC,MAAO,OAAA,IAAA;AAAA;AACT;AAGF,EAAO,OAAA,KAAA;AACT;;;;"}
package/dist/index.js CHANGED
@@ -10413,31 +10413,22 @@ function toMetricFindValues(valueProp, textProp) {
10413
10413
  const value = fieldValue(indices.value);
10414
10414
  const text = fieldValue(indices.text);
10415
10415
  const expandable = fieldValue(indices.expandable);
10416
- if (!indices.properties.length) {
10417
- metrics.push({
10418
- value: value || text,
10419
- text: text || value,
10420
- expandable
10421
- });
10422
- continue;
10423
- }
10424
10416
  const properties = {};
10425
10417
  for (const p of indices.properties) {
10426
10418
  properties[p.name] = fieldValue(p.index);
10427
10419
  }
10428
- metrics.push({
10429
- value: value || valueProp || text || textProp,
10430
- text: text || textProp || value || valueProp,
10431
- properties,
10432
- expandable
10433
- });
10420
+ const result = { value, text, properties };
10421
+ if (expandable !== void 0) {
10422
+ result.expandable = Boolean(expandable);
10423
+ }
10424
+ metrics.push(result);
10434
10425
  }
10435
10426
  }
10436
10427
  return metrics;
10437
10428
  })
10438
10429
  );
10439
10430
  }
10440
- function findFieldsIndices(frames) {
10431
+ function findFieldsIndices(frames, valueProp, textProp) {
10441
10432
  const indices = {
10442
10433
  value: -1,
10443
10434
  text: -1,
@@ -10449,17 +10440,11 @@ function findFieldsIndices(frames) {
10449
10440
  const field = frame.fields[index];
10450
10441
  const fieldName = data.getFieldDisplayName(field, frame, frames).toLowerCase();
10451
10442
  if (field.type === data.FieldType.string) {
10452
- if (fieldName === "value") {
10453
- if (indices.value === -1) {
10454
- indices.value = index;
10455
- }
10456
- continue;
10443
+ if (fieldName === "value" && indices.value === -1) {
10444
+ indices.value = index;
10457
10445
  }
10458
- if (fieldName === "text") {
10459
- if (indices.text === -1) {
10460
- indices.text = index;
10461
- }
10462
- continue;
10446
+ if (fieldName === "text" && indices.text === -1) {
10447
+ indices.text = index;
10463
10448
  }
10464
10449
  indices.properties.push({ name: fieldName, index });
10465
10450
  continue;
@@ -10471,17 +10456,20 @@ function findFieldsIndices(frames) {
10471
10456
  }
10472
10457
  return indices;
10473
10458
  }
10474
- function validateIndices(indices, valueProp, textProp) {
10459
+ function validateIndices(indices) {
10475
10460
  const hasNoValueOrText = indices.value === -1 && indices.text === -1;
10476
- if (hasNoValueOrText && !indices.properties.length) {
10461
+ if (!indices.properties.length) {
10477
10462
  throw new Error("Couldn't find any field of type string in the results");
10478
10463
  }
10479
- if (hasNoValueOrText && indices.properties.length === 1) {
10464
+ if (hasNoValueOrText) {
10480
10465
  indices.value = indices.properties[0].index;
10481
- indices.properties = [];
10466
+ indices.text = indices.properties[0].index;
10467
+ }
10468
+ if (indices.value === -1 && indices.text !== -1) {
10469
+ indices.value = indices.text;
10482
10470
  }
10483
- if (hasNoValueOrText && indices.properties.length && true && true) {
10484
- throw new Error("Properties found in series but missing valueProp and textProp");
10471
+ if (indices.text === -1 && indices.value !== -1) {
10472
+ indices.text = indices.value;
10485
10473
  }
10486
10474
  return indices;
10487
10475
  }