({});
- if (collection && queryParams) {
+ if (collection != null) {
queryParams["filter[collection]"] = collection;
}
@@ -39,13 +39,13 @@ const TreeSpeciesTable = ({ modelName, modelUUID, collection, onFetch }: TreeSpe
: false;
const showTreeSpecies = useProcessRecordData(modelUUID, modelName, "treeSpecies");
+ const data = showTreeSpecies ? treeSpecies?.data?.map(item => ({ ...item, amount: item.amount ?? 0 })) ?? [] : [];
return (
({ ...item, amount: item.amount || 0 })) : []) ?? []}
+ data={data}
isLoading={isLoading}
- treeSpeciesShow={true}
onQueryParamChange={setQueryParams}
columns={[
{
diff --git a/src/hooks/useProcessRecordData.ts b/src/hooks/useProcessRecordData.ts
index 9e3959b61..c6adcc0f3 100644
--- a/src/hooks/useProcessRecordData.ts
+++ b/src/hooks/useProcessRecordData.ts
@@ -1,9 +1,8 @@
-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,
@@ -11,31 +10,21 @@ export function useProcessRecordData(modelUUID: string, modelName: string, input
}
});
- 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]);
}
diff --git a/src/pages/reports/site-report/[uuid].page.tsx b/src/pages/reports/site-report/[uuid].page.tsx
index 01e507adb..e1ee18eb0 100644
--- a/src/pages/reports/site-report/[uuid].page.tsx
+++ b/src/pages/reports/site-report/[uuid].page.tsx
@@ -161,9 +161,19 @@ const SiteReportDetailPage = () => {
{siteReport.public_narrative}
-
+
+
+