Skip to content

Commit 8173db2

Browse files
committed
[ILM] Update UrlGenerator interface, clean up internal navigation service
1 parent 2e94ed2 commit 8173db2

13 files changed

Lines changed: 71 additions & 75 deletions

File tree

x-pack/plugins/ingest_pipelines/__jest__/client_integration/helpers/pipelines_clone.helpers.ts

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,7 @@ import { registerTestBed, TestBedConfig, TestBed } from '../../../../../test_uti
88
import { PipelinesClone } from '../../../public/application/sections/pipelines_clone';
99
import { getFormActions, PipelineFormTestSubjects } from './pipeline_form.helpers';
1010
import { WithAppDependencies } from './setup_environment';
11-
import {
12-
INGEST_PIPELINES_PAGES,
13-
ROUTES_CONFIG,
14-
URL_GENERATOR,
15-
} from '../../../public/application/services/navigation';
11+
import { getClonePath, ROUTES_CONFIG } from '../../../public/application/services/navigation';
1612

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

3430
const testBedConfig: TestBedConfig = {
3531
memoryRouter: {
36-
initialEntries: [URL_GENERATOR[INGEST_PIPELINES_PAGES.CLONE](PIPELINE_TO_CLONE.name)],
37-
componentRoutePath: ROUTES_CONFIG[INGEST_PIPELINES_PAGES.CLONE],
32+
initialEntries: [getClonePath(PIPELINE_TO_CLONE.name)],
33+
componentRoutePath: ROUTES_CONFIG.clone,
3834
},
3935
doMountAsync: true,
4036
};

x-pack/plugins/ingest_pipelines/__jest__/client_integration/helpers/pipelines_create.helpers.ts

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,20 +8,16 @@ import { registerTestBed, TestBedConfig, TestBed } from '../../../../../test_uti
88
import { PipelinesCreate } from '../../../public/application/sections/pipelines_create';
99
import { getFormActions, PipelineFormTestSubjects } from './pipeline_form.helpers';
1010
import { WithAppDependencies } from './setup_environment';
11-
import {
12-
INGEST_PIPELINES_PAGES,
13-
ROUTES_CONFIG,
14-
URL_GENERATOR,
15-
} from '../../../public/application/services/navigation';
11+
import { getCreatePath, ROUTES_CONFIG } from '../../../public/application/services/navigation';
1612

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

2117
const testBedConfig: TestBedConfig = {
2218
memoryRouter: {
23-
initialEntries: [URL_GENERATOR[INGEST_PIPELINES_PAGES.CREATE]()],
24-
componentRoutePath: ROUTES_CONFIG[INGEST_PIPELINES_PAGES.CREATE],
19+
initialEntries: [getCreatePath()],
20+
componentRoutePath: ROUTES_CONFIG.create,
2521
},
2622
doMountAsync: true,
2723
};

x-pack/plugins/ingest_pipelines/__jest__/client_integration/helpers/pipelines_edit.helpers.ts

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,7 @@ import { registerTestBed, TestBedConfig, TestBed } from '../../../../../test_uti
88
import { PipelinesEdit } from '../../../public/application/sections/pipelines_edit';
99
import { getFormActions, PipelineFormTestSubjects } from './pipeline_form.helpers';
1010
import { WithAppDependencies } from './setup_environment';
11-
import {
12-
INGEST_PIPELINES_PAGES,
13-
ROUTES_CONFIG,
14-
URL_GENERATOR,
15-
} from '../../../public/application/services/navigation';
11+
import { getEditPath, ROUTES_CONFIG } from '../../../public/application/services/navigation';
1612

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

3430
const testBedConfig: TestBedConfig = {
3531
memoryRouter: {
36-
initialEntries: [URL_GENERATOR[INGEST_PIPELINES_PAGES.EDIT](PIPELINE_TO_EDIT.name)],
37-
componentRoutePath: ROUTES_CONFIG[INGEST_PIPELINES_PAGES.EDIT],
32+
initialEntries: [getEditPath(PIPELINE_TO_EDIT.name)],
33+
componentRoutePath: ROUTES_CONFIG.edit,
3834
},
3935
doMountAsync: true,
4036
};

x-pack/plugins/ingest_pipelines/__jest__/client_integration/helpers/pipelines_list.helpers.ts

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,12 @@ import {
1515
} from '../../../../../test_utils';
1616
import { PipelinesList } from '../../../public/application/sections/pipelines_list';
1717
import { WithAppDependencies } from './setup_environment';
18-
import {
19-
INGEST_PIPELINES_PAGES,
20-
ROUTES_CONFIG,
21-
URL_GENERATOR,
22-
} from '../../../public/application/services/navigation';
18+
import { getListPath, ROUTES_CONFIG } from '../../../public/application/services/navigation';
2319

