QueryVariableRefreshSelect.tsx 1.1 KB

123456789101112131415161718192021222324252627282930313233
  1. import React, { PropsWithChildren, useMemo } from 'react';
  2. import { SelectableValue } from '@grafana/data';
  3. import { selectors } from '@grafana/e2e-selectors';
  4. import { VariableSelectField } from '../editor/VariableSelectField';
  5. import { VariableRefresh } from '../types';
  6. interface Props {
  7. onChange: (option: SelectableValue<VariableRefresh>) => void;
  8. refresh: VariableRefresh;
  9. }
  10. const REFRESH_OPTIONS = [
  11. { label: 'On dashboard load', value: VariableRefresh.onDashboardLoad },
  12. { label: 'On time range change', value: VariableRefresh.onTimeRangeChanged },
  13. ];
  14. export function QueryVariableRefreshSelect({ onChange, refresh }: PropsWithChildren<Props>) {
  15. const value = useMemo(() => REFRESH_OPTIONS.find((o) => o.value === refresh) ?? REFRESH_OPTIONS[0], [refresh]);
  16. return (
  17. <VariableSelectField
  18. name="Refresh"
  19. value={value}
  20. options={REFRESH_OPTIONS}
  21. onChange={onChange}
  22. labelWidth={10}
  23. testId={selectors.pages.Dashboard.Settings.Variables.Edit.QueryVariable.queryOptionsRefreshSelectV2}
  24. tooltip="When to update the values of this variable."
  25. />
  26. );
  27. }