From 12207f27fd5103bcf4728559b9eea4e1ca1550a8 Mon Sep 17 00:00:00 2001 From: Nathan Curtis Date: Wed, 5 Jun 2024 21:23:55 -0700 Subject: [PATCH 1/5] [TM-911] Display seeding counts on project, site and their report admin pages. --- .../HighLevelMetrics.tsx | 5 ++++ .../HighLevelMetrics.tsx | 9 ++++++++ .../SiteInformationAside/HighLevelMetrics.tsx | 23 +++++++++++-------- 3 files changed, 27 insertions(+), 10 deletions(-) diff --git a/src/admin/components/ResourceTabs/InformationTab/components/ProjectInformationAside/HighLevelMetrics.tsx b/src/admin/components/ResourceTabs/InformationTab/components/ProjectInformationAside/HighLevelMetrics.tsx index ee72b1cfe..a07351a8b 100644 --- a/src/admin/components/ResourceTabs/InformationTab/components/ProjectInformationAside/HighLevelMetrics.tsx +++ b/src/admin/components/ResourceTabs/InformationTab/components/ProjectInformationAside/HighLevelMetrics.tsx @@ -36,6 +36,11 @@ const HighLevelMetics: FC = () => { + + + + + ); diff --git a/src/admin/components/ResourceTabs/InformationTab/components/ReportInformationAside/HighLevelMetrics.tsx b/src/admin/components/ResourceTabs/InformationTab/components/ReportInformationAside/HighLevelMetrics.tsx index 8016a55b6..f51002a26 100644 --- a/src/admin/components/ResourceTabs/InformationTab/components/ReportInformationAside/HighLevelMetrics.tsx +++ b/src/admin/components/ResourceTabs/InformationTab/components/ReportInformationAside/HighLevelMetrics.tsx @@ -12,6 +12,7 @@ const HighLevelMetics: FC = () => { }; const isTerraFund = record.framework_key === "terrafund"; + const isPPC = record.framework_key === "ppc"; const workdaysType = resource === "projectReport" ? "Project" : resource === "siteReport" ? "Site" : null; return ( @@ -48,6 +49,14 @@ const HighLevelMetics: FC = () => { emptyText="0" /> + + + + + diff --git a/src/admin/components/ResourceTabs/InformationTab/components/SiteInformationAside/HighLevelMetrics.tsx b/src/admin/components/ResourceTabs/InformationTab/components/SiteInformationAside/HighLevelMetrics.tsx index d6fa709eb..846eb2abb 100644 --- a/src/admin/components/ResourceTabs/InformationTab/components/SiteInformationAside/HighLevelMetrics.tsx +++ b/src/admin/components/ResourceTabs/InformationTab/components/SiteInformationAside/HighLevelMetrics.tsx @@ -1,8 +1,9 @@ -import { Box, Card, Divider, Stack, SxProps, Theme, Typography } from "@mui/material"; +import { Box, Card, Stack, SxProps, Theme } from "@mui/material"; import { FC } from "react"; import { Labeled, NumberField, useShowContext } from "react-admin"; import { When } from "react-if"; +import Text from "@/components/elements/Text/Text"; const HighLevelMetics: FC = () => { const { record } = useShowContext(); @@ -14,15 +15,12 @@ const HighLevelMetics: FC = () => { const isPPC = record.framework_key === "ppc"; return ( - - - High Level Metrics - - - - + + + High Level Metrics + @@ -31,10 +29,15 @@ const HighLevelMetics: FC = () => { - + - + + + + + + From 93d4a477b66365be4599246ae22b54adc38738be Mon Sep 17 00:00:00 2001 From: Nathan Curtis Date: Thu, 6 Jun 2024 13:57:37 -0700 Subject: [PATCH 2/5] [TM-754] Display tree and seeding totals on the PPC site report page. --- src/pages/reports/site-report/[uuid].page.tsx | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/pages/reports/site-report/[uuid].page.tsx b/src/pages/reports/site-report/[uuid].page.tsx index 01e507adb..a551f08e0 100644 --- a/src/pages/reports/site-report/[uuid].page.tsx +++ b/src/pages/reports/site-report/[uuid].page.tsx @@ -161,9 +161,23 @@ const SiteReportDetailPage = () => { {siteReport.public_narrative} + + + + + + From 74f18ed446b1889b621fc86b7a42051e9f43a561 Mon Sep 17 00:00:00 2001 From: Nathan Curtis Date: Fri, 7 Jun 2024 12:39:14 -0700 Subject: [PATCH 3/5] [TM-754] Enable the new field on all site reports, not just PPC. --- src/pages/reports/site-report/[uuid].page.tsx | 24 ++++++++----------- 1 file changed, 10 insertions(+), 14 deletions(-) diff --git a/src/pages/reports/site-report/[uuid].page.tsx b/src/pages/reports/site-report/[uuid].page.tsx index a551f08e0..a2f795c14 100644 --- a/src/pages/reports/site-report/[uuid].page.tsx +++ b/src/pages/reports/site-report/[uuid].page.tsx @@ -161,23 +161,19 @@ const SiteReportDetailPage = () => { {siteReport.public_narrative} - - - + - - - + From 05338cd658c25a7dac2be975af01c0fc138f943d Mon Sep 17 00:00:00 2001 From: Nathan Curtis Date: Tue, 11 Jun 2024 15:28:48 -0700 Subject: [PATCH 4/5] [TM-754] Only include tree-planted collection on the site report page. --- src/pages/reports/site-report/[uuid].page.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pages/reports/site-report/[uuid].page.tsx b/src/pages/reports/site-report/[uuid].page.tsx index a2f795c14..e1ee18eb0 100644 --- a/src/pages/reports/site-report/[uuid].page.tsx +++ b/src/pages/reports/site-report/[uuid].page.tsx @@ -166,7 +166,7 @@ const SiteReportDetailPage = () => { label={t("Total Trees Planted")} value={siteReport.total_trees_planted_count} /> - + Date: Tue, 11 Jun 2024 16:05:05 -0700 Subject: [PATCH 5/5] [TM-754] Improve the process for filtering out data that is hidden due to a conditional question. --- .../ServerSideTable/ServerSideTable.tsx | 2 - src/components/extensive/Pagination/index.tsx | 37 ++++++++----------- .../extensive/Tables/TreeSpeciesTable.tsx | 8 ++-- src/hooks/useProcessRecordData.ts | 35 ++++++------------ 4 files changed, 31 insertions(+), 51 deletions(-) diff --git a/src/components/elements/ServerSideTable/ServerSideTable.tsx b/src/components/elements/ServerSideTable/ServerSideTable.tsx index cc48e39b7..4b3ca406a 100644 --- a/src/components/elements/ServerSideTable/ServerSideTable.tsx +++ b/src/components/elements/ServerSideTable/ServerSideTable.tsx @@ -18,7 +18,6 @@ export interface ServerSideTableProps extends Omit, "on meta: any; onTableStateChange?: (state: ServerSideTableState) => void; onQueryParamChange?: (queryParams: any) => void; - treeSpeciesShow?: boolean; } export function ServerSideTable({ @@ -68,7 +67,6 @@ export function ServerSideTable({ setPage(1); setPageSize(size); }} - treeSpeciesShow={props.treeSpeciesShow} /> )} diff --git a/src/components/extensive/Pagination/index.tsx b/src/components/extensive/Pagination/index.tsx index 35e5d429c..99885e949 100644 --- a/src/components/extensive/Pagination/index.tsx +++ b/src/components/extensive/Pagination/index.tsx @@ -8,29 +8,22 @@ export interface PaginationProps extends PageSelectorProps { hasPageSizeSelector?: boolean; defaultPageSize?: number; setPageSize?: (count: number) => void; - treeSpeciesShow?: boolean; } -function Pagination(props: PaginationProps) { - return props.treeSpeciesShow ? ( -
- -
- ) : ( -
- {props.hasPageSizeSelector ? ( - - ) : ( -
- )} - -
- ); -} +const Pagination = (props: PaginationProps) => ( +
+ {props.hasPageSizeSelector ? ( + + ) : ( +
+ )} + +
+); export default Pagination; diff --git a/src/components/extensive/Tables/TreeSpeciesTable.tsx b/src/components/extensive/Tables/TreeSpeciesTable.tsx index c5af405fb..8d05e2f1d 100644 --- a/src/components/extensive/Tables/TreeSpeciesTable.tsx +++ b/src/components/extensive/Tables/TreeSpeciesTable.tsx @@ -15,9 +15,9 @@ export interface TreeSpeciesTableProps { const TreeSpeciesTable = ({ modelName, modelUUID, collection, onFetch }: TreeSpeciesTableProps) => { const t = useT(); - const [queryParams, setQueryParams] = useState(); + const [queryParams, setQueryParams] = useState({}); - 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]); }