Ingest pipeline locator (#102878)

* feat: 🎸 implement ingest pipeline locator

* feat: 🎸 improve ingest pipeline locator

* feat: 🎸 register ingest pipeline locator

* refactor: 💡 use locator in expand_row component

* chore: 🤖 remove ingest pipelines URL generator

* fix: 🐛 correct TypeScript errors

Co-authored-by: Vadim Kibana <vadimkibana@gmail.com>
This commit is contained in:
Vadim Dalecky 2021-06-23 10:23:28 +02:00 committed by GitHub
parent 12aa46fad9
commit 1315521760
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 220 additions and 231 deletions

View file

@ -7,7 +7,8 @@
*/
export { CSV_QUOTE_VALUES_SETTING, CSV_SEPARATOR_SETTING } from '../common/constants';
export { LocatorDefinition } from '../common/url_service';
export { LocatorDefinition, LocatorPublic, KibanaLocation } from '../common/url_service';
export { UrlGeneratorStateMapping } from './url_generators/url_generator_definition';

View file

@ -10,10 +10,3 @@ import { IngestPipelinesPlugin } from './plugin';
export function plugin() {
return new IngestPipelinesPlugin();
}
export {
INGEST_PIPELINES_APP_ULR_GENERATOR,
IngestPipelinesUrlGenerator,
IngestPipelinesUrlGeneratorState,
INGEST_PIPELINES_PAGES,
} from './url_generator';

View file

@ -0,0 +1,100 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/
import { ManagementAppLocatorDefinition } from 'src/plugins/management/common/locator';
import { IngestPipelinesLocatorDefinition, INGEST_PIPELINES_PAGES } from './locator';
describe('Ingest pipeline locator', () => {
const setup = () => {
const managementDefinition = new ManagementAppLocatorDefinition();
const definition = new IngestPipelinesLocatorDefinition({
managementAppLocator: {
getLocation: (params) => managementDefinition.getLocation(params),
getUrl: async () => {
throw new Error('not implemented');
},
navigate: async () => {
throw new Error('not implemented');
},
useUrl: () => '',
},
});
return { definition };
};
describe('Pipelines List', () => {
it('generates relative url for list without pipelineId', async () => {
const { definition } = setup();
const location = await definition.getLocation({
page: INGEST_PIPELINES_PAGES.LIST,
});
expect(location).toMatchObject({
app: 'management',
path: '/ingest/ingest_pipelines',
});
});
it('generates relative url for list with a pipelineId', async () => {
const { definition } = setup();
const location = await definition.getLocation({
page: INGEST_PIPELINES_PAGES.LIST,
pipelineId: 'pipeline_name',
});
expect(location).toMatchObject({
app: 'management',
path: '/ingest/ingest_pipelines/?pipeline=pipeline_name',
});
});
});
describe('Pipeline Edit', () => {
it('generates relative url for pipeline edit', async () => {
const { definition } = setup();
const location = await definition.getLocation({
page: INGEST_PIPELINES_PAGES.EDIT,
pipelineId: 'pipeline_name',
});
expect(location).toMatchObject({
app: 'management',
path: '/ingest/ingest_pipelines/edit/pipeline_name',
});
});
});
describe('Pipeline Clone', () => {
it('generates relative url for pipeline clone', async () => {
const { definition } = setup();
const location = await definition.getLocation({
page: INGEST_PIPELINES_PAGES.CLONE,
pipelineId: 'pipeline_name',
});
expect(location).toMatchObject({
app: 'management',
path: '/ingest/ingest_pipelines/create/pipeline_name',
});
});
});
describe('Pipeline Create', () => {
it('generates relative url for pipeline create', async () => {
const { definition } = setup();
const location = await definition.getLocation({
page: INGEST_PIPELINES_PAGES.CREATE,
pipelineId: 'pipeline_name',
});
expect(location).toMatchObject({
app: 'management',
path: '/ingest/ingest_pipelines/create',
});
});
});
});

View file

@ -0,0 +1,102 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/
import { SerializableState } from 'src/plugins/kibana_utils/common';
import { ManagementAppLocator } from 'src/plugins/management/common';
import {
LocatorPublic,
LocatorDefinition,
KibanaLocation,
} from '../../../../src/plugins/share/public';
import {
getClonePath,
getCreatePath,
getEditPath,
getListPath,
} from './application/services/navigation';
import { PLUGIN_ID } from '../common/constants';
export enum INGEST_PIPELINES_PAGES {
LIST = 'pipelines_list',
EDIT = 'pipeline_edit',
CREATE = 'pipeline_create',
CLONE = 'pipeline_clone',
}
interface IngestPipelinesBaseParams extends SerializableState {
pipelineId: string;
}
export interface IngestPipelinesListParams extends Partial<IngestPipelinesBaseParams> {
page: INGEST_PIPELINES_PAGES.LIST;
}
export interface IngestPipelinesEditParams extends IngestPipelinesBaseParams {
page: INGEST_PIPELINES_PAGES.EDIT;
}
export interface IngestPipelinesCloneParams extends IngestPipelinesBaseParams {
page: INGEST_PIPELINES_PAGES.CLONE;
}
export interface IngestPipelinesCreateParams extends IngestPipelinesBaseParams {
page: INGEST_PIPELINES_PAGES.CREATE;
}
export type IngestPipelinesParams =
| IngestPipelinesListParams
| IngestPipelinesEditParams
| IngestPipelinesCloneParams
| IngestPipelinesCreateParams;
export type IngestPipelinesLocator = LocatorPublic<void>;
export const INGEST_PIPELINES_APP_LOCATOR = 'INGEST_PIPELINES_APP_LOCATOR';
export interface IngestPipelinesLocatorDependencies {
managementAppLocator: ManagementAppLocator;
}
export class IngestPipelinesLocatorDefinition implements LocatorDefinition<IngestPipelinesParams> {
public readonly id = INGEST_PIPELINES_APP_LOCATOR;
constructor(protected readonly deps: IngestPipelinesLocatorDependencies) {}
public readonly getLocation = async (params: IngestPipelinesParams): Promise<KibanaLocation> => {
const location = await this.deps.managementAppLocator.getLocation({
sectionId: 'ingest',
appId: PLUGIN_ID,
});
let path: string = '';
switch (params.page) {
case INGEST_PIPELINES_PAGES.EDIT:
path = getEditPath({
pipelineName: params.pipelineId,
});
break;
case INGEST_PIPELINES_PAGES.CREATE:
path = getCreatePath();
break;
case INGEST_PIPELINES_PAGES.LIST:
path = getListPath({
inspectedPipelineName: params.pipelineId,
});
break;
case INGEST_PIPELINES_PAGES.CLONE:
path = getClonePath({
clonedPipelineName: params.pipelineId,
});
break;
}
return {
...location,
path: path === '/' ? location.path : location.path + path,
};
};
}

View file

@ -11,7 +11,7 @@ import { CoreSetup, Plugin } from 'src/core/public';
import { PLUGIN_ID } from '../common/constants';
import { uiMetricService, apiService } from './application/services';
import { SetupDependencies, StartDependencies } from './types';
import { registerUrlGenerator } from './url_generator';
import { IngestPipelinesLocatorDefinition } from './locator';
export class IngestPipelinesPlugin
implements Plugin<void, void, SetupDependencies, StartDependencies> {
@ -50,7 +50,11 @@ export class IngestPipelinesPlugin
},
});
registerUrlGenerator(coreSetup, management, share);
share.url.locators.create(
new IngestPipelinesLocatorDefinition({
managementAppLocator: management.locator,
})
);
}
public start() {}

