mirror of
https://github.com/grafana/grafana.git
synced 2025-01-17 04:02:50 -06:00
04d857dfe6
* Variables: Adds description field * Refactor: Adds new Form components * Refactor: Fixes aria labels * Refactor: removes skipped tests * Refactor: Breaks out smaller select components * Refactor: removes gf-form div * Refactor: Breaks up several more selects into smaller components * Chore: Fixes typings
29 lines
1.0 KiB
TypeScript
29 lines
1.0 KiB
TypeScript
import React, { PropsWithChildren, useMemo } from 'react';
|
|
import { DataSourceSelectItem, SelectableValue } from '@grafana/data';
|
|
import { selectors } from '@grafana/e2e-selectors';
|
|
import { VariableSelectField } from '../editor/VariableSelectField';
|
|
|
|
interface Props {
|
|
onChange: (option: SelectableValue<string>) => void;
|
|
datasource: string | null;
|
|
dataSources?: DataSourceSelectItem[];
|
|
}
|
|
|
|
export function QueryVariableDatasourceSelect({ onChange, datasource, dataSources }: PropsWithChildren<Props>) {
|
|
const options = useMemo(() => {
|
|
return dataSources ? dataSources.map(ds => ({ label: ds.name, value: ds.value ?? '' })) : [];
|
|
}, [dataSources]);
|
|
const value = useMemo(() => options.find(o => o.value === datasource) ?? options[0], [options, datasource]);
|
|
|
|
return (
|
|
<VariableSelectField
|
|
name="Data source"
|
|
value={value}
|
|
options={options}
|
|
onChange={onChange}
|
|
labelWidth={10}
|
|
ariaLabel={selectors.pages.Dashboard.Settings.Variables.Edit.QueryVariable.queryOptionsDataSourceSelect}
|
|
/>
|
|
);
|
|
}
|