From 4cff28833ac8a7ee3da7b5374a87010d4229c2c5 Mon Sep 17 00:00:00 2001 From: carkom Date: Wed, 13 Dec 2023 14:16:00 +0000 Subject: [PATCH] update table layout --- .../src/components/reports/ChooseGraph.tsx | 18 +- .../src/components/reports/ColumnPrimary.tsx | 67 ------- .../components/reports/ColumnScrollbar.tsx | 56 ------ .../src/components/reports/ReportTable.tsx | 73 ++++--- .../reports/ReportTableColumTotals.tsx | 102 ++++++++++ .../reports/ReportTableColumnIndex.tsx | 81 ++++++++ .../components/reports/ReportTableHeader.tsx | 108 +++++------ .../components/reports/ReportTableInner.tsx | 89 ++++----- .../src/components/reports/ReportTableRow.tsx | 112 +++-------- .../components/reports/ReportTableTotals.tsx | 179 ++++++++++-------- .../src/components/reports/TableRowIndex.tsx | 41 ---- .../spreadsheets/default-spreadsheet.tsx | 4 +- .../spreadsheets/grouped-spreadsheet.ts | 4 +- 13 files changed, 459 insertions(+), 475 deletions(-) delete mode 100644 packages/desktop-client/src/components/reports/ColumnPrimary.tsx delete mode 100644 packages/desktop-client/src/components/reports/ColumnScrollbar.tsx create mode 100644 packages/desktop-client/src/components/reports/ReportTableColumTotals.tsx create mode 100644 packages/desktop-client/src/components/reports/ReportTableColumnIndex.tsx delete mode 100644 packages/desktop-client/src/components/reports/TableRowIndex.tsx diff --git a/packages/desktop-client/src/components/reports/ChooseGraph.tsx b/packages/desktop-client/src/components/reports/ChooseGraph.tsx index 12401ff91df..dcbc2c2cd48 100644 --- a/packages/desktop-client/src/components/reports/ChooseGraph.tsx +++ b/packages/desktop-client/src/components/reports/ChooseGraph.tsx @@ -65,18 +65,26 @@ function ChooseGraph({ listScrollRef.current.scrollLeft = scroll.target.scrollLeft; } if (scroll.target.id === 'list') { - if (headerScrollRef.current.scrollLeft !== scroll.target.scrollLeft) { - headerScrollRef.current.scrollLeft = scroll.target.scrollLeft; - totalScrollRef.current.scrollLeft = scroll.target.scrollLeft; - } else { + if (indexScrollRef.current.scrollTop !== scroll.target.scrollTop) { indexScrollRef.current.scrollTop = scroll.target.scrollTop; scrollScrollRef.current.scrollTop = scroll.target.scrollTop; + } else { + if (headerScrollRef.current) { + headerScrollRef.current.scrollLeft = scroll.target.scrollLeft; + } + if (totalScrollRef.current) { + totalScrollRef.current.scrollLeft = scroll.target.scrollLeft; + } } } if (scroll.target.id === 'index') { listScrollRef.current.scrollTop = scroll.target.scrollTop; scrollScrollRef.current.scrollTop = scroll.target.scrollTop; } + if (scroll.target.id === 'scroll') { + listScrollRef.current.scrollTop = scroll.target.scrollTop; + indexScrollRef.current.scrollTop = scroll.target.scrollTop; + } }; if (graphType === 'AreaGraph') { @@ -123,7 +131,7 @@ function ChooseGraph({ - - {item.categories && ( - <> - - {item.categories - .filter(i => - !showEmpty - ? balanceTypeOp === 'totalTotals' - ? i.totalAssets !== 0 || - i.totalDebts !== 0 || - i.totalTotals !== 0 - : i[balanceTypeOp] !== 0 - : true, - ) - .map(cat => { - return ( - - ); - })} - - - - )} - - ); -} - -export default ColumnPrimary; diff --git a/packages/desktop-client/src/components/reports/ColumnScrollbar.tsx b/packages/desktop-client/src/components/reports/ColumnScrollbar.tsx deleted file mode 100644 index b5b867b3d18..00000000000 --- a/packages/desktop-client/src/components/reports/ColumnScrollbar.tsx +++ /dev/null @@ -1,56 +0,0 @@ -import React from 'react'; - -import { theme } from '../../style'; -import View from '../common/View'; -import { Row } from '../table'; - -import { type GroupedEntity } from './entities'; -import TableRowIndex from './TableRowIndex'; - -type ColumnScrollbarProps = { - item: GroupedEntity; - balanceTypeOp: string; - showEmpty: boolean; -}; - -function ColumnScrollbar({ - item, - balanceTypeOp, - showEmpty, -}: ColumnScrollbarProps) { - return ( - <> - - {item.categories && ( - <> - - {item.categories - .filter(i => - !showEmpty - ? balanceTypeOp === 'totalTotals' - ? i.totalAssets !== 0 || - i.totalDebts !== 0 || - i.totalTotals !== 0 - : i[balanceTypeOp] !== 0 - : true, - ) - .map(cat => { - return ; - })} - - - - )} - - ); -} - -export default ColumnScrollbar; diff --git a/packages/desktop-client/src/components/reports/ReportTable.tsx b/packages/desktop-client/src/components/reports/ReportTable.tsx index 29df35c0343..76ec40cb690 100644 --- a/packages/desktop-client/src/components/reports/ReportTable.tsx +++ b/packages/desktop-client/src/components/reports/ReportTable.tsx @@ -5,13 +5,13 @@ import React, { } from 'react'; import { type RefProp } from 'react-spring'; -import { type CSSProperties } from '../../style'; +import { theme, type CSSProperties } from '../../style'; import Block from '../common/Block'; import View from '../common/View'; -import ColumnPrimary from './ColumnPrimary'; -import ColumnScrollbar from './ColumnScrollbar'; import { type GroupedEntity } from './entities'; +import ReportTableColumnIndex from './ReportTableColumnIndex'; +import ReportTableColumnTotals from './ReportTableColumTotals'; import ReportTableInner from './ReportTableInner'; import ReportTableRow from './ReportTableRow'; @@ -48,22 +48,25 @@ export default function ReportTable({ useLayoutEffect(() => { if (scrollScrollRef.current && saveScrollWidth) { - saveScrollWidth( - scrollScrollRef.current ? scrollScrollRef.current.offsetWidth : 0, - ); + const [parent, child] = [ + scrollScrollRef.current.offsetWidth, + scrollScrollRef.current.clientWidth, + ]; + + saveScrollWidth(parent > 0 && child > 0 && parent - child); } }); - const renderItem = useCallback( - ({ item, groupByItem, mode, monthsCount, style, key }) => { + const renderItemTotal = useCallback( + ({ item, groupByItem, monthsCount, style, key }) => { return ( - ); @@ -71,13 +74,22 @@ export default function ReportTable({ [], ); + const renderItem = useCallback(({ item, groupByItem, mode, style, key }) => { + return ( + + ); + }, []); + return ( {data.map(item => { return ( - ); })} - {data.map(item => { - return ( - - ); - })} + ); diff --git a/packages/desktop-client/src/components/reports/ReportTableColumTotals.tsx b/packages/desktop-client/src/components/reports/ReportTableColumTotals.tsx new file mode 100644 index 00000000000..bb1e108833a --- /dev/null +++ b/packages/desktop-client/src/components/reports/ReportTableColumTotals.tsx @@ -0,0 +1,102 @@ +import React, { memo } from 'react'; + +import { + amountToCurrency, + amountToInteger, + integerToCurrency, +} from 'loot-core/src/shared/util'; + +import { styles, theme } from '../../style'; +import { Row, Cell } from '../table'; + +import { type GroupedEntity } from './entities'; + +type ReportTableColumnTotalsProps = { + item: GroupedEntity; + balanceTypeOp?: string; + groupByItem: string; + monthsCount: number; + mode: string; + style?: object; +}; + +const ReportTableColumnTotals = memo( + ({ + item, + balanceTypeOp, + groupByItem, + monthsCount, + mode, + style, + }: ReportTableColumnTotalsProps) => { + const average = amountToInteger(item[balanceTypeOp]) / monthsCount; + return ( + + {balanceTypeOp === 'totalTotals' && ( + <> + 100000 && + amountToCurrency(item.totalAssets) + } + width="flex" + style={{ + width: 85, + ...styles.tnum, + }} + /> + 100000 && + amountToCurrency(item.totalDebts) + } + width="flex" + style={{ + width: 85, + ...styles.tnum, + }} + /> + + )} + 100000 && + amountToCurrency(item[balanceTypeOp]) + } + style={{ + fontWeight: 600, + width: 85, + ...styles.tnum, + }} + privacyFilter + /> + 100000 && + integerToCurrency(Math.round(average)) + } + style={{ + fontWeight: 600, + width: 85, + ...styles.tnum, + }} + privacyFilter + /> + + ); + }, +); + +export default ReportTableColumnTotals; diff --git a/packages/desktop-client/src/components/reports/ReportTableColumnIndex.tsx b/packages/desktop-client/src/components/reports/ReportTableColumnIndex.tsx new file mode 100644 index 00000000000..be1e32d6c8f --- /dev/null +++ b/packages/desktop-client/src/components/reports/ReportTableColumnIndex.tsx @@ -0,0 +1,81 @@ +import React from 'react'; + +import { type CSSProperties, styles, theme } from '../../style'; +import View from '../common/View'; +import { Row, Cell } from '../table'; + +import { type GroupedEntity } from './entities'; + +type ReportTableColumnIndexProps = { + item?: GroupedEntity; + groupByItem?: string; + headerStyle?: CSSProperties; +}; + +function ReportTableColumnIndex({ + item, + groupByItem, + headerStyle, +}: ReportTableColumnIndexProps) { + return ( + <> + + {item ? ( + 12 && item[groupByItem]} + style={{ + minWidth: 125, + ...styles.tnum, + }} + /> + ) : ( + + )} + + {item.categories && ( + <> + + {item.categories.map(cat => { + return ( + + {cat ? ( + 12 && cat[groupByItem]} + style={{ + minWidth: 125, + ...styles.tnum, + }} + /> + ) : ( + + )} + + ); + })} + + + + )} + + ); +} + +export default ReportTableColumnIndex; diff --git a/packages/desktop-client/src/components/reports/ReportTableHeader.tsx b/packages/desktop-client/src/components/reports/ReportTableHeader.tsx index cf5377f0c90..20503097de4 100644 --- a/packages/desktop-client/src/components/reports/ReportTableHeader.tsx +++ b/packages/desktop-client/src/components/reports/ReportTableHeader.tsx @@ -1,18 +1,16 @@ import React, { type UIEventHandler } from 'react'; import { type RefProp } from 'react-spring'; -import * as d from 'date-fns'; - import { styles, theme } from '../../style'; import View from '../common/View'; import { Row, Cell } from '../table'; -import { type Month } from './entities'; +import { type GroupedEntity } from './entities'; type ReportTableHeaderProps = { scrollWidth?: number; groupBy: string; - interval?: Month[]; + interval?: GroupedEntity[]; balanceType: string; headerScrollRef: RefProp; handleScroll: UIEventHandler; @@ -29,11 +27,7 @@ function ReportTableHeader({ return ( + {interval ? ( + + {interval.map((header, index) => { + return ( + + ); + })} + + ) : ( + + )} - {interval - ? interval.map((header, index) => { - return ( - - ); - }) - : balanceType === 'Net' && ( - <> - - - - )} + {balanceType === 'Net' && ( + <> + + + + )} {scrollWidth > 0 && } diff --git a/packages/desktop-client/src/components/reports/ReportTableInner.tsx b/packages/desktop-client/src/components/reports/ReportTableInner.tsx index 4297e2a15ca..fb2454e53ca 100644 --- a/packages/desktop-client/src/components/reports/ReportTableInner.tsx +++ b/packages/desktop-client/src/components/reports/ReportTableInner.tsx @@ -2,25 +2,21 @@ import React from 'react'; import { type CSSProperties, theme } from '../../style'; import View from '../common/View'; -import { Row } from '../table'; +import { Cell, Row } from '../table'; import { type GroupedEntity } from './entities'; type ReportTableInnerProps = { data: GroupedEntity[]; - balanceTypeOp?: string; - mode: string; - monthsCount: number; - showEmpty: boolean; + mode?: string; + monthsCount?: number; groupBy: string; renderItem; }; function ReportTableInner({ data, - showEmpty, monthsCount, - balanceTypeOp, mode, groupBy, renderItem, @@ -29,17 +25,16 @@ function ReportTableInner({ type RenderRowProps = { key: string; - row; index: number; parent_index?: number; style?: CSSProperties; }; - function RenderRow({ row, index, parent_index, style, key }: RenderRowProps) { + function RenderRow({ index, parent_index, style, key }: RenderRowProps) { let item; - if (row.categories) { - item = data[index]; - } else { + if (parent_index != null) { item = data[parent_index].categories[index]; + } else { + item = data[index]; } const rendered_row = renderItem({ @@ -58,47 +53,41 @@ function ReportTableInner({ {data.map((item, index) => { return ( - <> - - {item.categories && ( + + {data ? ( <> - - {item.categories - .filter(i => - !showEmpty - ? balanceTypeOp === 'totalTotals' - ? i.totalAssets !== 0 || - i.totalDebts !== 0 || - i.totalTotals !== 0 - : i[balanceTypeOp] !== 0 - : true, - ) - .map((category, i) => { - return ( - - ); - })} - - + + {item.categories && ( + <> + + {item.categories.map((category, i) => { + return ( + + ); + })} + + + + )} + ) : ( + )} - + ); })} diff --git a/packages/desktop-client/src/components/reports/ReportTableRow.tsx b/packages/desktop-client/src/components/reports/ReportTableRow.tsx index ba91ee2775b..942a92db25f 100644 --- a/packages/desktop-client/src/components/reports/ReportTableRow.tsx +++ b/packages/desktop-client/src/components/reports/ReportTableRow.tsx @@ -1,10 +1,6 @@ import React, { memo } from 'react'; -import { - amountToCurrency, - amountToInteger, - integerToCurrency, -} from 'loot-core/src/shared/util'; +import { amountToCurrency } from 'loot-core/src/shared/util'; import { styles, theme } from '../../style'; import { Row, Cell } from '../table'; @@ -16,20 +12,11 @@ type ReportTableRowProps = { balanceTypeOp?: string; groupByItem: string; mode: string; - monthsCount: number; style?: object; }; const ReportTableRow = memo( - ({ - item, - balanceTypeOp, - groupByItem, - mode, - monthsCount, - style, - }: ReportTableRowProps) => { - const average = amountToInteger(item[balanceTypeOp]) / monthsCount; + ({ item, balanceTypeOp, groupByItem, mode, style }: ReportTableRowProps) => { return ( - {item.monthData && mode === 'time' - ? item.monthData.map(month => { - return ( - 100000 && - amountToCurrency(month[balanceTypeOp]) - } - width="flex" - privacyFilter - /> - ); - }) - : balanceTypeOp === 'totalTotals' && ( - <> - 100000 && - amountToCurrency(item.totalAssets) - } - width="flex" - style={{ - minWidth: 85, - ...styles.tnum, - }} - /> - 100000 && - amountToCurrency(item.totalDebts) - } - width="flex" - style={{ - minWidth: 85, - ...styles.tnum, - }} - /> - - )} - 100000 && - amountToCurrency(item[balanceTypeOp]) - } - style={{ - fontWeight: 600, - minWidth: 85, - ...styles.tnum, - }} - width="flex" - privacyFilter - /> - 100000 && - integerToCurrency(Math.round(average)) - } - style={{ - fontWeight: 600, - minWidth: 85, - ...styles.tnum, - }} - width="flex" - privacyFilter - /> + {item.monthData && + mode === 'time' && + item.monthData.map(month => { + return ( + 100000 && + amountToCurrency(month[balanceTypeOp]) + } + width="flex" + privacyFilter + /> + ); + })} ); }, diff --git a/packages/desktop-client/src/components/reports/ReportTableTotals.tsx b/packages/desktop-client/src/components/reports/ReportTableTotals.tsx index e82cccfbfac..cac42a1b3da 100644 --- a/packages/desktop-client/src/components/reports/ReportTableTotals.tsx +++ b/packages/desktop-client/src/components/reports/ReportTableTotals.tsx @@ -81,91 +81,114 @@ function ReportTableTotals({ /> )} + {mode === 'time' ? ( + + {data.monthData.map(item => { + return ( + 100000 && + amountToCurrency(item[balanceTypeOp]) + } + width="flex" + privacyFilter + /> + ); + })} + + ) : ( + + )} - {mode === 'time' - ? data.monthData.map(item => { - return ( - 100000 && - amountToCurrency(item[balanceTypeOp]) - } - width="flex" - privacyFilter - /> - ); - }) - : balanceTypeOp === 'totalTotals' && ( - <> - 100000 && - amountToCurrency(data.totalAssets) - } - width="flex" - /> - 100000 && - amountToCurrency(data.totalDebts) - } - width="flex" - /> - - )} - 100000 && - amountToCurrency(data[balanceTypeOp]) - } - width="flex" - privacyFilter - /> - 100000 && - integerToCurrency(Math.round(average)) - } - width="flex" - privacyFilter - /> + > + {balanceTypeOp === 'totalTotals' && ( + <> + 100000 && + amountToCurrency(data.totalAssets) + } + /> + 100000 && + amountToCurrency(data.totalDebts) + } + /> + + )} + 100000 && + amountToCurrency(data[balanceTypeOp]) + } + privacyFilter + /> + 100000 && + integerToCurrency(Math.round(average)) + } + privacyFilter + /> - {scrollWidth > 0 && } + {scrollWidth > 0 && } + + {scrollWidthTotals > 0 && ( + + )} ); diff --git a/packages/desktop-client/src/components/reports/TableRowIndex.tsx b/packages/desktop-client/src/components/reports/TableRowIndex.tsx deleted file mode 100644 index 333f5ed36cb..00000000000 --- a/packages/desktop-client/src/components/reports/TableRowIndex.tsx +++ /dev/null @@ -1,41 +0,0 @@ -import React from 'react'; - -import { type CSSProperties, styles, theme } from '../../style'; -import { Row, Cell } from '../table'; - -import { type GroupedEntity } from './entities'; - -type TableRowIndexProps = { - item?: GroupedEntity; - groupByItem?: string; - style?: CSSProperties; -}; - -const TableRowIndex = ({ item, groupByItem, style }: TableRowIndexProps) => { - return ( - - {item ? ( - 12 && item[groupByItem]} - style={{ - minWidth: 125, - ...styles.tnum, - }} - /> - ) : ( - - )} - - ); -}; - -export default TableRowIndex; diff --git a/packages/desktop-client/src/components/reports/spreadsheets/default-spreadsheet.tsx b/packages/desktop-client/src/components/reports/spreadsheets/default-spreadsheet.tsx index 4d17270d4c5..23fcf52c931 100644 --- a/packages/desktop-client/src/components/reports/spreadsheets/default-spreadsheet.tsx +++ b/packages/desktop-client/src/components/reports/spreadsheets/default-spreadsheet.tsx @@ -170,9 +170,7 @@ export default function createSpreadsheet({ setData({ data: calcData.filter(i => (!showEmpty ? i[balanceTypeOp] !== 0 : true)), - monthData: monthData.filter(i => - !showEmpty ? i[balanceTypeOp] !== 0 : true, - ), + monthData, startDate, endDate, totalDebts: integerToAmount(totalDebts), diff --git a/packages/desktop-client/src/components/reports/spreadsheets/grouped-spreadsheet.ts b/packages/desktop-client/src/components/reports/spreadsheets/grouped-spreadsheet.ts index c0199b5a79c..49e7bd82e53 100644 --- a/packages/desktop-client/src/components/reports/spreadsheets/grouped-spreadsheet.ts +++ b/packages/desktop-client/src/components/reports/spreadsheets/grouped-spreadsheet.ts @@ -134,7 +134,9 @@ function createGroupedSpreadsheet({ totalDebts: integerToAmount(totalDebts), totalTotals: integerToAmount(totalAssets + totalDebts), monthData, - categories: stackedCategories, + categories: stackedCategories.filter(i => + !showEmpty ? i[balanceTypeOp] !== 0 : true, + ), }; }, [startDate, endDate],