From 4dc098678751b59d78426cc865ac1b60ce07068a Mon Sep 17 00:00:00 2001 From: Alison Goryachev Date: Thu, 9 Jul 2020 11:59:04 -0400 Subject: [PATCH] [Index Management] Fix broken app links (#71007) (#71241) --- .../components/policy_table/policy_table.js | 2 +- .../helpers/setup_environment.tsx | 6 ++++- .../public/application/sections/home/home.tsx | 1 - .../index_list/index_table/index_table.js | 2 +- .../template_details/tabs/tab_summary.tsx | 15 +++++++++++-- .../public/application/services/navigation.ts | 21 ------------------ .../public/application/services/routing.ts | 22 +++++++++++++++++++ .../plugins/index_management/public/index.ts | 2 +- 8 files changed, 43 insertions(+), 28 deletions(-) delete mode 100644 x-pack/plugins/index_management/public/application/services/navigation.ts diff --git a/x-pack/plugins/index_lifecycle_management/public/application/sections/policy_table/components/policy_table/policy_table.js b/x-pack/plugins/index_lifecycle_management/public/application/sections/policy_table/components/policy_table/policy_table.js index dad259681eb7aa..500ab44d966941 100644 --- a/x-pack/plugins/index_lifecycle_management/public/application/sections/policy_table/components/policy_table/policy_table.js +++ b/x-pack/plugins/index_lifecycle_management/public/application/sections/policy_table/components/policy_table/policy_table.js @@ -254,7 +254,7 @@ export class PolicyTable extends Component { icon: 'list', onClick: () => { this.props.navigateToApp('management', { - path: `/data/index_management${getIndexListUri(`ilm.policy:${policy.name}`)}`, + path: `/data/index_management${getIndexListUri(`ilm.policy:${policy.name}`, true)}`, }); }, }); diff --git a/x-pack/plugins/index_management/__jest__/client_integration/helpers/setup_environment.tsx b/x-pack/plugins/index_management/__jest__/client_integration/helpers/setup_environment.tsx index d85db94d4a970c..ad445f75f047c1 100644 --- a/x-pack/plugins/index_management/__jest__/client_integration/helpers/setup_environment.tsx +++ b/x-pack/plugins/index_management/__jest__/client_integration/helpers/setup_environment.tsx @@ -34,7 +34,11 @@ export const services = { services.uiMetricService.setup({ reportUiStats() {} } as any); setExtensionsService(services.extensionsService); setUiMetricService(services.uiMetricService); -const appDependencies = { services, core: { getUrlForApp: () => {} }, plugins: {} } as any; +const appDependencies = { + services, + core: { getUrlForApp: () => {} }, + plugins: {}, +} as any; export const setupEnvironment = () => { // Mock initialization of services diff --git a/x-pack/plugins/index_management/public/application/sections/home/home.tsx b/x-pack/plugins/index_management/public/application/sections/home/home.tsx index 7bd04cdbf0c91f..ee8970a3c45097 100644 --- a/x-pack/plugins/index_management/public/application/sections/home/home.tsx +++ b/x-pack/plugins/index_management/public/application/sections/home/home.tsx @@ -144,7 +144,6 @@ export const IndexManagementHome: React.FunctionComponent - index.name); const selectedIndexNames = Object.keys(selectedIndicesMap); 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 fe6c9ad3d8e071..de2fc29ec85435 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 @@ -18,8 +18,9 @@ import { EuiFlexItem, EuiCodeBlock, } from '@elastic/eui'; +import { useAppContext } from '../../../../../app_context'; import { TemplateDeserialized } from '../../../../../../../common'; -import { getILMPolicyPath } from '../../../../../services/navigation'; +import { getILMPolicyPath } from '../../../../../services/routing'; interface Props { templateDetails: TemplateDeserialized; @@ -51,6 +52,10 @@ export const TabSummary: React.FunctionComponent = ({ templateDetails }) const numIndexPatterns = indexPatterns.length; + const { + core: { getUrlForApp }, + } = useAppContext(); + return ( @@ -153,7 +158,13 @@ export const TabSummary: React.FunctionComponent = ({ templateDetails }) {ilmPolicy && ilmPolicy.name ? ( - {ilmPolicy.name} + + {ilmPolicy.name} + ) : ( i18nTexts.none )} diff --git a/x-pack/plugins/index_management/public/application/services/navigation.ts b/x-pack/plugins/index_management/public/application/services/navigation.ts deleted file mode 100644 index 3b4977bb637514..00000000000000 --- a/x-pack/plugins/index_management/public/application/services/navigation.ts +++ /dev/null @@ -1,21 +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. - */ - -export const getIndexListUri = (filter: any) => { - if (filter) { - // React router tries to decode url params but it can't because the browser partially - // decodes them. So we have to encode both the URL and the filter to get it all to - // work correctly for filters with URL unsafe characters in them. - return encodeURI(`/indices/filter/${encodeURIComponent(filter)}`); - } - - // If no filter, URI is already safe so no need to encode. - return '/indices'; -}; - -export const getILMPolicyPath = (policyName: string) => { - return encodeURI(`/policies/edit/${encodeURIComponent(policyName)}`); -}; diff --git a/x-pack/plugins/index_management/public/application/services/routing.ts b/x-pack/plugins/index_management/public/application/services/routing.ts index 8831fa2368f471..68bf06409e6ab5 100644 --- a/x-pack/plugins/index_management/public/application/services/routing.ts +++ b/x-pack/plugins/index_management/public/application/services/routing.ts @@ -31,6 +31,28 @@ export const getTemplateCloneLink = (name: string, isLegacy?: boolean) => { return encodeURI(url); }; +export const getILMPolicyPath = (policyName: string) => { + return encodeURI( + `/data/index_lifecycle_management/policies/edit/${encodeURIComponent(policyName)}` + ); +}; + +export const getIndexListUri = (filter?: string, includeHiddenIndices?: boolean) => { + const hiddenIndicesParam = + typeof includeHiddenIndices !== 'undefined' ? includeHiddenIndices : false; + if (filter) { + // React router tries to decode url params but it can't because the browser partially + // decodes them. So we have to encode both the URL and the filter to get it all to + // work correctly for filters with URL unsafe characters in them. + return encodeURI( + `/indices?includeHiddenIndices=${hiddenIndicesParam}&filter=${encodeURIComponent(filter)}` + ); + } + + // If no filter, URI is already safe so no need to encode. + return '/indices'; +}; + export const decodePathFromReactRouter = (pathname: string): string => { let decodedPath; try { diff --git a/x-pack/plugins/index_management/public/index.ts b/x-pack/plugins/index_management/public/index.ts index 7a76fff7f3ec65..a2e9a41feb165d 100644 --- a/x-pack/plugins/index_management/public/index.ts +++ b/x-pack/plugins/index_management/public/index.ts @@ -13,4 +13,4 @@ export const plugin = () => { export { IndexManagementPluginSetup }; -export { getIndexListUri } from './application/services/navigation'; +export { getIndexListUri } from './application/services/routing';