diff --git a/x-pack/plugins/ingest_pipelines/__jest__/client_integration/helpers/pipelines_clone.helpers.ts b/x-pack/plugins/ingest_pipelines/__jest__/client_integration/helpers/pipelines_clone.helpers.ts index 2705750006081..5b30e8ec021a7 100644 --- a/x-pack/plugins/ingest_pipelines/__jest__/client_integration/helpers/pipelines_clone.helpers.ts +++ b/x-pack/plugins/ingest_pipelines/__jest__/client_integration/helpers/pipelines_clone.helpers.ts @@ -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 & { actions: ReturnType; @@ -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, }; diff --git a/x-pack/plugins/ingest_pipelines/__jest__/client_integration/helpers/pipelines_create.helpers.ts b/x-pack/plugins/ingest_pipelines/__jest__/client_integration/helpers/pipelines_create.helpers.ts index da3a482af78f4..b60400eb28a3c 100644 --- a/x-pack/plugins/ingest_pipelines/__jest__/client_integration/helpers/pipelines_create.helpers.ts +++ b/x-pack/plugins/ingest_pipelines/__jest__/client_integration/helpers/pipelines_create.helpers.ts @@ -8,11 +8,7 @@ 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 & { actions: ReturnType; @@ -20,8 +16,8 @@ export type PipelinesCreateTestBed = TestBed & { 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, }; diff --git a/x-pack/plugins/ingest_pipelines/__jest__/client_integration/helpers/pipelines_edit.helpers.ts b/x-pack/plugins/ingest_pipelines/__jest__/client_integration/helpers/pipelines_edit.helpers.ts index f84e313d2f3de..43649c5b5be54 100644 --- a/x-pack/plugins/ingest_pipelines/__jest__/client_integration/helpers/pipelines_edit.helpers.ts +++ b/x-pack/plugins/ingest_pipelines/__jest__/client_integration/helpers/pipelines_edit.helpers.ts @@ -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 & { actions: ReturnType; @@ -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, }; diff --git a/x-pack/plugins/ingest_pipelines/__jest__/client_integration/helpers/pipelines_list.helpers.ts b/x-pack/plugins/ingest_pipelines/__jest__/client_integration/helpers/pipelines_list.helpers.ts index 2fe06c925d23e..6afc59c164fff 100644 --- a/x-pack/plugins/ingest_pipelines/__jest__/client_integration/helpers/pipelines_list.helpers.ts +++ b/x-pack/plugins/ingest_pipelines/__jest__/client_integration/helpers/pipelines_list.helpers.ts @@ -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, }; diff --git a/x-pack/plugins/ingest_pipelines/public/application/app.tsx b/x-pack/plugins/ingest_pipelines/public/application/app.tsx index 53c31e10e1dff..e5c5b7108081a 100644 --- a/x-pack/plugins/ingest_pipelines/public/application/app.tsx +++ b/x-pack/plugins/ingest_pipelines/public/application/app.tsx @@ -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 = () => ( - - - - + + + + {/* Catch all */} diff --git a/x-pack/plugins/ingest_pipelines/public/application/sections/pipelines_create/pipelines_create.tsx b/x-pack/plugins/ingest_pipelines/public/application/sections/pipelines_create/pipelines_create.tsx index 93c4c3a65bb54..115094abc4c24 100644 --- a/x-pack/plugins/ingest_pipelines/public/application/sections/pipelines_create/pipelines_create.tsx +++ b/x-pack/plugins/ingest_pipelines/public/application/sections/pipelines_create/pipelines_create.tsx @@ -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'; @@ -50,11 +50,11 @@ export const PipelinesCreate: React.FunctionComponent { - history.push(URL_GENERATOR[INGEST_PIPELINES_PAGES.LIST]()); + history.push(getListPath()); }; useEffect(() => { diff --git a/x-pack/plugins/ingest_pipelines/public/application/sections/pipelines_edit/pipelines_edit.tsx b/x-pack/plugins/ingest_pipelines/public/application/sections/pipelines_edit/pipelines_edit.tsx index f2cf52f77b865..181427c37a8be 100644 --- a/x-pack/plugins/ingest_pipelines/public/application/sections/pipelines_edit/pipelines_edit.tsx +++ b/x-pack/plugins/ingest_pipelines/public/application/sections/pipelines_edit/pipelines_edit.tsx @@ -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'; @@ -56,11 +56,11 @@ export const PipelinesEdit: React.FunctionComponent { - history.push(URL_GENERATOR[INGEST_PIPELINES_PAGES.LIST]()); + history.push(getListPath()); }; useEffect(() => { diff --git a/x-pack/plugins/ingest_pipelines/public/application/sections/pipelines_list/empty_list.tsx b/x-pack/plugins/ingest_pipelines/public/application/sections/pipelines_list/empty_list.tsx index 144636d053f73..7f4caa09b6df0 100644 --- a/x-pack/plugins/ingest_pipelines/public/application/sections/pipelines_list/empty_list.tsx +++ b/x-pack/plugins/ingest_pipelines/public/application/sections/pipelines_list/empty_list.tsx @@ -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(); @@ -46,7 +46,7 @@ export const EmptyList: FunctionComponent = () => { } actions={ diff --git a/x-pack/plugins/ingest_pipelines/public/application/sections/pipelines_list/main.tsx b/x-pack/plugins/ingest_pipelines/public/application/sections/pipelines_list/main.tsx index be6f3b7d21a91..f2201530bfd02 100644 --- a/x-pack/plugins/ingest_pipelines/public/application/sections/pipelines_list/main.tsx +++ b/x-pack/plugins/ingest_pipelines/public/application/sections/pipelines_list/main.tsx @@ -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'; @@ -68,16 +68,16 @@ export const PipelinesList: React.FunctionComponent = ({ }, [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) { diff --git a/x-pack/plugins/ingest_pipelines/public/application/services/navigation.ts b/x-pack/plugins/ingest_pipelines/public/application/services/navigation.ts index 462f4752b6284..c822819b39285 100644 --- a/x-pack/plugins/ingest_pipelines/public/application/services/navigation.ts +++ b/x-pack/plugins/ingest_pipelines/public/application/services/navigation.ts @@ -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); diff --git a/x-pack/plugins/ingest_pipelines/public/index.ts b/x-pack/plugins/ingest_pipelines/public/index.ts index d04f08e71d07a..0b99f2eae047d 100644 --- a/x-pack/plugins/ingest_pipelines/public/index.ts +++ b/x-pack/plugins/ingest_pipelines/public/index.ts @@ -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'; diff --git a/x-pack/plugins/ingest_pipelines/public/url_generator.test.ts b/x-pack/plugins/ingest_pipelines/public/url_generator.test.ts index 6480f64f23014..120ced90deac1 100644 --- a/x-pack/plugins/ingest_pipelines/public/url_generator.test.ts +++ b/x-pack/plugins/ingest_pipelines/public/url_generator.test.ts @@ -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) => { diff --git a/x-pack/plugins/ingest_pipelines/public/url_generator.ts b/x-pack/plugins/ingest_pipelines/public/url_generator.ts index 88137b0163f37..ca1a094eddec9 100644 --- a/x-pack/plugins/ingest_pipelines/public/url_generator.ts +++ b/x-pack/plugins/ingest_pipelines/public/url_generator.ts @@ -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; @@ -45,9 +57,20 @@ export class IngestPipelinesUrlGenerator public readonly id = INGEST_PIPELINES_APP_ULR_GENERATOR; public readonly createUrl = async (state: IngestPipelinesUrlGeneratorState): Promise => { - 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)}`; + } + } }; }