Skip to content

Commit

Permalink
[Workplace Search] Refactor Add Source Views to support base service …
Browse files Browse the repository at this point in the history
…types for external connectors (#131802)
  • Loading branch information
Byron Hulcher authored May 10, 2022
1 parent 4ef0f1e commit 626b4ae
Show file tree
Hide file tree
Showing 52 changed files with 1,415 additions and 1,447 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ import {
SOURCES_PATH,
PRIVATE_SOURCES_PATH,
SOURCE_DETAILS_PATH,
getAddPath,
getEditPath,
} from './routes';

const TestComponent = ({ id, isOrg }: { id: string; isOrg?: boolean }) => {
Expand Down Expand Up @@ -86,3 +88,32 @@ describe('getReindexJobRoute', () => {
);
});
});

describe('getAddPath', () => {
it('should handle a service type', () => {
expect(getAddPath('share_point')).toEqual('/sources/add/share_point');
});

it('should should handle an external service type with no base service type', () => {
expect(getAddPath('external')).toEqual('/sources/add/external');
});

it('should should handle an external service type with a base service type', () => {
expect(getAddPath('external', 'share_point')).toEqual('/sources/add/share_point/external');
});
it('should should handle a custom service type with no base service type', () => {
expect(getAddPath('external')).toEqual('/sources/add/external');
});

it('should should handle a custom service type with a base service type', () => {
expect(getAddPath('custom', 'share_point_server')).toEqual(
'/sources/add/share_point_server/custom'
);
});
});

