From cbd8018ac83863b28a83701c0f0c742b6bc9399f Mon Sep 17 00:00:00 2001 From: Luke Barnard Date: Mon, 14 Aug 2017 12:26:31 +0100 Subject: [PATCH 1/4] 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. --- src/UserSettingsStore.js | 36 ++++++++++++++++------- src/components/structures/UserSettings.js | 16 ++++++++-- 2 files changed, 39 insertions(+), 13 deletions(-) diff --git a/src/UserSettingsStore.js b/src/UserSettingsStore.js index 4c66c90598..bf6d7e93cf 100644 --- a/src/UserSettingsStore.js +++ b/src/UserSettingsStore.js @@ -171,22 +171,36 @@ export default { localStorage.setItem('mx_local_settings', JSON.stringify(settings)); }, - isFeatureEnabled: function(feature: string): boolean { + getFeatureById(feature: string) { + for (let i = 0; i < this.LABS_FEATURES.length; i++) { + const f = this.LABS_FEATURES[i]; + if (f.id === feature) { + return f; + } + } + return null; + }, + + isFeatureEnabled: function(featureId: string): boolean { // 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++) { - const f = this.LABS_FEATURES[i]; - if (f.id === feature) { - return f.default; - } - } + const feature = this.getFeatureById(featureId); + if (!feature) { + console.warn('Unknown feature'); + return false; } - return localStorage.getItem(`mx_labs_feature_${feature}`) === 'true'; + // 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(feature: string, enabled: boolean) { - localStorage.setItem(`mx_labs_feature_${feature}`, enabled); + setFeatureEnabled: function(featureId: string, enabled: boolean) { + localStorage.setItem(`mx_labs_feature_${featureId}`, enabled); }, }; diff --git a/src/components/structures/UserSettings.js b/src/components/structures/UserSettings.js index e2463a3ac7..c33410e857 100644 --- a/src/components/structures/UserSettings.js +++ b/src/components/structures/UserSettings.js @@ -859,7 +859,13 @@ module.exports = React.createClass({ if (this.props.enableLabs === false) return null; 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 // to rebind the onChange each time we render const onChange = (e) => { @@ -867,7 +873,7 @@ module.exports = React.createClass({ this.forceUpdate(); }; - return ( + features.push(
); }); + + // No labs section when there are no features in labs + if (features.length === 0) { + return null; + } + return (

{ _t("Labs") }

From c97ae5c2e15581ae98f102ecc3e4863684e413b5 Mon Sep 17 00:00:00 2001 From: Luke Barnard Date: Mon, 14 Aug 2017 12:29:42 +0100 Subject: [PATCH 2/4] Override matrix-apps to be disabled - ignores localStorage setting - hides feature from labs section in user settings --- src/UserSettingsStore.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/UserSettingsStore.js b/src/UserSettingsStore.js index bf6d7e93cf..ea060ff8d6 100644 --- a/src/UserSettingsStore.js +++ b/src/UserSettingsStore.js @@ -29,6 +29,9 @@ export default { name: "-", id: 'matrix_apps', default: false, + + // XXX: Always use default, ignore localStorage and remove from labs + override: true, }, ], From 3d5d7fa9c8cd4bb62fe8fcd14b7fb2afa51deccd Mon Sep 17 00:00:00 2001 From: Luke Barnard Date: Mon, 14 Aug 2017 13:59:12 +0100 Subject: [PATCH 3/4] Lint --- src/components/structures/UserSettings.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/components/structures/UserSettings.js b/src/components/structures/UserSettings.js index c33410e857..3c139f77a6 100644 --- a/src/components/structures/UserSettings.js +++ b/src/components/structures/UserSettings.js @@ -883,8 +883,7 @@ module.exports = React.createClass({ onChange={ onChange } /> -
- ); +
); }); // No labs section when there are no features in labs From 867e83edffd3b04f606085bd8e775f5dddde5eb1 Mon Sep 17 00:00:00 2001 From: Luke Barnard Date: Mon, 14 Aug 2017 14:47:05 +0100 Subject: [PATCH 4/4] Fix log to include some useful info --- src/UserSettingsStore.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/UserSettingsStore.js b/src/UserSettingsStore.js index ea060ff8d6..796dab4d60 100644 --- a/src/UserSettingsStore.js +++ b/src/UserSettingsStore.js @@ -190,7 +190,7 @@ export default { const feature = this.getFeatureById(featureId); if (!feature) { - console.warn('Unknown feature'); + console.warn(`Unknown feature "${featureId}"`); return false; } // Return the default if this feature has an override to be the default value or