import { useMemo } from 'react'; import { SelectableValue } from '@grafana/data'; import { EditorField, EditorFieldGroup } from '@grafana/plugin-ui'; import { MultiSelect } from '@grafana/ui'; import { SYSTEM_LABELS } from '../constants'; import { labelsToGroupedOptions } from '../functions'; import { TimeSeriesList } from '../types/query'; import { MetricDescriptor } from '../types/types'; import { Aggregation } from './Aggregation'; export interface Props { refId: string; variableOptionGroup: SelectableValue; labels: string[]; metricDescriptor?: MetricDescriptor; onChange: (query: TimeSeriesList) => void; query: TimeSeriesList; } export const GroupBy = ({ refId, labels: groupBys = [], query, onChange, variableOptionGroup, metricDescriptor, }: Props) => { const options = useMemo( () => [variableOptionGroup, ...labelsToGroupedOptions([...groupBys, ...SYSTEM_LABELS])], [groupBys, variableOptionGroup] ); return ( { onChange({ ...query, groupBys: options.map((o) => o.value!) }); }} menuPlacement="top" /> onChange({ ...query, crossSeriesReducer })} refId={refId} /> ); };