View file

@ -1,108 +0,0 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/
import { IngestPipelinesUrlGenerator, INGEST_PIPELINES_PAGES } from './url_generator';
describe('IngestPipelinesUrlGenerator', () => {
const getAppBasePath = (absolute: boolean = false) => {
if (absolute) {
return Promise.resolve('http://localhost/app/test_app');
}
return Promise.resolve('/app/test_app');
};
const urlGenerator = new IngestPipelinesUrlGenerator(getAppBasePath);
describe('Pipelines List', () => {
it('generates relative url for list without pipelineId', async () => {
const url = await urlGenerator.createUrl({
page: INGEST_PIPELINES_PAGES.LIST,
});
expect(url).toBe('/app/test_app/');
});
it('generates absolute url for list without pipelineId', async () => {
const url = await urlGenerator.createUrl({
page: INGEST_PIPELINES_PAGES.LIST,
absolute: true,
});
expect(url).toBe('http://localhost/app/test_app/');
});
it('generates relative url for list with a pipelineId', async () => {
const url = await urlGenerator.createUrl({
page: INGEST_PIPELINES_PAGES.LIST,
pipelineId: 'pipeline_name',
});
expect(url).toBe('/app/test_app/?pipeline=pipeline_name');
});
it('generates absolute url for list with a pipelineId', async () => {
const url = await urlGenerator.createUrl({
page: INGEST_PIPELINES_PAGES.LIST,
pipelineId: 'pipeline_name',
absolute: true,
});
expect(url).toBe('http://localhost/app/test_app/?pipeline=pipeline_name');
});
});
describe('Pipeline Edit', () => {
it('generates relative url for pipeline edit', async () => {
const url = await urlGenerator.createUrl({
page: INGEST_PIPELINES_PAGES.EDIT,
pipelineId: 'pipeline_name',
});
expect(url).toBe('/app/test_app/edit/pipeline_name');
});
it('generates absolute url for pipeline edit', async () => {
const url = await urlGenerator.createUrl({
page: INGEST_PIPELINES_PAGES.EDIT,
pipelineId: 'pipeline_name',
absolute: true,
});
expect(url).toBe('http://localhost/app/test_app/edit/pipeline_name');
});
});
describe('Pipeline Clone', () => {
it('generates relative url for pipeline clone', async () => {
const url = await urlGenerator.createUrl({
page: INGEST_PIPELINES_PAGES.CLONE,
pipelineId: 'pipeline_name',
});
expect(url).toBe('/app/test_app/create/pipeline_name');
});
it('generates absolute url for pipeline clone', async () => {
const url = await urlGenerator.createUrl({
page: INGEST_PIPELINES_PAGES.CLONE,
pipelineId: 'pipeline_name',
absolute: true,
});
expect(url).toBe('http://localhost/app/test_app/create/pipeline_name');
});
});
describe('Pipeline Create', () => {
it('generates relative url for pipeline create', async () => {
const url = await urlGenerator.createUrl({
page: INGEST_PIPELINES_PAGES.CREATE,
pipelineId: 'pipeline_name',
});
expect(url).toBe('/app/test_app/create');
});
it('generates absolute url for pipeline create', async () => {
const url = await urlGenerator.createUrl({
page: INGEST_PIPELINES_PAGES.CREATE,
pipelineId: 'pipeline_name',
absolute: true,
});
expect(url).toBe('http://localhost/app/test_app/create');
});
});
});

