Files
grafana/public/app/plugins/datasource/cloud-monitoring/components/LookbackPeriodSelect.tsx
Zoltán Bedi c0b778134e Revert: Query editor components from grafana-ui (#57436)
* Revert: QueryEditor components from grafana-ui

* Use local version of experimental

* Use experimental for query editor components

* Fix type issues in MSSQL

* point to actual version of experimental package

* point to latest version of experimental

Co-authored-by: Erik Sundell <erik.sundell87@gmail.com>
2022-10-24 17:12:36 +02:00

49 lines
1.4 KiB
TypeScript

import React from 'react';
import { SelectableValue } from '@grafana/data';
import { EditorField } from '@grafana/experimental';
import { Select } from '@grafana/ui';
import { LOOKBACK_PERIODS } from '../constants';
export interface Props {
refId: string;
onChange: (lookbackPeriod: string) => void;
templateVariableOptions: Array<SelectableValue<string>>;
current?: string;
}
export const LookbackPeriodSelect = ({ refId, current, templateVariableOptions, onChange }: Props) => {
const options = LOOKBACK_PERIODS.map((lp) => ({
...lp,
label: lp.text,
}));
if (current && !options.find((op) => op.value === current)) {
options.push({ label: current, text: current, value: current, hidden: false });
}
const visibleOptions = options.filter((lp) => !lp.hidden);
return (
<EditorField label="Lookback period" htmlFor={`${refId}-lookback-period`}>
<Select
inputId={`${refId}-lookback-period`}
width="auto"
allowCustomValue
value={[...options, ...templateVariableOptions].find((s) => s.value === current)}
options={[
{
label: 'Template Variables',
options: templateVariableOptions,
},
{
label: 'Predefined periods',
expanded: true,
options: visibleOptions,
},
]}
onChange={({ value }) => onChange(value!)}
/>
</EditorField>
);
};