import React, { useState } from 'react'; import { css } from 'emotion'; import { Button, FormField, DataLinkInput, stylesFactory, LegacyForms } from '@grafana/ui'; const { Switch } = LegacyForms; import { VariableSuggestion } from '@grafana/data'; import { DataSourceSelectItem } from '@grafana/data'; import { DerivedFieldConfig } from '../types'; import DataSourcePicker from 'app/core/components/Select/DataSourcePicker'; import { getDatasourceSrv } from 'app/features/plugins/datasource_srv'; import { config } from 'app/core/config'; const getStyles = stylesFactory(() => ({ row: css` display: flex; align-items: baseline; `, nameField: css` flex: 2; `, regexField: css` flex: 3; `, })); type Props = { value: DerivedFieldConfig; onChange: (value: DerivedFieldConfig) => void; onDelete: () => void; suggestions: VariableSuggestion[]; className?: string; }; export const DerivedField = (props: Props) => { const { value, onChange, onDelete, suggestions, className } = props; const styles = getStyles(); const [hasIntenalLink, setHasInternalLink] = useState(!!value.datasourceName); const handleChange = (field: keyof typeof value) => (event: React.ChangeEvent) => { onChange({ ...value, [field]: event.currentTarget.value, }); }; return (
onChange({ ...value, url: newValue, }) } suggestions={suggestions} /> } className={css` width: 100%; `} /> {config.featureToggles.tracingIntegration && (
{ if (hasIntenalLink) { onChange({ ...value, datasourceName: undefined, }); } setHasInternalLink(!hasIntenalLink); }} /> {hasIntenalLink && ( { onChange({ ...value, datasourceName, }); }} datasourceName={value.datasourceName} /> )}
)}
); }; type DataSourceSectionProps = { datasourceName?: string; onChange: (name: string) => void; }; const DataSourceSection = (props: DataSourceSectionProps) => { const { datasourceName, onChange } = props; const datasources: DataSourceSelectItem[] = getDatasourceSrv() .getExternal() .map( (ds: any) => ({ value: ds.name, name: ds.name, meta: ds.meta, } as DataSourceSelectItem) ); const selectedDatasource = datasourceName && datasources.find(d => d.name === datasourceName); return ( { onChange(newValue.name); }} datasources={datasources} current={selectedDatasource} /> ); };