Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Synonyms UI] Synonyms UI base plugin #203284

Open
wants to merge 12 commits into
base: main
Choose a base branch
from
Open
1 change: 1 addition & 0 deletions .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
Expand Up @@ -944,6 +944,7 @@ x-pack/plugins/search_inference_endpoints @elastic/search-kibana
x-pack/plugins/search_notebooks @elastic/search-kibana
x-pack/plugins/search_playground @elastic/search-kibana
x-pack/plugins/search_solution/search_navigation @elastic/search-kibana
x-pack/plugins/search_synonyms @elastic/search-kibana
x-pack/plugins/security @elastic/kibana-security
x-pack/plugins/serverless @elastic/appex-sharedux
x-pack/plugins/serverless_search @elastic/search-kibana
Expand Down
1 change: 1 addition & 0 deletions config/serverless.oblt.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ xpack.securitySolution.enabled: false
xpack.search.notebooks.enabled: false
xpack.searchPlayground.enabled: false
xpack.searchInferenceEndpoints.enabled: false
xpack.searchSynonyms.enabled: false

## Fine-tune the observability solution feature privileges. Also, refer to `serverless.yml` for the project-agnostic overrides.
xpack.features.overrides:
Expand Down
1 change: 1 addition & 0 deletions config/serverless.security.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ xpack.search.notebooks.enabled: false
xpack.searchPlayground.enabled: false
xpack.searchInferenceEndpoints.enabled: false
xpack.inventory.enabled: false
xpack.searchSynonyms.enabled: false

## Fine-tune the security solution feature privileges. Also, refer to `serverless.yml` for the project-agnostic overrides.
xpack.features.overrides:
Expand Down
4 changes: 4 additions & 0 deletions docs/developer/plugin-list.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -859,6 +859,10 @@ detailed information on how Elasticsearch executed the search request. People us
to understand why a search request might be slow.


|{kib-repo}blob/{branch}/x-pack/plugins/search_synonyms/README.md[searchSynonyms]
|A plugin to manage synonyms in Elasticsearch through Synonyms APIs through Kibana.


|{kib-repo}blob/{branch}/x-pack/plugins/security/README.md[security]
|See Configuring security in
Kibana.
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -815,6 +815,7 @@
"@kbn/search-playground": "link:x-pack/plugins/search_playground",
"@kbn/search-response-warnings": "link:packages/kbn-search-response-warnings",
"@kbn/search-shared-ui": "link:x-pack/packages/search/shared_ui",
"@kbn/search-synonyms": "link:x-pack/plugins/search_synonyms",
"@kbn/search-types": "link:packages/kbn-search-types",
"@kbn/searchprofiler-plugin": "link:x-pack/platform/plugins/shared/searchprofiler",
"@kbn/security-api-key-management": "link:x-pack/packages/security/api_key_management",
Expand Down
1 change: 1 addition & 0 deletions packages/deeplinks/search/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export const SERVERLESS_ES_CONNECTORS_ID = 'serverlessConnectors';
export const SERVERLESS_ES_WEB_CRAWLERS_ID = 'serverlessWebCrawlers';
export const ES_SEARCH_PLAYGROUND_ID = 'searchPlayground';
export const SERVERLESS_ES_SEARCH_INFERENCE_ENDPOINTS_ID = 'searchInferenceEndpoints';
export const SERVERLESS_ES_SEARCH_SYNONYMS_ID = 'searchSynonyms';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can drop SERVERLESS_ since this app id/deep link will be used in both serverless and stack.

Suggested change
export const SERVERLESS_ES_SEARCH_SYNONYMS_ID = 'searchSynonyms';
export const ES_SEARCH_SYNONYMS_ID = 'searchSynonyms';

export const SEARCH_HOMEPAGE = 'searchHomepage';
export const SEARCH_INDICES_START = 'elasticsearchStart';
export const SEARCH_INDICES = 'elasticsearchIndices';
Expand Down
6 changes: 6 additions & 0 deletions packages/deeplinks/search/deep_links.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import {
SEARCH_VECTOR_SEARCH,
SEARCH_SEMANTIC_SEARCH,
SEARCH_AI_SEARCH,
SERVERLESS_ES_SEARCH_SYNONYMS_ID,
} from './constants';

