Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions .changeset/37521-rich-text-cell-docs-select-first.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
---
'@object-ui/fields': patch
'@object-ui/components': patch
'@object-ui/types': patch
---

fix(ui): the rich-text cell text, the read-only `data-table` warning and the `onBatchSave` refusal describe the one editing model the grid has

Clause-②: no
Metadata-protocol: none

The list grid has one way to edit: select-first, each committed cell saved at once. Three shipped texts still described the retired staged model or named the wrong thing to mount.

- **`@object-ui/fields`.** The README's "grid cell editor's face" section and the `FieldEditWidget` comment on the rich-content cell panel no longer say that a grid without `cellSelection` opens the `markdown`, `html` or `richtext` box over the cell and keeps its text for the grid's save buttons. The grid edits only in its select-first model, and it opens the box in a panel under the cell: Enter is a new line, Ctrl/Cmd+Enter or a click outside saves, Esc discards.
- **`@object-ui/components`.** The console warning for an editable `data-table` that renders read-only now tells the host to mount `GridCellSelectionProvider`. It named `GridCellSelection`, which is the context's value type and cannot be mounted. The table's host-injected cell editor no longer checks for the select-first model on each key, because an editor only opens inside that model. Tab and Ctrl/Cmd+Enter behave as before.
- **`@object-ui/types`.** The `data-table` schema's refusal of `onBatchSave` names its successor: `onBatchSave` → `onRowSave` on `object-grid`. Render an `object-grid`, which writes each committed cell through its data source, or pass `onRowSave` inside a `GridCellSelectionProvider` from a React host, and delete the key. It used to point the author at a toast or an `action:button` node. The key is refused exactly as before.

Nothing to migrate.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

