File tree Expand file tree Collapse file tree
components/feature-switches Expand file tree Collapse file tree Original file line number Diff line number Diff line change 77import angular from 'angular' ;
88import featureSwitches from './feature-switches.html' ;
99import _ from 'lodash' ;
10- import { featureSwitchKeys , getDefaultFeatureSwitchValues } from "../../lib/feature-switches.ts"
10+ import { featureSwitchKeys , getDefaultFeatureSwitchValues , featureSwitchReadableNames } from "../../lib/feature-switches.ts"
1111
1212angular . module ( 'wfFeatureSwitches' , [ 'wfPreferencesService' , 'wfIcons' ] )
1313 . directive ( 'wfFeatureSwitches' , [ wfFeatureSwitchesDirective ] ) ;
@@ -41,10 +41,7 @@ class FeatureSwitches {
4141
4242function 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 ] ) )
Original file line number Diff line number Diff line change 1-
21type 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+ } , { } ) ;
You can’t perform that action at this time.
0 commit comments