export type EnterpriseSearchApp = typeof ENTERPRISE_SEARCH_APP_ID;
Expand All @@ -40,6 +41,7 @@ export type ConnectorsId = typeof SERVERLESS_ES_CONNECTORS_ID;
export type ServerlessWebCrawlers = typeof SERVERLESS_ES_WEB_CRAWLERS_ID;
export type SearchPlaygroundId = typeof ES_SEARCH_PLAYGROUND_ID;
export type SearchInferenceEndpointsId = typeof SERVERLESS_ES_SEARCH_INFERENCE_ENDPOINTS_ID;
export type SearchSynonymsId = typeof SERVERLESS_ES_SEARCH_SYNONYMS_ID;
export type SearchHomepage = typeof SEARCH_HOMEPAGE;
export type SearchStart = typeof SEARCH_INDICES_START;
export type SearchIndices = typeof SEARCH_INDICES;
Expand All @@ -56,6 +58,8 @@ export type AppsearchLinkId = 'engines';

export type SearchInferenceEndpointsLinkId = 'inferenceEndpoints';

export type SynonymsLinkId = 'synonyms';

export type SearchIndicesLinkId = typeof SEARCH_INDICES_CREATE_INDEX;

export type DeepLinkId =
Expand All @@ -70,11 +74,13 @@ export type DeepLinkId =
| ServerlessWebCrawlers
| SearchPlaygroundId
| SearchInferenceEndpointsId
| SearchSynonymsId
| SearchHomepage
| `${EnterpriseSearchContentApp}:${ContentLinkId}`
| `${EnterpriseSearchApplicationsApp}:${ApplicationsLinkId}`
| `${EnterpriseSearchAppsearchApp}:${AppsearchLinkId}`
| `${SearchInferenceEndpointsId}:${SearchInferenceEndpointsLinkId}`
| `${SearchSynonymsId}:${SynonymsLinkId}`
| SearchStart
| SearchIndices
| SearchElasticsearch
Expand Down
1 change: 1 addition & 0 deletions packages/kbn-optimizer/limits.yml
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ pageLoadAssetSize:
searchNotebooks: 18942
searchPlayground: 19325
searchprofiler: 67080
searchSynonyms: 20262
security: 81771
securitySolution: 98429
securitySolutionEss: 31781
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,7 @@ export default function ({ getService }: PluginFunctionalProviderContext) {
'xpack.searchAssistant.ui.enabled (boolean?)',
'xpack.searchInferenceEndpoints.ui.enabled (boolean?)',
'xpack.searchPlayground.ui.enabled (boolean?)',
'xpack.searchSynonyms.ui.enabled (boolean?)',
'xpack.security.loginAssistanceMessage (string?)',
'xpack.security.sameSiteCookies (Strict?|Lax?|None?)',
'xpack.security.showInsecureClusterWarning (boolean?)',
Expand Down
2 changes: 2 additions & 0 deletions tsconfig.base.json
Original file line number Diff line number Diff line change
Expand Up @@ -1606,6 +1606,8 @@
"@kbn/search-response-warnings/*": ["packages/kbn-search-response-warnings/*"],
"@kbn/search-shared-ui": ["x-pack/packages/search/shared_ui"],
"@kbn/search-shared-ui/*": ["x-pack/packages/search/shared_ui/*"],
"@kbn/search-synonyms": ["x-pack/plugins/search_synonyms"],
"@kbn/search-synonyms/*": ["x-pack/plugins/search_synonyms/*"],
"@kbn/search-types": ["packages/kbn-search-types"],
"@kbn/search-types/*": ["packages/kbn-search-types/*"],
"@kbn/searchprofiler-plugin": ["x-pack/platform/plugins/shared/searchprofiler"],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,14 @@ export const buildBaseClassicNavItems = (): ClassicNavItem[] => {
},
id: 'inference_endpoints',
},
{
'data-test-subj': 'searchSideNav-Synonyms',
deepLink: {
link: 'searchSynonyms:synonyms',
shouldShowActiveForSubroutes: true,
},
id: 'synonyms',
},
],
name: i18n.translate('xpack.enterpriseSearch.nav.relevanceTitle', {
defaultMessage: 'Relevance',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,10 @@ export const getNavigationTreeDefinition = ({
}),
},
{
children: [{ link: 'searchInferenceEndpoints:inferenceEndpoints' }],
children: [
{ link: 'searchInferenceEndpoints:inferenceEndpoints' },
{ link: 'searchSynonyms:synonyms' },
],
id: 'relevance',
title: i18n.translate('xpack.enterpriseSearch.searchNav.relevance', {
defaultMessage: 'Relevance',
Expand Down
3 changes: 3 additions & 0 deletions x-pack/plugins/search_synonyms/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Search Synonyms
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@gsoldevila I know we’re relocating plugins into solution-specific folders (x-pack/solutions) right now, but I don’t see a dedicated folder for the Search solution. Is the current recommendation to still place new plugins related to the Search solution within x-pack/plugins?


A plugin to manage synonyms in Elasticsearch through Synonyms APIs through Kibana.
10 changes: 10 additions & 0 deletions x-pack/plugins/search_synonyms/common/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/*
* 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.
*/

export const PLUGIN_ID = 'searchSynonyms';
export const PLUGIN_NAME = 'Synonyms';
export const PLUGIN_PATH = '/synonyms';
24 changes: 24 additions & 0 deletions x-pack/plugins/search_synonyms/common/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/*
* 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.
*/

// eslint-disable-next-line @typescript-eslint/no-empty-interface
export interface SearchSynonymsPluginSetup {}

// eslint-disable-next-line @typescript-eslint/no-empty-interface
export interface SearchSynonymsPluginStart {}

// eslint-disable-next-line @typescript-eslint/no-empty-interface
export interface SearchSynonymsConfigType {}

// eslint-disable-next-line @typescript-eslint/no-empty-interface
export interface AppPluginSetupDependencies {}

export interface SearchSynonymsConfigType {
ui: {
enabled: boolean;
};
}
15 changes: 15 additions & 0 deletions x-pack/plugins/search_synonyms/jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/*
* 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.
*/

module.exports = {
preset: '@kbn/test',
rootDir: '../../..',
roots: ['<rootDir>/x-pack/plugins/search_synonyms'],
coverageDirectory: '<rootDir>/target/kibana-coverage/jest/x-pack/plugins/search_synonyms',
coverageReporters: ['text', 'html'],
collectCoverageFrom: ['<rootDir>/x-pack/plugins/search_synonyms/{public,server}/**/*.{ts,tsx}'],
};
29 changes: 29 additions & 0 deletions x-pack/plugins/search_synonyms/kibana.jsonc
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
"type": "plugin",
"id": "@kbn/search-synonyms",
"owner": "@elastic/search-kibana",
"group": "search",
"visibility": "private",
"plugin": {
"id": "searchSynonyms",
"server": true,
"browser": true,
"configPath": [
"xpack",
"searchSynonyms"
],
"requiredPlugins": [
"licensing",
"features",
],
"optionalPlugins": [
"cloud",
"console",
"usageCollection",
"searchNavigation",
],
"requiredBundles": [
"kibanaReact",
]
Comment on lines +15 to +27
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Caution

Let's only add dependencies when we know we need them.

Suggested change
"requiredPlugins": [
"licensing",
"features",
],
"optionalPlugins": [
"cloud",
"console",
"usageCollection",
"searchNavigation",
],
"requiredBundles": [
"kibanaReact",
]
"requiredPlugins": [
"features"
],
"optionalPlugins": [
"searchNavigation"
],
"requiredBundles": [
"kibanaReact"
]

}
}
35 changes: 35 additions & 0 deletions x-pack/plugins/search_synonyms/public/application.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
* 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 React from 'react';
import ReactDOM from 'react-dom';
import { CoreStart } from '@kbn/core/public';
import { KibanaRenderContextProvider } from '@kbn/react-kibana-context-render';
import { KibanaContextProvider } from '@kbn/kibana-react-plugin/public';
import { I18nProvider } from '@kbn/i18n-react';
import { Router } from '@kbn/shared-ux-router';
import { AppPluginStartDependencies } from './types';

export const renderApp = async (
core: CoreStart,
services: AppPluginStartDependencies,
element: HTMLElement
) => {
ReactDOM.render(
<KibanaRenderContextProvider {...core}>
<KibanaContextProvider services={{ ...core, ...services }}>
<I18nProvider>
<Router history={services.history}>
<div>Synonyms</div>
</Router>
</I18nProvider>
</KibanaContextProvider>
</KibanaRenderContextProvider>,
element
);
return () => ReactDOM.unmountComponentAtNode(element);
};
16 changes: 16 additions & 0 deletions x-pack/plugins/search_synonyms/public/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/*
* 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 { PluginInitializerContext } from '@kbn/core/public';

import { SearchSynonymsPlugin } from './plugin';

export function plugin(initializerContext: PluginInitializerContext) {
return new SearchSynonymsPlugin(initializerContext);
}

export const SYNONYMS_UI_FLAG = 'searchSynonyms:synonymsEnabled';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

question: Exporting anything from server/index.ts, public/index.ts, or common/index.ts makes it part of your public contract that other plugins can rely on. Is that the goal? Exposing something publicly that you intend to use only internally doesn’t break anything yet, but it’s still recommended to separate internal and public domains.

104 changes: 104 additions & 0 deletions x-pack/plugins/search_synonyms/public/plugin.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
/*
* 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 { BehaviorSubject, type Subscription } from 'rxjs';

import { AppStatus } from '@kbn/core/public';
import type {
AppUpdater,
CoreSetup,
Plugin,
PluginInitializerContext,
AppMountParameters,
CoreStart,
} from '@kbn/core/public';
import { i18n } from '@kbn/i18n';
import { PLUGIN_ID, PLUGIN_NAME, PLUGIN_PATH } from '../common';
import {
AppPluginSetupDependencies,
AppPluginStartDependencies,
SearchSynonymsConfigType,
SearchSynonymsPluginSetup,
SearchSynonymsPluginStart,
} from './types';
import { SYNONYMS_UI_FLAG } from '.';

export class SearchSynonymsPlugin
implements Plugin<SearchSynonymsPluginSetup, SearchSynonymsPluginStart>
{
private config: SearchSynonymsConfigType;
private readonly appUpdater$ = new BehaviorSubject<AppUpdater>(() => ({}));
private licenseSubscription?: Subscription;

constructor(initializerContext: PluginInitializerContext) {
this.config = initializerContext.config.get<SearchSynonymsConfigType>();
}

public setup(
core: CoreSetup<AppPluginStartDependencies, SearchSynonymsPluginStart>,
_: AppPluginSetupDependencies
): SearchSynonymsPluginSetup {
if (!this.config.ui?.enabled && !core.uiSettings.get<boolean>(SYNONYMS_UI_FLAG, false)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure we need the config.ui for this plugin. Those were added for the other plugins to share backend without sharing the frontend. Now that these plugins should always use both I think we can leave this out.

return {};
}
core.application.register({
id: PLUGIN_ID,
appRoute: '/app/elasticsearch/synonyms',
title: PLUGIN_NAME,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Caution

The title expects a localizable string. Even though “Synonyms” might remain “Synonyms” in Japanese or French, it’s still recommended for consistency.

deepLinks: [
{
id: 'synonyms',
path: PLUGIN_PATH,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PLUGIN_PATH = '/synonyms' so the full URL path is going to be /app/elasticsearch/synonyms/synonyms should that be /app/elasticsearch/synonyms/list or something else? the double /synonyms seems like it could be better.

title: i18n.translate('xpack.searchSynonyms.appTitle', {
defaultMessage: 'Synonyms',
}),
visibleIn: ['globalSearch'],
},
],
status: AppStatus.inaccessible,
updater$: this.appUpdater$,
async mount({ element, history }: AppMountParameters) {
const { renderApp } = await import('./application');
const [coreStart, depsStart] = await core.getStartServices();

coreStart.chrome.docTitle.change(PLUGIN_NAME);

const startDeps: AppPluginStartDependencies = {
...depsStart,
history,
};

depsStart.searchNavigation?.handleOnAppMount();

return renderApp(coreStart, startDeps, element);
},
visibleIn: [],
});

return {};
}

public start(_: CoreStart, deps: AppPluginStartDependencies): SearchSynonymsPluginStart {
const { licensing } = deps;
this.licenseSubscription = licensing.license$.subscribe((license) => {
const status: AppStatus =
license && license.isAvailable && license.isActive && license.hasAtLeast('enterprise')
? AppStatus.accessible
: AppStatus.inaccessible;

this.appUpdater$.next(() => ({ status }));
});
return {};
}

public stop() {
if (this.licenseSubscription) {
this.licenseSubscription.unsubscribe();
this.licenseSubscription = undefined;
}
}
}
Loading