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

(fix)O3-4372:Feature flags that no longer exist should be removed from local storage #1276

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

Bharath-K-Shetty
Copy link

@Bharath-K-Shetty Bharath-K-Shetty commented Jan 23, 2025

Requirements

  • This PR has a title that briefly describes the work done including the ticket number. Ensure your PR title includes a conventional commit label (such as feat, fix, or chore, among others). See existing PR titles for inspiration.

For changes to apps

If applicable

  • My work includes tests or is validated by existing tests.
  • I have updated the esm-framework mock to reflect any API changes I have made.

Summary

This pull request addresses the issue of removing feature flags that no longer exist from local storage. The following changes have been made:

  1. Added cleanupObsoleteFeatureFlags function: This function removes feature flags from local storage that no longer exist in the current state.

  2. Called cleanupObsoleteFeatureFlags within featureFlagsStore.subscribe: Ensures that obsolete feature flags are cleaned up whenever the state is updated.

  3. Called cleanupObsoleteFeatureFlags within registerFeatureFlag: Ensures that obsolete feature flags are cleaned up whenever a new feature flag is registered.

Testing
To verify the functionality, the following steps were performed:

  1. Registered a new feature flag:
registerFeatureFlag('testFlag', 'Test Flag', 'This is a test flag');
  1. Checked local storage:
  • Opened the browser's developer tools.

  • Navigated to the "Application" tab

  • Verified that the key openmrs:feature-flag:testFlag was present in local storage.

  1. Removed the feature flag from the application's state:
window.featureFlagsStore.setState((state) => {
  const { testFlag, ...remainingFlags } = state.flags;
  return { flags: remainingFlags };
});
  1. Checked local storage again:
  • Verified that the key openmrs:feature-flag:testFlag was removed from local storage.

Screenshots

Screen.Recording.2025-01-23.165035.mp4

Related Issue

https://openmrs.atlassian.net/browse/O3-4372

Other

@Bharath-K-Shetty
Copy link
Author

@ibacher review required..!Thanks

Copy link
Member

@ibacher ibacher left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @Bharath-K-Shetty! So, the deletion code looks correct, but I don't think calling it at the two points that this PR does will delete them at the right point. This is because registerFeatureFlag() is called as each feature flag is registered, which means, on each run, this would—presumably—delete all existing flags from local storage, which is not what we want.

We need to find a point in the app start-up cycle when the feature flags will all be registered to call this, so likely at some point in the app shell itself.

@Bharath-K-Shetty
Copy link
Author

@ibacher, as you suggested, I moved the cleanupObsoleteFeatureFlags function to core-config.ts so that it runs at app startup. However, I’ve encountered a challenge: the cleanup function in core-config.ts gets called before all the feature flags are registered. This causes the cleanup logic to fail, as it requires all flags to be registered beforehand.

Would using promises be a viable solution to ensure that the cleanup logic runs only after all the flags are registered?

Additionally, while logging, I noticed that the billing module is not registering its feature flags. Could you provide guidance on what steps I should take to address both these issues?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants