From b6d58da8ce1fce02eedf74ce938f2ed662626abd Mon Sep 17 00:00:00 2001 From: Jusheng Huang <117657272+viajes7@users.noreply.github.com> Date: Fri, 22 Nov 2024 02:35:59 +0800 Subject: [PATCH] [Index Management] Fix ILM policy link trigger an SPA friendly navigation (#199252) ## Summary Close #87876 Use `core.application.navigateToUrl` navigate to given URL in a SPA friendly. https://github.com/user-attachments/assets/1918eb3d-fbec-46d9-8eae-b4a26ebd36a2 --- .../home/data_streams_tab.test.ts | 2 +- .../data_stream_detail_panel.tsx | 16 ++++++++++++---- .../edit_data_retention_modal.tsx | 7 ++++++- .../template_details/tabs/tab_summary.tsx | 6 ++++-- 4 files changed, 23 insertions(+), 8 deletions(-) diff --git a/x-pack/plugins/index_management/__jest__/client_integration/home/data_streams_tab.test.ts b/x-pack/plugins/index_management/__jest__/client_integration/home/data_streams_tab.test.ts index 1d7ee65790cfd..3bc122ad867f6 100644 --- a/x-pack/plugins/index_management/__jest__/client_integration/home/data_streams_tab.test.ts +++ b/x-pack/plugins/index_management/__jest__/client_integration/home/data_streams_tab.test.ts @@ -812,7 +812,7 @@ describe('Data Streams tab', () => { const { actions, findDetailPanelIlmPolicyLink } = testBed; await actions.clickNameAt(0); - expect(findDetailPanelIlmPolicyLink().prop('href')).toBe('/test/my_ilm_policy'); + expect(findDetailPanelIlmPolicyLink().prop('data-href')).toBe('/test/my_ilm_policy'); }); test('with an ILM url locator and no ILM policy', async () => { diff --git a/x-pack/plugins/index_management/public/application/sections/home/data_stream_list/data_stream_detail_panel/data_stream_detail_panel.tsx b/x-pack/plugins/index_management/public/application/sections/home/data_stream_list/data_stream_detail_panel/data_stream_detail_panel.tsx index d962305a7147c..10ef17c566241 100644 --- a/x-pack/plugins/index_management/public/application/sections/home/data_stream_list/data_stream_detail_panel/data_stream_detail_panel.tsx +++ b/x-pack/plugins/index_management/public/application/sections/home/data_stream_list/data_stream_detail_panel/data_stream_detail_panel.tsx @@ -131,7 +131,7 @@ export const DataStreamDetailPanel: React.FunctionComponent = ({ const { error, data: dataStream, isLoading } = useLoadDataStream(dataStreamName); const ilmPolicyLink = useIlmLocator(ILM_PAGES_POLICY_EDIT, dataStream?.ilmPolicyName); - const { history, config } = useAppContext(); + const { history, config, core } = useAppContext(); let indicesLink; let content; @@ -193,7 +193,11 @@ export const DataStreamDetailPanel: React.FunctionComponent = ({ > <> {ilmPolicyLink ? ( - + core.application.navigateToUrl(ilmPolicyLink)} + > {ilmPolicyName} ) : ( @@ -204,7 +208,11 @@ export const DataStreamDetailPanel: React.FunctionComponent = ({ ) : ( <> {ilmPolicyLink ? ( - + core.application.navigateToUrl(ilmPolicyLink)} + > {ilmPolicyName} ) : ( @@ -429,7 +437,7 @@ export const DataStreamDetailPanel: React.FunctionComponent = ({ defaultMessage="To edit data retention for this data stream, you must edit its associated {link}." values={{ link: ( - + core.application.navigateToUrl(ilmPolicyLink)}> { + const { core } = useAppContext(); + return ( + core.application.navigateToUrl(ilmPolicyLink)} + > {ilmPolicyName} ), diff --git a/x-pack/plugins/index_management/public/application/sections/home/template_list/template_details/tabs/tab_summary.tsx b/x-pack/plugins/index_management/public/application/sections/home/template_list/template_details/tabs/tab_summary.tsx index 2621f3ec483c1..eed3335d01431 100644 --- a/x-pack/plugins/index_management/public/application/sections/home/template_list/template_details/tabs/tab_summary.tsx +++ b/x-pack/plugins/index_management/public/application/sections/home/template_list/template_details/tabs/tab_summary.tsx @@ -63,7 +63,7 @@ export const TabSummary: React.FunctionComponent = ({ templateDetails }) const numIndexPatterns = indexPatterns.length; - const { history } = useAppContext(); + const { history, core } = useAppContext(); const ilmPolicyLink = useIlmLocator(ILM_PAGES_POLICY_EDIT, ilmPolicy?.name); return ( @@ -171,7 +171,9 @@ export const TabSummary: React.FunctionComponent = ({ templateDetails }) {ilmPolicy?.name && ilmPolicyLink ? ( - {ilmPolicy!.name} + core.application.navigateToUrl(ilmPolicyLink)}> + {ilmPolicy!.name} + ) : ( ilmPolicy?.name || i18nTexts.none )}