Skip to content

Commit cfa5cdd

Browse files
committed
generator: support the hidden property of choices
fixes #1102 There can be an optional `hidden` boolean column in the `Choices` tab of the Excel file to say if a choice should be hidden.
1 parent dfae5ce commit cfa5cdd

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed

packages/evolution-generator/src/scripts/generate_choices.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ def generate_choices(input_file: str, output_file: str):
7070
label_en = process_label(row_dict["label::en"])
7171
spread_choices_name = row_dict["spreadChoicesName"]
7272
conditional = row_dict["conditional"]
73+
hidden = row_dict.get("hidden", False)
7374

7475
# Check if the row is valid
7576
if choice_name is None or (value is None and spread_choices_name is None):
@@ -80,6 +81,7 @@ def generate_choices(input_file: str, output_file: str):
8081
"value": value,
8182
"label": {"fr": label_fr, "en": label_en},
8283
"spread_choices_name": spread_choices_name,
84+
"hidden": hidden,
8385
}
8486

8587
# Add conditional field to choice object if it exists
@@ -123,7 +125,8 @@ def generate_choices(input_file: str, output_file: str):
123125
f"{INDENT}{INDENT}label: {{\n"
124126
f"{INDENT}{INDENT}{INDENT}fr: '{choice['label']['fr']}',\n"
125127
f"{INDENT}{INDENT}{INDENT}en: '{choice['label']['en']}'\n"
126-
f"{INDENT}{INDENT}}}{',' if choice.get("conditional", None) is not None else ''}\n"
128+
f"{INDENT}{INDENT}}}{f",\n{INDENT}{INDENT}hidden: true" if choice["hidden"] else ''}"
129+
f"{INDENT}{INDENT}{',' if choice.get("conditional", None) is not None else ''}\n"
127130
)
128131
# Add the 'conditional' field only if it exists
129132
if choice.get("conditional", None) is not None:

packages/evolution-generator/src/tests/test_generate_choices.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,20 @@
110110
None,
111111
],
112112
]
113+
# FIXME We do not actually test that the hidden choices are correctly generated, just that it works
114+
GOOD_HEADERS_WITH_HIDDEN = [
115+
"choicesName",
116+
"value",
117+
"label::fr",
118+
"label::en",
119+
"spreadChoicesName",
120+
"conditional",
121+
"hidden",
122+
]
123+
GOOD_ROWS_DATA_WITH_HIDDEN = [
124+
["yesNoChoices", "yes", "Oui", "Yes", None, None, True],
125+
["yesNoChoices", "no", "Non", "No", None, None, False],
126+
]
113127
BAD_ROWS_DATA = [["badRowData"]]
114128

115129

@@ -134,6 +148,15 @@
134148
GOOD_OUPUT_FILE,
135149
None, # No error expected
136150
),
151+
# Test that the function works correctly with 'hidden' headers
152+
(
153+
GOOD_SHEET_NAME,
154+
GOOD_HEADERS_WITH_HIDDEN,
155+
GOOD_ROWS_DATA_WITH_HIDDEN,
156+
GOOD_INPUT_FILE,
157+
GOOD_OUPUT_FILE,
158+
None, # No error expected
159+
),
137160
# Test that the function catch bad input file type
138161
(
139162
GOOD_SHEET_NAME,

0 commit comments

Comments
 (0)