Skip to content

armgit / macro

Public Imported from GitHub
0

Macro is a unified workspace for teams: email, chat, docs, tasks, agents, calls, and CRM — @-linked together with shared AI memory.

fix(databases): reject unsafe integers before saving cell edits (#7578)

Wolf Mermelsteindc4cffde3807
diff --git a/apps/web/src/features/block-database/browser-test/table.browser.e2e.ts b/apps/web/src/features/block-database/browser-test/table.browser.e2e.ts
index f276107c85..a97f49571a 100644
--- a/apps/web/src/features/block-database/browser-test/table.browser.e2e.ts
+++ b/apps/web/src/features/block-database/browser-test/table.browser.e2e.ts
@@ -67,6 +67,26 @@ test('resizes from the rendered width and saves once on release', async ({
.toBe(Math.round(before.width + 70));
});
+test('keeps an unsafe integer draft instead of saving a rounded value', async ({
+ page,
+}) => {
+ await page.getByRole('button', { name: /^Amount: 12\./ }).click();
+ const input = page.getByRole('textbox', { name: 'Edit Amount' });
+ await input.fill('9007199254740993');
+ await input.press('Tab');
+ await expect(page.getByRole('alert')).toHaveText('Enter a valid number');
+ await expect(input).toBeFocused();
+ await expect(input).toHaveValue('9007199254740993');
+ await expect(page.getByLabel('Writes', { exact: true })).toHaveText('0');
+
+ await input.fill('1.25e3');
+ await input.press('Enter');
+ await expect(page.getByLabel('Writes', { exact: true })).toHaveText('1');
+ await expect(
+ page.getByRole('button', { name: /^Amount: 1,250\./ })
+ ).toBeFocused();
+});
+
test('sorts through the column menu and keeps sorting when switching layouts', async ({
page,
}) => {
diff --git a/apps/web/src/features/block-database/browser-test/table.tsx b/apps/web/src/features/block-database/browser-test/table.tsx
index 9125663e9e..ca632b06f3 100644
--- a/apps/web/src/features/block-database/browser-test/table.tsx
+++ b/apps/web/src/features/block-database/browser-test/table.tsx
@@ -39,18 +39,31 @@ function TableFixture() {
{ id: 'done', label: 'Done', color: null },
],
},
+ {
+ id: 'amount',
+ name: 'Amount',
+ dataType: 'NUMBER',
+ writable: true,
+ isMultiSelect: false,
+ options: [],
+ },
]);
const [rows, setRows] = createSignal<DatabaseRow[]>([
{
rowId: 'one',
- cells: { name: 'First', notes: 'First note', status: 'Open' },
+ cells: { name: 'First', notes: 'First note', status: 'Open', amount: 12 },
},
{
rowId: 'two',
- cells: { name: 'Second', notes: 'Second note', status: 'Done' },
+ cells: {
+ name: 'Second',
+ notes: 'Second note',
+ status: 'Done',
+ amount: 24,
+ },
},
]);
- const [order, setOrder] = createSignal(['name', 'notes', 'status']);
+ const [order, setOrder] = createSignal(['name', 'notes', 'status', 'amount']);
const [widths, setWidths] = createSignal<Record<string, number | null>>({});
const [sort, setSort] = createSignal<SortKey[]>([]);
const [resizeSaves, setResizeSaves] = createSignal(0);
diff --git a/apps/web/src/features/block-database/component/GridCell.test.tsx b/apps/web/src/features/block-database/component/GridCell.test.tsx
index 5d70143855..6a6c4c3fa2 100644
--- a/apps/web/src/features/block-database/component/GridCell.test.tsx
+++ b/apps/web/src/features/block-database/component/GridCell.test.tsx
@@ -752,6 +752,58 @@ describe('grid cell', () => {
expect(onWrite).not.toHaveBeenCalled();
});
+ it.each(['9007199254740993', '-9007199254740993', '0x10', '1e309'])(
+ 'keeps the numeric draft %s instead of silently coercing it on save',
+ (draft) => {
+ const onWrite = vi.fn(async () => true);
+ render(() => (
+ <GridCell
+ column={{ ...column, dataType: 'NUMBER' }}
+ value={12}
+ canEdit
+ onWrite={onWrite}
+ onAddOption={vi.fn(async () => true)}
+ />
+ ));
+ fireEvent.click(screen.getByRole('button', { name: /Name: 12/ }));
+ const input = screen.getByRole('textbox', { name: 'Edit Name' });
+ fireEvent.input(input, { target: { value: draft } });
+ fireEvent.keyDown(input, { key: 'Enter' });
+ expect(screen.getByRole('alert').textContent).toBe(
+ 'Enter a valid number'
+ );
+ expect(document.activeElement).toBe(input);
+ expect((input as HTMLInputElement).value).toBe(draft);
+ expect(onWrite).not.toHaveBeenCalled();
+ }
+ );
+
+ it.each([
+ ['9007199254740991', Number.MAX_SAFE_INTEGER],
+ ['-12.5', -12.5],
+ ['.75', 0.75],
+ ['1.25e3', 1250],
+ ])('saves the numeric draft %s without losing its value', (draft, value) => {
+ const onWrite = vi.fn(async () => true);
+ render(() => (
+ <GridCell
+ column={{ ...column, dataType: 'NUMBER' }}
+ value={12}
+ canEdit
+ onWrite={onWrite}
+ onAddOption={vi.fn(async () => true)}
+ />
+ ));
+ fireEvent.click(screen.getByRole('button', { name: /Name: 12/ }));
+ fireEvent.input(screen.getByRole('textbox', { name: 'Edit Name' }), {
+ target: { value: draft },
+ });
+ fireEvent.keyDown(screen.getByRole('textbox', { name: 'Edit Name' }), {
+ key: 'Enter',
+ });
+ expect(onWrite).toHaveBeenCalledExactlyOnceWith(value);
+ });
+
it('opens a select through its editor control and tabs directly to a text field', async () => {
let select: GridCellControl | undefined;
let next: GridCellControl | undefined;
diff --git a/apps/web/src/features/block-database/component/GridCell.tsx b/apps/web/src/features/block-database/component/GridCell.tsx
index c39ea986e9..0553cc451c 100644
--- a/apps/web/src/features/block-database/component/GridCell.tsx
+++ b/apps/web/src/features/block-database/component/GridCell.tsx
@@ -29,9 +29,10 @@ import {
import { SelectPill } from '../components/select-pill';
import { useOptionEditing } from '../context/option-editing';
import { fromCellDate, toCellDate } from '../core/cell-date';
-import type {
- DatabaseEntityType,
- DatabaseMention,
+import {
+ type DatabaseEntityType,
+ type DatabaseMention,
+ inferDatabaseNumber,
} from '../core/column-inference';
import {
type DatabaseCellValue,
@@ -631,9 +632,9 @@ function InlineEditor(props: {
props.draft.trim() === ''
? null
: props.column.dataType === 'NUMBER'
- ? Number(props.draft)
+ ? inferDatabaseNumber(props.draft)
: props.draft;
- if (typeof value === 'number' && !Number.isFinite(value)) {
+ if (value === undefined) {
setError('Enter a valid number');
input?.focus();
return false;
diff --git a/docs/AGENT_GUIDE/databases.md b/docs/AGENT_GUIDE/databases.md
index 76128ad796..624d4fef1e 100644
--- a/docs/AGENT_GUIDE/databases.md
+++ b/docs/AGENT_GUIDE/databases.md
@@ -162,7 +162,9 @@ skipped. Select values open the option picker; checkboxes change
directly. Type on a selected select cell to search its options; Enter chooses a
match, and Tab chooses the highlighted option or typed match before moving on.
Number cells display thousands separators (for example, `100,000`); opening an
-editor shows the raw number for editing.
+editor shows the raw number for editing. Invalid numbers and integers outside the
+safe integer range stay in the editor with **Enter a valid number** instead of
+saving a rounded value. Signed decimals and scientific notation remain supported.
Date cells open Macro's date selector (the one tasks use): type a date or phrase
such as `tomorrow`, `3d`, or `feb 17` and press Enter, or pick **Custom date...**