Skip to content
This repository was archived by the owner on Sep 11, 2024. It is now read-only.

Commit e50478a

Browse files
committed
enable/disable features in config.json
As per https://docs.google.com/document/d/1Kn-mz2dDce9Cqc4oUTl5yJXGvmTlky1_KezuwUg58x0/edit# Replaces: * enableLabs setting * 'override' flag in labs * 'default' flag in labs Un-feature-flags matrix apps since this was now overidden to be enabled.
1 parent 757e42d commit e50478a

File tree

5 files changed

+78
-86
lines changed

5 files changed

+78
-86
lines changed

src/UserSettingsStore.js

Lines changed: 51 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
/*
22
Copyright 2015, 2016 OpenMarket Ltd
3+
Copyright 2017 New Vector Ltd
34
45
Licensed under the Apache License, Version 2.0 (the "License");
56
you may not use this file except in compliance with the License.
@@ -17,33 +18,42 @@ limitations under the License.
1718
import Promise from 'bluebird';
1819
import MatrixClientPeg from './MatrixClientPeg';
1920
import Notifier from './Notifier';
20-
import { _t } from './languageHandler';
21+
import { _t, _td } from './languageHandler';
22+
import SdkConfig from './SdkConfig';
2123

2224
/*
2325
* TODO: Make things use this. This is all WIP - see UserSettings.js for usage.
2426
*/
2527

