From bb240658fbb9000c847227ab0815405184b35ecc Mon Sep 17 00:00:00 2001 From: Rick Falkvinge Date: Thu, 9 Apr 2026 11:03:35 +0200 Subject: [PATCH] Align tree grid header/footer padding + add initialExpanded prop - Header and footer rows now use same CELL_PX padding as data rows, fixing horizontal misalignment of column values - New initialExpanded prop: 'roots' (default), 'all', 'none', or Set for specific node IDs Made-with: Cursor --- frontend/src/components/AccountTreeGrid.tsx | 29 ++++++++++++++++----- 1 file changed, 22 insertions(+), 7 deletions(-) diff --git a/frontend/src/components/AccountTreeGrid.tsx b/frontend/src/components/AccountTreeGrid.tsx index 03982238..22479cae 100644 --- a/frontend/src/components/AccountTreeGrid.tsx +++ b/frontend/src/components/AccountTreeGrid.tsx @@ -19,6 +19,8 @@ export interface AccountTreeGridProps { title?: string onDownloadCsv?: () => void reverseSign?: boolean + /** Which nodes start expanded. 'roots' (default) = top-level only, 'all' = everything, 'none' = all collapsed, or a Set of node IDs */ + initialExpanded?: 'roots' | 'all' | 'none' | Set } interface BuiltNode { @@ -86,14 +88,26 @@ function formatValue(cents: number, reverseSign: boolean): string { export default function AccountTreeGrid({ nodes, columnHeaders, title, onDownloadCsv, reverseSign = false, + initialExpanded = 'roots', }: AccountTreeGridProps) { const colCount = columnHeaders.length const tree = useMemo(() => buildTree(nodes, colCount), [nodes, colCount]) const [expanded, setExpanded] = useState>(() => { - const initial = new Set() - for (const root of tree) if (!root.isLeaf) initial.add(root.id) - return initial + if (initialExpanded instanceof Set) return new Set(initialExpanded) + if (initialExpanded === 'none') return new Set() + + const result = new Set() + function collect(nodes: BuiltNode[], depth: number) { + for (const n of nodes) { + if (!n.isLeaf) { + if (initialExpanded === 'all' || depth === 0) result.add(n.id) + if (initialExpanded === 'all') collect(n.children, depth + 1) + } + } + } + collect(tree, 0) + return result }) const toggleExpand = useCallback((id: number) => { @@ -159,9 +173,9 @@ export default function AccountTreeGrid({ - Account + Account {columnHeaders.map((h, i) => ( - {h} + {h} ))} @@ -199,9 +213,10 @@ export default function AccountTreeGrid({ })} - Total + Total {totals.map((val, i) => ( -