diff --git a/src/app/components/portfolio/summary/SummaryTable.tsx b/src/app/components/portfolio/summary/SummaryTable.tsx
index 8d35eb6..dc25f39 100644
--- a/src/app/components/portfolio/summary/SummaryTable.tsx
+++ b/src/app/components/portfolio/summary/SummaryTable.tsx
@@ -17,13 +17,12 @@ import {
} from "@/app/shadcn_components/ui/table";
import SelectComparisonModal from "./SelectComparisonModal";
import EpcBarChart from "./EpcBarChart";
+import { DataItem, ChartData } from "@/app/portfolio/[slug]/utils";
const SummaryTable = ({
- portfolioName,
data,
userPortfolios,
}: {
- portfolioName: string;
data: DataItem[];
userPortfolios: { name: string; id: bigint }[];
}) => {
diff --git a/src/app/portfolio/[slug]/(portfolio)/summary/page.tsx b/src/app/portfolio/[slug]/(portfolio)/summary/page.tsx
index 1d4512e..42384f8 100644
--- a/src/app/portfolio/[slug]/(portfolio)/summary/page.tsx
+++ b/src/app/portfolio/[slug]/(portfolio)/summary/page.tsx
@@ -7,7 +7,7 @@ export default async function PortfolioSummary({
params: { slug: string };
}) {
const portfolioId = params.slug;
- const { portfolioName, data } = await getOverviewPortfolioData(portfolioId);
+ const data = await getOverviewPortfolioData(portfolioId);
// Retrieve all of the names and ids of the portfolios, attributed to this user
// Get user id from the session
@@ -16,11 +16,7 @@ export default async function PortfolioSummary({
return (
Overview
-
+
);
}
diff --git a/src/app/portfolio/[slug]/utils.ts b/src/app/portfolio/[slug]/utils.ts
index 2d84c7e..5f539ee 100644
--- a/src/app/portfolio/[slug]/utils.ts
+++ b/src/app/portfolio/[slug]/utils.ts
@@ -1,3 +1,4 @@
+import { formatNumber } from "@/app/utils";
import {
recommendation,
UnnestedRecommendation,
@@ -30,7 +31,7 @@ export async function getPortfolio(portfolioId: string): Promise {
}
// Types needed for the overview page
-interface ChartData {
+export interface ChartData {
name: string;
[key: string]: number | string; // Allows for any number of properties with numeric values, plus the name
}
@@ -47,7 +48,7 @@ export interface DataItem {
export async function getOverviewPortfolioData(
portfolioId: string
-): Promise<{ portfolioName: string; data: DataItem[] }> {
+): Promise {
// Keep just the columns we need for the overview
const data = await db
@@ -86,7 +87,7 @@ export async function getOverviewPortfolioData(
const portfolioName = data[0].name;
// Format the data we need for the overview
- const output = [
+ const output: DataItem[] = [
{
title: "EPCs",
scenarios: [
@@ -107,7 +108,10 @@ export async function getOverviewPortfolioData(
{
title: "# Units",
scenarios: [
- { scenarioName: "Today", data: data[0].numberOfProperties },
+ {
+ scenarioName: "Today",
+ data: String(data[0].numberOfProperties) || "",
+ },
{ scenarioName: portfolioName, data: "" },
],
},
@@ -115,23 +119,32 @@ export async function getOverviewPortfolioData(
title: "# Units to retrofit",
scenarios: [
{ scenarioName: "Today", data: "" },
- { scenarioName: portfolioName, data: data[0].nUnitsToRetrofit },
+ {
+ scenarioName: portfolioName,
+ data: String(data[0].nUnitsToRetrofit) || "",
+ },
],
},
{
title: "Co2/unit",
scenarios: [
- { scenarioName: "Today", data: data[0].co2PerUnitPreRetrofit },
- { scenarioName: portfolioName, data: data[0].co2PerUnitPostRetrofit },
+ { scenarioName: "Today", data: data[0].co2PerUnitPreRetrofit || "" },
+ {
+ scenarioName: portfolioName,
+ data: data[0].co2PerUnitPostRetrofit || "",
+ },
],
},
{
title: "Energy bills/unit",
scenarios: [
- { scenarioName: "Today", data: data[0].energyBillPerUnitPreRetrofit },
+ {
+ scenarioName: "Today",
+ data: data[0].energyBillPerUnitPreRetrofit || "",
+ },
{
scenarioName: portfolioName,
- data: data[0].energyBillPerUnitPostRetrofit,
+ data: data[0].energyBillPerUnitPostRetrofit || "",
},
],
},
@@ -140,11 +153,11 @@ export async function getOverviewPortfolioData(
scenarios: [
{
scenarioName: "Today",
- data: data[0].energyConsumptionPerUnitPreRetrofit,
+ data: data[0].energyConsumptionPerUnitPreRetrofit || "",
},
{
scenarioName: portfolioName,
- data: data[0].energyConsumptionPerUnitPostRetrofit,
+ data: data[0].energyConsumptionPerUnitPostRetrofit || "",
},
],
},
@@ -152,28 +165,28 @@ export async function getOverviewPortfolioData(
title: "Cost (£)",
scenarios: [
{ scenarioName: "Today", data: "" },
- { scenarioName: portfolioName, data: data[0].cost },
+ { scenarioName: portfolioName, data: formatNumber(data[0].cost || 0) },
],
},
{
title: "Cost (£) /unit",
scenarios: [
{ scenarioName: "Today", data: "" },
- { scenarioName: portfolioName, data: data[0].costPerUnit },
+ { scenarioName: portfolioName, data: data[0].costPerUnit || "" },
],
},
{
title: "£ per CO2 reduction",
scenarios: [
{ scenarioName: "Today", data: "" },
- { scenarioName: portfolioName, data: data[0].costPerCo2Saved },
+ { scenarioName: portfolioName, data: data[0].costPerCo2Saved || "" },
],
},
{
title: "£ per SAP point",
scenarios: [
{ scenarioName: "Today", data: "" },
- { scenarioName: portfolioName, data: data[0].costPerSapPoint },
+ { scenarioName: portfolioName, data: data[0].costPerSapPoint || "" },
],
},
{
@@ -182,7 +195,7 @@ export async function getOverviewPortfolioData(
{ scenarioName: "Today", data: "" },
{
scenarioName: portfolioName,
- data: data[0].valuationImprovementPerUnit,
+ data: data[0].valuationImprovementPerUnit || "",
},
],
},
@@ -192,16 +205,13 @@ export async function getOverviewPortfolioData(
{ scenarioName: "Today", data: "" },
{
scenarioName: portfolioName,
- data: data[0].valuationReturnOnInvestment,
+ data: data[0].valuationReturnOnInvestment || "",
},
],
},
- ] as DataItem[];
+ ];
- return {
- portfolioName: portfolioName,
- data: output,
- };
+ return output;
}
export async function getUserPortfolios(