From 42faccf1cb65786a3b6b1e76db7b12a120a14ff5 Mon Sep 17 00:00:00 2001 From: carkom Date: Thu, 7 Dec 2023 11:06:07 +0000 Subject: [PATCH 1/7] work --- .../src/components/common/Block.tsx | 3 + .../components/reports/CategorySelector.tsx | 17 +- .../src/components/reports/ChooseGraph.tsx | 106 ++++++-- .../src/components/reports/ColumnPrimary.tsx | 67 +++++ .../components/reports/ColumnScrollbar.tsx | 56 ++++ .../src/components/reports/ModeButton.tsx | 39 +++ .../src/components/reports/ReportLegend.tsx | 71 +++++ .../src/components/reports/ReportSidebar.js | 213 +++++++-------- .../src/components/reports/ReportSummary.js | 197 -------------- .../src/components/reports/ReportSummary.tsx | 140 ++++++++++ .../src/components/reports/ReportTable.tsx | 131 +++++++++- .../components/reports/ReportTableHeader.tsx | 52 ++-- .../components/reports/ReportTableInner.tsx | 108 ++++++++ .../components/reports/ReportTableList.tsx | 243 ------------------ .../src/components/reports/ReportTableRow.tsx | 123 +++++++++ .../components/reports/ReportTableTotals.tsx | 81 ++++-- .../src/components/reports/TableRowIndex.tsx | 41 +++ .../src/components/reports/entities.d.ts | 41 +++ .../components/reports/graphs/DonutGraph.tsx | 9 +- .../reports/reports/CustomReport.js | 102 ++++---- 20 files changed, 1164 insertions(+), 676 deletions(-) create mode 100644 packages/desktop-client/src/components/reports/ColumnPrimary.tsx create mode 100644 packages/desktop-client/src/components/reports/ColumnScrollbar.tsx create mode 100644 packages/desktop-client/src/components/reports/ModeButton.tsx create mode 100644 packages/desktop-client/src/components/reports/ReportLegend.tsx delete mode 100644 packages/desktop-client/src/components/reports/ReportSummary.js create mode 100644 packages/desktop-client/src/components/reports/ReportSummary.tsx create mode 100644 packages/desktop-client/src/components/reports/ReportTableInner.tsx delete mode 100644 packages/desktop-client/src/components/reports/ReportTableList.tsx create mode 100644 packages/desktop-client/src/components/reports/ReportTableRow.tsx create mode 100644 packages/desktop-client/src/components/reports/TableRowIndex.tsx create mode 100644 packages/desktop-client/src/components/reports/entities.d.ts diff --git a/packages/desktop-client/src/components/common/Block.tsx b/packages/desktop-client/src/components/common/Block.tsx index 4a4db9b9686..38b99615043 100644 --- a/packages/desktop-client/src/components/common/Block.tsx +++ b/packages/desktop-client/src/components/common/Block.tsx @@ -2,8 +2,11 @@ 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 6c75ba288a5..c098715798b 100644 --- a/packages/desktop-client/src/components/reports/CategorySelector.tsx +++ b/packages/desktop-client/src/components/reports/CategorySelector.tsx @@ -50,8 +50,19 @@ export default function CategorySelector({ return ( - - + ); +} + +export default ModeButton; diff --git a/packages/desktop-client/src/components/reports/ReportLegend.tsx b/packages/desktop-client/src/components/reports/ReportLegend.tsx new file mode 100644 index 00000000000..7db528cfe63 --- /dev/null +++ b/packages/desktop-client/src/components/reports/ReportLegend.tsx @@ -0,0 +1,71 @@ +import React from 'react'; + +import { theme, styles } from '../../style'; +import Text from '../common/Text'; +import View from '../common/View'; + +type ReportLegendProps = { + data?; + legend; + groupBy: string; +}; + +function ReportLegend({ data, legend, groupBy }: ReportLegendProps) { + return ( + + + {groupBy} + + + {legend.map(item => { + return ( + + + + {item.name} + + + ); + })} + + + ); +} + +export default ReportLegend; diff --git a/packages/desktop-client/src/components/reports/ReportSidebar.js b/packages/desktop-client/src/components/reports/ReportSidebar.js index 5f22d0a13c7..65f147b9f4c 100644 --- a/packages/desktop-client/src/components/reports/ReportSidebar.js +++ b/packages/desktop-client/src/components/reports/ReportSidebar.js @@ -3,7 +3,6 @@ import React from 'react'; import * as monthUtils from 'loot-core/src/shared/months'; import { theme } from '../../style'; -import Button from '../common/Button'; import Select from '../common/Select'; import Text from '../common/Text'; import View from '../common/View'; @@ -17,37 +16,12 @@ import { getFullRange, validateRange, } from './Header'; +import ModeButton from './ModeButton'; import { ReportOptions } from './ReportOptions'; -function ModeButton({ selected, children, style, onSelect }) { - return ( - - ); -} - export function ReportSidebar({ - start, - end, + startDate, + endDate, onChangeDates, dateRange, setDateRange, @@ -64,12 +38,14 @@ export function ReportSidebar({ setBalanceType, mode, setMode, - empty, - setEmpty, - hidden, - setHidden, - uncat, - setUncat, + datePaused, + setDatePaused, + showEmpty, + setShowEmpty, + showOffBudgetHidden, + setShowOffBudgetHidden, + showUncategorized, + setShowUncategorized, categories, selectedCategories, setSelectedCategories, @@ -106,6 +82,15 @@ export function ReportSidebar({ } }; + const onChangeDatePaused = cond => { + setDatePaused(cond); + if (cond === 'live') { + onSelectRange(dateRange); + } else { + onChangeDates(startDate, endDate); + } + }; + const onChangeMode = cond => { setMode(cond); if (cond === 'time') { @@ -114,7 +99,7 @@ export function ReportSidebar({ } else { setTypeDisabled(['Net']); if (['Net'].includes(balanceType)) { - setBalanceType('Expense'); + setBalanceType('Payment'); } } if (graphType === 'BarGraph') { @@ -144,7 +129,7 @@ export function ReportSidebar({ } } if (['Net'].includes(balanceType) && graphType !== 'TableGraph') { - setBalanceType('Expense'); + setBalanceType('Payment'); } }; @@ -274,9 +259,9 @@ export function ReportSidebar({ setEmpty(!empty)} + checked={showEmpty} + value={showEmpty} + onChange={() => setShowEmpty(!showEmpty)} /> + ); } diff --git a/packages/desktop-client/src/components/reports/ReportTableTotals.tsx b/packages/desktop-client/src/components/reports/ReportTableTotals.tsx index a40780abe62..e82cccfbfac 100644 --- a/packages/desktop-client/src/components/reports/ReportTableTotals.tsx +++ b/packages/desktop-client/src/components/reports/ReportTableTotals.tsx @@ -52,7 +52,6 @@ function ReportTableTotals({ collapsed={true} height={32 + scrollWidthTotals} style={{ - overflowX: 'auto', borderTopWidth: 1, borderColor: theme.tableBorder, justifyContent: 'center', From 4cff28833ac8a7ee3da7b5374a87010d4229c2c5 Mon Sep 17 00:00:00 2001 From: carkom Date: Wed, 13 Dec 2023 14:16:00 +0000 Subject: [PATCH 4/7] 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], From 130ad0f0fad00ddbecd6ce8998495e60b31b56b6 Mon Sep 17 00:00:00 2001 From: carkom Date: Wed, 13 Dec 2023 17:51:53 +0000 Subject: [PATCH 5/7] 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; From 8179f85b4574153f09453d9675448fc5d1d86b17 Mon Sep 17 00:00:00 2001 From: carkom Date: Wed, 13 Dec 2023 17:55:50 +0000 Subject: [PATCH 6/7] notes --- upcoming-release-notes/2080.md | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 upcoming-release-notes/2080.md diff --git a/upcoming-release-notes/2080.md b/upcoming-release-notes/2080.md new file mode 100644 index 00000000000..c43aa923abc --- /dev/null +++ b/upcoming-release-notes/2080.md @@ -0,0 +1,6 @@ +--- +category: Enhancements +authors: [carkom] +--- + +Add live/static choice for date filters. From 14472c85bbae720c9b452186416d9a9d65156d6d Mon Sep 17 00:00:00 2001 From: carkom Date: Fri, 15 Dec 2023 10:26:27 +0000 Subject: [PATCH 7/7] updae names and improve flow --- .../src/components/reports/ReportSidebar.js | 31 +++++++++---------- .../reports/reports/CustomReport.js | 6 ++-- 2 files changed, 17 insertions(+), 20 deletions(-) diff --git a/packages/desktop-client/src/components/reports/ReportSidebar.js b/packages/desktop-client/src/components/reports/ReportSidebar.js index 65f147b9f4c..347f3184f61 100644 --- a/packages/desktop-client/src/components/reports/ReportSidebar.js +++ b/packages/desktop-client/src/components/reports/ReportSidebar.js @@ -38,8 +38,8 @@ export function ReportSidebar({ setBalanceType, mode, setMode, - datePaused, - setDatePaused, + isDateStatic, + setIsDateStatic, showEmpty, setShowEmpty, showOffBudgetHidden, @@ -51,6 +51,7 @@ export function ReportSidebar({ setSelectedCategories, }) { const onSelectRange = cond => { + setDateRange(cond); switch (cond) { case 'All time': onChangeDates(...getFullRange(allMonths)); @@ -82,15 +83,6 @@ export function ReportSidebar({ } }; - const onChangeDatePaused = cond => { - setDatePaused(cond); - if (cond === 'live') { - onSelectRange(dateRange); - } else { - onChangeDates(startDate, endDate); - } - }; - const onChangeMode = cond => { setMode(cond); if (cond === 'time') { @@ -338,19 +330,25 @@ export function ReportSidebar({ onChangeDatePaused('live')} + selected={!isDateStatic} + onSelect={() => { + setIsDateStatic(false); + onSelectRange(dateRange); + }} > Live onChangeDatePaused('static')} + selected={isDateStatic} + onSelect={() => { + setIsDateStatic(true); + onChangeDates(startDate, endDate); + }} > Static - {datePaused === 'live' ? ( + {!isDateStatic ? ( { - setDateRange(e); onSelectRange(e); }} options={ReportOptions.dateRange.map(option => [ diff --git a/packages/desktop-client/src/components/reports/reports/CustomReport.js b/packages/desktop-client/src/components/reports/reports/CustomReport.js index 0f6c555fc6c..01103a48532 100644 --- a/packages/desktop-client/src/components/reports/reports/CustomReport.js +++ b/packages/desktop-client/src/components/reports/reports/CustomReport.js @@ -51,7 +51,7 @@ export default function CustomReport() { const [endDate, setEndDate] = useState(monthUtils.currentMonth()); const [mode, setMode] = useState('total'); - const [datePaused, setDatePaused] = useState('live'); + const [isDateStatic, setIsDateStatic] = useState(false); const [groupBy, setGroupBy] = useState('Category'); const [balanceType, setBalanceType] = useState('Payment'); const [showEmpty, setShowEmpty] = useState(false); @@ -212,8 +212,8 @@ export default function CustomReport() { setBalanceType={setBalanceType} mode={mode} setMode={setMode} - datePaused={datePaused} - setDatePaused={setDatePaused} + isDateStatic={isDateStatic} + setIsDateStatic={setIsDateStatic} showEmpty={showEmpty} setShowEmpty={setShowEmpty} showOffBudgetHidden={showOffBudgetHidden}