@grafana/scenes 6.48.0--canary.1236.19576619727.0 → 6.48.0--canary.1236.19576705002.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.
|
@@ -109,7 +109,8 @@ function areMetricFindValues(data) {
|
|
|
109
109
|
if (!firstValue.hasOwnProperty(firstValueKey)) {
|
|
110
110
|
continue;
|
|
111
111
|
}
|
|
112
|
-
|
|
112
|
+
const value = firstValue[firstValueKey];
|
|
113
|
+
if (value !== null && typeof value !== "string" && typeof value !== "number") {
|
|
113
114
|
continue;
|
|
114
115
|
}
|
|
115
116
|
const key = firstValueKey.toLowerCase();
|
|
@@ -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, 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 = 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: Record<string, string> = {};\n for (const p of indices.properties) {\n properties[p.name] = fieldValue(p.index);\n }\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 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
|
|
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 = 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: Record<string, string> = {};\n for (const p of indices.properties) {\n properties[p.name] = fieldValue(p.index);\n }\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 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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,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
|
@@ -9642,7 +9642,8 @@ function areMetricFindValues(data$1) {
|
|
|
9642
9642
|
if (!firstValue.hasOwnProperty(firstValueKey)) {
|
|
9643
9643
|
continue;
|
|
9644
9644
|
}
|
|
9645
|
-
|
|
9645
|
+
const value = firstValue[firstValueKey];
|
|
9646
|
+
if (value !== null && typeof value !== "string" && typeof value !== "number") {
|
|
9646
9647
|
continue;
|
|
9647
9648
|
}
|
|
9648
9649
|
const key = firstValueKey.toLowerCase();
|