Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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();
Expand Down