mirror of
https://github.com/grafana/grafana.git
synced 2025-07-31 09:32:40 +08:00

* Performance: Standardize lodash imports to use destructured members Changes lodash imports of the form `import x from 'lodash/x'` to `import { x } from 'lodash'` to reduce bundle size. * Remove unnecessary _ import from Graph component * Enforce lodash import style * Fix remaining lodash imports
38 lines
882 B
TypeScript
38 lines
882 B
TypeScript
import { every, find } from 'lodash';
|
|
import { DataQuery } from '@grafana/data';
|
|
|
|
export const getNextRefIdChar = (queries: DataQuery[]): string => {
|
|
const letters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
|
|
|
|
return (
|
|
find(letters, (refId) => {
|
|
return every(queries, (other) => {
|
|
return other.refId !== refId;
|
|
});
|
|
}) ?? 'NA'
|
|
);
|
|
};
|
|
|
|
export function addQuery(queries: DataQuery[], query?: Partial<DataQuery>): DataQuery[] {
|
|
const q = query || {};
|
|
q.refId = getNextRefIdChar(queries);
|
|
q.hide = false;
|
|
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/);
|
|
}
|