diff --git a/packages/desktop-client/src/components/reports/reports/CustomReportListCards.tsx b/packages/desktop-client/src/components/reports/reports/CustomReportListCards.tsx index 292352d183a..4ef5c08932b 100644 --- a/packages/desktop-client/src/components/reports/reports/CustomReportListCards.tsx +++ b/packages/desktop-client/src/components/reports/reports/CustomReportListCards.tsx @@ -1,6 +1,7 @@ -import React, { createRef, useMemo, useState } from 'react'; +import React, { createRef, useEffect, useMemo, useState } from 'react'; import { send, sendCatch } from 'loot-core/platform/client/fetch/index'; +import * as monthUtils from 'loot-core/src/shared/months'; import { type CustomReportEntity } from 'loot-core/types/models/reports'; import { useAccounts } from '../../../hooks/useAccounts'; @@ -72,6 +73,7 @@ export function CustomReportListCards({ const [err, setErr] = useState(''); const [name, setName] = useState(''); const inputRef = createRef(); + const [earliestTransaction, setEarliestTransaction] = useState(''); const payees = usePayees(); const accounts = useAccounts(); @@ -85,6 +87,14 @@ export function CustomReportListCards({ onDeleteMenuOpen(reportData === undefined ? '' : reportData, false); }; + useEffect(() => { + async function run() { + const trans = await send('get-earliest-transaction'); + setEarliestTransaction(trans ? trans.date : monthUtils.currentDay()); + } + run(); + }, []); + const onAddUpdate = async ({ reportData, }: { @@ -216,6 +226,7 @@ export function CustomReportListCards({ payees={payees} accounts={accounts} categories={categories} + earliestTransaction={earliestTransaction} /> diff --git a/packages/desktop-client/src/components/reports/reports/GetCardData.tsx b/packages/desktop-client/src/components/reports/reports/GetCardData.tsx index ade04b9cc4f..44f58d36806 100644 --- a/packages/desktop-client/src/components/reports/reports/GetCardData.tsx +++ b/packages/desktop-client/src/components/reports/reports/GetCardData.tsx @@ -11,6 +11,7 @@ import { styles } from '../../../style/styles'; import { theme } from '../../../style/theme'; import { Text } from '../../common/Text'; import { ChooseGraph } from '../ChooseGraph'; +import { getLiveRange } from '../getLiveRange'; import { LoadingIndicator } from '../LoadingIndicator'; import { ReportOptions } from '../ReportOptions'; import { createCustomSpreadsheet } from '../spreadsheets/custom-spreadsheet'; @@ -35,16 +36,30 @@ export function GetCardData({ payees, accounts, categories, + earliestTransaction, }: { report: CustomReportEntity; payees: PayeeEntity[]; accounts: AccountEntity[]; categories: { list: CategoryEntity[]; grouped: CategoryGroupEntity[] }; + earliestTransaction: string; }) { + let startDate = report.startDate; + let endDate = report.endDate; + + if (!report.isDateStatic) { + const [dateStart, dateEnd] = getLiveRange( + report.dateRange, + earliestTransaction, + ); + startDate = dateStart || report.startDate; + endDate = dateEnd || report.startDate; + } + const getGroupData = useMemo(() => { return createGroupedSpreadsheet({ - startDate: report.startDate, - endDate: report.endDate, + startDate, + endDate, interval: report.interval, categories, selectedCategories: report.selectedCategories ?? categories.list, @@ -56,11 +71,11 @@ export function GetCardData({ showUncategorized: report.showUncategorized, balanceTypeOp: ReportOptions.balanceTypeMap.get(report.balanceType), }); - }, [report, categories]); + }, [report, categories, startDate, endDate]); const getGraphData = useMemo(() => { return createCustomSpreadsheet({ - startDate: report.startDate, - endDate: report.endDate, + startDate, + endDate, interval: report.interval, categories, selectedCategories: report.selectedCategories ?? categories.list, @@ -76,7 +91,7 @@ export function GetCardData({ accounts, graphType: report.graphType, }); - }, [report, categories, payees, accounts]); + }, [report, categories, payees, accounts, startDate, endDate]); const graphData = useReport('default' + report.name, getGraphData); const groupedData = useReport('grouped' + report.name, getGroupData); @@ -86,8 +101,8 @@ export function GetCardData({ return data?.data ? (