@@ -25,7 +25,24 @@ let filterSelection = []
25
25
26
26
let upcomingFeatureFlagFilterEnabled = false
27
27
28
+ /** Proposal state string constants */
29
+ const State = Object . freeze ( {
30
+ awaitingReview : 'awaitingReview' ,
31
+ scheduledForReview : 'scheduledForReview' ,
32
+ activeReview : 'activeReview' ,
33
+ returnedForRevision : 'returnedForRevision' ,
34
+ withdrawn : 'withdrawn' ,
35
+ accepted : 'accepted' ,
36
+ acceptedWithRevisions : 'acceptedWithRevisions' ,
37
+ rejected : 'rejected' ,
38
+ implemented : 'implemented' ,
39
+ previewing : 'previewing' ,
40
+ error : 'error' ,
41
+ } )
42
+
28
43
/**
44
+ * property names: Proposal state string constants
45
+ *
29
46
* `name`: Mapping of the states in the proposals JSON to human-readable names.
30
47
*
31
48
* `shortName`: Mapping of the states in the proposals JSON to short human-readable names.
@@ -34,71 +51,71 @@ let upcomingFeatureFlagFilterEnabled = false
34
51
* `className`: Mapping of states in the proposals JSON to the CSS class names used
35
52
* to manipulate and display proposals based on their status.
36
53
*
37
- * `count`: Number of proposals that determine after all proposals is loaded
54
+ * `count`: Number of proposals with that state. Calculated after proposals are loaded.
38
55
*/
39
- var states = {
40
- ' .awaitingReview' : {
56
+ const states = {
57
+ [ State . awaitingReview ] : {
41
58
name : 'Awaiting Review' ,
42
59
shortName : 'Awaiting Review' ,
43
60
className : 'awaiting-review' ,
44
61
count : 0
45
62
} ,
46
- ' .scheduledForReview' : {
63
+ [ State . scheduledForReview ] : {
47
64
name : 'Scheduled for Review' ,
48
65
shortName : 'Scheduled' ,
49
66
className : 'scheduled-for-review' ,
50
67
count : 0
51
68
} ,
52
- ' .activeReview' : {
69
+ [ State . activeReview ] : {
53
70
name : 'Active Review' ,
54
71
shortName : 'Active Review' ,
55
72
statusPrefix : 'In ' ,
56
73
className : 'active-review' ,
57
74
count : 0
58
75
} ,
59
- ' .returnedForRevision' : {
76
+ [ State . returnedForRevision ] : {
60
77
name : 'Returned for Revision' ,
61
78
shortName : 'Returned' ,
62
79
className : 'returned-for-revision' ,
63
80
count : 0
64
81
} ,
65
- ' .withdrawn' : {
82
+ [ State . withdrawn ] : {
66
83
name : 'Withdrawn' ,
67
84
shortName : 'Withdrawn' ,
68
85
className : 'withdrawn' ,
69
86
count : 0
70
87
} ,
71
- ' .accepted' : {
88
+ [ State . accepted ] : {
72
89
name : 'Accepted' ,
73
90
shortName : 'Accepted' ,
74
91
className : 'accepted' ,
75
92
count : 0
76
93
} ,
77
- ' .acceptedWithRevisions' : {
94
+ [ State . acceptedWithRevisions ] : {
78
95
name : 'Accepted with revisions' ,
79
96
shortName : 'Accepted' ,
80
97
className : 'accepted-with-revisions' ,
81
98
count : 0
82
99
} ,
83
- ' .rejected' : {
100
+ [ State . rejected ] : {
84
101
name : 'Rejected' ,
85
102
shortName : 'Rejected' ,
86
103
className : 'rejected' ,
87
104
count : 0
88
105
} ,
89
- ' .implemented' : {
106
+ [ State . implemented ] : {
90
107
name : 'Implemented' ,
91
108
shortName : 'Implemented' ,
92
109
className : 'implemented' ,
93
110
count : 0
94
111
} ,
95
- ' .previewing' : {
112
+ [ State . previewing ] : {
96
113
name : 'Previewing' ,
97
114
shortName : 'Previewing' ,
98
115
className : 'previewing' ,
99
116
count : 0
100
117
} ,
101
- ' .error' : {
118
+ [ State . error ] : {
102
119
name : 'Error' ,
103
120
shortName : 'Error' ,
104
121
className : 'error' ,
@@ -113,7 +130,7 @@ function init() {
113
130
var req = new window . XMLHttpRequest ( )
114
131
115
132
req . addEventListener ( 'load' , function ( ) {
116
- let evolutionMetadata = JSON . parse ( req . responseText , adjustStatusValue )
133
+ let evolutionMetadata = JSON . parse ( req . responseText )
117
134
proposals = evolutionMetadata . proposals
118
135
languageVersions = evolutionMetadata . implementationVersions
119
136
@@ -150,16 +167,6 @@ function init() {
150
167
req . send ( )
151
168
}
152
169
153
- /**
154
- * Reviver function passed to JSON.parse() to convert new status field value to old value.
155
- */
156
- function adjustStatusValue ( key , value ) {
157
- if ( key == "state" && value !== "" && ! value . startsWith ( "." ) ) {
158
- return "." + value
159
- }
160
- return value
161
- }
162
-
163
170
/**
164
171
* Creates an Element. Convenience wrapper for `document.createElement`.
165
172
*
@@ -209,7 +216,7 @@ function determineNumberOfProposals(proposals) {
209
216
210
217
// .acceptedWithRevisions proposals are combined in the filtering UI
211
218
// with .accepted proposals.
212
- states [ ' .accepted' ] . count += states [ ' .acceptedWithRevisions' ] . count
219
+ states [ State . accepted ] . count += states [ State . acceptedWithRevisions ] . count
213
220
}
214
221
215
222
/**
@@ -232,8 +239,8 @@ function renderSearchBar () {
232
239
// .acceptedWithRevisions proposals are combined in the filtering UI
233
240
// with .accepted proposals.
234
241
var checkboxes = [
235
- ' .awaitingReview' , ' .scheduledForReview' , ' .activeReview' , ' .accepted' ,
236
- ' .previewing' , ' .implemented' , ' .returnedForRevision' , ' .rejected' , ' .withdrawn'
242
+ State . awaitingReview , State . scheduledForReview , State . activeReview , State . accepted ,
243
+ State . previewing , State . implemented , State . returnedForRevision , State . rejected , State . withdrawn
237
244
] . map ( function ( state ) {
238
245
var className = states [ state ] . className
239
246
@@ -258,7 +265,7 @@ function renderSearchBar () {
258
265
259
266
// The 'Implemented' filter selection gets an extra row of options if selected.
260
267
var implementedCheckboxIfPresent = checkboxes . filter ( function ( cb ) {
261
- return cb . querySelector ( `#filter-by-${ states [ ' .implemented' ] . className } ` )
268
+ return cb . querySelector ( `#filter-by-${ states [ State . implemented ] . className } ` )
262
269
} ) [ 0 ]
263
270
264
271
if ( implementedCheckboxIfPresent ) {
@@ -300,8 +307,8 @@ function renderProposals() {
300
307
var proposalAttachPoint = article . querySelector ( '.proposals-list' )
301
308
302
309
var proposalPresentationOrder = [
303
- ' .awaitingReview' , ' .scheduledForReview' , ' .activeReview' , ' .accepted' , ' .acceptedWithRevisions' ,
304
- ' .previewing' , ' .implemented' , ' .returnedForRevision' , ' .rejected' , ' .withdrawn'
310
+ State . awaitingReview , State . scheduledForReview , State . activeReview , State . accepted , State . acceptedWithRevisions ,
311
+ State . previewing , State . implemented , State . returnedForRevision , State . rejected , State . withdrawn
305
312
]
306
313
307
314
proposalPresentationOrder . map ( function ( state ) {
@@ -340,18 +347,18 @@ function renderProposals() {
340
347
341
348
if ( proposal . reviewManagers . length > 0 ) detailNodes . push ( renderReviewManagers ( proposal . reviewManagers ) )
342
349
if ( proposal . trackingBugs ) detailNodes . push ( renderTrackingBugs ( proposal . trackingBugs ) )
343
- if ( state === ' .implemented' ) detailNodes . push ( renderVersion ( proposal . status . version ) )
344
- if ( state === ' .previewing' ) detailNodes . push ( renderPreview ( ) )
350
+ if ( state === State . implemented ) detailNodes . push ( renderVersion ( proposal . status . version ) )
351
+ if ( state === State . previewing ) detailNodes . push ( renderPreview ( ) )
345
352
if ( proposal . implementation ) detailNodes . push ( renderImplementation ( proposal . implementation ) )
346
353
if ( proposal . upcomingFeatureFlag ) detailNodes . push ( renderUpcomingFeatureFlag ( proposal . upcomingFeatureFlag . flag ) )
347
- if ( state === ' .acceptedWithRevisions' ) detailNodes . push ( renderStatus ( proposal . status ) )
354
+ if ( state === State . acceptedWithRevisions ) detailNodes . push ( renderStatus ( proposal . status ) )
348
355
349
- if ( state === ' .activeReview' || state === ' .scheduledForReview' ) {
356
+ if ( state === State . activeReview || state === State . scheduledForReview ) {
350
357
detailNodes . push ( renderStatus ( proposal . status ) )
351
358
detailNodes . push ( renderReviewPeriod ( proposal . status ) )
352
359
}
353
360
354
- if ( state === ' .returnedForRevision' ) {
361
+ if ( state === State . returnedForRevision ) {
355
362
detailNodes . push ( renderStatus ( proposal . status ) )
356
363
}
357
364
@@ -847,7 +854,7 @@ function _applyStatusFilter(matchingProposals) {
847
854
matchingProposals = matchingProposals
848
855
. filter ( function ( proposal ) {
849
856
return selectedStates . some ( function ( state ) {
850
- if ( ! ( proposal . status . state === ' .implemented' ) ) return true // only filter among Implemented (N.N.N)
857
+ if ( ! ( proposal . status . state === State . implemented ) ) return true // only filter among Implemented (N.N.N)
851
858
if ( state === 'swift-swift-Next' && proposal . status . version === 'Next' ) return true // special case
852
859
853
860
var version = state . split ( / \D + / ) . filter ( function ( s ) { return s . length } ) . join ( '.' )
@@ -969,7 +976,7 @@ function _applyFragment(fragment) {
969
976
970
977
if ( hasVersionSelections ) {
971
978
document . querySelector (
972
- '#filter-by-' + states [ ' .implemented' ] . className
979
+ '#filter-by-' + states [ State . implemented ] . className
973
980
) . checked = true
974
981
}
975
982
}
@@ -988,7 +995,7 @@ function _applyFragment(fragment) {
988
995
if ( ! stateName ) return // fragment contains a nonexistent state
989
996
var state = states [ stateName ]
990
997
991
- if ( stateName === ' .implemented' ) implementedSelected = true
998
+ if ( stateName === State . implemented ) implementedSelected = true
992
999
993
1000
return document . querySelector ( '#filter-by-' + state . className )
994
1001
} ) . filter ( function ( status ) {
@@ -1061,7 +1068,7 @@ function _updateURIFragment() {
1061
1068
// .implemented is redundant if any specific implementation versions are selected.
1062
1069
if ( actions . version . length ) {
1063
1070
statuses = statuses . filter ( function ( status ) {
1064
- return status !== states [ ' .implemented' ] . className
1071
+ return status !== states [ State . implemented ] . className
1065
1072
} )
1066
1073
}
1067
1074
@@ -1171,9 +1178,9 @@ function addNumberToState (state, count) {
1171
1178
*/
1172
1179
function descriptionForSelectedStatuses ( selectedOptions ) {
1173
1180
let allStateOptions = [
1174
- ' .awaitingReview' , ' .scheduledForReview' , ' .activeReview' , ' .accepted' ,
1175
- ' .previewing' , ' .implemented' , ' .returnedForRevision' , ' .rejected' , ' .withdrawn'
1176
- ]
1181
+ State . awaitingReview , State . scheduledForReview , State . activeReview , State . accepted ,
1182
+ State . previewing , State . implemented , State . returnedForRevision , State . rejected , State . withdrawn
1183
+ ]
1177
1184
let selectedCount = selectedOptions . length
1178
1185
let totalCount = allStateOptions . length
1179
1186
let ALL_EXCEPT_MAX_COUNT = 3
0 commit comments