Skip to content

Commit

Permalink
[#558] Handle load data NA & comment
Browse files Browse the repository at this point in the history
  • Loading branch information
wayangalihpratama committed Dec 25, 2024
1 parent 4ff7142 commit b18e569
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 3 deletions.
5 changes: 4 additions & 1 deletion frontend/src/pages/data-cleaning/DataDetail.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ const DataDetail = ({ record }) => {
});
record["answer"] = recordAnswer;

const history = record?.history?.map((h) => {
let history = record?.history?.map((h) => {
const identifierAnswer = h?.answer?.filter((a) => a?.is_repeat_identifier);
const historyAnswer = h?.answer?.map((ha) => {
// handle repeat group index with is_repeat_identifier
Expand Down Expand Up @@ -113,6 +113,9 @@ const DataDetail = ({ record }) => {
});
return { ...h, answer: historyAnswer };
});
// show only 1 history
history = _.orderBy(history, "year", "desc");
// history = history?.length ? [history[0]] : [];
// EOL Remap answer and history to provide the repeat_identifier

// generate history columns
Expand Down
48 changes: 46 additions & 2 deletions frontend/src/pages/survey/WebformPage.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -412,6 +412,16 @@ const WebformPage = ({
const { data, status } = res;
// const { form, initial_values, mismatch, collaborators } = test; // testing purpose
const { form, initial_values, mismatch, collaborators } = data;
// handle leading question
const questionWithLeadingQuestionGroup = form.question_group
.flatMap((qg) => {
const question = qg.question.map((q) => ({
...q,
lead_by_question: qg?.leading_question,
}));
return question;
})
?.filter((q) => q?.lead_by_question);
// submission already submitted
if (status === 208) {
setErrorPage(true);
Expand All @@ -424,15 +434,33 @@ const WebformPage = ({
setSavedData(initial_values);
const answers = initial_values.answer.map((a) => {
const { question, repeat_index, comment } = a;
// handle leading question
let repeatIndexString =
repeat_index > 0 ? String(repeat_index) : null;
const findQuestion = questionWithLeadingQuestionGroup.find(
(q) => q.id === question
);
if (findQuestion?.lead_by_question) {
const leadingAnswer = initial_values.answer.find(
(a) => a.question === findQuestion.lead_by_question
)?.value;
repeatIndexString =
leadingAnswer?.[repeat_index] || repeat_index;
}
// eol handle leading question
const commentQid =
repeat_index > 0 ? `${question}-${repeat_index}` : question;
repeat_index > 0 || repeatIndexString
? `${question}-${repeatIndexString}`
: question;
commentValues = {
...commentValues,
[commentQid]: comment,
};
return {
...a,
repeatIndex: repeat_index,
repeat_index: repeat_index,
repeat_index_string: repeatIndexString,
};
});
setInitialAnswers(answers);
Expand All @@ -444,8 +472,24 @@ const WebformPage = ({
setInitialAnswers(answer);
answer.forEach((a) => {
const { question, repeat_index, comment } = a;
// handle leading question
let repeatIndexString =
repeat_index > 0 ? String(repeat_index) : null;
const findQuestion = questionWithLeadingQuestionGroup.find(
(q) => q.id === question
);
if (findQuestion?.lead_by_question) {
const leadingAnswer = initial_values.answer.find(
(a) => a.question === findQuestion.lead_by_question
)?.value;
repeatIndexString =
leadingAnswer?.[repeat_index] || repeat_index;
}
// eol handle leading question
const commentQid =
repeat_index > 0 ? `${question}-${repeat_index}` : question;
repeat_index > 0 || repeatIndexString
? `${question}-${repeatIndexString}`
: question;
commentValues = {
...commentValues,
[commentQid]: comment,
Expand Down

0 comments on commit b18e569

Please # to comment.