From 3b233f923757f5a85140f93ef1a4a061cf0b4c67 Mon Sep 17 00:00:00 2001 From: Liza K Date: Tue, 2 Feb 2021 16:35:58 +0200 Subject: [PATCH 1/9] Rename management button to "delete" --- .../{cancel_button.tsx => delete_button.tsx} | 32 +++++++++---------- .../components/actions/get_action.tsx | 6 ++-- .../components/actions/popover_actions.tsx | 2 +- .../sessions_mgmt/components/actions/types.ts | 2 +- .../public/search/sessions_mgmt/lib/api.ts | 2 +- .../search_sessions_management_page.ts | 4 +-- .../search_sessions/sessions_management.ts | 5 ++- 7 files changed, 26 insertions(+), 27 deletions(-) rename x-pack/plugins/data_enhanced/public/search/sessions_mgmt/components/actions/{cancel_button.tsx => delete_button.tsx} (70%) diff --git a/x-pack/plugins/data_enhanced/public/search/sessions_mgmt/components/actions/cancel_button.tsx b/x-pack/plugins/data_enhanced/public/search/sessions_mgmt/components/actions/delete_button.tsx similarity index 70% rename from x-pack/plugins/data_enhanced/public/search/sessions_mgmt/components/actions/cancel_button.tsx rename to x-pack/plugins/data_enhanced/public/search/sessions_mgmt/components/actions/delete_button.tsx index 8f4c8845de23..1d926e703d76 100644 --- a/x-pack/plugins/data_enhanced/public/search/sessions_mgmt/components/actions/cancel_button.tsx +++ b/x-pack/plugins/data_enhanced/public/search/sessions_mgmt/components/actions/delete_button.tsx @@ -12,31 +12,31 @@ import { SearchSessionsMgmtAPI } from '../../lib/api'; import { TableText } from '../'; import { OnActionComplete } from './types'; -interface CancelButtonProps { +interface DeleteButtonProps { id: string; name: string; api: SearchSessionsMgmtAPI; onActionComplete: OnActionComplete; } -const CancelConfirm = ({ - onConfirmDismiss, +const DeleteConfirm = ({ + onConfirmCancel, ...props -}: CancelButtonProps & { onConfirmDismiss: () => void }) => { +}: DeleteButtonProps & { onConfirmCancel: () => void }) => { const { id, name, api, onActionComplete } = props; const [isLoading, setIsLoading] = useState(false); const title = i18n.translate('xpack.data.mgmt.searchSessions.cancelModal.title', { - defaultMessage: 'Cancel search session', + defaultMessage: 'Delete search session', }); - const confirm = i18n.translate('xpack.data.mgmt.searchSessions.cancelModal.cancelButton', { - defaultMessage: 'Cancel', + const confirm = i18n.translate('xpack.data.mgmt.searchSessions.cancelModal.deleteButton', { + defaultMessage: 'Delete', }); - const cancel = i18n.translate('xpack.data.mgmt.searchSessions.cancelModal.dontCancelButton', { - defaultMessage: 'Dismiss', + const cancel = i18n.translate('xpack.data.mgmt.searchSessions.cancelModal.cancelButton', { + defaultMessage: 'Cancel', }); const message = i18n.translate('xpack.data.mgmt.searchSessions.cancelModal.message', { - defaultMessage: `Canceling the search session \'{name}\' will expire any cached results, so that quick restore will no longer be available. You will still be able to re-run it, using the reload action.`, + defaultMessage: `Deleting the search session \'{name}\' will expire any cached results.`, values: { name, }, @@ -46,7 +46,7 @@ const CancelConfirm = ({ { setIsLoading(true); await api.sendCancel(id); @@ -64,14 +64,14 @@ const CancelConfirm = ({ ); }; -export const CancelButton = (props: CancelButtonProps) => { +export const DeleteButton = (props: DeleteButtonProps) => { const [showConfirm, setShowConfirm] = useState(false); const onClick = () => { setShowConfirm(true); }; - const onConfirmDismiss = () => { + const onConfirmCancel = () => { setShowConfirm(false); }; @@ -79,11 +79,11 @@ export const CancelButton = (props: CancelButtonProps) => { <> - {showConfirm ? : null} + {showConfirm ? : null} ); }; diff --git a/x-pack/plugins/data_enhanced/public/search/sessions_mgmt/components/actions/get_action.tsx b/x-pack/plugins/data_enhanced/public/search/sessions_mgmt/components/actions/get_action.tsx index c80cf6c24489..c3695f09323b 100644 --- a/x-pack/plugins/data_enhanced/public/search/sessions_mgmt/components/actions/get_action.tsx +++ b/x-pack/plugins/data_enhanced/public/search/sessions_mgmt/components/actions/get_action.tsx @@ -9,7 +9,7 @@ import { IClickActionDescriptor } from '../'; import extendSessionIcon from '../../icons/extend_session.svg'; import { SearchSessionsMgmtAPI } from '../../lib/api'; import { UISession } from '../../types'; -import { CancelButton } from './cancel_button'; +import { DeleteButton } from './delete_button'; import { ExtendButton } from './extend_button'; import { ReloadButton } from './reload_button'; import { ACTION, OnActionComplete } from './types'; @@ -21,11 +21,11 @@ export const getAction = ( onActionComplete: OnActionComplete ): IClickActionDescriptor | null => { switch (actionType) { - case ACTION.CANCEL: + case ACTION.DELETE: return { iconType: 'crossInACircleFilled', textColor: 'default', - label: , + label: , }; case ACTION.RELOAD: diff --git a/x-pack/plugins/data_enhanced/public/search/sessions_mgmt/components/actions/popover_actions.tsx b/x-pack/plugins/data_enhanced/public/search/sessions_mgmt/components/actions/popover_actions.tsx index b9b915c0b17c..a23a138b1187 100644 --- a/x-pack/plugins/data_enhanced/public/search/sessions_mgmt/components/actions/popover_actions.tsx +++ b/x-pack/plugins/data_enhanced/public/search/sessions_mgmt/components/actions/popover_actions.tsx @@ -95,7 +95,7 @@ export const PopoverActionsMenu = ({ api, onActionComplete, session }: PopoverAc // add a line above the delete action (when there are multiple) // NOTE: Delete action MUST be the final action[] item - if (actions.length > 1 && actionType === ACTION.CANCEL) { + if (actions.length > 1 && actionType === ACTION.DELETE) { itemSet.push({ isSeparator: true, key: 'separadorable' }); } diff --git a/x-pack/plugins/data_enhanced/public/search/sessions_mgmt/components/actions/types.ts b/x-pack/plugins/data_enhanced/public/search/sessions_mgmt/components/actions/types.ts index 4b81fd7fda9a..c318df2b15f0 100644 --- a/x-pack/plugins/data_enhanced/public/search/sessions_mgmt/components/actions/types.ts +++ b/x-pack/plugins/data_enhanced/public/search/sessions_mgmt/components/actions/types.ts @@ -8,6 +8,6 @@ export type OnActionComplete = () => void; export enum ACTION { EXTEND = 'extend', - CANCEL = 'cancel', + DELETE = 'delete', RELOAD = 'reload', } diff --git a/x-pack/plugins/data_enhanced/public/search/sessions_mgmt/lib/api.ts b/x-pack/plugins/data_enhanced/public/search/sessions_mgmt/lib/api.ts index c6a3d088b3cd..0a3b3a47d5ac 100644 --- a/x-pack/plugins/data_enhanced/public/search/sessions_mgmt/lib/api.ts +++ b/x-pack/plugins/data_enhanced/public/search/sessions_mgmt/lib/api.ts @@ -24,7 +24,7 @@ function getActions(status: SearchSessionStatus) { actions.push(ACTION.RELOAD); if (status === SearchSessionStatus.IN_PROGRESS || status === SearchSessionStatus.COMPLETE) { actions.push(ACTION.EXTEND); - actions.push(ACTION.CANCEL); + actions.push(ACTION.DELETE); } return actions; } diff --git a/x-pack/test/functional/page_objects/search_sessions_management_page.ts b/x-pack/test/functional/page_objects/search_sessions_management_page.ts index 99c3be82a214..896fbd586172 100644 --- a/x-pack/test/functional/page_objects/search_sessions_management_page.ts +++ b/x-pack/test/functional/page_objects/search_sessions_management_page.ts @@ -45,10 +45,10 @@ export function SearchSessionsPageProvider({ getService, getPageObjects }: FtrPr '[data-test-subj="sessionManagementPopoverAction-reload"]' ); }, - cancel: async () => { + delete: async () => { await actionsCell.click(); await find.clickByCssSelector( - '[data-test-subj="sessionManagementPopoverAction-cancel"]' + '[data-test-subj="sessionManagementPopoverAction-delete"]' ); await PageObjects.common.clickConfirmOnModal(); }, diff --git a/x-pack/test/send_search_to_background_integration/tests/apps/management/search_sessions/sessions_management.ts b/x-pack/test/send_search_to_background_integration/tests/apps/management/search_sessions/sessions_management.ts index e3797550984a..769474a2ab44 100644 --- a/x-pack/test/send_search_to_background_integration/tests/apps/management/search_sessions/sessions_management.ts +++ b/x-pack/test/send_search_to_background_integration/tests/apps/management/search_sessions/sessions_management.ts @@ -78,15 +78,14 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) { await searchSessions.expectState('completed'); }); - it('Cancels a session from management', async () => { + it('Deletes a session from management', async () => { await PageObjects.searchSessionsManagement.goTo(); const searchSessionList = await PageObjects.searchSessionsManagement.getList(); expect(searchSessionList.length).to.be(1); - await searchSessionList[0].cancel(); + await searchSessionList[0].delete(); - // TODO: update this once canceling doesn't delete the object! await retry.waitFor(`wait for list to be empty`, async function () { const s = await PageObjects.searchSessionsManagement.getList(); From e75f2f870f82c413b498c92f550320d1dc22cf03 Mon Sep 17 00:00:00 2001 From: Liza K Date: Tue, 2 Feb 2021 18:48:00 +0200 Subject: [PATCH 2/9] fix jest --- .../data_enhanced/public/search/sessions_mgmt/lib/api.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/x-pack/plugins/data_enhanced/public/search/sessions_mgmt/lib/api.test.ts b/x-pack/plugins/data_enhanced/public/search/sessions_mgmt/lib/api.test.ts index 068225d0df8c..c8b51025f5e0 100644 --- a/x-pack/plugins/data_enhanced/public/search/sessions_mgmt/lib/api.test.ts +++ b/x-pack/plugins/data_enhanced/public/search/sessions_mgmt/lib/api.test.ts @@ -62,7 +62,7 @@ describe('Search Sessions Management API', () => { "actions": Array [ "reload", "extend", - "cancel", + "delete", ], "appId": "pizza", "created": undefined, From b4b985ef77b8c3b4bbed18ec1dfa72169da2e6fa Mon Sep 17 00:00:00 2001 From: Liza K Date: Tue, 2 Feb 2021 18:50:37 +0200 Subject: [PATCH 3/9] Delete reload action from management --- .../components/actions/get_action.tsx | 10 +----- .../components/actions/reload_button.tsx | 32 ------------------- .../sessions_mgmt/components/actions/types.ts | 1 - .../search/sessions_mgmt/lib/api.test.ts | 27 ---------------- .../public/search/sessions_mgmt/lib/api.ts | 1 - 5 files changed, 1 insertion(+), 70 deletions(-) delete mode 100644 x-pack/plugins/data_enhanced/public/search/sessions_mgmt/components/actions/reload_button.tsx diff --git a/x-pack/plugins/data_enhanced/public/search/sessions_mgmt/components/actions/get_action.tsx b/x-pack/plugins/data_enhanced/public/search/sessions_mgmt/components/actions/get_action.tsx index c3695f09323b..3b0602687729 100644 --- a/x-pack/plugins/data_enhanced/public/search/sessions_mgmt/components/actions/get_action.tsx +++ b/x-pack/plugins/data_enhanced/public/search/sessions_mgmt/components/actions/get_action.tsx @@ -11,13 +11,12 @@ import { SearchSessionsMgmtAPI } from '../../lib/api'; import { UISession } from '../../types'; import { DeleteButton } from './delete_button'; import { ExtendButton } from './extend_button'; -import { ReloadButton } from './reload_button'; import { ACTION, OnActionComplete } from './types'; export const getAction = ( api: SearchSessionsMgmtAPI, actionType: string, - { id, name, expires, reloadUrl }: UISession, + { id, name, expires }: UISession, onActionComplete: OnActionComplete ): IClickActionDescriptor | null => { switch (actionType) { @@ -28,13 +27,6 @@ export const getAction = ( label: , }; - case ACTION.RELOAD: - return { - iconType: 'refresh', - textColor: 'default', - label: , - }; - case ACTION.EXTEND: return { iconType: extendSessionIcon, diff --git a/x-pack/plugins/data_enhanced/public/search/sessions_mgmt/components/actions/reload_button.tsx b/x-pack/plugins/data_enhanced/public/search/sessions_mgmt/components/actions/reload_button.tsx deleted file mode 100644 index 9a98ab204477..000000000000 --- a/x-pack/plugins/data_enhanced/public/search/sessions_mgmt/components/actions/reload_button.tsx +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License; - * you may not use this file except in compliance with the Elastic License. - */ - -import { FormattedMessage } from '@kbn/i18n/react'; -import React from 'react'; -import { TableText } from '../'; -import { SearchSessionsMgmtAPI } from '../../lib/api'; - -interface ReloadButtonProps { - api: SearchSessionsMgmtAPI; - reloadUrl: string; -} - -export const ReloadButton = (props: ReloadButtonProps) => { - function onClick() { - props.api.reloadSearchSession(props.reloadUrl); - } - - return ( - <> - - - - - ); -}; diff --git a/x-pack/plugins/data_enhanced/public/search/sessions_mgmt/components/actions/types.ts b/x-pack/plugins/data_enhanced/public/search/sessions_mgmt/components/actions/types.ts index c318df2b15f0..be2e913a40b7 100644 --- a/x-pack/plugins/data_enhanced/public/search/sessions_mgmt/components/actions/types.ts +++ b/x-pack/plugins/data_enhanced/public/search/sessions_mgmt/components/actions/types.ts @@ -9,5 +9,4 @@ export type OnActionComplete = () => void; export enum ACTION { EXTEND = 'extend', DELETE = 'delete', - RELOAD = 'reload', } diff --git a/x-pack/plugins/data_enhanced/public/search/sessions_mgmt/lib/api.test.ts b/x-pack/plugins/data_enhanced/public/search/sessions_mgmt/lib/api.test.ts index c8b51025f5e0..b679043e6bce 100644 --- a/x-pack/plugins/data_enhanced/public/search/sessions_mgmt/lib/api.test.ts +++ b/x-pack/plugins/data_enhanced/public/search/sessions_mgmt/lib/api.test.ts @@ -60,7 +60,6 @@ describe('Search Sessions Management API', () => { Array [ Object { "actions": Array [ - "reload", "extend", "delete", ], @@ -166,32 +165,6 @@ describe('Search Sessions Management API', () => { }); }); - describe('reload', () => { - beforeEach(() => { - sessionsClient.find = jest.fn().mockImplementation(async () => { - return { - saved_objects: [ - { - id: 'hello-pizza-123', - attributes: { name: 'Veggie', appId: 'pizza', status: SearchSessionStatus.COMPLETE }, - }, - ], - } as SavedObjectsFindResponse; - }); - }); - - test('send cancel calls the cancel endpoint with a session ID', async () => { - const api = new SearchSessionsMgmtAPI(sessionsClient, mockConfig, { - urls: mockUrls, - notifications: mockCoreStart.notifications, - application: mockCoreStart.application, - }); - await api.reloadSearchSession('www.myurl.com'); - - expect(mockCoreStart.application.navigateToUrl).toHaveBeenCalledWith('www.myurl.com'); - }); - }); - describe('extend', () => { beforeEach(() => { sessionsClient.find = jest.fn().mockImplementation(async () => { diff --git a/x-pack/plugins/data_enhanced/public/search/sessions_mgmt/lib/api.ts b/x-pack/plugins/data_enhanced/public/search/sessions_mgmt/lib/api.ts index 0a3b3a47d5ac..805f8255b0f4 100644 --- a/x-pack/plugins/data_enhanced/public/search/sessions_mgmt/lib/api.ts +++ b/x-pack/plugins/data_enhanced/public/search/sessions_mgmt/lib/api.ts @@ -21,7 +21,6 @@ type UrlGeneratorsStart = SharePluginStart['urlGenerators']; function getActions(status: SearchSessionStatus) { const actions: ACTION[] = []; - actions.push(ACTION.RELOAD); if (status === SearchSessionStatus.IN_PROGRESS || status === SearchSessionStatus.COMPLETE) { actions.push(ACTION.EXTEND); actions.push(ACTION.DELETE); From 143d1d1c8147b65a65281e5cf76159ae8c36cd14 Mon Sep 17 00:00:00 2001 From: Liza K Date: Wed, 3 Feb 2021 18:02:58 +0200 Subject: [PATCH 4/9] Added both cancel and delete session --- .../data/server/search/search_service.ts | 13 ++++++++-- .../server/search/session/session_service.ts | 3 +++ .../data/server/search/session/types.ts | 1 + src/plugins/data/server/search/types.ts | 1 + .../server/routes/session.test.ts | 19 ++++++++++++-- .../data_enhanced/server/routes/session.ts | 23 ++++++++++++++++ .../server/search/session/session_service.ts | 6 +++++ .../api_integration/apis/search/session.ts | 26 +++++++++++++++++-- 8 files changed, 86 insertions(+), 6 deletions(-) diff --git a/src/plugins/data/server/search/search_service.ts b/src/plugins/data/server/search/search_service.ts index 34aefe33e440..553fef23552f 100644 --- a/src/plugins/data/server/search/search_service.ts +++ b/src/plugins/data/server/search/search_service.ts @@ -308,9 +308,8 @@ export class SearchService implements Plugin { return strategy.extend(id, keepAlive, options, deps); }; - private cancelSession = async (deps: SearchStrategyDependencies, sessionId: string) => { + private cancelSessionSearches = async (deps: SearchStrategyDependencies, sessionId: string) => { const searchIdMapping = await deps.searchSessionsClient.getSearchIdMapping(sessionId); - const response = await deps.searchSessionsClient.cancel(sessionId); for (const [searchId, strategyName] of searchIdMapping.entries()) { const searchOptions = { @@ -320,10 +319,19 @@ export class SearchService implements Plugin { }; this.cancel(deps, searchId, searchOptions); } + }; + private cancelSession = async (deps: SearchStrategyDependencies, sessionId: string) => { + const response = await deps.searchSessionsClient.cancel(sessionId); + this.cancelSessionSearches(deps, sessionId); return response; }; + private deleteSession = async (deps: SearchStrategyDependencies, sessionId: string) => { + this.cancelSessionSearches(deps, sessionId); + const response = await deps.searchSessionsClient.delete(sessionId); + }; + private extendSession = async ( deps: SearchStrategyDependencies, sessionId: string, @@ -373,6 +381,7 @@ export class SearchService implements Plugin { updateSession: searchSessionsClient.update, extendSession: this.extendSession.bind(this, deps), cancelSession: this.cancelSession.bind(this, deps), + deleteSession: this.deleteSession.bind(this, deps), }; }; }; diff --git a/src/plugins/data/server/search/session/session_service.ts b/src/plugins/data/server/search/session/session_service.ts index dc4f19f12688..31b4068e76dc 100644 --- a/src/plugins/data/server/search/session/session_service.ts +++ b/src/plugins/data/server/search/session/session_service.ts @@ -41,6 +41,9 @@ export class SearchSessionService implements ISearchSessionService { cancel: async () => { throw new Error('cancel not implemented in OSS search session service'); }, + delete: async () => { + throw new Error('delete not implemented in OSS search session service'); + }, }); } } diff --git a/src/plugins/data/server/search/session/types.ts b/src/plugins/data/server/search/session/types.ts index 3c074955a108..34e77eed9f5e 100644 --- a/src/plugins/data/server/search/session/types.ts +++ b/src/plugins/data/server/search/session/types.ts @@ -29,6 +29,7 @@ export interface IScopedSearchSessionsClient { find: (options: Omit) => Promise>; update: (sessionId: string, attributes: Partial) => Promise>; cancel: (sessionId: string) => Promise<{}>; + delete: (sessionId: string) => Promise<{}>; extend: (sessionId: string, expires: Date) => Promise>; } diff --git a/src/plugins/data/server/search/types.ts b/src/plugins/data/server/search/types.ts index ff3844c3d115..855af56cd8dd 100644 --- a/src/plugins/data/server/search/types.ts +++ b/src/plugins/data/server/search/types.ts @@ -92,6 +92,7 @@ export interface IScopedSearchClient extends ISearchClient { findSessions: IScopedSearchSessionsClient['find']; updateSession: IScopedSearchSessionsClient['update']; cancelSession: IScopedSearchSessionsClient['cancel']; + deleteSession: IScopedSearchSessionsClient['delete']; extendSession: IScopedSearchSessionsClient['extend']; } diff --git a/x-pack/plugins/data_enhanced/server/routes/session.test.ts b/x-pack/plugins/data_enhanced/server/routes/session.test.ts index 6af7618e43d9..a2c215df54d8 100644 --- a/x-pack/plugins/data_enhanced/server/routes/session.test.ts +++ b/x-pack/plugins/data_enhanced/server/routes/session.test.ts @@ -95,7 +95,22 @@ describe('registerSessionRoutes', () => { expect(mockContext.search!.updateSession).toHaveBeenCalledWith(id, body); }); - it('delete calls cancelSession with id', async () => { + it('cancel calls cancelSession with id', async () => { + const id = 'd7170a35-7e2c-48d6-8dec-9a056721b489'; + const params = { id }; + + const mockRequest = httpServerMock.createKibanaRequest({ params }); + const mockResponse = httpServerMock.createResponseFactory(); + + const mockRouter = mockCoreSetup.http.createRouter.mock.results[0].value; + const [[, cancelHandler]] = mockRouter.cancel.mock.calls; + + cancelHandler(mockContext, mockRequest, mockResponse); + + expect(mockContext.search!.cancelSession).toHaveBeenCalledWith(id); + }); + + it('delete calls deleteSession with id', async () => { const id = 'd7170a35-7e2c-48d6-8dec-9a056721b489'; const params = { id }; @@ -107,7 +122,7 @@ describe('registerSessionRoutes', () => { deleteHandler(mockContext, mockRequest, mockResponse); - expect(mockContext.search!.cancelSession).toHaveBeenCalledWith(id); + expect(mockContext.search!.deleteSession).toHaveBeenCalledWith(id); }); it('extend calls extendSession with id', async () => { diff --git a/x-pack/plugins/data_enhanced/server/routes/session.ts b/x-pack/plugins/data_enhanced/server/routes/session.ts index b39ffd41f33c..12cb911dc1a7 100644 --- a/x-pack/plugins/data_enhanced/server/routes/session.ts +++ b/x-pack/plugins/data_enhanced/server/routes/session.ts @@ -124,6 +124,29 @@ export function registerSessionRoutes(router: DataEnhancedPluginRouter, logger: }), }, }, + async (context, request, res) => { + const { id } = request.params; + try { + await context.search!.deleteSession(id); + + return res.ok(); + } catch (e) { + const err = e.output?.payload || e; + logger.error(err); + return reportServerError(res, err); + } + } + ); + + router.post( + { + path: '/internal/session/{id}/cancel', + validate: { + params: schema.object({ + id: schema.string(), + }), + }, + }, async (context, request, res) => { const { id } = request.params; try { diff --git a/x-pack/plugins/data_enhanced/server/search/session/session_service.ts b/x-pack/plugins/data_enhanced/server/search/session/session_service.ts index 03466c769d9b..71252ccc5f6d 100644 --- a/x-pack/plugins/data_enhanced/server/search/session/session_service.ts +++ b/x-pack/plugins/data_enhanced/server/search/session/session_service.ts @@ -315,6 +315,11 @@ export class SearchSessionService }); }; + // TODO: Throw an error if this session doesn't belong to this user + public delete = ({ savedObjectsClient }: SearchSessionDependencies, sessionId: string) => { + return savedObjectsClient.delete(SEARCH_SESSION_TYPE, sessionId); + }; + /** * Tracks the given search request/search ID in the saved session (if it exists). Otherwise, just * store it in memory until a saved session exists. @@ -397,6 +402,7 @@ export class SearchSessionService update: this.update.bind(this, deps), extend: this.extend.bind(this, deps), cancel: this.cancel.bind(this, deps), + delete: this.delete.bind(this, deps), }; }; }; diff --git a/x-pack/test/api_integration/apis/search/session.ts b/x-pack/test/api_integration/apis/search/session.ts index 96d601a00ff3..3daff0efe718 100644 --- a/x-pack/test/api_integration/apis/search/session.ts +++ b/x-pack/test/api_integration/apis/search/session.ts @@ -30,11 +30,11 @@ export default function ({ getService }: FtrProviderContext) { await supertest.get(`/internal/session/${sessionId}`).set('kbn-xsrf', 'foo').expect(200); }); - it('should fail to cancel an unknown session', async () => { + it('should fail to delete an unknown session', async () => { await supertest.delete(`/internal/session/123`).set('kbn-xsrf', 'foo').expect(404); }); - it('should create and cancel a session', async () => { + it('should create and delete a session', async () => { const sessionId = `my-session-${Math.random()}`; await supertest .post(`/internal/session`) @@ -50,6 +50,28 @@ export default function ({ getService }: FtrProviderContext) { await supertest.delete(`/internal/session/${sessionId}`).set('kbn-xsrf', 'foo').expect(200); + await supertest.get(`/internal/session/${sessionId}`).set('kbn-xsrf', 'foo').expect(404); + }); + + it('should create and cancel a session', async () => { + const sessionId = `my-session-${Math.random()}`; + await supertest + .post(`/internal/session`) + .set('kbn-xsrf', 'foo') + .send({ + sessionId, + name: 'My Session', + appId: 'discover', + expires: '123', + urlGeneratorId: 'discover', + }) + .expect(200); + + await supertest + .post(`/internal/session/${sessionId}/cancel`) + .set('kbn-xsrf', 'foo') + .expect(200); + const resp = await supertest .get(`/internal/session/${sessionId}`) .set('kbn-xsrf', 'foo') From 61ef149be726fa44efdf5d2b16345223c04a2908 Mon Sep 17 00:00:00 2001 From: Liza K Date: Wed, 3 Feb 2021 18:05:10 +0200 Subject: [PATCH 5/9] Improve texts --- .../sessions_mgmt/components/actions/delete_button.tsx | 2 +- .../public/search/sessions_mgmt/lib/api.test.ts | 2 +- .../data_enhanced/public/search/sessions_mgmt/lib/api.ts | 8 ++++---- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/x-pack/plugins/data_enhanced/public/search/sessions_mgmt/components/actions/delete_button.tsx b/x-pack/plugins/data_enhanced/public/search/sessions_mgmt/components/actions/delete_button.tsx index 1d926e703d76..024bcc7e48e3 100644 --- a/x-pack/plugins/data_enhanced/public/search/sessions_mgmt/components/actions/delete_button.tsx +++ b/x-pack/plugins/data_enhanced/public/search/sessions_mgmt/components/actions/delete_button.tsx @@ -36,7 +36,7 @@ const DeleteConfirm = ({ defaultMessage: 'Cancel', }); const message = i18n.translate('xpack.data.mgmt.searchSessions.cancelModal.message', { - defaultMessage: `Deleting the search session \'{name}\' will expire any cached results.`, + defaultMessage: `Deleting the search session \'{name}\' deletes all cached results.`, values: { name, }, diff --git a/x-pack/plugins/data_enhanced/public/search/sessions_mgmt/lib/api.test.ts b/x-pack/plugins/data_enhanced/public/search/sessions_mgmt/lib/api.test.ts index b679043e6bce..0a361a5f7825 100644 --- a/x-pack/plugins/data_enhanced/public/search/sessions_mgmt/lib/api.test.ts +++ b/x-pack/plugins/data_enhanced/public/search/sessions_mgmt/lib/api.test.ts @@ -144,7 +144,7 @@ describe('Search Sessions Management API', () => { await api.sendCancel('abc-123-cool-session-ID'); expect(mockCoreStart.notifications.toasts.addSuccess).toHaveBeenCalledWith({ - title: 'The search session was canceled and expired.', + title: 'The search session was deleted.', }); }); diff --git a/x-pack/plugins/data_enhanced/public/search/sessions_mgmt/lib/api.ts b/x-pack/plugins/data_enhanced/public/search/sessions_mgmt/lib/api.ts index 805f8255b0f4..30bc474c0271 100644 --- a/x-pack/plugins/data_enhanced/public/search/sessions_mgmt/lib/api.ts +++ b/x-pack/plugins/data_enhanced/public/search/sessions_mgmt/lib/api.ts @@ -159,8 +159,8 @@ export class SearchSessionsMgmtAPI { await this.sessionsClient.delete(id); this.deps.notifications.toasts.addSuccess({ - title: i18n.translate('xpack.data.mgmt.searchSessions.api.canceled', { - defaultMessage: 'The search session was canceled and expired.', + title: i18n.translate('xpack.data.mgmt.searchSessions.api.deleted', { + defaultMessage: 'The search session was deleted.', }), }); } catch (err) { @@ -168,8 +168,8 @@ export class SearchSessionsMgmtAPI { console.error(err); this.deps.notifications.toasts.addError(err, { - title: i18n.translate('xpack.data.mgmt.searchSessions.api.cancelError', { - defaultMessage: 'Failed to cancel the search session!', + title: i18n.translate('xpack.data.mgmt.searchSessions.api.deletedError', { + defaultMessage: 'Failed to delete the search session!', }), }); } From 76ba1eee45ebd075a57484d6b917fdbad9eb34ed Mon Sep 17 00:00:00 2001 From: Liza K Date: Wed, 3 Feb 2021 23:22:15 +0200 Subject: [PATCH 6/9] fix test --- .../data_enhanced/public/search/sessions_mgmt/lib/api.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/x-pack/plugins/data_enhanced/public/search/sessions_mgmt/lib/api.test.ts b/x-pack/plugins/data_enhanced/public/search/sessions_mgmt/lib/api.test.ts index 0a361a5f7825..ff64b4e7d882 100644 --- a/x-pack/plugins/data_enhanced/public/search/sessions_mgmt/lib/api.test.ts +++ b/x-pack/plugins/data_enhanced/public/search/sessions_mgmt/lib/api.test.ts @@ -160,7 +160,7 @@ describe('Search Sessions Management API', () => { expect(mockCoreStart.notifications.toasts.addError).toHaveBeenCalledWith( new Error('implementation is so bad'), - { title: 'Failed to cancel the search session!' } + { title: 'Failed to delete the search session!' } ); }); }); From 51cfd6a9d5f06786fffa4022c731f824cfe25f86 Mon Sep 17 00:00:00 2001 From: Liza K Date: Wed, 3 Feb 2021 23:24:44 +0200 Subject: [PATCH 7/9] ts --- src/plugins/data/server/search/search_service.ts | 2 +- src/plugins/data/server/search/session/mocks.ts | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/plugins/data/server/search/search_service.ts b/src/plugins/data/server/search/search_service.ts index e756016f61d5..e1be1e64fd6e 100644 --- a/src/plugins/data/server/search/search_service.ts +++ b/src/plugins/data/server/search/search_service.ts @@ -328,7 +328,7 @@ export class SearchService implements Plugin { private deleteSession = async (deps: SearchStrategyDependencies, sessionId: string) => { this.cancelSessionSearches(deps, sessionId); - const response = await deps.searchSessionsClient.delete(sessionId); + return deps.searchSessionsClient.delete(sessionId); }; private extendSession = async ( diff --git a/src/plugins/data/server/search/session/mocks.ts b/src/plugins/data/server/search/session/mocks.ts index f75ba6fcc662..aab5e93d31d3 100644 --- a/src/plugins/data/server/search/session/mocks.ts +++ b/src/plugins/data/server/search/session/mocks.ts @@ -21,5 +21,6 @@ export function createSearchSessionsClientMock(): jest.Mocked< update: jest.fn(), cancel: jest.fn(), extend: jest.fn(), + delete: jest.fn(), }; } From 1d165c25ce980d4affc3ec8419a750cd55370922 Mon Sep 17 00:00:00 2001 From: Liza K Date: Wed, 3 Feb 2021 23:46:19 +0200 Subject: [PATCH 8/9] doc --- src/plugins/data/server/server.api.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/plugins/data/server/server.api.md b/src/plugins/data/server/server.api.md index beda5b3cea97..68582a9d877e 100644 --- a/src/plugins/data/server/server.api.md +++ b/src/plugins/data/server/server.api.md @@ -1254,6 +1254,7 @@ export class SearchSessionService implements ISearchSessionService { update: () => Promise; extend: () => Promise; cancel: () => Promise; + delete: () => Promise; }; } @@ -1430,7 +1431,7 @@ export function usageProvider(core: CoreSetup_2): SearchUsage; // src/plugins/data/server/index.ts:266:1 - (ae-forgotten-export) The symbol "calcAutoIntervalLessThan" needs to be exported by the entry point index.d.ts // src/plugins/data/server/index_patterns/index_patterns_service.ts:59:14 - (ae-forgotten-export) The symbol "IndexPatternsService" needs to be exported by the entry point index.d.ts // src/plugins/data/server/plugin.ts:79:74 - (ae-forgotten-export) The symbol "DataEnhancements" needs to be exported by the entry point index.d.ts -// src/plugins/data/server/search/types.ts:113:5 - (ae-forgotten-export) The symbol "ISearchStartSearchSource" needs to be exported by the entry point index.d.ts +// src/plugins/data/server/search/types.ts:114:5 - (ae-forgotten-export) The symbol "ISearchStartSearchSource" needs to be exported by the entry point index.d.ts // (No @packageDocumentation comment for this package) From 182b21c34f406fbfd2648e395b60c327fb532e8b Mon Sep 17 00:00:00 2001 From: Liza K Date: Thu, 4 Feb 2021 14:39:45 +0200 Subject: [PATCH 9/9] fix jest --- src/plugins/data/server/search/mocks.ts | 1 + .../server/routes/session.test.ts | 21 ++++++++++++------- 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/src/plugins/data/server/search/mocks.ts b/src/plugins/data/server/search/mocks.ts index e32e3326dede..248487f216a5 100644 --- a/src/plugins/data/server/search/mocks.ts +++ b/src/plugins/data/server/search/mocks.ts @@ -40,5 +40,6 @@ export function createSearchRequestHandlerContext() { updateSession: jest.fn(), extendSession: jest.fn(), cancelSession: jest.fn(), + deleteSession: jest.fn(), }; } diff --git a/x-pack/plugins/data_enhanced/server/routes/session.test.ts b/x-pack/plugins/data_enhanced/server/routes/session.test.ts index e3aea49496be..ebc501346aed 100644 --- a/x-pack/plugins/data_enhanced/server/routes/session.test.ts +++ b/x-pack/plugins/data_enhanced/server/routes/session.test.ts @@ -16,6 +16,13 @@ import type { import { dataPluginMock } from '../../../../../src/plugins/data/server/mocks'; import { registerSessionRoutes } from './session'; +enum PostHandlerIndex { + SAVE, + FIND, + CANCEL, + EXTEND, +} + describe('registerSessionRoutes', () => { let mockCoreSetup: MockedKeys>; let mockContext: jest.Mocked; @@ -37,7 +44,7 @@ describe('registerSessionRoutes', () => { const mockResponse = httpServerMock.createResponseFactory(); const mockRouter = mockCoreSetup.http.createRouter.mock.results[0].value; - const [[, saveHandler]] = mockRouter.post.mock.calls; + const [, saveHandler] = mockRouter.post.mock.calls[PostHandlerIndex.SAVE]; saveHandler(mockContext, mockRequest, mockResponse); @@ -71,7 +78,7 @@ describe('registerSessionRoutes', () => { const mockResponse = httpServerMock.createResponseFactory(); const mockRouter = mockCoreSetup.http.createRouter.mock.results[0].value; - const [, [, findHandler]] = mockRouter.post.mock.calls; + const [, findHandler] = mockRouter.post.mock.calls[PostHandlerIndex.FIND]; findHandler(mockContext, mockRequest, mockResponse); @@ -89,7 +96,7 @@ describe('registerSessionRoutes', () => { const mockResponse = httpServerMock.createResponseFactory(); const mockRouter = mockCoreSetup.http.createRouter.mock.results[0].value; - const [[, updateHandler]] = mockRouter.put.mock.calls; + const [, updateHandler] = mockRouter.put.mock.calls[0]; updateHandler(mockContext, mockRequest, mockResponse); @@ -104,7 +111,7 @@ describe('registerSessionRoutes', () => { const mockResponse = httpServerMock.createResponseFactory(); const mockRouter = mockCoreSetup.http.createRouter.mock.results[0].value; - const [[, cancelHandler]] = mockRouter.cancel.mock.calls; + const [, cancelHandler] = mockRouter.post.mock.calls[PostHandlerIndex.CANCEL]; cancelHandler(mockContext, mockRequest, mockResponse); @@ -119,9 +126,9 @@ describe('registerSessionRoutes', () => { const mockResponse = httpServerMock.createResponseFactory(); const mockRouter = mockCoreSetup.http.createRouter.mock.results[0].value; - const [[, deleteHandler]] = mockRouter.delete.mock.calls; + const [, deleteHandler] = mockRouter.delete.mock.calls[0]; - deleteHandler(mockContext, mockRequest, mockResponse); + await deleteHandler(mockContext, mockRequest, mockResponse); expect(mockContext.search!.deleteSession).toHaveBeenCalledWith(id); }); @@ -136,7 +143,7 @@ describe('registerSessionRoutes', () => { const mockResponse = httpServerMock.createResponseFactory(); const mockRouter = mockCoreSetup.http.createRouter.mock.results[0].value; - const [, , [, extendHandler]] = mockRouter.post.mock.calls; + const [, extendHandler] = mockRouter.post.mock.calls[PostHandlerIndex.EXTEND]; extendHandler(mockContext, mockRequest, mockResponse);