mirror of
https://github.com/grafana/grafana.git
synced 2025-09-18 07:53:02 +08:00

* add new option for multi variables to lock value list wip * WIP - lock option list * tests * fix * fixes + canary scenes * wip * wip * fix snapshot * bump scenes * Dashboards: Add possibility to lock adhoc variables options list (#96077) * Lock list of options flag for ad hoc * refactor * fix snapshot
66 lines
2.4 KiB
TypeScript
66 lines
2.4 KiB
TypeScript
import { ChangeEvent, FormEvent } from 'react';
|
|
|
|
import { selectors } from '@grafana/e2e-selectors';
|
|
import { Stack } from '@grafana/ui';
|
|
import { VariableCheckboxField } from 'app/features/dashboard-scene/settings/variables/components/VariableCheckboxField';
|
|
import { VariableTextField } from 'app/features/dashboard-scene/settings/variables/components/VariableTextField';
|
|
|
|
interface SelectionOptionsFormProps {
|
|
multi: boolean;
|
|
includeAll: boolean;
|
|
allowCustomValue?: boolean;
|
|
allValue?: string | null;
|
|
onMultiChange: (event: ChangeEvent<HTMLInputElement>) => void;
|
|
onAllowCustomValueChange?: (event: ChangeEvent<HTMLInputElement>) => void;
|
|
onIncludeAllChange: (event: ChangeEvent<HTMLInputElement>) => void;
|
|
onAllValueChange: (event: FormEvent<HTMLInputElement>) => void;
|
|
}
|
|
|
|
export function SelectionOptionsForm({
|
|
multi,
|
|
allowCustomValue,
|
|
includeAll,
|
|
allValue,
|
|
onMultiChange,
|
|
onAllowCustomValueChange,
|
|
onIncludeAllChange,
|
|
onAllValueChange,
|
|
}: SelectionOptionsFormProps) {
|
|
return (
|
|
<Stack direction="column" gap={2} height="inherit" alignItems="start">
|
|
<VariableCheckboxField
|
|
value={multi}
|
|
name="Multi-value"
|
|
description="Enables multiple values to be selected at the same time"
|
|
onChange={onMultiChange}
|
|
testId={selectors.pages.Dashboard.Settings.Variables.Edit.General.selectionOptionsMultiSwitch}
|
|
/>
|
|
{onAllowCustomValueChange && ( // backwards compat with old arch, remove on cleanup
|
|
<VariableCheckboxField
|
|
value={allowCustomValue ?? true}
|
|
name="Allow custom values"
|
|
description="Enables users to add custom values to the list"
|
|
onChange={onAllowCustomValueChange}
|
|
testId={selectors.pages.Dashboard.Settings.Variables.Edit.General.selectionOptionsAllowCustomValueSwitch}
|
|
/>
|
|
)}
|
|
<VariableCheckboxField
|
|
value={includeAll}
|
|
name="Include All option"
|
|
description="Enables an option to include all variables"
|
|
onChange={onIncludeAllChange}
|
|
testId={selectors.pages.Dashboard.Settings.Variables.Edit.General.selectionOptionsIncludeAllSwitch}
|
|
/>
|
|
{includeAll && (
|
|
<VariableTextField
|
|
defaultValue={allValue ?? ''}
|
|
onBlur={onAllValueChange}
|
|
name="Custom all value"
|
|
placeholder="blank = auto"
|
|
testId={selectors.pages.Dashboard.Settings.Variables.Edit.General.selectionOptionsCustomAllInput}
|
|
/>
|
|
)}
|
|
</Stack>
|
|
);
|
|
}
|