Skip to content

Commit f6ad926

Browse files
authored
Merge pull request #595 from guardian/dblatcher/intended-audience-on-by-default
intended audience on by default
2 parents f9c19e4 + 337c49c commit f6ad926

2 files changed

Lines changed: 29 additions & 12 deletions

File tree

public/components/feature-switches/feature-switches.js

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
import angular from 'angular';
88
import featureSwitches from './feature-switches.html';
99
import _ from 'lodash';
10-
import { featureSwitchKeys, getDefaultFeatureSwitchValues } from "../../lib/feature-switches.ts"
10+
import { featureSwitchKeys, getDefaultFeatureSwitchValues, featureSwitchReadableNames } from "../../lib/feature-switches.ts"
1111

1212
angular.module('wfFeatureSwitches', ['wfPreferencesService', 'wfIcons'])
1313
.directive('wfFeatureSwitches', [wfFeatureSwitchesDirective]);
@@ -41,10 +41,7 @@ class FeatureSwitches {
4141

4242
function wfFeatureSwitchesController ($scope, wfPreferencesService) {
4343

44-
$scope.readableNames = {
45-
// e.g. 'multiByline': 'Multi-byline',
46-
'intendedAudienceColumn': 'Show Intended Audience'
47-
}
44+
$scope.readableNames = featureSwitchReadableNames
4845

4946
// Feature switches are provided to the directive as an array of entries because it's simpler to iterate through in ng-repeat
5047
$scope.featureSwitchEntries = Object.entries(getDefaultFeatureSwitchValues()).filter(featureSwitch => featureSwitchKeys.includes(featureSwitch[0]))

public/lib/feature-switches.ts

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,33 @@
1-
21
type FeatureSwitchData = Record<string, unknown>;
32

4-
export const featureSwitchKeys = [
5-
// e.g. 'multiByline'
6-
"intendedAudienceColumn",
3+
type FeatureSwitch = {
4+
key: string;
5+
defaultValue: boolean;
6+
description: string;
7+
};
8+
9+
const featureSwitchList: FeatureSwitch[] = [
10+
{
11+
key: "intendedAudienceColumn",
12+
defaultValue: true,
13+
description: "Show Intended Audience",
14+
},
715
];
816

9-
export const getDefaultFeatureSwitchValues = ():FeatureSwitchData => {
10-
const switches:FeatureSwitchData = {};
11-
featureSwitchKeys.forEach((key) => (switches[key] = false));
17+
export const featureSwitchKeys = featureSwitchList.map(
18+
(featureSwitch) => featureSwitch.key,
19+
);
20+
21+
export const getDefaultFeatureSwitchValues = (): FeatureSwitchData => {
22+
const switches: FeatureSwitchData = {};
23+
featureSwitchList.forEach(
24+
({ key, defaultValue }) => (switches[key] = defaultValue),
25+
);
1226
return switches;
1327
};
28+
29+
export const featureSwitchReadableNames = featureSwitchList.reduce<
30+
Record<string, string>
31+
>((namesMap, nextSwitch) => {
32+
return { ...namesMap, [nextSwitch.key]: nextSwitch.description };
33+
}, {});

0 commit comments

Comments
 (0)