/**
* `data-table`'s per-cell save in the select-first model (objectstack#35685),
* behind the `GridCellSelection` a host mounts.
* behind the `GridCellSelectionProvider` a host mounts.
*
* 1. A committed cell sends its record's update at once: one call, that
* cell only; no save bar, no row Save/Cancel column, no amber row; the
Expand Down Expand Up @@ -115,7 +115,7 @@ function deferredSave() {
}

describe('data-table autosave — a committed cell saves at once (objectstack#35685)', () => {
it('sends one update with that cell only, draws no save bar, no edit column and no amber row', async () => {
it('sends one update with that cell only, draws no save bar, no row Save button and no amber row', async () => {
const { onRowSave, calls } = deferredSave();
const t = renderTable(onRowSave);
t.typeAndEnter(0, 0, 'Alpha 2');
Expand All @@ -127,7 +127,6 @@ describe('data-table autosave — a committed cell saves at once (objectstack#35
expect(screen.queryByText(/Save All/)).toBeNull();
expect(screen.queryByText(/row modified/)).toBeNull();
expect(t.container.querySelector('button[title="Save row"]')).toBeNull();
expect(t.container.querySelector('[data-testid="data-table-edit-column-header"]')).toBeNull();
const firstRow = t.container.querySelectorAll('tbody tr')[0] as HTMLElement;
expect(firstRow.className).not.toContain('bg-amber-50');
expect(t.cell(0, 0).className).not.toContain('text-amber-700');
Expand Down Expand Up @@ -291,7 +290,10 @@ describe('data-table autosave — no staged fallback: a table that cannot save r
expect(onRowSave).not.toHaveBeenCalled();
const lines = warn.mock.calls.map((c) => String(c[0])).filter((m) => m.startsWith('[ObjectUI] DataTable editable:'));
expect(lines).toHaveLength(1);
expect(lines[0]).toMatch(/GridCellSelection/);
// The component a host mounts is the provider; `GridCellSelection` is the
// context's value type, which cannot be mounted.
expect(lines[0].match(/`GridCellSelectionProvider`/g)).toHaveLength(2);
expect(lines[0]).not.toContain('`GridCellSelection`');
});

it('under the provider with no onRowSave: no editor opens, no save bar, one console warning naming onRowSave', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

/**
* `data-table`'s select-first cell model (objectstack#35684), behind the
* `GridCellSelection` a host mounts. The list page mounts it through
* `GridCellSelectionProvider` a host mounts. The list page mounts it through
* `ObjectGrid`'s `cellSelection`; its keys while selected and while editing
* are `data-table-keys-35687.test.tsx`.
*
Expand Down Expand Up @@ -336,20 +336,17 @@ describe('data-table select-first — a cell that opens no editor says why', ()
});

describe('data-table select-first — no edit-only column, ever (objectstack#35554, objectstack#35685)', () => {
const editHeader = (c: HTMLElement) => c.querySelector('[data-testid="data-table-edit-column-header"]');
const lastHeader = (c: HTMLElement) => [...c.querySelectorAll('thead th')].pop()!;
// The shape `ObjectGrid` hands the list page: a save path and no row menu.
const EDIT_ONLY = { rowActions: true, onRowSave: () => Promise.resolve() };

it('none at rest and none after a commit: the commit saves itself', () => {
const onRowSave = vi.fn(() => Promise.resolve());
const t = renderTable({ extra: { ...EDIT_ONLY, onRowSave } });
expect(editHeader(t.container)).toBeNull();
expect(lastHeader(t.container)).toHaveTextContent('Site');
fireEvent.click(t.cell(0, 0));
fireEvent.change(t.catcher()!, { target: { value: 'A' } });
fireEvent.keyDown(t.editor()!, { key: 'Enter' });
expect(editHeader(t.container)).toBeNull();
expect(lastHeader(t.container)).toHaveTextContent('Site');
expect(t.container.querySelector('button[title="Save row"]')).toBeNull();
expect(onRowSave).toHaveBeenCalledTimes(1);
Expand Down Expand Up @@ -627,3 +624,38 @@ describe('data-table select-first — a read-only cell says so in the grid (obje
expect(t.container.querySelector('[aria-readonly]')).toBeNull();
});
});

describe('data-table select-first — an injected editor keeps the model\'s keys (objectstack#35687)', () => {
// An editor opens only inside the select-first model (an `editable` table
// with no select-first host is read-only), so a host-injected editor's Tab
// and Ctrl/Cmd+Enter always follow that model.
const renderCellEditor = (ctx: { value: unknown; stage: (v: unknown) => void }) => (
<textarea aria-label="name editor" value={String(ctx.value ?? '')} onChange={(e) => ctx.stage(e.target.value)} />
);
const openEditor = () => {
const t = renderTable({ extra: { renderCellEditor } });
fireEvent.click(t.cell(0, 0));
fireEvent.keyDown(t.catcher()!, { key: 'Enter' });
const area = screen.getByLabelText('name editor');
fireEvent.change(area, { target: { value: 'Alpha 2' } });
return { t, area };
};

it('Tab commits a multi-line editor and moves to the next cell', () => {
const { t, area } = openEditor();
fireEvent.keyDown(area, { key: 'Tab' });
expect(screen.queryByLabelText('name editor')).toBeNull();
expect(t.onCellChange).toHaveBeenLastCalledWith(0, 'name', 'Alpha 2', ROWS[0]);
expect(t.cell(0, 1)).toHaveAttribute('aria-selected', 'true');
});

it('Enter is a new line; Ctrl/Cmd+Enter commits and the cell stays selected', () => {
const { t, area } = openEditor();
fireEvent.keyDown(area, { key: 'Enter' });
expect(screen.getByLabelText('name editor')).toBeInTheDocument();
fireEvent.keyDown(area, { key: 'Enter', ctrlKey: true });
expect(screen.queryByLabelText('name editor')).toBeNull();
expect(t.onCellChange).toHaveBeenLastCalledWith(0, 'name', 'Alpha 2', ROWS[0]);
expect(t.cell(0, 0)).toHaveAttribute('aria-selected', 'true');
});
});
33 changes: 13 additions & 20 deletions ui/packages/components/src/renderers/complex/data-table.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4069,7 +4069,7 @@ const DataTableRenderer = ({ schema }: { schema: DataTableSchema }) => {
// its first control, once it has drawn one (a lazily loaded picker draws it
// a few frames late). Before this the caret stayed on the cell.
useEffect(() => {
if (!selectFirst || !editingCell) return undefined;
if (!editingCell) return undefined;
let frame = 0;
let frames = 0;
const place = () => {
Expand All @@ -4083,7 +4083,7 @@ const DataTableRenderer = ({ schema }: { schema: DataTableSchema }) => {
};
place();
return () => cancelAnimationFrame(frame);
}, [editingCell, selectFirst]);
}, [editingCell]);

// Commit a host-injected widget editor on click-outside (objectui#2321).
//
Expand Down Expand Up @@ -5080,7 +5080,7 @@ const DataTableRenderer = ({ schema }: { schema: DataTableSchema }) => {
const cellValue = hasPendingChange ? rowChanges[col.accessorKey] : originalValue;
const isEditing = editingCell !== null && editingCell.rowKey === rowKey && editingCell.columnKey === col.accessorKey;
// objectstack#36023 — a picker's panel opens under the cell, which keeps its value drawn.
const editsBelow = isEditing && selectFirst && editorBelow;
const editsBelow = isEditing && editorBelow;
// The reason the last refusal gave for THIS cell, if it
// named it (objectstack-ai/objectstack#27520).
const cellError = rowCellErrors?.[col.accessorKey];
Expand Down Expand Up @@ -5394,7 +5394,7 @@ const DataTableRenderer = ({ schema }: { schema: DataTableSchema }) => {
// objectstack#35688 — a pick that commits hands the
// focus back to the selected cell, as Enter does.
commit: (v?: any) => {
focusSelectionRef.current = selectFirst;
focusSelectionRef.current = true;
if (!saveEdit(true, v)) focusSelectionRef.current = false;
},
cancel: cancelEdit,
Expand All @@ -5417,17 +5417,10 @@ const DataTableRenderer = ({ schema }: { schema: DataTableSchema }) => {
// textarea it's left alone so Enter opens the
// dropdown / inserts a newline as usual.
//
// Outside the select-first model, Tab is
// deliberately NOT in that list, and
// tabbing out therefore does not leave edit
// mode — measured, `64d937c53`. It costs
// nothing: the widget has already staged
// every keystroke into `pendingChanges` (or,
// reading its input on blur, staged on the
// Tab's own blur — objectui#12664), so
// the value is safe; the cell simply stays
// open until Enter, Escape, or a pointer
// press outside closes it.
// An editor opens only in the select-first
// model (`startEdit` refuses a table that is
// not `editable`, and `editable` needs that
// model), so its keys are always the model's.
return (
<div
ref={(n) => { injectedEditorElRef.current = n; }}
Expand All @@ -5439,19 +5432,19 @@ const DataTableRenderer = ({ schema }: { schema: DataTableSchema }) => {
const tag = (e.target as HTMLElement).tagName;
// The select-first model (objectstack#35687): in a
// multi-line editor Ctrl/Cmd+Enter commits, and Tab
// commits and moves, superseding the Tab-stays rule.
// commits and moves.
const commits = (e.key === 'Enter' && (tag === 'INPUT'
|| (selectFirst && tag === 'TEXTAREA' && (e.ctrlKey || e.metaKey))))
|| (selectFirst && e.key === 'Tab');
|| (tag === 'TEXTAREA' && (e.ctrlKey || e.metaKey))))
|| e.key === 'Tab';
if (commits) {
e.preventDefault();
// A commit-on-blur widget stages
// on this blur (objectui#12664).
flushInjectedEditor();
if (saveEdit(true) && selectFirst) commitMoves(e);
if (saveEdit(true)) commitMoves(e);
} else if (e.key === 'Escape') {
e.preventDefault();
focusSelectionRef.current = selectFirst;
focusSelectionRef.current = true;
exitEdit(true);
}
}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ export const DATA_TABLE_EDITABLE_DIAGNOSTIC_PREFIX = '[ObjectUI] DataTable edita
* The table has ONE editing model: select-first, each committed cell saved at
* once through `onRowSave`. The staged model — click-to-edit, a
* pending-changes bar and "Save All" through `onBatchSave` — is retired, so an
* `editable` table without both a select-first host (`GridCellSelection`) and
* `editable` table without both a select-first host (`GridCellSelectionProvider`) and
* an `onRowSave` slot has no way to save an edit. It draws read-only rather
* than hold an edit nothing sends; this line says so, once per node, on the
* channel the other diagnostics in this module use.
Expand All @@ -314,12 +314,12 @@ export function describeUnsavableEditable(
): string | null {
if (!editable || (savePath.selectFirst && savePath.rowSave)) return null;
const missing = [
savePath.selectFirst ? null : 'no select-first cell model is mounted around it (`GridCellSelection`)',
savePath.selectFirst ? null : 'no select-first cell model is mounted around it (`GridCellSelectionProvider`)',
savePath.rowSave ? null : 'no `onRowSave` slot is supplied to save each committed cell',
].filter((part): part is string => part !== null);
return `${DATA_TABLE_EDITABLE_DIAGNOSTIC_PREFIX} ${describeAddress(address)} — `
+ `\`editable: true\` is refused and the table renders read-only: ${missing.join(', and ')}. `
+ 'Inline editing saves each committed cell on its own; there is no staged "Save All" mode.\n'
+ ' Render an `object-grid` (`ObjectGrid`), which mounts both and writes through its data '
+ 'source, or mount `GridCellSelection` and pass `onRowSave` in code.';
+ 'source, or mount `GridCellSelectionProvider` and pass `onRowSave` in code.';
}
9 changes: 4 additions & 5 deletions ui/packages/fields/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -167,11 +167,10 @@ they stay in `INLINE_EXCLUDED_FIELD_TYPES` and `hasFieldEditWidget` answers
`false` for them, so every other host keeps them out, while
`hasInCellPanelEditWidget(type)` answers `true` and `FieldEditWidget` draws the
form's rich-text box for them (loaded lazily) when the host asks for the cell
face. A select-first list grid (`cellSelection`) opens it in a panel under the
cell, where Enter is a new line, Ctrl/Cmd+Enter saves, Esc discards and a click
outside saves; a grid without `cellSelection` opens it over the cell, where
Ctrl/Cmd+Enter does nothing and a click outside keeps the text as a pending
change for the grid's save buttons.
face. The list grid edits only in its select-first model, and it opens the box
in a panel under the cell, where Enter is a new line, Ctrl/Cmd+Enter saves, Esc
discards and a click outside saves; the cell keeps showing its value. A table
with no select-first host edits nothing, rich text included.

### Resolving declared action params

Expand Down
8 changes: 3 additions & 5 deletions ui/packages/fields/src/FieldEditWidget.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -212,11 +212,9 @@ export const INLINE_EXCLUDED_FIELD_TYPES = new Set<string>([
* Members of {@link INLINE_EXCLUDED_FIELD_TYPES} that the LIST GRID's cell
* nevertheless edits, in a panel opened under the cell (objectstack#36023):
* the rich-content types, whose panel is the form's own text box over the
* stored source. Enter in it is a new line; a select-first grid
* (`cellSelection`) saves on Ctrl/Cmd+Enter or a click outside and discards on
* Esc. A grid without `cellSelection` opens the box over the cell instead, where
* Ctrl/Cmd+Enter does nothing, Esc discards and a click outside keeps the text
* as a pending change for the grid's save buttons.
* stored source. Enter in it is a new line; Ctrl/Cmd+Enter or a click outside
* saves and Esc discards. The grid edits only in its select-first model, so
* the panel under the cell is the only place these types are edited in a grid.
*
* Only a host that asks for the cell face (`inCell`) gets them, so the record
* page's field editor, the required-fields dialogs and every other host of
Expand Down
5 changes: 2 additions & 3 deletions ui/packages/plugin-form/src/affordanceGrantMap-12082.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -904,9 +904,8 @@ const WRITE_SITES: Record<string, WriteSite> = {
...mapped(['listImport'], CONSOLE_LIST, 'packages/app-shell/src/views/importTargetFields.ts'),
note: "the console list's Import reads the row where it offers Import; HOST_GATED below holds every mount of the wizard to this list",
} as WriteSite,
// The inline-edit saves (objectui#12292): `defaultRowSave` and
// `defaultBatchSave` both write through `writeRowGuarded`, the `If-Match`
// write; `resolveRowConflict` is the same save's Overwrite after a 409, re-keyed
// The inline-edit save (objectui#12292): `defaultRowSave` writes through
// `writeRowGuarded`, the `If-Match` write; `resolveRowConflict` is the same save's Overwrite after a 409, re-keyed
// to the server's version. One affordance, the grid's `listInlineEdit` row.
'packages/plugin-grid/src/ObjectGrid.tsx :: ObjectGrid > writeRowGuarded :: update': mapped(['listInlineEdit'], OBJECT_GRID),
'packages/plugin-grid/src/ObjectGrid.tsx :: ObjectGrid > resolveRowConflict :: update': mapped(['listInlineEdit'], OBJECT_GRID),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -201,14 +201,6 @@ async function kebabOffersEdit(c: Case): Promise<boolean> {
return screen.queryAllByTestId('row-action-builtin-edit').length > 0;
}

/** Header cell count — the observable for the save/cancel `rowActions` column. */
async function headerCellCount(c: Case): Promise<number> {
const { container } = renderGrid(c);
await waitFor(() => expect(screen.getByText('Row One')).toBeInTheDocument());
await waitFor(() => expect(screen.getByText('Row Two')).toBeInTheDocument());
return container.querySelectorAll('thead th').length;
}

beforeEach(() => {
state.permUpdate = true;
state.effectiveOps = undefined;
Expand Down Expand Up @@ -248,22 +240,6 @@ describe("ObjectGrid `editable` vs can(object, 'update') (#5143)", () => {
cleanup();
expect(await entersEditState({ editable: true, permUpdate: true })).toBe(true);
});

it('e — no verdict draws a save/cancel column: the gated grid IS the non-editable grid', async () => {
// The staged model drew a trailing save/cancel column on an editable grid,
// and this case pinned that a read-only principal did not get it. That
// column is retired with the staged model (objectstack#35827): each cell
// saves on its own, so an editable grid, a gated one and a never-editable
// one are column-for-column the same.
const editableWithGrant = await headerCellCount({ editable: true, permUpdate: true });
cleanup();
const editableNoGrant = await headerCellCount({ editable: true, permUpdate: false });
cleanup();
const neverEditable = await headerCellCount({ permUpdate: true });

expect(editableNoGrant).toBe(neverEditable);
expect(editableWithGrant).toBe(neverEditable);
});
});

describe('ObjectGrid inline edit vs the object-level affordance (#5143)', () => {
Expand Down
Loading
Loading