From 0a90eecc91fb4fd37fc7a0989dbb0bc4ded52e14 Mon Sep 17 00:00:00 2001 From: Khalim Conn-Kowlessar Date: Sat, 23 Aug 2025 13:35:34 +0000 Subject: [PATCH] rendered the condition report tab, only if we have the data --- .../components/building-passport/Toolbar.tsx | 18 ++++++++++++++++- src/app/db/surveyDB/schema/surveyDB.ts | 4 ++-- .../[slug]/(portfolio)/summary/page.tsx | 2 -- .../[propertyId]/documents/page.tsx | 7 +++---- .../building-passport/[propertyId]/layout.tsx | 11 ++++++++-- .../building-passport/[propertyId]/utils.ts | 20 +++++++++++++++++-- 6 files changed, 49 insertions(+), 13 deletions(-) diff --git a/src/app/components/building-passport/Toolbar.tsx b/src/app/components/building-passport/Toolbar.tsx index 57ad05d..901b8ac 100644 --- a/src/app/components/building-passport/Toolbar.tsx +++ b/src/app/components/building-passport/Toolbar.tsx @@ -16,10 +16,12 @@ import { NavigationMenuLink, } from "@/app/shadcn_components/ui/navigation-menu"; import { cva } from "class-variance-authority"; +import { getUploadedFile } from "@/app/db/surveyDB/schema/surveyDB"; interface ToolbarProps { propertyId: string; portfolioId: string; + conditionReport: getUploadedFile; } const navigationMenuTriggerStyle = cva( @@ -53,7 +55,7 @@ const navigationMenuTriggerStyle = cva( ].join(" ") ); -export function Toolbar({ propertyId, portfolioId }: ToolbarProps) { +export function Toolbar({ propertyId, portfolioId, conditionReport }: ToolbarProps) { function handleClickSettings() { console.log("Settings were clicked, implement me"); } @@ -108,6 +110,18 @@ export function Toolbar({ propertyId, portfolioId }: ToolbarProps) { ); + const conditionButton = ( + + + Condition Report + + ); + + console.log("conditionReport", conditionReport) + return ( 0 && conditionButton} {energyAssessmentsReportButton}

Summary

diff --git a/src/app/portfolio/[slug]/building-passport/[propertyId]/documents/page.tsx b/src/app/portfolio/[slug]/building-passport/[propertyId]/documents/page.tsx index 6811e87..1ded30a 100644 --- a/src/app/portfolio/[slug]/building-passport/[propertyId]/documents/page.tsx +++ b/src/app/portfolio/[slug]/building-passport/[propertyId]/documents/page.tsx @@ -2,16 +2,15 @@ import { getPropertyMeta } from "@/app/portfolio/[slug]/building-passport/[prope import { eq } from "drizzle-orm"; import { DocumentsTable } from "./DocumentsTable"; import { surveyDB } from "@/app/db/surveyDB/connection"; -import { uploaded_files } from "@/app/db/surveyDB/schema/surveyDB"; +import { uploadedFiles } from "@/app/db/surveyDB/schema/surveyDB"; import { type getUploadedFiles } from "@/app/db/surveyDB/schema/surveyDB"; -import { EmptyObject } from "react-hook-form"; async function getDocuments( uprn: number ): Promise< getUploadedFiles> { - const result = surveyDB.query.uploaded_files.findMany({ - where: eq(uploaded_files.uprn, String(uprn)), + const result = surveyDB.query.uploadedFiles.findMany({ + where: eq(uploadedFiles.uprn, String(uprn)), }); return result; diff --git a/src/app/portfolio/[slug]/building-passport/[propertyId]/layout.tsx b/src/app/portfolio/[slug]/building-passport/[propertyId]/layout.tsx index 02686b0..43f4c92 100644 --- a/src/app/portfolio/[slug]/building-passport/[propertyId]/layout.tsx +++ b/src/app/portfolio/[slug]/building-passport/[propertyId]/layout.tsx @@ -1,5 +1,5 @@ import { Toolbar } from "@/app/components/building-passport/Toolbar"; -import { getPropertyMeta } from "./utils"; +import { getPropertyMeta, getDocument } from "./utils"; import BackToPortfolioButton from "@/app/components/building-passport/BackToPortfolioButton"; import { ExclamationCircleIcon } from "@heroicons/react/24/outline"; @@ -30,6 +30,13 @@ export default async function DashboardLayout( // The layout is a server component by default so we can fetch meta data here const propertyMeta = await getPropertyMeta(params.propertyId); + // We check if we have an uploaded condition report and if so, we show the condition tab. Otherwise, we + // don't show it + const conditionReport = await getDocument( + { uprn: String(propertyMeta.uprn), documentType: "ECO_CONDITION_REPORT" } + ); + + console.log("conditionReport", conditionReport) if (!propertyId && propertyId !== "0") { throw Error("Invalid propertyId"); @@ -53,7 +60,7 @@ export default async function DashboardLayout(

{propertyMeta.postcode}

- +
{propertyMeta.detailsEpc.estimated && } {children} diff --git a/src/app/portfolio/[slug]/building-passport/[propertyId]/utils.ts b/src/app/portfolio/[slug]/building-passport/[propertyId]/utils.ts index d737e33..43bcd70 100644 --- a/src/app/portfolio/[slug]/building-passport/[propertyId]/utils.ts +++ b/src/app/portfolio/[slug]/building-passport/[propertyId]/utils.ts @@ -5,6 +5,7 @@ import { Plan, } from "@/app/db/schema/recommendations"; import { db } from "@/app/db/db"; +import { surveyDB } from "@/app/db/surveyDB/connection"; import { Feature, GeneralFeature, @@ -17,7 +18,7 @@ import { nonInstrusiveSurvey, } from "@/app/db/schema/property"; import { getRating } from "@/app/utils"; -import { eq, desc } from "drizzle-orm"; +import { eq, desc, and } from "drizzle-orm"; import { energyAssessment, EnergyAssessment, @@ -26,9 +27,9 @@ import { } from "@/app/db/schema/energy_assessments"; import { fundingPackage, - FundingPackage, FundingPackageWithMeasures } from "@/app/db/schema/funding"; +import { getUploadedFile, uploadedFiles, DB_REPORT_TYPES } from "@/app/db/surveyDB/schema/surveyDB"; type RecommendationList = { recommendation: Recommendation; @@ -49,6 +50,21 @@ export async function getPlanFunding(planId: string): Promise { + // We get the latest entry for the given UPRN and document type, by s3JsonUploadTimestamp + const data = await surveyDB.query.uploadedFiles.findFirst({ + where: and(eq(uploadedFiles.uprn, String(uprn)), eq(uploadedFiles.docType, documentType)), + orderBy: (uploadedFiles, { desc }) => [desc(uploadedFiles.s3JsonUploadTimestamp)] + }); + // We may not have an uploaded document so we return an empty array + if (!data) { + return {} as getUploadedFile; + } + return data; +} + export async function getEnergyAssessment( uprn: number ): Promise {