-
Notifications
You must be signed in to change notification settings - Fork 214
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
(feat) Add "Enable Feature Flags" config option to the app-shell (#1249)
- Loading branch information
1 parent
77414b1
commit 275b090
Showing
4 changed files
with
43 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import { defineConfigSchema, Type, getConfigStore } from '@openmrs/esm-framework'; | ||
import { registerModuleLoad, featureFlagsStore } from '@openmrs/esm-framework/src/internal'; | ||
import { appName } from './ui'; | ||
|
||
/** | ||
* Sets up the app shell's configuration. | ||
*/ | ||
export function setupCoreConfig() { | ||
defineConfigSchema(appName, { | ||
'Enabled feature flags': { | ||
_description: 'The feature flags that will be enabled', | ||
_type: Type.Array, | ||
_default: [], | ||
_elements: { | ||
_type: Type.String, | ||
}, | ||
}, | ||
}); | ||
registerModuleLoad(appName); | ||
|
||
// process feature flags | ||
getConfigStore(appName).subscribe(({ config }) => { | ||
const flagsToEnable = new Set((config?.['Enabled feature flags'] as Array<string>) || []); | ||
if (flagsToEnable.size) { | ||
const newFlags = { ...featureFlagsStore.getState().flags }; | ||
for (const flag of flagsToEnable) { | ||
// validate the flag exists | ||
if (!newFlags[flag]) { | ||
console.error(`Feature flag "${flag}" does not exist. Please define the flag first.`); | ||
} else { | ||
newFlags[flag] = { ...newFlags[flag], enabled: true }; | ||
} | ||
} | ||
|
||
featureFlagsStore.setState({ flags: newFlags }); | ||
} | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters