From 85272a400d028f4596820ad2f0159926540b3605 Mon Sep 17 00:00:00 2001 From: Jean-Louis Leysens Date: Wed, 14 Oct 2020 12:39:04 +0200 Subject: [PATCH 1/4] Add CTA for warm phase too - add/updated component integration tests for checking callouts - sharing deployment url from cloud plugin --- x-pack/plugins/cloud/public/plugin.ts | 4 +- .../__jest__/components/edit_policy.test.tsx | 21 ++++- .../cloud_data_tier_callout.tsx | 77 ++++++++++++++++--- .../shared/data_tier_allocation_field.tsx | 30 ++++---- 4 files changed, 106 insertions(+), 26 deletions(-) diff --git a/x-pack/plugins/cloud/public/plugin.ts b/x-pack/plugins/cloud/public/plugin.ts index 1c3a770da79f5..45005f3f5e422 100644 --- a/x-pack/plugins/cloud/public/plugin.ts +++ b/x-pack/plugins/cloud/public/plugin.ts @@ -22,6 +22,7 @@ interface CloudSetupDependencies { export interface CloudSetup { cloudId?: string; + cloudDeploymentUrl?: string; isCloudEnabled: boolean; } @@ -33,7 +34,7 @@ export class CloudPlugin implements Plugin { } public async setup(core: CoreSetup, { home }: CloudSetupDependencies) { - const { id, resetPasswordUrl } = this.config; + const { id, resetPasswordUrl, deploymentUrl } = this.config; const isCloudEnabled = getIsCloudEnabled(id); if (home) { @@ -45,6 +46,7 @@ export class CloudPlugin implements Plugin { return { cloudId: id, + cloudDeploymentUrl: deploymentUrl, isCloudEnabled, }; } diff --git a/x-pack/plugins/index_lifecycle_management/__jest__/components/edit_policy.test.tsx b/x-pack/plugins/index_lifecycle_management/__jest__/components/edit_policy.test.tsx index 953e6244b077f..28f0fcb663fd7 100644 --- a/x-pack/plugins/index_lifecycle_management/__jest__/components/edit_policy.test.tsx +++ b/x-pack/plugins/index_lifecycle_management/__jest__/components/edit_policy.test.tsx @@ -738,7 +738,7 @@ describe('edit policy', () => { httpRequestsMockHelpers.setPoliciesResponse(policies); }); - describe('with legacy data role config', () => { + describe('with deprecated data role config', () => { test('should hide data tier option on cloud using legacy node role configuration', async () => { http.setupNodeListResponse({ nodesByAttributes: { test: ['123'] }, @@ -776,6 +776,25 @@ describe('edit policy', () => { expect(findTestSubject(rendered, 'defaultDataAllocationOption').exists()).toBeTruthy(); expect(findTestSubject(rendered, 'customDataAllocationOption').exists()).toBeTruthy(); expect(findTestSubject(rendered, 'noneDataAllocationOption').exists()).toBeTruthy(); + // We should not be showing the call-to-action for users to activate data tiers in cloud + expect(findTestSubject(rendered, 'cloudDataTierCallout').exists()).toBeFalsy(); + }); + + test('should show cloud notice when warm tier nodes do not exist', async () => { + http.setupNodeListResponse({ + nodesByAttributes: {}, + nodesByRoles: { data: ['test'], data_hot: ['test'], data_cold: ['test'] }, + isUsingDeprecatedDataRoleConfig: false, + }); + const rendered = mountWithIntl(component); + noRollover(rendered); + setPolicyName(rendered, 'mypolicy'); + await activatePhase(rendered, 'warm'); + expect(rendered.find('.euiLoadingSpinner').exists()).toBeFalsy(); + expect(findTestSubject(rendered, 'cloudDataTierCallout').exists()).toBeTruthy(); + // Assert that other notices are not showing + expect(findTestSubject(rendered, 'defaultAllocationNotice').exists()).toBeFalsy(); + expect(findTestSubject(rendered, 'noNodeAttributesWarning').exists()).toBeFalsy(); }); test('should show cloud notice when cold tier nodes do not exist', async () => { diff --git a/x-pack/plugins/index_lifecycle_management/public/application/sections/edit_policy/components/data_tier_allocation/cloud_data_tier_callout.tsx b/x-pack/plugins/index_lifecycle_management/public/application/sections/edit_policy/components/data_tier_allocation/cloud_data_tier_callout.tsx index 2dff55ac10de1..5ad164d9b873e 100644 --- a/x-pack/plugins/index_lifecycle_management/public/application/sections/edit_policy/components/data_tier_allocation/cloud_data_tier_callout.tsx +++ b/x-pack/plugins/index_lifecycle_management/public/application/sections/edit_policy/components/data_tier_allocation/cloud_data_tier_callout.tsx @@ -5,22 +5,79 @@ */ import { i18n } from '@kbn/i18n'; +import { FormattedMessage } from '@kbn/i18n/react'; import React, { FunctionComponent } from 'react'; -import { EuiCallOut } from '@elastic/eui'; +import { EuiCallOut, EuiLink } from '@elastic/eui'; + +import { PhaseWithAllocation } from '../../../../../../common/types'; +import { useKibana } from '../../../../../shared_imports'; + +const deployment = i18n.translate( + 'xpack.indexLifecycleMgmt.editPolicy.cloudDataTierCallout.body.elasticDeploymentLink', + { + defaultMessage: 'deployment', + } +); const i18nTexts = { - title: i18n.translate('xpack.indexLifecycleMgmt.editPolicy.cloudDataTierCallout.title', { - defaultMessage: 'Create a cold tier', - }), - body: i18n.translate('xpack.indexLifecycleMgmt.editPolicy.cloudDataTierCallout.body', { - defaultMessage: 'Edit your Elastic Cloud deployment to set up a cold tier.', - }), + warm: { + title: i18n.translate('xpack.indexLifecycleMgmt.editPolicy.cloudDataTierCallout.title', { + defaultMessage: 'Create a warm tier', + }), + body: (deploymentUrl?: string) => { + return ( + + {deployment} + + ) : ( + deployment + ), + }} + /> + ); + }, + }, + cold: { + title: i18n.translate('xpack.indexLifecycleMgmt.editPolicy.cloudDataTierCallout.title', { + defaultMessage: 'Create a cold tier', + }), + body: (deploymentUrl?: string) => { + return ( + + {deployment} + + ) : ( + deployment + ), + }} + /> + ); + }, + }, }; -export const CloudDataTierCallout: FunctionComponent = () => { +interface Props { + phase: PhaseWithAllocation; +} + +export const CloudDataTierCallout: FunctionComponent = ({ phase }) => { + const { + services: { cloud }, + } = useKibana(); + return ( - - {i18nTexts.body} + + {i18nTexts[phase].body(cloud?.cloudDeploymentUrl)} ); }; diff --git a/x-pack/plugins/index_lifecycle_management/public/application/sections/edit_policy/phases/shared/data_tier_allocation_field.tsx b/x-pack/plugins/index_lifecycle_management/public/application/sections/edit_policy/phases/shared/data_tier_allocation_field.tsx index b3772a6e3ebd4..70de5140e618d 100644 --- a/x-pack/plugins/index_lifecycle_management/public/application/sections/edit_policy/phases/shared/data_tier_allocation_field.tsx +++ b/x-pack/plugins/index_lifecycle_management/public/application/sections/edit_policy/phases/shared/data_tier_allocation_field.tsx @@ -61,20 +61,22 @@ export const DataTierAllocationField: FunctionComponent = ({ switch (phaseData.dataTierAllocationType) { case 'default': const isCloudEnabled = cloud?.isCloudEnabled ?? false; - const isUsingNodeRoles = !isUsingDeprecatedDataRoleConfig; - if ( - isCloudEnabled && - isUsingNodeRoles && - phase === 'cold' && - !nodesByRoles.data_cold?.length - ) { - // Tell cloud users they can deploy cold tier nodes. - return ( - <> - - - - ); + if (isCloudEnabled && (phase === 'warm' || phase === 'cold')) { + const isUsingNodeRolesAllocation = !isUsingDeprecatedDataRoleConfig; + const hasNoNodesWithNodeRole = + phase === 'warm' + ? !nodesByRoles.data_warm?.length + : !nodesByRoles.data_cold?.length; + + if (isUsingNodeRolesAllocation && hasNoNodesWithNodeRole) { + // Tell cloud users they can deploy cold tier nodes. + return ( + <> + + + + ); + } } const allocationNodeRole = getAvailableNodeRoleForPhase(phase, nodesByRoles); From 9fee7f34bd1ce6fe464328e29493a0949d33e611 Mon Sep 17 00:00:00 2001 From: Jean-Louis Leysens Date: Wed, 14 Oct 2020 12:49:26 +0200 Subject: [PATCH 2/4] update comment --- .../edit_policy/phases/shared/data_tier_allocation_field.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/x-pack/plugins/index_lifecycle_management/public/application/sections/edit_policy/phases/shared/data_tier_allocation_field.tsx b/x-pack/plugins/index_lifecycle_management/public/application/sections/edit_policy/phases/shared/data_tier_allocation_field.tsx index 70de5140e618d..f4f4708ef671d 100644 --- a/x-pack/plugins/index_lifecycle_management/public/application/sections/edit_policy/phases/shared/data_tier_allocation_field.tsx +++ b/x-pack/plugins/index_lifecycle_management/public/application/sections/edit_policy/phases/shared/data_tier_allocation_field.tsx @@ -69,7 +69,7 @@ export const DataTierAllocationField: FunctionComponent = ({ : !nodesByRoles.data_cold?.length; if (isUsingNodeRolesAllocation && hasNoNodesWithNodeRole) { - // Tell cloud users they can deploy cold tier nodes. + // Tell cloud users they can deploy nodes on cloud. return ( <> From 030631f6d142cf22416297fd2656e4b9da0635aa Mon Sep 17 00:00:00 2001 From: Jean-Louis Leysens Date: Wed, 14 Oct 2020 15:53:58 +0200 Subject: [PATCH 3/4] fix i18n --- .../cloud_data_tier_callout.tsx | 22 ++++++++++++------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/x-pack/plugins/index_lifecycle_management/public/application/sections/edit_policy/components/data_tier_allocation/cloud_data_tier_callout.tsx b/x-pack/plugins/index_lifecycle_management/public/application/sections/edit_policy/components/data_tier_allocation/cloud_data_tier_callout.tsx index 5ad164d9b873e..21206a9f0fd7d 100644 --- a/x-pack/plugins/index_lifecycle_management/public/application/sections/edit_policy/components/data_tier_allocation/cloud_data_tier_callout.tsx +++ b/x-pack/plugins/index_lifecycle_management/public/application/sections/edit_policy/components/data_tier_allocation/cloud_data_tier_callout.tsx @@ -21,13 +21,16 @@ const deployment = i18n.translate( const i18nTexts = { warm: { - title: i18n.translate('xpack.indexLifecycleMgmt.editPolicy.cloudDataTierCallout.title', { - defaultMessage: 'Create a warm tier', - }), + title: i18n.translate( + 'xpack.indexLifecycleMgmt.editPolicy.cloudDataTierCallout.warmTierTitle', + { + defaultMessage: 'Create a warm tier', + } + ), body: (deploymentUrl?: string) => { return ( { return ( Date: Tue, 20 Oct 2020 11:51:19 +0200 Subject: [PATCH 4/4] scope changes to cold phase only --- .../__jest__/components/edit_policy.test.tsx | 17 ---- .../cloud_data_tier_callout.tsx | 79 ++++++------------- .../shared/data_tier_allocation_field.tsx | 9 +-- 3 files changed, 25 insertions(+), 80 deletions(-) diff --git a/x-pack/plugins/index_lifecycle_management/__jest__/components/edit_policy.test.tsx b/x-pack/plugins/index_lifecycle_management/__jest__/components/edit_policy.test.tsx index 541a2c184b084..c7664f2d837b9 100644 --- a/x-pack/plugins/index_lifecycle_management/__jest__/components/edit_policy.test.tsx +++ b/x-pack/plugins/index_lifecycle_management/__jest__/components/edit_policy.test.tsx @@ -834,23 +834,6 @@ describe('edit policy', () => { expect(findTestSubject(rendered, 'cloudDataTierCallout').exists()).toBeFalsy(); }); - test('should show cloud notice when warm tier nodes do not exist', async () => { - http.setupNodeListResponse({ - nodesByAttributes: {}, - nodesByRoles: { data: ['test'], data_hot: ['test'], data_cold: ['test'] }, - isUsingDeprecatedDataRoleConfig: false, - }); - const rendered = mountWithIntl(component); - noRollover(rendered); - setPolicyName(rendered, 'mypolicy'); - await activatePhase(rendered, 'warm'); - expect(rendered.find('.euiLoadingSpinner').exists()).toBeFalsy(); - expect(findTestSubject(rendered, 'cloudDataTierCallout').exists()).toBeTruthy(); - // Assert that other notices are not showing - expect(findTestSubject(rendered, 'defaultAllocationNotice').exists()).toBeFalsy(); - expect(findTestSubject(rendered, 'noNodeAttributesWarning').exists()).toBeFalsy(); - }); - test('should show cloud notice when cold tier nodes do not exist', async () => { http.setupNodeListResponse({ nodesByAttributes: {}, diff --git a/x-pack/plugins/index_lifecycle_management/public/application/sections/edit_policy/components/data_tier_allocation/cloud_data_tier_callout.tsx b/x-pack/plugins/index_lifecycle_management/public/application/sections/edit_policy/components/data_tier_allocation/cloud_data_tier_callout.tsx index 21206a9f0fd7d..fc87b553ba521 100644 --- a/x-pack/plugins/index_lifecycle_management/public/application/sections/edit_policy/components/data_tier_allocation/cloud_data_tier_callout.tsx +++ b/x-pack/plugins/index_lifecycle_management/public/application/sections/edit_policy/components/data_tier_allocation/cloud_data_tier_callout.tsx @@ -9,7 +9,6 @@ import { FormattedMessage } from '@kbn/i18n/react'; import React, { FunctionComponent } from 'react'; import { EuiCallOut, EuiLink } from '@elastic/eui'; -import { PhaseWithAllocation } from '../../../../../../common/types'; import { useKibana } from '../../../../../shared_imports'; const deployment = i18n.translate( @@ -20,70 +19,36 @@ const deployment = i18n.translate( ); const i18nTexts = { - warm: { - title: i18n.translate( - 'xpack.indexLifecycleMgmt.editPolicy.cloudDataTierCallout.warmTierTitle', - { - defaultMessage: 'Create a warm tier', - } - ), - body: (deploymentUrl?: string) => { - return ( - - {deployment} - - ) : ( - deployment - ), - }} - /> - ); - }, - }, - cold: { - title: i18n.translate( - 'xpack.indexLifecycleMgmt.editPolicy.cloudDataTierCallout.coldTierTitle', - { - defaultMessage: 'Create a cold tier', - } - ), - body: (deploymentUrl?: string) => { - return ( - - {deployment} - - ) : ( - deployment - ), - }} - /> - ); - }, + title: i18n.translate('xpack.indexLifecycleMgmt.editPolicy.cloudDataTierCallout.coldTierTitle', { + defaultMessage: 'Create a cold tier', + }), + body: (deploymentUrl?: string) => { + return ( + + {deployment} + + ) : ( + deployment + ), + }} + /> + ); }, }; -interface Props { - phase: PhaseWithAllocation; -} - -export const CloudDataTierCallout: FunctionComponent = ({ phase }) => { +export const CloudDataTierCallout: FunctionComponent = () => { const { services: { cloud }, } = useKibana(); return ( - - {i18nTexts[phase].body(cloud?.cloudDeploymentUrl)} + + {i18nTexts.body(cloud?.cloudDeploymentUrl)} ); }; diff --git a/x-pack/plugins/index_lifecycle_management/public/application/sections/edit_policy/components/phases/shared/data_tier_allocation_field.tsx b/x-pack/plugins/index_lifecycle_management/public/application/sections/edit_policy/components/phases/shared/data_tier_allocation_field.tsx index c11c14de7a0d9..df59efcbfd299 100644 --- a/x-pack/plugins/index_lifecycle_management/public/application/sections/edit_policy/components/phases/shared/data_tier_allocation_field.tsx +++ b/x-pack/plugins/index_lifecycle_management/public/application/sections/edit_policy/components/phases/shared/data_tier_allocation_field.tsx @@ -61,19 +61,16 @@ export const DataTierAllocationField: FunctionComponent = ({ switch (phaseData.dataTierAllocationType) { case 'default': const isCloudEnabled = cloud?.isCloudEnabled ?? false; - if (isCloudEnabled && (phase === 'warm' || phase === 'cold')) { + if (isCloudEnabled && phase === 'cold') { const isUsingNodeRolesAllocation = !isUsingDeprecatedDataRoleConfig; - const hasNoNodesWithNodeRole = - phase === 'warm' - ? !nodesByRoles.data_warm?.length - : !nodesByRoles.data_cold?.length; + const hasNoNodesWithNodeRole = !nodesByRoles.data_cold?.length; if (isUsingNodeRolesAllocation && hasNoNodesWithNodeRole) { // Tell cloud users they can deploy nodes on cloud. return ( <> - + ); }