describe('getEditPath', () => {
it('should handle a service type', () => {
expect(getEditPath('share_point')).toEqual('/settings/connectors/share_point/edit');
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,14 @@ export const getReindexJobRoute = (
isOrganization: boolean
) =>
getSourcesPath(generatePath(REINDEX_JOB_PATH, { sourceId, activeReindexJobId }), isOrganization);
export const getAddPath = (serviceType: string): string => `${SOURCES_PATH}/add/${serviceType}`;

export const getAddPath = (serviceType: string, baseServiceType?: string): string => {
const baseServiceTypePath = baseServiceType
? `${baseServiceType}/${serviceType}`
: `${serviceType}`;
return `${SOURCES_PATH}/add/${baseServiceTypePath}`;
};

// TODO this should handle base service type once we are getting it back from registered external connectors
export const getEditPath = (serviceType: string): string =>
`${ORG_SETTINGS_CONNECTORS_PATH}/${serviceType}/edit`;
Original file line number Diff line number Diff line change
Expand Up @@ -72,18 +72,14 @@ export interface Configuration {

export interface SourceDataItem {
name: string;
iconName: string;
categories?: string[];
serviceType: string;
baseServiceType?: string;
configuration: Configuration;
configured?: boolean;
connected?: boolean;
features?: Features;
objTypes?: string[];
accountContextOnly: boolean;
internalConnectorAvailable?: boolean;
externalConnectorAvailable?: boolean;
customConnectorAvailable?: boolean;
isBeta?: boolean;
}

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,5 @@ export { mimeType } from './mime_types';
export { readUploadedFileAsBase64 } from './read_uploaded_file_as_base64';
export { readUploadedFileAsText } from './read_uploaded_file_as_text';
export { handlePrivateKeyUpload } from './handle_private_key_upload';
export { hasMultipleConnectorOptions } from './has_multiple_connector_options';
export { isNotNullish } from './is_not_nullish';
export { sortByName } from './sort_by_name';
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import '../../../../../../__mocks__/shallow_useeffect.mock';
import { setMockValues } from '../../../../../../__mocks__/kea_logic';
import { mockUseParams } from '../../../../../../__mocks__/react_router';
import { sourceConfigData } from '../../../../../__mocks__/content_sources.mock';

import React from 'react';
Expand All @@ -17,52 +18,55 @@ import {
WorkplaceSearchPageTemplate,
PersonalDashboardLayout,
} from '../../../../../components/layout';
import { staticSourceData } from '../../../source_data';

import { AddCustomSource } from './add_custom_source';
import { AddCustomSourceSteps } from './add_custom_source_logic';
import { ConfigureCustom } from './configure_custom';
import { SaveCustom } from './save_custom';

describe('AddCustomSource', () => {
const props = {
sourceData: staticSourceData[0],
initialValues: undefined,
};

const values = {
sourceConfigData,
isOrganization: true,
};

beforeEach(() => {
setMockValues({ ...values });
mockUseParams.mockReturnValue({ baseServiceType: 'share_point_server' });
});

it('renders', () => {
const wrapper = shallow(<AddCustomSource {...props} />);
const wrapper = shallow(<AddCustomSource />);

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

it('returns null if there is no matching source data for the service type', () => {
mockUseParams.mockReturnValue({ baseServiceType: 'doesnt_exist' });

const wrapper = shallow(<AddCustomSource />);

expect(wrapper.isEmptyRender()).toBe(true);
});

it('should show correct layout for personal dashboard', () => {
setMockValues({ isOrganization: false });
const wrapper = shallow(<AddCustomSource {...props} />);
const wrapper = shallow(<AddCustomSource />);

expect(wrapper.find(WorkplaceSearchPageTemplate)).toHaveLength(0);
expect(wrapper.find(PersonalDashboardLayout)).toHaveLength(1);
});

it('should show Configure Custom for custom configuration step', () => {
setMockValues({ currentStep: AddCustomSourceSteps.ConfigureCustomStep });
const wrapper = shallow(<AddCustomSource {...props} />);
const wrapper = shallow(<AddCustomSource />);

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

it('should show Save Custom for save custom step', () => {
setMockValues({ currentStep: AddCustomSourceSteps.SaveCustomStep });
const wrapper = shallow(<AddCustomSource {...props} />);
const wrapper = shallow(<AddCustomSource />);

expect(wrapper.find(SaveCustom)).toHaveLength(1);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@

import React from 'react';

import { useParams } from 'react-router-dom';

import { useValues } from 'kea';

import { AppLogic } from '../../../../../app_logic';
Expand All @@ -16,27 +18,38 @@ import {
} from '../../../../../components/layout';
import { NAV } from '../../../../../constants';

import { SourceDataItem } from '../../../../../types';
import { getSourceData } from '../../../source_data';

import { AddCustomSourceLogic, AddCustomSourceSteps } from './add_custom_source_logic';
import { ConfigureCustom } from './configure_custom';
import { SaveCustom } from './save_custom';

interface Props {
sourceData: SourceDataItem;
initialValue?: string;
}
export const AddCustomSource: React.FC<Props> = ({ sourceData, initialValue = '' }) => {
const addCustomSourceLogic = AddCustomSourceLogic({ sourceData, initialValue });
export const AddCustomSource: React.FC = () => {
const { baseServiceType } = useParams<{ baseServiceType?: string }>();
const sourceData = getSourceData('custom', baseServiceType);

const addCustomSourceLogic = AddCustomSourceLogic({
baseServiceType,
initialValue: sourceData?.name,
});

const { currentStep } = useValues(addCustomSourceLogic);
const { isOrganization } = useValues(AppLogic);

if (!sourceData) {
return null;
}

const Layout = isOrganization ? WorkplaceSearchPageTemplate : PersonalDashboardLayout;

return (
<Layout pageChrome={[NAV.SOURCES, NAV.ADD_SOURCE, sourceData.name || '...']}>
{currentStep === AddCustomSourceSteps.ConfigureCustomStep && <ConfigureCustom />}
{currentStep === AddCustomSourceSteps.SaveCustomStep && <SaveCustom />}
<Layout pageChrome={[NAV.SOURCES, NAV.ADD_SOURCE, sourceData.name]}>
{currentStep === AddCustomSourceSteps.ConfigureCustomStep && (
<ConfigureCustom sourceData={sourceData} />
)}
{currentStep === AddCustomSourceSteps.SaveCustomStep && (
<SaveCustom sourceData={sourceData} />
)}
</Layout>
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -14,43 +14,24 @@ import { sourceConfigData } from '../../../../../__mocks__/content_sources.mock'

import { nextTick } from '@kbn/test-jest-helpers';

import { docLinks } from '../../../../../../shared/doc_links';
import { itShowsServerErrorAsFlashMessage } from '../../../../../../test_helpers';

jest.mock('../../../../../app_logic', () => ({
AppLogic: { values: { isOrganization: true } },
}));
import { AppLogic } from '../../../../../app_logic';

import { SOURCE_NAMES } from '../../../../../constants';
import { CustomSource, SourceDataItem } from '../../../../../types';
import { CustomSource } from '../../../../../types';

import { AddCustomSourceLogic, AddCustomSourceSteps } from './add_custom_source_logic';

const CUSTOM_SOURCE_DATA_ITEM: SourceDataItem = {
name: SOURCE_NAMES.CUSTOM,
iconName: SOURCE_NAMES.CUSTOM,
serviceType: 'custom',
configuration: {
isPublicKey: false,
hasOauthRedirect: false,
needsBaseUrl: false,
documentationUrl: docLinks.workplaceSearchCustomSources,
applicationPortalUrl: '',
},
accountContextOnly: false,
};

const DEFAULT_VALUES = {
currentStep: AddCustomSourceSteps.ConfigureCustomStep,
buttonLoading: false,
customSourceNameValue: '',
newCustomSource: {} as CustomSource,
sourceData: CUSTOM_SOURCE_DATA_ITEM,
};

const MOCK_PROPS = { initialValue: '', sourceData: CUSTOM_SOURCE_DATA_ITEM };

const MOCK_NAME = 'name';

describe('AddCustomSourceLogic', () => {
Expand All @@ -60,7 +41,7 @@ describe('AddCustomSourceLogic', () => {

beforeEach(() => {
jest.clearAllMocks();
mount({}, MOCK_PROPS);
mount({});
});

it('has expected default values', () => {
Expand Down Expand Up @@ -112,12 +93,9 @@ describe('AddCustomSourceLogic', () => {

describe('listeners', () => {
beforeEach(() => {
mount(
{
customSourceNameValue: MOCK_NAME,
},
MOCK_PROPS
);
mount({
customSourceNameValue: MOCK_NAME,
});
});

describe('organization context', () => {
Expand Down Expand Up @@ -151,11 +129,7 @@ describe('AddCustomSourceLogic', () => {
customSourceNameValue: MOCK_NAME,
},
{
...MOCK_PROPS,
sourceData: {
...CUSTOM_SOURCE_DATA_ITEM,
serviceType: 'sharepoint-server',
},
baseServiceType: 'share_point_server',
}
);

Expand All @@ -165,7 +139,7 @@ describe('AddCustomSourceLogic', () => {
body: JSON.stringify({
service_type: 'custom',
name: MOCK_NAME,
base_service_type: 'sharepoint-server',
base_service_type: 'share_point_server',
}),
});
});
Expand Down Expand Up @@ -199,11 +173,7 @@ describe('AddCustomSourceLogic', () => {
customSourceNameValue: MOCK_NAME,
},
{
...MOCK_PROPS,
sourceData: {
...CUSTOM_SOURCE_DATA_ITEM,
serviceType: 'sharepoint-server',
},
baseServiceType: 'share_point_server',
}
);

Expand All @@ -215,7 +185,7 @@ describe('AddCustomSourceLogic', () => {
body: JSON.stringify({
service_type: 'custom',
name: MOCK_NAME,
base_service_type: 'sharepoint-server',
base_service_type: 'share_point_server',
}),
}
);
Expand Down
Loading

0 comments on commit 626b4ae

Please sign in to comment.