From d99aa332525983d460df90e0991a927a5f966929 Mon Sep 17 00:00:00 2001 From: Khalim Conn-Kowlessar Date: Mon, 29 Sep 2025 11:22:43 +0000 Subject: [PATCH] handle no data bug for decent homes --- .../decent-homes/DecentHomesDashboard.tsx | 20 ++++-- .../[propertyId]/decent-homes/page.tsx | 61 +++++++++++++++---- 2 files changed, 65 insertions(+), 16 deletions(-) diff --git a/src/app/portfolio/[slug]/(portfolio)/decent-homes/DecentHomesDashboard.tsx b/src/app/portfolio/[slug]/(portfolio)/decent-homes/DecentHomesDashboard.tsx index 8355576..b298ffd 100644 --- a/src/app/portfolio/[slug]/(portfolio)/decent-homes/DecentHomesDashboard.tsx +++ b/src/app/portfolio/[slug]/(portfolio)/decent-homes/DecentHomesDashboard.tsx @@ -193,6 +193,8 @@ const DecentHomesDashboard: React.FC = ({ data, portfolioId }) => { const critCFails = data.filter((p) => p.criterion_c === "fail"); const critDFails = data.filter((p) => p.criterion_d === "fail"); + // print the no datas + const overallPassRate = ((passes.length / total) * 100).toFixed(1); const openDrawer = (group: PropertySummary[], title: string) => { @@ -372,10 +374,20 @@ const DecentHomesDashboard: React.FC = ({ data, portfolioId }) => { size="sm" className="mt-3 bg-brandblue text-white hover:bg-hoverblue hover:text-gray-100" onClick={() => - window.open( - `/portfolio/${portfolioId}/building-passport/${p.id}/decent-homes`, - "_blank" - ) + // If all options are no_data, we open the /assessment page, otherwise we open the /decent-homes page + p.decent_homes === "no_data" && + p.criterion_a === "no_data" && + p.criterion_b === "no_data" && + p.criterion_c === "no_data" && + p.criterion_d === "no_data" + ? window.open( + `/portfolio/${portfolioId}/building-passport/${p.id}`, + "_blank" + ) + : window.open( + `/portfolio/${portfolioId}/building-passport/${p.id}/decent-homes`, + "_blank" + ) } > View Property diff --git a/src/app/portfolio/[slug]/building-passport/[propertyId]/decent-homes/page.tsx b/src/app/portfolio/[slug]/building-passport/[propertyId]/decent-homes/page.tsx index 4354842..bb8c481 100644 --- a/src/app/portfolio/[slug]/building-passport/[propertyId]/decent-homes/page.tsx +++ b/src/app/portfolio/[slug]/building-passport/[propertyId]/decent-homes/page.tsx @@ -164,6 +164,20 @@ const LABEL_MAP: Record = { no_data: "Not Assessed", }; +const OVERALL_LABEL_MAP: Record = { + pass: "Pass", + fail: "Fail", + no_data: "Information Missing", +}; + +const OVERALL_LABEL_COLORS: Record = { + pass: "bg-green-600 hover:bg-green-700", + fail: "bg-red-700 hover:bg-red-800", + no_data: "bg-gray-500 hover:bg-gray-600", +}; + +// status badge + function StatusBadge({ status }: { status: string }) { const colors = status === "pass" @@ -379,6 +393,15 @@ function ReplacementsContent({ ); } +function StatusCircle({ status }: { status: string }) { + const colorMap: Record = { + pass: "bg-green-600", + fail: "bg-red-700", + no_data: "bg-gray-500", + }; + return
; +} + function DecentHomesSummary({ decentHomes, decentHomesMeta, @@ -400,7 +423,11 @@ function DecentHomesSummary({ install_date?: string | null; }[]; }) { - const overallPass = decentHomes.decent_homes === "pass"; + // There are three possible overall outcomes: "pass", "fail", "no_data" + // overall is "pass" if all criteria are "pass" + // overall is "fail" if any criteria are "fail" + // overall is "no_data" if all criteria are "no_data" or some are "no_data" and others are "pass" + const overallPass = decentHomes.decent_homes; const lastUpdated = new Date(decentHomes.creation_date).toLocaleDateString( "en-GB", { @@ -458,13 +485,9 @@ function DecentHomesSummary({ - {overallPass ? "Pass" : "Fail"} + {OVERALL_LABEL_MAP[overallPass]}

Last updated: {lastUpdated}

@@ -472,10 +495,22 @@ function DecentHomesSummary({ - Criterion A - Criterion B - Criterion C - Criterion D + +
Criterion A
+ +
+ +
Criterion B
+ +
+ +
Criterion C
+ +
+ +
Criterion D
+ +