Skip to content
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

(feat) Introduce "Enable Feature Flags" config option to the app-shell #1249

Merged
merged 1 commit into from
Jan 16, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import {
temporaryConfigStore,
getExtensionSlotsConfigStore,
} from './state';
import type {} from '@openmrs/esm-globals';
import { type TemporaryConfigStore } from '..';

/**
Expand Down
6 changes: 3 additions & 3 deletions packages/framework/esm-routes/src/loaders/components.ts
Original file line number Diff line number Diff line change
Expand Up @@ -200,10 +200,10 @@ supported, so the workspace will not be loaded.`,
}

/**
* This function registers a workspace definition with the framework so that it can be launched.
* This function registers a feature flag definition with the framework.
*
* @param appName The name of the app defining this workspace
* @param featureFlag An object that describes the workspace, derived from `routes.json`
* @param appName The name of the app defining this feature flag
* @param featureFlag An object that describes the feature flag, derived from `routes.json`
*/
export function tryRegisterFeatureFlag(appName: string, featureFlag: FeatureFlagDefinition) {
const name = featureFlag.flagName;
Expand Down
38 changes: 38 additions & 0 deletions packages/shell/esm-app-shell/src/core-config.ts
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 });
}
});
}
2 changes: 2 additions & 0 deletions packages/shell/esm-app-shell/src/run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ import {
import { setupI18n } from './locale';
import { registerOptionalDependencyHandler } from './optionaldeps';
import { appName, getCoreExtensions } from './ui';
import { setupCoreConfig } from './core-config';

// @internal
// used to track when the window.installedModules global is finalised
Expand Down Expand Up @@ -408,6 +409,7 @@ export function run(configUrls: Array<string>) {
setupApiModule();
setupHistory();
registerCoreExtensions();
setupCoreConfig();

return setupApps()
.then(finishRegisteringAllApps)
Expand Down
Loading