mirror of
https://github.com/grafana/grafana.git
synced 2025-09-22 04:32:55 +08:00

* Chore: initial commit * Tests: fixes MetricsQueryEditor.test.tsx * Tests: fixes cloudwatch/specs/datasource.test.ts * Tests: fixes stackdriver/specs/datasource.test.ts * Tests: remove refrences to CustomVariable * Refactor: moves DefaultVariableQueryEditor * Refactor: moves utils * Refactor: moves types * Refactor: removes variableSrv * Refactor: removes feature toggle newVariables * Refactor: removes valueSelectDropDown * Chore: removes GeneralTabCtrl * Chore: migrates RowOptions * Refactor: adds RowOptionsButton * Refactor: makes the interface more explicit * Refactor: small changes * Refactor: changed type as it can be any variable type * Tests: fixes broken test * Refactor: changes after PR comments * Refactor: adds loading state and call to onChange in componentDidMount
41 lines
1.1 KiB
TypeScript
41 lines
1.1 KiB
TypeScript
import React, { FC, useCallback, useMemo } from 'react';
|
|
import { useSelector } from 'react-redux';
|
|
import { Select } from '@grafana/ui';
|
|
import { SelectableValue } from '@grafana/data';
|
|
|
|
import { getVariables } from '../../../variables/state/selectors';
|
|
import { StoreState } from '../../../../types';
|
|
|
|
export interface Props {
|
|
repeat: string | undefined;
|
|
onChange: (name: string) => void;
|
|
}
|
|
|
|
export const RepeatRowSelect: FC<Props> = ({ repeat, onChange }) => {
|
|
const variables = useSelector((state: StoreState) => getVariables(state));
|
|
|
|
const variableOptions = useMemo(() => {
|
|
const options = variables.map((item: any) => {
|
|
return { label: item.name, value: item.name };
|
|
});
|
|
|
|
if (options.length === 0) {
|
|
options.unshift({
|
|
label: 'No template variables found',
|
|
value: null,
|
|
});
|
|
}
|
|
|
|
options.unshift({
|
|
label: 'Disable repeating',
|
|
value: null,
|
|
});
|
|
|
|
return options;
|
|
}, variables);
|
|
|
|
const onSelectChange = useCallback((option: SelectableValue<string | null>) => onChange(option.value), [onChange]);
|
|
|
|
return <Select value={repeat} onChange={onSelectChange} options={variableOptions} />;
|
|
};
|