Skip to content

Commit aa38cd3

Browse files
committed
feat: Extract title lists from FactSers
for facts with choices.
1 parent 833fc8d commit aa38cd3

File tree

1 file changed

+30
-15
lines changed

1 file changed

+30
-15
lines changed

lib/index.js

Lines changed: 30 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,27 @@ module.exports = function (cardscript) {
33
$simpleTitleMaps: {}
44
}
55

6+
function buildLabelList (id, choices) {
7+
const map = {}
8+
lists[id] = choices.map(({ title, value }) => {
9+
map[value] = title || value
10+
return {
11+
text: title || value,
12+
label: title || value,
13+
value
14+
}
15+
})
16+
lists.$simpleTitleMaps[id] = map
17+
}
18+
19+
function buildTitleMap (id, choices) {
20+
const map = {}
21+
choices.forEach(({ title, value }) => {
22+
map[value] = title || value
23+
})
24+
lists.$simpleTitleMaps[id] = map
25+
}
26+
627
function parseElement (element) {
728
switch (element.type) {
829
case 'Container':
@@ -11,10 +32,7 @@ module.exports = function (cardscript) {
1132
case 'ColumnSet':
1233
element.columns.forEach(parseElement)
1334
break
14-
case 'FactSet':
15-
element.facts.forEach(parseElement)
16-
break
17-
case 'CardList':
35+
case 'CardList':
1836
element.card.body.forEach(parseElement)
1937
break
2038
case 'Column':
@@ -25,18 +43,15 @@ module.exports = function (cardscript) {
2543
break
2644
case 'Input.ChoiceSet':
2745
if (element.choices) {
28-
const map = {}
29-
lists[element.id] = element.choices.map(({ title, value }) => {
30-
map[value] = title || value
31-
return {
32-
text: title || value,
33-
label: title || value,
34-
value
35-
}
36-
})
37-
lists.$simpleTitleMaps[element.id] = map
38-
}
46+
buildLabelList(element.id, element.choices) }
3947
break
48+
case 'FactSet':
49+
for (const fact of element.facts) {
50+
if (fact.choices) {
51+
buildTitleMap(fact.title, fact.choices, true)
52+
}
53+
}
54+
break;
4055
}
4156
}
4257

0 commit comments

Comments
 (0)