forked from grafana.jool/grafana-jool
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.
50 lines
1.3 KiB
50 lines
1.3 KiB
import React, { useMemo } from 'react';
|
|
import { SelectableValue } from '@grafana/data';
|
|
import { Select } from '@grafana/ui';
|
|
import { ALIGNMENT_PERIODS } from '../constants';
|
|
import { MetricQuery, SLOQuery } from '../types';
|
|
|
|
export interface Props<TQuery> {
|
|
onChange(query: TQuery): void;
|
|
query: TQuery;
|
|
templateVariableOptions: Array<SelectableValue<string>>;
|
|
selectWidth?: number;
|
|
}
|
|
|
|
export function AlignmentPeriod<TQuery extends MetricQuery | SLOQuery>({
|
|
templateVariableOptions,
|
|
onChange,
|
|
query,
|
|
selectWidth,
|
|
}: Props<TQuery>) {
|
|
const options = useMemo(
|
|
() =>
|
|
ALIGNMENT_PERIODS.map((ap) => ({
|
|
...ap,
|
|
label: ap.text,
|
|
})),
|
|
[]
|
|
);
|
|
const visibleOptions = useMemo(() => options.filter((ap) => !ap.hidden), [options]);
|
|
|
|
return (
|
|
<Select
|
|
menuShouldPortal
|
|
width={selectWidth}
|
|
onChange={({ value }) => onChange({ ...query, alignmentPeriod: value! })}
|
|
value={[...options, ...templateVariableOptions].find((s) => s.value === query.alignmentPeriod)}
|
|
options={[
|
|
{
|
|
label: 'Template Variables',
|
|
options: templateVariableOptions,
|
|
},
|
|
{
|
|
label: 'Aggregations',
|
|
expanded: true,
|
|
options: visibleOptions,
|
|
},
|
|
]}
|
|
placeholder="Select Alignment"
|
|
></Select>
|
|
);
|
|
}
|
|
|