From 7602efe0fc9afde91daa8ed7a0ba868f95b96473 Mon Sep 17 00:00:00 2001 From: Constance Chen Date: Wed, 16 Jun 2021 20:35:00 -0700 Subject: [PATCH 1/3] Convert WS Overview page to new page template --- .../workplace_search/index.test.tsx | 2 +- .../applications/workplace_search/index.tsx | 8 +-- .../views/overview/overview.test.tsx | 58 +++++++------------ .../views/overview/overview.tsx | 25 ++++---- 4 files changed, 35 insertions(+), 58 deletions(-) diff --git a/x-pack/plugins/enterprise_search/public/applications/workplace_search/index.test.tsx b/x-pack/plugins/enterprise_search/public/applications/workplace_search/index.test.tsx index fb0ea822206400..28169afd4bdebc 100644 --- a/x-pack/plugins/enterprise_search/public/applications/workplace_search/index.test.tsx +++ b/x-pack/plugins/enterprise_search/public/applications/workplace_search/index.test.tsx @@ -88,7 +88,7 @@ describe('WorkplaceSearchConfigured', () => { const wrapper = shallow(); - expect(wrapper.find(ErrorState)).toHaveLength(2); + expect(wrapper.find(ErrorState)).toHaveLength(1); }); it('passes readOnlyMode state', () => { diff --git a/x-pack/plugins/enterprise_search/public/applications/workplace_search/index.tsx b/x-pack/plugins/enterprise_search/public/applications/workplace_search/index.tsx index dd263c3bd69f5d..5c2c5f7b94a6c6 100644 --- a/x-pack/plugins/enterprise_search/public/applications/workplace_search/index.tsx +++ b/x-pack/plugins/enterprise_search/public/applications/workplace_search/index.tsx @@ -96,13 +96,7 @@ export const WorkplaceSearchConfigured: React.FC = (props) => { - {errorConnecting ? ( - - ) : ( - } restrictWidth readOnlyMode={readOnlyMode}> - - - )} + { - describe('non-happy-path states', () => { - it('isLoading', () => { - const wrapper = shallow(); + it('calls initialize function', async () => { + mount(); - expect(wrapper.find(Loading)).toHaveLength(1); - }); + expect(mockActions.initializeOverview).toHaveBeenCalled(); }); - describe('happy-path states', () => { - it('calls initialize function', async () => { - mount(); - - expect(mockActions.initializeOverview).toHaveBeenCalled(); - }); + it('renders onboarding state', () => { + setMockValues({ dataLoading: false }); + const wrapper = shallow(); - it('renders onboarding state', () => { - setMockValues({ dataLoading: false }); - const wrapper = shallow(); + expect(wrapper.find(OnboardingSteps)).toHaveLength(1); + expect(wrapper.find(OrganizationStats)).toHaveLength(1); + expect(wrapper.find(RecentActivity)).toHaveLength(1); + }); - expect(wrapper.find(ViewContentHeader)).toHaveLength(1); - expect(wrapper.find(OnboardingSteps)).toHaveLength(1); - expect(wrapper.find(OrganizationStats)).toHaveLength(1); - expect(wrapper.find(RecentActivity)).toHaveLength(1); + it('renders when onboarding complete', () => { + setMockValues({ + dataLoading: false, + hasUsers: true, + hasOrgSources: true, + isOldAccount: true, + organization: { + name: 'foo', + defaultOrgName: 'bar', + }, }); + const wrapper = shallow(); - it('renders when onboarding complete', () => { - setMockValues({ - dataLoading: false, - hasUsers: true, - hasOrgSources: true, - isOldAccount: true, - organization: { - name: 'foo', - defaultOrgName: 'bar', - }, - }); - const wrapper = shallow(); - - expect(wrapper.find(OnboardingSteps)).toHaveLength(0); - }); + expect(wrapper.find(OnboardingSteps)).toHaveLength(0); }); }); diff --git a/x-pack/plugins/enterprise_search/public/applications/workplace_search/views/overview/overview.tsx b/x-pack/plugins/enterprise_search/public/applications/workplace_search/views/overview/overview.tsx index 9242bd8b6fbddf..2bdce37fe36c0c 100644 --- a/x-pack/plugins/enterprise_search/public/applications/workplace_search/views/overview/overview.tsx +++ b/x-pack/plugins/enterprise_search/public/applications/workplace_search/views/overview/overview.tsx @@ -12,11 +12,8 @@ import { useActions, useValues } from 'kea'; import { EuiSpacer } from '@elastic/eui'; import { i18n } from '@kbn/i18n'; -import { SetWorkplaceSearchChrome as SetPageChrome } from '../../../shared/kibana_chrome'; -import { Loading } from '../../../shared/loading'; -import { SendWorkplaceSearchTelemetry as SendTelemetry } from '../../../shared/telemetry'; import { AppLogic } from '../../app_logic'; -import { ViewContentHeader } from '../../components/shared/view_content_header'; +import { WorkplaceSearchPageTemplate } from '../../components/layout'; import { OnboardingSteps } from './onboarding_steps'; import { OrganizationStats } from './organization_stats'; @@ -54,26 +51,26 @@ export const Overview: React.FC = () => { initializeOverview(); }, [initializeOverview]); - if (dataLoading) { - return ; - } - const hideOnboarding = hasUsers && hasOrgSources && isOldAccount && orgName !== defaultOrgName; const headerTitle = hideOnboarding ? HEADER_TITLE : ONBOARDING_HEADER_TITLE; const headerDescription = hideOnboarding ? HEADER_DESCRIPTION : ONBOARDING_HEADER_DESCRIPTION; return ( - <> - - - - + {!hideOnboarding && } - + ); }; From 281e7a6dec6296dd1e5773f37a08932b508ace26 Mon Sep 17 00:00:00 2001 From: Constance Chen Date: Wed, 16 Jun 2021 20:36:44 -0700 Subject: [PATCH 2/3] Misc Overview refactors - Fix extra spacing caused by hidden onboarding steps - Default page title to "Organization overview" instead of to onboarding title which flashes during loading - Prefer shallow over mount (will matter later, when WorkplaceSearchPageTemplate nav includes more kea logic) --- .../views/overview/overview.test.tsx | 5 +++-- .../workplace_search/views/overview/overview.tsx | 13 +++++++++---- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/x-pack/plugins/enterprise_search/public/applications/workplace_search/views/overview/overview.test.tsx b/x-pack/plugins/enterprise_search/public/applications/workplace_search/views/overview/overview.test.tsx index 50057c244ea92b..cf23470e8155eb 100644 --- a/x-pack/plugins/enterprise_search/public/applications/workplace_search/views/overview/overview.test.tsx +++ b/x-pack/plugins/enterprise_search/public/applications/workplace_search/views/overview/overview.test.tsx @@ -5,12 +5,13 @@ * 2.0. */ +import '../../../__mocks__/shallow_useeffect.mock'; import './__mocks__/overview_logic.mock'; import { mockActions, setMockValues } from './__mocks__'; import React from 'react'; -import { shallow, mount } from 'enzyme'; +import { shallow } from 'enzyme'; import { OnboardingSteps } from './onboarding_steps'; import { OrganizationStats } from './organization_stats'; @@ -19,7 +20,7 @@ import { RecentActivity } from './recent_activity'; describe('Overview', () => { it('calls initialize function', async () => { - mount(); + shallow(); expect(mockActions.initializeOverview).toHaveBeenCalled(); }); diff --git a/x-pack/plugins/enterprise_search/public/applications/workplace_search/views/overview/overview.tsx b/x-pack/plugins/enterprise_search/public/applications/workplace_search/views/overview/overview.tsx index 2bdce37fe36c0c..0049c5b732d3d0 100644 --- a/x-pack/plugins/enterprise_search/public/applications/workplace_search/views/overview/overview.tsx +++ b/x-pack/plugins/enterprise_search/public/applications/workplace_search/views/overview/overview.tsx @@ -53,8 +53,9 @@ export const Overview: React.FC = () => { const hideOnboarding = hasUsers && hasOrgSources && isOldAccount && orgName !== defaultOrgName; - const headerTitle = hideOnboarding ? HEADER_TITLE : ONBOARDING_HEADER_TITLE; - const headerDescription = hideOnboarding ? HEADER_DESCRIPTION : ONBOARDING_HEADER_DESCRIPTION; + const headerTitle = dataLoading || hideOnboarding ? HEADER_TITLE : ONBOARDING_HEADER_TITLE; + const headerDescription = + dataLoading || hideOnboarding ? HEADER_DESCRIPTION : ONBOARDING_HEADER_DESCRIPTION; return ( { pageViewTelemetry="overview" isLoading={dataLoading} > - {!hideOnboarding && } - + {!hideOnboarding && ( + <> + + + + )} From 1616f078215f6efbc32b7d09d3adaa00abec31e1 Mon Sep 17 00:00:00 2001 From: Constance Chen Date: Wed, 16 Jun 2021 20:56:13 -0700 Subject: [PATCH 3/3] Convert Security page to new page template + misc ux enhancement disabling header actions while data is still loading --- .../applications/workplace_search/index.tsx | 4 +- .../views/security/security.test.tsx | 18 +---- .../views/security/security.tsx | 66 +++++++------------ 3 files changed, 28 insertions(+), 60 deletions(-) diff --git a/x-pack/plugins/enterprise_search/public/applications/workplace_search/index.tsx b/x-pack/plugins/enterprise_search/public/applications/workplace_search/index.tsx index 5c2c5f7b94a6c6..6961f45bae757a 100644 --- a/x-pack/plugins/enterprise_search/public/applications/workplace_search/index.tsx +++ b/x-pack/plugins/enterprise_search/public/applications/workplace_search/index.tsx @@ -138,9 +138,7 @@ export const WorkplaceSearchConfigured: React.FC = (props) => { - } restrictWidth readOnlyMode={readOnlyMode}> - - + { setMockValues({ ...mockValues, hasPlatinumLicense: false }); const wrapper = shallow(); - expect(wrapper.find(SetPageChrome)).toHaveLength(1); expect(wrapper.find(UnsavedChangesPrompt)).toHaveLength(1); - expect(wrapper.find(ViewContentHeader)).toHaveLength(1); expect(wrapper.find(EuiSwitch).prop('disabled')).toEqual(true); }); @@ -71,13 +66,6 @@ describe('Security', () => { expect(wrapper.find(EuiSwitch).prop('disabled')).toEqual(false); }); - it('returns Loading when loading', () => { - setMockValues({ ...mockValues, dataLoading: true }); - const wrapper = shallow(); - - expect(wrapper.find(Loading)).toHaveLength(1); - }); - it('handles switch click', () => { const wrapper = shallow(); @@ -92,8 +80,8 @@ describe('Security', () => { setMockValues({ ...mockValues, unsavedChanges: true }); const wrapper = shallow(); - const header = wrapper.find(ViewContentHeader).dive(); - header.find('[data-test-subj="SaveSettingsButton"]').prop('onClick')!({} as any); + const headerActions = getPageHeaderActions(wrapper); + headerActions.find('[data-test-subj="SaveSettingsButton"]').prop('onClick')!({} as any); const modal = wrapper.find(EuiConfirmModal); modal.prop('onConfirm')!({} as any); diff --git a/x-pack/plugins/enterprise_search/public/applications/workplace_search/views/security/security.tsx b/x-pack/plugins/enterprise_search/public/applications/workplace_search/views/security/security.tsx index b746344b3806bb..6cf1831dc07e7e 100644 --- a/x-pack/plugins/enterprise_search/public/applications/workplace_search/views/security/security.tsx +++ b/x-pack/plugins/enterprise_search/public/applications/workplace_search/views/security/security.tsx @@ -22,13 +22,10 @@ import { EuiConfirmModal, } from '@elastic/eui'; -import { FlashMessages } from '../../../shared/flash_messages'; -import { SetWorkplaceSearchChrome as SetPageChrome } from '../../../shared/kibana_chrome'; import { LicensingLogic } from '../../../shared/licensing'; -import { Loading } from '../../../shared/loading'; import { UnsavedChangesPrompt } from '../../../shared/unsaved_changes_prompt'; +import { WorkplaceSearchPageTemplate } from '../../components/layout'; import { LicenseCallout } from '../../components/shared/license_callout'; -import { ViewContentHeader } from '../../components/shared/view_content_header'; import { SECURITY_UNSAVED_CHANGES_MESSAGE, RESET_BUTTON, @@ -72,44 +69,24 @@ export const Security: React.FC = () => { initializeSourceRestrictions(); }, []); - if (dataLoading) return ; - const savePrivateSources = () => { saveSourceRestrictions(); hideConfirmModal(); }; - const headerActions = ( - - - - {RESET_BUTTON} - - - - - {SAVE_SETTINGS_BUTTON} - - - - ); - - const header = ( - <> - - - - ); + const headerActions = [ + + {RESET_BUTTON} + , + + {SAVE_SETTINGS_BUTTON} + , + ]; const allSourcesToggle = ( { ); return ( - <> - - + - {header} {allSourcesToggle} {!hasPlatinumLicense && platinumLicenseCallout} {sourceTables} {confirmModalVisible && confirmModal} - + ); };