Skip to content

A local-first personal finance app

[AI] Fix long payee names being cut off in the rule editor on mobile (#9335)

Vu Linh Truong6ad4b3c9a5b0
diff --git a/packages/desktop-client/e2e/rules.mobile.test.ts-snapshots/Mobile-Rules-clicking-add-button-opens-rule-creation-form-1-chromium-linux.png b/packages/desktop-client/e2e/rules.mobile.test.ts-snapshots/Mobile-Rules-clicking-add-button-opens-rule-creation-form-1-chromium-linux.png
index 145c1c57b7..6020345685 100644
Binary files a/packages/desktop-client/e2e/rules.mobile.test.ts-snapshots/Mobile-Rules-clicking-add-button-opens-rule-creation-form-1-chromium-linux.png and b/packages/desktop-client/e2e/rules.mobile.test.ts-snapshots/Mobile-Rules-clicking-add-button-opens-rule-creation-form-1-chromium-linux.png differ
diff --git a/packages/desktop-client/e2e/rules.mobile.test.ts-snapshots/Mobile-Rules-clicking-add-button-opens-rule-creation-form-2-chromium-linux.png b/packages/desktop-client/e2e/rules.mobile.test.ts-snapshots/Mobile-Rules-clicking-add-button-opens-rule-creation-form-2-chromium-linux.png
index df43b916c2..0304e1e66d 100644
Binary files a/packages/desktop-client/e2e/rules.mobile.test.ts-snapshots/Mobile-Rules-clicking-add-button-opens-rule-creation-form-2-chromium-linux.png and b/packages/desktop-client/e2e/rules.mobile.test.ts-snapshots/Mobile-Rules-clicking-add-button-opens-rule-creation-form-2-chromium-linux.png differ
diff --git a/packages/desktop-client/e2e/rules.mobile.test.ts-snapshots/Mobile-Rules-clicking-add-button-opens-rule-creation-form-3-chromium-linux.png b/packages/desktop-client/e2e/rules.mobile.test.ts-snapshots/Mobile-Rules-clicking-add-button-opens-rule-creation-form-3-chromium-linux.png
index 2c71fb8337..9f80480ec7 100644
Binary files a/packages/desktop-client/e2e/rules.mobile.test.ts-snapshots/Mobile-Rules-clicking-add-button-opens-rule-creation-form-3-chromium-linux.png and b/packages/desktop-client/e2e/rules.mobile.test.ts-snapshots/Mobile-Rules-clicking-add-button-opens-rule-creation-form-3-chromium-linux.png differ
diff --git a/packages/desktop-client/e2e/rules.mobile.test.ts-snapshots/Mobile-Rules-clicking-on-a-rule-opens-edit-form-1-chromium-linux.png b/packages/desktop-client/e2e/rules.mobile.test.ts-snapshots/Mobile-Rules-clicking-on-a-rule-opens-edit-form-1-chromium-linux.png
index 42822af549..0b36bbc054 100644
Binary files a/packages/desktop-client/e2e/rules.mobile.test.ts-snapshots/Mobile-Rules-clicking-on-a-rule-opens-edit-form-1-chromium-linux.png and b/packages/desktop-client/e2e/rules.mobile.test.ts-snapshots/Mobile-Rules-clicking-on-a-rule-opens-edit-form-1-chromium-linux.png differ
diff --git a/packages/desktop-client/e2e/rules.mobile.test.ts-snapshots/Mobile-Rules-clicking-on-a-rule-opens-edit-form-2-chromium-linux.png b/packages/desktop-client/e2e/rules.mobile.test.ts-snapshots/Mobile-Rules-clicking-on-a-rule-opens-edit-form-2-chromium-linux.png
index 429f3a5179..3b17807170 100644
Binary files a/packages/desktop-client/e2e/rules.mobile.test.ts-snapshots/Mobile-Rules-clicking-on-a-rule-opens-edit-form-2-chromium-linux.png and b/packages/desktop-client/e2e/rules.mobile.test.ts-snapshots/Mobile-Rules-clicking-on-a-rule-opens-edit-form-2-chromium-linux.png differ
diff --git a/packages/desktop-client/e2e/rules.mobile.test.ts-snapshots/Mobile-Rules-clicking-on-a-rule-opens-edit-form-3-chromium-linux.png b/packages/desktop-client/e2e/rules.mobile.test.ts-snapshots/Mobile-Rules-clicking-on-a-rule-opens-edit-form-3-chromium-linux.png
index e9a6a7c70a..b88c1b5990 100644
Binary files a/packages/desktop-client/e2e/rules.mobile.test.ts-snapshots/Mobile-Rules-clicking-on-a-rule-opens-edit-form-3-chromium-linux.png and b/packages/desktop-client/e2e/rules.mobile.test.ts-snapshots/Mobile-Rules-clicking-on-a-rule-opens-edit-form-3-chromium-linux.png differ
diff --git a/packages/desktop-client/src/components/rules/RuleEditor.tsx b/packages/desktop-client/src/components/rules/RuleEditor.tsx
index b1e37818a2..fd113e988c 100644
--- a/packages/desktop-client/src/components/rules/RuleEditor.tsx
+++ b/packages/desktop-client/src/components/rules/RuleEditor.tsx
@@ -63,6 +63,36 @@ import { friendlyOp, getAllocationMethods, mapField } from '#util/rule';
import { FormulaActionEditor } from './FormulaActionEditor';
+// On narrow screens the value editor drops to its own full-width line and the
+// -/+ buttons stay on the first line, pushed to the right.
+const narrowValueStyle: CSSProperties = { order: 1, flexBasis: '100%' };
+const narrowButtonsStyle: CSSProperties = { marginLeft: 'auto' };
+
+// Keeps the split method select on the first line, truncating its label
+// instead of wrapping.
+const narrowMethodSelectStyle: CSSProperties = {
+ flex: '1 1 0',
+ minWidth: 0,
+ maxWidth: 'max-content',
+};
+
+// Minimum width of the transactions table on narrow screens, mirroring the
+// select, date and amount cell widths in SimpleTransactionsTable plus 200px per
+// flexible column. Fields the table does not render (e.g. `cleared`) are
+// ignored.
+const flexibleTableFields = [
+ 'imported_payee',
+ 'payee',
+ 'category',
+ 'account',
+ 'notes',
+];
+
+function getNarrowTableMinWidth(fields: string[]) {
+ const flexCount = fields.filter(f => flexibleTableFields.includes(f)).length;
+ return 20 + 100 + 75 + flexCount * 200;
+}
+
function updateValue(array, value, update) {
return array.map(v => (v === value ? update() : v));
}
@@ -272,6 +302,7 @@ function ConditionEditor({
onDelete,
onAdd,
}) {
+ const { isNarrowWidth } = useResponsive();
const {
field: originalField,
op,
@@ -345,9 +376,21 @@ function ConditionEditor({
/>
<OpSelect ops={ops} value={op} type={type} onChange={onChange} />
- <View style={{ flex: 1, minWidth: 80 }}>{valueEditor}</View>
+ <View
+ style={{
+ flex: 1,
+ minWidth: 80,
+ ...(isNarrowWidth && narrowValueStyle),
+ }}
+ >
+ {valueEditor}
+ </View>
- <SpaceBetween direction="horizontal" gap={0}>
+ <SpaceBetween
+ direction="horizontal"
+ gap={0}
+ style={isNarrowWidth ? narrowButtonsStyle : undefined}
+ >
<EditorButtons
onAdd={onAdd}
onDelete={isSchedule && field === 'date' ? null : onDelete}
@@ -486,6 +529,7 @@ function ActionEditor({
onAdd,
}: ActionEditorProps) {
const { t } = useTranslation();
+ const { isNarrowWidth } = useResponsive();
const {
field,
op,
@@ -530,7 +574,7 @@ function ActionEditor({
onChange={value => onChange('field', value)}
/>
- <View style={{ flex: 1 }}>
+ <View style={{ flex: 1, ...(isNarrowWidth && narrowValueStyle) }}>
<View style={{ flex: 1 }}>
{hasFormula ? (
<FormulaActionEditor
@@ -638,35 +682,43 @@ function ActionEditor({
<SplitAmountMethodSelect
options={getAllocationMethodOptions(isFormulaEnabled)}
value={options.method}
+ style={isNarrowWidth ? narrowMethodSelectStyle : undefined}
onChange={onChange}
/>
- <View
- style={{
- flex: 1,
- minWidth: options.method === 'fixed-percent' ? 45 : 70,
- }}
- >
- {options.method === 'formula' ? (
- <FormulaActionEditor
- value={options?.formula || '='}
- onChange={v => onChange('formula', v, { formula: true })}
- />
- ) : options.method !== 'remainder' ? (
- <GenericInput
- key={inputKey}
- // @ts-expect-error fix this
- field={field}
- op={op}
- type="number"
- numberFormatType={
- options.method === 'fixed-percent' ? 'percentage' : 'currency'
- }
- value={value ?? ''}
- onChange={v => onChange('value', v)}
- />
- ) : null}
- </View>
+ {/* On wide screens the empty remainder wrapper spaces the buttons to
+ the right; on narrow screens it would only add a blank line. */}
+ {(options.method !== 'remainder' || !isNarrowWidth) && (
+ <View
+ style={{
+ flex: 1,
+ minWidth: options.method === 'fixed-percent' ? 45 : 70,
+ ...(isNarrowWidth && narrowValueStyle),
+ }}
+ >
+ {options.method === 'formula' ? (
+ <FormulaActionEditor
+ value={options?.formula || '='}
+ onChange={v => onChange('formula', v, { formula: true })}
+ />
+ ) : options.method !== 'remainder' ? (
+ <GenericInput
+ key={inputKey}
+ // @ts-expect-error fix this
+ field={field}
+ op={op}
+ type="number"
+ numberFormatType={
+ options.method === 'fixed-percent'
+ ? 'percentage'
+ : 'currency'
+ }
+ value={value ?? ''}
+ onChange={v => onChange('value', v)}
+ />
+ ) : null}
+ </View>
+ )}
{options.method === 'formula' && (
<View
style={{
@@ -714,7 +766,7 @@ function ActionEditor({
onChange={onChange}
/>
- <View style={{ flex: 1 }}>
+ <View style={{ flex: 1, ...(isNarrowWidth && narrowValueStyle) }}>
<GenericInput
key={inputKey}
// @ts-expect-error fix this
@@ -735,7 +787,13 @@ function ActionEditor({
) : null}
{op !== 'delete-transaction' && (
- <SpaceBetween gap={0} style={{ flexShrink: 0 }}>
+ <SpaceBetween
+ gap={0}
+ style={{
+ flexShrink: 0,
+ ...(isNarrowWidth && narrowButtonsStyle),
+ }}
+ >
<EditorButtons
onAdd={onAdd}
onDelete={
@@ -1034,6 +1092,7 @@ export function RuleEditor({
style,
}: RuleEditorProps) {
const { t } = useTranslation();
+ const { isNarrowWidth } = useResponsive();
const [conditions, setConditions] = useState(
defaultRule.conditions.map(parse).map(c => ({ ...c, inputKey: uuidv4() })),
);
@@ -1065,6 +1124,10 @@ export function RuleEditor({
const isSchedule = getActions(actionSplits).some(
action => action.op === 'link-schedule',
);
+ const transactionFields = getTransactionFields(
+ conditions,
+ getActions(actionSplits),
+ );
useEffect(() => {
// Disable undo while this modal is open
@@ -1555,15 +1618,28 @@ export function RuleEditor({
</Button>
</SpaceBetween>
- {/* @ts-expect-error fix this */}
- <SimpleTransactionsTable
- transactions={transactions}
- fields={getTransactionFields(conditions, getActions(actionSplits))}
+ <View
style={{
- border: '1px solid ' + theme.tableBorder,
- borderRadius: '6px 6px 0 0',
+ flex: 1,
+ ...(isNarrowWidth && {
+ ...styles.horizontalScrollbar,
+ overflowX: 'auto',
+ }),
}}
- />
+ >
+ {/* @ts-expect-error fix this */}
+ <SimpleTransactionsTable
+ transactions={transactions}
+ fields={transactionFields}
+ style={{
+ border: '1px solid ' + theme.tableBorder,
+ borderRadius: '6px 6px 0 0',
+ ...(isNarrowWidth && {
+ minWidth: getNarrowTableMinWidth(transactionFields),
+ }),
+ }}
+ />
+ </View>
<SpaceBetween
style={{
diff --git a/upcoming-release-notes/fix-mobile-rule-editor-long-names.md b/upcoming-release-notes/fix-mobile-rule-editor-long-names.md
new file mode 100644
index 0000000000..8fdcdaaf54
--- /dev/null
+++ b/upcoming-release-notes/fix-mobile-rule-editor-long-names.md
@@ -0,0 +1,6 @@
+---
+category: Bugfix
+authors: [vulinh1704]
+---
+
+Fix long payee names being cut off in the rule editor on mobile