From 79e2db11a69ac5ac23b45e1dc138e20ec84be235 Mon Sep 17 00:00:00 2001 From: Ignacio Rivas Date: Tue, 8 Oct 2024 14:36:55 +0200 Subject: [PATCH] [Index management] Add locator for deep linking into datastreams flyout (#195299) (cherry picked from commit 17ae71b3d9008bc41582c8c92e1c3dadddd2e38b) --- .../src/types.ts | 10 +++++ .../tsconfig.json | 2 + .../common/constants/index.ts | 8 ++++ .../plugins/index_management/public/index.ts | 3 ++ .../index_management/public/locator.test.ts | 37 ++++++++++++++++ .../index_management/public/locator.ts | 42 +++++++++++++++++++ .../plugins/index_management/public/plugin.ts | 10 +++++ 7 files changed, 112 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 82dba5ed7e3102..190aadfc29d019 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 type { LocatorPublic } from '@kbn/share-plugin/public'; import { ExtensionsSetup } from './services/extensions_service'; import { PublicApiServiceSetup } from './services/public_api_service'; +export interface IndexManagementLocatorParams 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/packages/index-management/index_management_shared_types/tsconfig.json b/x-pack/packages/index-management/index_management_shared_types/tsconfig.json index 351991448dba77..8e9142a8383220 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", ] } diff --git a/x-pack/plugins/index_management/common/constants/index.ts b/x-pack/plugins/index_management/common/constants/index.ts index 2174985095ea5c..49e2a7f9505a98 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 e49b83b892addb..aef482471e91b0 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 { IndexManagementLocatorParams } from '@kbn/index-management-shared-types'; +export { INDEX_MANAGEMENT_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 00000000000000..712223d7cbfe4b --- /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 00000000000000..d32d33573507dc --- /dev/null +++ b/x-pack/plugins/index_management/public/locator.ts @@ -0,0 +1,42 @@ +/* + * 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 { IndexManagementLocatorParams } 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: IndexManagementLocatorParams) => { + 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 347dc7ada24f68..3b2d9ad68de201 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, }; }