From 9447015e546a7ab3fec1ceb5c16bcca6c5fc56af Mon Sep 17 00:00:00 2001 From: grafakus Date: Wed, 26 Nov 2025 19:51:00 +0100 Subject: [PATCH] Remove temp switch in QueryVariableEditor - rely on options instead to determine if the variable has multi props --- .../components/QueryVariableForm.tsx | 47 ++++++------------- .../variables/editors/QueryVariableEditor.tsx | 18 ++++++- 2 files changed, 31 insertions(+), 34 deletions(-) diff --git a/public/app/features/dashboard-scene/settings/variables/components/QueryVariableForm.tsx b/public/app/features/dashboard-scene/settings/variables/components/QueryVariableForm.tsx index d83d3f95f77..e519ec8c181 100644 --- a/public/app/features/dashboard-scene/settings/variables/components/QueryVariableForm.tsx +++ b/public/app/features/dashboard-scene/settings/variables/components/QueryVariableForm.tsx @@ -1,4 +1,4 @@ -import { FormEvent, useState } from 'react'; +import { FormEvent } from 'react'; import { useAsync } from 'react-use'; import { DataSourceInstanceSettings, SelectableValue, TimeRange } from '@grafana/data'; @@ -7,7 +7,7 @@ import { Trans, t } from '@grafana/i18n'; import { getDataSourceSrv } from '@grafana/runtime'; import { QueryVariable } from '@grafana/scenes'; import { DataSourceRef, VariableRefresh, VariableSort } from '@grafana/schema'; -import { Box, Field, Switch, TextLink } from '@grafana/ui'; +import { Box, Field, TextLink } from '@grafana/ui'; import { QueryEditor } from 'app/features/dashboard-scene/settings/variables/components/QueryEditor'; import { SelectionOptionsForm } from 'app/features/dashboard-scene/settings/variables/components/SelectionOptionsForm'; import { DataSourcePicker } from 'app/features/datasources/components/picker/DataSourcePicker'; @@ -34,6 +34,7 @@ interface QueryVariableEditorFormProps { timeRange: TimeRange; regex: string | null; onRegExChange: (event: FormEvent) => void; + disableRegexEdition?: boolean; sort: VariableSort; onSortChange: (option: SelectableValue) => void; refresh: VariableRefresh; @@ -42,14 +43,17 @@ interface QueryVariableEditorFormProps { onMultiChange: (event: FormEvent) => void; allowCustomValue?: boolean; onAllowCustomValueChange?: (event: FormEvent) => void; + disableAllowCustomValue?: boolean; includeAll: boolean; onIncludeAllChange: (event: FormEvent) => void; allValue: string; onAllValueChange: (event: FormEvent) => void; + disableCustomAllValue?: boolean; staticOptions?: StaticOptionsType; staticOptionsOrder?: StaticOptionsOrderType; onStaticOptionsChange?: (staticOptions: StaticOptionsType) => void; onStaticOptionsOrderChange?: (staticOptionsOrder: StaticOptionsOrderType) => void; + disableStaticOptions?: boolean; } export function QueryVariableEditorForm({ @@ -61,6 +65,7 @@ export function QueryVariableEditorForm({ timeRange, regex, onRegExChange, + disableRegexEdition, sort, onSortChange, refresh, @@ -69,14 +74,17 @@ export function QueryVariableEditorForm({ onMultiChange, allowCustomValue, onAllowCustomValueChange, + disableAllowCustomValue, includeAll, onIncludeAllChange, allValue, onAllValueChange, + disableCustomAllValue, staticOptions, staticOptionsOrder, onStaticOptionsChange, onStaticOptionsOrderChange, + disableStaticOptions, }: QueryVariableEditorFormProps) { const { value: dsConfig } = useAsync(async () => { const datasource = await getDataSourceSrv().get(datasourceRef ?? ''); @@ -102,16 +110,6 @@ export function QueryVariableEditorForm({ const { datasource, VariableQueryEditor } = dsConfig ?? {}; - // TODO: remove me after finished testing - each DS can/should implement their own UI - const [returnsMultiProps, setReturnsMultiProps] = useState(false); - const onChangeReturnsMultipleProps = (e: FormEvent) => { - setReturnsMultiProps(e.currentTarget.checked); - onAllowCustomValueChange?.({ currentTarget: { checked: false } }); - onAllValueChange({ currentTarget: { value: '' } }); - onRegExChange({ currentTarget: { value: '' } }); - onStaticOptionsChange?.([]); - }; - return ( <> @@ -135,27 +133,10 @@ export function QueryVariableEditorForm({ VariableQueryEditor={VariableQueryEditor} timeRange={timeRange} /> - {/* TODO: remove me after finished testing - each DS can/should implement their own UI */} - - Check{' '} - - our docs - {' '} - for more information. - - } - noMargin - > - - )} - {!returnsMultiProps && ( + {!disableRegexEdition && ( - {!returnsMultiProps && onStaticOptionsChange && onStaticOptionsOrderChange && ( + {!disableStaticOptions && onStaticOptionsChange && onStaticOptionsOrderChange && ( options.every((o) => Boolean(o.properties)), [options]); + + useEffect(() => { + if (hasMultiProps) { + variable.setState({ allowCustomValue: false }); + variable.setState({ allValue: '' }); + variable.setState({ regex: '' }); + variable.setState({ staticOptions: [] }); + } + }, [hasMultiProps, variable]); + return ( ); }