Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Workplace Search] Convert Sources pages to new page template (+ personal dashboard) #102592

Merged
merged 15 commits into from
Jun 22, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,10 @@ import { setMockValues, setMockActions } from '../../../__mocks__/kea_logic';
import { contentSources } from '../../__mocks__/content_sources.mock';

import React from 'react';
import { Redirect } from 'react-router-dom';

import { shallow } from 'enzyme';

import { Loading } from '../../../shared/loading';
import { SourcesTable } from '../../components/shared/sources_table';
import { ViewContentHeader } from '../../components/shared/view_content_header';
import { ADD_SOURCE_PATH, getSourcesPath } from '../../routes';

import { OrganizationSources } from './organization_sources';

Expand All @@ -42,20 +38,5 @@ describe('OrganizationSources', () => {
const wrapper = shallow(<OrganizationSources />);

expect(wrapper.find(SourcesTable)).toHaveLength(1);
expect(wrapper.find(ViewContentHeader)).toHaveLength(1);
});

it('returns loading when loading', () => {
setMockValues({ ...mockValues, dataLoading: true });
const wrapper = shallow(<OrganizationSources />);

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

it('returns redirect when no sources', () => {
setMockValues({ ...mockValues, contentSources: [] });
const wrapper = shallow(<OrganizationSources />);

expect(wrapper.find(Redirect).prop('to')).toEqual(getSourcesPath(ADD_SOURCE_PATH, true));
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,15 @@
*/

import React, { useEffect } from 'react';
import { Link, Redirect } from 'react-router-dom';
import { Redirect } from 'react-router-dom';

import { useActions, useValues } from 'kea';

import { EuiButton } from '@elastic/eui';

import { Loading } from '../../../shared/loading';
import { EuiButtonTo } from '../../../shared/react_router_helpers';
import { WorkplaceSearchPageTemplate } from '../../components/layout';
import { ContentSection } from '../../components/shared/content_section';
import { SourcesTable } from '../../components/shared/sources_table';
import { ViewContentHeader } from '../../components/shared/view_content_header';
import { NAV } from '../../constants';
import { ADD_SOURCE_PATH, getSourcesPath } from '../../routes';

import {
Expand All @@ -36,33 +35,37 @@ export const OrganizationSources: React.FC = () => {

const { dataLoading, contentSources } = useValues(SourcesLogic);

if (dataLoading) return <Loading />;

if (contentSources.length === 0) return <Redirect to={getSourcesPath(ADD_SOURCE_PATH, true)} />;
yakhinvadim marked this conversation as resolved.
Show resolved Hide resolved

return (
<SourcesView>
<ViewContentHeader
title={ORG_SOURCES_HEADER_TITLE}
action={
<Link to={getSourcesPath(ADD_SOURCE_PATH, true)}>
<EuiButton fill color="primary" data-test-subj="AddSourceButton">
{ORG_SOURCES_LINK}
</EuiButton>
</Link>
}
description={ORG_SOURCES_HEADER_DESCRIPTION}
alignItems="flexStart"
/>

<ContentSection>
<SourcesTable
showDetails
isOrganization
onSearchableToggle={setSourceSearchability}
sources={contentSources}
/>
</ContentSection>
</SourcesView>
<WorkplaceSearchPageTemplate
pageChrome={[NAV.SOURCES]}
pageViewTelemetry="organization_sources"
pageHeader={{
pageTitle: ORG_SOURCES_HEADER_TITLE,
description: ORG_SOURCES_HEADER_DESCRIPTION,
rightSideItems: [
<EuiButtonTo
to={getSourcesPath(ADD_SOURCE_PATH, true)}
data-test-subj="AddSourceButton"
fill
>
{ORG_SOURCES_LINK}
</EuiButtonTo>,
],
}}
isLoading={dataLoading}
isEmptyState={!contentSources.length}
emptyState={<Redirect to={getSourcesPath(ADD_SOURCE_PATH, true)} />}
>
<SourcesView>
<ContentSection>
<SourcesTable
showDetails
isOrganization
onSearchableToggle={setSourceSearchability}
sources={contentSources}
/>
</ContentSection>
</SourcesView>
</WorkplaceSearchPageTemplate>
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import { shallow } from 'enzyme';

import { EuiCallOut, EuiEmptyPrompt } from '@elastic/eui';

import { Loading } from '../../../shared/loading';
import { ContentSection } from '../../components/shared/content_section';
import { SourcesTable } from '../../components/shared/sources_table';

Expand Down Expand Up @@ -43,13 +42,6 @@ describe('PrivateSources', () => {
expect(wrapper.find(SourcesView)).toHaveLength(1);
});

it('renders Loading when loading', () => {
setMockValues({ ...mockValues, dataLoading: true });
const wrapper = shallow(<PrivateSources />);

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

it('renders only shared sources section when canCreatePersonalSources is false', () => {
setMockValues({ ...mockValues });
const wrapper = shallow(<PrivateSources />);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,13 @@ import { EuiCallOut, EuiEmptyPrompt, EuiSpacer, EuiPanel } from '@elastic/eui';
import { FormattedMessage } from '@kbn/i18n/react';

import { LicensingLogic } from '../../../shared/licensing';
import { Loading } from '../../../shared/loading';
import { EuiButtonTo } from '../../../shared/react_router_helpers';
import { AppLogic } from '../../app_logic';
import noSharedSourcesIcon from '../../assets/share_circle.svg';
import { PersonalDashboardLayout } from '../../components/layout';
import { ContentSection } from '../../components/shared/content_section';
import { SourcesTable } from '../../components/shared/sources_table';
import { NAV } from '../../constants';
import { ADD_SOURCE_PATH, getSourcesPath } from '../../routes';
import { toSentenceSerial } from '../../utils';

Expand Down Expand Up @@ -53,8 +54,6 @@ export const PrivateSources: React.FC = () => {
account: { canCreatePersonalSources, groups },
} = useValues(AppLogic);

if (dataLoading) return <Loading />;

const hasConfiguredConnectors = serviceTypes.some(({ configured }) => configured);
const canAddSources = canCreatePersonalSources && hasConfiguredConnectors;
const hasPrivateSources = privateContentSources?.length > 0;
Expand Down Expand Up @@ -144,10 +143,12 @@ export const PrivateSources: React.FC = () => {
);

return (
<SourcesView>
{hasPrivateSources && !hasPlatinumLicense && licenseCallout}
{canCreatePersonalSources && privateSourcesSection}
{sharedSourcesSection}
</SourcesView>
<PersonalDashboardLayout pageChrome={[NAV.SOURCES]} isLoading={dataLoading}>
<SourcesView>
{hasPrivateSources && !hasPlatinumLicense && licenseCallout}
{canCreatePersonalSources && privateSourcesSection}
{sharedSourcesSection}
</SourcesView>
</PersonalDashboardLayout>
);
};