Skip to content

Commit

Permalink
fix(core): provide API for plugins to customise hawtconfig programmat…
Browse files Browse the repository at this point in the history
…ically
  • Loading branch information
tadayosi committed Dec 20, 2023
1 parent ede1bde commit 852d5e0
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
11 changes: 10 additions & 1 deletion app/src/examples/example2/index.ts
Original file line number Diff line number Diff line change
@@ -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 = () => {
Expand All @@ -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.'
})
9 changes: 9 additions & 0 deletions packages/hawtio/src/core/config-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,10 @@ class ConfigManager {
this.config = undefined
}

setHawtconfig(config: Hawtconfig) {
this.config = Promise.resolve(config)
}

getHawtconfig(): Promise<Hawtconfig> {
if (this.config) {
return this.config
Expand Down Expand Up @@ -156,6 +160,11 @@ class ConfigManager {
}
}

async configure(configurer: (config: Hawtconfig) => void) {
const config = await this.getHawtconfig()
configurer(config)
}

async applyBranding(): Promise<boolean> {
const { branding } = await this.getHawtconfig()
if (!branding) {
Expand Down

0 comments on commit 852d5e0

Please sign in to comment.