From bfb0cf8b6ff87c026550a34d1880dd7461618c25 Mon Sep 17 00:00:00 2001 From: denis Date: Thu, 5 Nov 2020 11:20:53 +0200 Subject: [PATCH 1/5] fix: do not reset formatting when switching between custom ranges and auto histogram --- .../operations/definitions/ranges/ranges.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/x-pack/plugins/lens/public/indexpattern_datasource/operations/definitions/ranges/ranges.tsx b/x-pack/plugins/lens/public/indexpattern_datasource/operations/definitions/ranges/ranges.tsx index 1050eef45a71c..46d9e4e6c22de 100644 --- a/x-pack/plugins/lens/public/indexpattern_datasource/operations/definitions/ranges/ranges.tsx +++ b/x-pack/plugins/lens/public/indexpattern_datasource/operations/definitions/ranges/ranges.tsx @@ -225,7 +225,7 @@ export const rangeOperation: OperationDefinition Date: Fri, 6 Nov 2020 11:19:03 +0200 Subject: [PATCH 2/5] test for Do not reset formatting when switching between custom ranges and auto histogram #82694 --- .../definitions/ranges/ranges.test.tsx | 49 +++++++++++++++++++ 1 file changed, 49 insertions(+) diff --git a/x-pack/plugins/lens/public/indexpattern_datasource/operations/definitions/ranges/ranges.test.tsx b/x-pack/plugins/lens/public/indexpattern_datasource/operations/definitions/ranges/ranges.test.tsx index c8a8ffa7b128f..74b39df2762a8 100644 --- a/x-pack/plugins/lens/public/indexpattern_datasource/operations/definitions/ranges/ranges.test.tsx +++ b/x-pack/plugins/lens/public/indexpattern_datasource/operations/definitions/ranges/ranges.test.tsx @@ -744,6 +744,55 @@ describe('ranges', () => { /^Bytes format:/ ); }); + + it('should not reset formatters when switching between custom ranges and auto histogram', () => { + const setStateSpy = jest.fn(); + + // Add an extra range + (state.layers.first.columns.col1 as RangeIndexPatternColumn).params.ranges.push({ + from: DEFAULT_INTERVAL, + to: 2 * DEFAULT_INTERVAL, + label: '', + }); + + state.indexPatterns['1'].fieldFormatMap = { + MyField: { id: 'custom', params: {} }, + }; + + // now set a format on the range operation + (state.layers.first.columns.col1 as RangeIndexPatternColumn).params.format = { + id: 'custom', + params: { decimals: 0 }, + }; + + const instance = mount( + + ); + + expect(instance.find(RangePopover)).toHaveLength(2); + + // This series of act closures are made to make it work properly the update flush + act(() => { + instance + .find('[data-test-subj="lns-customBucketContainer-remove"]') + .last() + .prop('onClick')!({} as ReactMouseEvent); + }); + + act(() => { + instance.update(); + expect(instance.find(RangePopover).find(EuiText).prop('children')).toMatch( + /^Custom format:/ + ); + }); + }); }); }); }); From 2459d72f2d7d374b5608c01e82a91ab98a060f14 Mon Sep 17 00:00:00 2001 From: denis Date: Fri, 6 Nov 2020 17:05:48 +0200 Subject: [PATCH 3/5] [Lens] test for Do not reset formatting when switching between custom ranges and auto histogram --- .../definitions/ranges/ranges.test.tsx | 44 ++++++++++++------- 1 file changed, 27 insertions(+), 17 deletions(-) diff --git a/x-pack/plugins/lens/public/indexpattern_datasource/operations/definitions/ranges/ranges.test.tsx b/x-pack/plugins/lens/public/indexpattern_datasource/operations/definitions/ranges/ranges.test.tsx index 74b39df2762a8..406fee9026e07 100644 --- a/x-pack/plugins/lens/public/indexpattern_datasource/operations/definitions/ranges/ranges.test.tsx +++ b/x-pack/plugins/lens/public/indexpattern_datasource/operations/definitions/ranges/ranges.test.tsx @@ -30,6 +30,7 @@ import { } from './constants'; import { RangePopover } from './advanced_editor'; import { DragDropBuckets } from '../shared_components'; +import { FormatSelector } from '../../../dimension_panel/format_selector'; const dataPluginMockValue = dataPluginMock.createStartContract(); // need to overwrite the formatter field first @@ -747,14 +748,13 @@ describe('ranges', () => { it('should not reset formatters when switching between custom ranges and auto histogram', () => { const setStateSpy = jest.fn(); - - // Add an extra range (state.layers.first.columns.col1 as RangeIndexPatternColumn).params.ranges.push({ - from: DEFAULT_INTERVAL, - to: 2 * DEFAULT_INTERVAL, + from: null, + to: null, label: '', }); + // set a default formatter for the sourceField used state.indexPatterns['1'].fieldFormatMap = { MyField: { id: 'custom', params: {} }, }; @@ -762,7 +762,7 @@ describe('ranges', () => { // now set a format on the range operation (state.layers.first.columns.col1 as RangeIndexPatternColumn).params.format = { id: 'custom', - params: { decimals: 0 }, + params: { decimals: 3 }, }; const instance = mount( @@ -776,21 +776,31 @@ describe('ranges', () => { /> ); - expect(instance.find(RangePopover)).toHaveLength(2); - // This series of act closures are made to make it work properly the update flush act(() => { - instance - .find('[data-test-subj="lns-customBucketContainer-remove"]') - .last() - .prop('onClick')!({} as ReactMouseEvent); - }); + instance.find('.euiLink').first().prop('onClick')!({} as ReactMouseEvent); - act(() => { - instance.update(); - expect(instance.find(RangePopover).find(EuiText).prop('children')).toMatch( - /^Custom format:/ - ); + expect(setStateSpy).toHaveBeenCalledWith({ + ...state, + layers: { + first: { + ...state.layers.first, + columns: { + ...state.layers.first.columns, + col1: { + ...state.layers.first.columns.col1, + params: { + ...state.layers.first.columns.col1.params, + format: { + id: 'custom', + params: { decimals: 3 }, + }, + }, + }, + }, + }, + }, + }); }); }); }); From 8c051c82a1fe8b08809aab0884d06e90c907dd45 Mon Sep 17 00:00:00 2001 From: denis Date: Mon, 9 Nov 2020 21:36:17 +0200 Subject: [PATCH 4/5] fix: Do not reset formatting when switching between custom ranges and auto histogram #82694 --- .../definitions/ranges/ranges.test.tsx | 38 +++---------------- 1 file changed, 5 insertions(+), 33 deletions(-) diff --git a/x-pack/plugins/lens/public/indexpattern_datasource/operations/definitions/ranges/ranges.test.tsx b/x-pack/plugins/lens/public/indexpattern_datasource/operations/definitions/ranges/ranges.test.tsx index 406fee9026e07..43fa73a7a3b72 100644 --- a/x-pack/plugins/lens/public/indexpattern_datasource/operations/definitions/ranges/ranges.test.tsx +++ b/x-pack/plugins/lens/public/indexpattern_datasource/operations/definitions/ranges/ranges.test.tsx @@ -748,17 +748,6 @@ describe('ranges', () => { it('should not reset formatters when switching between custom ranges and auto histogram', () => { const setStateSpy = jest.fn(); - (state.layers.first.columns.col1 as RangeIndexPatternColumn).params.ranges.push({ - from: null, - to: null, - label: '', - }); - - // set a default formatter for the sourceField used - state.indexPatterns['1'].fieldFormatMap = { - MyField: { id: 'custom', params: {} }, - }; - // now set a format on the range operation (state.layers.first.columns.col1 as RangeIndexPatternColumn).params.format = { id: 'custom', @@ -778,29 +767,12 @@ describe('ranges', () => { // This series of act closures are made to make it work properly the update flush act(() => { - instance.find('.euiLink').first().prop('onClick')!({} as ReactMouseEvent); + instance.find(EuiLink).first().prop('onClick')!({} as ReactMouseEvent); + }); - expect(setStateSpy).toHaveBeenCalledWith({ - ...state, - layers: { - first: { - ...state.layers.first, - columns: { - ...state.layers.first.columns, - col1: { - ...state.layers.first.columns.col1, - params: { - ...state.layers.first.columns.col1.params, - format: { - id: 'custom', - params: { decimals: 3 }, - }, - }, - }, - }, - }, - }, - }); + expect(setStateSpy.mock.calls[1][0].layers.first.columns.col1.params.format).toEqual({ + id: 'custom', + params: { decimals: 3 }, }); }); }); From ba7778136eead8ba6150de34d40608747254174f Mon Sep 17 00:00:00 2001 From: denis Date: Tue, 10 Nov 2020 10:30:02 +0200 Subject: [PATCH 5/5] fix: remove unused import --- .../operations/definitions/ranges/ranges.test.tsx | 1 - 1 file changed, 1 deletion(-) diff --git a/x-pack/plugins/lens/public/indexpattern_datasource/operations/definitions/ranges/ranges.test.tsx b/x-pack/plugins/lens/public/indexpattern_datasource/operations/definitions/ranges/ranges.test.tsx index 43fa73a7a3b72..d43a905434c02 100644 --- a/x-pack/plugins/lens/public/indexpattern_datasource/operations/definitions/ranges/ranges.test.tsx +++ b/x-pack/plugins/lens/public/indexpattern_datasource/operations/definitions/ranges/ranges.test.tsx @@ -30,7 +30,6 @@ import { } from './constants'; import { RangePopover } from './advanced_editor'; import { DragDropBuckets } from '../shared_components'; -import { FormatSelector } from '../../../dimension_panel/format_selector'; const dataPluginMockValue = dataPluginMock.createStartContract(); // need to overwrite the formatter field first