From 852d5e0e946192ef7dbc196a69aecad8e0cabe7c Mon Sep 17 00:00:00 2001 From: Tadayoshi Sato Date: Tue, 19 Dec 2023 23:20:10 +0900 Subject: [PATCH] fix(core): provide API for plugins to customise hawtconfig programmatically --- app/src/examples/example2/index.ts | 11 ++++++++++- packages/hawtio/src/core/config-manager.ts | 9 +++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/app/src/examples/example2/index.ts b/app/src/examples/example2/index.ts index 2f4aa873..78062927 100644 --- a/app/src/examples/example2/index.ts +++ b/app/src/examples/example2/index.ts @@ -1,4 +1,4 @@ -import { hawtio, HawtioPlugin } from '@hawtio/react' +import { configManager, hawtio, HawtioPlugin } from '@hawtio/react' import { Example2 } from './Example2' export const registerExample2: HawtioPlugin = () => { @@ -10,3 +10,12 @@ export const registerExample2: HawtioPlugin = () => { isActive: async () => true, }) } + +// Plugin can extend Hawtconfig +configManager.configure(config => { + if (!config.about) { + config.about = {} + } + const description = config.about.description + config.about.description = (description ?? '') + ' This text is added by the example 2 plugin.' +}) diff --git a/packages/hawtio/src/core/config-manager.ts b/packages/hawtio/src/core/config-manager.ts index ef4a46c7..bfa7beea 100644 --- a/packages/hawtio/src/core/config-manager.ts +++ b/packages/hawtio/src/core/config-manager.ts @@ -127,6 +127,10 @@ class ConfigManager { this.config = undefined } + setHawtconfig(config: Hawtconfig) { + this.config = Promise.resolve(config) + } + getHawtconfig(): Promise { if (this.config) { return this.config @@ -156,6 +160,11 @@ class ConfigManager { } } + async configure(configurer: (config: Hawtconfig) => void) { + const config = await this.getHawtconfig() + configurer(config) + } + async applyBranding(): Promise { const { branding } = await this.getHawtconfig() if (!branding) {