From 9581e4e1c643881d27cd993e038d4bf65044aa32 Mon Sep 17 00:00:00 2001 From: Joe Reuter Date: Thu, 18 Jul 2019 17:12:41 +0200 Subject: [PATCH] [Lens] Optimize dimension panel flow (#41114) --- .../dimension_panel/dimension_panel.test.tsx | 35 +++++++++++++++++++ .../dimension_panel/popover_editor.tsx | 24 ++++++++++++- 2 files changed, 58 insertions(+), 1 deletion(-) diff --git a/x-pack/legacy/plugins/lens/public/indexpattern_plugin/dimension_panel/dimension_panel.test.tsx b/x-pack/legacy/plugins/lens/public/indexpattern_plugin/dimension_panel/dimension_panel.test.tsx index 2af755568c2a7..06e2933956d7f 100644 --- a/x-pack/legacy/plugins/lens/public/indexpattern_plugin/dimension_panel/dimension_panel.test.tsx +++ b/x-pack/legacy/plugins/lens/public/indexpattern_plugin/dimension_panel/dimension_panel.test.tsx @@ -542,6 +542,41 @@ describe('IndexPatternDimensionPanel', () => { }); }); + it('should select operation directly if only one field is possible', () => { + const initialState = { + ...defaultProps.state, + indexPatterns: { + 1: { + ...defaultProps.state.indexPatterns['1'], + fields: defaultProps.state.indexPatterns['1'].fields.filter( + field => field.name !== 'memory' + ), + }, + }, + }; + + wrapper = mount( + + ); + + openPopover(); + + wrapper.find('button[data-test-subj="lns-indexPatternDimension-avg"]').simulate('click'); + + expect(setState).toHaveBeenCalledWith({ + ...initialState, + columns: { + ...state.columns, + col2: expect.objectContaining({ + sourceField: 'bytes', + operationType: 'avg', + // Other parts of this don't matter for this test + }), + }, + columnOrder: ['col1', 'col2'], + }); + }); + it('should indicate compatible fields when selecting the operation first', () => { wrapper = mount(); diff --git a/x-pack/legacy/plugins/lens/public/indexpattern_plugin/dimension_panel/popover_editor.tsx b/x-pack/legacy/plugins/lens/public/indexpattern_plugin/dimension_panel/popover_editor.tsx index 560007d44862e..b00fc980d5303 100644 --- a/x-pack/legacy/plugins/lens/public/indexpattern_plugin/dimension_panel/popover_editor.tsx +++ b/x-pack/legacy/plugins/lens/public/indexpattern_plugin/dimension_panel/popover_editor.tsx @@ -88,7 +88,19 @@ export function PopoverEditor(props: PopoverEditorProps) { }), 'data-test-subj': `lns-indexPatternDimension-${operationType}`, onClick() { - if (!selectedColumn || !compatibleWithCurrentField) { + if (!selectedColumn) { + const possibleColumns = _.uniq( + filteredColumns.filter(col => col.operationType === operationType), + 'sourceField' + ); + if (possibleColumns.length === 1) { + setState(changeColumn(state, columnId, possibleColumns[0])); + } else { + setInvalidOperationType(operationType); + } + return; + } + if (!compatibleWithCurrentField) { setInvalidOperationType(operationType); return; } @@ -179,6 +191,16 @@ export function PopoverEditor(props: PopoverEditorProps) {

)} + {incompatibleSelectedOperationType && !selectedColumn && ( + + )} {!incompatibleSelectedOperationType && ParamEditor && (