Skip to content

A local-first personal finance app

✨ (dashboards) ability to save cash-flow report filters/date-range (#3417)

Matiss Janis Aboltins183c4b25a902
diff --git a/.eslintignore b/.eslintignore
index 2487b54410..bec05ebf71 100644
--- a/.eslintignore
+++ b/.eslintignore
@@ -14,6 +14,7 @@ packages/desktop-client/**/node_modules/*
packages/desktop-client/node_modules/
packages/desktop-client/src/icons/**/*
packages/desktop-client/test-results/
+packages/desktop-client/playwright-report/
packages/desktop-electron/client-build/
packages/desktop-electron/dist/
diff --git a/packages/desktop-client/e2e/reports.test.js-snapshots/Reports-loads-cash-flow-graph-and-checks-visuals-1-chromium-linux.png b/packages/desktop-client/e2e/reports.test.js-snapshots/Reports-loads-cash-flow-graph-and-checks-visuals-1-chromium-linux.png
index 48901464a0..d47f6a82e2 100644
Binary files a/packages/desktop-client/e2e/reports.test.js-snapshots/Reports-loads-cash-flow-graph-and-checks-visuals-1-chromium-linux.png and b/packages/desktop-client/e2e/reports.test.js-snapshots/Reports-loads-cash-flow-graph-and-checks-visuals-1-chromium-linux.png differ
diff --git a/packages/desktop-client/e2e/reports.test.js-snapshots/Reports-loads-cash-flow-graph-and-checks-visuals-2-chromium-linux.png b/packages/desktop-client/e2e/reports.test.js-snapshots/Reports-loads-cash-flow-graph-and-checks-visuals-2-chromium-linux.png
index aa2e7d20f4..2eca7e5bbb 100644
Binary files a/packages/desktop-client/e2e/reports.test.js-snapshots/Reports-loads-cash-flow-graph-and-checks-visuals-2-chromium-linux.png and b/packages/desktop-client/e2e/reports.test.js-snapshots/Reports-loads-cash-flow-graph-and-checks-visuals-2-chromium-linux.png differ
diff --git a/packages/desktop-client/e2e/reports.test.js-snapshots/Reports-loads-cash-flow-graph-and-checks-visuals-3-chromium-linux.png b/packages/desktop-client/e2e/reports.test.js-snapshots/Reports-loads-cash-flow-graph-and-checks-visuals-3-chromium-linux.png
index 42b40b2ca0..38ccd95922 100644
Binary files a/packages/desktop-client/e2e/reports.test.js-snapshots/Reports-loads-cash-flow-graph-and-checks-visuals-3-chromium-linux.png and b/packages/desktop-client/e2e/reports.test.js-snapshots/Reports-loads-cash-flow-graph-and-checks-visuals-3-chromium-linux.png differ
diff --git a/packages/desktop-client/src/components/reports/Header.tsx b/packages/desktop-client/src/components/reports/Header.tsx
index 3414909928..1eb9fe0ab5 100644
--- a/packages/desktop-client/src/components/reports/Header.tsx
+++ b/packages/desktop-client/src/components/reports/Header.tsx
@@ -8,7 +8,6 @@ import {
} from 'loot-core/types/models';
import { useFeatureFlag } from '../../hooks/useFeatureFlag';
-import { SvgPause, SvgPlay } from '../../icons/v1';
import { useResponsive } from '../../ResponsiveProvider';
import { Button } from '../common/Button2';
import { Select } from '../common/Select';
@@ -17,6 +16,7 @@ import { AppliedFilters } from '../filters/AppliedFilters';
import { FilterButton } from '../filters/FiltersMenu';
import {
+ calculateTimeRange,
getFullRange,
getLatestRange,
validateEnd,
@@ -85,16 +85,18 @@ export function Header({
{isDashboardsFeatureEnabled && mode && (
<Button
variant={mode === 'static' ? 'normal' : 'primary'}
- onPress={() =>
- onChangeDates(
+ onPress={() => {
+ const newMode = mode === 'static' ? 'sliding-window' : 'static';
+ const [newStart, newEnd] = calculateTimeRange({
start,
end,
- mode === 'static' ? 'sliding-window' : 'static',
- )
- }
- Icon={mode === 'static' ? SvgPause : SvgPlay}
+ mode: newMode,
+ });
+
+ onChangeDates(newStart, newEnd, newMode);
+ }}
>
- {mode === 'static' ? 'Paused' : 'Live'}
+ {mode === 'static' ? 'Static' : 'Live'}
</Button>
)}
diff --git a/packages/desktop-client/src/components/reports/Overview.tsx b/packages/desktop-client/src/components/reports/Overview.tsx
index f234cf8122..f6dfb88437 100644
--- a/packages/desktop-client/src/components/reports/Overview.tsx
+++ b/packages/desktop-client/src/components/reports/Overview.tsx
@@ -537,6 +537,7 @@ export function Overview() {
/>
) : item.type === 'cash-flow-card' ? (
<CashFlowCard
+ widgetId={item.i}
isEditing={isEditing}
meta={item.meta}
onMetaChange={newMeta => onMetaChange(item, newMeta)}
diff --git a/packages/desktop-client/src/components/reports/ReportRouter.tsx b/packages/desktop-client/src/components/reports/ReportRouter.tsx
index 795658e1aa..08dfa109e8 100644
--- a/packages/desktop-client/src/components/reports/ReportRouter.tsx
+++ b/packages/desktop-client/src/components/reports/ReportRouter.tsx
@@ -14,6 +14,7 @@ export function ReportRouter() {
<Route path="/net-worth" element={<NetWorth />} />
<Route path="/net-worth/:id" element={<NetWorth />} />
<Route path="/cash-flow" element={<CashFlow />} />
+ <Route path="/cash-flow/:id" element={<CashFlow />} />
<Route path="/custom" element={<CustomReport />} />
<Route path="/spending" element={<Spending />} />
</Routes>
diff --git a/packages/desktop-client/src/components/reports/graphs/CashFlowGraph.tsx b/packages/desktop-client/src/components/reports/graphs/CashFlowGraph.tsx
index 0ce818ab00..188e4b054b 100644
--- a/packages/desktop-client/src/components/reports/graphs/CashFlowGraph.tsx
+++ b/packages/desktop-client/src/components/reports/graphs/CashFlowGraph.tsx
@@ -37,7 +37,7 @@ type CustomTooltipProps = TooltipProps<number, 'date'> & {
function CustomTooltip({ active, payload, isConcise }: CustomTooltipProps) {
const { t } = useTranslation();
- if (!active || !payload) {
+ if (!active || !payload || !Array.isArray(payload) || !payload[0]) {
return null;
}
diff --git a/packages/desktop-client/src/components/reports/reportRanges.ts b/packages/desktop-client/src/components/reports/reportRanges.ts
index 631b56665c..7c3004894a 100644
--- a/packages/desktop-client/src/components/reports/reportRanges.ts
+++ b/packages/desktop-client/src/components/reports/reportRanges.ts
@@ -166,12 +166,17 @@ export function getLatestRange(offset: number) {
}
export function calculateTimeRange(
- { start, end, mode }: TimeFrame = {
- start: monthUtils.subMonths(monthUtils.currentMonth(), 5),
- end: monthUtils.currentMonth(),
- mode: 'sliding-window',
- },
+ timeFrame?: TimeFrame,
+ defaultTimeFrame?: TimeFrame,
) {
+ const start =
+ timeFrame?.start ??
+ defaultTimeFrame?.start ??
+ monthUtils.subMonths(monthUtils.currentMonth(), 5);
+ const end =
+ timeFrame?.end ?? defaultTimeFrame?.end ?? monthUtils.currentMonth();
+ const mode = timeFrame?.mode ?? defaultTimeFrame?.mode ?? 'sliding-window';
+
if (mode === 'full') {
return getFullRange(start);
}
@@ -179,5 +184,5 @@ export function calculateTimeRange(
return getLatestRange(monthUtils.differenceInCalendarMonths(end, start));
}
- return [start, end, 'static'];
+ return [start, end, 'static'] as const;
}
diff --git a/packages/desktop-client/src/components/reports/reports/CashFlow.tsx b/packages/desktop-client/src/components/reports/reports/CashFlow.tsx
index 4a105b042b..eb5f65a840 100644
--- a/packages/desktop-client/src/components/reports/reports/CashFlow.tsx
+++ b/packages/desktop-client/src/components/reports/reports/CashFlow.tsx
@@ -1,11 +1,20 @@
import React, { useState, useEffect, useMemo } from 'react';
+import { Trans, useTranslation } from 'react-i18next';
+import { useDispatch } from 'react-redux';
+import { useParams } from 'react-router-dom';
import * as d from 'date-fns';
+import { addNotification } from 'loot-core/client/actions';
+import { useWidget } from 'loot-core/client/data-hooks/widget';
import { send } from 'loot-core/src/platform/client/fetch';
import * as monthUtils from 'loot-core/src/shared/months';
import { integerToCurrency } from 'loot-core/src/shared/util';
-import { type RuleConditionEntity } from 'loot-core/types/models';
+import {
+ type CashFlowWidget,
+ type RuleConditionEntity,
+ type TimeFrame,
+} from 'loot-core/types/models';
import { useFilters } from '../../../hooks/useFilters';
import { useNavigate } from '../../../hooks/useNavigate';
@@ -23,10 +32,39 @@ import { PrivacyFilter } from '../../PrivacyFilter';
import { Change } from '../Change';
import { CashFlowGraph } from '../graphs/CashFlowGraph';
import { Header } from '../Header';
+import { LoadingIndicator } from '../LoadingIndicator';
+import { calculateTimeRange } from '../reportRanges';
import { cashFlowByDate } from '../spreadsheets/cash-flow-spreadsheet';
import { useReport } from '../useReport';
+export const defaultTimeFrame = {
+ start: monthUtils.dayFromDate(monthUtils.currentMonth()),
+ end: monthUtils.currentDay(),
+ mode: 'sliding-window',
+} satisfies TimeFrame;
+
export function CashFlow() {
+ const params = useParams();
+ const { data: widget, isLoading } = useWidget<CashFlowWidget>(
+ params.id ?? '',
+ 'cash-flow-card',
+ );
+
+ if (isLoading) {
+ return <LoadingIndicator />;
+ }
+
+ return <CashFlowInner widget={widget} />;
+}
+
+type CashFlowInnerProps = {
+ widget: CashFlowWidget;
+};
+
+function CashFlowInner({ widget }: CashFlowInnerProps) {
+ const dispatch = useDispatch();
+ const { t } = useTranslation();
+
const {
conditions,
conditionsOp,
@@ -34,16 +72,23 @@ export function CashFlow() {
onDelete: onDeleteFilter,
onUpdate: onUpdateFilter,
onConditionsOpChange,
- } = useFilters<RuleConditionEntity>();
+ } = useFilters<RuleConditionEntity>(
+ widget?.meta?.conditions,
+ widget?.meta?.conditionsOp,
+ );
const [allMonths, setAllMonths] = useState<null | Array<{
name: string;
pretty: string;
}>>(null);
- const [start, setStart] = useState(
- monthUtils.subMonths(monthUtils.currentMonth(), 5),
+
+ const [initialStart, initialEnd, initialMode] = calculateTimeRange(
+ widget?.meta?.timeFrame,
+ defaultTimeFrame,
);
- const [end, setEnd] = useState(monthUtils.currentDay());
+ const [start, setStart] = useState(initialStart);
+ const [end, setEnd] = useState(initialEnd);
+ const [mode, setMode] = useState(initialMode);
const [showBalance, setShowBalance] = useState(true);
const [isConcise, setIsConcise] = useState(() => {
@@ -80,52 +125,72 @@ export function CashFlow() {
run();
}, []);
- function onChangeDates(start: string, end: string) {
+ function onChangeDates(start: string, end: string, mode: TimeFrame['mode']) {
const numDays = d.differenceInCalendarDays(
d.parseISO(end),
d.parseISO(start),
);
const isConcise = numDays > 31 * 3;
- let endDay = end + '-31';
- if (endDay > monthUtils.currentDay()) {
- endDay = monthUtils.currentDay();
- }
-
- setStart(start + '-01');
- setEnd(endDay);
+ setStart(start);
+ setEnd(end);
+ setMode(mode);
setIsConcise(isConcise);
}
const navigate = useNavigate();
const { isNarrowWidth } = useResponsive();
+ async function onSaveWidget() {
+ await send('dashboard-update-widget', {
+ id: widget?.id,
+ meta: {
+ ...(widget.meta ?? {}),
+ conditions,
+ conditionsOp,
+ timeFrame: {
+ start,
+ end,
+ mode,
+ },
+ },
+ });
+ dispatch(
+ addNotification({
+ type: 'message',
+ message: t('Dashboard widget successfully saved.'),
+ }),
+ );
+ }
+
if (!allMonths || !data) {
return null;
}
const { graphData, totalExpenses, totalIncome, totalTransfers } = data;
+ const title = widget?.meta?.name ?? t('Cash Flow');
return (
<Page
header={
isNarrowWidth ? (
<MobilePageHeader
- title="Cash Flow"
+ title={title}
leftContent={
<MobileBackButton onPress={() => navigate('/reports')} />
}
/>
) : (
- <PageHeader title="Cash Flow" />
+ <PageHeader title={title} />
)
}
padding={0}
>
<Header
allMonths={allMonths}
- start={monthUtils.getMonth(start)}
- end={monthUtils.getMonth(end)}
+ start={start}
+ end={end}
+ mode={mode}
show1Month
onChangeDates={onChangeDates}
onApply={onApplyFilter}
@@ -135,9 +200,17 @@ export function CashFlow() {
conditionsOp={conditionsOp}
onConditionsOpChange={onConditionsOpChange}
>
- <Button onPress={() => setShowBalance(state => !state)}>
- {showBalance ? 'Hide balance' : 'Show balance'}
- </Button>
+ <View style={{ flexDirection: 'row', gap: 10 }}>
+ <Button onPress={() => setShowBalance(state => !state)}>
+ {showBalance ? t('Hide balance') : t('Show balance')}
+ </Button>
+
+ {widget && (
+ <Button variant="primary" onPress={onSaveWidget}>
+ <Trans>Save widget</Trans>
+ </Button>
+ )}
+ </View>
</Header>
<View
style={{
@@ -167,7 +240,11 @@ export function CashFlow() {
<AlignedText
style={{ marginBottom: 5, minWidth: 160 }}
- left={<Block>Expenses:</Block>}
+ left={
+ <Block>
+ <Trans>Expenses:</Trans>
+ </Block>
+ }
right={
<Text style={{ fontWeight: 600 }}>
<PrivacyFilter>
@@ -179,7 +256,11 @@ export function CashFlow() {
<AlignedText
style={{ marginBottom: 5, minWidth: 160 }}
- left={<Block>Transfers:</Block>}
+ left={
+ <Block>
+ <Trans>Transfers:</Trans>
+ </Block>
+ }
right={
<Text style={{ fontWeight: 600 }}>
<PrivacyFilter>
@@ -207,15 +288,17 @@ export function CashFlow() {
userSelect: 'none',
}}
>
- <Paragraph>
- <strong>How is cash flow calculated?</strong>
- </Paragraph>
- <Paragraph>
- Cash flow shows the balance of your budgeted accounts over time, and
- the amount of expenses/income each day or month. Your budgeted
- accounts are considered to be “cash on hand,” so this gives you a
- picture of how available money fluctuates.
- </Paragraph>
+ <Trans>
+ <Paragraph>
+ <strong>How is cash flow calculated?</strong>
+ </Paragraph>
+ <Paragraph>
+ Cash flow shows the balance of your budgeted accounts over time,
+ and the amount of expenses/income each day or month. Your budgeted
+ accounts are considered to be “cash on hand,” so this gives you a
+ picture of how available money fluctuates.
+ </Paragraph>
+ </Trans>
</View>
</View>
</Page>
diff --git a/packages/desktop-client/src/components/reports/reports/CashFlowCard.tsx b/packages/desktop-client/src/components/reports/reports/CashFlowCard.tsx
index 3bf8fe415e..552b87ea49 100644
--- a/packages/desktop-client/src/components/reports/reports/CashFlowCard.tsx
+++ b/packages/desktop-client/src/components/reports/reports/CashFlowCard.tsx
@@ -3,10 +3,10 @@ import { useTranslation } from 'react-i18next';
import { Bar, BarChart, LabelList, ResponsiveContainer } from 'recharts';
-import * as monthUtils from 'loot-core/src/shared/months';
import { integerToCurrency } from 'loot-core/src/shared/util';
import { type CashFlowWidget } from 'loot-core/src/types/models';
+import { useFeatureFlag } from '../../../hooks/useFeatureFlag';
import { theme } from '../../../style';
import { View } from '../../common/View';
import { PrivacyFilter } from '../../PrivacyFilter';
@@ -17,9 +17,12 @@ import { DateRange } from '../DateRange';
import { LoadingIndicator } from '../LoadingIndicator';
import { ReportCard } from '../ReportCard';
import { ReportCardName } from '../ReportCardName';
+import { calculateTimeRange } from '../reportRanges';
import { simpleCashFlow } from '../spreadsheets/cash-flow-spreadsheet';
import { useReport } from '../useReport';
+import { defaultTimeFrame } from './CashFlow';
+
type CustomLabelProps = {
value?: number;
name: string;
@@ -81,6 +84,7 @@ function CustomLabel({
}
type CashFlowCardProps = {
+ widgetId: string;
isEditing?: boolean;
meta?: CashFlowWidget['meta'];
onMetaChange: (newMeta: CashFlowWidget['meta']) => void;
@@ -88,18 +92,22 @@ type CashFlowCardProps = {
};
export function CashFlowCard({
+ widgetId,
isEditing,
- meta,
+ meta = {},
onMetaChange,
onRemove,
}: CashFlowCardProps) {
+ const isDashboardsFeatureEnabled = useFeatureFlag('dashboards');
const { t } = useTranslation();
- const end = monthUtils.currentDay();
- const start = monthUtils.currentMonth() + '-01';
+ const [start, end] = calculateTimeRange(meta?.timeFrame, defaultTimeFrame);
const [nameMenuOpen, setNameMenuOpen] = useState(false);
- const params = useMemo(() => simpleCashFlow(start, end), [start, end]);
+ const params = useMemo(
+ () => simpleCashFlow(start, end, meta?.conditions, meta?.conditionsOp),
+ [start, end, meta?.conditions, meta?.conditionsOp],
+ );
const data = useReport('cash_flow_simple', params);
const [isCardHovered, setIsCardHovered] = useState(false);
@@ -113,7 +121,11 @@ export function CashFlowCard({
return (
<ReportCard
isEditing={isEditing}
- to="/reports/cash-flow"
+ to={
+ isDashboardsFeatureEnabled
+ ? `/reports/cash-flow/${widgetId}`
+ : '/reports/cash-flow'
+ }
menuItems={[
{
name: 'rename',
diff --git a/packages/desktop-client/src/components/reports/reports/NetWorth.jsx b/packages/desktop-client/src/components/reports/reports/NetWorth.jsx
index fe36605e58..31a0abace8 100644
--- a/packages/desktop-client/src/components/reports/reports/NetWorth.jsx
+++ b/packages/desktop-client/src/components/reports/reports/NetWorth.jsx
@@ -33,7 +33,10 @@ import { fromDateRepr } from '../util';
export function NetWorth() {
const params = useParams();
- const { data: widget, isLoading } = useWidget(params.id ?? '');
+ const { data: widget, isLoading } = useWidget(
+ params.id ?? '',
+ 'net-worth-card',
+ );
if (isLoading) {
return <LoadingIndicator />;
diff --git a/packages/desktop-client/src/components/reports/spreadsheets/cash-flow-spreadsheet.tsx b/packages/desktop-client/src/components/reports/spreadsheets/cash-flow-spreadsheet.tsx
index 04a7967d09..7c79430ae6 100644
--- a/packages/desktop-client/src/components/reports/spreadsheets/cash-flow-spreadsheet.tsx
+++ b/packages/desktop-client/src/components/reports/spreadsheets/cash-flow-spreadsheet.tsx
@@ -12,15 +12,37 @@ import { type RuleConditionEntity } from 'loot-core/types/models';
import { AlignedText } from '../../common/AlignedText';
import { runAll, indexCashFlow } from '../util';
-export function simpleCashFlow(start: string, end: string) {
+export function simpleCashFlow(
+ startMonth: string,
+ endMonth: string,
+ conditions: RuleConditionEntity[] = [],
+ conditionsOp: 'and' | 'or' = 'and',
+) {
+ const start = monthUtils.firstDayOfMonth(startMonth);
+ const end = monthUtils.lastDayOfMonth(endMonth);
+
return async (
spreadsheet: ReturnType<typeof useSpreadsheet>,
setData: (data: { graphData: { income: number; expense: number } }) => void,
) => {
+ const { filters } = await send('make-filters-from-conditions', {
+ conditions: conditions.filter(cond => !cond.customName),
+ });
+ const conditionsOpKey = conditionsOp === 'or' ? '$or' : '$and';
+
function makeQuery() {
return q('transactions')
.filter({
- $and: [{ date: { $gte: start } }, { date: { $lte: end } }],
+ [conditionsOpKey]: filters,
+ $and: [
+ { date: { $gte: start } },
+ {
+ date: {
+ $lte:
+ end > monthUtils.currentDay() ? monthUtils.currentDay() : end,
+ },
+ },
+ ],
'account.offbudget': false,
'payee.transfer_acct': null,
})
@@ -45,12 +67,17 @@ export function simpleCashFlow(start: string, end: string) {
}
export function cashFlowByDate(
- start: string,
- end: string,
+ startMonth: string,
+ endMonth: string,
isConcise: boolean,
conditions: RuleConditionEntity[] = [],
conditionsOp: 'and' | 'or',
) {
+ const start = monthUtils.firstDayOfMonth(startMonth);
+ const end = monthUtils.lastDayOfMonth(endMonth);
+ const fixedEnd =
+ end > monthUtils.currentDay() ? monthUtils.currentDay() : end;
+
return async (
spreadsheet: ReturnType<typeof useSpreadsheet>,
setData: (data: ReturnType<typeof recalculate>) => void,
@@ -68,7 +95,7 @@ export function cashFlowByDate(
.filter({
$and: [
{ date: { $transform: '$month', $gte: start } },
- { date: { $transform: '$month', $lte: end } },
+ { date: { $transform: '$month', $lte: fixedEnd } },
],
'account.offbudget': false,
});
@@ -105,7 +132,7 @@ export function cashFlowByDate(
makeQuery().filter({ amount: { $lt: 0 } }),
],
data => {
- setData(recalculate(data, start, end, isConcise));
+ setData(recalculate(data, start, fixedEnd, isConcise));
},
);
};
diff --git a/packages/desktop-client/src/components/reports/spreadsheets/net-worth-spreadsheet.ts b/packages/desktop-client/src/components/reports/spreadsheets/net-worth-spreadsheet.ts
index 49c01d96d6..c07783edf7 100644
--- a/packages/desktop-client/src/components/reports/spreadsheets/net-worth-spreadsheet.ts
+++ b/packages/desktop-client/src/components/reports/spreadsheets/net-worth-spreadsheet.ts
@@ -45,7 +45,7 @@ export function createSpreadsheet(
.filter({
[conditionsOpKey]: filters,
account: acct.id,
- date: { $lt: start + '-01' },
+ date: { $lt: monthUtils.firstDayOfMonth(start) },
})
.calculate({ $sum: '$amount' }),
).then(({ data }) => data),
@@ -58,8 +58,8 @@ export function createSpreadsheet(
.filter({
account: acct.id,
$and: [
- { date: { $gte: start + '-01' } },
- { date: { $lte: end + '-31' } },
+ { date: { $gte: monthUtils.firstDayOfMonth(start) } },
+ { date: { $lte: monthUtils.lastDayOfMonth(end) } },
],
})
.groupBy({ $month: '$date' })
diff --git a/packages/loot-core/src/client/data-hooks/widget.ts b/packages/loot-core/src/client/data-hooks/widget.ts
index 367957b4f0..5610a29eca 100644
--- a/packages/loot-core/src/client/data-hooks/widget.ts
+++ b/packages/loot-core/src/client/data-hooks/widget.ts
@@ -4,9 +4,9 @@ import { q } from '../../shared/query';
import { type Widget } from '../../types/models';
import { useLiveQuery } from '../query-hooks';
-export function useWidget(id: string) {
- const data = useLiveQuery<Widget[]>(
- () => q('dashboard').filter({ id }).select('*'),
+export function useWidget<W extends Widget>(id: string, type: W['type']) {
+ const data = useLiveQuery<W[]>(
+ () => q('dashboard').filter({ id, type }).select('*'),
[id],
);
diff --git a/packages/loot-core/src/shared/months.ts b/packages/loot-core/src/shared/months.ts
index 0c0f5793f8..4d1c7ace69 100644
--- a/packages/loot-core/src/shared/months.ts
+++ b/packages/loot-core/src/shared/months.ts
@@ -100,6 +100,14 @@ export function weekFromDate(
);
}
+export function firstDayOfMonth(date: DateLike): string {
+ return dayFromDate(d.startOfMonth(_parse(date)));
+}
+
+export function lastDayOfMonth(date: DateLike): string {
+ return dayFromDate(d.endOfMonth(_parse(date)));
+}
+
export function dayFromDate(date: DateLike): string {
return d.format(_parse(date), 'yyyy-MM-dd');
}
diff --git a/packages/loot-core/src/types/models/dashboard.d.ts b/packages/loot-core/src/types/models/dashboard.d.ts
index 40b0063332..a2d7252b1b 100644
--- a/packages/loot-core/src/types/models/dashboard.d.ts
+++ b/packages/loot-core/src/types/models/dashboard.d.ts
@@ -32,7 +32,12 @@ export type NetWorthWidget = AbstractWidget<
>;
export type CashFlowWidget = AbstractWidget<
'cash-flow-card',
- { name?: string } | null
+ {
+ name?: string;
+ conditions?: RuleConditionEntity[];
+ conditionsOp?: 'and' | 'or';
+ timeFrame?: TimeFrame;
+ } | null
>;
export type SpendingWidget = AbstractWidget<
'spending-card',
diff --git a/tsconfig.json b/tsconfig.json
index 79731b6981..5c5510f8c7 100644
--- a/tsconfig.json
+++ b/tsconfig.json
@@ -48,7 +48,8 @@
"**/client-build/*",
"**/dist/*",
"**/lib-dist/*",
- "**/test-results/*"
+ "**/test-results/*",
+ "**/playwright-report/*"
],
"ts-node": {
"compilerOptions": {
diff --git a/upcoming-release-notes/3417.md b/upcoming-release-notes/3417.md
new file mode 100644
index 0000000000..72abdd69ee
--- /dev/null
+++ b/upcoming-release-notes/3417.md
@@ -0,0 +1,6 @@
+---
+category: Enhancements
+authors: [MatissJanis]
+---
+
+Dashboards: ability to save filters & time-range on cash-flow widgets.