From aa13249b4245b84f18c1a3c196079a9e2b66fd56 Mon Sep 17 00:00:00 2001 From: Bogdan Matei Date: Tue, 9 Sep 2025 19:21:59 +0300 Subject: [PATCH] Dashboard: Improve static options editors on variables --- eslint-suppressions.json | 5 - .../src/selectors/pages.ts | 6 + .../components/CustomVariableForm.tsx | 47 +------ .../components/VariableOptionsInput.tsx | 106 --------------- .../components/VariableStaticOptionsForm.tsx | 113 ++++++++++++++++ .../VariableStaticOptionsFormItemEditor.tsx | 103 ++++++++++++++ .../VariableStaticOptionsFormItems.tsx | 78 +++++++++++ .../editors/CustomVariableEditor.tsx | 126 +++++++++++++++++- .../variables/editors/QueryVariableEditor.tsx | 32 ++++- .../query/QueryVariableStaticOptions.tsx | 9 +- public/locales/en-US/grafana.json | 11 +- 11 files changed, 469 insertions(+), 167 deletions(-) delete mode 100644 public/app/features/dashboard-scene/settings/variables/components/VariableOptionsInput.tsx create mode 100644 public/app/features/dashboard-scene/settings/variables/components/VariableStaticOptionsForm.tsx create mode 100644 public/app/features/dashboard-scene/settings/variables/components/VariableStaticOptionsFormItemEditor.tsx create mode 100644 public/app/features/dashboard-scene/settings/variables/components/VariableStaticOptionsFormItems.tsx diff --git a/eslint-suppressions.json b/eslint-suppressions.json index 2612b2c0400..42fc0d8cac8 100644 --- a/eslint-suppressions.json +++ b/eslint-suppressions.json @@ -2194,11 +2194,6 @@ "count": 1 } }, - "public/app/features/dashboard-scene/settings/variables/editors/QueryVariableEditor.tsx": { - "no-restricted-syntax": { - "count": 1 - } - }, "public/app/features/dashboard-scene/settings/variables/utils.ts": { "@typescript-eslint/consistent-type-assertions": { "count": 1 diff --git a/packages/grafana-e2e-selectors/src/selectors/pages.ts b/packages/grafana-e2e-selectors/src/selectors/pages.ts index 581a8294d10..9b8574f1b73 100644 --- a/packages/grafana-e2e-selectors/src/selectors/pages.ts +++ b/packages/grafana-e2e-selectors/src/selectors/pages.ts @@ -559,6 +559,12 @@ export const versionedPages = { customValueInput: { [MIN_GRAFANA_VERSION]: 'data-testid custom-variable-input', }, + optionsOpenButton: { + [MIN_GRAFANA_VERSION]: 'data-testid custom-variable-options-open-button', + }, + closeButton: { + [MIN_GRAFANA_VERSION]: 'data-testid custom-variable-close-button', + }, }, IntervalVariable: { intervalsValueInput: { diff --git a/public/app/features/dashboard-scene/settings/variables/components/CustomVariableForm.tsx b/public/app/features/dashboard-scene/settings/variables/components/CustomVariableForm.tsx index f11037fb80c..b3c78330156 100644 --- a/public/app/features/dashboard-scene/settings/variables/components/CustomVariableForm.tsx +++ b/public/app/features/dashboard-scene/settings/variables/components/CustomVariableForm.tsx @@ -1,16 +1,11 @@ import { FormEvent } from 'react'; -import { lastValueFrom } from 'rxjs'; import { selectors } from '@grafana/e2e-selectors'; import { Trans, t } from '@grafana/i18n'; -import { CustomVariable, SceneVariable } from '@grafana/scenes'; -import { TextArea } from '@grafana/ui'; -import { OptionsPaneItemDescriptor } from 'app/features/dashboard/components/PanelEditor/OptionsPaneItemDescriptor'; - -import { VariableLegend } from '../components/VariableLegend'; -import { VariableTextAreaField } from '../components/VariableTextAreaField'; import { SelectionOptionsForm } from './SelectionOptionsForm'; +import { VariableLegend } from './VariableLegend'; +import { VariableTextAreaField } from './VariableTextAreaField'; interface CustomVariableFormProps { query: string; @@ -71,41 +66,3 @@ export function CustomVariableForm({ ); } - -export function getCustomVariableOptions(variable: SceneVariable): OptionsPaneItemDescriptor[] { - if (!(variable instanceof CustomVariable)) { - return []; - } - - return [ - new OptionsPaneItemDescriptor({ - title: t('dashboard.edit-pane.variable.custom-options.values', 'Values separated by comma'), - id: 'custom-variable-values', - render: (descriptor) => , - }), - ]; -} - -function ValuesTextField({ variable, id }: { variable: CustomVariable; id?: string }) { - const { query } = variable.useState(); - - const onBlur = async (event: FormEvent) => { - variable.setState({ query: event.currentTarget.value }); - await lastValueFrom(variable.validateAndUpdate!()); - }; - - return ( -