[Search Sessions][Discover] Send to background integration improvements and fixes (#87311)
This commit is contained in:
parent
78dea4f03f
commit
86d53b683e
|
@ -295,7 +295,7 @@ function discoverController($element, $route, $scope, $timeout, Promise, uiCapab
|
||||||
createSearchSessionRestorationDataProvider({
|
createSearchSessionRestorationDataProvider({
|
||||||
appStateContainer,
|
appStateContainer,
|
||||||
data,
|
data,
|
||||||
getSavedSearchId: () => savedSearch.id,
|
getSavedSearch: () => savedSearch,
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
|
@ -17,8 +17,14 @@
|
||||||
* under the License.
|
* under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { getState, GetStateReturn } from './discover_state';
|
import {
|
||||||
|
getState,
|
||||||
|
GetStateReturn,
|
||||||
|
createSearchSessionRestorationDataProvider,
|
||||||
|
} from './discover_state';
|
||||||
import { createBrowserHistory, History } from 'history';
|
import { createBrowserHistory, History } from 'history';
|
||||||
|
import { dataPluginMock } from '../../../../data/public/mocks';
|
||||||
|
import { SavedSearch } from '../../saved_searches';
|
||||||
|
|
||||||
let history: History;
|
let history: History;
|
||||||
let state: GetStateReturn;
|
let state: GetStateReturn;
|
||||||
|
@ -103,3 +109,30 @@ describe('Test discover state with legacy migration', () => {
|
||||||
`);
|
`);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('createSearchSessionRestorationDataProvider', () => {
|
||||||
|
let mockSavedSearch: SavedSearch = ({} as unknown) as SavedSearch;
|
||||||
|
const searchSessionInfoProvider = createSearchSessionRestorationDataProvider({
|
||||||
|
data: dataPluginMock.createStartContract(),
|
||||||
|
appStateContainer: getState({
|
||||||
|
history: createBrowserHistory(),
|
||||||
|
}).appStateContainer,
|
||||||
|
getSavedSearch: () => mockSavedSearch,
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('session name', () => {
|
||||||
|
test('No saved search returns default name', async () => {
|
||||||
|
expect(await searchSessionInfoProvider.getName()).toBe('Discover');
|
||||||
|
});
|
||||||
|
|
||||||
|
test('Saved Search with a title returns saved search title', async () => {
|
||||||
|
mockSavedSearch = ({ id: 'id', title: 'Name' } as unknown) as SavedSearch;
|
||||||
|
expect(await searchSessionInfoProvider.getName()).toBe('Name');
|
||||||
|
});
|
||||||
|
|
||||||
|
test('Saved Search without a title returns default name', async () => {
|
||||||
|
mockSavedSearch = ({ id: 'id', title: undefined } as unknown) as SavedSearch;
|
||||||
|
expect(await searchSessionInfoProvider.getName()).toBe('Discover');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
|
@ -17,6 +17,7 @@
|
||||||
* under the License.
|
* under the License.
|
||||||
*/
|
*/
|
||||||
import { isEqual } from 'lodash';
|
import { isEqual } from 'lodash';
|
||||||
|
import { i18n } from '@kbn/i18n';
|
||||||
import { History } from 'history';
|
import { History } from 'history';
|
||||||
import { NotificationsStart } from 'kibana/public';
|
import { NotificationsStart } from 'kibana/public';
|
||||||
import {
|
import {
|
||||||
|
@ -38,6 +39,7 @@ import {
|
||||||
import { migrateLegacyQuery } from '../helpers/migrate_legacy_query';
|
import { migrateLegacyQuery } from '../helpers/migrate_legacy_query';
|
||||||
import { DiscoverGridSettings } from '../components/discover_grid/types';
|
import { DiscoverGridSettings } from '../components/discover_grid/types';
|
||||||
import { DISCOVER_APP_URL_GENERATOR, DiscoverUrlGeneratorState } from '../../url_generator';
|
import { DISCOVER_APP_URL_GENERATOR, DiscoverUrlGeneratorState } from '../../url_generator';
|
||||||
|
import { SavedSearch } from '../../saved_searches';
|
||||||
|
|
||||||
export interface AppState {
|
export interface AppState {
|
||||||
/**
|
/**
|
||||||
|
@ -264,15 +266,32 @@ export function isEqualState(stateA: AppState, stateB: AppState) {
|
||||||
export function createSearchSessionRestorationDataProvider(deps: {
|
export function createSearchSessionRestorationDataProvider(deps: {
|
||||||
appStateContainer: StateContainer<AppState>;
|
appStateContainer: StateContainer<AppState>;
|
||||||
data: DataPublicPluginStart;
|
data: DataPublicPluginStart;
|
||||||
getSavedSearchId: () => string | undefined;
|
getSavedSearch: () => SavedSearch;
|
||||||
}): SearchSessionInfoProvider {
|
}): SearchSessionInfoProvider {
|
||||||
|
const getSavedSearchId = () => deps.getSavedSearch().id;
|
||||||
return {
|
return {
|
||||||
getName: async () => 'Discover',
|
getName: async () => {
|
||||||
|
const savedSearch = deps.getSavedSearch();
|
||||||
|
return (
|
||||||
|
(savedSearch.id && savedSearch.title) ||
|
||||||
|
i18n.translate('discover.discoverDefaultSearchSessionName', {
|
||||||
|
defaultMessage: 'Discover',
|
||||||
|
})
|
||||||
|
);
|
||||||
|
},
|
||||||
getUrlGeneratorData: async () => {
|
getUrlGeneratorData: async () => {
|
||||||
return {
|
return {
|
||||||
urlGeneratorId: DISCOVER_APP_URL_GENERATOR,
|
urlGeneratorId: DISCOVER_APP_URL_GENERATOR,
|
||||||
initialState: createUrlGeneratorState({ ...deps, forceAbsoluteTime: false }),
|
initialState: createUrlGeneratorState({
|
||||||
restoreState: createUrlGeneratorState({ ...deps, forceAbsoluteTime: true }),
|
...deps,
|
||||||
|
getSavedSearchId,
|
||||||
|
forceAbsoluteTime: false,
|
||||||
|
}),
|
||||||
|
restoreState: createUrlGeneratorState({
|
||||||
|
...deps,
|
||||||
|
getSavedSearchId,
|
||||||
|
forceAbsoluteTime: true,
|
||||||
|
}),
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
|
@ -62,7 +62,7 @@ describe('Discover url generator', () => {
|
||||||
const url = await generator.createUrl({ savedSearchId });
|
const url = await generator.createUrl({ savedSearchId });
|
||||||
const { _a, _g } = getStatesFromKbnUrl(url, ['_a', '_g']);
|
const { _a, _g } = getStatesFromKbnUrl(url, ['_a', '_g']);
|
||||||
|
|
||||||
expect(url.startsWith(`${appBasePath}#/${savedSearchId}`)).toBe(true);
|
expect(url.startsWith(`${appBasePath}#/view/${savedSearchId}`)).toBe(true);
|
||||||
expect(_a).toEqual({});
|
expect(_a).toEqual({});
|
||||||
expect(_g).toEqual({});
|
expect(_g).toEqual({});
|
||||||
});
|
});
|
||||||
|
|
|
@ -119,7 +119,7 @@ export class DiscoverUrlGenerator
|
||||||
sort,
|
sort,
|
||||||
interval,
|
interval,
|
||||||
}: DiscoverUrlGeneratorState): Promise<string> => {
|
}: DiscoverUrlGeneratorState): Promise<string> => {
|
||||||
const savedSearchPath = savedSearchId ? encodeURIComponent(savedSearchId) : '';
|
const savedSearchPath = savedSearchId ? `view/${encodeURIComponent(savedSearchId)}` : '';
|
||||||
const appState: {
|
const appState: {
|
||||||
query?: Query;
|
query?: Query;
|
||||||
filters?: Filter[];
|
filters?: Filter[];
|
||||||
|
|
|
@ -16,6 +16,5 @@ export default function ({ loadTestFile }: FtrProviderContext) {
|
||||||
loadTestFile(require.resolve('./error_handling'));
|
loadTestFile(require.resolve('./error_handling'));
|
||||||
loadTestFile(require.resolve('./visualize_field'));
|
loadTestFile(require.resolve('./visualize_field'));
|
||||||
loadTestFile(require.resolve('./value_suggestions'));
|
loadTestFile(require.resolve('./value_suggestions'));
|
||||||
loadTestFile(require.resolve('./async_search'));
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
* you may not use this file except in compliance with the Elastic License.
|
* you may not use this file except in compliance with the Elastic License.
|
||||||
*/
|
*/
|
||||||
import expect from '@kbn/expect';
|
import expect from '@kbn/expect';
|
||||||
import { FtrProviderContext } from '../../ftr_provider_context';
|
import { FtrProviderContext } from '../../../ftr_provider_context';
|
||||||
|
|
||||||
export default function ({ getPageObjects, getService }: FtrProviderContext) {
|
export default function ({ getPageObjects, getService }: FtrProviderContext) {
|
||||||
const esArchiver = getService('esArchiver');
|
const esArchiver = getService('esArchiver');
|
||||||
|
@ -31,14 +31,13 @@ export default function ({ getPageObjects, getService }: FtrProviderContext) {
|
||||||
expect(searchSessionId2).not.to.be(searchSessionId1);
|
expect(searchSessionId2).not.to.be(searchSessionId1);
|
||||||
});
|
});
|
||||||
|
|
||||||
// NOTE: this test will be revised when
|
it('search session id should be picked up from the URL, non existing session id errors out', async () => {
|
||||||
// `searchSessionId` functionality actually works
|
|
||||||
it('search session id should be picked up from the URL', async () => {
|
|
||||||
const url = await browser.getCurrentUrl();
|
const url = await browser.getCurrentUrl();
|
||||||
const fakeSearchSessionId = '__test__';
|
const fakeSearchSessionId = '__test__';
|
||||||
const savedSessionURL = url + `&searchSessionId=${fakeSearchSessionId}`;
|
const savedSessionURL = url + `&searchSessionId=${fakeSearchSessionId}`;
|
||||||
await browser.navigateTo(savedSessionURL);
|
await browser.navigateTo(savedSessionURL);
|
||||||
await PageObjects.header.waitUntilLoadingHasFinished();
|
await PageObjects.header.waitUntilLoadingHasFinished();
|
||||||
|
await testSubjects.existOrFail('discoverNoResultsError'); // expect error because of fake searchSessionId
|
||||||
const searchSessionId1 = await getSearchSessionId();
|
const searchSessionId1 = await getSearchSessionId();
|
||||||
expect(searchSessionId1).to.be(fakeSearchSessionId);
|
expect(searchSessionId1).to.be(fakeSearchSessionId);
|
||||||
await queryBar.clickQuerySubmitButton();
|
await queryBar.clickQuerySubmitButton();
|
|
@ -17,6 +17,7 @@ export default function ({ loadTestFile, getService }: FtrProviderContext) {
|
||||||
await kibanaServer.uiSettings.replace({ defaultIndex: 'logstash-*' });
|
await kibanaServer.uiSettings.replace({ defaultIndex: 'logstash-*' });
|
||||||
});
|
});
|
||||||
|
|
||||||
|
loadTestFile(require.resolve('./async_search'));
|
||||||
loadTestFile(require.resolve('./sessions_in_space'));
|
loadTestFile(require.resolve('./sessions_in_space'));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue