SavedQuery: Types refactor (#110554)
This commit is contained in:
@@ -2,8 +2,9 @@ import { createContext, ReactNode, useContext } from 'react';
|
||||
|
||||
import { CoreApp } from '@grafana/data';
|
||||
import { DataQuery } from '@grafana/schema';
|
||||
import { SavedQuery } from 'app/features/explore/QueryLibrary/types';
|
||||
|
||||
import { OnSelectQueryType, QueryTemplate, QueryLibraryEventsPropertyMap } from './types';
|
||||
import { OnSelectQueryType, QueryLibraryEventsPropertyMap } from './types';
|
||||
|
||||
export type QueryLibraryDrawerOptions = {
|
||||
datasourceFilters?: string[];
|
||||
@@ -70,7 +71,7 @@ export type QueryLibraryContextType = {
|
||||
properties?: QueryLibraryEventsPropertyMap,
|
||||
contextOverride?: string
|
||||
) => void;
|
||||
setNewQuery: (query?: QueryTemplate) => void;
|
||||
setNewQuery: (query?: SavedQuery) => void;
|
||||
onSelectQuery: (query: DataQuery) => void;
|
||||
};
|
||||
|
||||
|
||||
@@ -10,18 +10,26 @@ export type OnSelectQueryType = (query: DataQuery) => void;
|
||||
|
||||
export type QueryLibraryEventsPropertyMap = Record<string, string | boolean | undefined>;
|
||||
|
||||
export type QueryTemplate = {
|
||||
// flattened data from API response to facilitate structs
|
||||
export type SavedQueryBase = {
|
||||
uid: string;
|
||||
title: string;
|
||||
description: string;
|
||||
tags: string[];
|
||||
isLocked: boolean;
|
||||
isVisible: boolean;
|
||||
createdAtTimestamp: number;
|
||||
user: User;
|
||||
targets: DataQuery[];
|
||||
};
|
||||
// this should actually be like this, but not posssible due to enterprise Spec
|
||||
// & Required<Pick<QuerySpec, 'title' | 'description' | 'tags' | 'isLocked' | 'isVisible'>>;
|
||||
|
||||
// our model of SavedQuery to use throughout the frontend
|
||||
export type SavedQuery = {
|
||||
query: DataQuery;
|
||||
datasourceName?: string;
|
||||
title?: string;
|
||||
description?: string;
|
||||
tags?: string[];
|
||||
isLocked?: boolean;
|
||||
isVisible?: boolean;
|
||||
queryText?: string;
|
||||
datasourceRef?: DataSourceRef | null;
|
||||
datasourceType?: string;
|
||||
createdAtTimestamp?: number;
|
||||
user?: User;
|
||||
uid?: string;
|
||||
};
|
||||
} & Omit<Partial<SavedQueryBase>, 'targets'>;
|
||||
|
||||
Reference in New Issue
Block a user