Skip to content

Commit

Permalink
[Workplace Search] Convert Overview & Security pages to new page temp…
Browse files Browse the repository at this point in the history
…late (#102444)

* Convert WS Overview page to new page template

* 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)

* Convert Security page to new page template

+ misc ux enhancement disabling header actions while data is still loading
  • Loading branch information
Constance committed Jun 17, 2021
1 parent e8c16e3 commit 1627240
Show file tree
Hide file tree
Showing 6 changed files with 74 additions and 123 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ describe('WorkplaceSearchConfigured', () => {

const wrapper = shallow(<WorkplaceSearchConfigured />);

expect(wrapper.find(ErrorState)).toHaveLength(2);
expect(wrapper.find(ErrorState)).toHaveLength(1);
});

it('passes readOnlyMode state', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,13 +96,7 @@ export const WorkplaceSearchConfigured: React.FC<InitialAppData> = (props) => {
<SourceAdded />
</Route>
<Route exact path="/">
{errorConnecting ? (
<ErrorState />
) : (
<Layout navigation={<WorkplaceSearchNav />} restrictWidth readOnlyMode={readOnlyMode}>
<Overview />
</Layout>
)}
<Overview />
</Route>
<Route path={PERSONAL_SOURCES_PATH}>
<PersonalDashboardLayout
Expand Down Expand Up @@ -144,9 +138,7 @@ export const WorkplaceSearchConfigured: React.FC<InitialAppData> = (props) => {
<RoleMappings />
</Route>
<Route path={SECURITY_PATH}>
<Layout navigation={<WorkplaceSearchNav />} restrictWidth readOnlyMode={readOnlyMode}>
<Security />
</Layout>
<Security />
</Route>
<Route path={ORG_SETTINGS_PATH}>
<Layout
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,61 +5,48 @@
* 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 { Loading } from '../../../shared/loading';
import { ViewContentHeader } from '../../components/shared/view_content_header';
import { shallow } from 'enzyme';

import { OnboardingSteps } from './onboarding_steps';
import { OrganizationStats } from './organization_stats';
import { Overview } from './overview';
import { RecentActivity } from './recent_activity';

describe('Overview', () => {
describe('non-happy-path states', () => {
it('isLoading', () => {
const wrapper = shallow(<Overview />);
it('calls initialize function', async () => {
shallow(<Overview />);

expect(wrapper.find(Loading)).toHaveLength(1);
});
expect(mockActions.initializeOverview).toHaveBeenCalled();
});

describe('happy-path states', () => {
it('calls initialize function', async () => {
mount(<Overview />);

expect(mockActions.initializeOverview).toHaveBeenCalled();
});
it('renders onboarding state', () => {
setMockValues({ dataLoading: false });
const wrapper = shallow(<Overview />);

it('renders onboarding state', () => {
setMockValues({ dataLoading: false });
const wrapper = shallow(<Overview />);
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(<Overview />);

it('renders when onboarding complete', () => {
setMockValues({
dataLoading: false,
hasUsers: true,
hasOrgSources: true,
isOldAccount: true,
organization: {
name: 'foo',
defaultOrgName: 'bar',
},
});
const wrapper = shallow(<Overview />);

expect(wrapper.find(OnboardingSteps)).toHaveLength(0);
});
expect(wrapper.find(OnboardingSteps)).toHaveLength(0);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -54,26 +51,31 @@ export const Overview: React.FC = () => {
initializeOverview();
}, [initializeOverview]);

if (dataLoading) {
return <Loading />;
}

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 (
<>
<SetPageChrome />
<SendTelemetry action="viewed" metric="overview" />

<ViewContentHeader title={headerTitle} description={headerDescription} />
{!hideOnboarding && <OnboardingSteps />}
<EuiSpacer size="xl" />
<WorkplaceSearchPageTemplate
pageChrome={[]}
pageHeader={{
pageTitle: headerTitle,
description: headerDescription,
}}
pageViewTelemetry="overview"
isLoading={dataLoading}
>
{!hideOnboarding && (
<>
<OnboardingSteps />
<EuiSpacer size="xl" />
</>
)}
<OrganizationStats />
<EuiSpacer size="xl" />
<RecentActivity />
</>
</WorkplaceSearchPageTemplate>
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,8 @@ import { shallow } from 'enzyme';

import { EuiSwitch, EuiConfirmModal } from '@elastic/eui';

import { SetWorkplaceSearchChrome as SetPageChrome } from '../../../shared/kibana_chrome';

import { Loading } from '../../../shared/loading';
import { UnsavedChangesPrompt } from '../../../shared/unsaved_changes_prompt';
import { ViewContentHeader } from '../../components/shared/view_content_header';
import { getPageHeaderActions } from '../../../test_helpers';

import { Security } from './security';

Expand Down Expand Up @@ -59,9 +56,7 @@ describe('Security', () => {
setMockValues({ ...mockValues, hasPlatinumLicense: false });
const wrapper = shallow(<Security />);

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);
});

Expand All @@ -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(<Security />);

expect(wrapper.find(Loading)).toHaveLength(1);
});

it('handles switch click', () => {
const wrapper = shallow(<Security />);

Expand All @@ -92,8 +80,8 @@ describe('Security', () => {
setMockValues({ ...mockValues, unsavedChanges: true });
const wrapper = shallow(<Security />);

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);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -72,44 +69,24 @@ export const Security: React.FC = () => {
initializeSourceRestrictions();
}, []);

if (dataLoading) return <Loading />;

const savePrivateSources = () => {
saveSourceRestrictions();
hideConfirmModal();
};

const headerActions = (
<EuiFlexGroup alignItems="center" justifyContent="flexStart" gutterSize="m">
<EuiFlexItem grow={false}>
<EuiButtonEmpty disabled={!unsavedChanges} onClick={resetState}>
{RESET_BUTTON}
</EuiButtonEmpty>
</EuiFlexItem>
<EuiFlexItem>
<EuiButton
disabled={!hasPlatinumLicense || !unsavedChanges}
onClick={showConfirmModal}
fill
data-test-subj="SaveSettingsButton"
>
{SAVE_SETTINGS_BUTTON}
</EuiButton>
</EuiFlexItem>
</EuiFlexGroup>
);

const header = (
<>
<ViewContentHeader
title={PRIVATE_SOURCES}
alignItems="flexStart"
description={PRIVATE_SOURCES_DESCRIPTION}
action={headerActions}
/>
<EuiSpacer />
</>
);
const headerActions = [
<EuiButtonEmpty disabled={!unsavedChanges || dataLoading} onClick={resetState}>
{RESET_BUTTON}
</EuiButtonEmpty>,
<EuiButton
disabled={!hasPlatinumLicense || !unsavedChanges || dataLoading}
onClick={showConfirmModal}
fill
data-test-subj="SaveSettingsButton"
>
{SAVE_SETTINGS_BUTTON}
</EuiButton>,
];

const allSourcesToggle = (
<EuiPanel
Expand Down Expand Up @@ -180,20 +157,25 @@ export const Security: React.FC = () => {
);

return (
<>
<SetPageChrome trail={[NAV.SECURITY]} />
<FlashMessages />
<WorkplaceSearchPageTemplate
pageChrome={[NAV.SECURITY]}
pageHeader={{
pageTitle: PRIVATE_SOURCES,
description: PRIVATE_SOURCES_DESCRIPTION,
rightSideItems: headerActions,
}}
isLoading={dataLoading}
>
<UnsavedChangesPrompt
hasUnsavedChanges={unsavedChanges}
messageText={SECURITY_UNSAVED_CHANGES_MESSAGE}
/>
{header}
<EuiPanel color="subdued" hasBorder={false}>
{allSourcesToggle}
{!hasPlatinumLicense && platinumLicenseCallout}
{sourceTables}
</EuiPanel>
{confirmModalVisible && confirmModal}
</>
</WorkplaceSearchPageTemplate>
);
};

0 comments on commit 1627240

Please sign in to comment.