-
Notifications
You must be signed in to change notification settings - Fork 8.3k
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
Conversation
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? |
Pinging @elastic/kibana-app (Team:KibanaApp) |
Thanks for working on this, @denismaxim0v ! Would you mind adding a small unit test for the new behavior? |
Sure, will do |
… and auto histogram elastic#82694
Alright, just added the unit test |
@elasticmachine merge upstream |
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 }, |
There was a problem hiding this comment.
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)
There was a problem hiding this comment.
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)?
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
Can you push your latest state? Then I can take a look |
… ranges and auto histogram
any comments on the test issue? |
@denismaxim0v Sorry for the delay, I'm blocked this morning but I will take a look this afternoon. Expect an update today |
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 },
});
});
Please update the PR with latest state of upstream master and fix the test this way, then this LGTM. |
Thanks, will do |
Jenkins, test this |
@denismaxim0v Seems like there is an unused import that has to be removed. |
done |
Jenkins, test this |
💚 Build SucceededMetrics [docs]Async chunks
History
To update your PR or re-run it, just comment with: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, thanks!
…nd auto histogram (elastic#82694)
…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) ...
…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) :
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