-
Notifications
You must be signed in to change notification settings - Fork 8.3k
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
base: main
Are you sure you want to change the base?
Changes from 7 commits
1b9cbcd
97c8d0a
3c4c114
ac08dfa
0706eca
ba7c1f4
7cf6cf1
78c132c
88404f4
807c206
9bcf377
e43981a
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 | ||
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. @gsoldevila I know we’re relocating plugins into solution-specific folders ( |
||
|
||
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", | ||||||||||||||||||||||||||||||||||||||||||||||
] | ||||||||||||||||||||||||||||||||||||||||||||||
Comment on lines
+15
to
+27
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
|
||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||
} |
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'; | ||
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. question: Exporting anything from |
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)) { | ||
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'm not sure we need the |
||
return {}; | ||
} | ||
core.application.register({ | ||
id: PLUGIN_ID, | ||
appRoute: '/app/elasticsearch/synonyms', | ||
title: PLUGIN_NAME, | ||
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 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, | ||
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.
|
||
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.