Merge pull request #96 from Hestia-Homes/db/funding

handle no data bug for decent homes
This commit is contained in:
KhalimCK 2025-09-29 12:27:02 +01:00 committed by GitHub
commit 4bf3ec44f2
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 65 additions and 16 deletions

View file

@ -193,6 +193,8 @@ const DecentHomesDashboard: React.FC<Props> = ({ 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<Props> = ({ 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

View file

@ -164,6 +164,20 @@ const LABEL_MAP: Record<string, string> = {
no_data: "Not Assessed",
};
const OVERALL_LABEL_MAP: Record<string, string> = {
pass: "Pass",
fail: "Fail",
no_data: "Information Missing",
};
const OVERALL_LABEL_COLORS: Record<string, string> = {
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<string, string> = {
pass: "bg-green-600",
fail: "bg-red-700",
no_data: "bg-gray-500",
};
return <div className={`w-4 h-4 rounded-full ${colorMap[status]}`} />;
}
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({
</CardHeader>
<CardContent className="flex flex-col items-center space-y-1">
<Badge
className={`px-4 py-2 text-lg ${
overallPass
? "bg-green-600 hover:bg-green-700"
: "bg-red-700 hover:bg-red-800"
} text-white`}
className={`px-4 py-2 text-lg ${OVERALL_LABEL_COLORS[overallPass]} text-white`}
>
{overallPass ? "Pass" : "Fail"}
{OVERALL_LABEL_MAP[overallPass]}
</Badge>
<p className="text-sm text-gray-500">Last updated: {lastUpdated}</p>
</CardContent>
@ -472,10 +495,22 @@ function DecentHomesSummary({
<Tabs defaultValue="A" className="w-full max-w-4xl">
<TabsList className="grid grid-cols-5 w-full">
<TabsTrigger value="A">Criterion A</TabsTrigger>
<TabsTrigger value="B">Criterion B</TabsTrigger>
<TabsTrigger value="C">Criterion C</TabsTrigger>
<TabsTrigger value="D">Criterion D</TabsTrigger>
<TabsTrigger value="A">
<div className="mr-4">Criterion A</div>
<StatusCircle status={decentHomes.criterion_a} />
</TabsTrigger>
<TabsTrigger value="B">
<div className="mr-4">Criterion B</div>
<StatusCircle status={decentHomes.criterion_b} />
</TabsTrigger>
<TabsTrigger value="C">
<div className="mr-4">Criterion C</div>
<StatusCircle status={decentHomes.criterion_c} />
</TabsTrigger>
<TabsTrigger value="D">
<div className="mr-4">Criterion D</div>
<StatusCircle status={decentHomes.criterion_d} />
</TabsTrigger>
<TabsTrigger
value="replacements"
className="relative flex items-center space-x-2 text-orange-700 font-medium
@ -545,7 +580,9 @@ export default async function DecentHomesPage(props: {
!decentHomesSummary.s3JsonUri ||
!decentPropertyMeta.s3JsonUri
) {
throw new Error("Decent Homes data is missing");
throw new Error(
`Decent Homes data is missing for uprn ${propertyMeta.uprn}`
);
}
const decentHomesMeta = await getEnergyAssessmentFromS3(