mirror of
https://github.com/grafana/grafana.git
synced 2025-09-22 20:37:05 +08:00

* Remove menuShouldPortal from all <Select /> components * fix unit tests * leave menuShouldPortal as an escape hatch * Fix import order
45 lines
1.3 KiB
TypeScript
45 lines
1.3 KiB
TypeScript
import React, { FC, useMemo } from 'react';
|
|
|
|
import { SelectableValue } from '@grafana/data';
|
|
import { Select } from '@grafana/ui';
|
|
|
|
import { SELECT_WIDTH } from '../constants';
|
|
import { getAlignmentPickerData } from '../functions';
|
|
import { MetricQuery } from '../types';
|
|
|
|
export interface Props {
|
|
inputId: string;
|
|
onChange: (query: MetricQuery) => void;
|
|
query: MetricQuery;
|
|
templateVariableOptions: Array<SelectableValue<string>>;
|
|
}
|
|
|
|
export const AlignmentFunction: FC<Props> = ({ inputId, query, templateVariableOptions, onChange }) => {
|
|
const { valueType, metricKind, perSeriesAligner: psa, preprocessor } = query;
|
|
const { perSeriesAligner, alignOptions } = useMemo(
|
|
() => getAlignmentPickerData(valueType, metricKind, psa, preprocessor),
|
|
[valueType, metricKind, psa, preprocessor]
|
|
);
|
|
|
|
return (
|
|
<Select
|
|
width={SELECT_WIDTH}
|
|
onChange={({ value }) => onChange({ ...query, perSeriesAligner: value! })}
|
|
value={[...alignOptions, ...templateVariableOptions].find((s) => s.value === perSeriesAligner)}
|
|
options={[
|
|
{
|
|
label: 'Template Variables',
|
|
options: templateVariableOptions,
|
|
},
|
|
{
|
|
label: 'Alignment options',
|
|
expanded: true,
|
|
options: alignOptions,
|
|
},
|
|
]}
|
|
placeholder="Select Alignment"
|
|
inputId={inputId}
|
|
></Select>
|
|
);
|
|
};
|