@grafana/scenes 6.47.0--canary.1236.19342683681.0 → 6.47.0--canary.1302.19359467581.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/dist/index.js CHANGED
@@ -1774,7 +1774,7 @@ function isRepeatCloneOrChildOf(scene) {
1774
1774
  return false;
1775
1775
  }
1776
1776
 
1777
- const _MultiValueVariable = class _MultiValueVariable extends SceneObjectBase {
1777
+ class MultiValueVariable extends SceneObjectBase {
1778
1778
  constructor() {
1779
1779
  super(...arguments);
1780
1780
  this._urlSync = new MultiValueUrlSyncHandler(this);
@@ -1865,7 +1865,7 @@ const _MultiValueVariable = class _MultiValueVariable extends SceneObjectBase {
1865
1865
  } else {
1866
1866
  const defaultState = this.getDefaultSingleState(options);
1867
1867
  stateUpdate.value = defaultState.value;
1868
- stateUpdate.text = defaultState.label;
1868
+ stateUpdate.text = defaultState.text;
1869
1869
  }
1870
1870
  return stateUpdate;
1871
1871
  }
@@ -1887,35 +1887,16 @@ const _MultiValueVariable = 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((o) => o.value);
1890
+ value = this.state.options.map((x) => x.value);
1891
1891
  }
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);
1892
+ if (fieldPath != null && Array.isArray(value)) {
1893
+ const index = parseInt(fieldPath, 10);
1894
+ if (!isNaN(index) && index >= 0 && index < value.length) {
1895
+ return value[index];
1908
1896
  }
1909
1897
  }
1910
1898
  return value;
