-
Notifications
You must be signed in to change notification settings - Fork 47
Variables: support object-based values with multiple properties #1236
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: variable-value-properties
Are you sure you want to change the base?
Changes from 1 commit
2383d0b
51bfbdf
e49743e
da04a3b
c32c895
4d065f1
7a39e48
b83b465
c52ad61
339cc7c
fcf42f3
86ac6ab
5a2b438
901a7ff
5355a08
29c0bdf
82a780a
c6c76f4
20f655b
0fe0503
932bd3c
ce11620
0a39fea
f27e56a
34e9ca0
4b3b50f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,7 +8,11 @@ import { | |
| } from '@grafana/data'; | ||
| import { map, OperatorFunction } from 'rxjs'; | ||
|
|
||
| export function toMetricFindValues(): OperatorFunction<PanelData, MetricFindValue[]> { | ||
| interface MetricFindValueWithProperties extends MetricFindValue { | ||
| properties?: Record<string, any>; | ||
| } | ||
|
|
||
| export function toMetricFindValues(): OperatorFunction<PanelData, MetricFindValueWithProperties[]> { | ||
| return (source) => | ||
| source.pipe( | ||
| map((panelData) => { | ||
|
|
@@ -26,12 +30,13 @@ export function toMetricFindValues(): OperatorFunction<PanelData, MetricFindValu | |
| } | ||
|
|
||
| const processedDataFrames = getProcessedDataFrames(frames); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Both elastic and postgres use the metricFindQuery so already return MetricFindValue, so this function will return already on line 29 (unless we update those data sources to handle variables differently) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it was mentioned when we reached the consensus on the design doc. Besides pinging the owners of the Elastic and Postgres datasources, is the change in this PR enough? |
||
| const metrics: MetricFindValue[] = []; | ||
| const metrics: MetricFindValueWithProperties[] = []; | ||
|
|
||
| let valueIndex = -1; | ||
| let textIndex = -1; | ||
| let stringIndex = -1; | ||
| let expandableIndex = -1; | ||
| let propertiesIndex = -1; | ||
|
|
||
| for (const frame of processedDataFrames) { | ||
| for (let index = 0; index < frame.fields.length; index++) { | ||
|
|
@@ -42,6 +47,10 @@ export function toMetricFindValues(): OperatorFunction<PanelData, MetricFindValu | |
| stringIndex = index; | ||
| } | ||
|
|
||
| if (field.type === FieldType.other && propertiesIndex === -1) { | ||
| propertiesIndex = index; | ||
| } | ||
|
|
||
| if (fieldName === 'text' && field.type === FieldType.string && textIndex === -1) { | ||
| textIndex = index; | ||
| } | ||
|
|
@@ -70,23 +79,24 @@ export function toMetricFindValues(): OperatorFunction<PanelData, MetricFindValu | |
| const string = frame.fields[stringIndex].values.get(index); | ||
| const text = textIndex !== -1 ? frame.fields[textIndex].values.get(index) : ''; | ||
| const value = valueIndex !== -1 ? frame.fields[valueIndex].values.get(index) : ''; | ||
| const properties = propertiesIndex !== -1 ? frame.fields[propertiesIndex].values.get(index) : undefined; | ||
|
|
||
| if (valueIndex === -1 && textIndex === -1) { | ||
| metrics.push({ text: string, value: string, expandable }); | ||
| metrics.push({ text: string, value: string, expandable, properties }); | ||
| continue; | ||
| } | ||
|
|
||
| if (valueIndex === -1 && textIndex !== -1) { | ||
| metrics.push({ text, value: text, expandable }); | ||
| metrics.push({ text, value: text, expandable, properties }); | ||
| continue; | ||
| } | ||
|
|
||
| if (valueIndex !== -1 && textIndex === -1) { | ||
| metrics.push({ text: value, value, expandable }); | ||
| metrics.push({ text: value, value, expandable, properties }); | ||
| continue; | ||
| } | ||
|
|
||
| metrics.push({ text, value, expandable }); | ||
| metrics.push({ text, value, expandable, properties }); | ||
| } | ||
| } | ||
|
|
||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.