From e4bd1b22e6dadd3caa45d893a9aac485680b1eed Mon Sep 17 00:00:00 2001 From: James Gowdy Date: Fri, 16 Aug 2024 12:54:52 +0100 Subject: [PATCH] [Search] [Playground] Adding playground locators (#190606) Adds locators for the playground app in the enterprise search and search playground plugins. These will be used by the file upload tool to link to Playground after a successful upload. https://github.com/elastic/kibana/pull/186956 These locators are not registered in the observability or security serverless projects, and so the file upload plugin will not render the link to Playground. Note to reviewers, I originally attempted to have one common locator class which would be used by both plugins, this turned out to be more trouble due to cross plugin import restrictions, plus I was concerned the increase to the enterprise search bundle would be larger than the size of the duplicated function. --------- Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com> --- .../enterprise_search/common/constants.ts | 1 + .../common/locators/create_index_locator.tsx | 12 ++++---- .../common/locators/index.ts | 19 ++++++++++++ .../common/locators/playground_locator.tsx | 28 +++++++++++++++++ .../enterprise_search/public/plugin.ts | 8 ++--- .../public/locators/index.ts | 13 ++++++++ .../public/locators/playground_locator.tsx | 30 +++++++++++++++++++ .../search_playground/public/plugin.ts | 11 +++++-- .../plugins/search_playground/public/types.ts | 6 +++- .../plugins/search_playground/tsconfig.json | 3 +- 10 files changed, 115 insertions(+), 16 deletions(-) create mode 100644 x-pack/plugins/enterprise_search/common/locators/index.ts create mode 100644 x-pack/plugins/enterprise_search/common/locators/playground_locator.tsx create mode 100644 x-pack/plugins/search_playground/public/locators/index.ts create mode 100644 x-pack/plugins/search_playground/public/locators/playground_locator.tsx diff --git a/x-pack/plugins/enterprise_search/common/constants.ts b/x-pack/plugins/enterprise_search/common/constants.ts index 1e498b92fd0ac..8e736193e9b61 100644 --- a/x-pack/plugins/enterprise_search/common/constants.ts +++ b/x-pack/plugins/enterprise_search/common/constants.ts @@ -230,6 +230,7 @@ export const APP_SEARCH_URL = '/app/enterprise_search/app_search'; export const ENTERPRISE_SEARCH_ELASTICSEARCH_URL = '/app/enterprise_search/elasticsearch'; export const WORKPLACE_SEARCH_URL = '/app/enterprise_search/workplace_search'; export const CREATE_NEW_INDEX_URL = '/search_indices/new_index'; +export const PLAYGROUND_URL = '/playground'; export const MANAGE_API_KEYS_URL = '/app/management/security/api_keys'; diff --git a/x-pack/plugins/enterprise_search/common/locators/create_index_locator.tsx b/x-pack/plugins/enterprise_search/common/locators/create_index_locator.tsx index c5d8b80125f62..eaf034ac1f697 100644 --- a/x-pack/plugins/enterprise_search/common/locators/create_index_locator.tsx +++ b/x-pack/plugins/enterprise_search/common/locators/create_index_locator.tsx @@ -5,16 +5,14 @@ * 2.0. */ -import { LocatorDefinition } from '@kbn/share-plugin/common'; -import { SerializableRecord } from '@kbn/utility-types'; +import type { LocatorDefinition } from '@kbn/share-plugin/common'; +import type { SerializableRecord } from '@kbn/utility-types'; import { CREATE_NEW_INDEX_URL, ENTERPRISE_SEARCH_CONTENT_PLUGIN } from '../constants'; -export type CreatIndexLocatorParams = SerializableRecord; - -export class CreatIndexLocatorDefinition implements LocatorDefinition { - public readonly id = 'CREATE_INDEX_LOCATOR_ID'; +export type CreateIndexLocatorParams = SerializableRecord; +export class CreateIndexLocatorDefinition implements LocatorDefinition { public readonly getLocation = async () => { return { app: ENTERPRISE_SEARCH_CONTENT_PLUGIN.ID, @@ -22,4 +20,6 @@ export class CreatIndexLocatorDefinition implements LocatorDefinition(new CreateIndexLocatorDefinition()); + share.url.locators.create(new PlaygroundLocatorDefinition()); +} diff --git a/x-pack/plugins/enterprise_search/common/locators/playground_locator.tsx b/x-pack/plugins/enterprise_search/common/locators/playground_locator.tsx new file mode 100644 index 0000000000000..eca283c8c2b06 --- /dev/null +++ b/x-pack/plugins/enterprise_search/common/locators/playground_locator.tsx @@ -0,0 +1,28 @@ +/* + * 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 type { LocatorDefinition } from '@kbn/share-plugin/common'; +import type { SerializableRecord } from '@kbn/utility-types'; + +import { APPLICATIONS_PLUGIN, PLAYGROUND_URL } from '../constants'; + +export type PlaygroundLocatorParams = { 'default-index': string } & SerializableRecord; + +export class PlaygroundLocatorDefinition implements LocatorDefinition { + public readonly getLocation = async (params: PlaygroundLocatorParams) => { + const defaultIndex = params['default-index']; + const path = `${PLAYGROUND_URL}${defaultIndex ? `?default-index=${defaultIndex}` : ''}`; + + return { + app: APPLICATIONS_PLUGIN.ID, + path, + state: {}, + }; + }; + + public readonly id = 'PLAYGROUND_LOCATOR_ID'; +} diff --git a/x-pack/plugins/enterprise_search/public/plugin.ts b/x-pack/plugins/enterprise_search/public/plugin.ts index 77e82885fe6a3..d6ae1dcc0ac6d 100644 --- a/x-pack/plugins/enterprise_search/public/plugin.ts +++ b/x-pack/plugins/enterprise_search/public/plugin.ts @@ -57,10 +57,8 @@ import { INFERENCE_ENDPOINTS_PLUGIN, SEMANTIC_SEARCH_PLUGIN, } from '../common/constants'; -import { - CreatIndexLocatorDefinition, - CreatIndexLocatorParams, -} from '../common/locators/create_index_locator'; +import { registerLocators } from '../common/locators'; + import { ClientConfigType, InitialAppData } from '../common/types'; import { ENGINES_PATH } from './applications/app_search/routes'; @@ -523,7 +521,7 @@ export class EnterpriseSearchPlugin implements Plugin { visibleIn: [], }); - share?.url.locators.create(new CreatIndexLocatorDefinition()); + registerLocators(share!); if (config.canDeployEntSearch) { core.application.register({ diff --git a/x-pack/plugins/search_playground/public/locators/index.ts b/x-pack/plugins/search_playground/public/locators/index.ts new file mode 100644 index 0000000000000..ed4023948ebdc --- /dev/null +++ b/x-pack/plugins/search_playground/public/locators/index.ts @@ -0,0 +1,13 @@ +/* + * 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 { type SharePluginSetup } from '@kbn/share-plugin/public'; +import { PlaygroundLocatorDefinition, type PlaygroundLocatorParams } from './playground_locator'; + +export function registerLocators(share: SharePluginSetup) { + share.url.locators.create(new PlaygroundLocatorDefinition()); +} diff --git a/x-pack/plugins/search_playground/public/locators/playground_locator.tsx b/x-pack/plugins/search_playground/public/locators/playground_locator.tsx new file mode 100644 index 0000000000000..45a604de4aba1 --- /dev/null +++ b/x-pack/plugins/search_playground/public/locators/playground_locator.tsx @@ -0,0 +1,30 @@ +/* + * 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 type { LocatorDefinition } from '@kbn/share-plugin/common'; +import type { SerializableRecord } from '@kbn/utility-types'; + +import { PLUGIN_ID } from '../../common'; + +export type PlaygroundLocatorParams = { 'default-index': string } & SerializableRecord; + +const PLAYGROUND_URL = '/chat'; + +export class PlaygroundLocatorDefinition implements LocatorDefinition { + public readonly getLocation = async (params: PlaygroundLocatorParams) => { + const defaultIndex = params['default-index']; + const path = `${PLAYGROUND_URL}${defaultIndex ? `?default-index=${defaultIndex}` : ''}`; + + return { + app: PLUGIN_ID, + path, + state: {}, + }; + }; + + public readonly id = 'PLAYGROUND_LOCATOR_ID'; +} diff --git a/x-pack/plugins/search_playground/public/plugin.ts b/x-pack/plugins/search_playground/public/plugin.ts index 8b2976cab10c9..c3cfd8bc7583e 100644 --- a/x-pack/plugins/search_playground/public/plugin.ts +++ b/x-pack/plugins/search_playground/public/plugin.ts @@ -5,7 +5,7 @@ * 2.0. */ -import { +import type { CoreSetup, Plugin, CoreStart, @@ -16,12 +16,14 @@ import { PLUGIN_ID, PLUGIN_NAME } from '../common'; import { docLinks } from '../common/doc_links'; import { PlaygroundHeaderDocs } from './components/playground_header_docs'; import { Playground, getPlaygroundProvider } from './embeddable'; -import { +import type { + AppPluginSetupDependencies, AppPluginStartDependencies, SearchPlaygroundConfigType, SearchPlaygroundPluginSetup, SearchPlaygroundPluginStart, } from './types'; +import { registerLocators } from './locators'; export class SearchPlaygroundPlugin implements Plugin @@ -33,7 +35,8 @@ export class SearchPlaygroundPlugin } public setup( - core: CoreSetup + core: CoreSetup, + deps: AppPluginSetupDependencies ): SearchPlaygroundPluginSetup { if (!this.config.ui?.enabled) return {}; @@ -53,6 +56,8 @@ export class SearchPlaygroundPlugin }, }); + registerLocators(deps.share); + return {}; } diff --git a/x-pack/plugins/search_playground/public/types.ts b/x-pack/plugins/search_playground/public/types.ts index 90f6cdc72e04f..6e83f52f3f683 100644 --- a/x-pack/plugins/search_playground/public/types.ts +++ b/x-pack/plugins/search_playground/public/types.ts @@ -15,7 +15,7 @@ import { NavigationPublicPluginStart } from '@kbn/navigation-plugin/public'; import { SecurityPluginStart } from '@kbn/security-plugin/public'; import { HttpStart } from '@kbn/core-http-browser'; import React, { ComponentType } from 'react'; -import { SharePluginStart } from '@kbn/share-plugin/public'; +import { SharePluginSetup, SharePluginStart } from '@kbn/share-plugin/public'; import { CloudSetup } from '@kbn/cloud-plugin/public'; import { TriggersAndActionsUIPublicPluginStart } from '@kbn/triggers-actions-ui-plugin/public'; import { AppMountParameters } from '@kbn/core/public'; @@ -36,6 +36,10 @@ export interface SearchPlaygroundPluginStart { PlaygroundHeaderDocs: React.FC>; } +export interface AppPluginSetupDependencies { + share: SharePluginSetup; +} + export interface AppPluginStartDependencies { history: AppMountParameters['history']; usageCollection?: UsageCollectionStart; diff --git a/x-pack/plugins/search_playground/tsconfig.json b/x-pack/plugins/search_playground/tsconfig.json index 20ede9bad89ad..af242ed063be2 100644 --- a/x-pack/plugins/search_playground/tsconfig.json +++ b/x-pack/plugins/search_playground/tsconfig.json @@ -38,7 +38,8 @@ "@kbn/core-logging-server-mocks", "@kbn/analytics", "@kbn/usage-collection-plugin", - "@kbn/console-plugin" + "@kbn/console-plugin", + "@kbn/utility-types" ], "exclude": [ "target/**/*",