diff --git a/client/src/containers/projects/custom-project/annual-project-cash-flow/table/columns.tsx b/client/src/containers/projects/custom-project/annual-project-cash-flow/table/columns.tsx index 358b309f..ddf98742 100644 --- a/client/src/containers/projects/custom-project/annual-project-cash-flow/table/columns.tsx +++ b/client/src/containers/projects/custom-project/annual-project-cash-flow/table/columns.tsx @@ -3,6 +3,8 @@ import { createColumnHelper } from "@tanstack/react-table"; import { formatCurrency } from "@/lib/format"; +import { cashflowConfig } from "@/containers/projects/custom-project/annual-project-cash-flow/utils"; + interface CostValues { [key: string]: number; } @@ -15,40 +17,13 @@ interface TableRow { } const columnHelper = createColumnHelper(); -const cashflowCostNameMap: Record = { - financingCost: "Financing cost", - monitoring: "Monitoring", - maintenance: "Maintenance", - communityBenefitSharingFund: "Community benefit sharing fund", - carbonStandardFees: "Carbon standard fees", - baselineReassessment: "Baseline reassessment", - mrv: "MRV", - longTermProjectOperatingCost: "Long-term project operating", - feasibilityAnalysis: "Feasibility analysis", - conservationPlanningAndAdmin: "Conservation planning and admin", - dataCollectionAndFieldCost: "Data collection and field costs", - communityRepresentation: "Community representation", - blueCarbonProjectPlanning: "Blue carbon project planning", - establishingCarbonRights: "Establishing carbon rights", - validation: "Validation", - implementationLabor: "Implementation labor", - opexTotalCostPlan: "Total OpEx", - capexTotalCostPlan: "Total CapEx", - totalCostPlan: "Total Cost", - estimatedRevenuePlan: "Est. revenue", - creditsIssuedPlan: "Est. Credit issued", - cumulativeNetIncomePlan: "Revenue OpEx", - cumulativeNetIncomeCapexOpex: "Revenue CapEx + OpEx", - annualNetCashFlow: "Annual net cash flow", - annualNetIncome: "Revenue Opex", -}; export const columns = (years: number[]) => [ columnHelper.accessor("costName", { header: () => Project, cell: (info) => ( - {cashflowCostNameMap[info.getValue() as YearlyBreakdownCostName]} + {cashflowConfig[info.getValue() as YearlyBreakdownCostName].label} ), }), diff --git a/client/src/containers/projects/custom-project/annual-project-cash-flow/table/index.tsx b/client/src/containers/projects/custom-project/annual-project-cash-flow/table/index.tsx index da1e867c..4867e6b0 100644 --- a/client/src/containers/projects/custom-project/annual-project-cash-flow/table/index.tsx +++ b/client/src/containers/projects/custom-project/annual-project-cash-flow/table/index.tsx @@ -72,7 +72,18 @@ const CashFlowTable: FC = ({ data }) => { {table.getRowModel().rows?.length ? ( table.getRowModel().rows.map((row) => ( - + {row.getVisibleCells().map((cell) => ( = { + feasibilityAnalysis: { + order: 0, + label: "Feasibility analysis", + }, + conservationPlanningAndAdmin: { + order: 1, + label: "Conservation planning and admin", + }, + dataCollectionAndFieldCost: { + order: 3, + label: "Data collection and field costs", + }, + communityRepresentation: { + order: 4, + label: "Community representation", + }, + blueCarbonProjectPlanning: { + order: 5, + label: "Blue carbon project planning", + }, + establishingCarbonRights: { + order: 6, + label: "Establishing carbon rights", + }, + validation: { + order: 7, + label: "Validation", + }, + implementationLabor: { + order: 8, + label: "Implementation labor", + }, + capexTotalCostPlan: { + order: 9, + label: "Total CapEx", + }, + monitoring: { + order: 10, + label: "Monitoring", + }, + maintenance: { + order: 11, + label: "Maintenance", + }, + communityBenefitSharingFund: { + order: 12, + label: "Community benefit sharing fund", + }, + carbonStandardFees: { + order: 13, + label: "Carbon standard fees", + }, + baselineReassessment: { + order: 14, + label: "Baseline reassessment", + }, + mrv: { + order: 15, + label: "MRV", + }, + longTermProjectOperatingCost: { + order: 16, + label: "Long-term project operating", + }, + opexTotalCostPlan: { + order: 17, + label: "Total OpEx", + }, + totalCostPlan: { + order: 18, + label: "Total Cost", + }, + creditsIssuedPlan: { + order: 19, + label: "Est. credits issued", + }, + estimatedRevenuePlan: { + order: 20, + label: "Est. revenue", + }, + financingCost: { + order: 21, + label: "Financing cost", + }, + cumulativeNetIncomePlan: { + order: 22, + label: "Revenue OpEx", + }, + cumulativeNetIncomeCapexOpex: { + order: 23, + label: "Revenue CapEx + OpEx", + }, + annualNetIncome: { + order: 24, + label: "Revenue Opex", + }, + annualNetCashFlow: { + order: 25, + label: "Annual net cash flow", + }, +}; + +function parseYearlyBreakdownForTable( + data: YearlyBreakdown[], +): YearlyBreakdown[] { + return [...data].sort((a, b) => { + const orderA = cashflowConfig[a.costName].order; + const orderB = cashflowConfig[b.costName].order; + return orderA - orderB; + }); +} export { getBreakdownYears, parseYearlyBreakdownForChart, + parseYearlyBreakdownForTable, + cashflowConfig, type YearlyBreakdownChartData, }; diff --git a/client/src/containers/projects/custom-project/index.tsx b/client/src/containers/projects/custom-project/index.tsx index 069fcd62..64d05167 100644 --- a/client/src/containers/projects/custom-project/index.tsx +++ b/client/src/containers/projects/custom-project/index.tsx @@ -13,6 +13,7 @@ import AnnualProjectCashFlow from "@/containers/projects/custom-project/annual-p import { getBreakdownYears, parseYearlyBreakdownForChart, + parseYearlyBreakdownForTable, } from "@/containers/projects/custom-project/annual-project-cash-flow/utils"; import ProjectCost from "@/containers/projects/custom-project/cost"; import CostDetails from "@/containers/projects/custom-project/cost-details"; @@ -60,6 +61,10 @@ const CustomProject: FC = ({ data }) => { ), [output.yearlyBreakdown], ); + const tableData = useMemo( + () => parseYearlyBreakdownForTable(output.yearlyBreakdown), + [output.yearlyBreakdown], + ); return ( = ({ data }) => { - + ); diff --git a/shared/dtos/custom-projects/custom-project-output.dto.ts b/shared/dtos/custom-projects/custom-project-output.dto.ts index ebb1b889..4ca1cae5 100644 --- a/shared/dtos/custom-projects/custom-project-output.dto.ts +++ b/shared/dtos/custom-projects/custom-project-output.dto.ts @@ -42,20 +42,20 @@ export type CustomProjectCostDetails = { longTermProjectOperatingCost: number; }; -export type OutputCostNames = keyof [ - "opexTotalCostPlan", - "capexTotalCostPlan", - "totalCostPlan", - "estimatedRevenuePlan", - "creditsIssuedPlan", - "cumulativeNetIncomePlan", - "cumulativeNetIncomeCapexOpex", - "annualNetCashFlow", - "annualNetIncome", -]; +export type OutputCostNames = + | "opexTotalCostPlan" + | "capexTotalCostPlan" + | "totalCostPlan" + | "estimatedRevenuePlan" + | "creditsIssuedPlan" + | "cumulativeNetIncomePlan" + | "cumulativeNetIncomeCapexOpex" + | "annualNetCashFlow" + | "annualNetIncome"; -export type YearlyBreakdownCostName = keyof OverridableCostInputs & - OutputCostNames; +export type YearlyBreakdownCostName = + | keyof InstanceType + | OutputCostNames; export type YearlyBreakdown = { costName: YearlyBreakdownCostName;