Feature flags are useful to hide or show features before they are completed or ready for release to allow a developer to test a feature without disrupting the codebase.
djblets/djblets/features/level.py
This file has the different options for a feature level (docs). The current feature levels available are:
reviewboard/reviewboard/reviews/features.py
This file contains many of the feature flags for ReviewBoard. Here is an example of what a feature flag definition could look like:
class MyFeature(Feature):
"""A description about what this feature will do."""
feature_id = 'reviews.my_feature'
name = _('My Feature Name')
level = FeatureLevel.FEATURE_LEVEL
summary = _('A summary of my feature.')
my_feature = MyFeature()
The feature_id
is how it will be identified in the code.
The level corresponds to the Feature Levels in Djblets.
/reviewboard/settings.py
Add
ENABLED_FEATURES = {
'reviews.FEATURE_FLAG_NAME': True
}
to the bottom of this file.
FEATURE_FLAG_NAME
is the feature_id
of the feature identified in the features.py
file. For example, reviews.my_feature
.
The feature flags can be used as is in Django templates and .py files.
To use the feature flags in Javascript files, add this to the corresponding Django template:
RB.EnabledFeatures = {
VARIABLE_NAME: {% if_feature_enabled 'FEATURE_FLAG_NAME' %}true{% else %}false{% endif_feature_enabled %},
};
FEATURE_FLAG_NAME
is the ID in the features.py
file.
This feature flag can now be accessed in the Javascript file with RB.EnabledFeatures.VARIABLE_NAME
.