Skip to content

Commit 8c2f3cd

Browse files
Add ability for dashboard script to work with current and proposed schemas (#602)
* Add ability for dashboard script to work with current and proposed schemas
1 parent 44da9ff commit 8c2f3cd

File tree

1 file changed

+22
-2
lines changed

1 file changed

+22
-2
lines changed

assets/javascripts/swift-evolution.js

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -158,8 +158,16 @@ function init() {
158158
var req = new window.XMLHttpRequest()
159159

160160
req.addEventListener('load', function() {
161-
proposals = JSON.parse(req.responseText)
162-
161+
let evolutionMetadata = JSON.parse(req.responseText, flattenStatus)
162+
163+
// Temporary conditional to allow script to work with old and new schemas
164+
if (Array.isArray(evolutionMetadata)) { // current schema
165+
proposals = evolutionMetadata
166+
} else { // new schema
167+
proposals = evolutionMetadata.proposals
168+
languageVersions = evolutionMetadata.implementationVersions
169+
}
170+
163171
// Don't display malformed proposals
164172
proposals = proposals.filter(function (proposal) {
165173
return !proposal.errors
@@ -201,6 +209,18 @@ function init() {
201209
req.send()
202210
}
203211

212+
/**
213+
* Reviver function passed to JSON.parse() to convert new status field structure to old structure.
214+
*/
215+
function flattenStatus(key, value) {
216+
if (key == "status" && value !== "" && !value.state) {
217+
let [subkey, subvalue] = Object.entries(value)[0]
218+
subvalue.state = "." + subkey
219+
return subvalue
220+
}
221+
return value
222+
}
223+
204224
/**
205225
* Creates an Element. Convenience wrapper for `document.createElement`.
206226
*

0 commit comments

Comments
 (0)