mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
QueryGroup: Cleanup leftovers from hackathons (#67048)
This commit is contained in:
parent
cebdb49912
commit
0f9c6be3f0
@ -3206,10 +3206,6 @@ exports[`better eslint`] = {
|
|||||||
"public/app/features/query/components/QueryGroupOptions.tsx:5381": [
|
"public/app/features/query/components/QueryGroupOptions.tsx:5381": [
|
||||||
[0, 0, 0, "Do not use any type assertions.", "0"]
|
[0, 0, 0, "Do not use any type assertions.", "0"]
|
||||||
],
|
],
|
||||||
"public/app/features/query/components/SavedQueryPicker.tsx:5381": [
|
|
||||||
[0, 0, 0, "Use data-testid for E2E selectors instead of aria-label", "0"],
|
|
||||||
[0, 0, 0, "Use data-testid for E2E selectors instead of aria-label", "1"]
|
|
||||||
],
|
|
||||||
"public/app/features/query/state/DashboardQueryRunner/AlertStatesWorker.test.ts:5381": [
|
"public/app/features/query/state/DashboardQueryRunner/AlertStatesWorker.test.ts:5381": [
|
||||||
[0, 0, 0, "Unexpected any. Specify a different type.", "0"],
|
[0, 0, 0, "Unexpected any. Specify a different type.", "0"],
|
||||||
[0, 0, 0, "Unexpected any. Specify a different type.", "1"],
|
[0, 0, 0, "Unexpected any. Specify a different type.", "1"],
|
||||||
|
@ -27,7 +27,7 @@ import { DataSourcePicker } from 'app/features/datasources/components/picker/Dat
|
|||||||
import { dataSource as expressionDatasource } from 'app/features/expressions/ExpressionDatasource';
|
import { dataSource as expressionDatasource } from 'app/features/expressions/ExpressionDatasource';
|
||||||
import { DashboardQueryEditor, isSharedDashboardQuery } from 'app/plugins/datasource/dashboard';
|
import { DashboardQueryEditor, isSharedDashboardQuery } from 'app/plugins/datasource/dashboard';
|
||||||
import { GrafanaQuery, GrafanaQueryType } from 'app/plugins/datasource/grafana/types';
|
import { GrafanaQuery, GrafanaQueryType } from 'app/plugins/datasource/grafana/types';
|
||||||
import { QueryGroupDataSource, QueryGroupOptions } from 'app/types';
|
import { QueryGroupOptions } from 'app/types';
|
||||||
|
|
||||||
import { PanelQueryRunner } from '../state/PanelQueryRunner';
|
import { PanelQueryRunner } from '../state/PanelQueryRunner';
|
||||||
import { updateQueries } from '../state/updateQueries';
|
import { updateQueries } from '../state/updateQueries';
|
||||||
@ -57,12 +57,6 @@ interface State {
|
|||||||
isHelpOpen: boolean;
|
isHelpOpen: boolean;
|
||||||
defaultDataSource?: DataSourceApi;
|
defaultDataSource?: DataSourceApi;
|
||||||
scrollElement?: HTMLDivElement;
|
scrollElement?: HTMLDivElement;
|
||||||
savedQueryUid?: string | null;
|
|
||||||
initialState: {
|
|
||||||
queries: DataQuery[];
|
|
||||||
dataSource?: QueryGroupDataSource;
|
|
||||||
savedQueryUid?: string | null;
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export class QueryGroup extends PureComponent<Props, State> {
|
export class QueryGroup extends PureComponent<Props, State> {
|
||||||
@ -78,11 +72,6 @@ export class QueryGroup extends PureComponent<Props, State> {
|
|||||||
isAddingMixed: false,
|
isAddingMixed: false,
|
||||||
isHelpOpen: false,
|
isHelpOpen: false,
|
||||||
queries: [],
|
queries: [],
|
||||||
savedQueryUid: null,
|
|
||||||
initialState: {
|
|
||||||
queries: [],
|
|
||||||
savedQueryUid: null,
|
|
||||||
},
|
|
||||||
data: {
|
data: {
|
||||||
state: LoadingState.NotStarted,
|
state: LoadingState.NotStarted,
|
||||||
series: [],
|
series: [],
|
||||||
@ -113,12 +102,6 @@ export class QueryGroup extends PureComponent<Props, State> {
|
|||||||
dataSource: ds,
|
dataSource: ds,
|
||||||
dsSettings,
|
dsSettings,
|
||||||
defaultDataSource,
|
defaultDataSource,
|
||||||
savedQueryUid: options.savedQueryUid,
|
|
||||||
initialState: {
|
|
||||||
queries: options.queries.map((q) => ({ ...q })),
|
|
||||||
dataSource: { ...options.dataSource },
|
|
||||||
savedQueryUid: options.savedQueryUid,
|
|
||||||
},
|
|
||||||
// TODO: Detect the first panel added into a new dashboard better.
|
// TODO: Detect the first panel added into a new dashboard better.
|
||||||
// This is flaky in case the UID is generated differently
|
// This is flaky in case the UID is generated differently
|
||||||
isDataSourceModalOpen:
|
isDataSourceModalOpen:
|
||||||
@ -152,7 +135,6 @@ export class QueryGroup extends PureComponent<Props, State> {
|
|||||||
const dataSource = await this.dataSourceSrv.get(newSettings.name);
|
const dataSource = await this.dataSourceSrv.get(newSettings.name);
|
||||||
this.onChange({
|
this.onChange({
|
||||||
queries,
|
queries,
|
||||||
savedQueryUid: null,
|
|
||||||
dataSource: {
|
dataSource: {
|
||||||
name: newSettings.name,
|
name: newSettings.name,
|
||||||
uid: newSettings.uid,
|
uid: newSettings.uid,
|
||||||
@ -163,7 +145,6 @@ export class QueryGroup extends PureComponent<Props, State> {
|
|||||||
|
|
||||||
this.setState({
|
this.setState({
|
||||||
queries,
|
queries,
|
||||||
savedQueryUid: null,
|
|
||||||
dataSource: dataSource,
|
dataSource: dataSource,
|
||||||
dsSettings: newSettings,
|
dsSettings: newSettings,
|
||||||
});
|
});
|
||||||
|
@ -1,116 +0,0 @@
|
|||||||
// Libraries
|
|
||||||
import React, { useMemo } from 'react';
|
|
||||||
// Components
|
|
||||||
import { useAsync } from 'react-use';
|
|
||||||
import { AsyncState } from 'react-use/lib/useAsyncFn';
|
|
||||||
|
|
||||||
import { DataSourceInstanceSettings, isUnsignedPluginSignature, SelectableValue } from '@grafana/data';
|
|
||||||
import { selectors } from '@grafana/e2e-selectors';
|
|
||||||
import { getDataSourceSrv } from '@grafana/runtime/src';
|
|
||||||
import { HorizontalGroup, PluginSignatureBadge, Select } from '@grafana/ui';
|
|
||||||
|
|
||||||
import { getGrafanaSearcher, QueryResponse, SearchQuery } from '../../search/service';
|
|
||||||
|
|
||||||
export type SavedQueryPickerProps = {
|
|
||||||
onChange: (savedQueryUid: string | null) => void;
|
|
||||||
current?: string | null; // type
|
|
||||||
hideTextValue?: boolean;
|
|
||||||
onBlur?: () => void;
|
|
||||||
autoFocus?: boolean;
|
|
||||||
openMenuOnFocus?: boolean;
|
|
||||||
placeholder?: string;
|
|
||||||
tracing?: boolean;
|
|
||||||
mixed?: boolean;
|
|
||||||
dashboard?: boolean;
|
|
||||||
metrics?: boolean;
|
|
||||||
type?: string | string[];
|
|
||||||
annotations?: boolean;
|
|
||||||
variables?: boolean;
|
|
||||||
alerting?: boolean;
|
|
||||||
pluginId?: string;
|
|
||||||
/** If true,we show only DSs with logs; and if true, pluginId shouldnt be passed in */
|
|
||||||
logs?: boolean;
|
|
||||||
width?: number;
|
|
||||||
inputId?: string;
|
|
||||||
filter?: (dataSource: DataSourceInstanceSettings) => boolean;
|
|
||||||
onClear?: () => void;
|
|
||||||
};
|
|
||||||
|
|
||||||
function getSavedQueryPickerOptions(results: AsyncState<QueryResponse>): Array<SelectableValue<string>> {
|
|
||||||
if (results?.loading) {
|
|
||||||
return [];
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!results?.value?.totalRows) {
|
|
||||||
return [];
|
|
||||||
}
|
|
||||||
|
|
||||||
const hits = results.value.view.toArray();
|
|
||||||
|
|
||||||
return hits.map((h) => {
|
|
||||||
const dsSettings = h.ds_uid?.length ? getDataSourceSrv().getInstanceSettings(h.ds_uid[0]) : undefined;
|
|
||||||
|
|
||||||
return {
|
|
||||||
value: h.uid,
|
|
||||||
label: h.name,
|
|
||||||
imgUrl: dsSettings?.meta.info.logos.small,
|
|
||||||
meta: dsSettings?.meta,
|
|
||||||
};
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
export const SavedQueryPicker = (props: SavedQueryPickerProps) => {
|
|
||||||
const { autoFocus, onBlur, onChange, current, openMenuOnFocus, placeholder, width, inputId } = props;
|
|
||||||
|
|
||||||
const searchQuery = useMemo<SearchQuery>(() => {
|
|
||||||
// TODO: ensure we fetch all saved queries?
|
|
||||||
const query: SearchQuery = {
|
|
||||||
query: '*',
|
|
||||||
explain: true,
|
|
||||||
kind: ['query'],
|
|
||||||
};
|
|
||||||
|
|
||||||
return query;
|
|
||||||
}, []);
|
|
||||||
|
|
||||||
const results = useAsync(async () => {
|
|
||||||
return getGrafanaSearcher().search(searchQuery);
|
|
||||||
}, [searchQuery]);
|
|
||||||
|
|
||||||
const options = getSavedQueryPickerOptions(results);
|
|
||||||
|
|
||||||
return (
|
|
||||||
<div aria-label={selectors.components.DataSourcePicker.container}>
|
|
||||||
<Select
|
|
||||||
aria-label={selectors.components.DataSourcePicker.inputV2}
|
|
||||||
inputId={inputId || 'data-source-picker'}
|
|
||||||
className="ds-picker select-container"
|
|
||||||
isMulti={false}
|
|
||||||
isClearable={true}
|
|
||||||
backspaceRemovesValue={true}
|
|
||||||
options={options}
|
|
||||||
autoFocus={autoFocus}
|
|
||||||
onBlur={onBlur}
|
|
||||||
width={width}
|
|
||||||
value={current}
|
|
||||||
onChange={(newValue) => {
|
|
||||||
onChange(newValue?.value ?? null);
|
|
||||||
}}
|
|
||||||
openMenuOnFocus={openMenuOnFocus}
|
|
||||||
maxMenuHeight={500}
|
|
||||||
placeholder={placeholder ?? 'Select query from the library'}
|
|
||||||
noOptionsMessage="No queries found"
|
|
||||||
getOptionLabel={(o) => {
|
|
||||||
if (o.meta && isUnsignedPluginSignature(o.meta.signature)) {
|
|
||||||
return (
|
|
||||||
<HorizontalGroup align="center" justify="space-between">
|
|
||||||
<span>{o.label}</span> <PluginSignatureBadge status={o.meta.signature} />
|
|
||||||
</HorizontalGroup>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
return o.label || '';
|
|
||||||
}}
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
};
|
|
@ -143,7 +143,6 @@ export function getDefaultState(): State {
|
|||||||
name: 'gdev-testdata',
|
name: 'gdev-testdata',
|
||||||
},
|
},
|
||||||
maxDataPoints: 100,
|
maxDataPoints: 100,
|
||||||
savedQueryUid: null,
|
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -3,7 +3,6 @@ import { DataQuery, DataSourceRef } from '@grafana/data';
|
|||||||
export interface QueryGroupOptions {
|
export interface QueryGroupOptions {
|
||||||
queries: DataQuery[];
|
queries: DataQuery[];
|
||||||
dataSource: QueryGroupDataSource;
|
dataSource: QueryGroupDataSource;
|
||||||
savedQueryUid?: string | null;
|
|
||||||
maxDataPoints?: number | null;
|
maxDataPoints?: number | null;
|
||||||
minInterval?: string | null;
|
minInterval?: string | null;
|
||||||
cacheTimeout?: string | null;
|
cacheTimeout?: string | null;
|
||||||
|
Loading…
Reference in New Issue
Block a user