diff options
| author | Joe Carstairs <me@joeac.net> | 2024-10-22 07:46:43 +0100 |
|---|---|---|
| committer | Joe Carstairs <me@joeac.net> | 2024-10-22 07:46:43 +0100 |
| commit | 5824c353f978a5b9ab9696451ee3014c6a614ffc (patch) | |
| tree | bc39754ca417e84eb00b0aa9a1ae2330da0bf282 /gui/src/components/histogram | |
| parent | 7adaace61a4fe983eba5ded3aaaf624ce6fb9014 (diff) | |
Refactors importer to use core stuff
Diffstat (limited to 'gui/src/components/histogram')
| -rw-r--r-- | gui/src/components/histogram/Histogram.tsx | 32 |
1 files changed, 24 insertions, 8 deletions
diff --git a/gui/src/components/histogram/Histogram.tsx b/gui/src/components/histogram/Histogram.tsx index 3a8309b..1dd8c65 100644 --- a/gui/src/components/histogram/Histogram.tsx +++ b/gui/src/components/histogram/Histogram.tsx @@ -1,5 +1,7 @@ import { BalanceToBudgetRatio } from "../../types/balanceToBudgetRatio"; import { Category } from "../../types/category"; +import { Group } from "../../types/group"; +import { groupCategories } from "../../util/groupCategories"; import './Histogram.scss'; function Histogram({ categories }: Props) { @@ -14,6 +16,8 @@ function Histogram({ categories }: Props) { category.balanceToBudgetRatio = balanceToBudgetRatioNormaliser(category.balanceToBudgetRatio); } + const groups = [...groupCategories(categories)]; + return ( <table> <thead> @@ -23,18 +27,26 @@ function Histogram({ categories }: Props) { <th>Balance</th> </tr> </thead> - - <tbody> - { - categories - .sort((c1, c2) => BalanceToBudgetRatio.compare(c1.balanceToBudgetRatio, c2.balanceToBudgetRatio)) - .map((category) => Row({ category })) - } - </tbody> + { + groups.map(g => <RowGroup group={g} />) + } </table> ); } +function RowGroup({ group }: GroupProps) { + return ( + <tbody> + <tr role="heading" aria-level="3">{group.name}</tr> + { + group.categories + .sort((c1, c2) => BalanceToBudgetRatio.compare(c1.balanceToBudgetRatio, c2.balanceToBudgetRatio)) + .map((category) => Row({ category })) + } + </tbody> + ); +} + function Row({ category }: RowProps) { return ( <tr> @@ -57,6 +69,10 @@ type Props = { categories: Category[] | null, }; +type GroupProps = { + group: Group; +} + type RowProps = { category: Category, }; |