2420
const testBedConfig: TestBedConfig = {
2521
memoryRouter: {
26-
initialEntries: [URL_GENERATOR[INGEST_PIPELINES_PAGES.LIST]()],
27-
componentRoutePath: ROUTES_CONFIG[INGEST_PIPELINES_PAGES.LIST],
22+
initialEntries: [getListPath()],
23+
componentRoutePath: ROUTES_CONFIG.list,
2824
},
2925
doMountAsync: true,
3026
};

x-pack/plugins/ingest_pipelines/public/application/app.tsx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,14 @@ import {
2121
} from '../shared_imports';
2222

2323
import { PipelinesList, PipelinesCreate, PipelinesEdit, PipelinesClone } from './sections';
24-
import { INGEST_PIPELINES_PAGES, ROUTES_CONFIG } from './services/navigation';
24+
import { ROUTES_CONFIG } from './services/navigation';
2525

2626
export const AppWithoutRouter = () => (
2727
<Switch>
28-
<Route exact path={ROUTES_CONFIG[INGEST_PIPELINES_PAGES.LIST]} component={PipelinesList} />
29-
<Route exact path={ROUTES_CONFIG[INGEST_PIPELINES_PAGES.CLONE]} component={PipelinesClone} />
30-
<Route exact path={ROUTES_CONFIG[INGEST_PIPELINES_PAGES.CREATE]} component={PipelinesCreate} />
31-
<Route exact path={ROUTES_CONFIG[INGEST_PIPELINES_PAGES.EDIT]} component={PipelinesEdit} />
28+
<Route exact path={ROUTES_CONFIG.list} component={PipelinesList} />
29+
<Route exact path={ROUTES_CONFIG.clone} component={PipelinesClone} />
30+
<Route exact path={ROUTES_CONFIG.create} component={PipelinesCreate} />
31+
<Route exact path={ROUTES_CONFIG.edit} component={PipelinesEdit} />
3232
{/* Catch all */}
3333
<Route component={PipelinesList} />
3434
</Switch>

x-pack/plugins/ingest_pipelines/public/application/sections/pipelines_create/pipelines_create.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import {
1616
EuiSpacer,
1717
} from '@elastic/eui';
1818

19-
import { INGEST_PIPELINES_PAGES, URL_GENERATOR } from '../../services/navigation';
19+
import { getListPath } from '../../services/navigation';
2020
import { Pipeline } from '../../../../common/types';
2121
import { useKibana } from '../../../shared_imports';
2222
import { PipelineForm } from '../../components';
@@ -50,11 +50,11 @@ export const PipelinesCreate: React.FunctionComponent<RouteComponentProps & Prop
5050
return;
5151
}
5252

53-
history.push(URL_GENERATOR[INGEST_PIPELINES_PAGES.LIST](pipeline.name));
53+
history.push(getListPath(pipeline.name));
5454
};
5555

5656
const onCancel = () => {
57-
history.push(URL_GENERATOR[INGEST_PIPELINES_PAGES.LIST]());
57+
history.push(getListPath());
5858
};
5959

6060
useEffect(() => {

x-pack/plugins/ingest_pipelines/public/application/sections/pipelines_edit/pipelines_edit.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import { EuiCallOut } from '@elastic/eui';
2020
import { Pipeline } from '../../../../common/types';
2121
import { useKibana, SectionLoading } from '../../../shared_imports';
2222

23-
import { INGEST_PIPELINES_PAGES, URL_GENERATOR } from '../../services/navigation';
23+
import { getListPath } from '../../services/navigation';
2424
import { PipelineForm } from '../../components';
2525
import { attemptToURIDecode } from '../shared';
2626

@@ -56,11 +56,11 @@ export const PipelinesEdit: React.FunctionComponent<RouteComponentProps<MatchPar
5656
return;
5757
}
5858

59-
history.push(URL_GENERATOR[INGEST_PIPELINES_PAGES.LIST](updatedPipeline.name));
59+
history.push(getListPath(updatedPipeline.name));
6060
};
6161

6262
const onCancel = () => {
63-
history.push(URL_GENERATOR[INGEST_PIPELINES_PAGES.LIST]());
63+
history.push(getListPath());
6464
};
6565

6666
useEffect(() => {

x-pack/plugins/ingest_pipelines/public/application/sections/pipelines_list/empty_list.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import { useHistory } from 'react-router-dom';
1111
import { ScopedHistory } from 'kibana/public';
1212
import { reactRouterNavigate } from '../../../../../../../src/plugins/kibana_react/public';
1313
import { useKibana } from '../../../shared_imports';
14-
import { INGEST_PIPELINES_PAGES, URL_GENERATOR } from '../../services/navigation';
14+
import { getCreatePath } from '../../services/navigation';
1515

1616
export const EmptyList: FunctionComponent = () => {
1717
const { services } = useKibana();
@@ -46,7 +46,7 @@ export const EmptyList: FunctionComponent = () => {
4646
}
4747
actions={
4848
<EuiButton
49-
{...reactRouterNavigate(history, URL_GENERATOR[INGEST_PIPELINES_PAGES.CREATE]())}
49+
{...reactRouterNavigate(history, getCreatePath())}
5050
iconType="plusInCircle"
5151
fill
5252
>

x-pack/plugins/ingest_pipelines/public/application/sections/pipelines_list/main.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ import {
2626
import { Pipeline } from '../../../../common/types';
2727
import { useKibana, SectionLoading } from '../../../shared_imports';
2828
import { UIM_PIPELINES_LIST_LOAD } from '../../constants';
29-
import { INGEST_PIPELINES_PAGES, URL_GENERATOR } from '../../services/navigation';
29+
import { getEditPath, getClonePath, getListPath } from '../../services/navigation';
3030

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

7070
const goToEditPipeline = (name: string) => {
71-
history.push(URL_GENERATOR[INGEST_PIPELINES_PAGES.EDIT](name));
71+
history.push(getEditPath(name));
7272
};
7373

7474
const goToClonePipeline = (name: string) => {
75-
history.push(URL_GENERATOR[INGEST_PIPELINES_PAGES.CLONE](name));
75+
history.push(getClonePath(name));
7676
};
7777

7878
const goHome = () => {
7979
setShowFlyout(false);
80-
history.push(URL_GENERATOR[INGEST_PIPELINES_PAGES.LIST]());
80+
history.push(getListPath());
8181
};
8282

8383
if (data && data.length === 0) {

x-pack/plugins/ingest_pipelines/public/application/services/navigation.ts

Lines changed: 13 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -10,39 +10,30 @@ const EDIT_PATH = 'edit';
1010

1111
const CREATE_PATH = 'create';
1212

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

17-
const getCreatePath = (): string => {
17+
const _getCreatePath = (): string => {
1818
return `${BASE_PATH}${CREATE_PATH}`;
1919
};
2020

21-
const getClonePath = (name: string, encode = true): string => {
21+
const _getClonePath = (name: string, encode = true): string => {
2222
return `${BASE_PATH}${CREATE_PATH}/${encode ? encodeURIComponent(name) : name}`;
2323
};
24-
const getListPath = (name?: string): string => {
24+
const _getListPath = (name?: string): string => {
2525
return `${BASE_PATH}${name ? `?pipeline=${encodeURIComponent(name)}` : ''}`;
2626
};
2727

28-
export enum INGEST_PIPELINES_PAGES {
29-
LIST = 'pipelines_list',
30-
EDIT = 'pipeline_edit',
31-
CREATE = 'pipeline_create',
32-
CLONE = 'pipeline_clone',
33-
}
34-
3528
export const ROUTES_CONFIG = {
36-
[INGEST_PIPELINES_PAGES.LIST]: getListPath(),
37-
[INGEST_PIPELINES_PAGES.EDIT]: getEditPath(':name', false),
38-
[INGEST_PIPELINES_PAGES.CREATE]: getCreatePath(),
39-
[INGEST_PIPELINES_PAGES.CLONE]: getClonePath(':sourceName', false),
29+
list: _getListPath(),
30+
edit: _getEditPath(':name', false),
31+
create: _getCreatePath(),
32+
clone: _getClonePath(':sourceName', false),
4033
};
4134

42-
export const URL_GENERATOR = {
43-
[INGEST_PIPELINES_PAGES.LIST]: (selectedPipelineName?: string) =>
44-
getListPath(selectedPipelineName),
45-
[INGEST_PIPELINES_PAGES.EDIT]: (pipelineName: string) => getEditPath(pipelineName, true),
46-
[INGEST_PIPELINES_PAGES.CREATE]: getCreatePath,
47-
[INGEST_PIPELINES_PAGES.CLONE]: (pipelineName: string) => getClonePath(pipelineName, true),
48-
};
35+
export const getListPath = (selectedPipelineName?: string): string =>
36+
_getListPath(selectedPipelineName);
37+
export const getEditPath = (pipelineName: string): string => _getEditPath(pipelineName, true);
38+
export const getCreatePath = (): string => _getCreatePath;
39+
export const getClonePath = (pipelineName: string): string => _getClonePath(pipelineName, true);

0 commit comments

Comments
 (0)