grafana/public/app/plugins/datasource/mssql/response_parser.ts
Zoltán Bedi 35d98104ad
MSSQL: Migrate to React (#51765)
* 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
2022-07-15 19:51:28 +02:00

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');
}
}