-
Notifications
You must be signed in to change notification settings - Fork 8.5k
[Synonyms UI] Synonyms UI base plugin #203284
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
Changes from 7 commits
1b9cbcd
97c8d0a
3c4c114
ac08dfa
0706eca
ba7c1f4
7cf6cf1
78c132c
88404f4
807c206
9bcf377
e43981a
2dc16b4
4097ac5
eeefab0
1a609df
268d63f
cafd722
c32620e
8500b3a
b5b5df3
2e4e87f
804f38d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| # Search Synonyms | ||
efegurkan marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| A plugin to manage synonyms in Elasticsearch through Synonyms APIs through Kibana. | ||
| 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'; |
| 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; | ||
| }; | ||
| } |
| 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}'], | ||
| }; |
| 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", | ||||||||||||||||||||||||||||||||||||||||||||||
| ] | ||||||||||||||||||||||||||||||||||||||||||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I updated this, and left the console in, as I will use it in the next PR same as the permissions conversation above. TBH eventually I will use (almost) all of the above but it is a good habit to not include unless using it, I understand your point. |
||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||
| 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); | ||
| }; |
| 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'; | ||
efegurkan marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| 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)) { | ||
|
||
| return {}; | ||
| } | ||
| core.application.register({ | ||
| id: PLUGIN_ID, | ||
| appRoute: '/app/elasticsearch/synonyms', | ||
| title: PLUGIN_NAME, | ||
efegurkan marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| deepLinks: [ | ||
| { | ||
| id: 'synonyms', | ||
| path: PLUGIN_PATH, | ||
|
||
| 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; | ||
| } | ||
| } | ||
| } | ||
There was a problem hiding this comment.
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.