Skip to content

A local-first personal finance app

automation UI: add options section to sidebar (#7791)

Matt Fiddamand50005749488
diff --git a/packages/desktop-client/src/components/budget/goals/displayTemplateMeta.ts b/packages/desktop-client/src/components/budget/goals/displayTemplateMeta.ts
index 016652a4e8..8832f4e27f 100644
--- a/packages/desktop-client/src/components/budget/goals/displayTemplateMeta.ts
+++ b/packages/desktop-client/src/components/budget/goals/displayTemplateMeta.ts
@@ -65,7 +65,9 @@ export function getDisplayTemplateMeta(
case 'limit':
return {
label: t('Balance cap'),
- description: t('Never let the category balance exceed a cap.'),
+ description: t(
+ 'Stop budgeting to this category once the balance reaches a cap.',
+ ),
icon: SvgEquals,
};
case 'refill':
diff --git a/packages/desktop-client/src/components/budget/goals/editor/LimitAutomationShort.tsx b/packages/desktop-client/src/components/budget/goals/editor/LimitAutomationShort.tsx
new file mode 100644
index 0000000000..fcccbc259a
--- /dev/null
+++ b/packages/desktop-client/src/components/budget/goals/editor/LimitAutomationShort.tsx
@@ -0,0 +1,31 @@
+import { Trans } from 'react-i18next';
+
+import { amountToInteger } from '@actual-app/core/shared/util';
+import type { LimitTemplate } from '@actual-app/core/types/models/templates';
+
+import { useFormat } from '#hooks/useFormat';
+
+type LimitAutomationShortProps = {
+ template: LimitTemplate;
+};
+
+export const LimitAutomationShort = ({
+ template,
+}: LimitAutomationShortProps) => {
+ const format = useFormat();
+ const amount = format(
+ amountToInteger(template.amount, format.currency.decimalPlaces),
+ 'financial',
+ );
+
+ switch (template.period) {
+ case 'daily':
+ return <Trans>{{ amount }} / day</Trans>;
+ case 'weekly':
+ return <Trans>{{ amount }} / week</Trans>;
+ case 'monthly':
+ return <Trans>{{ amount }} / month</Trans>;
+ default:
+ return null;
+ }
+};
diff --git a/packages/desktop-client/src/components/modals/BudgetAutomationsModal/AutomationEditorPane.tsx b/packages/desktop-client/src/components/modals/BudgetAutomationsModal/AutomationEditorPane.tsx
index 9bf2e43d00..d1dc887090 100644
--- a/packages/desktop-client/src/components/modals/BudgetAutomationsModal/AutomationEditorPane.tsx
+++ b/packages/desktop-client/src/components/modals/BudgetAutomationsModal/AutomationEditorPane.tsx
@@ -20,13 +20,14 @@ import {
AutomationErrorTitle,
} from '#components/budget/goals/automationMessages';
import type { DisplayTemplateType } from '#components/budget/goals/constants';
+import { getDisplayTemplateMeta } from '#components/budget/goals/displayTemplateMeta';
import {
getInitialState,
templateReducer,
} from '#components/budget/goals/reducer';
import type { AutomationErrorKind } from '#components/budget/goals/validateAutomation';
-import { TypePicker } from './TypePicker';
+import { NON_CONTRIBUTION_TYPES, TypePicker } from './TypePicker';
const CONFIG_PANEL_CLASS = css({
'& > *:first-child': {
@@ -179,22 +180,26 @@ export function AutomationEditorPane({
</View>
)}
- <Text
- style={{
- fontSize: 11,
- textTransform: 'uppercase',
- color: theme.pageTextSubdued,
- fontWeight: 600,
- letterSpacing: '0.05em',
- }}
- >
- <Trans>Automation type</Trans>
- </Text>
- <TypePicker
- active={state.displayType}
- disabledTypes={disabledTypes}
- onPick={type => dispatch({ type: 'set-type', payload: type })}
- />
+ {!NON_CONTRIBUTION_TYPES.has(state.displayType) && (
+ <>
+ <Text
+ style={{
+ fontSize: 11,
+ textTransform: 'uppercase',
+ color: theme.pageTextSubdued,
+ fontWeight: 600,
+ letterSpacing: '0.05em',
+ }}
+ >
+ <Trans>Automation type</Trans>
+ </Text>
+ <TypePicker
+ active={state.displayType}
+ disabledTypes={disabledTypes}
+ onPick={type => dispatch({ type: 'set-type', payload: type })}
+ />
+ </>
+ )}
{state.displayType !== 'refill' && (
<>
@@ -218,6 +223,18 @@ export function AutomationEditorPane({
border: `1px solid ${theme.tableBorder}`,
}}
>
+ {NON_CONTRIBUTION_TYPES.has(state.displayType) && (
+ <Text
+ style={{
+ fontSize: 12,
+ color: theme.pageTextSubdued,
+ display: 'block',
+ marginBottom: 4,
+ }}
+ >
+ {getDisplayTemplateMeta(state.displayType).description}
+ </Text>
+ )}
<ActiveEditor
state={state}
dispatch={dispatch}
diff --git a/packages/desktop-client/src/components/modals/BudgetAutomationsModal/AutomationListRow.tsx b/packages/desktop-client/src/components/modals/BudgetAutomationsModal/AutomationListRow.tsx
index 5a7732dddf..2817f9016a 100644
--- a/packages/desktop-client/src/components/modals/BudgetAutomationsModal/AutomationListRow.tsx
+++ b/packages/desktop-client/src/components/modals/BudgetAutomationsModal/AutomationListRow.tsx
@@ -8,10 +8,13 @@ import { View } from '@actual-app/components/view';
import type { AutomationEntry } from '#components/budget/goals/automationExamples';
import { AutomationErrorShort } from '#components/budget/goals/automationMessages';
import { getDisplayTemplateMeta } from '#components/budget/goals/displayTemplateMeta';
+import { LimitAutomationShort } from '#components/budget/goals/editor/LimitAutomationShort';
import { TemplateSentence } from '#components/budget/goals/TemplateSentence';
import type { AutomationErrorKind } from '#components/budget/goals/validateAutomation';
import { useFormat } from '#hooks/useFormat';
+import { NON_CONTRIBUTION_TYPES } from './TypePicker';
+
type AutomationListRowProps = {
index: number;
entry: AutomationEntry;
@@ -38,6 +41,8 @@ export function AutomationListRow({
const subtitle = error ? (
<AutomationErrorShort error={error} />
+ ) : entry.template.type === 'limit' ? (
+ <LimitAutomationShort template={entry.template} />
) : (
<TemplateSentence
template={entry.template}
@@ -135,45 +140,47 @@ export function AutomationListRow({
{subtitle}
</Text>
</View>
- <View
- style={{
- flexShrink: 0,
- alignItems: 'flex-end',
- gap: 2,
- }}
- >
- <Text
+ {!NON_CONTRIBUTION_TYPES.has(entry.displayType) && (
+ <View
style={{
- fontSize: 12,
- fontWeight: 600,
- fontVariantNumeric: 'tabular-nums',
- color:
- contribution == null ||
- Number.isNaN(contribution) ||
- contribution === 0
- ? theme.pageTextSubdued
- : theme.pageText,
+ flexShrink: 0,
+ alignItems: 'flex-end',
+ gap: 2,
}}
>
- {contribution == null || Number.isNaN(contribution)
- ? '—'
- : contribution > 0
- ? '+' + format(contribution, 'financial')
- : format(contribution, 'financial')}
- </Text>
- {priority != null && (
<Text
style={{
- fontSize: 10,
- color: theme.pageTextSubdued,
+ fontSize: 12,
+ fontWeight: 600,
fontVariantNumeric: 'tabular-nums',
- letterSpacing: '0.04em',
+ color:
+ contribution == null ||
+ Number.isNaN(contribution) ||
+ contribution === 0
+ ? theme.pageTextSubdued
+ : theme.pageText,
}}
>
- {t('Priority: {{priority}}', { priority })}
+ {contribution == null || Number.isNaN(contribution)
+ ? '—'
+ : contribution > 0
+ ? '+' + format(contribution, 'financial')
+ : format(contribution, 'financial')}
</Text>
- )}
- </View>
+ {priority != null && (
+ <Text
+ style={{
+ fontSize: 10,
+ color: theme.pageTextSubdued,
+ fontVariantNumeric: 'tabular-nums',
+ letterSpacing: '0.04em',
+ }}
+ >
+ {t('Priority: {{priority}}', { priority })}
+ </Text>
+ )}
+ </View>
+ )}
</View>
);
}
diff --git a/packages/desktop-client/src/components/modals/BudgetAutomationsModal/BudgetAutomationsBody.tsx b/packages/desktop-client/src/components/modals/BudgetAutomationsModal/BudgetAutomationsBody.tsx
index 9a8aca1178..49331d2857 100644
--- a/packages/desktop-client/src/components/modals/BudgetAutomationsModal/BudgetAutomationsBody.tsx
+++ b/packages/desktop-client/src/components/modals/BudgetAutomationsModal/BudgetAutomationsBody.tsx
@@ -1,4 +1,5 @@
import { useEffect, useState } from 'react';
+import type { CSSProperties, ReactNode } from 'react';
import { Trans } from 'react-i18next';
import { Button } from '@actual-app/components/button';
@@ -55,6 +56,82 @@ const ALWAYS_SCROLL_CLASS = css({
},
});
+function SidebarSectionHeader({
+ children,
+ style,
+}: {
+ children: ReactNode;
+ style?: CSSProperties;
+}) {
+ return (
+ <View
+ style={{
+ flexShrink: 0,
+ flexDirection: 'row',
+ justifyContent: 'space-between',
+ alignItems: 'center',
+ padding: '6px 8px',
+ fontSize: 11,
+ textTransform: 'uppercase',
+ color: theme.pageTextSubdued,
+ fontWeight: 600,
+ letterSpacing: '0.05em',
+ ...style,
+ }}
+ >
+ <Text>{children}</Text>
+ </View>
+ );
+}
+
+function SidebarAddButton({
+ onPress,
+ children,
+}: {
+ onPress: () => void;
+ children: ReactNode;
+}) {
+ return (
+ <Button
+ variant="bare"
+ onPress={onPress}
+ style={{
+ flexShrink: 0,
+ width: '100%',
+ marginTop: 8,
+ padding: 10,
+ border: `1px dashed ${theme.tableBorder}`,
+ borderRadius: 6,
+ color: theme.pageTextPositive,
+ fontWeight: 600,
+ fontSize: 12,
+ justifyContent: 'center',
+ }}
+ >
+ {children}
+ </Button>
+ );
+}
+
+function SidebarPlaceholderRow({ children }: { children: ReactNode }) {
+ return (
+ <View
+ style={{
+ flexShrink: 0,
+ padding: '8px 10px',
+ marginTop: 4,
+ borderRadius: 6,
+ border: `1px dashed ${theme.tableBorder}`,
+ color: theme.pageTextSubdued,
+ fontSize: 12,
+ opacity: 0.6,
+ }}
+ >
+ <Text>{children}</Text>
+ </View>
+ );
+}
+
type BudgetAutomationsBodyProps = {
categoryId: string;
categoryName: string;
@@ -113,8 +190,11 @@ export function BudgetAutomationsBody({
},
'limit',
);
- setEntries(prev => [entry, ...prev]);
- setActiveIdx(0);
+ setEntries(prev => {
+ const next = [...prev, entry];
+ setActiveIdx(next.length - 1);
+ return next;
+ });
};
const onDelete = (index: number) => {
@@ -227,6 +307,14 @@ export function BudgetAutomationsBody({
const hasLimitAutomation = entries.some(e => e.displayType === 'limit');
+ const indexedEntries = entries.map((entry, idx) => ({ entry, idx }));
+ const contributionEntries = indexedEntries.filter(
+ ({ entry }) => entry.displayType !== 'limit',
+ );
+ const constraintEntries = indexedEntries.filter(
+ ({ entry }) => entry.displayType === 'limit',
+ );
+
const safeActiveIdx = Math.min(activeIdx, Math.max(0, entries.length - 1));
return (
@@ -337,53 +425,51 @@ export function BudgetAutomationsBody({
overflowY: 'scroll',
}}
>
- <View
- style={{
- flexShrink: 0,
- flexDirection: 'row',
- justifyContent: 'space-between',
- alignItems: 'center',
- padding: '6px 8px',
- fontSize: 11,
- textTransform: 'uppercase',
- color: theme.pageTextSubdued,
- fontWeight: 600,
- letterSpacing: '0.05em',
- }}
- >
- <Text>
- <Trans>Automations</Trans>
- </Text>
- </View>
- {entries.map((entry, i) => (
+ <SidebarSectionHeader>
+ <Trans>Automations</Trans>
+ </SidebarSectionHeader>
+ {contributionEntries.map(({ entry, idx }) => (
<AutomationListRow
key={entry.id}
- index={i}
+ index={idx}
entry={entry}
- isActive={i === safeActiveIdx}
- error={automationErrors[i]}
- contribution={contributions[i]}
+ isActive={idx === safeActiveIdx}
+ error={automationErrors[idx]}
+ contribution={contributions[idx]}
categoryNameMap={categoryNameMap}
onSelect={setActiveIdx}
/>
))}
- <Button
- variant="bare"
- onPress={() => onAddAutomation()}
- style={{
- width: '100%',
- marginTop: 8,
- padding: 10,
- border: `1px dashed ${theme.tableBorder}`,
- borderRadius: 6,
- color: theme.pageTextPositive,
- fontWeight: 600,
- fontSize: 12,
- justifyContent: 'center',
- }}
- >
+ <SidebarAddButton onPress={() => onAddAutomation()}>
+ <Trans>Add an automation</Trans>
- </Button>
+ </SidebarAddButton>
+
+ <SidebarSectionHeader style={{ marginTop: 16 }}>
+ <Trans>Options</Trans>
+ </SidebarSectionHeader>
+ {constraintEntries.map(({ entry, idx }) => (
+ <AutomationListRow
+ key={entry.id}
+ index={idx}
+ entry={entry}
+ isActive={idx === safeActiveIdx}
+ error={automationErrors[idx]}
+ contribution={contributions[idx]}
+ categoryNameMap={categoryNameMap}
+ onSelect={setActiveIdx}
+ />
+ ))}
+ {!hasLimitAutomation && (
+ <SidebarAddButton onPress={onAddLimitAutomation}>
+ + <Trans>Add balance cap</Trans>
+ </SidebarAddButton>
+ )}
+ <SidebarPlaceholderRow>
+ <Trans>Long-term goal (coming soon)</Trans>
+ </SidebarPlaceholderRow>
+ <SidebarPlaceholderRow>
+ <Trans>End of month cleanup (coming soon)</Trans>
+ </SidebarPlaceholderRow>
</View>
<View style={{ flex: 1, minWidth: 0 }}>
diff --git a/packages/desktop-client/src/components/modals/BudgetAutomationsModal/TypePicker.tsx b/packages/desktop-client/src/components/modals/BudgetAutomationsModal/TypePicker.tsx
index fc710a0c5b..e73958db4c 100644
--- a/packages/desktop-client/src/components/modals/BudgetAutomationsModal/TypePicker.tsx
+++ b/packages/desktop-client/src/components/modals/BudgetAutomationsModal/TypePicker.tsx
@@ -8,6 +8,12 @@ import { displayTemplateTypes } from '#components/budget/goals/constants';
import type { DisplayTemplateType } from '#components/budget/goals/constants';
import { getDisplayTemplateMeta } from '#components/budget/goals/displayTemplateMeta';
+// Types managed in the Options sidebar section, not as contribution-type
+// swaps.
+export const NON_CONTRIBUTION_TYPES: ReadonlySet<DisplayTemplateType> = new Set(
+ ['limit'],
+);
+
type TypePickerProps = {
active: DisplayTemplateType;
disabledTypes: ReadonlySet<DisplayTemplateType>;
@@ -16,9 +22,9 @@ type TypePickerProps = {
export function TypePicker({ active, disabledTypes, onPick }: TypePickerProps) {
const { t } = useTranslation();
- const entries = displayTemplateTypes.map(
- id => [id, getDisplayTemplateMeta(id)] as const,
- );
+ const entries = displayTemplateTypes
+ .filter(id => !NON_CONTRIBUTION_TYPES.has(id))
+ .map(id => [id, getDisplayTemplateMeta(id)] as const);
const disabledHint = t('Only one of this type allowed per category');
return (
diff --git a/upcoming-release-notes/7791.md b/upcoming-release-notes/7791.md
new file mode 100644
index 0000000000..6735c8946d
--- /dev/null
+++ b/upcoming-release-notes/7791.md
@@ -0,0 +1,6 @@
+---
+category: Enhancements
+authors: [matt-fidd]
+---
+
+Automation UI: Add options section for one-off settings