Skip to content

A local-first personal finance app

automation UI: add goal template functionality (#7792)

Matt Fiddaman70716a59da87
diff --git a/packages/desktop-client/src/components/budget/goals/ActiveEditor.tsx b/packages/desktop-client/src/components/budget/goals/ActiveEditor.tsx
index ad122704f0..306964ca85 100644
--- a/packages/desktop-client/src/components/budget/goals/ActiveEditor.tsx
+++ b/packages/desktop-client/src/components/budget/goals/ActiveEditor.tsx
@@ -9,6 +9,7 @@ import { BySaveAutomation } from './editor/BySaveAutomation';
import { FixedAutomation } from './editor/FixedAutomation';
import { HistoricalAutomation } from './editor/HistoricalAutomation';
import { LimitAutomation } from './editor/LimitAutomation';
+import { LongTermGoalAutomation } from './editor/LongTermGoalAutomation';
import { PercentageAutomation } from './editor/PercentageAutomation';
import { RefillAutomation } from './editor/RefillAutomation';
import { RemainderAutomation } from './editor/RemainderAutomation';
@@ -69,6 +70,10 @@ export function ActiveEditor({
return (
<RemainderAutomation template={state.template} dispatch={dispatch} />
);
+ case 'goal':
+ return (
+ <LongTermGoalAutomation template={state.template} dispatch={dispatch} />
+ );
default:
state satisfies never;
return null;
diff --git a/packages/desktop-client/src/components/budget/goals/BudgetAutomationEditor.tsx b/packages/desktop-client/src/components/budget/goals/BudgetAutomationEditor.tsx
index 23c2d643d4..a78955fc27 100644
--- a/packages/desktop-client/src/components/budget/goals/BudgetAutomationEditor.tsx
+++ b/packages/desktop-client/src/components/budget/goals/BudgetAutomationEditor.tsx
@@ -23,6 +23,7 @@ import { BySaveAutomation } from './editor/BySaveAutomation';
import { FixedAutomation } from './editor/FixedAutomation';
import { HistoricalAutomation } from './editor/HistoricalAutomation';
import { LimitAutomation } from './editor/LimitAutomation';
+import { LongTermGoalAutomation } from './editor/LongTermGoalAutomation';
import { PercentageAutomation } from './editor/PercentageAutomation';
import { RefillAutomation } from './editor/RefillAutomation';
import { RemainderAutomation } from './editor/RemainderAutomation';
@@ -95,6 +96,13 @@ const displayTypeToDescription = {
Higher weights take a larger share of the leftover funds.
</Trans>
),
+ goal: (
+ <Trans>
+ Set a long-term savings target. This changes the coloring of the balance
+ on the budget page to be based on progress towards the target rather than
+ the current month funding progress.
+ </Trans>
+ ),
};
export function BudgetAutomationEditor({
@@ -161,6 +169,11 @@ export function BudgetAutomationEditor({
<RemainderAutomation template={state.template} dispatch={dispatch} />
);
break;
+ case 'goal':
+ automationEditor = (
+ <LongTermGoalAutomation template={state.template} dispatch={dispatch} />
+ );
+ break;
default:
state satisfies never;
automationEditor = (
diff --git a/packages/desktop-client/src/components/budget/goals/BudgetAutomationReadOnly.tsx b/packages/desktop-client/src/components/budget/goals/BudgetAutomationReadOnly.tsx
index ec46d7da11..a6119e6928 100644
--- a/packages/desktop-client/src/components/budget/goals/BudgetAutomationReadOnly.tsx
+++ b/packages/desktop-client/src/components/budget/goals/BudgetAutomationReadOnly.tsx
@@ -18,6 +18,7 @@ import { BySaveAutomationReadOnly } from './editor/BySaveAutomationReadOnly';
import { FixedAutomationReadOnly } from './editor/FixedAutomationReadOnly';
import { HistoricalAutomationReadOnly } from './editor/HistoricalAutomationReadOnly';
import { LimitAutomationReadOnly } from './editor/LimitAutomationReadOnly';
+import { LongTermGoalAutomationReadOnly } from './editor/LongTermGoalAutomationReadOnly';
import { PercentageAutomationReadOnly } from './editor/PercentageAutomationReadOnly';
import { RefillAutomationReadOnly } from './editor/RefillAutomationReadOnly';
import { RemainderAutomationReadOnly } from './editor/RemainderAutomationReadOnly';
@@ -87,6 +88,11 @@ export function BudgetAutomationReadOnly({
<RemainderAutomationReadOnly template={state.template} />
);
break;
+ case 'goal':
+ automationReadOnly = (
+ <LongTermGoalAutomationReadOnly template={state.template} />
+ );
+ break;
default:
state satisfies never;
automationReadOnly = (
diff --git a/packages/desktop-client/src/components/budget/goals/TemplateSentence.tsx b/packages/desktop-client/src/components/budget/goals/TemplateSentence.tsx
index 925c74af41..2d95369d7a 100644
--- a/packages/desktop-client/src/components/budget/goals/TemplateSentence.tsx
+++ b/packages/desktop-client/src/components/budget/goals/TemplateSentence.tsx
@@ -7,6 +7,7 @@ import { BySaveAutomationReadOnly } from './editor/BySaveAutomationReadOnly';
import { FixedAutomationReadOnly } from './editor/FixedAutomationReadOnly';
import { HistoricalAutomationReadOnly } from './editor/HistoricalAutomationReadOnly';
import { LimitAutomationReadOnly } from './editor/LimitAutomationReadOnly';
+import { LongTermGoalAutomationReadOnly } from './editor/LongTermGoalAutomationReadOnly';
import { PercentageAutomationReadOnly } from './editor/PercentageAutomationReadOnly';
import { RefillAutomationReadOnly } from './editor/RefillAutomationReadOnly';
import { RemainderAutomationReadOnly } from './editor/RemainderAutomationReadOnly';
@@ -44,9 +45,10 @@ export function TemplateSentence({
return <BySaveAutomationReadOnly template={template} />;
case 'remainder':
return <RemainderAutomationReadOnly template={template} />;
+ case 'goal':
+ return <LongTermGoalAutomationReadOnly template={template} />;
case 'simple':
case 'spend':
- case 'goal':
case 'error': {
const type = template.type;
return (
diff --git a/packages/desktop-client/src/components/budget/goals/constants.ts b/packages/desktop-client/src/components/budget/goals/constants.ts
index 2f11a7c4f1..1422b29e2e 100644
--- a/packages/desktop-client/src/components/budget/goals/constants.ts
+++ b/packages/desktop-client/src/components/budget/goals/constants.ts
@@ -2,6 +2,7 @@ import type {
AverageTemplate,
ByTemplate,
CopyTemplate,
+ GoalTemplate,
LimitTemplate,
PercentageTemplate,
PeriodicTemplate,
@@ -19,6 +20,7 @@ export const displayTemplateTypes = [
'limit',
'refill',
'remainder',
+ 'goal',
] as const;
export type DisplayTemplateType = (typeof displayTemplateTypes)[number];
@@ -55,4 +57,8 @@ export type ReducerState =
| {
template: RemainderTemplate;
displayType: 'remainder';
+ }
+ | {
+ template: GoalTemplate;
+ displayType: 'goal';
};
diff --git a/packages/desktop-client/src/components/budget/goals/displayTemplateMeta.ts b/packages/desktop-client/src/components/budget/goals/displayTemplateMeta.ts
index 8832f4e27f..6950ea6fb2 100644
--- a/packages/desktop-client/src/components/budget/goals/displayTemplateMeta.ts
+++ b/packages/desktop-client/src/components/budget/goals/displayTemplateMeta.ts
@@ -3,6 +3,7 @@ import type { ComponentType, SVGProps } from 'react';
import {
SvgChartPie,
SvgEquals,
+ SvgFlag,
SvgMoneyBag,
SvgPiggyBank,
SvgShare,
@@ -86,6 +87,14 @@ export function getDisplayTemplateMeta(
),
icon: SvgShare,
};
+ case 'goal':
+ return {
+ label: t('Long-term goal'),
+ description: t(
+ 'Set a long-term savings target. This changes the coloring of the balance on the budget page to be based on progress towards the target rather than the current month funding progress.',
+ ),
+ icon: SvgFlag,
+ };
default:
displayType satisfies never;
throw new Error(`Unknown display type: ${String(displayType)}`);
diff --git a/packages/desktop-client/src/components/budget/goals/editor/LongTermGoalAutomation.tsx b/packages/desktop-client/src/components/budget/goals/editor/LongTermGoalAutomation.tsx
new file mode 100644
index 0000000000..a790077344
--- /dev/null
+++ b/packages/desktop-client/src/components/budget/goals/editor/LongTermGoalAutomation.tsx
@@ -0,0 +1,49 @@
+import { useTranslation } from 'react-i18next';
+
+import { SpaceBetween } from '@actual-app/components/space-between';
+import { amountToInteger, integerToAmount } from '@actual-app/core/shared/util';
+import type { GoalTemplate } from '@actual-app/core/types/models/templates';
+
+import { updateTemplate } from '#components/budget/goals/actions';
+import type { Action } from '#components/budget/goals/actions';
+import { FormField, FormLabel } from '#components/forms';
+import { AmountInput } from '#components/util/AmountInput';
+import { useFormat } from '#hooks/useFormat';
+
+type LongTermGoalAutomationProps = {
+ template: GoalTemplate;
+ dispatch: (action: Action) => void;
+};
+
+export function LongTermGoalAutomation({
+ template,
+ dispatch,
+}: LongTermGoalAutomationProps) {
+ const { t } = useTranslation();
+ const format = useFormat();
+ const amount = amountToInteger(
+ template.amount,
+ format.currency.decimalPlaces,
+ );
+
+ return (
+ <SpaceBetween align="center" gap={10} style={{ marginTop: 10 }}>
+ <FormField style={{ flex: 1 }}>
+ <FormLabel title={t('Target amount')} htmlFor="goal-amount-field" />
+ <AmountInput
+ id="goal-amount-field"
+ value={amount}
+ sign="+"
+ onUpdate={(value: number) =>
+ dispatch(
+ updateTemplate({
+ type: 'goal',
+ amount: integerToAmount(value, format.currency.decimalPlaces),
+ }),
+ )
+ }
+ />
+ </FormField>
+ </SpaceBetween>
+ );
+}
diff --git a/packages/desktop-client/src/components/budget/goals/editor/LongTermGoalAutomationReadOnly.tsx b/packages/desktop-client/src/components/budget/goals/editor/LongTermGoalAutomationReadOnly.tsx
new file mode 100644
index 0000000000..fce489678c
--- /dev/null
+++ b/packages/desktop-client/src/components/budget/goals/editor/LongTermGoalAutomationReadOnly.tsx
@@ -0,0 +1,29 @@
+import { Trans } from 'react-i18next';
+
+import { amountToInteger } from '@actual-app/core/shared/util';
+import type { GoalTemplate } from '@actual-app/core/types/models/templates';
+import type { TransObjectLiteral } from '@actual-app/core/types/util';
+
+import { FinancialText } from '#components/FinancialText';
+import { useFormat } from '#hooks/useFormat';
+
+type LongTermGoalAutomationReadOnlyProps = {
+ template: GoalTemplate;
+};
+
+export function LongTermGoalAutomationReadOnly({
+ template,
+}: LongTermGoalAutomationReadOnlyProps) {
+ const format = useFormat();
+ const amount = format(
+ amountToInteger(template.amount, format.currency.decimalPlaces),
+ 'financial',
+ );
+
+ return (
+ <Trans>
+ Long-term goal of{' '}
+ <FinancialText>{{ amount } as TransObjectLiteral}</FinancialText>
+ </Trans>
+ );
+}
diff --git a/packages/desktop-client/src/components/budget/goals/reducer.ts b/packages/desktop-client/src/components/budget/goals/reducer.ts
index f2ced53bcc..b222cc6c5f 100644
--- a/packages/desktop-client/src/components/budget/goals/reducer.ts
+++ b/packages/desktop-client/src/components/budget/goals/reducer.ts
@@ -79,7 +79,10 @@ export const getInitialState = (template: Template | null): ReducerState => {
displayType: 'historical',
};
case 'goal':
- throw new Error('Goal is not yet supported');
+ return {
+ template,
+ displayType: 'goal',
+ };
case 'error':
throw new Error('An error occurred while parsing the template');
default:
@@ -212,6 +215,18 @@ const changeType = (
priority: null,
},
};
+ case 'goal':
+ if (prevState.template.type === 'goal') {
+ return prevState;
+ }
+ return {
+ displayType: visualType,
+ template: {
+ directive: 'goal',
+ type: 'goal',
+ amount: 1000,
+ },
+ };
default:
// Make sure we're not missing any cases
throw new Error(
diff --git a/packages/desktop-client/src/components/modals/BudgetAutomationsModal/BudgetAutomationsBody.tsx b/packages/desktop-client/src/components/modals/BudgetAutomationsModal/BudgetAutomationsBody.tsx
index 7093453c39..efe6f893b1 100644
--- a/packages/desktop-client/src/components/modals/BudgetAutomationsModal/BudgetAutomationsBody.tsx
+++ b/packages/desktop-client/src/components/modals/BudgetAutomationsModal/BudgetAutomationsBody.tsx
@@ -203,6 +203,22 @@ export function BudgetAutomationsBody({
});
};
+ const onAddGoalAutomation = () => {
+ const entry = createAutomationEntry(
+ {
+ directive: 'goal',
+ type: 'goal',
+ amount: 1000,
+ },
+ 'goal',
+ );
+ setEntries(prev => {
+ const next = [...prev, entry];
+ setActiveIdx(next.length - 1);
+ return next;
+ });
+ };
+
const onDelete = (index: number) => {
setEntries(prev => {
const next = prev.filter((_, i) => i !== index);
@@ -312,14 +328,15 @@ export function BudgetAutomationsBody({
}
const hasLimitAutomation = entries.some(e => e.displayType === 'limit');
+ const hasGoalAutomation = entries.some(e => e.displayType === 'goal');
+ const isOption = (entry: AutomationEntry) =>
+ entry.displayType === 'limit' || entry.displayType === 'goal';
const indexedEntries = entries.map((entry, idx) => ({ entry, idx }));
const contributionEntries = indexedEntries.filter(
- ({ entry }) => entry.displayType !== 'limit',
- );
- const constraintEntries = indexedEntries.filter(
- ({ entry }) => entry.displayType === 'limit',
+ ({ entry }) => !isOption(entry),
);
+ const optionEntries = indexedEntries.filter(({ entry }) => isOption(entry));
const safeActiveIdx = Math.min(activeIdx, Math.max(0, entries.length - 1));
@@ -453,7 +470,7 @@ export function BudgetAutomationsBody({
<SidebarSectionHeader style={{ marginTop: 16 }}>
<Trans>Options</Trans>
</SidebarSectionHeader>
- {constraintEntries.map(({ entry, idx }) => (
+ {optionEntries.map(({ entry, idx }) => (
<AutomationListRow
key={entry.id}
index={idx}
@@ -470,9 +487,11 @@ export function BudgetAutomationsBody({
+ <Trans>Add balance cap</Trans>
</SidebarAddButton>
)}
- <SidebarPlaceholderRow>
- <Trans>Long-term goal (coming soon)</Trans>
- </SidebarPlaceholderRow>
+ {!hasGoalAutomation && (
+ <SidebarAddButton onPress={onAddGoalAutomation}>
+ + <Trans>Add long-term goal</Trans>
+ </SidebarAddButton>
+ )}
<SidebarPlaceholderRow>
<Trans>End of month cleanup (coming soon)</Trans>
</SidebarPlaceholderRow>
diff --git a/packages/desktop-client/src/components/modals/BudgetAutomationsModal/BudgetAutomationsModal.test.ts b/packages/desktop-client/src/components/modals/BudgetAutomationsModal/BudgetAutomationsModal.test.ts
index 13710acaf9..4292ae2854 100644
--- a/packages/desktop-client/src/components/modals/BudgetAutomationsModal/BudgetAutomationsModal.test.ts
+++ b/packages/desktop-client/src/components/modals/BudgetAutomationsModal/BudgetAutomationsModal.test.ts
@@ -26,16 +26,17 @@ describe('migrateTemplatesToAutomations', () => {
expect(migrateTemplatesToAutomations([simpleTemplate])).toEqual([]);
});
- it('throws when a goal directive reaches migration', () => {
+ it('migrates a goal directive to a long-term goal entry', () => {
const goalTemplate = {
type: 'goal',
amount: 1000,
directive: 'goal',
} satisfies Template;
- expect(() => migrateTemplatesToAutomations([goalTemplate])).toThrow(
- /Unsupported template type/,
- );
+ const [entry, ...rest] = migrateTemplatesToAutomations([goalTemplate]);
+ expect(rest).toHaveLength(0);
+ expect(entry.displayType).toBe('goal');
+ expect(entry.template).toEqual(goalTemplate);
});
it('expands a simple template with limit into limit and refill entries', () => {
diff --git a/packages/desktop-client/src/components/modals/BudgetAutomationsModal/BudgetAutomationsModal.tsx b/packages/desktop-client/src/components/modals/BudgetAutomationsModal/BudgetAutomationsModal.tsx
index 5172179fa5..8ad8243f23 100644
--- a/packages/desktop-client/src/components/modals/BudgetAutomationsModal/BudgetAutomationsModal.tsx
+++ b/packages/desktop-client/src/components/modals/BudgetAutomationsModal/BudgetAutomationsModal.tsx
@@ -49,8 +49,6 @@ export function BudgetAutomationsModal({
const needsMigration = currentCategory?.template_settings?.source !== 'ui';
- const hasGoalTemplate =
- parsedTemplates?.some(t => t.type === 'goal') ?? false;
const hasErrorTemplate =
parsedTemplates?.some(t => t.type === 'error') ?? false;
const hasSpendTemplate =
@@ -60,10 +58,7 @@ export function BudgetAutomationsModal({
// are no longer the source of truth.
const hasCleanupDirective = needsMigration && hasCleanupLine(notes);
const hasUnsupportedDirective =
- hasGoalTemplate ||
- hasErrorTemplate ||
- hasSpendTemplate ||
- hasCleanupDirective;
+ hasErrorTemplate || hasSpendTemplate || hasCleanupDirective;
const incomeNameToId = new Map<string, string>();
for (const group of categories) {
@@ -111,10 +106,8 @@ export function BudgetAutomationsModal({
</View>
) : hasUnsupportedDirective ? (
<UnsupportedDirectivesNotice
- hasGoalTemplate={hasGoalTemplate}
hasErrorTemplate={hasErrorTemplate}
hasSpendTemplate={hasSpendTemplate}
- hasCleanupDirective={hasCleanupDirective}
onClose={() => state.close()}
/>
) : (
diff --git a/packages/desktop-client/src/components/modals/BudgetAutomationsModal/TypePicker.tsx b/packages/desktop-client/src/components/modals/BudgetAutomationsModal/TypePicker.tsx
index e73958db4c..e08aa14293 100644
--- a/packages/desktop-client/src/components/modals/BudgetAutomationsModal/TypePicker.tsx
+++ b/packages/desktop-client/src/components/modals/BudgetAutomationsModal/TypePicker.tsx
@@ -11,7 +11,7 @@ import { getDisplayTemplateMeta } from '#components/budget/goals/displayTemplate
// Types managed in the Options sidebar section, not as contribution-type
// swaps.
export const NON_CONTRIBUTION_TYPES: ReadonlySet<DisplayTemplateType> = new Set(
- ['limit'],
+ ['limit', 'goal'],
);
type TypePickerProps = {
diff --git a/packages/desktop-client/src/components/modals/BudgetAutomationsModal/UnsupportedDirectivesNotice.tsx b/packages/desktop-client/src/components/modals/BudgetAutomationsModal/UnsupportedDirectivesNotice.tsx
index 8b4301a8a5..fa9fbe488b 100644
--- a/packages/desktop-client/src/components/modals/BudgetAutomationsModal/UnsupportedDirectivesNotice.tsx
+++ b/packages/desktop-client/src/components/modals/BudgetAutomationsModal/UnsupportedDirectivesNotice.tsx
@@ -7,16 +7,12 @@ import { theme } from '@actual-app/components/theme';
import { View } from '@actual-app/components/view';
export function UnsupportedDirectivesNotice({
- hasGoalTemplate,
hasErrorTemplate,
hasSpendTemplate,
- hasCleanupDirective,
onClose,
}: {
- hasGoalTemplate: boolean;
hasErrorTemplate: boolean;
hasSpendTemplate: boolean;
- hasCleanupDirective: boolean;
onClose: () => void;
}) {
return (
@@ -64,19 +60,6 @@ export function UnsupportedDirectivesNotice({
budget automations UI doesn&rsquo;t handle yet. Keep editing it as
text in the category&rsquo;s notes.
</Trans>
- ) : hasGoalTemplate && hasCleanupDirective ? (
- <Trans>
- This category&rsquo;s notes use <code>#goal</code> and{' '}
- <code>#cleanup</code> directives, neither of which the budget
- automations UI handles yet. Keep editing them as text in the
- category&rsquo;s notes.
- </Trans>
- ) : hasGoalTemplate ? (
- <Trans>
- This category uses a <code>#goal</code> directive, which the budget
- automations UI doesn&rsquo;t handle yet. Keep editing it as text in
- the category&rsquo;s notes.
- </Trans>
) : (
<Trans>
This category uses a <code>#cleanup</code> directive, which the
diff --git a/packages/desktop-client/src/components/modals/BudgetAutomationsModal/migrateTemplatesToAutomations.ts b/packages/desktop-client/src/components/modals/BudgetAutomationsModal/migrateTemplatesToAutomations.ts
index bf7174ab25..36a97175e2 100644
--- a/packages/desktop-client/src/components/modals/BudgetAutomationsModal/migrateTemplatesToAutomations.ts
+++ b/packages/desktop-client/src/components/modals/BudgetAutomationsModal/migrateTemplatesToAutomations.ts
@@ -26,6 +26,7 @@ function getDisplayTypeFromTemplate(template: Template): DisplayTemplateType {
case 'remainder':
return 'remainder';
case 'goal':
+ return 'goal';
case 'error':
case 'spend':
// filtered upstream by hasUnsupportedDirective; surface if it ever isn't
diff --git a/upcoming-release-notes/7792.md b/upcoming-release-notes/7792.md
new file mode 100644
index 0000000000..ce583ea498
--- /dev/null
+++ b/upcoming-release-notes/7792.md
@@ -0,0 +1,6 @@
+---
+category: Enhancements
+authors: [matt-fidd]
+---
+
+Automation UI: Add long-term goal functionality