mirror of
https://github.com/grafana/grafana.git
synced 2024-12-02 13:39:19 -06:00
35d98104ad
* Fix: sql plugins feature
* SQLDS: Use builtin annotation editor
Plus strict rule fixes
* MSSQL: Migrate query editor to React
* Make code editor work
* Make SQLOptions and SQLQuery in SQLDatasource and in Editor generic
* MSSQL: Fix ts issues
* Fix SQLDatasource refID
* Remove comment
* Revert "Make SQLOptions and SQLQuery in SQLDatasource and in Editor generic"
This reverts commit 1d15b4061a
.
* Fix ts issues without generic
* TS
29 lines
892 B
TypeScript
29 lines
892 B
TypeScript
import { uniqBy } from 'lodash';
|
|
|
|
import { DataFrame, MetricFindValue } from '@grafana/data';
|
|
import { ResponseParser } from 'app/features/plugins/sql/types';
|
|
|
|
export class MSSqlResponseParser implements ResponseParser {
|
|
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');
|
|
}
|
|
}
|