Dashboard: Allow more than 26 queries per panel. (#35442)

* Dashboard: Allow more than 26 queries per panel.

Fixes #4978

* Chore: Remove underscores from helper function names

Co-authored-by: Danyal Fairburn <danyal.fairburn@bt.com>
This commit is contained in:
Dan Fairburn
2021-06-23 14:23:02 +01:00
committed by GitHub
parent db81e55512
commit b9582ea93d
2 changed files with 34 additions and 28 deletions

View File

@@ -1,16 +1,12 @@
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'
);
for (let num = 0; ; num++) {
const refId = getRefId(num);
if (!queries.some((query) => query.refId === refId)) {
return refId;
}
}
};
export function addQuery(queries: DataQuery[], query?: Partial<DataQuery>): DataQuery[] {
@@ -35,3 +31,13 @@ export function isDataQuery(url: string): boolean {
export function isLocalUrl(url: string) {
return !url.match(/^http/);
}
function getRefId(num: number): string {
const letters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
if (num < letters.length) {
return letters[num];
} else {
return getRefId(Math.floor(num / letters.length) - 1) + letters[num % letters.length];
}
}