QueryGroup & DataSourceSrv & DataSourcePicker changes simplify usage, error handling and reduce duplication, support for uid (#29542)

* Starting moving more stuff into data source picker

* WIP progress

* Progress on datasource picker rethink

* Things are working now some details to figure out

* Removed commented part

* Complex work on getting data source lists

* Fixed variable support showing correct data sources

* Tried fixing dashboard import but failed

* Fixes

* Fixed import dashboard

* Fixed unit test

* Fixed explore test

* Fixed test

* Fix

* fixed more tests

* fixed more tests

* fixed showing which option is default in picker

* Changed query variable to use data source picker, updated tests and e2e

* Fixed more tests

* Updated snapshots, had wrong typescript version
This commit is contained in:
Torkel Ödegaard
2020-12-04 14:24:55 +01:00
committed by GitHub
parent c62a0aa4d0
commit 3d6380a0aa
45 changed files with 707 additions and 807 deletions

View File

@@ -1,12 +1,11 @@
import React, { Dispatch, SetStateAction, useEffect, useState } from 'react';
import { css } from 'emotion';
import { DataSourceSelectItem, VariableSuggestion } from '@grafana/data';
import { VariableSuggestion } from '@grafana/data';
import { Button, LegacyForms, DataLinkInput, stylesFactory } from '@grafana/ui';
const { FormField, Switch } = LegacyForms;
import { DataLinkConfig } from '../types';
import { usePrevious } from 'react-use';
import { getDatasourceSrv } from '../../../../features/plugins/datasource_srv';
import DataSourcePicker from '../../../../core/components/Select/DataSourcePicker';
import { DataSourcePicker } from '../../../../core/components/Select/DataSourcePicker';
const getStyles = stylesFactory(() => ({
firstRow: css`
@@ -107,14 +106,16 @@ export const DataLink = (props: Props) => {
/>
{showInternalLink && (
<DataSourceSection
onChange={datasourceUid => {
<DataSourcePicker
tracing={true}
// Uid and value should be always set in the db and so in the items.
onChange={ds => {
onChange({
...value,
datasourceUid,
datasourceUid: ds.uid,
});
}}
datasourceUid={value.datasourceUid}
current={value.datasourceUid}
/>
)}
</div>
@@ -122,37 +123,6 @@ export const DataLink = (props: Props) => {
);
};
type DataSourceSectionProps = {
datasourceUid?: string;
onChange: (uid: string) => void;
};
const DataSourceSection = (props: DataSourceSectionProps) => {
const { datasourceUid, onChange } = props;
const datasources: DataSourceSelectItem[] = getDatasourceSrv()
.getExternal()
// At this moment only Jaeger and Zipkin datasource is supported as the link target.
.filter(ds => ds.meta.tracing)
.map(
ds =>
({
value: ds.uid,
name: ds.name,
meta: ds.meta,
} as DataSourceSelectItem)
);
let selectedDatasource = datasourceUid && datasources.find(d => d.value === datasourceUid);
return (
<DataSourcePicker
// Uid and value should be always set in the db and so in the items.
onChange={ds => onChange(ds.value!)}
datasources={datasources}
current={selectedDatasource || undefined}
/>
);
};
function useInternalLink(datasourceUid?: string): [boolean, Dispatch<SetStateAction<boolean>>] {
const [showInternalLink, setShowInternalLink] = useState<boolean>(!!datasourceUid);
const previousUid = usePrevious(datasourceUid);