Skip to content

A local-first personal finance app

[AI] Fix bulk edit date picker formatting regression (#8765)

Zannis Kalampoukis1372f7b56484
diff --git a/packages/desktop-client/e2e/accounts.test.ts b/packages/desktop-client/e2e/accounts.test.ts
index 0b08d402df..6238ac67ff 100644
--- a/packages/desktop-client/e2e/accounts.test.ts
+++ b/packages/desktop-client/e2e/accounts.test.ts
@@ -1,6 +1,6 @@
import { join } from 'path';
-import type { Page } from '@playwright/test';
+import type { Locator, Page } from '@playwright/test';
import { expect, test } from './fixtures';
import type { AccountPage } from './page-models/account-page';
@@ -119,6 +119,59 @@ test.describe('Accounts', () => {
await expect(transaction.balance).toHaveText('25.00');
});
+ test('bulk editing the date shows a properly formatted date picker', async () => {
+ async function measure(locator: Locator) {
+ const box = await locator.boundingBox();
+ if (!box) {
+ throw new Error('Could not measure the date picker modal');
+ }
+ return box;
+ }
+
+ accountPage = await navigation.goToAccountPage('Ally Savings');
+ await accountPage.waitFor();
+
+ await accountPage.selectNthTransaction(0);
+ await accountPage.clickSelectAction('Date');
+
+ const dialog = page.getByRole('dialog');
+ const calendarGrid = dialog.locator('.react-aria-CalendarGrid');
+ await expect(calendarGrid).toBeVisible();
+
+ // The calendar is horizontally centered in the modal, not pinned to a side
+ const dialogBox = await measure(dialog);
+ const calendarGridBox = await measure(calendarGrid);
+ const leftGap = calendarGridBox.x - dialogBox.x;
+ const rightGap =
+ dialogBox.x +
+ dialogBox.width -
+ (calendarGridBox.x + calendarGridBox.width);
+ expect(Math.abs(leftGap - rightGap)).toBeLessThanOrEqual(2);
+
+ // The calendar is fully visible even for months spanning six rows
+ // (April 2017 relative to the pinned e2e date of January 2017)
+ await dialog.getByRole('button', { name: 'Next month' }).click();
+ await dialog.getByRole('button', { name: 'Next month' }).click();
+ await dialog.getByRole('button', { name: 'Next month' }).click();
+ await expect(dialog.locator('.calendar-header-title')).toHaveText(
+ 'April 2017',
+ );
+
+ const sixRowDialogBox = await measure(dialog);
+ const sixRowGridBox = await measure(calendarGrid);
+ expect(sixRowGridBox.y + sixRowGridBox.height).toBeLessThanOrEqual(
+ sixRowDialogBox.y + sixRowDialogBox.height,
+ );
+
+ await expect(dialog).toMatchThemeScreenshots();
+
+ // On a wide screen the modal keeps a bounded width instead of
+ // stretching to fit the 100%-wide calendar grid
+ await page.setViewportSize({ width: 2560, height: 1080 });
+ const wideDialogBox = await measure(dialog);
+ expect(wideDialogBox.width).toBeLessThanOrEqual(700);
+ });
+
test('shift-click range selection skips hidden reconciled transactions', async () => {
accountPage = await navigation.createAccount({
name: 'Range Select',
diff --git a/packages/desktop-client/e2e/accounts.test.ts-snapshots/Accounts-bulk-editing-the-date-shows-a-properly-formatted-date-picker-1-chromium-linux.png b/packages/desktop-client/e2e/accounts.test.ts-snapshots/Accounts-bulk-editing-the-date-shows-a-properly-formatted-date-picker-1-chromium-linux.png
new file mode 100644
index 0000000000..530ea87bda
Binary files /dev/null and b/packages/desktop-client/e2e/accounts.test.ts-snapshots/Accounts-bulk-editing-the-date-shows-a-properly-formatted-date-picker-1-chromium-linux.png differ
diff --git a/packages/desktop-client/e2e/accounts.test.ts-snapshots/Accounts-bulk-editing-the-date-shows-a-properly-formatted-date-picker-2-chromium-linux.png b/packages/desktop-client/e2e/accounts.test.ts-snapshots/Accounts-bulk-editing-the-date-shows-a-properly-formatted-date-picker-2-chromium-linux.png
new file mode 100644
index 0000000000..f5f9eeea26
Binary files /dev/null and b/packages/desktop-client/e2e/accounts.test.ts-snapshots/Accounts-bulk-editing-the-date-shows-a-properly-formatted-date-picker-2-chromium-linux.png differ
diff --git a/packages/desktop-client/e2e/accounts.test.ts-snapshots/Accounts-bulk-editing-the-date-shows-a-properly-formatted-date-picker-3-chromium-linux.png b/packages/desktop-client/e2e/accounts.test.ts-snapshots/Accounts-bulk-editing-the-date-shows-a-properly-formatted-date-picker-3-chromium-linux.png
new file mode 100644
index 0000000000..ac6934be34
Binary files /dev/null and b/packages/desktop-client/e2e/accounts.test.ts-snapshots/Accounts-bulk-editing-the-date-shows-a-properly-formatted-date-picker-3-chromium-linux.png differ
diff --git a/packages/desktop-client/src/components/formula/FormulaEditor.tsx b/packages/desktop-client/src/components/formula/FormulaEditor.tsx
index 2d15605c0f..8332428fb9 100644
--- a/packages/desktop-client/src/components/formula/FormulaEditor.tsx
+++ b/packages/desktop-client/src/components/formula/FormulaEditor.tsx
@@ -447,9 +447,10 @@ export function FormulaEditor({
top: timeframePicker.anchorRect.bottom + 4,
left: Math.min(
timeframePicker.anchorRect.left,
- window.innerWidth - 260,
+ window.innerWidth - TIMEFRAME_PICKER_WIDTH,
),
- minWidth: 225,
+ // Definite width required by the embedded calendar (see DateSelect)
+ width: TIMEFRAME_PICKER_WIDTH,
}}
onMouseDown={event => {
event.stopPropagation();
@@ -469,6 +470,8 @@ export function FormulaEditor({
);
}
+const TIMEFRAME_PICKER_WIDTH = 260;
+
const pickerActionButtonStyle = {
border: 0,
borderRadius: 4,
diff --git a/packages/desktop-client/src/components/modals/EditFieldModal.tsx b/packages/desktop-client/src/components/modals/EditFieldModal.tsx
index 15fe055550..0c4e11de8f 100644
--- a/packages/desktop-client/src/components/modals/EditFieldModal.tsx
+++ b/packages/desktop-client/src/components/modals/EditFieldModal.tsx
@@ -6,6 +6,7 @@ import { Button } from '@actual-app/components/button';
import { useResponsive } from '@actual-app/components/hooks/useResponsive';
import { Input } from '@actual-app/components/input';
import { theme } from '@actual-app/components/theme';
+import { tokens } from '@actual-app/components/tokens';
import { View } from '@actual-app/components/view';
import { currentDay, dayFromDate } from '@actual-app/core/shared/months';
import {
@@ -83,7 +84,8 @@ export function EditFieldModal({
const { isNarrowWidth } = useResponsive();
let label: string;
let editor: (props: { close: () => void }) => ReactNode;
- let minWidth: number | undefined;
+ let width: string | undefined;
+ let height: number | 'auto' = 275;
const inputStyle: CSSProperties = {
...(isNarrowWidth && itemStyle),
@@ -102,7 +104,10 @@ export function EditFieldModal({
case 'date': {
const today = currentDay();
label = t('Date');
- minWidth = 350;
+ // Definite width — the embedded calendar's 100%-wide grid must not
+ // size the modal (see DateSelect)
+ width = tokens.breakpoint_small;
+ height = 'auto'; // fit the calendar; 275 clips six-row months
editor = ({ close }) => (
<DateSelect
value={formatDate(parseISO(today), dateFormat)}
@@ -266,9 +271,9 @@ export function EditFieldModal({
style: {
height: isNarrowWidth
? 'calc(var(--visual-viewport-height) * 0.85)'
- : 275,
+ : height,
padding: '15px 10px',
- ...(minWidth && { minWidth }),
+ ...(width && { width }),
backgroundColor: theme.menuAutoCompleteBackground,
},
}}
diff --git a/packages/desktop-client/src/components/select/DateSelect.tsx b/packages/desktop-client/src/components/select/DateSelect.tsx
index a8f1bf7e94..b084764319 100644
--- a/packages/desktop-client/src/components/select/DateSelect.tsx
+++ b/packages/desktop-client/src/components/select/DateSelect.tsx
@@ -148,6 +148,7 @@ type DatePickerProps = {
onUpdate: (selectedDate: Date) => void;
onSelect: (selectedDate: Date) => void;
attached?: boolean;
+ embedded?: boolean;
};
type DatePickerForwardedRef = {
@@ -155,7 +156,16 @@ type DatePickerForwardedRef = {
};
const DatePicker = forwardRef<DatePickerForwardedRef, DatePickerProps>(
(
- { value, dateFormat, locale, firstDayOfWeek, onUpdate, onSelect, attached },
+ {
+ value,
+ dateFormat,
+ locale,
+ firstDayOfWeek,
+ onUpdate,
+ onSelect,
+ attached,
+ embedded,
+ },
ref,
) => {
const { t } = useTranslation();
@@ -221,6 +231,17 @@ const DatePicker = forwardRef<DatePickerForwardedRef, DatePickerProps>(
boxShadow: 'none',
},
},
+ // Embedded: stretch the grid to the container with equal columns
+ // (same technique as DayRangeCalendar). The container must have a
+ // definite width — a 100%-wide table blows up shrink-to-fit boxes.
+ embedded && {
+ '& .react-aria-Calendar': { width: '100%' },
+ '& .react-aria-CalendarGrid': {
+ width: '100%',
+ tableLayout: 'fixed',
+ },
+ '& .react-aria-CalendarCell': { width: 'auto' },
+ },
{ flex: 1 },
])}
data-date-picker
@@ -514,6 +535,7 @@ function DateSelectDesktop({
locale={locale}
firstDayOfWeek={firstDayOfWeek}
attached={!!onTransferDateSyncChange}
+ embedded={embedded}
onUpdate={date => {
setSelectedValue(format(date, dateFormat));
onUpdate?.(format(date, 'yyyy-MM-dd'));
diff --git a/upcoming-release-notes/fix-bulk-edit-date-picker.md b/upcoming-release-notes/fix-bulk-edit-date-picker.md
new file mode 100644
index 0000000000..838e02e4ad
--- /dev/null
+++ b/upcoming-release-notes/fix-bulk-edit-date-picker.md
@@ -0,0 +1,6 @@
+---
+category: Bugfix
+authors: [zannis]
+---
+
+Fix the misformatted date picker when bulk editing transaction dates