The open and composable observability and data visualization platform. Visualize metrics, logs, and traces from multiple sources like Prometheus, Loki, Elasticsearch, InfluxDB, Postgres and many more.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 
grafana/public/app/plugins/datasource/cloud-monitoring/components/SLO/LookbackPeriodSelect.tsx

53 lines
1.5 KiB

import React, { FunctionComponent } from 'react';
import { SelectableValue } from '@grafana/data';
import { Select } from '@grafana/ui';
import { QueryEditorRow } from '..';
import { SELECT_WIDTH, LOOKBACK_PERIODS } from '../../constants';
export interface Props {
refId: string;
onChange: (lookbackPeriod: string) => void;
templateVariableOptions: Array<SelectableValue<string>>;
current?: string;
}
export const LookbackPeriodSelect: FunctionComponent<Props> = ({
refId,
current,
templateVariableOptions,
onChange,
}) => {
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 (
<QueryEditorRow label="Lookback period" htmlFor={`${refId}-lookback-period`}>
<Select
inputId={`${refId}-lookback-period`}
width={SELECT_WIDTH}
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!)}
/>
</QueryEditorRow>
);
};