-
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 all 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,9 @@ | ||
/* | ||
* 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'; |
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. | ||
*/ | ||
|
||
// 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 AppPluginSetupDependencies {} | ||
|
||
export interface SearchSynonymsConfigType { | ||
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,80 @@ | ||||||
/* | ||||||
* 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 { | ||||||
CoreSetup, | ||||||
Plugin, | ||||||
PluginInitializerContext, | ||||||
AppMountParameters, | ||||||
} from '@kbn/core/public'; | ||||||
import { i18n } from '@kbn/i18n'; | ||||||
import { PLUGIN_ID, PLUGIN_NAME } 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; | ||||||
constructor(initializerContext: PluginInitializerContext) { | ||||||
this.config = initializerContext.config.get<SearchSynonymsConfigType>(); | ||||||
} | ||||||
|
||||||
public setup( | ||||||
core: CoreSetup<AppPluginStartDependencies, SearchSynonymsPluginStart>, | ||||||
_: AppPluginSetupDependencies | ||||||
): SearchSynonymsPluginSetup { | ||||||
if (!this.config.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. Caution See my comment in 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: Where is 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
Suggested change
|
||||||
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: '/', | ||||||
title: i18n.translate('xpack.searchSynonyms.appTitle', { | ||||||
defaultMessage: 'Synonyms', | ||||||
}), | ||||||
visibleIn: ['globalSearch'], | ||||||
}, | ||||||
], | ||||||
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(): SearchSynonymsPluginStart { | ||||||
return {}; | ||||||
} | ||||||
|
||||||
public stop() {} | ||||||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
/* | ||
* 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 { SearchNavigationPluginStart } from '@kbn/search-navigation/public'; | ||
export * from '../common/types'; | ||
|
||
export interface AppPluginStartDependencies { | ||
history: AppMountParameters['history']; | ||
console?: ConsolePluginStart; | ||
searchNavigation: SearchNavigationPluginStart; | ||
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 This dependency is declared as optional in the manifest, but here it's defined as required (without |
||
} | ||
import { AppMountParameters } from '@kbn/core/public'; | ||
import type { ConsolePluginStart } from '@kbn/console-plugin/public'; | ||
Comment on lines
+16
to
+17
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. optional nit: it feels a bit weird that your imports go after |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
/* | ||
* 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 { schema, TypeOf } from '@kbn/config-schema'; | ||
import { PluginConfigDescriptor } from '@kbn/core/server'; | ||
|
||
const configSchema = schema.object({ | ||
enabled: schema.boolean({ defaultValue: false }), | ||
}); | ||
|
||
export type SearchPlaygroundConfig = TypeOf<typeof configSchema>; | ||
|
||
export const config: PluginConfigDescriptor<SearchPlaygroundConfig> = { | ||
exposeToBrowser: { | ||
enabled: true, | ||
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 If the plugin is disabled, the client-side plugin won’t even be initialized to read this value. And if it’s initialized, that would implicitly mean it’s enabled. Why do you need to expose this to the browser? Do you happen to observe a different behavior? We should only expose configuration to the browser if it’s absolutely necessary, as it increases both the initial payload size and the risk of accidentally exposing something that shouldn’t be exposed (these values are accessible to any user, authenticated or not). |
||
}, | ||
schema: configSchema, | ||
}; |
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.
note: Since the plugin is disabled for all solutions/project-types, please disable it in the
serverless.yml
file instead of adding three identical entries in each solution-specific configuration file. This approach makes it much easier to reason about the plugin’s status in Serverless.But, I’m not sure you even need anything in the configuration files since your plugin is already disabled by default through its configuration schema.
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.
Yeah given that it's disabled by default, I would keep this flag out of the Serverless configs.