A local-first personal finance app
add warning when schedule/save by automation priorities don't match (#8088)
Matt Fiddaman1ac8b21089a8
diff --git a/packages/desktop-client/src/components/budget/goals/automationMessages.tsx b/packages/desktop-client/src/components/budget/goals/automationMessages.tsxindex e450bc0295..e47655d845 100644--- a/packages/desktop-client/src/components/budget/goals/automationMessages.tsx+++ b/packages/desktop-client/src/components/budget/goals/automationMessages.tsx@@ -187,6 +187,13 @@ export function GlobalConflictTitle({income</Trans>);+ case 'schedule-priority-mismatch':+ return (+ <Trans>+ All <i>cover schedule</i> and <i>save by date</i> automations must use+ the same priority+ </Trans>+ );default:conflict satisfies never;return null;@@ -216,6 +223,8 @@ export function GlobalConflictDetail({at 100%.</Trans>);+ case 'schedule-priority-mismatch':+ return null;default:conflict satisfies never;return null;diff --git a/packages/desktop-client/src/components/budget/goals/validateAutomation.test.ts b/packages/desktop-client/src/components/budget/goals/validateAutomation.test.tsindex 1f4fc70575..89c64f8b00 100644--- a/packages/desktop-client/src/components/budget/goals/validateAutomation.test.ts+++ b/packages/desktop-client/src/components/budget/goals/validateAutomation.test.ts@@ -5,6 +5,7 @@ import { describe, expect, it } from 'vitest';import {validateAutomation,validatePercentageAllocation,+ validateSchedulePriorities,} from './validateAutomation';function percent(@@ -211,3 +212,53 @@ describe('validateAutomation adjustment range', () => {).toEqual({ kind: 'schedule-not-found', name: 'Rent' });});});++describe('validateSchedulePriorities', () => {+ function scheduleAt(name: string, priority: number): Template {+ return { type: 'schedule', name, directive: 'template', priority };+ }+ function byAt(priority: number): Template {+ return {+ type: 'by',+ amount: 100,+ month: '2026-12',+ directive: 'template',+ priority,+ };+ }++ it('returns null when there are no schedule or by templates', () => {+ expect(validateSchedulePriorities([])).toBeNull();+ });++ it('returns null for a single schedule', () => {+ expect(validateSchedulePriorities([scheduleAt('Rent', 1)])).toBeNull();+ });++ it('returns null when all schedules share a priority', () => {+ expect(+ validateSchedulePriorities([scheduleAt('Rent', 2), scheduleAt('Gym', 2)]),+ ).toBeNull();+ });++ it('flags schedules with mismatched priorities', () => {+ expect(+ validateSchedulePriorities([scheduleAt('Rent', 1), scheduleAt('Gym', 2)]),+ ).toEqual({ kind: 'schedule-priority-mismatch' });+ });++ it('flags a schedule and a by-date with mismatched priorities', () => {+ expect(+ validateSchedulePriorities([scheduleAt('Rent', 1), byAt(2)]),+ ).toEqual({ kind: 'schedule-priority-mismatch' });+ });++ it('ignores priorities of other automation types', () => {+ expect(+ validateSchedulePriorities([+ scheduleAt('Rent', 1),+ percent('Salary', 10),+ ]),+ ).toBeNull();+ });+});diff --git a/packages/desktop-client/src/components/budget/goals/validateAutomation.ts b/packages/desktop-client/src/components/budget/goals/validateAutomation.tsindex 3f9009b6b8..fadb3bc8fa 100644--- a/packages/desktop-client/src/components/budget/goals/validateAutomation.ts+++ b/packages/desktop-client/src/components/budget/goals/validateAutomation.ts@@ -30,7 +30,8 @@ function isAdjustmentOutOfRange(template: Template): boolean {export type GlobalConflictKind =| { kind: 'over-income'; total: number; income: number }- | { kind: 'percent-over-100'; total: number };+ | { kind: 'percent-over-100'; total: number }+ | { kind: 'schedule-priority-mismatch' };export function validateAutomation(template: Template,@@ -150,3 +151,19 @@ export function validatePercentageAllocation(? { kind: 'percent-over-100', total: maxPercent }: null;}++// The engine (CategoryTemplateContext.checkByAndScheduleAndSpend) requires+// every schedule and by-date template in a category to share one priority; if+// they don't, none of them budget. Surface that as a conflict so it can't be+// saved.+export function validateSchedulePriorities(+ templates: readonly Template[],+): GlobalConflictKind | null {+ const priorities = new Set<number>();+ for (const t of templates) {+ if (t.type === 'schedule' || t.type === 'by') {+ priorities.add(t.priority);+ }+ }+ return priorities.size > 1 ? { kind: 'schedule-priority-mismatch' } : null;+}diff --git a/packages/desktop-client/src/components/modals/BudgetAutomationsModal/BudgetAutomationsBody.tsx b/packages/desktop-client/src/components/modals/BudgetAutomationsModal/BudgetAutomationsBody.tsxindex 5eeceeb453..36fa19c853 100644--- a/packages/desktop-client/src/components/modals/BudgetAutomationsModal/BudgetAutomationsBody.tsx+++ b/packages/desktop-client/src/components/modals/BudgetAutomationsModal/BudgetAutomationsBody.tsx@@ -35,6 +35,7 @@ import { formatMonthLabel } from '#components/budget/goals/formatMonthLabel';import {validateAutomation,validatePercentageAllocation,+ validateSchedulePriorities,} from '#components/budget/goals/validateAutomation';import { Link } from '#components/common/Link';import { useCleanupGroups } from '#hooks/useCleanupGroups';@@ -348,7 +349,10 @@ export function BudgetAutomationsBody({dryRun?.perTemplate?.[i] != null ? dryRun.perTemplate[i] : null,);const hasErrors = automationErrors.some(error => error !== null);- const conflict = validatePercentageAllocation(templates);+ const conflicts = [+ validatePercentageAllocation(templates),+ validateSchedulePriorities(templates),+ ].filter(conflict => conflict !== null);const categoryNameMap: Record<string, string> = {};for (const group of categories) {@@ -465,7 +469,9 @@ export function BudgetAutomationsBody({/>)}- {conflict && <ConflictBanner conflict={conflict} />}+ {conflicts.map((conflict, i) => (+ <ConflictBanner key={i} conflict={conflict} />+ ))}<Viewstyle={{@@ -627,7 +633,7 @@ export function BudgetAutomationsBody({<Buttonvariant="primary"onPress={onSave}- isDisabled={hasErrors || conflict !== null || saving}+ isDisabled={hasErrors || conflicts.length > 0 || saving}><Trans>Save</Trans></Button>diff --git a/upcoming-release-notes/8088.md b/upcoming-release-notes/8088.mdnew file mode 100644index 0000000000..36fa33b413--- /dev/null+++ b/upcoming-release-notes/8088.md@@ -0,0 +1,6 @@+---+category: Enhancements+authors: [matt-fidd]+---++Automation UI: Add warning when schedule/save by automation priorities don't match