VariableHideSelect.tsx 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. import React, { PropsWithChildren, useMemo } from 'react';
  2. import { SelectableValue, VariableType } from '@grafana/data';
  3. import { selectors } from '@grafana/e2e-selectors';
  4. import { VariableSelectField } from '../editor/VariableSelectField';
  5. import { VariableHide } from '../types';
  6. interface Props {
  7. onChange: (option: SelectableValue<VariableHide>) => void;
  8. hide: VariableHide;
  9. type: VariableType;
  10. }
  11. const HIDE_OPTIONS = [
  12. { label: '', value: VariableHide.dontHide },
  13. { label: 'Label', value: VariableHide.hideLabel },
  14. { label: 'Variable', value: VariableHide.hideVariable },
  15. ];
  16. export function VariableHideSelect({ onChange, hide, type }: PropsWithChildren<Props>) {
  17. const value = useMemo(() => HIDE_OPTIONS.find((o) => o.value === hide) ?? HIDE_OPTIONS[0], [hide]);
  18. if (type === 'constant') {
  19. return null;
  20. }
  21. return (
  22. <VariableSelectField
  23. name="Hide"
  24. value={value}
  25. options={HIDE_OPTIONS}
  26. onChange={onChange}
  27. testId={selectors.pages.Dashboard.Settings.Variables.Edit.General.generalHideSelectV2}
  28. />
  29. );
  30. }