View file

@ -1,99 +0,0 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/
import { CoreSetup } from 'src/core/public';
import { MANAGEMENT_APP_ID } from '../../../../src/plugins/management/public';
import { UrlGeneratorsDefinition } from '../../../../src/plugins/share/public';
import {
getClonePath,
getCreatePath,
getEditPath,
getListPath,
} from './application/services/navigation';
import { SetupDependencies } from './types';
import { 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;
}
export interface PipelinesListUrlGeneratorState extends Partial<UrlGeneratorState> {
page: INGEST_PIPELINES_PAGES.LIST;
}
export interface PipelineEditUrlGeneratorState extends UrlGeneratorState {
page: INGEST_PIPELINES_PAGES.EDIT;
}
export interface PipelineCloneUrlGeneratorState extends UrlGeneratorState {
page: INGEST_PIPELINES_PAGES.CLONE;
}
export interface PipelineCreateUrlGeneratorState extends UrlGeneratorState {
page: INGEST_PIPELINES_PAGES.CREATE;
}
export type IngestPipelinesUrlGeneratorState =
| PipelinesListUrlGeneratorState
| PipelineEditUrlGeneratorState
| PipelineCloneUrlGeneratorState
| PipelineCreateUrlGeneratorState;
export class IngestPipelinesUrlGenerator
implements UrlGeneratorsDefinition<typeof INGEST_PIPELINES_APP_ULR_GENERATOR> {
constructor(private readonly getAppBasePath: (absolute: boolean) => Promise<string>) {}
public readonly id = INGEST_PIPELINES_APP_ULR_GENERATOR;
public readonly createUrl = async (state: IngestPipelinesUrlGeneratorState): Promise<string> => {
switch (state.page) {
case INGEST_PIPELINES_PAGES.EDIT: {
return `${await this.getAppBasePath(!!state.absolute)}${getEditPath({
pipelineName: 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({
inspectedPipelineName: state.pipelineId,
})}`;
}
case INGEST_PIPELINES_PAGES.CLONE: {
return `${await this.getAppBasePath(!!state.absolute)}${getClonePath({
clonedPipelineName: state.pipelineId,
})}`;
}
}
};
}
export const registerUrlGenerator = (
coreSetup: CoreSetup,
management: SetupDependencies['management'],
share: SetupDependencies['share']
) => {
const getAppBasePath = async (absolute = false) => {
const [coreStart] = await coreSetup.getStartServices();
return coreStart.application.getUrlForApp(MANAGEMENT_APP_ID, {
path: management.sections.section.ingest.getApp(PLUGIN_ID)!.basePath,
absolute: !!absolute,
});
};
share.urlGenerators.registerUrlGenerator(new IngestPipelinesUrlGenerator(getAppBasePath));
};

View file

@ -114,10 +114,7 @@ export const ExpandedRow: FC<ExpandedRowProps> = ({ item }) => {
}
const {
services: {
share,
application: { navigateToUrl },
},
services: { share },
} = useMlKibana();
const tabs = [
@ -402,17 +399,16 @@ export const ExpandedRow: FC<ExpandedRowProps> = ({ item }) => {
</EuiFlexItem>
<EuiFlexItem grow={false}>
<EuiButtonEmpty
onClick={async () => {
const ingestPipelinesAppUrlGenerator = share.urlGenerators.getUrlGenerator(
'INGEST_PIPELINES_APP_URL_GENERATOR'
);
await navigateToUrl(
await ingestPipelinesAppUrlGenerator.createUrl({
page: 'pipeline_edit',
pipelineId: pipelineName,
absolute: true,
})
onClick={() => {
const locator = share.url.locators.get(
'INGEST_PIPELINES_APP_LOCATOR'
);
if (!locator) return;
locator.navigate({
page: 'pipeline_edit',
pipelineId: pipelineName,
absolute: true,
});
}}
>
<FormattedMessage