[8.11] [Security Solution] Fixes ES|QL Tab resetting to KQL Bar (#168716) (#168784)

# Backport

This will backport the following commits from `main` to `8.11`:
- [[Security Solution] Fixes ES|QL Tab resetting to KQL Bar
(#168716)](https://github.com/elastic/kibana/pull/168716)

<!--- Backport version: 8.9.7 -->

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

<!--BACKPORT [{"author":{"name":"Jatin
Kathuria","email":"jatin.kathuria@elastic.co"},"sourceCommit":{"committedDate":"2023-10-13T06:22:06Z","message":"[Security
Solution] Fixes ES|QL Tab resetting to KQL Bar (#168716)\n\n##
Summary\r\n\r\nHandles #168431\r\n\r\nThis PR fixes a race condition
which was causing Discover ES|QL tab to\r\nrevert to it KQL query bar.
See demo below:\r\n\r\n| Before | After |\r\n|---|---|\r\n|
<video\r\nsrc=\"746946ad-bd69-412f-bd38-d3d79b570c68\"\r\n/>|","sha":"6fd6966ed8225935feee247b04b4988424b47c88","branchLabelMapping":{"^v8.12.0$":"main","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:skip","Team:Threat
Hunting:Investigations","v8.11.0","v8.12.0"],"number":168716,"url":"https://github.com/elastic/kibana/pull/168716","mergeCommit":{"message":"[Security
Solution] Fixes ES|QL Tab resetting to KQL Bar (#168716)\n\n##
Summary\r\n\r\nHandles #168431\r\n\r\nThis PR fixes a race condition
which was causing Discover ES|QL tab to\r\nrevert to it KQL query bar.
See demo below:\r\n\r\n| Before | After |\r\n|---|---|\r\n|
<video\r\nsrc=\"746946ad-bd69-412f-bd38-d3d79b570c68\"\r\n/>|","sha":"6fd6966ed8225935feee247b04b4988424b47c88"}},"sourceBranch":"main","suggestedTargetBranches":["8.11"],"targetPullRequestStates":[{"branch":"8.11","label":"v8.11.0","labelRegex":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"},{"branch":"main","label":"v8.12.0","labelRegex":"^v8.12.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/168716","number":168716,"mergeCommit":{"message":"[Security
Solution] Fixes ES|QL Tab resetting to KQL Bar (#168716)\n\n##
Summary\r\n\r\nHandles #168431\r\n\r\nThis PR fixes a race condition
which was causing Discover ES|QL tab to\r\nrevert to it KQL query bar.
See demo below:\r\n\r\n| Before | After |\r\n|---|---|\r\n|
<video\r\nsrc=\"746946ad-bd69-412f-bd38-d3d79b570c68\"\r\n/>|","sha":"6fd6966ed8225935feee247b04b4988424b47c88"}}]}]
BACKPORT-->

Co-authored-by: Jatin Kathuria <jatin.kathuria@elastic.co>
This commit is contained in:
Kibana Machine 2023-10-13 03:48:25 -04:00 committed by GitHub
parent 5dc69b421c
commit 12a59a2521
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -181,6 +181,10 @@ export const DiscoverTabContent: FC<DiscoverTabContentProps> = ({ timelineId })
if (!savedObjectId) return;
if (!status || status === 'draft') return;
const latestState = getCombinedDiscoverSavedSearchState();
const index = latestState?.searchSource.getField('index');
/* when a new timeline is loaded, a new discover instance is loaded which first emits
* discover's initial state which is then updated in the saved search. We want to avoid that.*/
if (!index) return;
if (!latestState || combinedDiscoverSavedSearchStateRef.current === latestState) return;
if (isEqualWith(latestState, savedSearchById, savedSearchComparator)) return;
debouncedUpdateSavedSearch(latestState, timelineId);