Skip to content

Commit ceff0bf

Browse files
Migrate dashboard script to new status values (#646)
* Use string constants for proposal status state values - Add string constants to frozen State object to namespace the values - Update uses of the state strings to use the constants * Migrate dashboard script to use new status state values - Update state string constants to match new state values (no leading dot) - Remove reviver function that added leading dot during transition
1 parent 7a3b76a commit ceff0bf

File tree

1 file changed

+49
-42
lines changed

1 file changed

+49
-42
lines changed

assets/javascripts/swift-evolution.js

Lines changed: 49 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,24 @@ let filterSelection = []
2525

2626
let upcomingFeatureFlagFilterEnabled = false
2727

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+
2843
/**
44+
* property names: Proposal state string constants
45+
*
2946
* `name`: Mapping of the states in the proposals JSON to human-readable names.
3047
*
3148
* `shortName`: Mapping of the states in the proposals JSON to short human-readable names.
@@ -34,71 +51,71 @@ let upcomingFeatureFlagFilterEnabled = false
3451
* `className`: Mapping of states in the proposals JSON to the CSS class names used
3552
* to manipulate and display proposals based on their status.
3653
*
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.
3855
*/
39-
var states = {
40-
'.awaitingReview': {
56+
const states = {
57+
[State.awaitingReview]: {
4158
name: 'Awaiting Review',
4259
shortName: 'Awaiting Review',
4360
className: 'awaiting-review',
4461
count: 0
4562
},
46-
'.scheduledForReview': {
63+
[State.scheduledForReview]: {
4764
name: 'Scheduled for Review',
4865
shortName: 'Scheduled',
4966
className: 'scheduled-for-review',
5067
count: 0
5168
},
52-
'.activeReview': {
69+
[State.activeReview]: {
5370
name: 'Active Review',
5471
shortName: 'Active Review',
5572
statusPrefix: 'In ',
5673
className: 'active-review',
5774
count: 0
5875
},
59-
'.returnedForRevision': {
76+
[State.returnedForRevision]: {
6077
name: 'Returned for Revision',
6178
shortName: 'Returned',
6279
className: 'returned-for-revision',
6380
count: 0
6481
},
65-
'.withdrawn': {
82+
[State.withdrawn]: {
6683
name: 'Withdrawn',
6784
shortName: 'Withdrawn',
6885
className: 'withdrawn',
6986
count: 0
7087
},
71-
'.accepted': {
88+
[State.accepted]: {
7289
name: 'Accepted',
7390
shortName: 'Accepted',
7491
className: 'accepted',
7592
count: 0
7693
},
77-
'.acceptedWithRevisions': {
94+
[State.acceptedWithRevisions]: {
7895
name: 'Accepted with revisions',
7996
shortName: 'Accepted',
8097
className: 'accepted-with-revisions',
8198
count: 0
8299
},
83-
'.rejected': {
100+
[State.rejected]: {
84101
name: 'Rejected',
85102
shortName: 'Rejected',
86103
className: 'rejected',
87104
count: 0
88105
},
89-
'.implemented': {
106+
[State.implemented]: {
90107
name: 'Implemented',
91108
shortName: 'Implemented',
92109
className: 'implemented',
93110
count: 0
94111
},
95-
'.previewing': {
112+
[State.previewing]: {
96113
name: 'Previewing',
97114
shortName: 'Previewing',
98115
className: 'previewing',
99116
count: 0
100117
},
101-
'.error': {
118+
[State.error]: {
102119
name: 'Error',
103120
shortName: 'Error',
104121
className: 'error',
@@ -113,7 +130,7 @@ function init() {
113130
var req = new window.XMLHttpRequest()
114131

115132
req.addEventListener('load', function() {
116-
let evolutionMetadata = JSON.parse(req.responseText, adjustStatusValue)
133+
let evolutionMetadata = JSON.parse(req.responseText)
117134
proposals = evolutionMetadata.proposals
118135
languageVersions = evolutionMetadata.implementationVersions
119136

@@ -150,16 +167,6 @@ function init() {
150167
req.send()
151168
}
152169

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-
163170
/**
164171
* Creates an Element. Convenience wrapper for `document.createElement`.
165172
*
@@ -209,7 +216,7 @@ function determineNumberOfProposals(proposals) {
209216

210217
// .acceptedWithRevisions proposals are combined in the filtering UI
211218
// with .accepted proposals.
212-
states['.accepted'].count += states['.acceptedWithRevisions'].count
219+
states[State.accepted].count += states[State.acceptedWithRevisions].count
213220
}
214221

215222
/**
@@ -232,8 +239,8 @@ function renderSearchBar () {
232239
// .acceptedWithRevisions proposals are combined in the filtering UI
233240
// with .accepted proposals.
234241
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
237244
].map(function (state) {
238245
var className = states[state].className
239246

@@ -258,7 +265,7 @@ function renderSearchBar () {
258265

259266
// The 'Implemented' filter selection gets an extra row of options if selected.
260267
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}`)
262269
})[0]
263270

264271
if (implementedCheckboxIfPresent) {
@@ -300,8 +307,8 @@ function renderProposals() {
300307
var proposalAttachPoint = article.querySelector('.proposals-list')
301308

302309
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
305312
]
306313

307314
proposalPresentationOrder.map(function (state) {
@@ -340,18 +347,18 @@ function renderProposals() {
340347

341348
if (proposal.reviewManagers.length > 0) detailNodes.push(renderReviewManagers(proposal.reviewManagers))
342349
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())
345352
if (proposal.implementation) detailNodes.push(renderImplementation(proposal.implementation))
346353
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))
348355

349-
if (state === '.activeReview' || state === '.scheduledForReview') {
356+
if (state === State.activeReview || state === State.scheduledForReview) {
350357
detailNodes.push(renderStatus(proposal.status))
351358
detailNodes.push(renderReviewPeriod(proposal.status))
352359
}
353360

354-
if (state === '.returnedForRevision') {
361+
if (state === State.returnedForRevision) {
355362
detailNodes.push(renderStatus(proposal.status))
356363
}
357364

@@ -847,7 +854,7 @@ function _applyStatusFilter(matchingProposals) {
847854
matchingProposals = matchingProposals
848855
.filter(function (proposal) {
849856
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)
851858
if (state === 'swift-swift-Next' && proposal.status.version === 'Next') return true // special case
852859

853860
var version = state.split(/\D+/).filter(function (s) { return s.length }).join('.')
@@ -969,7 +976,7 @@ function _applyFragment(fragment) {
969976

970977
if (hasVersionSelections) {
971978
document.querySelector(
972-
'#filter-by-' + states['.implemented'].className
979+
'#filter-by-' + states[State.implemented].className
973980
).checked = true
974981
}
975982
}
@@ -988,7 +995,7 @@ function _applyFragment(fragment) {
988995
if (!stateName) return // fragment contains a nonexistent state
989996
var state = states[stateName]
990997

991-
if (stateName === '.implemented') implementedSelected = true
998+
if (stateName === State.implemented) implementedSelected = true
992999

9931000
return document.querySelector('#filter-by-' + state.className)
9941001
}).filter(function (status) {
@@ -1061,7 +1068,7 @@ function _updateURIFragment() {
10611068
// .implemented is redundant if any specific implementation versions are selected.
10621069
if (actions.version.length) {
10631070
statuses = statuses.filter(function (status) {
1064-
return status !== states['.implemented'].className
1071+
return status !== states[State.implemented].className
10651072
})
10661073
}
10671074

@@ -1171,9 +1178,9 @@ function addNumberToState (state, count) {
11711178
*/
11721179
function descriptionForSelectedStatuses(selectedOptions) {
11731180
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+
]
11771184
let selectedCount = selectedOptions.length
11781185
let totalCount = allStateOptions.length
11791186
let ALL_EXCEPT_MAX_COUNT = 3

0 commit comments

Comments
 (0)