From 21f231db428ff0c7817f3fab4779346dc3effbe0 Mon Sep 17 00:00:00 2001 From: Alison Goryachev Date: Tue, 7 Jul 2020 15:40:01 -0400 Subject: [PATCH 1/3] fix app links in index management --- .../helpers/setup_environment.tsx | 6 +++++- .../public/application/app_context.tsx | 1 + .../application/mount_management_section.ts | 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 | 18 ++++++++++++++++ .../plugins/index_management/public/index.ts | 2 +- 8 files changed, 40 insertions(+), 26 deletions(-) delete mode 100644 x-pack/plugins/index_management/public/application/services/navigation.ts 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 d85db94d4a970..b294b0f4db497 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: () => {}, navigateToApp: () => {} }, + plugins: {}, +} as any; export const setupEnvironment = () => { // Mock initialization of services diff --git a/x-pack/plugins/index_management/public/application/app_context.tsx b/x-pack/plugins/index_management/public/application/app_context.tsx index 6fbe177d24e06..daae988534b93 100644 --- a/x-pack/plugins/index_management/public/application/app_context.tsx +++ b/x-pack/plugins/index_management/public/application/app_context.tsx @@ -21,6 +21,7 @@ export interface AppDependencies { core: { fatalErrors: CoreStart['fatalErrors']; getUrlForApp: CoreStart['application']['getUrlForApp']; + navigateToApp: CoreStart['application']['navigateToApp']; }; plugins: { usageCollection: UsageCollectionSetup; diff --git a/x-pack/plugins/index_management/public/application/mount_management_section.ts b/x-pack/plugins/index_management/public/application/mount_management_section.ts index 6145ea410b0e8..5fe550e66f055 100644 --- a/x-pack/plugins/index_management/public/application/mount_management_section.ts +++ b/x-pack/plugins/index_management/public/application/mount_management_section.ts @@ -43,6 +43,7 @@ export async function mountManagementSection( core: { fatalErrors, getUrlForApp: application.getUrlForApp, + navigateToApp: application.navigateToApp, }, plugins: { usageCollection, diff --git a/x-pack/plugins/index_management/public/application/sections/home/index_list/index_table/index_table.js b/x-pack/plugins/index_management/public/application/sections/home/index_list/index_table/index_table.js index 5f10eebc9d270..209b888e91700 100644 --- a/x-pack/plugins/index_management/public/application/sections/home/index_list/index_table/index_table.js +++ b/x-pack/plugins/index_management/public/application/sections/home/index_list/index_table/index_table.js @@ -75,7 +75,7 @@ const HEADERS = { export class IndexTable extends Component { static getDerivedStateFromProps(props, state) { - // Deselct any indices which no longer exist, e.g. they've been deleted. + // Deselect any indices which no longer exist, e.g. they've been deleted. const { selectedIndicesMap } = state; const indexNames = props.indices.map((index) => 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 fe6c9ad3d8e07..57c2ca7a450eb 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: { navigateToApp }, + } = useAppContext(); + return ( @@ -153,7 +158,13 @@ export const TabSummary: React.FunctionComponent = ({ templateDetails }) {ilmPolicy && ilmPolicy.name ? ( - {ilmPolicy.name} + + navigateToApp('management', { path: getILMPolicyPath(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 3b4977bb63751..0000000000000 --- 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 8831fa2368f47..66f0b8a72ef36 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,24 @@ 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: 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?includeHiddenIndices=true&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 7a76fff7f3ec6..a2e9a41feb165 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'; From 5d0675d0e55fcfa5e6d96b44b13d181b1360fc47 Mon Sep 17 00:00:00 2001 From: Alison Goryachev Date: Tue, 7 Jul 2020 20:36:37 -0400 Subject: [PATCH 2/3] cleanup --- .../policy_table/components/policy_table/policy_table.js | 2 +- .../public/application/sections/home/home.tsx | 1 - .../public/application/services/routing.ts | 8 ++++++-- 3 files changed, 7 insertions(+), 4 deletions(-) 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 dad259681eb7a..500ab44d96694 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/public/application/sections/home/home.tsx b/x-pack/plugins/index_management/public/application/sections/home/home.tsx index 7bd04cdbf0c91..ee8970a3c4509 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 - { ); }; -export const getIndexListUri = (filter: any) => { +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=true&filter=${encodeURIComponent(filter)}`); + return encodeURI( + `/indices?includeHiddenIndices=${hiddenIndicesParam}&filter=${encodeURIComponent(filter)}` + ); } // If no filter, URI is already safe so no need to encode. From 8f37c18d94b1549585afdd5c2c35c4947cba62e8 Mon Sep 17 00:00:00 2001 From: Alison Goryachev Date: Wed, 8 Jul 2020 14:47:17 -0400 Subject: [PATCH 3/3] address review feedback --- .../client_integration/helpers/setup_environment.tsx | 2 +- .../index_management/public/application/app_context.tsx | 1 - .../public/application/mount_management_section.ts | 1 - .../template_list/template_details/tabs/tab_summary.tsx | 8 ++++---- 4 files changed, 5 insertions(+), 7 deletions(-) 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 b294b0f4db497..ad445f75f047c 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 @@ -36,7 +36,7 @@ setExtensionsService(services.extensionsService); setUiMetricService(services.uiMetricService); const appDependencies = { services, - core: { getUrlForApp: () => {}, navigateToApp: () => {} }, + core: { getUrlForApp: () => {} }, plugins: {}, } as any; diff --git a/x-pack/plugins/index_management/public/application/app_context.tsx b/x-pack/plugins/index_management/public/application/app_context.tsx index daae988534b93..6fbe177d24e06 100644 --- a/x-pack/plugins/index_management/public/application/app_context.tsx +++ b/x-pack/plugins/index_management/public/application/app_context.tsx @@ -21,7 +21,6 @@ export interface AppDependencies { core: { fatalErrors: CoreStart['fatalErrors']; getUrlForApp: CoreStart['application']['getUrlForApp']; - navigateToApp: CoreStart['application']['navigateToApp']; }; plugins: { usageCollection: UsageCollectionSetup; diff --git a/x-pack/plugins/index_management/public/application/mount_management_section.ts b/x-pack/plugins/index_management/public/application/mount_management_section.ts index 5fe550e66f055..6145ea410b0e8 100644 --- a/x-pack/plugins/index_management/public/application/mount_management_section.ts +++ b/x-pack/plugins/index_management/public/application/mount_management_section.ts @@ -43,7 +43,6 @@ export async function mountManagementSection( core: { fatalErrors, getUrlForApp: application.getUrlForApp, - navigateToApp: application.navigateToApp, }, plugins: { usageCollection, 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 57c2ca7a450eb..de2fc29ec8543 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 @@ -53,7 +53,7 @@ export const TabSummary: React.FunctionComponent = ({ templateDetails }) const numIndexPatterns = indexPatterns.length; const { - core: { navigateToApp }, + core: { getUrlForApp }, } = useAppContext(); return ( @@ -159,9 +159,9 @@ export const TabSummary: React.FunctionComponent = ({ templateDetails }) {ilmPolicy && ilmPolicy.name ? ( - navigateToApp('management', { path: getILMPolicyPath(ilmPolicy.name) }) - } + href={getUrlForApp('management', { + path: getILMPolicyPath(ilmPolicy.name), + })} > {ilmPolicy.name}