Skip to content

A local-first personal finance app

Add option to set how far out the upcoming scheduled transactions are shown in the account view. (#3310)

Samuel Barnes37ad584826ad
diff --git a/packages/desktop-client/e2e/schedules.test.js-snapshots/Schedules-checks-the-page-visuals-1-chromium-linux.png b/packages/desktop-client/e2e/schedules.test.js-snapshots/Schedules-checks-the-page-visuals-1-chromium-linux.png
index 1353be4b09..340de20b82 100644
Binary files a/packages/desktop-client/e2e/schedules.test.js-snapshots/Schedules-checks-the-page-visuals-1-chromium-linux.png and b/packages/desktop-client/e2e/schedules.test.js-snapshots/Schedules-checks-the-page-visuals-1-chromium-linux.png differ
diff --git a/packages/desktop-client/e2e/schedules.test.js-snapshots/Schedules-checks-the-page-visuals-2-chromium-linux.png b/packages/desktop-client/e2e/schedules.test.js-snapshots/Schedules-checks-the-page-visuals-2-chromium-linux.png
index 280bb8fdae..db77f9ee3e 100644
Binary files a/packages/desktop-client/e2e/schedules.test.js-snapshots/Schedules-checks-the-page-visuals-2-chromium-linux.png and b/packages/desktop-client/e2e/schedules.test.js-snapshots/Schedules-checks-the-page-visuals-2-chromium-linux.png differ
diff --git a/packages/desktop-client/e2e/schedules.test.js-snapshots/Schedules-checks-the-page-visuals-3-chromium-linux.png b/packages/desktop-client/e2e/schedules.test.js-snapshots/Schedules-checks-the-page-visuals-3-chromium-linux.png
index 4a5347d43a..36ac4f4e33 100644
Binary files a/packages/desktop-client/e2e/schedules.test.js-snapshots/Schedules-checks-the-page-visuals-3-chromium-linux.png and b/packages/desktop-client/e2e/schedules.test.js-snapshots/Schedules-checks-the-page-visuals-3-chromium-linux.png differ
diff --git a/packages/desktop-client/e2e/schedules.test.js-snapshots/Schedules-creates-a-new-schedule-posts-the-transaction-and-later-completes-it-1-chromium-linux.png b/packages/desktop-client/e2e/schedules.test.js-snapshots/Schedules-creates-a-new-schedule-posts-the-transaction-and-later-completes-it-1-chromium-linux.png
index 82687bb6bc..6750d147a6 100644
Binary files a/packages/desktop-client/e2e/schedules.test.js-snapshots/Schedules-creates-a-new-schedule-posts-the-transaction-and-later-completes-it-1-chromium-linux.png and b/packages/desktop-client/e2e/schedules.test.js-snapshots/Schedules-creates-a-new-schedule-posts-the-transaction-and-later-completes-it-1-chromium-linux.png differ
diff --git a/packages/desktop-client/e2e/schedules.test.js-snapshots/Schedules-creates-a-new-schedule-posts-the-transaction-and-later-completes-it-10-chromium-linux.png b/packages/desktop-client/e2e/schedules.test.js-snapshots/Schedules-creates-a-new-schedule-posts-the-transaction-and-later-completes-it-10-chromium-linux.png
index 11f4d7010d..d321d08495 100644
Binary files a/packages/desktop-client/e2e/schedules.test.js-snapshots/Schedules-creates-a-new-schedule-posts-the-transaction-and-later-completes-it-10-chromium-linux.png and b/packages/desktop-client/e2e/schedules.test.js-snapshots/Schedules-creates-a-new-schedule-posts-the-transaction-and-later-completes-it-10-chromium-linux.png differ
diff --git a/packages/desktop-client/e2e/schedules.test.js-snapshots/Schedules-creates-a-new-schedule-posts-the-transaction-and-later-completes-it-11-chromium-linux.png b/packages/desktop-client/e2e/schedules.test.js-snapshots/Schedules-creates-a-new-schedule-posts-the-transaction-and-later-completes-it-11-chromium-linux.png
index 1250b35799..e7fc8cfb90 100644
Binary files a/packages/desktop-client/e2e/schedules.test.js-snapshots/Schedules-creates-a-new-schedule-posts-the-transaction-and-later-completes-it-11-chromium-linux.png and b/packages/desktop-client/e2e/schedules.test.js-snapshots/Schedules-creates-a-new-schedule-posts-the-transaction-and-later-completes-it-11-chromium-linux.png differ
diff --git a/packages/desktop-client/e2e/schedules.test.js-snapshots/Schedules-creates-a-new-schedule-posts-the-transaction-and-later-completes-it-12-chromium-linux.png b/packages/desktop-client/e2e/schedules.test.js-snapshots/Schedules-creates-a-new-schedule-posts-the-transaction-and-later-completes-it-12-chromium-linux.png
index 8b9c0a3016..2df264f06f 100644
Binary files a/packages/desktop-client/e2e/schedules.test.js-snapshots/Schedules-creates-a-new-schedule-posts-the-transaction-and-later-completes-it-12-chromium-linux.png and b/packages/desktop-client/e2e/schedules.test.js-snapshots/Schedules-creates-a-new-schedule-posts-the-transaction-and-later-completes-it-12-chromium-linux.png differ
diff --git a/packages/desktop-client/e2e/schedules.test.js-snapshots/Schedules-creates-a-new-schedule-posts-the-transaction-and-later-completes-it-2-chromium-linux.png b/packages/desktop-client/e2e/schedules.test.js-snapshots/Schedules-creates-a-new-schedule-posts-the-transaction-and-later-completes-it-2-chromium-linux.png
index a3583611e4..c6e43632fb 100644
Binary files a/packages/desktop-client/e2e/schedules.test.js-snapshots/Schedules-creates-a-new-schedule-posts-the-transaction-and-later-completes-it-2-chromium-linux.png and b/packages/desktop-client/e2e/schedules.test.js-snapshots/Schedules-creates-a-new-schedule-posts-the-transaction-and-later-completes-it-2-chromium-linux.png differ
diff --git a/packages/desktop-client/e2e/schedules.test.js-snapshots/Schedules-creates-a-new-schedule-posts-the-transaction-and-later-completes-it-3-chromium-linux.png b/packages/desktop-client/e2e/schedules.test.js-snapshots/Schedules-creates-a-new-schedule-posts-the-transaction-and-later-completes-it-3-chromium-linux.png
index 89c39d89a5..50a8985a6f 100644
Binary files a/packages/desktop-client/e2e/schedules.test.js-snapshots/Schedules-creates-a-new-schedule-posts-the-transaction-and-later-completes-it-3-chromium-linux.png and b/packages/desktop-client/e2e/schedules.test.js-snapshots/Schedules-creates-a-new-schedule-posts-the-transaction-and-later-completes-it-3-chromium-linux.png differ
diff --git a/packages/desktop-client/e2e/schedules.test.js-snapshots/Schedules-creates-a-new-schedule-posts-the-transaction-and-later-completes-it-4-chromium-linux.png b/packages/desktop-client/e2e/schedules.test.js-snapshots/Schedules-creates-a-new-schedule-posts-the-transaction-and-later-completes-it-4-chromium-linux.png
index aad3a932ca..dcc9b3b6c4 100644
Binary files a/packages/desktop-client/e2e/schedules.test.js-snapshots/Schedules-creates-a-new-schedule-posts-the-transaction-and-later-completes-it-4-chromium-linux.png and b/packages/desktop-client/e2e/schedules.test.js-snapshots/Schedules-creates-a-new-schedule-posts-the-transaction-and-later-completes-it-4-chromium-linux.png differ
diff --git a/packages/desktop-client/e2e/schedules.test.js-snapshots/Schedules-creates-a-new-schedule-posts-the-transaction-and-later-completes-it-5-chromium-linux.png b/packages/desktop-client/e2e/schedules.test.js-snapshots/Schedules-creates-a-new-schedule-posts-the-transaction-and-later-completes-it-5-chromium-linux.png
index e08abc5c6a..2697b20012 100644
Binary files a/packages/desktop-client/e2e/schedules.test.js-snapshots/Schedules-creates-a-new-schedule-posts-the-transaction-and-later-completes-it-5-chromium-linux.png and b/packages/desktop-client/e2e/schedules.test.js-snapshots/Schedules-creates-a-new-schedule-posts-the-transaction-and-later-completes-it-5-chromium-linux.png differ
diff --git a/packages/desktop-client/e2e/schedules.test.js-snapshots/Schedules-creates-a-new-schedule-posts-the-transaction-and-later-completes-it-6-chromium-linux.png b/packages/desktop-client/e2e/schedules.test.js-snapshots/Schedules-creates-a-new-schedule-posts-the-transaction-and-later-completes-it-6-chromium-linux.png
index 53bca2e1a9..8ac1b50224 100644
Binary files a/packages/desktop-client/e2e/schedules.test.js-snapshots/Schedules-creates-a-new-schedule-posts-the-transaction-and-later-completes-it-6-chromium-linux.png and b/packages/desktop-client/e2e/schedules.test.js-snapshots/Schedules-creates-a-new-schedule-posts-the-transaction-and-later-completes-it-6-chromium-linux.png differ
diff --git a/packages/desktop-client/e2e/schedules.test.js-snapshots/Schedules-creates-a-new-schedule-posts-the-transaction-and-later-completes-it-7-chromium-linux.png b/packages/desktop-client/e2e/schedules.test.js-snapshots/Schedules-creates-a-new-schedule-posts-the-transaction-and-later-completes-it-7-chromium-linux.png
index cece39b6fc..3a3ee5fa0d 100644
Binary files a/packages/desktop-client/e2e/schedules.test.js-snapshots/Schedules-creates-a-new-schedule-posts-the-transaction-and-later-completes-it-7-chromium-linux.png and b/packages/desktop-client/e2e/schedules.test.js-snapshots/Schedules-creates-a-new-schedule-posts-the-transaction-and-later-completes-it-7-chromium-linux.png differ
diff --git a/packages/desktop-client/e2e/schedules.test.js-snapshots/Schedules-creates-a-new-schedule-posts-the-transaction-and-later-completes-it-8-chromium-linux.png b/packages/desktop-client/e2e/schedules.test.js-snapshots/Schedules-creates-a-new-schedule-posts-the-transaction-and-later-completes-it-8-chromium-linux.png
index 10b44ed026..29d52fe93e 100644
Binary files a/packages/desktop-client/e2e/schedules.test.js-snapshots/Schedules-creates-a-new-schedule-posts-the-transaction-and-later-completes-it-8-chromium-linux.png and b/packages/desktop-client/e2e/schedules.test.js-snapshots/Schedules-creates-a-new-schedule-posts-the-transaction-and-later-completes-it-8-chromium-linux.png differ
diff --git a/packages/desktop-client/e2e/schedules.test.js-snapshots/Schedules-creates-a-new-schedule-posts-the-transaction-and-later-completes-it-9-chromium-linux.png b/packages/desktop-client/e2e/schedules.test.js-snapshots/Schedules-creates-a-new-schedule-posts-the-transaction-and-later-completes-it-9-chromium-linux.png
index e61ff7a968..0494048c3f 100644
Binary files a/packages/desktop-client/e2e/schedules.test.js-snapshots/Schedules-creates-a-new-schedule-posts-the-transaction-and-later-completes-it-9-chromium-linux.png and b/packages/desktop-client/e2e/schedules.test.js-snapshots/Schedules-creates-a-new-schedule-posts-the-transaction-and-later-completes-it-9-chromium-linux.png differ
diff --git a/packages/desktop-client/src/components/schedules/index.tsx b/packages/desktop-client/src/components/schedules/index.tsx
index ffa41344e2..e0fd73e9e2 100644
--- a/packages/desktop-client/src/components/schedules/index.tsx
+++ b/packages/desktop-client/src/components/schedules/index.tsx
@@ -11,8 +11,9 @@ import { Button } from '../common/Button2';
import { Search } from '../common/Search';
import { View } from '../common/View';
import { Page } from '../Page';
+import { UpcomingLengthSettings } from '../settings/Upcoming';
-import { SchedulesTable, type ScheduleItemAction } from './SchedulesTable';
+import { type ScheduleItemAction, SchedulesTable } from './SchedulesTable';
export function Schedules() {
const { t } = useTranslation();
@@ -75,6 +76,15 @@ export function Schedules() {
padding: '0 0 15px',
}}
>
+ <View
+ style={{
+ flexDirection: 'row',
+ alignItems: 'center',
+ padding: '15px 0 0',
+ }}
+ >
+ <UpcomingLengthSettings />
+ </View>
<View
style={{
flex: 1,
diff --git a/packages/desktop-client/src/components/settings/Upcoming.tsx b/packages/desktop-client/src/components/settings/Upcoming.tsx
new file mode 100644
index 0000000000..0f1409c75d
--- /dev/null
+++ b/packages/desktop-client/src/components/settings/Upcoming.tsx
@@ -0,0 +1,85 @@
+import React, { useState } from 'react';
+import { Trans } from 'react-i18next';
+import { useLocation } from 'react-router-dom';
+
+import { Column } from 'glamor/jsxstyle';
+
+import { type SyncedPrefs } from 'loot-core/types/prefs';
+
+import { useSyncedPref } from '../../hooks/useSyncedPref';
+import { type CSSProperties, theme } from '../../style';
+import { Button } from '../common/Button2';
+import { Select } from '../common/Select';
+import { Text } from '../common/Text';
+import { View } from '../common/View';
+
+import { Setting } from './UI';
+
+const options: {
+ value: SyncedPrefs['upcomingScheduledTransactionLength'];
+ label: string;
+}[] = [
+ { value: '1', label: '1 Day' },
+ { value: '7', label: '1 Week' },
+ { value: '14', label: '2 Weeks' },
+ { value: '30', label: '1 Month' },
+];
+
+export function UpcomingLengthSettings() {
+ const [_upcomingLength, setUpcomingLength] = useSyncedPref(
+ 'upcomingScheduledTransactionLength',
+ );
+ const upcomingLength = _upcomingLength || '7';
+
+ const selectButtonStyle: CSSProperties = {
+ ':hover': {
+ backgroundColor: theme.buttonNormalBackgroundHover,
+ },
+ };
+
+ const location = useLocation();
+ const [expanded, setExpanded] = useState(location.hash === '#upcomingLength');
+
+ return expanded ? (
+ <Setting
+ primaryAction={
+ <View style={{ flexDirection: 'row', gap: '1em' }}>
+ <Column title="Upcoming Length">
+ <Select
+ options={options.map(x => [x.value || '7', x.label])}
+ value={upcomingLength}
+ onChange={newValue => setUpcomingLength(newValue)}
+ style={selectButtonStyle}
+ />
+ </Column>
+ </View>
+ }
+ >
+ <View style={{ flexDirection: 'row', gap: 20 }}>
+ <Text>
+ <strong>Upcoming Length</strong> does not affect how budget data is
+ stored, and can be changed at any time.
+ </Text>
+ <Button
+ onPress={() => setExpanded(false)}
+ aria-label="Close upcoming length settings"
+ >
+ Close
+ </Button>
+ </View>
+ </Setting>
+ ) : (
+ <View>
+ <Button
+ aria-label="Edit upcoming length settings"
+ variant="primary"
+ onPress={() => setExpanded(true)}
+ >
+ <Trans>
+ Edit Upcoming Length (
+ {options.find(x => x.value === upcomingLength)?.label ?? '1 Week'})
+ </Trans>
+ </Button>
+ </View>
+ );
+}
diff --git a/packages/desktop-client/src/components/settings/index.tsx b/packages/desktop-client/src/components/settings/index.tsx
index 04380ee782..30a3baf9a2 100644
--- a/packages/desktop-client/src/components/settings/index.tsx
+++ b/packages/desktop-client/src/components/settings/index.tsx
@@ -8,7 +8,7 @@ import { listen } from 'loot-core/src/platform/client/fetch';
import { useActions } from '../../hooks/useActions';
import { useFeatureFlag } from '../../hooks/useFeatureFlag';
import { useGlobalPref } from '../../hooks/useGlobalPref';
-import { useLatestVersion, useIsOutdated } from '../../hooks/useLatestVersion';
+import { useIsOutdated, useLatestVersion } from '../../hooks/useLatestVersion';
import { useMetadataPref } from '../../hooks/useMetadataPref';
import { useResponsive } from '../../ResponsiveProvider';
import { theme } from '../../style';
diff --git a/packages/loot-core/src/client/data-hooks/schedules.tsx b/packages/loot-core/src/client/data-hooks/schedules.tsx
index 5c18d87790..db4c06edf8 100644
--- a/packages/loot-core/src/client/data-hooks/schedules.tsx
+++ b/packages/loot-core/src/client/data-hooks/schedules.tsx
@@ -1,14 +1,16 @@
// @ts-strict-ignore
import React, {
createContext,
- useEffect,
- useState,
useContext,
+ useEffect,
useMemo,
+ useState,
} from 'react';
+import { useSyncedPref } from '@actual-app/web/src/hooks/useSyncedPref';
+
import { q, type Query } from '../../shared/query';
-import { getStatus, getHasTransactionsQuery } from '../../shared/schedules';
+import { getHasTransactionsQuery, getStatus } from '../../shared/schedules';
import { type ScheduleEntity } from '../../types/models';
import { getAccountFilter } from '../queries';
import { liveQuery } from '../query-helpers';
@@ -16,7 +18,7 @@ import { liveQuery } from '../query-helpers';
export type ScheduleStatusType = ReturnType<typeof getStatus>;
export type ScheduleStatuses = Map<ScheduleEntity['id'], ScheduleStatusType>;
-function loadStatuses(schedules: ScheduleEntity[], onData) {
+function loadStatuses(schedules: ScheduleEntity[], onData, prefs) {
return liveQuery(getHasTransactionsQuery(schedules), onData, {
mapper: data => {
const hasTrans = new Set(data.filter(Boolean).map(row => row.schedule));
@@ -24,7 +26,7 @@ function loadStatuses(schedules: ScheduleEntity[], onData) {
return new Map(
schedules.map(s => [
s.id,
- getStatus(s.next_date, s.completed, hasTrans.has(s.id)),
+ getStatus(s.next_date, s.completed, hasTrans.has(s.id), prefs),
]),
);
},
@@ -36,15 +38,15 @@ type UseSchedulesResult = {
schedules: ScheduleEntity[];
statuses: ScheduleStatuses;
} | null;
+
export function useSchedules({
transform,
}: UseSchedulesArgs = {}): UseSchedulesResult {
const [data, setData] = useState<UseSchedulesResult>(null);
-
+ const upcomingLength = useSyncedPref('upcomingScheduledTransactionLength')[0];
useEffect(() => {
const query = q('schedules').select('*');
let statusQuery;
-
const scheduleQuery = liveQuery(
transform ? transform(query) : query,
async (schedules: ScheduleEntity[]) => {
@@ -53,8 +55,10 @@ export function useSchedules({
statusQuery.unsubscribe();
}
- statusQuery = loadStatuses(schedules, (statuses: ScheduleStatuses) =>
- setData({ schedules, statuses }),
+ statusQuery = loadStatuses(
+ schedules,
+ (statuses: ScheduleStatuses) => setData({ schedules, statuses }),
+ upcomingLength,
);
}
},
@@ -68,7 +72,7 @@ export function useSchedules({
statusQuery.unsubscribe();
}
};
- }, [transform]);
+ }, [upcomingLength, transform]);
return data;
}
diff --git a/packages/loot-core/src/server/prefs.ts b/packages/loot-core/src/server/prefs.ts
index 14fd72ddce..84e27643a8 100644
--- a/packages/loot-core/src/server/prefs.ts
+++ b/packages/loot-core/src/server/prefs.ts
@@ -9,6 +9,15 @@ import { Message, sendMessages } from './sync';
export const BUDGET_TYPES = ['report', 'rollover'] as const;
export type BudgetType = (typeof BUDGET_TYPES)[number];
+export const UPCOMING_SCHEDULED_TRANSACTION_LENGTHS = [
+ '1',
+ '7',
+ '14',
+ '30',
+] as const;
+export type UpcomingScheduledTransactionLength =
+ (typeof UPCOMING_SCHEDULED_TRANSACTION_LENGTHS)[number];
+
let prefs: MetadataPrefs = null;
export async function loadPrefs(id?: string): Promise<MetadataPrefs> {
diff --git a/packages/loot-core/src/server/schedules/app.ts b/packages/loot-core/src/server/schedules/app.ts
index 9440ab4d07..67f31d367c 100644
--- a/packages/loot-core/src/server/schedules/app.ts
+++ b/packages/loot-core/src/server/schedules/app.ts
@@ -5,22 +5,22 @@ import { v4 as uuidv4 } from 'uuid';
import { captureBreadcrumb } from '../../platform/exceptions';
import * as connection from '../../platform/server/connection';
-import { dayFromDate, currentDay, parseDate } from '../../shared/months';
+import { currentDay, dayFromDate, parseDate } from '../../shared/months';
import { q } from '../../shared/query';
import {
extractScheduleConds,
- recurConfigToRSchedule,
getHasTransactionsQuery,
- getStatus,
getScheduledAmount,
+ getStatus,
+ recurConfigToRSchedule,
} from '../../shared/schedules';
-import { Rule, Condition } from '../accounts/rules';
+import { Condition, Rule } from '../accounts/rules';
import { addTransactions } from '../accounts/sync';
import {
- insertRule,
- updateRule,
getRules,
+ insertRule,
ruleModel,
+ updateRule,
} from '../accounts/transaction-rules';
import { createApp } from '../app';
import { runQuery as aqlQuery } from '../aql';
@@ -360,6 +360,7 @@ async function skipNextDate({ id }) {
},
});
}
+
function discoverSchedules() {
return findSchedules();
}
@@ -480,11 +481,20 @@ async function advanceSchedulesService(syncSuccess) {
const failedToPost = [];
let didPost = false;
+ const { data: upcomingLength } = await aqlQuery(
+ q('preferences')
+ .filter({ id: 'upcomingScheduledTransactionLength' })
+ .select('value'),
+ );
+
+ const upcomingLengthValue = upcomingLength[0]?.value ?? '7'; // Default to 7 days if not set
+
for (const schedule of schedules) {
const status = getStatus(
schedule.next_date,
schedule.completed,
hasTrans.has(schedule.id),
+ upcomingLengthValue,
);
if (status === 'paid') {
diff --git a/packages/loot-core/src/shared/schedules.test.ts b/packages/loot-core/src/shared/schedules.test.ts
index 68fff3556e..67f82e6ce8 100644
--- a/packages/loot-core/src/shared/schedules.test.ts
+++ b/packages/loot-core/src/shared/schedules.test.ts
@@ -1,287 +1,342 @@
import MockDate from 'mockdate';
-import { getRecurringDescription } from './schedules';
+import * as monthUtils from './months';
+import { getRecurringDescription, getStatus } from './schedules';
+
+describe('schedules', () => {
+ const today = new Date(2017, 0, 1); // Global date when testing is set to 2017-01-01 per monthUtils.currentDay()
+ const dateFormat = 'yyyy-MM-dd';
+ const todayString = monthUtils.format(today, dateFormat);
-describe('recurring date description', () => {
beforeEach(() => {
MockDate.set(new Date(2021, 4, 14));
});
+ afterEach(() => {
+ MockDate.reset();
+ });
+
+ describe('getStatus', () => {
+ it('returns completed if completed', () => {
+ expect(getStatus(todayString, true, false, '7')).toBe('completed');
+ });
+
+ it('returns paid if has transactions', () => {
+ expect(getStatus(todayString, false, true, '7')).toBe('paid');
+ });
+
+ it('returns due if today', () => {
+ expect(getStatus(todayString, false, false, '7')).toBe('due');
+ });
+
+ it.each([1, 7, 14, 30])(
+ 'returns upcoming if within upcoming range %n',
+ (upcomingLength: number) => {
+ const daysOut = upcomingLength;
+ const tomorrow = monthUtils.addDays(today, 1);
+ const upcomingDate = monthUtils.addDays(today, daysOut);
+ const scheduledDate = monthUtils.addDays(today, daysOut + 1);
+ expect(
+ getStatus(tomorrow, false, false, upcomingLength.toString()),
+ ).toBe('upcoming');
+ expect(
+ getStatus(upcomingDate, false, false, upcomingLength.toString()),
+ ).toBe('upcoming');
+ expect(
+ getStatus(scheduledDate, false, false, upcomingLength.toString()),
+ ).toBe('scheduled');
+ },
+ );
- it('describes weekly interval', () => {
- expect(
- getRecurringDescription(
- { start: '2021-05-17', frequency: 'weekly' },
- 'MM/dd/yyyy',
- ),
- ).toBe('Every week on Monday');
+ it('returns missed if past', () => {
+ expect(getStatus(monthUtils.addDays(today, -1), false, false, '7')).toBe(
+ 'missed',
+ );
+ });
- expect(
- getRecurringDescription(
- {
- start: '2021-05-17',
- frequency: 'weekly',
- interval: 2,
- },
- 'MM/dd/yyyy',
- ),
- ).toBe('Every 2 weeks on Monday');
+ it('returns scheduled if not due, upcoming, or missed', () => {
+ expect(getStatus(monthUtils.addDays(today, 8), false, false, '7')).toBe(
+ 'scheduled',
+ );
+ });
});
- it('describes monthly interval', () => {
- expect(
- getRecurringDescription(
- { start: '2021-04-25', frequency: 'monthly' },
- 'MM/dd/yyyy',
- ),
- ).toBe('Every month on the 25th');
+ describe('getRecurringDescription', () => {
+ it('describes weekly interval', () => {
+ expect(
+ getRecurringDescription(
+ { start: '2021-05-17', frequency: 'weekly' },
+ 'MM/dd/yyyy',
+ ),
+ ).toBe('Every week on Monday');
- expect(
- getRecurringDescription(
- {
- start: '2021-04-25',
- frequency: 'monthly',
- interval: 2,
- },
- 'MM/dd/yyyy',
- ),
- ).toBe('Every 2 months on the 25th');
+ expect(
+ getRecurringDescription(
+ {
+ start: '2021-05-17',
+ frequency: 'weekly',
+ interval: 2,
+ },
+ 'MM/dd/yyyy',
+ ),
+ ).toBe('Every 2 weeks on Monday');
+ });
- expect(
- getRecurringDescription(
- {
- start: '2021-04-25',
- frequency: 'monthly',
- patterns: [{ type: 'day', value: 25 }],
- },
- 'MM/dd/yyyy',
- ),
- ).toBe('Every month on the 25th');
+ it('describes monthly interval', () => {
+ expect(
+ getRecurringDescription(
+ { start: '2021-04-25', frequency: 'monthly' },
+ 'MM/dd/yyyy',
+ ),
+ ).toBe('Every month on the 25th');
- expect(
- getRecurringDescription(
- {
- start: '2021-04-25',
- frequency: 'monthly',
- interval: 2,
- patterns: [{ type: 'day', value: 25 }],
- },
- 'MM/dd/yyyy',
- ),
- ).toBe('Every 2 months on the 25th');
+ expect(
+ getRecurringDescription(
+ {
+ start: '2021-04-25',
+ frequency: 'monthly',
+ interval: 2,
+ },
+ 'MM/dd/yyyy',
+ ),
+ ).toBe('Every 2 months on the 25th');
- // Last day should work
- expect(
- getRecurringDescription(
- {
- start: '2021-04-25',
- frequency: 'monthly',
- patterns: [{ type: 'day', value: 31 }],
- },
- 'MM/dd/yyyy',
- ),
- ).toBe('Every month on the 31st');
+ expect(
+ getRecurringDescription(
+ {
+ start: '2021-04-25',
+ frequency: 'monthly',
+ patterns: [{ type: 'day', value: 25 }],
+ },
+ 'MM/dd/yyyy',
+ ),
+ ).toBe('Every month on the 25th');
- // -1 should work, representing the last day
- expect(
- getRecurringDescription(
- {
- start: '2021-04-25',
- frequency: 'monthly',
- patterns: [{ type: 'day', value: -1 }],
- },
- 'MM/dd/yyyy',
- ),
- ).toBe('Every month on the last day');
+ expect(
+ getRecurringDescription(
+ {
+ start: '2021-04-25',
+ frequency: 'monthly',
+ interval: 2,
+ patterns: [{ type: 'day', value: 25 }],
+ },
+ 'MM/dd/yyyy',
+ ),
+ ).toBe('Every 2 months on the 25th');
- // Day names should work
- expect(
- getRecurringDescription(
- {
- start: '2021-04-25',
- frequency: 'monthly',
- patterns: [{ type: 'FR', value: 2 }],
- },
- 'MM/dd/yyyy',
- ),
- ).toBe('Every month on the 2nd Friday');
+ // Last day should work
+ expect(
+ getRecurringDescription(
+ {
+ start: '2021-04-25',
+ frequency: 'monthly',
+ patterns: [{ type: 'day', value: 31 }],
+ },
+ 'MM/dd/yyyy',
+ ),
+ ).toBe('Every month on the 31st');
- expect(
- getRecurringDescription(
- {
- start: '2021-04-25',
- frequency: 'monthly',
- patterns: [{ type: 'FR', value: -1 }],
- },
- 'MM/dd/yyyy',
- ),
- ).toBe('Every month on the last Friday');
- });
+ // -1 should work, representing the last day
+ expect(
+ getRecurringDescription(
+ {
+ start: '2021-04-25',
+ frequency: 'monthly',
+ patterns: [{ type: 'day', value: -1 }],
+ },
+ 'MM/dd/yyyy',
+ ),
+ ).toBe('Every month on the last day');
- it('describes monthly interval with multiple days', () => {
- // Note how order doesn't matter - the day should be sorted
- expect(
- getRecurringDescription(
- {
- start: '2021-04-25',
- frequency: 'monthly',
- patterns: [
- { type: 'day', value: 15 },
- { type: 'day', value: 3 },
- { type: 'day', value: 20 },
- ],
- },
- 'MM/dd/yyyy',
- ),
- ).toBe('Every month on the 3rd, 15th, and 20th');
+ // Day names should work
+ expect(
+ getRecurringDescription(
+ {
+ start: '2021-04-25',
+ frequency: 'monthly',
+ patterns: [{ type: 'FR', value: 2 }],
+ },
+ 'MM/dd/yyyy',
+ ),
+ ).toBe('Every month on the 2nd Friday');
- expect(
- getRecurringDescription(
- {
- start: '2021-04-25',
- frequency: 'monthly',
- patterns: [
- { type: 'day', value: 3 },
- { type: 'day', value: -1 },
- { type: 'day', value: 20 },
- ],
- },
- 'MM/dd/yyyy',
- ),
- ).toBe('Every month on the 3rd, 20th, and last day');
+ expect(
+ getRecurringDescription(
+ {
+ start: '2021-04-25',
+ frequency: 'monthly',
+ patterns: [{ type: 'FR', value: -1 }],
+ },
+ 'MM/dd/yyyy',
+ ),
+ ).toBe('Every month on the last Friday');
+ });
- // Mix days and day names
- expect(
- getRecurringDescription(
- {
- start: '2021-04-25',
- frequency: 'monthly',
- patterns: [
- { type: 'day', value: 3 },
- { type: 'day', value: -1 },
- { type: 'FR', value: 2 },
- ],
- },
- 'MM/dd/yyyy',
- ),
- ).toBe('Every month on the 2nd Friday, 3rd, and last day');
+ it('describes monthly interval with multiple days', () => {
+ // Note how order doesn't matter - the day should be sorted
+ expect(
+ getRecurringDescription(
+ {
+ start: '2021-04-25',
+ frequency: 'monthly',
+ patterns: [
+ { type: 'day', value: 15 },
+ { type: 'day', value: 3 },
+ { type: 'day', value: 20 },
+ ],
+ },
+ 'MM/dd/yyyy',
+ ),
+ ).toBe('Every month on the 3rd, 15th, and 20th');
- // When there is a mixture of types, day names should always come first
- expect(
- getRecurringDescription(
- {
- start: '2021-04-25',
- frequency: 'monthly',
- patterns: [
- { type: 'SA', value: 1 },
- { type: 'day', value: 2 },
- { type: 'FR', value: 3 },
- { type: 'day', value: 10 },
- ],
- },
- 'MM/dd/yyyy',
- ),
- ).toBe('Every month on the 1st Saturday, 3rd Friday, 2nd, and 10th');
- });
+ expect(
+ getRecurringDescription(
+ {
+ start: '2021-04-25',
+ frequency: 'monthly',
+ patterns: [
+ { type: 'day', value: 3 },
+ { type: 'day', value: -1 },
+ { type: 'day', value: 20 },
+ ],
+ },
+ 'MM/dd/yyyy',
+ ),
+ ).toBe('Every month on the 3rd, 20th, and last day');
- it('describes yearly interval', () => {
- expect(
- getRecurringDescription(
- { start: '2021-05-17', frequency: 'yearly' },
- 'MM/dd/yyyy',
- ),
- ).toBe('Every year on May 17th');
+ // Mix days and day names
+ expect(
+ getRecurringDescription(
+ {
+ start: '2021-04-25',
+ frequency: 'monthly',
+ patterns: [
+ { type: 'day', value: 3 },
+ { type: 'day', value: -1 },
+ { type: 'FR', value: 2 },
+ ],
+ },
+ 'MM/dd/yyyy',
+ ),
+ ).toBe('Every month on the 2nd Friday, 3rd, and last day');
- expect(
- getRecurringDescription(
- {
- start: '2021-05-17',
- frequency: 'yearly',
- interval: 2,
- },
- 'MM/dd/yyyy',
- ),
- ).toBe('Every 2 years on May 17th');
- });
+ // When there is a mixture of types, day names should always come first
+ expect(
+ getRecurringDescription(
+ {
+ start: '2021-04-25',
+ frequency: 'monthly',
+ patterns: [
+ { type: 'SA', value: 1 },
+ { type: 'day', value: 2 },
+ { type: 'FR', value: 3 },
+ { type: 'day', value: 10 },
+ ],
+ },
+ 'MM/dd/yyyy',
+ ),
+ ).toBe('Every month on the 1st Saturday, 3rd Friday, 2nd, and 10th');
+ });
- it('describes intervals with limited occurrences', () => {
- expect(
- getRecurringDescription(
- {
- start: '2021-05-17',
- frequency: 'weekly',
- interval: 2,
- endMode: 'after_n_occurrences',
- endOccurrences: 2,
- },
- 'MM/dd/yyyy',
- ),
- ).toBe('Every 2 weeks on Monday, 2 times');
+ it('describes yearly interval', () => {
+ expect(
+ getRecurringDescription(
+ { start: '2021-05-17', frequency: 'yearly' },
+ 'MM/dd/yyyy',
+ ),
+ ).toBe('Every year on May 17th');
- expect(
- getRecurringDescription(
- {
- start: '2021-05-17',
- frequency: 'weekly',
- interval: 2,
- endMode: 'after_n_occurrences',
- endOccurrences: 1,
- },
- 'MM/dd/yyyy',
- ),
- ).toBe('Every 2 weeks on Monday, once');
+ expect(
+ getRecurringDescription(
+ {
+ start: '2021-05-17',
+ frequency: 'yearly',
+ interval: 2,
+ },
+ 'MM/dd/yyyy',
+ ),
+ ).toBe('Every 2 years on May 17th');
+ });
- expect(
- getRecurringDescription(
- {
- start: '2021-05-17',
- frequency: 'monthly',
- interval: 2,
- endMode: 'after_n_occurrences',
- endOccurrences: 2,
- },
- 'MM/dd/yyyy',
- ),
- ).toBe('Every 2 months on the 17th, 2 times');
+ it('describes intervals with limited occurrences', () => {
+ expect(
+ getRecurringDescription(
+ {
+ start: '2021-05-17',
+ frequency: 'weekly',
+ interval: 2,
+ endMode: 'after_n_occurrences',
+ endOccurrences: 2,
+ },
+ 'MM/dd/yyyy',
+ ),
+ ).toBe('Every 2 weeks on Monday, 2 times');
- expect(
- getRecurringDescription(
- {
- start: '2021-05-17',
- frequency: 'yearly',
- interval: 2,
- endMode: 'after_n_occurrences',
- endOccurrences: 2,
- },
- 'MM/dd/yyyy',
- ),
- ).toBe('Every 2 years on May 17th, 2 times');
- });
+ expect(
+ getRecurringDescription(
+ {
+ start: '2021-05-17',
+ frequency: 'weekly',
+ interval: 2,
+ endMode: 'after_n_occurrences',
+ endOccurrences: 1,
+ },
+ 'MM/dd/yyyy',
+ ),
+ ).toBe('Every 2 weeks on Monday, once');
+
+ expect(
+ getRecurringDescription(
+ {
+ start: '2021-05-17',
+ frequency: 'monthly',
+ interval: 2,
+ endMode: 'after_n_occurrences',
+ endOccurrences: 2,
+ },
+ 'MM/dd/yyyy',
+ ),
+ ).toBe('Every 2 months on the 17th, 2 times');
+
+ expect(
+ getRecurringDescription(
+ {
+ start: '2021-05-17',
+ frequency: 'yearly',
+ interval: 2,
+ endMode: 'after_n_occurrences',
+ endOccurrences: 2,
+ },
+ 'MM/dd/yyyy',
+ ),
+ ).toBe('Every 2 years on May 17th, 2 times');
+ });
- it('describes intervals with an end date', () => {
- expect(
- getRecurringDescription(
- {
- start: '2021-05-17',
- frequency: 'weekly',
- interval: 2,
- endMode: 'on_date',
- endDate: '2021-06-01',
- },
- 'MM/dd/yyyy',
- ),
- ).toBe('Every 2 weeks on Monday, until 06/01/2021');
+ it('describes intervals with an end date', () => {
+ expect(
+ getRecurringDescription(
+ {
+ start: '2021-05-17',
+ frequency: 'weekly',
+ interval: 2,
+ endMode: 'on_date',
+ endDate: '2021-06-01',
+ },
+ 'MM/dd/yyyy',
+ ),
+ ).toBe('Every 2 weeks on Monday, until 06/01/2021');
- expect(
- getRecurringDescription(
- {
- start: '2021-05-17',
- frequency: 'monthly',
- interval: 2,
- endMode: 'on_date',
- endDate: '2021-06-01',
- },
- 'yyyy-MM-dd',
- ),
- ).toBe('Every 2 months on the 17th, until 2021-06-01');
+ expect(
+ getRecurringDescription(
+ {
+ start: '2021-05-17',
+ frequency: 'monthly',
+ interval: 2,
+ endMode: 'on_date',
+ endDate: '2021-06-01',
+ },
+ 'yyyy-MM-dd',
+ ),
+ ).toBe('Every 2 months on the 17th, until 2021-06-01');
+ });
});
});
diff --git a/packages/loot-core/src/shared/schedules.ts b/packages/loot-core/src/shared/schedules.ts
index 2a52c23d51..42f88b930f 100644
--- a/packages/loot-core/src/shared/schedules.ts
+++ b/packages/loot-core/src/shared/schedules.ts
@@ -8,16 +8,19 @@ export function getStatus(
nextDate: string,
completed: boolean,
hasTrans: boolean,
+ upcomingLength: string,
) {
const today = monthUtils.currentDay();
-
if (completed) {
return 'completed';
} else if (hasTrans) {
return 'paid';
} else if (nextDate === today) {
return 'due';
- } else if (nextDate > today && nextDate <= monthUtils.addDays(today, 7)) {
+ } else if (
+ nextDate > today &&
+ nextDate <= monthUtils.addDays(today, parseInt(upcomingLength ?? '7'))
+ ) {
return 'upcoming';
} else if (nextDate < today) {
return 'missed';
diff --git a/packages/loot-core/src/types/prefs.d.ts b/packages/loot-core/src/types/prefs.d.ts
index 76d7990bfc..8817cc3b50 100644
--- a/packages/loot-core/src/types/prefs.d.ts
+++ b/packages/loot-core/src/types/prefs.d.ts
@@ -11,6 +11,7 @@ export type FeatureFlag =
export type SyncedPrefs = Partial<
Record<
| 'budgetType'
+ | 'upcomingScheduledTransactionLength'
| 'firstDayOfWeekIdx'
| 'dateFormat'
| 'numberFormat'
diff --git a/upcoming-release-notes/3310.md b/upcoming-release-notes/3310.md
new file mode 100644
index 0000000000..ec34a4bf09
--- /dev/null
+++ b/upcoming-release-notes/3310.md
@@ -0,0 +1,6 @@
+---
+category: Enhancements
+authors: [ SamBobBarnes ]
+---
+
+Add option to set how far out the upcoming scheduled transactions are shown in the account view.