Skip to content

Commit

Permalink
[8.14] [Discover] Fix resetting of breakdown field in a saved search (#…
Browse files Browse the repository at this point in the history
…184668) (#184998)

# Backport

This will backport the following commits from `main` to `8.14`:
- [[Discover] Fix resetting of breakdown field in a saved search
(#184668)](#184668)

<!--- Backport version: 9.4.3 -->

### Questions ?
Please refer to the [Backport tool
documentation](https://github.com/sqren/backport)

<!--BACKPORT [{"author":{"name":"Julia
Rechkunova","email":"julia.rechkunova@elastic.co"},"sourceCommit":{"committedDate":"2024-06-07T11:29:16Z","message":"[Discover]
Fix resetting of breakdown field in a saved search (#184668)\n\n- Closes
https://github.com/elastic/kibana/issues/184379\r\n\r\n##
Summary\r\n\r\nThis PR brings back the logic which was edited
in\r\nhttps://github.com//pull/169548 This should allow to
reset\r\nthe saved breakdown field with rather an empty string as
`undefined`\r\nseems to be ignored.\r\n\r\n### Checklist\r\n\r\n- [x]
[Unit or
functional\r\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\r\nwere
updated or added to match the most common
scenarios","sha":"132ab34ba54fbc6d119bc1e31d3838cd72493082","branchLabelMapping":{"^v8.15.0$":"main","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["Feature:Discover","release_note:fix","Team:DataDiscovery","backport:prev-minor","v8.15.0"],"title":"[Discover]
Fix resetting of breakdown field in a saved
search","number":184668,"url":"https://github.com/elastic/kibana/pull/184668","mergeCommit":{"message":"[Discover]
Fix resetting of breakdown field in a saved search (#184668)\n\n- Closes
https://github.com/elastic/kibana/issues/184379\r\n\r\n##
Summary\r\n\r\nThis PR brings back the logic which was edited
in\r\nhttps://github.com//pull/169548 This should allow to
reset\r\nthe saved breakdown field with rather an empty string as
`undefined`\r\nseems to be ignored.\r\n\r\n### Checklist\r\n\r\n- [x]
[Unit or
functional\r\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\r\nwere
updated or added to match the most common
scenarios","sha":"132ab34ba54fbc6d119bc1e31d3838cd72493082"}},"sourceBranch":"main","suggestedTargetBranches":[],"targetPullRequestStates":[{"branch":"main","label":"v8.15.0","branchLabelMappingKey":"^v8.15.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/184668","number":184668,"mergeCommit":{"message":"[Discover]
Fix resetting of breakdown field in a saved search (#184668)\n\n- Closes
https://github.com/elastic/kibana/issues/184379\r\n\r\n##
Summary\r\n\r\nThis PR brings back the logic which was edited
in\r\nhttps://github.com//pull/169548 This should allow to
reset\r\nthe saved breakdown field with rather an empty string as
`undefined`\r\nseems to be ignored.\r\n\r\n### Checklist\r\n\r\n- [x]
[Unit or
functional\r\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\r\nwere
updated or added to match the most common
scenarios","sha":"132ab34ba54fbc6d119bc1e31d3838cd72493082"}}]}]
BACKPORT-->

Co-authored-by: Julia Rechkunova <julia.rechkunova@elastic.co>
  • Loading branch information
kibanamachine and jughosta authored Jun 7, 2024
1 parent 8ba8515 commit df9480d
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -402,6 +402,10 @@ function getSavedSearchFieldForComparison(
return visContext;
}

if (fieldName === 'breakdownField') {
return savedSearch.breakdownField || ''; // ignore the difference between an empty string and undefined
}

return savedSearch[fieldName];
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -434,7 +434,6 @@ describe('Test discover state actions', () => {
const { searchSource, ...savedSearch } = state.savedSearchState.getState();
expect(savedSearch).toMatchInlineSnapshot(`
Object {
"breakdownField": undefined,
"columns": Array [
"default_column",
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,40 @@ describe('updateSavedSearch', () => {
});
});

it('should pass breakdownField if state has breakdownField', async () => {
const savedSearch = {
...savedSearchMock,
searchSource: savedSearchMock.searchSource.createCopy(),
};
expect(savedSearch.breakdownField).toBeUndefined();
updateSavedSearch({
savedSearch,
globalStateContainer: createGlobalStateContainer(),
services: discoverServiceMock,
state: {
breakdownField: 'test',
},
});
expect(savedSearch.breakdownField).toEqual('test');
});

it('should pass an empty string if state already has breakdownField', async () => {
const savedSearch = {
...savedSearchMock,
searchSource: savedSearchMock.searchSource.createCopy(),
breakdownField: 'test',
};
updateSavedSearch({
savedSearch,
globalStateContainer: createGlobalStateContainer(),
services: discoverServiceMock,
state: {
breakdownField: undefined,
},
});
expect(savedSearch.breakdownField).toEqual('');
});

it('should set query and filters from services', async () => {
const savedSearch = {
...savedSearchMock,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,12 @@ export function updateSavedSearch({
savedSearch.viewMode = state.viewMode;
}

savedSearch.breakdownField = state.breakdownField || undefined; // `undefined` instead of an empty string
if (typeof state.breakdownField !== 'undefined') {
savedSearch.breakdownField = state.breakdownField;
} else if (savedSearch.breakdownField) {
savedSearch.breakdownField = '';
}

savedSearch.hideAggregatedPreview = state.hideAggregatedPreview;

// add a flag here to identify text based language queries
Expand Down

0 comments on commit df9480d

Please sign in to comment.