-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #257 from wri/merge/main-staging-ii
[MERGE] main -> staging post II release
- Loading branch information
Showing
5 changed files
with
28 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,41 +1,30 @@ | ||
import { useMemo, useState } from "react"; | ||
import { useMemo } from "react"; | ||
|
||
import { GetV2FormsENTITYUUIDResponse, useGetV2FormsENTITYUUID } from "@/generated/apiComponents"; | ||
|
||
export function useProcessRecordData(modelUUID: string, modelName: string, inputType: string) { | ||
const [show, setShow] = useState(false); | ||
const { data: record } = useGetV2FormsENTITYUUID<{ data: GetV2FormsENTITYUUIDResponse }>({ | ||
pathParams: { | ||
uuid: modelUUID, | ||
entity: modelName | ||
} | ||
}); | ||
|
||
const ProcesssRecordData = useMemo(() => { | ||
const viewDataTable = record?.data?.form?.form_sections.map((formSection: any) => | ||
formSection.form_questions | ||
.map((formQuestion: any) => formQuestion.uuid) | ||
.map((formQuestionUUID: any) => record?.data?.answers?.[formQuestionUUID]) | ||
); | ||
return useMemo(() => { | ||
if (record?.data?.form == null) return false; | ||
|
||
for (let sectionIndex in record?.data?.form?.form_sections) { | ||
for (let questionIndex in record?.data?.form?.form_sections[sectionIndex].form_questions) { | ||
const question = record?.data?.form?.form_sections[sectionIndex].form_questions[questionIndex]; | ||
if (question.children) { | ||
for (let child of question.children) { | ||
if (child.input_type === inputType) { | ||
setShow(viewDataTable?.[sectionIndex]?.[questionIndex]); | ||
} | ||
for (const section of record.data.form.form_sections) { | ||
for (const question of section.form_questions) { | ||
for (const child of question.children ?? []) { | ||
if (child.input_type == inputType) { | ||
// Only hide the data if the answer is an explicit false in order to not break the UI | ||
// for reports that are older than the current version of the form. | ||
return record.data.answers![child.parent_id] !== false; | ||
} | ||
} else { | ||
setShow(true); | ||
} | ||
} | ||
} | ||
|
||
return show; | ||
// eslint-disable-next-line react-hooks/exhaustive-deps | ||
}, [record, inputType, modelUUID, modelName, show]); | ||
|
||
return ProcesssRecordData; | ||
return true; | ||
}, [record, inputType, modelUUID, modelName]); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters