Skip to content

A local-first personal finance app

automation UI: rework balance cap and fix error when clearing fields (#8082)

Matt Fiddaman85a4974fb4e0
diff --git a/packages/desktop-client/src/components/budget/goals/editor/HistoricalAutomation.tsx b/packages/desktop-client/src/components/budget/goals/editor/HistoricalAutomation.tsx
index 16be09b83e..d7739b3e61 100644
--- a/packages/desktop-client/src/components/budget/goals/editor/HistoricalAutomation.tsx
+++ b/packages/desktop-client/src/components/budget/goals/editor/HistoricalAutomation.tsx
@@ -1,5 +1,7 @@
+import { useEffect, useState } from 'react';
import { useTranslation } from 'react-i18next';
+import { Input } from '@actual-app/components/input';
import { Select } from '@actual-app/components/select';
import { SpaceBetween } from '@actual-app/components/space-between';
import type {
@@ -11,7 +13,6 @@ import { updateTemplate } from '#components/budget/goals/actions';
import type { Action } from '#components/budget/goals/actions';
import { AmountAdjustment } from '#components/budget/goals/editor/AmountAdjustment';
import { FormField, FormLabel } from '#components/forms';
-import { GenericInput } from '#components/util/GenericInput';
type HistoricalAutomationProps = {
template: CopyTemplate | AverageTemplate;
@@ -24,6 +25,26 @@ export const HistoricalAutomation = ({
}: HistoricalAutomationProps) => {
const { t } = useTranslation();
+ const months =
+ template.type === 'average' ? template.numMonths : template.lookBack;
+ const [rawMonths, setRawMonths] = useState(String(months));
+ useEffect(() => {
+ setRawMonths(String(months));
+ }, [months]);
+
+ const commitMonths = () => {
+ const parsed = Math.max(1, Math.trunc(Number(rawMonths)) || 1);
+ setRawMonths(String(parsed));
+ if (parsed === months) return;
+ dispatch(
+ updateTemplate(
+ template.type === 'average'
+ ? { type: 'average', numMonths: parsed }
+ : { type: 'copy', lookBack: parsed },
+ ),
+ );
+ };
+
return (
<>
<SpaceBetween gap={50} style={{ marginTop: 10 }}>
@@ -45,23 +66,14 @@ export const HistoricalAutomation = ({
title={t('Number of months back')}
htmlFor="look-back-field"
/>
- <GenericInput
- key="look-back-input"
+ <Input
+ id="look-back-field"
type="number"
- value={
- template.type === 'average'
- ? template.numMonths
- : template.lookBack
- }
- onChange={value =>
- dispatch(
- updateTemplate(
- template.type === 'average'
- ? { type: 'average', numMonths: value }
- : { type: 'copy', lookBack: value },
- ),
- )
- }
+ min={1}
+ step={1}
+ value={rawMonths}
+ onChangeValue={setRawMonths}
+ onBlur={commitMonths}
/>
</FormField>
</SpaceBetween>
diff --git a/packages/desktop-client/src/components/budget/goals/editor/LimitAutomation.tsx b/packages/desktop-client/src/components/budget/goals/editor/LimitAutomation.tsx
index e23c5663ea..642be2b32c 100644
--- a/packages/desktop-client/src/components/budget/goals/editor/LimitAutomation.tsx
+++ b/packages/desktop-client/src/components/budget/goals/editor/LimitAutomation.tsx
@@ -2,6 +2,7 @@ import { Trans, useTranslation } from 'react-i18next';
import { Select } from '@actual-app/components/select';
import { SpaceBetween } from '@actual-app/components/space-between';
+import { Text } from '@actual-app/components/text';
import { theme } from '@actual-app/components/theme';
import {
currentDate,
@@ -90,31 +91,71 @@ export const LimitAutomation = ({
</FormField>
);
+ const cadenceField = (
+ <FormField key="cadence-field" style={{ flex: 1 }}>
+ <FormLabel title={t('Every')} htmlFor="cadence-field" />
+
+ <Select
+ id="cadence-field"
+ value={period}
+ onChange={cadence =>
+ dispatch(updateTemplate({ type: 'limit', period: cadence }))
+ }
+ options={[
+ ['daily', t('Day')],
+ ['weekly', t('Week')],
+ ['monthly', t('Month')],
+ ]}
+ className={selectButtonClassName}
+ />
+ </FormField>
+ );
+
return (
<>
<SpaceBetween align="center" gap={10} style={{ marginTop: 10 }}>
- <FormField key="cadence-field" style={{ flex: 1 }}>
- <FormLabel title={t('Cadence')} htmlFor="cadence-field" />
-
- <Select
- id="cadence-field"
- value={period}
- onChange={cadence =>
- dispatch(updateTemplate({ type: 'limit', period: cadence }))
- }
- options={[
- ['daily', t('Daily')],
- ['weekly', t('Weekly')],
- ['monthly', t('Monthly')],
- ]}
- className={selectButtonClassName}
- />
- </FormField>
- {period === 'weekly' ? weekdayField : amountField}
+ {amountField}
+ {cadenceField}
</SpaceBetween>
+ <Text
+ style={{
+ fontSize: 12,
+ color: theme.pageTextLight,
+ display: 'block',
+ marginTop: 8,
+ }}
+ >
+ <Trans>
+ A weekly or daily cap is multiplied by the number of weeks or days in
+ the month, so the effective monthly cap changes with each month. For
+ example, a{' '}
+ {{
+ weekly: format(
+ amountToInteger(50, format.currency.decimalPlaces),
+ 'financial-no-decimals',
+ ),
+ }}
+ /week cap caps the balance at{' '}
+ {{
+ fourWeeks: format(
+ amountToInteger(200, format.currency.decimalPlaces),
+ 'financial-no-decimals',
+ ),
+ }}{' '}
+ in months with 4 weeks and{' '}
+ {{
+ fiveWeeks: format(
+ amountToInteger(250, format.currency.decimalPlaces),
+ 'financial-no-decimals',
+ ),
+ }}{' '}
+ in months with 5.
+ </Trans>
+ </Text>
+
<SpaceBetween align="center" gap={10} style={{ marginTop: 10 }}>
- {period === 'weekly' && amountField}
+ {period === 'weekly' && weekdayField}
<FormField key="hold-overflow-field" style={{ flex: 1 }}>
<LabeledCheckbox
id="hold-overflow-field"
diff --git a/upcoming-release-notes/8082.md b/upcoming-release-notes/8082.md
new file mode 100644
index 0000000000..ff9550a141
--- /dev/null
+++ b/upcoming-release-notes/8082.md
@@ -0,0 +1,6 @@
+---
+category: Bugfixes
+authors: [matt-fidd]
+---
+
+Automation UI: rework balance cap and fix error when clearing fields