Formatting portfolio page

This commit is contained in:
Khalim Conn-Kowlessar 2023-11-28 14:54:33 +00:00
parent bcab685acb
commit aabff33b82
5 changed files with 1424 additions and 12 deletions

View file

@ -0,0 +1,2 @@
ALTER TABLE "portfolio" ADD COLUMN "labour_days" real;--> statement-breakpoint
ALTER TABLE "recommendation" ADD COLUMN "labour_days" real;

File diff suppressed because it is too large Load diff

View file

@ -193,6 +193,7 @@ export type PropertyDetailsEpc = InferModel<
// This type is used for the getProperties function in src/app/portfolio/[slug]/utils.ts
export interface PropertyToRecommendation {
estimatedCost?: number | null;
sapPoints?: number | null;
}
export interface PropertyWithRelations {
@ -205,4 +206,6 @@ export interface PropertyWithRelations {
target: { epc?: string | null; heatDemand?: number | null };
recommendations: PropertyToRecommendation[];
cost?: number | null;
currentEpcRating: string | null;
currentSapPoints: number | null;
}

View file

@ -14,7 +14,7 @@ import { ArrowUpDown, MoreHorizontal } from "lucide-react";
import StatusBadge from "@/app/components/StatusBadge";
import { HomeIcon } from "@heroicons/react/20/solid";
import { FunnelIcon } from "@heroicons/react/24/outline";
import { formatNumber } from "@/app/utils";
import { formatNumber, sapToEpc } from "@/app/utils";
import { cn } from "@/lib/utils";
import { PortfolioStatus } from "@/app/db/schema/portfolio";
import {
@ -123,6 +123,49 @@ export const columns: ColumnDef<PropertyWithRelations>[] = [
);
},
},
{
accessorKey: "currentEpc",
header: () => <div className="flex justify-center">Current EPC Rating</div>,
cell: ({ row }) => {
return (
<div className="text-gray-700 font-medium flex justify-center">
{row.original.currentEpcRating || ""}
</div>
);
},
},
{
accessorKey: "targetEpc",
header: () => <div className="flex justify-center">Expected EPC</div>,
cell: ({ row }) => {
const recommendations = row.original.recommendations;
const currentSapPoints = row.original.currentSapPoints;
const expectedapPoints = recommendations.reduce(
(acc: number, rec: PropertyToRecommendation) => {
if (rec.sapPoints === null || rec.sapPoints === undefined) {
return acc;
}
return acc + rec.sapPoints;
},
0
);
if (currentSapPoints === null || currentSapPoints === undefined) {
return (
<div className="text-gray-700 font-medium flex justify-center">
{""}
</div>
);
}
const expectedEpc = sapToEpc(currentSapPoints + expectedapPoints);
return (
<div className="text-gray-700 font-medium flex justify-center">
{expectedEpc || ""}
</div>
);
},
},
{
accessorKey: "cost",
header: () => <div className="flex justify-center">Cost</div>,
@ -153,17 +196,6 @@ export const columns: ColumnDef<PropertyWithRelations>[] = [
);
},
},
{
accessorKey: "targetEpc",
header: () => <div className="flex justify-center">Target EPC</div>,
cell: ({ row }) => {
return (
<div className="text-gray-700 font-medium flex justify-center">
{row.original.target?.epc || ""}
</div>
);
},
},
{
id: "actions",
cell: ({ row }) => {

View file

@ -44,6 +44,8 @@ export async function getProperties(
postcode: true,
status: true,
creationStatus: true,
currentEpcRating: true,
currentSapPoints: true,
},
where: eq(property.portfolioId, BigInt(portfolioId)),
with: {
@ -55,6 +57,7 @@ export async function getProperties(
recommendations: {
columns: {
estimatedCost: true,
sapPoints: true,
},
where: eq(recommendation.default, true),
},