mirror of
https://github.com/grafana/grafana.git
synced 2025-02-13 00:55:47 -06:00
- Migrate Postgres query editor to react - Add support for field aliasing in SELECT clauses to SQL based datasources Co-authored-by: Kyle Cunningham <kyle@codeincarnate.com> Co-authored-by: Oscar Kilhed <oscar.kilhed@grafana.com>
29 lines
913 B
TypeScript
29 lines
913 B
TypeScript
import { uniqBy } from 'lodash';
|
|
|
|
import { DataFrame, MetricFindValue } from '@grafana/data';
|
|
import { ResponseParser as ResponseParserType } from 'app/features/plugins/sql/types';
|
|
|
|
export class ResponseParser implements ResponseParserType {
|
|
transformMetricFindResponse(frame: DataFrame): MetricFindValue[] {
|
|
const values: MetricFindValue[] = [];
|
|
const textField = frame.fields.find((f) => f.name === '__text');
|
|
const valueField = frame.fields.find((f) => f.name === '__value');
|
|
|
|
if (textField && valueField) {
|
|
for (let i = 0; i < textField.values.length; i++) {
|
|
values.push({ text: '' + textField.values.get(i), value: '' + valueField.values.get(i) });
|
|
}
|
|
} else {
|
|
values.push(
|
|
...frame.fields
|
|
.flatMap((f) => f.values.toArray())
|
|
.map((v) => ({
|
|
text: v,
|
|
}))
|
|
);
|
|
}
|
|
|
|
return uniqBy(values, 'text');
|
|
}
|
|
}
|