From 4622c9229b6bc57e2266cb5c422bb30611fa3b6a Mon Sep 17 00:00:00 2001 From: Khalim Conn-Kowlessar Date: Mon, 20 Nov 2023 15:15:38 +0000 Subject: [PATCH] formatting frontend for new recommendations --- .../building-passport/RecommendationCard.tsx | 2 ++ .../RecommendationContainer.tsx | 19 +++++++++---- .../RecommendationCostSummaryCard.tsx | 4 ++- src/app/db/schema/recommendations.ts | 6 ++++- .../[propertyId]/plans/page.tsx | 27 ++++++++++++------- .../building-passport/[propertyId]/utils.ts | 3 ++- src/types/recommendations.ts | 4 +-- 7 files changed, 45 insertions(+), 20 deletions(-) diff --git a/src/app/components/building-passport/RecommendationCard.tsx b/src/app/components/building-passport/RecommendationCard.tsx index a2b5148..f4a9ff8 100644 --- a/src/app/components/building-passport/RecommendationCard.tsx +++ b/src/app/components/building-passport/RecommendationCard.tsx @@ -16,6 +16,8 @@ const noSelectionStyling = const TitleMap = { wall_insulation: "Wall Insulation", floor_insulation: "Floor Insulation", + roof_insulation: "Roof Insulation", + mechanical_ventilation: "Mechanical Ventilation", }; export default function RecommendationCard({ diff --git a/src/app/components/building-passport/RecommendationContainer.tsx b/src/app/components/building-passport/RecommendationContainer.tsx index 9780819..9cfd74c 100644 --- a/src/app/components/building-passport/RecommendationContainer.tsx +++ b/src/app/components/building-passport/RecommendationContainer.tsx @@ -43,20 +43,29 @@ export default function RecommendationContainer({ (rec: Recommendation) => rec.default ) || { estimatedCost: 0, sapPoints: 0 }; - // const defaultVentiliationRecommendations = recommendations.Ventilation?.find( - // (rec: ComponentRecommendation) => rec.default - // ) || { estimatedCost: 0, sapPoints: 0 }; + const defaultRoofRecommendations = + categorizedRecommendations.roof_insulation?.find( + (rec: Recommendation) => rec.default + ) || { estimatedCost: 0, sapPoints: 0 }; + + const defaultVentiliationRecommendations = + categorizedRecommendations.mechanical_ventilation?.find( + (rec: Recommendation) => rec.default + ) || { estimatedCost: 0, sapPoints: 0 }; const [costMap, setCostMap] = useState({ wall_insulation: defaultWallsRecommendations?.estimatedCost || 0, floor_insulation: defaultFloorRecommendations?.estimatedCost || 0, - // Ventilation: defaultVentiliationRecommendations?.estimatedCost || 0, + roof_insulation: defaultRoofRecommendations?.estimatedCost || 0, + mechanical_ventilation: + defaultVentiliationRecommendations?.estimatedCost || 0, }); const [sapMap, setSapMap] = useState({ wall_insulation: defaultWallsRecommendations?.sapPoints || 0, floor_insulation: defaultFloorRecommendations.sapPoints || 0, - // Ventilation: defaultVentiliationRecommendations.sapPoints, + roof_insulation: defaultRoofRecommendations.sapPoints || 0, + mechanical_ventilation: defaultVentiliationRecommendations.sapPoints || 0, }); const [totalEstimatedCost, setTotalEstimatedCost] = useState( diff --git a/src/app/components/building-passport/RecommendationCostSummaryCard.tsx b/src/app/components/building-passport/RecommendationCostSummaryCard.tsx index 2d98e9b..1d8d67f 100644 --- a/src/app/components/building-passport/RecommendationCostSummaryCard.tsx +++ b/src/app/components/building-passport/RecommendationCostSummaryCard.tsx @@ -20,7 +20,9 @@ export default function RecommendationCostSummaryCard({ Total SAP Points Improvement: - {totalSapPoints} + + {Math.round((totalSapPoints + Number.EPSILON) * 100) / 100} + diff --git a/src/app/db/schema/recommendations.ts b/src/app/db/schema/recommendations.ts index 38f70fb..34765ac 100644 --- a/src/app/db/schema/recommendations.ts +++ b/src/app/db/schema/recommendations.ts @@ -144,7 +144,11 @@ export type PlanRecommendations = InferModel< // We allow recommendation types to be a string however we'll set up a typing for it here to control // the types we expect -export type RecommendationType = "wall_insulation" | "floor_insulation"; +export type RecommendationType = + | "wall_insulation" + | "floor_insulation" + | "roof_insulation" + | "mechanical_ventilation"; export type UnnestedRecommendation = { quantity: number; diff --git a/src/app/portfolio/[slug]/building-passport/[propertyId]/plans/page.tsx b/src/app/portfolio/[slug]/building-passport/[propertyId]/plans/page.tsx index 8545804..8f3c8a9 100644 --- a/src/app/portfolio/[slug]/building-passport/[propertyId]/plans/page.tsx +++ b/src/app/portfolio/[slug]/building-passport/[propertyId]/plans/page.tsx @@ -10,12 +10,14 @@ function PlanCard({ totalEstimatedCost, totalSapPoints, planId, + isDefault, }: { expectedEpcRating: string; createdAt: Date; totalEstimatedCost: number; totalSapPoints: number; planId: string; + isDefault: boolean; }) { return ( @@ -23,7 +25,7 @@ function PlanCard({
@@ -35,7 +37,9 @@ function PlanCard({
Total SAP points: - {totalSapPoints} + + {Math.round((totalSapPoints + Number.EPSILON) * 100) / 100} +
@@ -92,14 +96,17 @@ export default async function RecommendationPlans({ const expectedEpcRating = sapToEpc(expectedSapPoints); return ( - +
+ +
); })} diff --git a/src/app/portfolio/[slug]/building-passport/[propertyId]/utils.ts b/src/app/portfolio/[slug]/building-passport/[propertyId]/utils.ts index ba1ec03..3bbe470 100644 --- a/src/app/portfolio/[slug]/building-passport/[propertyId]/utils.ts +++ b/src/app/portfolio/[slug]/building-passport/[propertyId]/utils.ts @@ -13,7 +13,7 @@ import { } from "@/app/db/schema/property"; import { plan, Plan } from "@/app/db/schema/recommendations"; import { getRating } from "@/app/utils"; -import { eq } from "drizzle-orm"; +import { eq, desc } from "drizzle-orm"; type RecommendationList = { recommendation: Recommendation; @@ -53,6 +53,7 @@ type PlanRelation = Plan & { export async function getPlans(propertyId: string): Promise { const data = await db.query.plan.findMany({ where: eq(plan.propertyId, BigInt(propertyId)), + orderBy: [desc(plan.createdAt)], with: { planRecommendations: { columns: {}, diff --git a/src/types/recommendations.ts b/src/types/recommendations.ts index f6db317..ab9865b 100644 --- a/src/types/recommendations.ts +++ b/src/types/recommendations.ts @@ -1,6 +1,6 @@ export interface RecommendationMetricMap { wall_insulation: number; floor_insulation: number; - // TODO: Implement ventilation - // Ventilation: number; + roof_insulation: number; + mechanical_ventilation: number; }