Feature Flags in ERAS - JU-DEV-Bootcamps/ERAS GitHub Wiki

What are Feature Flags?

Feature Flags are a software development technique that allows developers to enable and disable features without a redeployment, usually in runtime. This technique is useful for testing purposes, gradual rollouts, kill switches, and safer deployments.

In sum, a feature flag works as a toggle that on evaluation enables or disables a specific feature.

Feature Flags in ERAS Frontend (Current)

Currently, ERAS Frontend has a Feature Flag implementation based on query parameters. The FeatureFlagService has a method (isEnabled()) that checks the query parameters of the current route, looks for a query parameter with the name of the feature flag, and, if exists, checks if its value is 'true'.

To implement it, the developer must inject the FeatureFlagService into the component and use the return value of the isEnabled() method to conditionally render the feature.

This approach is useful for runtime feature toggling as it only requires adding or removing a query parameter to the route to enable or disable the feature. However, if the user moves to any other page in the application, the route changes and the query parameters are removed thus the features are disabled.

Feature Flags Proposal

As an alternative to the query parameter approach, a 'persistence-based' approach is proposed. In this proposal, the FeatureFlagService stores an object of type FeatureFlags whose keys are the names of the feature flags (established in the FeatureFlagsName enum to avoid magic strings) and whose values are FeatureFlagRule objects. The FeatureFlagRule object has a enabled property whose value is a boolean and a userRoles property whose value might be an ErasRole array or undefined.

To create a new feature flag, add its name in the FeatureFlagsName enum and then add the name and the rules to the FEATURE_FLAGS constant in feature-flags.ts file.

To use the feature flag, inject the FeatureFlagService to the desired component, call the isEnabled() method of the service and store the return value in a variable that will be used to conditionally render the feature.