[Search sessions] Don't show incomplete warning if search requests aren't in session (#112364)

* [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 <dosantappdev@gmail.com>

* Fix lint

Co-authored-by: Anton Dosov <dosantappdev@gmail.com>
Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
This commit is contained in:
Lukas Olson 2021-09-22 13:36:27 -07:00 committed by GitHub
parent 791fed5b82
commit f4c2a934f0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 46 additions and 4 deletions

View file

@ -501,12 +501,12 @@ describe('SearchInterceptor', () => {
opts: {
isRestore?: boolean;
isStored?: boolean;
sessionId: string;
sessionId?: string;
} | null
) => {
const sessionServiceMock = sessionService as jest.Mocked<ISessionService>;
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,

View file

@ -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(() => {