From dfd35c6361be6426468ca6cd4e2bfe20b7978774 Mon Sep 17 00:00:00 2001 From: Angela Chuang <6295984+angorayc@users.noreply.github.com> Date: Wed, 4 Oct 2023 09:58:29 +0100 Subject: [PATCH] [SecuritySolution] It should return to the origin app and path after editing markdown from the dashboard (#167927) ## Summary issue: https://github.com/elastic/kibana/issues/167786 In this PR: https://github.com/elastic/kibana/assets/6295984/a35bd617-5805-4e60-a1e6-7ba559756ef0 ### Checklist Delete any items that are not applicable to this PR. - [x] [Unit or functional tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html) were updated or added to match the most common scenarios Co-authored-by: Stratoula Kalafateli --- .../utils/get_top_nav_config.test.tsx | 43 +++++++++++++++++++ .../utils/get_top_nav_config.tsx | 2 +- 2 files changed, 44 insertions(+), 1 deletion(-) diff --git a/src/plugins/visualizations/public/visualize_app/utils/get_top_nav_config.test.tsx b/src/plugins/visualizations/public/visualize_app/utils/get_top_nav_config.test.tsx index 909e3029db48d..edcff40f4763a 100644 --- a/src/plugins/visualizations/public/visualize_app/utils/get_top_nav_config.test.tsx +++ b/src/plugins/visualizations/public/visualize_app/utils/get_top_nav_config.test.tsx @@ -224,6 +224,49 @@ describe('getTopNavConfig', () => { ] `); }); + + test('navigates to origin app and path on cancel', async () => { + const vis = { + savedVis: { + id: 'test', + sharingSavedObjectProps: { + outcome: 'conflict', + aliasTargetId: 'alias_id', + }, + }, + vis: { + type: { + title: 'TSVB', + }, + }, + } as VisualizeEditorVisInstance; + const mockNavigateToApp = jest.fn(); + const topNavLinks = getTopNavConfig( + { + hasUnsavedChanges: false, + setHasUnsavedChanges: jest.fn(), + hasUnappliedChanges: false, + onOpenInspector: jest.fn(), + originatingApp: 'testApp', + originatingPath: '/testPath', + setOriginatingApp: jest.fn(), + visInstance: vis, + stateContainer, + visualizationIdFromUrl: undefined, + stateTransfer: createEmbeddableStateTransferMock(), + } as unknown as TopNavConfigParams, + { + ...services, + application: { navigateToApp: mockNavigateToApp }, + } as unknown as VisualizeServices + ); + + const executionFunction = topNavLinks.find(({ id }) => id === 'cancel')?.run; + const mockAnchorElement = document.createElement('div'); + await executionFunction?.(mockAnchorElement); + expect(mockNavigateToApp).toHaveBeenCalledWith('testApp', { path: '/testPath' }); + }); + test('returns correct links for by reference visualization', () => { const vis = { savedVis: { diff --git a/src/plugins/visualizations/public/visualize_app/utils/get_top_nav_config.tsx b/src/plugins/visualizations/public/visualize_app/utils/get_top_nav_config.tsx index 49ebc45833376..064e281f8c269 100644 --- a/src/plugins/visualizations/public/visualize_app/utils/get_top_nav_config.tsx +++ b/src/plugins/visualizations/public/visualize_app/utils/get_top_nav_config.tsx @@ -258,7 +258,7 @@ export const getTopNavConfig = ( const navigateToOriginatingApp = () => { if (originatingApp) { - application.navigateToApp(originatingApp); + application.navigateToApp(originatingApp, { path: originatingPath }); } };