Skip to content

Commit

Permalink
[Search] [Playground] Adding playground locators (elastic#190606)
Browse files Browse the repository at this point in the history
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. elastic#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 <[email protected]>
  • Loading branch information
jgowdyelastic and kibanamachine authored Aug 16, 2024
1 parent e8b82ff commit e4bd1b2
Show file tree
Hide file tree
Showing 10 changed files with 115 additions and 16 deletions.
1 change: 1 addition & 0 deletions x-pack/plugins/enterprise_search/common/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,21 @@
* 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<CreatIndexLocatorParams> {
public readonly id = 'CREATE_INDEX_LOCATOR_ID';
export type CreateIndexLocatorParams = SerializableRecord;

export class CreateIndexLocatorDefinition implements LocatorDefinition<CreateIndexLocatorParams> {
public readonly getLocation = async () => {
return {
app: ENTERPRISE_SEARCH_CONTENT_PLUGIN.ID,
path: CREATE_NEW_INDEX_URL,
state: {},
};
};

public readonly id = 'CREATE_INDEX_LOCATOR_ID';
}
19 changes: 19 additions & 0 deletions x-pack/plugins/enterprise_search/common/locators/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/*
* 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 {
CreateIndexLocatorDefinition,
type CreateIndexLocatorParams,
} from './create_index_locator';
import { PlaygroundLocatorDefinition, type PlaygroundLocatorParams } from './playground_locator';

export function registerLocators(share: SharePluginSetup) {
share.url.locators.create<CreateIndexLocatorParams>(new CreateIndexLocatorDefinition());
share.url.locators.create<PlaygroundLocatorParams>(new PlaygroundLocatorDefinition());
}
Original file line number Diff line number Diff line change
@@ -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<PlaygroundLocatorParams> {
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';
}
8 changes: 3 additions & 5 deletions x-pack/plugins/enterprise_search/public/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -523,7 +521,7 @@ export class EnterpriseSearchPlugin implements Plugin {
visibleIn: [],
});

share?.url.locators.create<CreatIndexLocatorParams>(new CreatIndexLocatorDefinition());
registerLocators(share!);

if (config.canDeployEntSearch) {
core.application.register({
Expand Down
13 changes: 13 additions & 0 deletions x-pack/plugins/search_playground/public/locators/index.ts
Original file line number Diff line number Diff line change
@@ -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<PlaygroundLocatorParams>(new PlaygroundLocatorDefinition());
}
Original file line number Diff line number Diff line change
@@ -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<PlaygroundLocatorParams> {
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';
}
11 changes: 8 additions & 3 deletions x-pack/plugins/search_playground/public/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* 2.0.
*/

import {
import type {
CoreSetup,
Plugin,
CoreStart,
Expand All @@ -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<SearchPlaygroundPluginSetup, SearchPlaygroundPluginStart>
Expand All @@ -33,7 +35,8 @@ export class SearchPlaygroundPlugin
}

public setup(
core: CoreSetup<AppPluginStartDependencies, SearchPlaygroundPluginStart>
core: CoreSetup<AppPluginStartDependencies, SearchPlaygroundPluginStart>,
deps: AppPluginSetupDependencies
): SearchPlaygroundPluginSetup {
if (!this.config.ui?.enabled) return {};

Expand All @@ -53,6 +56,8 @@ export class SearchPlaygroundPlugin
},
});

registerLocators(deps.share);

return {};
}

Expand Down
6 changes: 5 additions & 1 deletion x-pack/plugins/search_playground/public/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -36,6 +36,10 @@ export interface SearchPlaygroundPluginStart {
PlaygroundHeaderDocs: React.FC<React.ComponentProps<typeof PlaygroundHeaderDocs>>;
}

export interface AppPluginSetupDependencies {
share: SharePluginSetup;
}

export interface AppPluginStartDependencies {
history: AppMountParameters['history'];
usageCollection?: UsageCollectionStart;
Expand Down
3 changes: 2 additions & 1 deletion x-pack/plugins/search_playground/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -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/**/*",
Expand Down

0 comments on commit e4bd1b2

Please sign in to comment.