1911
1899
  }
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
- }
1919
1900
  getValueText() {
1920
1901
  if (this.hasAllValue()) {
1921
1902
  return ALL_VARIABLE_TEXT;
@@ -1933,18 +1914,18 @@ const _MultiValueVariable = class _MultiValueVariable extends SceneObjectBase {
1933
1914
  if (this.state.defaultToAll) {
1934
1915
  return { value: [ALL_VARIABLE_VALUE], text: [ALL_VARIABLE_TEXT] };
1935
1916
  } else if (options.length > 0) {
1936
- return { value: [options[0].value], text: [options[0].label], properties: [options[0].properties] };
1917
+ return { value: [options[0].value], text: [options[0].label] };
1937
1918
  } else {
1938
1919
  return { value: [], text: [] };
1939
1920
  }
1940
1921
  }
1941
1922
  getDefaultSingleState(options) {
1942
1923
  if (this.state.defaultToAll) {
1943
- return { value: ALL_VARIABLE_VALUE, label: ALL_VARIABLE_TEXT };
1924
+ return { value: ALL_VARIABLE_VALUE, text: ALL_VARIABLE_TEXT };
1944
1925
  } else if (options.length > 0) {
1945
- return { value: options[0].value, label: options[0].label, properties: options[0].properties };
1926
+ return { value: options[0].value, text: options[0].label };
1946
1927
  } else {
1947
- return { value: "", label: "" };
1928
+ return { value: "", text: "" };
1948
1929
  }
1949
1930
  }
1950
1931
  /**
@@ -2029,17 +2010,15 @@ const _MultiValueVariable = class _MultiValueVariable extends SceneObjectBase {
2029
2010
  this.updateValueGivenNewOptions(options);
2030
2011
  });
2031
2012
  }
2032
- };
2033
- _MultiValueVariable.fieldAccessorCache = {};
2034
- let MultiValueVariable = _MultiValueVariable;
2013
+ }
2035
2014
  function findOptionMatchingCurrent(currentValue, currentText, options) {
2036
2015
  let textMatch;
2037
- for (const o of options) {
2038
- if (o.value === currentValue) {
2039
- return o;
2016
+ for (const item of options) {
2017
+ if (item.value === currentValue) {
2018
+ return item;
2040
2019
  }
2041
- if (o.label === currentText) {
2042
- textMatch = o;
2020
+ if (item.label === currentText) {
2021
+ textMatch = item;
2043
2022
  }
2044
2023
  }
2045
2024
  return textMatch;
@@ -4143,7 +4122,7 @@ function VizPanelRenderer({ model }) {
4143
4122
  height,
4144
4123
  selectionId: model.state.key,
4145
4124
  displayMode,
4146
- titleItems: titleItemsElement,
4125
+ titleItems: titleItemsElement.length > 0 ? titleItemsElement : void 0,
4147
4126
  dragClass,
4148
4127
  actions: actionsElement,
4149
4128
  dragClassCancel,
@@ -9455,7 +9434,7 @@ function metricNamesToVariableValues(variableRegEx, sort, metricNames) {
9455
9434
  value = firstMatch[1];
9456
9435
  }
9457
9436
  }
9458
- options.push({ label: text, value, properties: item.properties });
9437
+ options.push({ label: text, value });
9459
9438
  }
9460
9439
  options = lodash.uniqBy(options, "value");
9461
9440
  return sortVariableValues(options, sort);
@@ -9529,7 +9508,7 @@ function sortByNaturalSort(options) {
9529
9508
  });
9530
9509
  }
9531
9510
 
9532
- function toMetricFindValues(valueProp, textProp) {
9511
+ function toMetricFindValues() {
9533
9512
  return (source) => source.pipe(
9534
9513
  rxjs.map((panelData) => {
9535
9514
  const frames = panelData.series;
@@ -9542,81 +9521,58 @@ function toMetricFindValues(valueProp, textProp) {
9542
9521
  if (frames[0].fields.length === 0) {
9543
9522
  return [];
9544
9523
  }
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 = [];
9524
+ const processedDataFrames = data.getProcessedDataFrames(frames);
9525
+ const metrics = [];
9526
+ let valueIndex = -1;
9527
+ let textIndex = -1;
9528
+ let stringIndex = -1;
9529
+ let expandableIndex = -1;
9530
+ for (const frame of processedDataFrames) {
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
+ }
9552
9547
  }
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");
9548
+ if (stringIndex === -1) {
9549
+ throw new Error("Couldn't find any field of type string in the results.");
9555
9550
  }
9556
- const metrics = [];
9557
9551
  for (const frame of frames) {
9558
9552
  for (let index = 0; index < frame.length; index++) {
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
- });
9553
+ const expandable = expandableIndex !== -1 ? frame.fields[expandableIndex].values.get(index) : void 0;
9554
+ const string = frame.fields[stringIndex].values.get(index);
9555
+ const text = textIndex !== -1 ? frame.fields[textIndex].values.get(index) : "";
9556
+ const value = valueIndex !== -1 ? frame.fields[valueIndex].values.get(index) : "";
9557
+ if (valueIndex === -1 && textIndex === -1) {
9558
+ metrics.push({ text: string, value: string, expandable });
9568
9559
  continue;
9569
9560
  }
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
- });
9561
+ if (valueIndex === -1 && textIndex !== -1) {
9562
+ metrics.push({ text, value: text, expandable });
9563
+ continue;
9564
+ }
9565
+ if (valueIndex !== -1 && textIndex === -1) {
9566
+ metrics.push({ text: value, value, expandable });
9567
+ continue;
9568
+ }
9569
+ metrics.push({ text, value, expandable });
9580
9570
  }
9581
9571
  }
9582
9572
  return metrics;
9583
9573
  })
9584
9574
  );
9585
9575
  }
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
- }
9620
9576
  function areMetricFindValues(data$1) {
9621
9577
  if (!data$1) {
9622
9578
  return false;
@@ -10020,7 +9976,7 @@ const sceneGraph = {
10020
9976
  getScopes
10021
9977
  };
10022
9978
 
10023
- const _LocalValueVariable = class _LocalValueVariable extends SceneObjectBase {
9979
+ class LocalValueVariable extends SceneObjectBase {
10024
9980
  constructor(initialState) {
10025
9981
  super({
10026
9982
  type: "system",
@@ -10031,19 +9987,9 @@ const _LocalValueVariable = class _LocalValueVariable extends SceneObjectBase {
10031
9987
  skipUrlSync: true
10032
9988
  });
10033
9989
  }
10034
- getValue(fieldPath) {
10035
- if (fieldPath != null && this.state.properties) {
10036
- return this.getFieldAccessor(fieldPath)(this.state.properties);
10037
- }
9990
+ getValue() {
10038
9991
  return this.state.value;
10039
9992
  }
10040
- getFieldAccessor(fieldPath) {
10041
- const accessor = _LocalValueVariable.fieldAccessorCache[fieldPath];
10042
- if (accessor) {
10043
- return accessor;
10044
- }
10045
- return _LocalValueVariable.fieldAccessorCache[fieldPath] = lodash.property(fieldPath);
10046
- }
10047
9993
  getValueText() {
10048
9994
  return this.state.text.toString();
10049
9995
  }
@@ -10064,9 +10010,7 @@ const _LocalValueVariable = class _LocalValueVariable extends SceneObjectBase {
10064
10010
  }
10065
10011
  return false;
10066
10012
  }
10067
- };
10068
- _LocalValueVariable.fieldAccessorCache = {};
10069
- let LocalValueVariable = _LocalValueVariable;
10013
+ }
10070
10014
 
10071
10015
  const PATH_ID_SEPARATOR = "$";
10072
10016
  function buildPathIdFor(panel) {
@@ -11863,7 +11807,6 @@ class CustomVariable extends MultiValueVariable {
11863
11807
  super({
11864
11808
  type: "custom",
11865
11809
  query: "",
11866
- valuesFormat: "csv",
11867
11810
  value: "",
11868
11811
  text: "",
11869
11812
  options: [],
@@ -11892,27 +11835,8 @@ class CustomVariable extends MultiValueVariable {
11892
11835
  }
11893
11836
  });
11894
11837
  }
11895
- transformJsonToOptions(json) {
11896
- if (!json) {
11897
- return [];
11898
- }
11899
- const parsedOptions = JSON.parse(json);
11900
- if (!Array.isArray(parsedOptions) || parsedOptions.some((o) => typeof o !== "object" || o === null)) {
11901
- throw new Error("Query must be a JSON array of objects");
11902
- }
11903
- const textProp = "text";
11904
- const valueProp = "value";
11905
- return parsedOptions.map((o) => {
11906
- var _a;
11907
- return {
11908
- label: (_a = String(o[textProp] || o[valueProp])) == null ? void 0 : _a.trim(),
11909
- value: String(o[valueProp]).trim(),
11910
- properties: lodash.omit(o, [textProp, valueProp])
11911
- };
11912
- });
11913
- }
11914
11838
  getValueOptions(args) {
11915
- const options = this.state.valuesFormat === "json" ? this.transformJsonToOptions(this.state.query) : this.transformCsvStringToOptions(this.state.query);
11839
+ const options = this.transformCsvStringToOptions(this.state.query);
11916
11840
  if (!options.length) {
11917
11841
  this.skipNextValidation = true;
11918
11842
  }