From a8222c56c0bc6f06a48a19b51620d5f4a80ebfe7 Mon Sep 17 00:00:00 2001 From: Ignacio Rivas Date: Mon, 7 Oct 2024 19:08:07 +0200 Subject: [PATCH 1/6] Add locator --- .../src/types.ts | 10 +++++ .../common/constants/index.ts | 8 ++++ .../plugins/index_management/public/index.ts | 3 ++ .../index_management/public/locator.test.ts | 37 +++++++++++++++++ .../index_management/public/locator.ts | 40 +++++++++++++++++++ .../plugins/index_management/public/plugin.ts | 10 +++++ 6 files changed, 108 insertions(+) create mode 100644 x-pack/plugins/index_management/public/locator.test.ts create mode 100644 x-pack/plugins/index_management/public/locator.ts diff --git a/x-pack/packages/index-management/index_management_shared_types/src/types.ts b/x-pack/packages/index-management/index_management_shared_types/src/types.ts index 82dba5ed7e310..113ede347a8dd 100644 --- a/x-pack/packages/index-management/index_management_shared_types/src/types.ts +++ b/x-pack/packages/index-management/index_management_shared_types/src/types.ts @@ -12,12 +12,22 @@ import { Uuid, } from '@elastic/elasticsearch/lib/api/typesWithBodyKey'; import type { ScopedHistory } from '@kbn/core-application-browser'; +import type { SerializableRecord } from '@kbn/utility-types'; +import { LocatorPublic } from '@kbn/share-plugin/public'; import { ExtensionsSetup } from './services/extensions_service'; import { PublicApiServiceSetup } from './services/public_api_service'; +export interface IMLocatorParams extends SerializableRecord { + page: 'data_streams_details'; + dataStreamName?: string; +} + +export type IndexManagementLocator = LocatorPublic; + export interface IndexManagementPluginSetup { apiService: PublicApiServiceSetup; extensionsService: ExtensionsSetup; + locator?: IndexManagementLocator; } export interface IndexManagementPluginStart { diff --git a/x-pack/plugins/index_management/common/constants/index.ts b/x-pack/plugins/index_management/common/constants/index.ts index 2174985095ea5..49e2a7f9505a9 100644 --- a/x-pack/plugins/index_management/common/constants/index.ts +++ b/x-pack/plugins/index_management/common/constants/index.ts @@ -5,6 +5,7 @@ * 2.0. */ +import { i18n } from '@kbn/i18n'; export { BASE_PATH } from './base_path'; export { API_BASE_PATH, INTERNAL_API_BASE_PATH } from './api_base_path'; export { INVALID_INDEX_PATTERN_CHARS, INVALID_TEMPLATE_NAME_CHARS } from './invalid_characters'; @@ -57,3 +58,10 @@ export { MAJOR_VERSION } from './plugin'; export { Section, IndexDetailsSection } from '@kbn/index-management-shared-types'; export type { IndexDetailsTab, IndexDetailsTabId } from '@kbn/index-management-shared-types'; export * from './allow_auto_create'; + +export const PLUGIN = { + ID: 'index_management', + TITLE: i18n.translate('xpack.idxMgmt.appTitle', { + defaultMessage: 'Index Management', + }), +}; diff --git a/x-pack/plugins/index_management/public/index.ts b/x-pack/plugins/index_management/public/index.ts index e49b83b892add..91a6ceb1b4318 100644 --- a/x-pack/plugins/index_management/public/index.ts +++ b/x-pack/plugins/index_management/public/index.ts @@ -22,3 +22,6 @@ export type { } from '@kbn/index-management-shared-types'; export { getIndexListUri, getTemplateDetailsLink } from './application/services/routing'; + +export type { IMLocatorParams } from './locator'; +export { IM_LOCATOR_ID } from './locator'; diff --git a/x-pack/plugins/index_management/public/locator.test.ts b/x-pack/plugins/index_management/public/locator.test.ts new file mode 100644 index 0000000000000..712223d7cbfe4 --- /dev/null +++ b/x-pack/plugins/index_management/public/locator.test.ts @@ -0,0 +1,37 @@ +/* + * 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 { sharePluginMock } from '@kbn/share-plugin/public/mocks'; +import { ManagementAppLocatorDefinition } from '@kbn/management-plugin/common/locator'; +import { IndexManagementLocatorDefinition, INDEX_MANAGEMENT_LOCATOR_ID } from './locator'; + +describe('Index Management URL locator', () => { + let locator: IndexManagementLocatorDefinition; + + beforeEach(() => { + const managementDefinition = new ManagementAppLocatorDefinition(); + + locator = new IndexManagementLocatorDefinition({ + managementAppLocator: { + ...sharePluginMock.createLocator(), + getLocation: (params) => managementDefinition.getLocation(params), + }, + }); + }); + + test('locator has the right ID', () => { + expect(locator.id).toBe(INDEX_MANAGEMENT_LOCATOR_ID); + }); + + test('locator returns the correct url for data streams details', async () => { + const { path } = await locator.getLocation({ + page: 'data_streams_details', + dataStreamName: 'test', + }); + expect(path).toBe('/data/index_management/data_streams/test'); + }); +}); diff --git a/x-pack/plugins/index_management/public/locator.ts b/x-pack/plugins/index_management/public/locator.ts new file mode 100644 index 0000000000000..eaeed81859ee4 --- /dev/null +++ b/x-pack/plugins/index_management/public/locator.ts @@ -0,0 +1,40 @@ +/* + * 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 { ManagementAppLocator } from '@kbn/management-plugin/common'; +import { LocatorDefinition } from '@kbn/share-plugin/public'; +import { IMLocatorParams } from '@kbn/index-management-shared-types'; +import { getDataStreamDetailsLink } from './application/services/routing'; +import { PLUGIN } from '../common/constants'; + +export const INDEX_MANAGEMENT_LOCATOR_ID = 'INDEX_MANAGEMENT_LOCATOR_ID'; + +export interface IndexManagementLocatorDefinitionDependencies { + managementAppLocator: ManagementAppLocator; +} + +export class IndexManagementLocatorDefinition implements LocatorDefinition { + constructor(protected readonly deps: IndexManagementLocatorDefinitionDependencies) {} + + public readonly id = INDEX_MANAGEMENT_LOCATOR_ID; + + public readonly getLocation = async (params: IMLocatorParams) => { + const location = await this.deps.managementAppLocator.getLocation({ + sectionId: 'data', + appId: PLUGIN.ID, + }); + + switch (params.page) { + case 'data_streams_details': { + return { + ...location, + path: location.path + getDataStreamDetailsLink(params.dataStreamName!), + }; + } + } + }; +} diff --git a/x-pack/plugins/index_management/public/plugin.ts b/x-pack/plugins/index_management/public/plugin.ts index 5b1706fe807bd..d0c92da025fe0 100644 --- a/x-pack/plugins/index_management/public/plugin.ts +++ b/x-pack/plugins/index_management/public/plugin.ts @@ -19,6 +19,7 @@ import { IndexManagementPluginSetup, IndexManagementPluginStart, } from '@kbn/index-management-shared-types'; +import { IndexManagementLocator } from '@kbn/index-management-shared-types'; import { setExtensionsService } from './application/store/selectors/extension_service'; import { ExtensionsService } from './services/extensions_service'; @@ -29,6 +30,7 @@ import { PLUGIN } from '../common/constants/plugin'; import { IndexMapping } from './application/sections/home/index_list/details_page/with_context_components/index_mappings_embeddable'; import { PublicApiService } from './services/public_api_service'; import { IndexSettings } from './application/sections/home/index_list/details_page/with_context_components/index_settings_embeddable'; +import { IndexManagementLocatorDefinition } from './locator'; export class IndexMgmtUIPlugin implements @@ -40,6 +42,7 @@ export class IndexMgmtUIPlugin > { private extensionsService = new ExtensionsService(); + private locator?: IndexManagementLocator; private kibanaVersion: SemVer; private config: { enableIndexActions: boolean; @@ -112,9 +115,16 @@ export class IndexMgmtUIPlugin }); } + this.locator = plugins.share.url.locators.create( + new IndexManagementLocatorDefinition({ + managementAppLocator: plugins.management.locator, + }) + ); + return { apiService: new PublicApiService(coreSetup.http), extensionsService: this.extensionsService.setup(), + locator: this.locator, }; } From c6549f2a264aca8c5c5681418929f269ce550dd0 Mon Sep 17 00:00:00 2001 From: Ignacio Rivas Date: Mon, 7 Oct 2024 19:08:12 +0200 Subject: [PATCH 2/6] commit with @elastic email From 8b02c44d46d454e033295f620d8b5aa008ee7742 Mon Sep 17 00:00:00 2001 From: Ignacio Rivas Date: Mon, 7 Oct 2024 19:11:52 +0200 Subject: [PATCH 3/6] Fix type names --- .../index_management_shared_types/src/types.ts | 4 ++-- x-pack/plugins/index_management/public/index.ts | 4 ++-- x-pack/plugins/index_management/public/locator.ts | 6 +++--- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/x-pack/packages/index-management/index_management_shared_types/src/types.ts b/x-pack/packages/index-management/index_management_shared_types/src/types.ts index 113ede347a8dd..8301654ac5f52 100644 --- a/x-pack/packages/index-management/index_management_shared_types/src/types.ts +++ b/x-pack/packages/index-management/index_management_shared_types/src/types.ts @@ -17,12 +17,12 @@ import { LocatorPublic } from '@kbn/share-plugin/public'; import { ExtensionsSetup } from './services/extensions_service'; import { PublicApiServiceSetup } from './services/public_api_service'; -export interface IMLocatorParams extends SerializableRecord { +export interface IndexManagementLocatorParams extends SerializableRecord { page: 'data_streams_details'; dataStreamName?: string; } -export type IndexManagementLocator = LocatorPublic; +export type IndexManagementLocator = LocatorPublic; export interface IndexManagementPluginSetup { apiService: PublicApiServiceSetup; diff --git a/x-pack/plugins/index_management/public/index.ts b/x-pack/plugins/index_management/public/index.ts index 91a6ceb1b4318..aef482471e91b 100644 --- a/x-pack/plugins/index_management/public/index.ts +++ b/x-pack/plugins/index_management/public/index.ts @@ -23,5 +23,5 @@ export type { export { getIndexListUri, getTemplateDetailsLink } from './application/services/routing'; -export type { IMLocatorParams } from './locator'; -export { IM_LOCATOR_ID } from './locator'; +export type { IndexManagementLocatorParams } from '@kbn/index-management-shared-types'; +export { INDEX_MANAGEMENT_LOCATOR_ID } from './locator'; diff --git a/x-pack/plugins/index_management/public/locator.ts b/x-pack/plugins/index_management/public/locator.ts index eaeed81859ee4..4e863c1088fb3 100644 --- a/x-pack/plugins/index_management/public/locator.ts +++ b/x-pack/plugins/index_management/public/locator.ts @@ -7,7 +7,7 @@ import { ManagementAppLocator } from '@kbn/management-plugin/common'; import { LocatorDefinition } from '@kbn/share-plugin/public'; -import { IMLocatorParams } from '@kbn/index-management-shared-types'; +import { IndexManagementLocatorParams } from '@kbn/index-management-shared-types'; import { getDataStreamDetailsLink } from './application/services/routing'; import { PLUGIN } from '../common/constants'; @@ -17,12 +17,12 @@ export interface IndexManagementLocatorDefinitionDependencies { managementAppLocator: ManagementAppLocator; } -export class IndexManagementLocatorDefinition implements LocatorDefinition { +export class IndexManagementLocatorDefinition implements LocatorDefinition { constructor(protected readonly deps: IndexManagementLocatorDefinitionDependencies) {} public readonly id = INDEX_MANAGEMENT_LOCATOR_ID; - public readonly getLocation = async (params: IMLocatorParams) => { + public readonly getLocation = async (params: IndexManagementLocatorParams) => { const location = await this.deps.managementAppLocator.getLocation({ sectionId: 'data', appId: PLUGIN.ID, From b370e82d527f317d2fa3140be7d9a1ba073c1459 Mon Sep 17 00:00:00 2001 From: kibanamachine <42973632+kibanamachine@users.noreply.github.com> Date: Mon, 7 Oct 2024 17:24:39 +0000 Subject: [PATCH 4/6] [CI] Auto-commit changed files from 'node scripts/notice' --- .../index_management_shared_types/tsconfig.json | 2 ++ 1 file changed, 2 insertions(+) diff --git a/x-pack/packages/index-management/index_management_shared_types/tsconfig.json b/x-pack/packages/index-management/index_management_shared_types/tsconfig.json index 351991448dba7..8e9142a838322 100644 --- a/x-pack/packages/index-management/index_management_shared_types/tsconfig.json +++ b/x-pack/packages/index-management/index_management_shared_types/tsconfig.json @@ -17,5 +17,7 @@ ], "kbn_references": [ "@kbn/core-application-browser", + "@kbn/utility-types", + "@kbn/share-plugin", ] } From 452fbdebcf73b2b8dc9cd0aa60ea9acad22c01f8 Mon Sep 17 00:00:00 2001 From: Ignacio Rivas Date: Mon, 7 Oct 2024 19:41:47 +0200 Subject: [PATCH 5/6] Import as type --- .../index-management/index_management_shared_types/src/types.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/x-pack/packages/index-management/index_management_shared_types/src/types.ts b/x-pack/packages/index-management/index_management_shared_types/src/types.ts index 8301654ac5f52..190aadfc29d01 100644 --- a/x-pack/packages/index-management/index_management_shared_types/src/types.ts +++ b/x-pack/packages/index-management/index_management_shared_types/src/types.ts @@ -13,7 +13,7 @@ import { } from '@elastic/elasticsearch/lib/api/typesWithBodyKey'; import type { ScopedHistory } from '@kbn/core-application-browser'; import type { SerializableRecord } from '@kbn/utility-types'; -import { LocatorPublic } from '@kbn/share-plugin/public'; +import type { LocatorPublic } from '@kbn/share-plugin/public'; import { ExtensionsSetup } from './services/extensions_service'; import { PublicApiServiceSetup } from './services/public_api_service'; From 9c819271ec0e7876403dc596e7d9c93618fe8981 Mon Sep 17 00:00:00 2001 From: Ignacio Rivas Date: Mon, 7 Oct 2024 21:13:33 +0200 Subject: [PATCH 6/6] Fix linter issues --- x-pack/plugins/index_management/public/locator.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/x-pack/plugins/index_management/public/locator.ts b/x-pack/plugins/index_management/public/locator.ts index 4e863c1088fb3..d32d33573507d 100644 --- a/x-pack/plugins/index_management/public/locator.ts +++ b/x-pack/plugins/index_management/public/locator.ts @@ -17,7 +17,9 @@ export interface IndexManagementLocatorDefinitionDependencies { managementAppLocator: ManagementAppLocator; } -export class IndexManagementLocatorDefinition implements LocatorDefinition { +export class IndexManagementLocatorDefinition + implements LocatorDefinition +{ constructor(protected readonly deps: IndexManagementLocatorDefinitionDependencies) {} public readonly id = INDEX_MANAGEMENT_LOCATOR_ID;