-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
194 additions
and
73 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
141 changes: 99 additions & 42 deletions
141
client/src/containers/overview/table/view/key-costs/columns.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,42 +1,99 @@ | ||
// import { createColumnHelper } from "@tanstack/react-table"; | ||
|
||
// const columnHelper = createColumnHelper<{ | ||
// // ! these types should be part of the Project entity eventually, we are adding them here to silent TS for now | ||
// // implementationLabor: number; | ||
// // communityBenefitSharingFund: number; | ||
// // monitoringAndMaintenance: number; | ||
// // communityRepresentationLiaison: number; | ||
// // conservationPlanningAndAdmin: number; | ||
// // carbonStandardFees: number; | ||
// }>(); | ||
|
||
export const TABLE_COLUMNS = [ | ||
// columnHelper.accessor("projectName", { | ||
// enableSorting: true, | ||
// header: () => <span>Project Name</span>, | ||
// }), | ||
// columnHelper.accessor("implementationLabor", { | ||
// enableSorting: true, | ||
// header: () => <span>Implementation labor</span>, | ||
// }), | ||
// columnHelper.accessor("communityBenefitSharingFund", { | ||
// enableSorting: true, | ||
// header: () => <span>Community benefit sharing fund</span>, | ||
// }), | ||
// columnHelper.accessor("monitoringAndMaintenance", { | ||
// enableSorting: true, | ||
// header: () => <span>Monitoring and maintenance</span>, | ||
// }), | ||
// columnHelper.accessor("communityRepresentationLiaison", { | ||
// enableSorting: true, | ||
// header: () => <span>Community representation/liaison</span>, | ||
// }), | ||
// columnHelper.accessor("conservationPlanningAndAdmin", { | ||
// enableSorting: true, | ||
// header: () => <span>Conservation planning and admin</span>, | ||
// }), | ||
// columnHelper.accessor("carbonStandardFees", { | ||
// enableSorting: true, | ||
// header: () => <span>Carbon standard fees</span>, | ||
// }), | ||
]; | ||
import { ProjectKeyCosts } from "@shared/dtos/projects/project-key-costs.dto"; | ||
import { CellContext, createColumnHelper } from "@tanstack/react-table"; | ||
import { z } from "zod"; | ||
|
||
import { formatCurrency } from "@/lib/format"; | ||
|
||
import { filtersSchema } from "@/app/(overview)/url-store"; | ||
|
||
import { HeaderText, CellText } from "@/containers/overview/table/utils"; | ||
import { KEY_COSTS_LABELS } from "@/containers/overview/table/view/key-costs/constants"; | ||
|
||
const columnHelper = createColumnHelper<ProjectKeyCosts>(); | ||
|
||
const renderHeader = (label: string) => { | ||
return function render() { | ||
return <HeaderText>{label}</HeaderText>; | ||
}; | ||
}; | ||
|
||
const renderCell = (props: CellContext<ProjectKeyCosts, number>) => { | ||
const value = props.getValue(); | ||
if (value === null || value === undefined) { | ||
return "-"; | ||
} | ||
return <CellText>{formatCurrency(value)}</CellText>; | ||
}; | ||
|
||
export const columns = (filters: z.infer<typeof filtersSchema>) => { | ||
const isNPV = filters.costRangeSelector === "npv"; | ||
const implementationLaborAccessor = isNPV | ||
? "implementationLaborNPV" | ||
: "implementationLabor"; | ||
|
||
const communityBenefitAccessor = isNPV | ||
? "communityBenefitNPV" | ||
: "communityBenefit"; | ||
|
||
const monitoringMaintenanceAccessor = isNPV | ||
? "monitoringMaintenanceNPV" | ||
: "monitoringMaintenance"; | ||
|
||
const communityRepresentationAccessor = isNPV | ||
? "communityRepresentationNPV" | ||
: "communityRepresentation"; | ||
|
||
const conservationPlanningAccessor = isNPV | ||
? "conservationPlanningNPV" | ||
: "conservationPlanning"; | ||
|
||
const longTermProjectOperatingAccessor = isNPV | ||
? "longTermProjectOperatingNPV" | ||
: "longTermProjectOperating"; | ||
|
||
const carbonStandardFeesAccessor = isNPV | ||
? "carbonStandardFeesNPV" | ||
: "carbonStandardFees"; | ||
|
||
return [ | ||
columnHelper.accessor("projectName", { | ||
enableSorting: true, | ||
header: renderHeader("Project Name"), | ||
}), | ||
columnHelper.accessor(implementationLaborAccessor, { | ||
enableSorting: true, | ||
header: renderHeader(KEY_COSTS_LABELS[implementationLaborAccessor]), | ||
cell: renderCell, | ||
}), | ||
columnHelper.accessor(communityBenefitAccessor, { | ||
enableSorting: true, | ||
header: renderHeader(KEY_COSTS_LABELS[communityBenefitAccessor]), | ||
cell: renderCell, | ||
}), | ||
columnHelper.accessor(monitoringMaintenanceAccessor, { | ||
enableSorting: true, | ||
header: renderHeader(KEY_COSTS_LABELS[monitoringMaintenanceAccessor]), | ||
cell: renderCell, | ||
}), | ||
columnHelper.accessor(communityRepresentationAccessor, { | ||
enableSorting: true, | ||
header: renderHeader(KEY_COSTS_LABELS[communityRepresentationAccessor]), | ||
cell: renderCell, | ||
}), | ||
columnHelper.accessor(conservationPlanningAccessor, { | ||
enableSorting: true, | ||
header: renderHeader(KEY_COSTS_LABELS[conservationPlanningAccessor]), | ||
cell: renderCell, | ||
}), | ||
columnHelper.accessor(longTermProjectOperatingAccessor, { | ||
enableSorting: true, | ||
header: renderHeader(KEY_COSTS_LABELS[longTermProjectOperatingAccessor]), | ||
cell: renderCell, | ||
}), | ||
columnHelper.accessor(carbonStandardFeesAccessor, { | ||
enableSorting: true, | ||
header: renderHeader(KEY_COSTS_LABELS[carbonStandardFeesAccessor]), | ||
cell: renderCell, | ||
}), | ||
]; | ||
}; |
21 changes: 21 additions & 0 deletions
21
client/src/containers/overview/table/view/key-costs/constants.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { PROJECT_KEY_COSTS_FIELDS } from "@shared/dtos/projects/project-key-costs.dto"; | ||
|
||
export const KEY_COSTS_LABELS: Omit< | ||
Record<(typeof PROJECT_KEY_COSTS_FIELDS)[number], string>, | ||
"id" | "projectName" | ||
> = { | ||
implementationLabor: "Implementation Labor", | ||
implementationLaborNPV: "Implementation Labor", | ||
communityBenefit: "Community benefit sharing fund", | ||
communityBenefitNPV: "Community benefit sharing fund", | ||
monitoringMaintenance: "Monitoring and Maintenance", | ||
monitoringMaintenanceNPV: "Monitoring and Maintenance", | ||
communityRepresentation: "Community representation/liaison", | ||
communityRepresentationNPV: "Community representation/liaison", | ||
conservationPlanning: "Conservation planning and admin", | ||
conservationPlanningNPV: "Conservation planning and admin", | ||
longTermProjectOperating: "Long-term project operating", | ||
longTermProjectOperatingNPV: "Long-term project operating", | ||
carbonStandardFees: "Carbon standard fees", | ||
carbonStandardFeesNPV: "Carbon standard fees", | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters