mirror of https://github.com/vector-im/riot-web
Support semi-perma-disabling of lab features
Adding `override: true` will remove the feature from the labs section, and force Riot to always use the default value (i.e. ignoring localStorage). This is useful removing features entirely when they might be deliberately not working but we still want to do a release.pull/21833/head
parent
02217c8bd2
commit
cbd8018ac8
|
@ -171,22 +171,36 @@ export default {
|
||||||
localStorage.setItem('mx_local_settings', JSON.stringify(settings));
|
localStorage.setItem('mx_local_settings', JSON.stringify(settings));
|
||||||
},
|
},
|
||||||
|
|
||||||
isFeatureEnabled: function(feature: string): boolean {
|
getFeatureById(feature: string) {
|
||||||
// Disable labs for guests.
|
|
||||||
if (MatrixClientPeg.get().isGuest()) return false;
|
|
||||||
|
|
||||||
if (localStorage.getItem(`mx_labs_feature_${feature}`) === null) {
|
|
||||||
for (let i = 0; i < this.LABS_FEATURES.length; i++) {
|
for (let i = 0; i < this.LABS_FEATURES.length; i++) {
|
||||||
const f = this.LABS_FEATURES[i];
|
const f = this.LABS_FEATURES[i];
|
||||||
if (f.id === feature) {
|
if (f.id === feature) {
|
||||||
return f.default;
|
return f;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
return null;
|
||||||
return localStorage.getItem(`mx_labs_feature_${feature}`) === 'true';
|
|
||||||
},
|
},
|
||||||
|
|
||||||
setFeatureEnabled: function(feature: string, enabled: boolean) {
|
isFeatureEnabled: function(featureId: string): boolean {
|
||||||
localStorage.setItem(`mx_labs_feature_${feature}`, enabled);
|
// Disable labs for guests.
|
||||||
|
if (MatrixClientPeg.get().isGuest()) return false;
|
||||||
|
|
||||||
|
const feature = this.getFeatureById(featureId);
|
||||||
|
if (!feature) {
|
||||||
|
console.warn('Unknown feature');
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
// Return the default if this feature has an override to be the default value or
|
||||||
|
// if the feature has never been toggled and is therefore not in localStorage
|
||||||
|
if (Object.keys(feature).includes('override') ||
|
||||||
|
localStorage.getItem(`mx_labs_feature_${featureId}`) === null
|
||||||
|
) {
|
||||||
|
return feature.default;
|
||||||
|
}
|
||||||
|
return localStorage.getItem(`mx_labs_feature_${featureId}`) === 'true';
|
||||||
|
},
|
||||||
|
|
||||||
|
setFeatureEnabled: function(featureId: string, enabled: boolean) {
|
||||||
|
localStorage.setItem(`mx_labs_feature_${featureId}`, enabled);
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
|
@ -859,7 +859,13 @@ module.exports = React.createClass({
|
||||||
if (this.props.enableLabs === false) return null;
|
if (this.props.enableLabs === false) return null;
|
||||||
UserSettingsStore.doTranslations();
|
UserSettingsStore.doTranslations();
|
||||||
|
|
||||||
const features = UserSettingsStore.LABS_FEATURES.map((feature) => {
|
const features = [];
|
||||||
|
UserSettingsStore.LABS_FEATURES.forEach((feature) => {
|
||||||
|
// This feature has an override and will be set to the default, so do not
|
||||||
|
// show it here.
|
||||||
|
if (feature.override) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
// TODO: this ought to be a separate component so that we don't need
|
// TODO: this ought to be a separate component so that we don't need
|
||||||
// to rebind the onChange each time we render
|
// to rebind the onChange each time we render
|
||||||
const onChange = (e) => {
|
const onChange = (e) => {
|
||||||
|
@ -867,7 +873,7 @@ module.exports = React.createClass({
|
||||||
this.forceUpdate();
|
this.forceUpdate();
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
features.push(
|
||||||
<div key={feature.id} className="mx_UserSettings_toggle">
|
<div key={feature.id} className="mx_UserSettings_toggle">
|
||||||
<input
|
<input
|
||||||
type="checkbox"
|
type="checkbox"
|
||||||
|
@ -880,6 +886,12 @@ module.exports = React.createClass({
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// No labs section when there are no features in labs
|
||||||
|
if (features.length === 0) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div>
|
<div>
|
||||||
<h3>{ _t("Labs") }</h3>
|
<h3>{ _t("Labs") }</h3>
|
||||||
|
|
Loading…
Reference in New Issue