mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
- remove `edited` property of query objects - query object semantics changes to be initial values only - resetting or externally modifying a query is done via giving it a new react key, which replaces the row completely - query changes while typing are sent up to Explore to be saved in a local property that is not part of the component state (prevent control circle) - all Explore functions using the queries must access the local property for current values
17 lines
561 B
TypeScript
17 lines
561 B
TypeScript
import { Query } from 'app/types/explore';
|
|
|
|
export function generateQueryKey(index = 0): string {
|
|
return `Q-${Date.now()}-${Math.random()}-${index}`;
|
|
}
|
|
|
|
export function ensureQueries(queries?: Query[]): Query[] {
|
|
if (queries && typeof queries === 'object' && queries.length > 0 && typeof queries[0].query === 'string') {
|
|
return queries.map(({ query }, i) => ({ key: generateQueryKey(i), query }));
|
|
}
|
|
return [{ key: generateQueryKey(), query: '' }];
|
|
}
|
|
|
|
export function hasQuery(queries: string[]): boolean {
|
|
return queries.some(q => Boolean(q));
|
|
}
|