rendered the condition report tab, only if we have the data

This commit is contained in:
Khalim Conn-Kowlessar 2025-08-23 13:35:34 +00:00
parent a66a5cd89d
commit 0a90eecc91
6 changed files with 49 additions and 13 deletions

View file

@ -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) {
</NavigationMenuLink>
);
const conditionButton = (
<NavigationMenuLink
className={navigationMenuTriggerStyle() + " ml-3 mr-2"}
href={`/portfolio/${portfolioId}/building-passport/${propertyId}/condition`}
>
<WrenchScrewdriverIcon className="h-4 w-4 mr-2" />
Condition Report
</NavigationMenuLink>
);
console.log("conditionReport", conditionReport)
return (
<NavigationMenu>
<NavigationMenuLink
@ -123,6 +137,8 @@ export function Toolbar({ propertyId, portfolioId }: ToolbarProps) {
{solarAnalysisButton}
{recommendationsButton}
{documentsButton}
{/*We only show the conditionButton if the condition report is not empty*/}
{Object.keys(conditionReport).length > 0 && conditionButton}
{energyAssessmentsReportButton}
<NavigationMenuItem
className={navigationMenuTriggerStyle() + " ml-3 mr-2"}

View file

@ -12,7 +12,7 @@ export const DB_REPORT_TYPES = [
export const docTypeEnum = pgEnum("reporttype", DB_REPORT_TYPES);
export const uploaded_files = pgTable("uploaded_files", {
export const uploadedFiles = pgTable("uploaded_files", {
id: uuid("id").primaryKey().defaultRandom(),
s3JsonUri: text("s3_json_uri"),
@ -26,6 +26,6 @@ export const uploaded_files = pgTable("uploaded_files", {
uprn: text("uprn").notNull(),
});
export type getUploadedFile = typeof uploaded_files.$inferSelect
export type getUploadedFile = typeof uploadedFiles.$inferSelect
export type getUploadedFiles = getUploadedFile[];

View file

@ -17,8 +17,6 @@ export default async function PortfolioSummary(
// Get user id from the session
const scenarios = await getNonDefaultPortfolioScenarios(portfolioId);
console.log(data)
return (
<div className="container mx-auto px-4">
<h1 className="text-3xl text-gray-700 font-bold my-4">Summary</h1>

View file

@ -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;

View file

@ -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(
<p className="text-xl text-gray-700">{propertyMeta.postcode}</p>
</div>
<div className="col-span-12 justify-center bg-gray-50 py-2 rounded-md">
<Toolbar propertyId={propertyId} portfolioId={portfolioId} />
<Toolbar propertyId={propertyId} portfolioId={portfolioId} conditionReport={conditionReport}/>
</div>
{propertyMeta.detailsEpc.estimated && <EstimatedDataNotification />}
{children}

View file

@ -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<FundingPackageWith
return data;
}
export async function getDocument(
{uprn, documentType}: {uprn: string; documentType: typeof DB_REPORT_TYPES[number]}
): Promise<getUploadedFile> {
// 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<EnergyAssessment> {