mirror of
https://github.com/grafana/grafana.git
synced 2025-01-17 04:02:50 -06:00
04d857dfe6
* Variables: Adds description field * Refactor: Adds new Form components * Refactor: Fixes aria labels * Refactor: removes skipped tests * Refactor: Breaks out smaller select components * Refactor: removes gf-form div * Refactor: Breaks up several more selects into smaller components * Chore: Fixes typings
33 lines
1.1 KiB
TypeScript
33 lines
1.1 KiB
TypeScript
import React, { PropsWithChildren, useMemo } from 'react';
|
|
import { SelectableValue } from '@grafana/data';
|
|
import { selectors } from '@grafana/e2e-selectors';
|
|
import { VariableSelectField } from '../editor/VariableSelectField';
|
|
import { VariableRefresh } from '../types';
|
|
|
|
interface Props {
|
|
onChange: (option: SelectableValue<VariableRefresh>) => void;
|
|
refresh: VariableRefresh;
|
|
}
|
|
|
|
const REFRESH_OPTIONS = [
|
|
{ label: 'Never', value: VariableRefresh.never },
|
|
{ label: 'On Dashboard Load', value: VariableRefresh.onDashboardLoad },
|
|
{ label: 'On Time Range Change', value: VariableRefresh.onTimeRangeChanged },
|
|
];
|
|
|
|
export function QueryVariableRefreshSelect({ onChange, refresh }: PropsWithChildren<Props>) {
|
|
const value = useMemo(() => REFRESH_OPTIONS.find(o => o.value === refresh) ?? REFRESH_OPTIONS[0], [refresh]);
|
|
|
|
return (
|
|
<VariableSelectField
|
|
name="Refresh"
|
|
value={value}
|
|
options={REFRESH_OPTIONS}
|
|
onChange={onChange}
|
|
labelWidth={10}
|
|
ariaLabel={selectors.pages.Dashboard.Settings.Variables.Edit.QueryVariable.queryOptionsRefreshSelect}
|
|
tooltip="When to update the values of this variable."
|
|
/>
|
|
);
|
|
}
|