Skip to content

Commit 3e78e20

Browse files
committed
Add a select all option for answers
1 parent a418ab9 commit 3e78e20

File tree

2 files changed

+21
-7
lines changed

2 files changed

+21
-7
lines changed

src/components/interactive-builder/modals/question/question-form/rendering-types/inputs/select/select-answers.component.tsx

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,12 @@ const SelectAnswers: React.FC = () => {
3737

3838
const handleSelectAnswers = useCallback(
3939
({ selectedItems }: { selectedItems: Array<AnswerItem> }) => {
40-
const mappedAnswers = selectedItems.map((answer) => ({
41-
concept: answer.id,
42-
label: answer.text,
43-
}));
40+
const mappedAnswers = selectedItems
41+
.filter((answer) => answer.id !== 'select-all')
42+
.map((answer) => ({
43+
concept: answer.id,
44+
label: answer.text,
45+
}));
4446

4547
setFormField((prevField) => {
4648
const currentAnswers = prevField.questionOptions?.answers || [];
@@ -131,7 +133,15 @@ const SelectAnswers: React.FC = () => {
131133
text: answer.label,
132134
}));
133135

134-
return [...answersFromConceptWithLabelsFromFormField, ...additionalAnswers];
136+
return [
137+
...answersFromConceptWithLabelsFromFormField,
138+
...additionalAnswers,
139+
{
140+
id: 'select-all',
141+
text: 'Select all options',
142+
isSelectAll: true,
143+
},
144+
];
135145
}, [concept?.answers, formField.questionOptions?.answers]);
136146

137147
const validateAnswers = useCallback(async () => {
@@ -142,7 +152,10 @@ const SelectAnswers: React.FC = () => {
142152

143153
const originalAnswerIds = new Set((concept?.answers || []).map((ans) => ans.uuid));
144154
const invalidIds: string[] = [];
145-
const uniqueAnswers = Array.from(new Map(answerItems.map((a) => [a.id, a])).values());
155+
// Filter out the 'select-all' option before validation
156+
const uniqueAnswers = Array.from(
157+
new Map(answerItems.filter((a) => a.id !== 'select-all').map((a) => [a.id, a])).values(),
158+
);
146159

147160
for (const answer of uniqueAnswers) {
148161
if (!originalAnswerIds.has(answer.id)) {

translations/en.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
"addProgramWorkflow": "Add program workflow",
66
"addQuestion": "Add Question",
77
"addSection": "Add Section",
8+
"answerConceptValidation": "One or more selected answer concepts do not exist in the system. ",
89
"auditDetails": "Audit Details",
910
"autogeneratedUuid": "UUID (auto-generated)",
1011
"backToDashboard": "Back to dashboard",
@@ -49,7 +50,6 @@
4950
"descriptionPlaceholderText": "e.g. A form used to collect encounter data for clients in the Express Care program.",
5051
"downloadSchema": "Download schema",
5152
"dragToReorder": "Drag to reorder",
52-
"duplicated": "Duplicated",
5353
"duplicateQuestion": "Duplicate question",
5454
"editButton": "Edit {{elementType}}",
5555
"editQuestion": "Edit question",
@@ -110,6 +110,7 @@
110110
"inputDummySchema": "Input dummy schema",
111111
"interactiveBuilder": "Interactive Builder",
112112
"interactiveBuilderHelperText": "The Interactive Builder lets you build your form schema without writing JSON code. The Preview tab automatically updates as you build your form. When done, click Save Form to save your form.",
113+
"invalidAnswerConcept": "Invalid Answer Concept Detected",
113114
"invalidMinMax": "Min value cannot be greater than max",
114115
"invalidVersionWarning": "Version can only start with with a number",
115116
"isQuestionInfoProvided": "Would you like to provide additional details about the question?",

0 commit comments

Comments
 (0)