grafana/public/app/core/utils/query.ts

37 lines
850 B
TypeScript
Raw Normal View History

2019-03-14 11:20:33 -05:00
import _ from 'lodash';
import { DataQuery } from '@grafana/data';
2019-03-14 11:20:33 -05:00
export const getNextRefIdChar = (queries: DataQuery[]): string => {
2019-03-14 11:20:33 -05:00
const letters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
return (
_.find(letters, refId => {
return _.every(queries, other => {
return other.refId !== refId;
});
}) ?? 'NA'
);
2019-03-14 11:20:33 -05:00
};
export function addQuery(queries: DataQuery[], query?: Partial<DataQuery>): DataQuery[] {
const q = query || {};
q.refId = getNextRefIdChar(queries);
return [...queries, q as DataQuery];
}
export function isDataQuery(url: string): boolean {
if (
url.indexOf('api/datasources/proxy') !== -1 ||
url.indexOf('api/tsdb/query') !== -1 ||
url.indexOf('api/ds/query') !== -1
) {
return true;
}
return false;
}
export function isLocalUrl(url: string) {
return !url.match(/^http/);
}