Skip to content

Commit 111c1c0

Browse files
authored
Merge pull request #893 from IFRCGo/fix/per-assessment-question-group-ordering
Fix per assessment question group ordering
2 parents ca08e47 + e200232 commit 111c1c0

File tree

2 files changed

+22
-10
lines changed
  • app/src
    • components/domain/PerAssessmentSummary
    • views/PerAssessmentForm/AreaInput/ComponentInput

2 files changed

+22
-10
lines changed

app/src/components/domain/PerAssessmentSummary/index.tsx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -143,9 +143,8 @@ function PerAssessmentSummary(props: Props) {
143143
// NOTE: do we take the average of only rated components or of all the
144144
// components?
145145
const filteredComponents = areaResponse?.component_responses?.filter(
146-
(component) => isDefined(component?.rating_details)
147-
&& isDefined(component.rating_details.value)
148-
&& component.rating_details?.value !== 0,
146+
(component) => isDefined(component?.rating)
147+
&& component.rating !== 0,
149148
) ?? [];
150149

151150
if (filteredComponents.length === 0) {

app/src/views/PerAssessmentForm/AreaInput/ComponentInput/index.tsx

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import { useTranslation } from '@ifrc-go/ui/hooks';
1313
import { numericIdSelector } from '@ifrc-go/ui/utils';
1414
import {
1515
_cs,
16+
compareNumber,
1617
isFalsyString,
1718
isNotDefined,
1819
listToGroupList,
@@ -149,18 +150,24 @@ function ComponentInput(props: Props) {
149150

150151
const groupedQuestions = useMemo(
151152
() => listToGroupList(
152-
questions,
153+
questions?.sort((q1, q2) => compareNumber(q1.question_num, q2.question_num)),
153154
(question) => question.question_group ?? NO_GROUP,
154155
),
155156
[questions],
156157
);
157158

158-
const groupedQuestionList = mapToList(
159-
groupedQuestions,
160-
(questionsInGroup, groupId) => ({
161-
groupId: Number(groupId),
162-
questionsInGroup,
163-
}),
159+
const groupedQuestionList = useMemo(
160+
() => mapToList(
161+
groupedQuestions,
162+
(questionsInGroup, groupId) => ({
163+
groupId: Number(groupId),
164+
questionsInGroup,
165+
}),
166+
)?.sort((g1, g2) => compareNumber(
167+
g1.questionsInGroup[0].question_num,
168+
g2.questionsInGroup[0].question_num,
169+
)),
170+
[groupedQuestions],
164171
);
165172

166173
if (isNotDefined(componentNumber)) {
@@ -272,6 +279,7 @@ function ComponentInput(props: Props) {
272279
/>
273280
{epi_considerations && (
274281
<InputSection
282+
withoutPadding
275283
title={strings.epiConsiderationTitle}
276284
description={(
277285
<ul className={styles.description}>
@@ -291,11 +299,13 @@ function ComponentInput(props: Props) {
291299
onChange={setFieldValue}
292300
disabled={disabled}
293301
readOnly={readOnly}
302+
rows={8}
294303
/>
295304
</InputSection>
296305
)}
297306
{urban_considerations && (
298307
<InputSection
308+
withoutPadding
299309
title={strings.urbanConsiderationTitle}
300310
description={strings.urbanConsiderationDescription}
301311
>
@@ -306,11 +316,13 @@ function ComponentInput(props: Props) {
306316
onChange={setFieldValue}
307317
disabled={disabled}
308318
readOnly={readOnly}
319+
rows={8}
309320
/>
310321
</InputSection>
311322
)}
312323
{climate_environmental_considerations && (
313324
<InputSection
325+
withoutPadding
314326
title={strings.environmentConsiderationTitle}
315327
description={(
316328
<ul className={styles.description}>
@@ -330,6 +342,7 @@ function ComponentInput(props: Props) {
330342
onChange={setFieldValue}
331343
disabled={disabled}
332344
readOnly={readOnly}
345+
rows={8}
333346
/>
334347
</InputSection>
335348
)}

0 commit comments

Comments
 (0)