2020-11-25 03:21:48 -06:00
|
|
|
import React, { PropsWithChildren, useMemo } from 'react';
|
2022-04-22 08:33:13 -05:00
|
|
|
|
2020-11-25 03:21:48 -06:00
|
|
|
import { SelectableValue } from '@grafana/data';
|
|
|
|
import { selectors } from '@grafana/e2e-selectors';
|
2022-04-22 08:33:13 -05:00
|
|
|
|
2020-11-25 03:21:48 -06:00
|
|
|
import { VariableSelectField } from '../editor/VariableSelectField';
|
|
|
|
import { VariableRefresh } from '../types';
|
|
|
|
|
|
|
|
interface Props {
|
|
|
|
onChange: (option: SelectableValue<VariableRefresh>) => void;
|
|
|
|
refresh: VariableRefresh;
|
|
|
|
}
|
|
|
|
|
|
|
|
const REFRESH_OPTIONS = [
|
2021-04-01 11:17:39 -05:00
|
|
|
{ label: 'On dashboard load', value: VariableRefresh.onDashboardLoad },
|
|
|
|
{ label: 'On time range change', value: VariableRefresh.onTimeRangeChanged },
|
2020-11-25 03:21:48 -06:00
|
|
|
];
|
|
|
|
|
|
|
|
export function QueryVariableRefreshSelect({ onChange, refresh }: PropsWithChildren<Props>) {
|
2021-01-20 00:59:48 -06:00
|
|
|
const value = useMemo(() => REFRESH_OPTIONS.find((o) => o.value === refresh) ?? REFRESH_OPTIONS[0], [refresh]);
|
2020-11-25 03:21:48 -06:00
|
|
|
|
|
|
|
return (
|
|
|
|
<VariableSelectField
|
|
|
|
name="Refresh"
|
|
|
|
value={value}
|
|
|
|
options={REFRESH_OPTIONS}
|
|
|
|
onChange={onChange}
|
|
|
|
labelWidth={10}
|
2022-02-03 18:55:19 -06:00
|
|
|
testId={selectors.pages.Dashboard.Settings.Variables.Edit.QueryVariable.queryOptionsRefreshSelectV2}
|
2020-11-25 03:21:48 -06:00
|
|
|
tooltip="When to update the values of this variable."
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
}
|