From edbcaba89bfb0f1d8c39f147b9078224a33ce8c2 Mon Sep 17 00:00:00 2001 From: Neil <55785687+carkom@users.noreply.github.com> Date: Tue, 26 Dec 2023 17:55:41 +0000 Subject: [PATCH] Custom reports header fix (#2085) * tablechanges * notes * trigger rerun * fixes * lint fixes --- .../src/components/reports/ChooseGraph.tsx | 22 ++++++-- .../src/components/reports/ReportTable.tsx | 12 +++- .../components/reports/ReportTableHeader.tsx | 55 +++++++++--------- .../components/reports/ReportTableList.tsx | 4 +- .../components/reports/ReportTableTotals.tsx | 56 ++++++++++++------- .../src/components/reports/entities.d.ts | 9 +-- upcoming-release-notes/2085.md | 6 ++ 7 files changed, 105 insertions(+), 59 deletions(-) create mode 100644 upcoming-release-notes/2085.md diff --git a/packages/desktop-client/src/components/reports/ChooseGraph.tsx b/packages/desktop-client/src/components/reports/ChooseGraph.tsx index 0c8825046ca..66574f564d7 100644 --- a/packages/desktop-client/src/components/reports/ChooseGraph.tsx +++ b/packages/desktop-client/src/components/reports/ChooseGraph.tsx @@ -48,9 +48,19 @@ function ChooseGraph({ const listScrollRef = useRef(null); const totalScrollRef = useRef(null); - const handleScrollTotals = scroll => { - headerScrollRef.current.scrollLeft = scroll.target.scrollLeft; - listScrollRef.current.scrollLeft = scroll.target.scrollLeft; + const handleScroll = scroll => { + if (scroll.target.id === 'header') { + totalScrollRef.current.scrollLeft = scroll.target.scrollLeft; + listScrollRef.current.scrollLeft = scroll.target.scrollLeft; + } + if (scroll.target.id === 'total') { + headerScrollRef.current.scrollLeft = scroll.target.scrollLeft; + listScrollRef.current.scrollLeft = scroll.target.scrollLeft; + } + if (scroll.target.id === 'list') { + headerScrollRef.current.scrollLeft = scroll.target.scrollLeft; + totalScrollRef.current.scrollLeft = scroll.target.scrollLeft; + } }; if (graphType === 'AreaGraph') { @@ -96,7 +106,8 @@ function ChooseGraph({ ; style?: CSSProperties; children?: ReactNode; + handleScroll?: UIEventHandler; }; export default function ReportTable({ @@ -16,6 +22,7 @@ export default function ReportTable({ listScrollRef, style, children, + handleScroll, }: ReportTableProps) { const contentRef = useRef(null); @@ -28,6 +35,8 @@ export default function ReportTable({ return (
{children}
diff --git a/packages/desktop-client/src/components/reports/ReportTableHeader.tsx b/packages/desktop-client/src/components/reports/ReportTableHeader.tsx index 7a1f5be90e5..da1e795258a 100644 --- a/packages/desktop-client/src/components/reports/ReportTableHeader.tsx +++ b/packages/desktop-client/src/components/reports/ReportTableHeader.tsx @@ -1,55 +1,60 @@ -import React, { type Ref } from 'react'; - -import * as d from 'date-fns'; +import React, { type UIEventHandler } from 'react'; +import { type RefProp } from 'react-spring'; import { styles, theme } from '../../style'; import View from '../common/View'; import { Row, Cell } from '../table'; -import { type Month } from './entities'; +import { type MonthData } from './entities'; type ReportTableHeaderProps = { scrollWidth?: number; groupBy: string; - interval?: Month[]; + interval?: MonthData[]; balanceType: string; - headerScrollRef?: Ref; + headerScrollRef: RefProp; + handleScroll?: UIEventHandler; }; -export default function ReportTableHeader({ +function ReportTableHeader({ scrollWidth, groupBy, interval, balanceType, headerScrollRef, + handleScroll, }: ReportTableHeaderProps) { return ( - - {interval ? interval.map((header, index) => { @@ -60,8 +65,7 @@ export default function ReportTableHeader({ ...styles.tnum, }} key={index} - // eslint-disable-next-line rulesdir/typography - value={d.format(d.parseISO(`${header}-01`), "MMM ''yy")} + value={header.date} width="flex" /> ); @@ -102,8 +106,9 @@ export default function ReportTableHeader({ value="Average" width="flex" /> - {scrollWidth > 0 && } - - +
+ ); } + +export default ReportTableHeader; diff --git a/packages/desktop-client/src/components/reports/ReportTableList.tsx b/packages/desktop-client/src/components/reports/ReportTableList.tsx index ddfdeca2c40..40939b0e640 100644 --- a/packages/desktop-client/src/components/reports/ReportTableList.tsx +++ b/packages/desktop-client/src/components/reports/ReportTableList.tsx @@ -47,10 +47,10 @@ const TableRow = memo( > 12 && item[groupByItem]} style={{ - minWidth: 125, + width: 120, + flexShrink: 0, ...styles.tnum, }} /> diff --git a/packages/desktop-client/src/components/reports/ReportTableTotals.tsx b/packages/desktop-client/src/components/reports/ReportTableTotals.tsx index 625ba16f81f..3fa158a03b9 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 } from 'react'; +import React, { type UIEventHandler, useLayoutEffect, useState } from 'react'; import { type RefProp } from 'react-spring'; import { @@ -20,45 +20,63 @@ type ReportTableTotalsProps = { mode: string; monthsCount: number; totalScrollRef: RefProp; - handleScrollTotals: UIEventHandler; + handleScroll: UIEventHandler; }; -export default function ReportTableTotals({ +function ReportTableTotals({ data, scrollWidth, balanceTypeOp, mode, monthsCount, totalScrollRef, - handleScrollTotals, + handleScroll, }: 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 ( - - {mode === 'time' ? data.monthData.map(item => { @@ -133,9 +151,9 @@ export default function ReportTableTotals({ width="flex" privacyFilter /> - - {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 d5869883738..db251812ee7 100644 --- a/packages/desktop-client/src/components/reports/entities.d.ts +++ b/packages/desktop-client/src/components/reports/entities.d.ts @@ -31,19 +31,16 @@ export type MonthData = { totalTotals: number; }; -/* this will be used in a future PR - -export type GroupedEntity = { +type GroupedEntity = { id: string; name: string; date?: string; - monthData: Array; - categories?: Array; + monthData: MonthData[]; + categories?: ItemEntity[]; totalAssets: number; totalDebts: number; totalTotals: number; }; -*/ export type Month = { month: string; diff --git a/upcoming-release-notes/2085.md b/upcoming-release-notes/2085.md new file mode 100644 index 00000000000..5f3fefcdb98 --- /dev/null +++ b/upcoming-release-notes/2085.md @@ -0,0 +1,6 @@ +--- +category: Bugfix +authors: [carkom] +--- + +Realign and fix header/totals row for table graph in custom reports