Skip to content

Commit

Permalink
[ILM] Update UrlGenerator interface, clean up internal navigation ser…
Browse files Browse the repository at this point in the history
…vice
  • Loading branch information
yuliacech committed Sep 21, 2020
1 parent 2e94ed2 commit 8173db2
Show file tree
Hide file tree
Showing 13 changed files with 71 additions and 75 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,7 @@ import { registerTestBed, TestBedConfig, TestBed } from '../../../../../test_uti
import { PipelinesClone } from '../../../public/application/sections/pipelines_clone';
import { getFormActions, PipelineFormTestSubjects } from './pipeline_form.helpers';
import { WithAppDependencies } from './setup_environment';
import {
INGEST_PIPELINES_PAGES,
ROUTES_CONFIG,
URL_GENERATOR,
} from '../../../public/application/services/navigation';
import { getClonePath, ROUTES_CONFIG } from '../../../public/application/services/navigation';

export type PipelinesCloneTestBed = TestBed<PipelineFormTestSubjects> & {
actions: ReturnType<typeof getFormActions>;
Expand All @@ -33,8 +29,8 @@ export const PIPELINE_TO_CLONE = {

const testBedConfig: TestBedConfig = {
memoryRouter: {
initialEntries: [URL_GENERATOR[INGEST_PIPELINES_PAGES.CLONE](PIPELINE_TO_CLONE.name)],
componentRoutePath: ROUTES_CONFIG[INGEST_PIPELINES_PAGES.CLONE],
initialEntries: [getClonePath(PIPELINE_TO_CLONE.name)],
componentRoutePath: ROUTES_CONFIG.clone,
},
doMountAsync: true,
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,16 @@ import { registerTestBed, TestBedConfig, TestBed } from '../../../../../test_uti
import { PipelinesCreate } from '../../../public/application/sections/pipelines_create';
import { getFormActions, PipelineFormTestSubjects } from './pipeline_form.helpers';
import { WithAppDependencies } from './setup_environment';
import {
INGEST_PIPELINES_PAGES,
ROUTES_CONFIG,
URL_GENERATOR,
} from '../../../public/application/services/navigation';
import { getCreatePath, ROUTES_CONFIG } from '../../../public/application/services/navigation';

export type PipelinesCreateTestBed = TestBed<PipelineFormTestSubjects> & {
actions: ReturnType<typeof getFormActions>;
};

const testBedConfig: TestBedConfig = {
memoryRouter: {
initialEntries: [URL_GENERATOR[INGEST_PIPELINES_PAGES.CREATE]()],
componentRoutePath: ROUTES_CONFIG[INGEST_PIPELINES_PAGES.CREATE],
initialEntries: [getCreatePath()],
componentRoutePath: ROUTES_CONFIG.create,
},
doMountAsync: true,
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,7 @@ import { registerTestBed, TestBedConfig, TestBed } from '../../../../../test_uti
import { PipelinesEdit } from '../../../public/application/sections/pipelines_edit';
import { getFormActions, PipelineFormTestSubjects } from './pipeline_form.helpers';
import { WithAppDependencies } from './setup_environment';
import {
INGEST_PIPELINES_PAGES,
ROUTES_CONFIG,
URL_GENERATOR,
} from '../../../public/application/services/navigation';
import { getEditPath, ROUTES_CONFIG } from '../../../public/application/services/navigation';

export type PipelinesEditTestBed = TestBed<PipelineFormTestSubjects> & {
actions: ReturnType<typeof getFormActions>;
Expand All @@ -33,8 +29,8 @@ export const PIPELINE_TO_EDIT = {

const testBedConfig: TestBedConfig = {
memoryRouter: {
initialEntries: [URL_GENERATOR[INGEST_PIPELINES_PAGES.EDIT](PIPELINE_TO_EDIT.name)],
componentRoutePath: ROUTES_CONFIG[INGEST_PIPELINES_PAGES.EDIT],
initialEntries: [getEditPath(PIPELINE_TO_EDIT.name)],
componentRoutePath: ROUTES_CONFIG.edit,
},
doMountAsync: true,
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,12 @@ import {
} from '../../../../../test_utils';
import { PipelinesList } from '../../../public/application/sections/pipelines_list';
import { WithAppDependencies } from './setup_environment';
import {
INGEST_PIPELINES_PAGES,
ROUTES_CONFIG,
URL_GENERATOR,
} from '../../../public/application/services/navigation';
import { getListPath, ROUTES_CONFIG } from '../../../public/application/services/navigation';

const testBedConfig: TestBedConfig = {
memoryRouter: {
initialEntries: [URL_GENERATOR[INGEST_PIPELINES_PAGES.LIST]()],
componentRoutePath: ROUTES_CONFIG[INGEST_PIPELINES_PAGES.LIST],
initialEntries: [getListPath()],
componentRoutePath: ROUTES_CONFIG.list,
},
doMountAsync: true,
};
Expand Down
10 changes: 5 additions & 5 deletions x-pack/plugins/ingest_pipelines/public/application/app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,14 @@ import {
} from '../shared_imports';

import { PipelinesList, PipelinesCreate, PipelinesEdit, PipelinesClone } from './sections';
import { INGEST_PIPELINES_PAGES, ROUTES_CONFIG } from './services/navigation';
import { ROUTES_CONFIG } from './services/navigation';

export const AppWithoutRouter = () => (
<Switch>
<Route exact path={ROUTES_CONFIG[INGEST_PIPELINES_PAGES.LIST]} component={PipelinesList} />
<Route exact path={ROUTES_CONFIG[INGEST_PIPELINES_PAGES.CLONE]} component={PipelinesClone} />
<Route exact path={ROUTES_CONFIG[INGEST_PIPELINES_PAGES.CREATE]} component={PipelinesCreate} />
<Route exact path={ROUTES_CONFIG[INGEST_PIPELINES_PAGES.EDIT]} component={PipelinesEdit} />
<Route exact path={ROUTES_CONFIG.list} component={PipelinesList} />
<Route exact path={ROUTES_CONFIG.clone} component={PipelinesClone} />
<Route exact path={ROUTES_CONFIG.create} component={PipelinesCreate} />
<Route exact path={ROUTES_CONFIG.edit} component={PipelinesEdit} />
{/* Catch all */}
<Route component={PipelinesList} />
</Switch>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import {
EuiSpacer,
} from '@elastic/eui';

import { INGEST_PIPELINES_PAGES, URL_GENERATOR } from '../../services/navigation';
import { getListPath } from '../../services/navigation';
import { Pipeline } from '../../../../common/types';
import { useKibana } from '../../../shared_imports';
import { PipelineForm } from '../../components';
Expand Down Expand Up @@ -50,11 +50,11 @@ export const PipelinesCreate: React.FunctionComponent<RouteComponentProps & Prop
return;
}

history.push(URL_GENERATOR[INGEST_PIPELINES_PAGES.LIST](pipeline.name));
history.push(getListPath(pipeline.name));
};

const onCancel = () => {
history.push(URL_GENERATOR[INGEST_PIPELINES_PAGES.LIST]());
history.push(getListPath());
};

useEffect(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import { EuiCallOut } from '@elastic/eui';
import { Pipeline } from '../../../../common/types';
import { useKibana, SectionLoading } from '../../../shared_imports';

import { INGEST_PIPELINES_PAGES, URL_GENERATOR } from '../../services/navigation';
import { getListPath } from '../../services/navigation';
import { PipelineForm } from '../../components';
import { attemptToURIDecode } from '../shared';

Expand Down Expand Up @@ -56,11 +56,11 @@ export const PipelinesEdit: React.FunctionComponent<RouteComponentProps<MatchPar
return;
}

history.push(URL_GENERATOR[INGEST_PIPELINES_PAGES.LIST](updatedPipeline.name));
history.push(getListPath(updatedPipeline.name));
};

const onCancel = () => {
history.push(URL_GENERATOR[INGEST_PIPELINES_PAGES.LIST]());
history.push(getListPath());
};

useEffect(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { useHistory } from 'react-router-dom';
import { ScopedHistory } from 'kibana/public';
import { reactRouterNavigate } from '../../../../../../../src/plugins/kibana_react/public';
import { useKibana } from '../../../shared_imports';
import { INGEST_PIPELINES_PAGES, URL_GENERATOR } from '../../services/navigation';
import { getCreatePath } from '../../services/navigation';

export const EmptyList: FunctionComponent = () => {
const { services } = useKibana();
Expand Down Expand Up @@ -46,7 +46,7 @@ export const EmptyList: FunctionComponent = () => {
}
actions={
<EuiButton
{...reactRouterNavigate(history, URL_GENERATOR[INGEST_PIPELINES_PAGES.CREATE]())}
{...reactRouterNavigate(history, getCreatePath())}
iconType="plusInCircle"
fill
>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import {
import { Pipeline } from '../../../../common/types';
import { useKibana, SectionLoading } from '../../../shared_imports';
import { UIM_PIPELINES_LIST_LOAD } from '../../constants';
import { INGEST_PIPELINES_PAGES, URL_GENERATOR } from '../../services/navigation';
import { getEditPath, getClonePath, getListPath } from '../../services/navigation';

import { EmptyList } from './empty_list';
import { PipelineTable } from './table';
Expand Down Expand Up @@ -68,16 +68,16 @@ export const PipelinesList: React.FunctionComponent<RouteComponentProps> = ({
}, [pipelineNameFromLocation, data]);

const goToEditPipeline = (name: string) => {
history.push(URL_GENERATOR[INGEST_PIPELINES_PAGES.EDIT](name));
history.push(getEditPath(name));
};

const goToClonePipeline = (name: string) => {
history.push(URL_GENERATOR[INGEST_PIPELINES_PAGES.CLONE](name));
history.push(getClonePath(name));
};

const goHome = () => {
setShowFlyout(false);
history.push(URL_GENERATOR[INGEST_PIPELINES_PAGES.LIST]());
history.push(getListPath());
};

if (data && data.length === 0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,39 +10,30 @@ const EDIT_PATH = 'edit';

const CREATE_PATH = 'create';

const getEditPath = (name: string, encode = true): string => {
const _getEditPath = (name: string, encode = true): string => {
return `${BASE_PATH}${EDIT_PATH}/${encode ? encodeURIComponent(name) : name}`;
};

const getCreatePath = (): string => {
const _getCreatePath = (): string => {
return `${BASE_PATH}${CREATE_PATH}`;
};

const getClonePath = (name: string, encode = true): string => {
const _getClonePath = (name: string, encode = true): string => {
return `${BASE_PATH}${CREATE_PATH}/${encode ? encodeURIComponent(name) : name}`;
};
const getListPath = (name?: string): string => {
const _getListPath = (name?: string): string => {
return `${BASE_PATH}${name ? `?pipeline=${encodeURIComponent(name)}` : ''}`;
};

export enum INGEST_PIPELINES_PAGES {
LIST = 'pipelines_list',
EDIT = 'pipeline_edit',
CREATE = 'pipeline_create',
CLONE = 'pipeline_clone',
}

export const ROUTES_CONFIG = {
[INGEST_PIPELINES_PAGES.LIST]: getListPath(),
[INGEST_PIPELINES_PAGES.EDIT]: getEditPath(':name', false),
[INGEST_PIPELINES_PAGES.CREATE]: getCreatePath(),
[INGEST_PIPELINES_PAGES.CLONE]: getClonePath(':sourceName', false),
list: _getListPath(),
edit: _getEditPath(':name', false),
create: _getCreatePath(),
clone: _getClonePath(':sourceName', false),
};

export const URL_GENERATOR = {
[INGEST_PIPELINES_PAGES.LIST]: (selectedPipelineName?: string) =>
getListPath(selectedPipelineName),
[INGEST_PIPELINES_PAGES.EDIT]: (pipelineName: string) => getEditPath(pipelineName, true),
[INGEST_PIPELINES_PAGES.CREATE]: getCreatePath,
[INGEST_PIPELINES_PAGES.CLONE]: (pipelineName: string) => getClonePath(pipelineName, true),
};
export const getListPath = (selectedPipelineName?: string): string =>
_getListPath(selectedPipelineName);
export const getEditPath = (pipelineName: string): string => _getEditPath(pipelineName, true);
export const getCreatePath = (): string => _getCreatePath;
export const getClonePath = (pipelineName: string): string => _getClonePath(pipelineName, true);
3 changes: 1 addition & 2 deletions x-pack/plugins/ingest_pipelines/public/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,5 @@ export function plugin() {
export {
INGEST_PIPELINES_APP_ULR_GENERATOR,
IngestPipelinesUrlGeneratorState,
INGEST_PIPELINES_PAGES,
} from './url_generator';

export { INGEST_PIPELINES_PAGES } from './application/services/navigation';
3 changes: 1 addition & 2 deletions x-pack/plugins/ingest_pipelines/public/url_generator.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@
* you may not use this file except in compliance with the Elastic License.
*/

import { IngestPipelinesUrlGenerator } from './url_generator';
import { INGEST_PIPELINES_PAGES } from './application/services/navigation';
import { IngestPipelinesUrlGenerator, INGEST_PIPELINES_PAGES } from './url_generator';

describe('IngestPipelinesUrlGenerator', () => {
const getAppBasePath = (absolute: boolean = false) => {
Expand Down
31 changes: 27 additions & 4 deletions x-pack/plugins/ingest_pipelines/public/url_generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,24 @@

import { CoreSetup } from 'src/core/public';
import { UrlGeneratorsDefinition } from '../../../../src/plugins/share/public';
import { INGEST_PIPELINES_PAGES, URL_GENERATOR } from './application/services/navigation';
import {
getClonePath,
getCreatePath,
getEditPath,
getListPath,
} from './application/services/navigation';
import { Dependencies } from './types';
import { MANAGEMENT_APP_ID, PLUGIN_ID } from '../common/constants';

export const INGEST_PIPELINES_APP_ULR_GENERATOR = 'INGEST_PIPELINES_APP_URL_GENERATOR';

export enum INGEST_PIPELINES_PAGES {
LIST = 'pipelines_list',
EDIT = 'pipeline_edit',
CREATE = 'pipeline_create',
CLONE = 'pipeline_clone',
}

interface UrlGeneratorState {
pipelineId: string;
absolute?: boolean;
Expand Down Expand Up @@ -45,9 +57,20 @@ export class IngestPipelinesUrlGenerator
public readonly id = INGEST_PIPELINES_APP_ULR_GENERATOR;

public readonly createUrl = async (state: IngestPipelinesUrlGeneratorState): Promise<string> => {
return `${await this.getAppBasePath(!!state.absolute)}${URL_GENERATOR[state.page](
state.pipelineId!
)}`;
switch (state.page) {
case INGEST_PIPELINES_PAGES.EDIT: {
return `${await this.getAppBasePath(!!state.absolute)}${getEditPath(state.pipelineId)}`;
}
case INGEST_PIPELINES_PAGES.CREATE: {
return `${await this.getAppBasePath(!!state.absolute)}${getCreatePath()}`;
}
case INGEST_PIPELINES_PAGES.LIST: {
return `${await this.getAppBasePath(!!state.absolute)}${getListPath(state.pipelineId)}`;
}
case INGEST_PIPELINES_PAGES.CLONE: {
return `${await this.getAppBasePath(!!state.absolute)}${getClonePath(state.pipelineId)}`;
}
}
};
}

Expand Down

0 comments on commit 8173db2

Please sign in to comment.