From 6d03ad440f64f4ef6e998fc45eeff9a2a1124d40 Mon Sep 17 00:00:00 2001 From: Chris Cowan Date: Fri, 7 Feb 2020 07:34:41 -0700 Subject: [PATCH] [Metrics UI] Limit group by selector to only 2 fields (#56800) * [Metrics UI] Limit group by selector to only 2 fields * Removing unused variable * Removing unused import Co-authored-by: Elastic Machine --- .../components/waffle/custom_field_panel.tsx | 14 ++++++++++--- .../waffle/waffle_group_by_controls.tsx | 20 +++++++++++++++++-- 2 files changed, 29 insertions(+), 5 deletions(-) diff --git a/x-pack/legacy/plugins/infra/public/components/waffle/custom_field_panel.tsx b/x-pack/legacy/plugins/infra/public/components/waffle/custom_field_panel.tsx index 01bff0b4f96e1e..15d8b8b0e42b8e 100644 --- a/x-pack/legacy/plugins/infra/public/components/waffle/custom_field_panel.tsx +++ b/x-pack/legacy/plugins/infra/public/components/waffle/custom_field_panel.tsx @@ -8,10 +8,12 @@ import { EuiButton, EuiComboBox, EuiForm, EuiFormRow } from '@elastic/eui'; import { i18n } from '@kbn/i18n'; import React from 'react'; import { IFieldType } from 'src/plugins/data/public'; +import { InfraGroupByOptions } from '../../lib/lib'; interface Props { onSubmit: (field: string) => void; fields: IFieldType[]; + currentOptions: InfraGroupByOptions[]; } interface SelectedOption { @@ -28,10 +30,16 @@ export const CustomFieldPanel = class extends React.PureComponent public static displayName = 'CustomFieldPanel'; public readonly state: State = initialState; public render() { - const { fields } = this.props; + const { fields, currentOptions } = this.props; const options = fields - .filter(f => f.aggregatable && f.type === 'string') + .filter( + f => + f.aggregatable && + f.type === 'string' && + !(currentOptions && currentOptions.some(o => o.field === f.name)) + ) .map(f => ({ label: f.name })); + const isSubmitDisabled = !this.state.selectedOptions.length; return (
@@ -57,7 +65,7 @@ export const CustomFieldPanel = class extends React.PureComponent /> = 2; + const maxGroupByTooltip = i18n.translate('xpack.infra.waffle.maxGroupByTooltip', { + defaultMessage: 'Only two groupings can be selected at a time', + }); const panels: EuiContextMenuPanelDescriptor[] = [ { id: 'firstPanel', @@ -72,6 +76,8 @@ export const WaffleGroupByControls = class extends React.PureComponent, + content: ( + + ), }, ]; const buttonBody = @@ -167,8 +183,8 @@ export const WaffleGroupByControls = class extends React.PureComponent