From 130ad0f0fad00ddbecd6ce8998495e60b31b56b6 Mon Sep 17 00:00:00 2001 From: carkom Date: Wed, 13 Dec 2023 17:51:53 +0000 Subject: [PATCH] revert changes --- .../src/components/common/Block.tsx | 3 - .../components/reports/CategorySelector.tsx | 1 - .../src/components/reports/ChooseGraph.tsx | 67 ++--- .../src/components/reports/ReportTable.tsx | 154 ++--------- .../reports/ReportTableColumTotals.tsx | 102 -------- .../reports/ReportTableColumnIndex.tsx | 81 ------ .../components/reports/ReportTableHeader.tsx | 140 +++++----- .../components/reports/ReportTableInner.tsx | 97 ------- .../components/reports/ReportTableList.tsx | 243 ++++++++++++++++++ .../src/components/reports/ReportTableRow.tsx | 55 ---- .../components/reports/ReportTableTotals.tsx | 232 +++++++---------- .../src/components/reports/entities.d.ts | 13 +- 12 files changed, 436 insertions(+), 752 deletions(-) delete mode 100644 packages/desktop-client/src/components/reports/ReportTableColumTotals.tsx delete mode 100644 packages/desktop-client/src/components/reports/ReportTableColumnIndex.tsx delete mode 100644 packages/desktop-client/src/components/reports/ReportTableInner.tsx create mode 100644 packages/desktop-client/src/components/reports/ReportTableList.tsx delete mode 100644 packages/desktop-client/src/components/reports/ReportTableRow.tsx diff --git a/packages/desktop-client/src/components/common/Block.tsx b/packages/desktop-client/src/components/common/Block.tsx index 38b99615043..4a4db9b9686 100644 --- a/packages/desktop-client/src/components/common/Block.tsx +++ b/packages/desktop-client/src/components/common/Block.tsx @@ -2,11 +2,8 @@ import { type HTMLProps, type Ref } from 'react'; import { css } from 'glamor'; -import { type CSSProperties } from '../../style'; - type BlockProps = HTMLProps & { innerRef?: Ref; - style?: CSSProperties; }; export default function Block(props: BlockProps) { diff --git a/packages/desktop-client/src/components/reports/CategorySelector.tsx b/packages/desktop-client/src/components/reports/CategorySelector.tsx index c098715798b..d83825eedb4 100644 --- a/packages/desktop-client/src/components/reports/CategorySelector.tsx +++ b/packages/desktop-client/src/components/reports/CategorySelector.tsx @@ -225,7 +225,6 @@ export default function CategorySelector({ ); })} - ); } diff --git a/packages/desktop-client/src/components/reports/ChooseGraph.tsx b/packages/desktop-client/src/components/reports/ChooseGraph.tsx index dcbc2c2cd48..0c8825046ca 100644 --- a/packages/desktop-client/src/components/reports/ChooseGraph.tsx +++ b/packages/desktop-client/src/components/reports/ChooseGraph.tsx @@ -12,6 +12,7 @@ import StackedBarGraph from './graphs/StackedBarGraph'; import { ReportOptions } from './ReportOptions'; import ReportTable from './ReportTable'; import ReportTableHeader from './ReportTableHeader'; +import ReportTableList from './ReportTableList'; import ReportTableTotals from './ReportTableTotals'; type ChooseGraphProps = { @@ -38,12 +39,6 @@ function ChooseGraph({ months, }: ChooseGraphProps) { const balanceTypeOp = ReportOptions.balanceTypeMap.get(balanceType); - const groupByData = - groupBy === 'Category' - ? 'groupedData' - : ['Month', 'Year'].includes(groupBy) - ? 'monthData' - : 'data'; const saveScrollWidth = value => { setScrollWidth(!value ? 0 : value); @@ -52,39 +47,10 @@ function ChooseGraph({ const headerScrollRef = useRef(null); const listScrollRef = useRef(null); const totalScrollRef = useRef(null); - const indexScrollRef = useRef(null); - const scrollScrollRef = useRef(null); - const handleScroll = scroll => { - if (scroll.target.id === 'total') { - headerScrollRef.current.scrollLeft = scroll.target.scrollLeft; - listScrollRef.current.scrollLeft = scroll.target.scrollLeft; - } - if (scroll.target.id === 'header') { - totalScrollRef.current.scrollLeft = scroll.target.scrollLeft; - listScrollRef.current.scrollLeft = scroll.target.scrollLeft; - } - if (scroll.target.id === 'list') { - 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; - } + const handleScrollTotals = scroll => { + headerScrollRef.current.scrollLeft = scroll.target.scrollLeft; + listScrollRef.current.scrollLeft = scroll.target.scrollLeft; }; if (graphType === 'AreaGraph') { @@ -130,8 +96,7 @@ function ChooseGraph({ + > + + void; - listScrollRef: RefProp; - indexScrollRef: RefProp; - scrollScrollRef: RefProp; - handleScroll: UIEventHandler; + saveScrollWidth?: (value: number) => void; + listScrollRef?: RefProp; style?: CSSProperties; - groupBy: string; - balanceTypeOp: string; - showEmpty: boolean; - data: GroupedEntity[]; - mode: string; - monthsCount: number; + children?: ReactNode; }; export default function ReportTable({ saveScrollWidth, listScrollRef, - indexScrollRef, - scrollScrollRef, - handleScroll, style, - groupBy, - balanceTypeOp, - showEmpty, - data, - mode, - monthsCount, + children, }: ReportTableProps) { - const groupByItem = ['Month', 'Year'].includes(groupBy) ? 'date' : 'name'; + const contentRef = useRef(null); useLayoutEffect(() => { - if (scrollScrollRef.current && saveScrollWidth) { - const [parent, child] = [ - scrollScrollRef.current.offsetWidth, - scrollScrollRef.current.clientWidth, - ]; - - saveScrollWidth(parent > 0 && child > 0 && parent - child); + if (contentRef.current && saveScrollWidth) { + saveScrollWidth(contentRef.current ? contentRef.current.offsetWidth : 0); } }); - const renderItemTotal = useCallback( - ({ item, groupByItem, monthsCount, style, key }) => { - return ( - - ); - }, - [], - ); - - const renderItem = useCallback(({ item, groupByItem, mode, style, key }) => { - return ( - - ); - }, []); - return ( - - {data.map(item => { - return ( - - ); - })} - - - - - - - + +
{children}
+
); } diff --git a/packages/desktop-client/src/components/reports/ReportTableColumTotals.tsx b/packages/desktop-client/src/components/reports/ReportTableColumTotals.tsx deleted file mode 100644 index bb1e108833a..00000000000 --- a/packages/desktop-client/src/components/reports/ReportTableColumTotals.tsx +++ /dev/null @@ -1,102 +0,0 @@ -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 deleted file mode 100644 index be1e32d6c8f..00000000000 --- a/packages/desktop-client/src/components/reports/ReportTableColumnIndex.tsx +++ /dev/null @@ -1,81 +0,0 @@ -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 20503097de4..983495d7370 100644 --- a/packages/desktop-client/src/components/reports/ReportTableHeader.tsx +++ b/packages/desktop-client/src/components/reports/ReportTableHeader.tsx @@ -1,119 +1,109 @@ -import React, { type UIEventHandler } from 'react'; -import { type RefProp } from 'react-spring'; +import React, { type Ref } from 'react'; + +import * as d from 'date-fns'; import { styles, theme } from '../../style'; import View from '../common/View'; import { Row, Cell } from '../table'; -import { type GroupedEntity } from './entities'; +import { type Month } from './entities'; type ReportTableHeaderProps = { scrollWidth?: number; groupBy: string; - interval?: GroupedEntity[]; + interval?: Month[]; balanceType: string; - headerScrollRef: RefProp; - handleScroll: UIEventHandler; + headerScrollRef?: Ref; }; -function ReportTableHeader({ +export default function ReportTableHeader({ scrollWidth, groupBy, interval, balanceType, headerScrollRef, - handleScroll, }: ReportTableHeaderProps) { return ( - - - {interval ? ( - + - {interval.map((header, index) => { - return ( - - ); - })} - - ) : ( - - )} - - {balanceType === 'Net' && ( - <> - - - - )} + value={groupBy} + width="flex" + /> + {interval + ? interval.map((header, index) => { + return ( + + ); + }) + : balanceType === 'Net' && ( + <> + + + + )} {scrollWidth > 0 && } - - + +
); } - -export default ReportTableHeader; diff --git a/packages/desktop-client/src/components/reports/ReportTableInner.tsx b/packages/desktop-client/src/components/reports/ReportTableInner.tsx deleted file mode 100644 index fb2454e53ca..00000000000 --- a/packages/desktop-client/src/components/reports/ReportTableInner.tsx +++ /dev/null @@ -1,97 +0,0 @@ -import React from 'react'; - -import { type CSSProperties, theme } from '../../style'; -import View from '../common/View'; -import { Cell, Row } from '../table'; - -import { type GroupedEntity } from './entities'; - -type ReportTableInnerProps = { - data: GroupedEntity[]; - mode?: string; - monthsCount?: number; - groupBy: string; - renderItem; -}; - -function ReportTableInner({ - data, - monthsCount, - mode, - groupBy, - renderItem, -}: ReportTableInnerProps) { - const groupByItem = ['Month', 'Year'].includes(groupBy) ? 'date' : 'name'; - - type RenderRowProps = { - key: string; - index: number; - parent_index?: number; - style?: CSSProperties; - }; - function RenderRow({ index, parent_index, style, key }: RenderRowProps) { - let item; - if (parent_index != null) { - item = data[parent_index].categories[index]; - } else { - item = data[index]; - } - - const rendered_row = renderItem({ - item, - groupByItem, - mode, - monthsCount, - style, - key, - }); - - return rendered_row; - } - - return ( - - {data.map((item, index) => { - return ( - - {data ? ( - <> - - {item.categories && ( - <> - - {item.categories.map((category, i) => { - return ( - - ); - })} - - - - )} - - ) : ( - - )} - - ); - })} - - ); -} - -export default ReportTableInner; diff --git a/packages/desktop-client/src/components/reports/ReportTableList.tsx b/packages/desktop-client/src/components/reports/ReportTableList.tsx new file mode 100644 index 00000000000..ddfdeca2c40 --- /dev/null +++ b/packages/desktop-client/src/components/reports/ReportTableList.tsx @@ -0,0 +1,243 @@ +import React, { memo } from 'react'; + +import { + amountToCurrency, + amountToInteger, + integerToCurrency, +} from 'loot-core/src/shared/util'; + +import { type CSSProperties, styles, theme } from '../../style'; +import View from '../common/View'; +import { Row, Cell } from '../table'; + +type TableRowProps = { + item: { + date: string; + name: string; + monthData: []; + totalAssets: number; + totalDebts: number; + }; + balanceTypeOp?: string; + groupByItem: string; + mode: string; + monthsCount: number; + style?: CSSProperties; +}; + +const TableRow = memo( + ({ + item, + balanceTypeOp, + groupByItem, + mode, + monthsCount, + style, + }: TableRowProps) => { + const average = amountToInteger(item[balanceTypeOp]) / monthsCount; + return ( + + 12 && item[groupByItem]} + style={{ + minWidth: 125, + ...styles.tnum, + }} + /> + {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 + /> + + ); + }, +); + +function GroupedTableRow({ + item, + balanceTypeOp, + groupByItem, + mode, + monthsCount, + empty, +}) { + return ( + <> + + + {item.categories + .filter(i => + !empty + ? balanceTypeOp === 'totalTotals' + ? i.totalAssets !== 0 || + i.totalDebts !== 0 || + i.totalTotals !== 0 + : i[balanceTypeOp] !== 0 + : true, + ) + .map(cat => { + return ( + + ); + })} + + + + ); +} + +export default function ReportTableList({ + data, + empty, + monthsCount, + balanceTypeOp, + mode, + groupBy, +}) { + const groupByItem = ['Month', 'Year'].includes(groupBy) ? 'date' : 'name'; + const groupByData = + groupBy === 'Category' + ? 'groupedData' + : ['Month', 'Year'].includes(groupBy) + ? 'monthData' + : 'data'; + + return ( + + {data[groupByData] + .filter(i => + !empty + ? balanceTypeOp === 'totalTotals' + ? i.totalAssets !== 0 || i.totalDebts !== 0 || i.totalTotals !== 0 + : i[balanceTypeOp] !== 0 + : true, + ) + .map(item => { + if (groupBy === 'Category') { + return ( + + ); + } else { + return ( + + ); + } + })} + + ); +} diff --git a/packages/desktop-client/src/components/reports/ReportTableRow.tsx b/packages/desktop-client/src/components/reports/ReportTableRow.tsx deleted file mode 100644 index 942a92db25f..00000000000 --- a/packages/desktop-client/src/components/reports/ReportTableRow.tsx +++ /dev/null @@ -1,55 +0,0 @@ -import React, { memo } from 'react'; - -import { amountToCurrency } from 'loot-core/src/shared/util'; - -import { styles, theme } from '../../style'; -import { Row, Cell } from '../table'; - -import { type GroupedEntity } from './entities'; - -type ReportTableRowProps = { - item: GroupedEntity; - balanceTypeOp?: string; - groupByItem: string; - mode: string; - style?: object; -}; - -const ReportTableRow = memo( - ({ item, balanceTypeOp, groupByItem, mode, style }: ReportTableRowProps) => { - return ( - - {item.monthData && - mode === 'time' && - item.monthData.map(month => { - return ( - 100000 && - amountToCurrency(month[balanceTypeOp]) - } - width="flex" - privacyFilter - /> - ); - })} - - ); - }, -); - -export default ReportTableRow; diff --git a/packages/desktop-client/src/components/reports/ReportTableTotals.tsx b/packages/desktop-client/src/components/reports/ReportTableTotals.tsx index cac42a1b3da..daf758ac335 100644 --- a/packages/desktop-client/src/components/reports/ReportTableTotals.tsx +++ b/packages/desktop-client/src/components/reports/ReportTableTotals.tsx @@ -1,4 +1,4 @@ -import React, { type UIEventHandler, useLayoutEffect, useState } from 'react'; +import React, { type UIEventHandler } from 'react'; import { type RefProp } from 'react-spring'; import { @@ -20,178 +20,122 @@ type ReportTableTotalsProps = { mode: string; monthsCount: number; totalScrollRef: RefProp; - handleScroll: UIEventHandler; + handleScrollTotals: UIEventHandler; }; -function ReportTableTotals({ +export default function ReportTableTotals({ data, scrollWidth, balanceTypeOp, mode, monthsCount, totalScrollRef, - handleScroll, + handleScrollTotals, }: ReportTableTotalsProps) { - const [scrollWidthTotals, setScrollWidthTotals] = useState(0); - - useLayoutEffect(() => { - if (totalScrollRef.current) { - const [parent, child] = [ - totalScrollRef.current.offsetParent - ? totalScrollRef.current.parentElement.scrollHeight - : 0, - totalScrollRef.current ? totalScrollRef.current.scrollHeight : 0, - ]; - setScrollWidthTotals(parent > 0 && child > 0 && parent - child); - } - }); - const average = amountToInteger(data[balanceTypeOp]) / monthsCount; return ( - - - {scrollWidthTotals > 0 && ( - - )} - - {mode === 'time' ? ( - { + return ( + 100000 && + amountToCurrency(item[balanceTypeOp]) + } + width="flex" + privacyFilter + /> + ); + }) + : balanceTypeOp === 'totalTotals' && ( + <> + 100000 && + amountToCurrency(data.totalAssets) + } + width="flex" + /> + 100000 && + amountToCurrency(data.totalDebts) + } + width="flex" + /> + + )} + - {data.monthData.map(item => { - return ( - 100000 && - amountToCurrency(item[balanceTypeOp]) - } - width="flex" - privacyFilter - /> - ); - })} - - ) : ( - - )} - - 100000 && + amountToCurrency(data[balanceTypeOp]) + } + width="flex" + privacyFilter + /> + - {balanceTypeOp === 'totalTotals' && ( - <> - 100000 && - amountToCurrency(data.totalAssets) - } - /> - 100000 && - amountToCurrency(data.totalDebts) - } - /> - - )} - 100000 && - amountToCurrency(data[balanceTypeOp]) - } - privacyFilter - /> - 100000 && - integerToCurrency(Math.round(average)) - } - privacyFilter - /> + value={integerToCurrency(Math.round(average))} + title={ + Math.abs(Math.round(average / 100)) > 100000 && + integerToCurrency(Math.round(average)) + } + width="flex" + privacyFilter + /> - {scrollWidth > 0 && } - - {scrollWidthTotals > 0 && ( - - )} - - + {scrollWidth > 0 && } + + ); } - -export default ReportTableTotals; diff --git a/packages/desktop-client/src/components/reports/entities.d.ts b/packages/desktop-client/src/components/reports/entities.d.ts index d7b54236bd7..cbd01affb52 100644 --- a/packages/desktop-client/src/components/reports/entities.d.ts +++ b/packages/desktop-client/src/components/reports/entities.d.ts @@ -1,7 +1,7 @@ export type DataEntity = { - data: GroupedEntity[]; - monthData: GroupedEntity[]; - groupedData: GroupedEntity[]; + data: Array; + monthData: Array; + groupedData: Array; startDate: string; endDate: string; totalDebts: number; @@ -25,16 +25,19 @@ type MonthData = { totalTotals: number; }; +/* this will be used in a future PR + export type GroupedEntity = { id: string; name: string; date?: string; - monthData: MonthData[]; - categories?: ItemEntity[]; + monthData: Array; + categories?: Array; totalAssets: number; totalDebts: number; totalTotals: number; }; +*/ export type Month = { month: string;