Skip to content

Commit

Permalink
[Discover] Migrate session session initialization to state container (e…
Browse files Browse the repository at this point in the history
…lastic#156957)

## Summary

Migrate `useSearchSession` to state container's `initializeAndSync` function, to remove another `hook`.
  • Loading branch information
kertal authored and delanni committed May 25, 2023
1 parent 3355148 commit 99837fd
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 82 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import React, { useCallback, useEffect } from 'react';
import { RootDragDropProvider } from '@kbn/dom-drag-drop';
import { useHistory } from 'react-router-dom';
import { useUrlTracking } from './hooks/use_url_tracking';
import { useSearchSession } from './hooks/use_search_session';
import { DiscoverStateContainer } from './services/discover_state';
import { DiscoverLayout } from './components/layout';
import { setBreadcrumbsTitle } from '../../utils/breadcrumbs';
Expand Down Expand Up @@ -44,11 +43,6 @@ export function DiscoverMainApp(props: DiscoverMainProps) {

useUrlTracking(stateContainer.savedSearchState);

/**
* Search session logic
*/
useSearchSession({ services, stateContainer });

/**
* Adhoc data views functionality
*/
Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ const startSync = (appState: DiscoverAppStateContainer) => {
return stop;
};

async function getState(url: string, savedSearch?: SavedSearch) {
async function getState(url: string = '/', savedSearch?: SavedSearch) {
const nextHistory = createBrowserHistory();
nextHistory.push(url);
const nextState = getDiscoverStateContainer({
Expand Down Expand Up @@ -237,6 +237,16 @@ describe('createSearchSessionRestorationDataProvider', () => {
});
});

describe('searchSessionManager', () => {
test('getting the next session id', async () => {
const { state } = await getState();
const nextId = 'id';
discoverServiceMock.data.search.session.start = jest.fn(() => nextId);
state.actions.initializeAndSync();
expect(state.searchSessionManager.getNextSearchSessionId()).toBe(nextId);
});
});

describe('actions', () => {
beforeEach(async () => {
discoverServiceMock.data.query.timefilter.timefilter.getTime = jest.fn(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {
} from '@kbn/kibana-utils-plugin/public';
import {
DataPublicPluginStart,
noSearchSessionStorageCapabilityMessage,
QueryState,
SearchSessionInfoProvider,
} from '@kbn/data-plugin/public';
Expand Down Expand Up @@ -382,6 +383,23 @@ export function getDiscoverStateContainer({
fetchData();
});

services.data.search.session.enableStorage(
createSearchSessionRestorationDataProvider({
appStateContainer,
data: services.data,
getSavedSearch: () => savedSearchContainer.getState(),
}),
{
isDisabled: () =>
services.capabilities.discover.storeSearchSession
? { disabled: false }
: {
disabled: true,
reasonText: noSearchSessionStorageCapabilityMessage,
},
}
);

return () => {
unsubscribeData();
appStateUnsubscribe();
Expand Down

0 comments on commit 99837fd

Please sign in to comment.