-
Notifications
You must be signed in to change notification settings - Fork 5
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
Document process on how to enable/disable plugins with the opensearch_dashboards.yml config file #6
Changes from all commits
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,49 @@ | ||||||
# Add new config to the {root}/config/opensearch-dashboards.yml file | ||||||
|
||||||
1. Add new config value in the opensearch_dashboards.yml file. Below is an example where I'm adding new flag to hide/show | ||||||
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.
Suggested change
|
||||||
`wizard` plugin. | ||||||
|
||||||
```yml | ||||||
|
||||||
# Set the value of this setting to true to start exploring wizard | ||||||
# functionality in Visualization. | ||||||
# wizard.enabled: true | ||||||
``` | ||||||
|
||||||
Note that the yml config values are read as path to the plugin config schema file. In the above example, `wizard` is the `Id` of the plugin to which I'm introducing this new config value. | ||||||
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.
Suggested change
|
||||||
|
||||||
|
||||||
2. Create a new config schema for the plugin. We should have this config file defined in the root folder of the plugin. For example, `config.ts` for `wizard` plugin is defined in the `src/plugin/wizard/config.ts` | ||||||
|
||||||
```ts | ||||||
|
||||||
import { schema, TypeOf } from '@osd/config-schema'; | ||||||
|
||||||
export const configSchema = schema.object({ | ||||||
enabled: schema.boolean({ defaultValue: true }), | ||||||
}); | ||||||
|
||||||
export type ConfigSchema = TypeOf<typeof configSchema>; | ||||||
``` | ||||||
Every plugin by default has `enabled` true if not defined in the config schema. When defined in the config schema, the value for if plugin should be enabled is read from here. This config value is overriden, when we define the config value in `opensearch_dashboards.yml`. | ||||||
|
||||||
3. Export the new config schema in the `index.ts` file of the plugin's server folder. This is required for plugin to read the properties to expose to client during plugin registration. | ||||||
|
||||||
```ts | ||||||
export const config: PluginConfigDescriptor<ConfigSchema> = { | ||||||
exposeToBrowser: { | ||||||
enabled: true, | ||||||
}, | ||||||
schema: configSchema, | ||||||
}; | ||||||
|
||||||
``` | ||||||
We need to set `exposeToBrowser` true for the config property `enabled` which we have defined in the config schema. | ||||||
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. Just pure speculation, but my guess is that you can use the config 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. Yes. exposeToBrowser will allow the components in the public folder to get that value but is still usable in the server. |
||||||
|
||||||
4. Now we can use the config schema in the `plugin.ts` class constructor, inside `public` folder of the plugin. | ||||||
|
||||||
```ts | ||||||
import { ConfigSchema } from '../config'; | ||||||
|
||||||
constructor(public initializerContext PluginInitializerContext<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.