Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Lens] Do not reset formatting when switching between custom ranges and auto histogram #82694

Merged
merged 8 commits into from
Nov 10, 2020

Conversation

denismaxim0v
Copy link
Contributor

@denismaxim0v denismaxim0v commented Nov 5, 2020

Fixes #81749

Summary

Summarize your PR. If it involves visual changes include a screenshot or gif.
I've noticed it has been resetting the format to undefined, so I just switched it to keep the format of the current column

Checklist

Delete any items that are not applicable to this PR.

For maintainers

@denismaxim0v denismaxim0v requested a review from a team November 5, 2020 09:26
@kibanamachine
Copy link
Contributor

Since this is a community submitted pull request, a Jenkins build has not been kicked off automatically. Can an Elastic organization member please verify the contents of this patch and then kick off a build manually?

@flash1293 flash1293 self-assigned this Nov 5, 2020
@flash1293 flash1293 added Feature:Lens Team:Visualizations Visualization editors, elastic-charts and infrastructure v7.11.0 v8.0.0 labels Nov 5, 2020
@elasticmachine
Copy link
Contributor

Pinging @elastic/kibana-app (Team:KibanaApp)

@flash1293
Copy link
Contributor

Thanks for working on this, @denismaxim0v ! Would you mind adding a small unit test for the new behavior?

@denismaxim0v
Copy link
Contributor Author

Thanks for working on this, @denismaxim0v ! Would you mind adding a small unit test for the new behavior?

Sure, will do

@mbondyra mbondyra changed the title fix: do not reset formatting when switching between custom ranges and… [Lens] Do not reset formatting when switching between custom ranges and auto histogram Nov 5, 2020
@denismaxim0v
Copy link
Contributor Author

Alright, just added the unit test

@flash1293
Copy link
Contributor

@elasticmachine merge upstream

@flash1293
Copy link
Contributor

Jenkins, test this

// now set a format on the range operation
(state.layers.first.columns.col1 as RangeIndexPatternColumn).params.format = {
id: 'custom',
params: { decimals: 0 },
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems like the only difference between the "default" format of MyField and the overwrite on the column are the params. Your test doesn't really validate these params are kept - I commented out lines 763 to 766 and the tests still pass. I suggest not setting the same formatter in the field format map of the index pattern (line 759)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if I understood that completely. Should I switch it to test for params on the same line(759)?

Copy link
Contributor

@flash1293 flash1293 Nov 6, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, I meant setting it to the number formatter there so you can actually check whether the format is persisted.

But I just realized your test is not testing the right thing anyway. lns-customBucketContainer-remove is removing one out of multiple ranges, but that's not what should be tested here - this is about switching between custom ranges in general and automatic ranges controlled by granularity.

A proper unit test should click the "Remove custom ranges" button, then check whether the state update issued by this still includes the custom format.

Let me know when you have problems adding such a test. I can do it and add it to your PR

Copy link
Contributor Author

@denismaxim0v denismaxim0v Nov 6, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, I meant setting it to the number formatter there so you can actually check whether the format is persisted.

But I just realized your test is not testing the right thing anyway. lns-customBucketContainer-remove is removing one out of multiple ranges, but that's not what should be tested here - this is about switching between custom ranges in general and automatic ranges controlled by granularity.

A proper unit test should click the "Remove custom ranges" button, then check whether the state update issued by this still includes the custom format.

Let me know when you have problems adding such a test. I can do it and add it to your PR

So, I have been trying to

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',
          params: { decimals: 3 },
        };

        const instance = mount(
          <InlineOptions
            {...defaultOptions}
            state={state}
            setState={setStateSpy}
            columnId="col1"
            currentColumn={state.layers.first.columns.col1 as RangeIndexPatternColumn}
            layerId="first"
          />
        );
        //expect(instance.find(RangePopover)).toHaveLength(2);
        // This series of act closures are made to make it work properly the update flush
        act(() => {
          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 }
                      }
                    },
                  },
                },
              },
            },
          });
        });

But it seems that Number of calls: 2 and I'm not sure how to handle that

@flash1293
Copy link
Contributor

Can you push your latest state? Then I can take a look

@denismaxim0v
Copy link
Contributor Author

Can you push your latest state? Then I can take a look

any comments on the test issue?

@flash1293
Copy link
Contributor

@denismaxim0v Sorry for the delay, I'm blocked this morning but I will take a look this afternoon. Expect an update today

@flash1293
Copy link
Contributor