28+
const FEATURES = [
29+
{
30+
id: 'feature_groups',
31+
name: _td("Groups"),
32+
},
33+
];
34+
2635
export default {
27-
LABS_FEATURES: [
28-
{
29-
name: "-",
30-
id: 'matrix_apps',
31-
default: true,
32-
33-
// XXX: Always use default, ignore localStorage and remove from labs
34-
override: true,
35-
},
36-
{
37-
name: "-",
38-
id: 'feature_groups',
39-
default: false,
40-
},
41-
],
42-
43-
// horrible but it works. The locality makes this somewhat more palatable.
44-
doTranslations: function() {
45-
this.LABS_FEATURES[0].name = _t("Matrix Apps");
46-
this.LABS_FEATURES[1].name = _t("Groups");
36+
getLabsFeatures() {
37+
const featuresConfig = SdkConfig.get()['features'] || {};
38+
39+
return FEATURES.filter((f) => {
40+
const sdkConfigValue = featuresConfig[f.id];
41+
if (!['enable', 'disable'].includes(sdkConfigValue)) {
42+
return true;
43+
}
44+
}).map((f) => {
45+
return f.id;
46+
});
47+
},
48+
49+
translatedNameForFeature(featureId) {
50+
const feature = FEATURES.filter((f) => {
51+
return f.id === featureId;
52+
})[0];
53+
54+
if (feature === undefined) return null;
55+
56+
return _t(feature.name);
4757
},
4858

4959
loadProfileInfo: function() {
@@ -180,33 +190,30 @@ export default {
180190
localStorage.setItem('mx_local_settings', JSON.stringify(settings));
181191
},
182192

183-
getFeatureById(feature: string) {
184-
for (let i = 0; i < this.LABS_FEATURES.length; i++) {
185-
const f = this.LABS_FEATURES[i];
186-
if (f.id === feature) {
187-
return f;
188-
}
189-
}
190-
return null;
191-
},
192-
193193
isFeatureEnabled: function(featureId: string): boolean {
194-
// Disable labs for guests.
195-
if (MatrixClientPeg.get().isGuest()) return false;
194+
const featuresConfig = SdkConfig.get()['features'];
196195

197-
const feature = this.getFeatureById(featureId);
198-
if (!feature) {
199-
console.warn(`Unknown feature "${featureId}"`);
200-
return false;
196+
let sdkConfigValue = 'labs';
197+
if (featuresConfig && featuresConfig[featureId] !== undefined) {
198+
sdkConfigValue = featuresConfig[featureId];
201199
}
202-
// Return the default if this feature has an override to be the default value or
203-
// if the feature has never been toggled and is therefore not in localStorage
204-
if (Object.keys(feature).includes('override') ||
205-
localStorage.getItem(`mx_labs_feature_${featureId}`) === null
206-
) {
207-
return feature.default;
200+
201+
if (sdkConfigValue === 'enable') {
202+
return true;
203+
} else if (sdkConfigValue === 'enable') {
204+
return false;
205+
} else if (sdkConfigValue === 'labs') {
206+
if (!MatrixClientPeg.get().isGuest()) {
207+
const userValue = localStorage.getItem(`mx_labs_feature_${featureId}`);
208+
if (userValue !== null) {
209+
return userValue === 'true';
210+
}
211+
}
212+
return false;
213+
} else {
214+
console.warn(`Unknown features config for ${featureId}: ${sdkConfigValue}`);
215+
return false;
208216
}
209-
return localStorage.getItem(`mx_labs_feature_${featureId}`) === 'true';
210217
},
211218

212219
setFeatureEnabled: function(featureId: string, enabled: boolean) {

src/components/structures/LoggedInView.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
/*
22
Copyright 2015, 2016 OpenMarket Ltd
33
Copyright 2017 Vector Creations Ltd
4+
Copyright 2017 New Vector Ltd
45
56
Licensed under the Apache License, Version 2.0 (the "License");
67
you may not use this file except in compliance with the License.
@@ -250,7 +251,6 @@ export default React.createClass({
250251
page_element = <UserSettings
251252
onClose={this.props.onUserSettingsClose}
252253
brand={this.props.config.brand}
253-
enableLabs={this.props.config.enableLabs}
254254
referralBaseUrl={this.props.config.referralBaseUrl}
255255
teamToken={this.props.teamToken}
256256
/>;

src/components/structures/UserSettings.js

Lines changed: 8 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
/*
22
Copyright 2015, 2016 OpenMarket Ltd
33
Copyright 2017 Vector Creations Ltd
4+
Copyright 2017 New Vector Ltd
45
56
Licensed under the Apache License, Version 2.0 (the "License");
67
you may not use this file except in compliance with the License.
@@ -212,9 +213,6 @@ module.exports = React.createClass({
212213
// The brand string given when creating email pushers
213214
brand: React.PropTypes.string,
214215

215-
// True to show the 'labs' section of experimental features
216-
enableLabs: React.PropTypes.bool,
217-
218216
// The base URL to use in the referral link. Defaults to window.location.origin.
219217
referralBaseUrl: React.PropTypes.string,
220218

@@ -226,7 +224,6 @@ module.exports = React.createClass({
226224
getDefaultProps: function() {
227225
return {
228226
onClose: function() {},
229-
enableLabs: true,
230227
};
231228
},
232229

@@ -923,34 +920,25 @@ module.exports = React.createClass({
923920
},
924921

925922
_renderLabs: function() {
926-
// default to enabled if undefined
927-
if (this.props.enableLabs === false) return null;
928-
UserSettingsStore.doTranslations();
929-
930923
const features = [];
931-
UserSettingsStore.LABS_FEATURES.forEach((feature) => {
932-
// This feature has an override and will be set to the default, so do not
933-
// show it here.
934-
if (feature.override) {
935-
return;
936-
}
924+
UserSettingsStore.getLabsFeatures().forEach((featureId) => {
937925
// TODO: this ought to be a separate component so that we don't need
938926
// to rebind the onChange each time we render
939927
const onChange = (e) => {
940-
UserSettingsStore.setFeatureEnabled(feature.id, e.target.checked);
928+
UserSettingsStore.setFeatureEnabled(featureId, e.target.checked);
941929
this.forceUpdate();
942930
};
943931

944932
features.push(
945-
<div key={feature.id} className="mx_UserSettings_toggle">
933+
<div key={featureId} className="mx_UserSettings_toggle">
946934
<input
947935
type="checkbox"
948-
id={feature.id}
949-
name={feature.id}
950-
defaultChecked={UserSettingsStore.isFeatureEnabled(feature.id)}
936+
id={featureId}
937+
name={featureId}
938+
defaultChecked={UserSettingsStore.isFeatureEnabled(featureId)}
951939
onChange={onChange}
952940
/>
953-
<label htmlFor={feature.id}>{ feature.name }</label>
941+
<label htmlFor={featureId}>{ UserSettingsStore.translatedNameForFeature(featureId) }</label>
954942
</div>);
955943
});
956944

src/components/views/rooms/AuxPanel.js

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
/*
22
Copyright 2015, 2016 OpenMarket Ltd
3+
Copyright 2017 New Vector Ltd
34
45
Licensed under the Apache License, Version 2.0 (the "License");
56
you may not use this file except in compliance with the License.
@@ -128,15 +129,12 @@ module.exports = React.createClass({
128129
/>
129130
);
130131

131-
let appsDrawer = null;
132-
if(UserSettingsStore.isFeatureEnabled('matrix_apps')) {
133-
appsDrawer = <AppsDrawer ref="appsDrawer"
134-
room={this.props.room}
135-
userId={this.props.userId}
136-
maxHeight={this.props.maxHeight}
137-
showApps={this.props.showApps}
138-
/>;
139-
}
132+
const appsDrawer = <AppsDrawer ref="appsDrawer"
133+
room={this.props.room}
134+
userId={this.props.userId}
135+
maxHeight={this.props.maxHeight}
136+
showApps={this.props.showApps}
137+
/>;
140138

141139
return (
142140
<div className="mx_RoomView_auxPanel" style={{maxHeight: this.props.maxHeight}} >

src/components/views/rooms/MessageComposer.js

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
/*
22
Copyright 2015, 2016 OpenMarket Ltd
3+
Copyright 2017 New Vector Ltd
34
45
Licensed under the Apache License, Version 2.0 (the "License");
56
you may not use this file except in compliance with the License.
@@ -285,18 +286,16 @@ export default class MessageComposer extends React.Component {
285286
}
286287

287288
// Apps
288-
if (UserSettingsStore.isFeatureEnabled('matrix_apps')) {
289-
if (this.props.showApps) {
290-
hideAppsButton =
291-
<div key="controls_hide_apps" className="mx_MessageComposer_apps" onClick={this.onHideAppsClick} title={_t("Hide Apps")}>
292-
<TintableSvg src="img/icons-hide-apps.svg" width="35" height="35" />
293-
</div>;
294-
} else {
295-
showAppsButton =
296-
<div key="show_apps" className="mx_MessageComposer_apps" onClick={this.onShowAppsClick} title={_t("Show Apps")}>
297-
<TintableSvg src="img/icons-show-apps.svg" width="35" height="35" />
298-
</div>;
299-
}
289+
if (this.props.showApps) {
290+
hideAppsButton =
291+
<div key="controls_hide_apps" className="mx_MessageComposer_apps" onClick={this.onHideAppsClick} title={_t("Hide Apps")}>
292+
<TintableSvg src="img/icons-hide-apps.svg" width="35" height="35" />
293+
</div>;
294+
} else {
295+
showAppsButton =
296+
<div key="show_apps" className="mx_MessageComposer_apps" onClick={this.onShowAppsClick} title={_t("Show Apps")}>
297+
<TintableSvg src="img/icons-show-apps.svg" width="35" height="35" />
298+
</div>;
300299
}
301300

302301
const canSendMessages = this.props.room.currentState.maySendMessage(

0 commit comments

Comments
 (0)