-
-
Notifications
You must be signed in to change notification settings - Fork 57
Feature Flags
Implementing feature flags is a way to deploy a piece of code in production while restricting access to only a subset of users. (1)
To create and enable a feature flag:
- Within Admin menu, select Feature Flags
- Click on ADD NEW FEATURE button on the top right
- In Add a new feature forum, enter a feature name in camel-case.
- Submit
- Feature by default is not globally enabled.
- At Feature Flag page, click on a feature to expand the table row.
- Click on add user icon on the right
- Fill in user registered email in Add a suer to table
- Submit.
Add feature flag Strategies to define how the flag should be applied. For each strategy, include the Type (defaults to All users) and Environments (defaults to all environments). Select Create feature flag. To change these settings, select Edit ( ) next to any feature flag in the list.
On the left sidebar, select Search or go to and find your project. Select Deploy > Feature flags. Select New feature flag. Enter a name that starts with a letter and contains only lowercase letters, digits, underscores (), or dashes (-), and does not end with a dash (-) or underscore (). Optional. Enter a description (255 characters maximum). Add feature flag Strategies to define how the flag should be applied. For each strategy, include the Type (defaults to All users) and Environments (defaults to all environments). Select Create feature flag. To change these settings, select Edit ( ) next to any feature flag in the list.
Next few points are a discussion on how this was implemented in our project to selectively remove the "Search this area" button:
- To implement feature flags, we created a custom react hook useFeatureFlag which returns a boolean, based on if the environment variable
REACT_APP_FEATURE_FLAGSis present in the.env.localfile (the .env.local file was added to the local environment with the aforementioned environment variable). - The
/client/.env.localpath was also added to the .gitignore file so that the file is not part of the repo, however, .env.local file can be added in another environment, to use the environment variables as required. (A copy of .env.local file, nameddotenvdotlocal, used for PR 1827, can be found in the development folder of our google drive here). - Finally, we passed the
advancedFilterparameter in the custom hook function within the resultmap.js file as follows:const hasAdvancedFilterFeatureFlag = useFeatureFlag("advancedFilter");reference link. The boolean value thus returned (depending on if the env variable is present in .env.local file) was then used with the "search this area" button (in this line) to turn on or off its visibility.
Similarly, this custom hook can be used while developing other features.
References/Resources