From 3cbde064e65d058511a2f4a0ce740393631b6973 Mon Sep 17 00:00:00 2001 From: Kibana Machine <42973632+kibanamachine@users.noreply.github.com> Date: Wed, 22 Sep 2021 20:00:05 -0400 Subject: [PATCH] [Search sessions] Don't show incomplete warning if search requests aren't in session (#112364) (#112892) * [Search sessions] Don't show incomplete warning if search requests aren't in session" * Update src/plugins/data/public/search/search_interceptor/search_interceptor.ts Co-authored-by: Anton Dosov * Fix lint Co-authored-by: Anton Dosov Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com> Co-authored-by: Lukas Olson Co-authored-by: Anton Dosov --- .../search_interceptor.test.ts | 40 ++++++++++++++++++- .../search_interceptor/search_interceptor.ts | 10 ++++- 2 files changed, 46 insertions(+), 4 deletions(-) diff --git a/src/plugins/data/public/search/search_interceptor/search_interceptor.test.ts b/src/plugins/data/public/search/search_interceptor/search_interceptor.test.ts index 155638250a2a4..7186938816d5f 100644 --- a/src/plugins/data/public/search/search_interceptor/search_interceptor.test.ts +++ b/src/plugins/data/public/search/search_interceptor/search_interceptor.test.ts @@ -501,12 +501,12 @@ describe('SearchInterceptor', () => { opts: { isRestore?: boolean; isStored?: boolean; - sessionId: string; + sessionId?: string; } | null ) => { const sessionServiceMock = sessionService as jest.Mocked; sessionServiceMock.getSearchOptions.mockImplementation(() => - opts + opts && opts.sessionId ? { sessionId: opts.sessionId, isRestore: opts.isRestore ?? false, @@ -515,6 +515,7 @@ describe('SearchInterceptor', () => { : null ); sessionServiceMock.isRestore.mockReturnValue(!!opts?.isRestore); + sessionServiceMock.getSessionId.mockImplementation(() => opts?.sessionId); fetchMock.mockResolvedValue({ result: 200 }); }; @@ -606,6 +607,41 @@ describe('SearchInterceptor', () => { expect(SearchSessionIncompleteWarning).toBeCalledTimes(0); }); + test('should not show warning if a search outside of session is running', async () => { + setup({ + isRestore: false, + isStored: false, + }); + + const responses = [ + { + time: 10, + value: { + isPartial: false, + isRunning: false, + isRestored: false, + id: 1, + rawResponse: { + took: 1, + }, + }, + }, + ]; + mockFetchImplementation(responses); + + const response = searchInterceptor.search( + {}, + { + sessionId: undefined, + } + ); + response.subscribe({ next, error, complete }); + + await timeTravel(10); + + expect(SearchSessionIncompleteWarning).toBeCalledTimes(0); + }); + test('should show warning once if a search is not available during restore', async () => { setup({ isRestore: true, diff --git a/src/plugins/data/public/search/search_interceptor/search_interceptor.ts b/src/plugins/data/public/search/search_interceptor/search_interceptor.ts index ff3c173fd18cf..180e826b5bc4e 100644 --- a/src/plugins/data/public/search/search_interceptor/search_interceptor.ts +++ b/src/plugins/data/public/search/search_interceptor/search_interceptor.ts @@ -352,8 +352,14 @@ export class SearchInterceptor { ); }), tap((response) => { - if (this.deps.session.isRestore() && response.isRestored === false) { - this.showRestoreWarning(this.deps.session.getSessionId()); + const isSearchInScopeOfSession = + sessionId && sessionId === this.deps.session.getSessionId(); + if ( + isSearchInScopeOfSession && + this.deps.session.isRestore() && + response.isRestored === false + ) { + this.showRestoreWarning(sessionId); } }), finalize(() => {