I made several changes to your unit test:

      it('should not reset formatters when switching between custom ranges and auto histogram', () => {
        const setStateSpy = jest.fn();
        // now set a format on the range operation
        (state.layers.first.columns.col1 as RangeIndexPatternColumn).params.format = {
          id: 'custom',
          params: { decimals: 3 },
        };

        const instance = mount(
          <InlineOptions
            {...defaultOptions}
            state={state}
            setState={setStateSpy}
            columnId="col1"
            currentColumn={state.layers.first.columns.col1 as RangeIndexPatternColumn}
            layerId="first"
          />
        );

        // This series of act closures are made to make it work properly the update flush
        act(() => {
          instance.find(EuiLink).first().prop('onClick')!({} as ReactMouseEvent);
        });

        expect(setStateSpy.mock.calls[1][0].layers.first.columns.col1.params.format).toEqual({
          id: 'custom',
          params: { decimals: 3 },
        });
      });
  • Remove unnecessary mock setup
  • Use EuiLink instead of class based selector (those shouldn't be used because they are internal to the EUI lib and can change anytime)
  • Assert using .mock.calls instead to be able to just check the relevant bit

Please update the PR with latest state of upstream master and fix the test this way, then this LGTM.

@denismaxim0v
Copy link
Contributor Author

Thanks, will do

@flash1293
Copy link
Contributor

Jenkins, test this

@flash1293
Copy link
Contributor

@denismaxim0v Seems like there is an unused import that has to be removed.

@denismaxim0v
Copy link
Contributor Author

done

@flash1293
Copy link
Contributor

Jenkins, test this

@kibanamachine
Copy link
Contributor

💚 Build Succeeded

Metrics [docs]

Async chunks

Total size of all lazy-loaded chunks that will be downloaded as the user navigates the app

id before after diff
lens 1.0MB 1.0MB +18.0B

History

To update your PR or re-run it, just comment with:
@elasticmachine merge upstream

Copy link
Contributor

@flash1293 flash1293 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks!

@flash1293 flash1293 merged commit 0503f87 into elastic:master Nov 10, 2020
flash1293 pushed a commit to flash1293/kibana that referenced this pull request Nov 10, 2020
flash1293 added a commit that referenced this pull request Nov 10, 2020
phillipb added a commit to phillipb/kibana that referenced this pull request Nov 10, 2020
…kibana into bootstrap-node-details-overlay

* 'bootstrap-node-details-overlay' of github.com:phillipb/kibana: (49 commits)
  [Security Solution] Fix DNS Network table query (elastic#82778)
  [Workplace Search] Consolidate groups routes (elastic#83015)
  Adds cloud links to user menu (elastic#82803)
  [Security Solution][Detections] - follow up cleanup on auto refresh rules (elastic#83023)
  [App Search] Added the log retention panel to the Settings page (elastic#82982)
  [Maps] show icon when layer is filtered by time and allow layers to ignore global time range (elastic#83006)
  [DOCS] Consolidates drilldown pages (elastic#82081)
  [Maps] add on-prem EMS config (elastic#82525)
  migrate i18n mixin to KP (elastic#81799)
  [bundle optimization] fix imports of react-use lib (elastic#82847)
  [Discover] Add metric on adding filter (elastic#82961)
  [Lens] Performance refactoring for indexpattern fast lookup and Operation support matrix computation (elastic#82829)
  skip flaky suite (elastic#82804)
  Fix SO query for searching across spaces (elastic#83025)
  renaming built-in alerts to Stack Alerts (elastic#82873)
  [TSVB] Disable using top_hits in pipeline aggregations (elastic#82278)
  [Visualizations] Remove kui usage (elastic#82810)
  [Visualizations] Make the icon buttons labels more descriptive (elastic#82585)
  [Lens] Do not reset formatting when switching between custom ranges and auto histogram (elastic#82694)
  Fix ilm navigation (elastic#81664)
  ...
gmmorris added a commit to gmmorris/kibana that referenced this pull request Nov 10, 2020
…na into alerts/stack-alerts-public

* 'alerts/stack-alerts-public' of github.com:gmmorris/kibana:
  [Security Solution] Fix DNS Network table query (elastic#82778)
  [Workplace Search] Consolidate groups routes (elastic#83015)
  Adds cloud links to user menu (elastic#82803)
  [Security Solution][Detections] - follow up cleanup on auto refresh rules (elastic#83023)
  [App Search] Added the log retention panel to the Settings page (elastic#82982)
  [Maps] show icon when layer is filtered by time and allow layers to ignore global time range (elastic#83006)
  [DOCS] Consolidates drilldown pages (elastic#82081)
  [Maps] add on-prem EMS config (elastic#82525)
  migrate i18n mixin to KP (elastic#81799)
  [bundle optimization] fix imports of react-use lib (elastic#82847)
  [Discover] Add metric on adding filter (elastic#82961)
  [Lens] Performance refactoring for indexpattern fast lookup and Operation support matrix computation (elastic#82829)
  skip flaky suite (elastic#82804)
  Fix SO query for searching across spaces (elastic#83025)
  renaming built-in alerts to Stack Alerts (elastic#82873)
  [TSVB] Disable using top_hits in pipeline aggregations (elastic#82278)
  [Visualizations] Remove kui usage (elastic#82810)
  [Visualizations] Make the icon buttons labels more descriptive (elastic#82585)
  [Lens] Do not reset formatting when switching between custom ranges and auto histogram (elastic#82694)
:
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Lens] Do not reset formatting when switching between custom ranges and auto histogram
4 participants