diff --git a/src/platform/plugins/shared/dashboard/public/dashboard_api/search_sessions/start_dashboard_search_session_integration.ts b/src/platform/plugins/shared/dashboard/public/dashboard_api/search_sessions/start_dashboard_search_session_integration.ts index ac960be081764..07cc8fcfb3e93 100644 --- a/src/platform/plugins/shared/dashboard/public/dashboard_api/search_sessions/start_dashboard_search_session_integration.ts +++ b/src/platform/plugins/shared/dashboard/public/dashboard_api/search_sessions/start_dashboard_search_session_integration.ts @@ -7,15 +7,15 @@ * License v3.0 only", or the "Server Side Public License, v 1". */ -import { skip } from 'rxjs'; +import { combineLatest, filter, skip } from 'rxjs'; import { noSearchSessionStorageCapabilityMessage } from '@kbn/data-plugin/public'; -import { dataService } from '../../services/kibana_services'; import type { DashboardApi, DashboardCreationOptions } from '../..'; -import { newSession$ } from './new_session'; +import { dataService } from '../../services/kibana_services'; import { getDashboardCapabilities } from '../../utils/get_dashboard_capabilities'; import type { DashboardInternalApi } from '../types'; +import { newSession$ } from './new_session'; /** * Enables dashboard search sessions. @@ -53,30 +53,37 @@ export function startDashboardSearchSessionIntegration( ?.pipe(skip(1)) .subscribe(() => dashboardApi.forceRefresh()); - const newSessionSubscription = newSession$(dashboardApi).subscribe(() => { - const currentSearchSessionId = dashboardApi.searchSessionId$.value; + const newSessionSubscription = combineLatest([ + newSession$(dashboardApi), + dashboardApi.isFetchPaused$, + ]) + .pipe( + filter(([, isFetchPaused]) => !isFetchPaused) // don't generate new search session until fetch is unpaused + ) + .subscribe(() => { + const currentSearchSessionId = dashboardApi.searchSessionId$.value; - const updatedSearchSessionId: string | undefined = (() => { - let searchSessionIdFromURL = getSearchSessionIdFromURL(); - if (searchSessionIdFromURL) { - if ( - dataService.search.session.isRestore() && - dataService.search.session.isCurrentSession(searchSessionIdFromURL) - ) { - // we had previously been in a restored session but have now changed state so remove the session id from the URL. - removeSessionIdFromUrl(); - searchSessionIdFromURL = undefined; - } else { - dataService.search.session.restore(searchSessionIdFromURL); + const updatedSearchSessionId: string | undefined = (() => { + let searchSessionIdFromURL = getSearchSessionIdFromURL(); + if (searchSessionIdFromURL) { + if ( + dataService.search.session.isRestore() && + dataService.search.session.isCurrentSession(searchSessionIdFromURL) + ) { + // we had previously been in a restored session but have now changed state so remove the session id from the URL. + removeSessionIdFromUrl(); + searchSessionIdFromURL = undefined; + } else { + dataService.search.session.restore(searchSessionIdFromURL); + } } - } - return searchSessionIdFromURL ?? dataService.search.session.start(); - })(); + return searchSessionIdFromURL ?? dataService.search.session.start(); + })(); - if (updatedSearchSessionId && updatedSearchSessionId !== currentSearchSessionId) { - setSearchSessionId(updatedSearchSessionId); - } - }); + if (updatedSearchSessionId && updatedSearchSessionId !== currentSearchSessionId) { + setSearchSessionId(updatedSearchSessionId); + } + }); return () => { searchSessionIdChangeSubscription?.unsubscribe();