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/35956-stage-menu-shared-fill-in.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
---
'@object-ui/fields': patch
'@object-ui/plugin-detail': patch
---

feat(detail): the record header's stage menu asks for the fields a stage needs through the shared fill-in dialog

Clause-②: no
Metadata-protocol: none

The stage menu beside the record's name now opens the same dialog the list cell, the record page's inline Save and the kanban drop open (`RequiredFieldsDialog`, with `collectRequiredWhenPromptFields` judging which fields to ask for), and its own copy of the pre-check and field form is gone:

- **What it shows:** the record's name and the move (「阶段:赢单」, read-only), then the fields the stage makes required while they are still empty. A stage that needs nothing opens the same dialog as the move's confirmation, with Move focused so Enter confirms.
- **Move** writes the stage and the typed values as ONE update; **Cancel** writes nothing. A value typed there that makes one more field required adds that field, and Move waits for it.
- **A refusal stays in the dialog** and the stage does not move: under the field it names, as a new row for another field the reader can fill, or at the foot (someone else changed the record, which is then re-read; a permission or other refusal as the stage line it was before).
- **Now not asked for, and refused as before:** a field with no in-place editor (rich text, a file, a formula). The menu's old form did not ask whether a field has one; the shared pre-check never offers such a field.

`record:path`'s stage press keeps its plain confirmation.
19 changes: 18 additions & 1 deletion ui/packages/fields/src/RequiredFieldsDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,13 @@
* the preview gallery) reads English instead of a raw key. The host may pass
* its own `title`, `description` and `submitLabel` (the board keeps its
* 「移动卡片」).
*
* ## Nothing to fill
*
* A host may open it with no fields (the record header's stage menu, whose
* every move goes through this dialog): it is then the change's confirmation,
* the record and the change above Cancel and Save, and Save takes the focus.
* A refusal naming a field the reader can fill still adds that field.
*/

import React from 'react';
Expand Down Expand Up @@ -164,6 +171,7 @@ export function RequiredFieldsDialog({
const [footLines, setFootLines] = React.useState<string[]>([]);
const [sending, setSending] = React.useState(false);
const busy = !!submitting || sending;
const submitRef = React.useRef<HTMLButtonElement>(null);

const shown: RequiredFieldsDialogField[] = [];
const seen = new Set<string>();
Expand Down Expand Up @@ -226,6 +234,15 @@ export function RequiredFieldsDialog({
<DialogContent
className="sm:max-w-md max-h-[90dvh] overflow-y-auto"
data-testid="required-fields-dialog"
onOpenAutoFocus={(event) => {
// With fields to fill the first one takes focus (the default). With
// none — a host using the dialog as the change's confirmation, the
// record header's stage menu — Save does, so Enter confirms the
// change the reader just picked rather than Cancel (objectstack#35891).
if (shown.length > 0 || !submitRef.current) return;
event.preventDefault();
submitRef.current.focus();
}}
>
<DialogHeader>
<DialogTitle>
Expand Down Expand Up @@ -318,7 +335,7 @@ export function RequiredFieldsDialog({
<Button variant="outline" onClick={onCancel} disabled={busy}>
{tt('common.cancel', 'Cancel')}
</Button>
<Button onClick={() => { void handleSubmit(); }} disabled={busy}>
<Button ref={submitRef} onClick={() => { void handleSubmit(); }} disabled={busy}>
{submitLabel ?? tt('common.save', 'Save')}
</Button>
</DialogFooter>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,3 +138,30 @@ describe('RequiredFieldsDialog in place (objectstack#35956)', () => {
expect(onSubmit).not.toHaveBeenCalled();
});
});

describe('RequiredFieldsDialog with nothing to fill (objectstack#35956 PR 2, the stage menu)', () => {
it('is the change confirmation: Save takes the focus, and Save submits at once', async () => {
const onSubmit = vi.fn();
render(
<RequiredFieldsDialog
open
fields={[]}
recordName="Acme deal"
changes={[{ name: 'stage', label: 'Stage', value: 'Negotiation' }]}
submitLabel="Move"
onCancel={vi.fn()}
onSubmit={onSubmit}
/>,
);
const dialog = screen.getByTestId('required-fields-dialog');
expect(dialog.querySelector('[data-required-fields-field]')).toBeNull();
await waitFor(() => expect(within(dialog).getByRole('button', { name: 'Move' })).toHaveFocus());
fireEvent.click(within(dialog).getByRole('button', { name: 'Move' }));
await waitFor(() => expect(onSubmit).toHaveBeenCalledWith({}));
});

it('control: with a field to fill, that field takes the focus, not Save', async () => {
const dialog = renderDialog(vi.fn());
await waitFor(() => expect(textboxOf(dialog, 'win_reason')).toHaveFocus());
});
});
7 changes: 4 additions & 3 deletions ui/packages/plugin-detail/src/RecordStageMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,10 @@
* `record:path`'s press asks (`useStageChange`).
* - A stage the field's blocking `state_machine` cannot reach from the stored
* value is drawn disabled, with the reason under its name.
* - Picking a stage opens the stage confirmation. A stage that needs other
* fields filled first asks for exactly those fields in the same dialog and
* writes them with the move; a refusal is shown in the dialog and the stage
* - Picking a stage opens the shared in-place fill-in dialog
* (`RequiredFieldsDialog`, objectstack#35956): the record's name, the move,
* and the fields the stage makes required, if any. The move and those
* values go in one write; a refusal is shown in the dialog and the stage
* does not move (`collectFields`, see `recordPathStageChange.tsx`).
* - The menu is Radix's: Enter or Space on the focused tag opens it, the arrow
* keys move, Enter picks, Esc closes without a change.
Expand Down
Loading
Loading