Skip to content
Merged
24 changes: 24 additions & 0 deletions .changeset/34794-studio-records-tab-authoring.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
---
'@object-ui/app-shell': patch
'@object-ui/i18n': patch
'@object-ui/components': patch
---

feat(studio): the Data pillar's Records tab keeps Add field on screen, a header click opens the field, the name field leads, and the field inspector puts the label first

Clause-②: yes (widening) — an optional `columnMenuLabel` member on the exported `GridFieldAuthoring` context type of `@object-ui/components`, and new keys in the lazy `studio` namespace of the `@object-ui/i18n` packs; nothing that worked before is refused
Metadata-protocol: none

Studio's Data pillar, Records tab:

- **Add field is always on screen.** The records grid's toolbar row now starts with an Add field button that opens the same Add field popover. The trailing "+" column is kept. Both entries are offered only where a field may be added: not on a read-only package, not on an external object.
- **A header click opens the field.** Clicking a field's column header selects the field and opens its properties, and no longer sorts. Sort and hide are in the column menu, which a caret in every header now opens (the same menu a right-click opens). A column the object does not declare (such as the server's owner column) keeps the old click.
- **The name field leads.** The grid puts the object's name field first, frozen, in the shared order every list uses, and the server-injected columns (`owner_id`) after the author's fields. Only the Studio grid changes; runtime list views keep their column order.
- **The machine name is a tooltip.** The object's title no longer carries its machine name as a chip beside it; hovering the title shows it.

Field inspector:

- **The label comes first.** The display name is the first box. The API name moves into a collapsed "Developer info" section.
- **Delete is confirmed.** Remove moves from the inspector's footer into the header's "⋯" menu, and asks before it removes the field from the draft.

`@object-ui/components`: `GridFieldAuthoring` gains an optional `columnMenuLabel`. When a host sets it, every column header draws a caret, named by the value, that opens the table's own column menu (sort ascending, sort descending, hide). A table with no provider, or a provider that does not set the member, draws exactly the header it drew before.
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import * as React from 'react';
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
import { cleanup, render, screen, within } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
import { t, tFormat } from '../i18n';
import { t } from '../i18n';

type Row = Record<string, unknown>;

Expand Down Expand Up @@ -163,7 +163,8 @@ describe('ObjectFieldInspector — display-patch mode explains every locked cont
within(rail).getByLabelText(t('designer.field.visibleWhen', LOCALE)),
// The header's pair and each option row's.
...within(rail).getAllByRole('button', { name: t('engine.inspector.reorder.up', LOCALE) }),
within(rail).getByRole('button', { name: tFormat('designer.field.remove', LOCALE, { label: 'Industry' }) }),
// objectstack#34794 — Remove is the header's ⋯ menu, its one entry.
within(rail).getByTestId('field-more-menu'),
within(rail).getAllByTestId('option-value')[0]!,
];
for (const control of named) {
Expand All @@ -177,6 +178,9 @@ describe('ObjectFieldInspector — display-patch mode explains every locked cont
it('Tab reaches a lock, and focus or hover shows the reason as a tooltip', async () => {
const rail = mount('name');
const sentence = within(rail).getByTestId('field-base-patch-only').textContent!.trim();
// objectstack#34794 — the API name sits in the collapsed Developer info
// section: open it, as an author must, before Tab can reach its lock.
await userEvent.click(within(rail).getByTestId('field-developer-toggle'));
const apiNameLock = within(rail).getByTestId('field-apiname-input').closest<HTMLElement>('[data-disabled-reason]')!;
let reached = false;
for (let i = 0; i < 12 && !reached; i++) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -977,3 +977,80 @@ describe('ObjectFieldInspector — stored expression editor (objectstack#32576)'
await waitFor(() => expect(onBlocking).toHaveBeenLastCalledWith(0), { timeout: 3000 });
});
});

describe('ObjectFieldInspector — label first, API name under Developer info, delete behind ⋯ (objectstack#34794)', () => {
it('the label is the first input; the API name is in a Developer info section that opens collapsed', async () => {
renderField({ title: { type: 'text', label: 'Meeting' } }, 'title');
// The first input in document order, so the first one an author meets.
const inputs = Array.from(document.querySelectorAll('input, textarea'));
expect(inputs[0]).toBe(screen.getByTestId('field-label-input'));
expect(screen.getByTestId('field-apiname-input')).not.toBeVisible();
const toggle = screen.getByTestId('field-developer-toggle');
expect(toggle).toHaveTextContent(t('designer.field.section.developer', 'en-US'));
expect(toggle).toHaveAttribute('aria-expanded', 'false');
await userEvent.click(toggle);
expect(toggle).toHaveAttribute('aria-expanded', 'true');
expect(screen.getByTestId('field-apiname-input')).toBeVisible();
expect(screen.getByTestId('field-apiname-input')).toHaveValue('title');
});

it('renaming from the opened section still renames, and a taken name is still refused', async () => {
const { onPatch } = renderField(
{ title: { type: 'text', label: 'Meeting' }, place: { type: 'text', label: 'Place' } },
'title',
);
await userEvent.click(screen.getByTestId('field-developer-toggle'));
const box = screen.getByTestId('field-apiname-input');
fireEvent.change(box, { target: { value: 'meeting_name' } });
expect(Object.keys(onPatch.mock.calls.at(-1)![0].fields)).toEqual(['meeting_name', 'place']);
fireEvent.change(box, { target: { value: 'place' } });
expect(screen.getByTestId('field-apiname-refusal')).toBeInTheDocument();
});

it('no Remove button in the panel; Delete is in the header ⋯ menu and asks first — Cancel keeps the field, Delete removes it', async () => {
const onClearSelection = vi.fn();
const { onPatch } = renderField(
{ title: { type: 'text', label: 'Meeting' }, place: { type: 'text', label: 'Place' } },
'place',
{ onClearSelection },
);
const removeName = `Remove “Place”`;
expect(screen.queryByRole('button', { name: removeName })).not.toBeInTheDocument();

const more = screen.getByTestId('field-more-menu');
await userEvent.click(more);
await userEvent.click(await screen.findByRole('menuitem', { name: removeName }));
const dialog = await screen.findByRole('alertdialog');
expect(dialog).toHaveTextContent('Delete the field “Place”?');
await userEvent.click(within(dialog).getByTestId('field-remove-confirm-cancel'));
expect(onPatch).not.toHaveBeenCalled();
expect(onClearSelection).not.toHaveBeenCalled();

await userEvent.click(screen.getByTestId('field-more-menu'));
await userEvent.click(await screen.findByRole('menuitem', { name: removeName }));
await userEvent.click(within(await screen.findByRole('alertdialog')).getByTestId('field-remove-confirm-action'));
expect(Object.keys(onPatch.mock.calls.at(-1)![0].fields)).toEqual(['title']);
expect(onClearSelection).toHaveBeenCalled();
});

it('a read-only inspector draws the ⋯ menu disabled; an external object offers no Delete at all', () => {
renderField({ title: { type: 'text', label: 'Meeting' } }, 'title', { readOnly: true });
expect(screen.getByTestId('field-more-menu')).toBeDisabled();
cleanup();

render(
<ObjectFieldInspector
type="object"
name="remote_account"
draft={{ name: 'remote_account', external: {}, fields: { title: { type: 'text', label: 'Meeting' } } }}
selection={{ kind: 'field', id: 'title' }}
onPatch={vi.fn()}
onClearSelection={vi.fn()}
readOnly={false}
locale={'en-US'}
/>,
);
expect(screen.getByTestId('field-label-input')).toBeInTheDocument();
expect(screen.queryByTestId('field-more-menu')).not.toBeInTheDocument();
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -82,12 +82,24 @@ import {
InspectorNumberField,
InspectorSelectField,
InspectorCheckboxField,
InspectorRemoveButton,
InspectorEmptyState,
moveArray,
} from './_shared.js';
import {
AlertDialog,
AlertDialogAction,
AlertDialogCancel,
AlertDialogContent,
AlertDialogDescription,
AlertDialogFooter,
AlertDialogHeader,
AlertDialogTitle,
Button,
cn,
DropdownMenu,
DropdownMenuContent,
DropdownMenuItem,
DropdownMenuTrigger,
Input,
Label,
Badge,
Expand All @@ -101,7 +113,7 @@ import {
TooltipProvider,
TooltipTrigger,
} from '@object-ui/components';
import { Plus, X, ArrowUp, ArrowDown, Copy, AlertTriangle } from 'lucide-react';
import { Plus, X, ArrowUp, ArrowDown, Copy, AlertTriangle, ChevronRight, MoreHorizontal, Trash2 } from 'lucide-react';
import { InspectorComboField, type InspectorComboOption } from './InspectorComboField.js';
import { ObjectPicker } from './ObjectPicker.js';
import { useObjectFields } from '../previews/useObjectFields.js';
Expand Down Expand Up @@ -1381,6 +1393,24 @@ export function ObjectFieldInspector({

/* ─── Render ─── */

// objectstack#34794 — delete is in the header's ⋯ menu, confirmed first,
// not the panel's most prominent button. An external field offers none.
const removeLabel = typeof def.label === 'string' && def.label ? def.label : entry.name;
const moreMenu = external ? null : (
<DisplayPatchLock>
<FieldMoreMenu
label={tr('engine.studio.if.more')}
removeLabel={tFormat('designer.field.remove', locale, { label: removeLabel })}
confirmTitle={tFormat('designer.field.removeConfirmTitle', locale, { label: removeLabel })}
confirmBody={tr('designer.field.removeConfirmBody')}
confirmAction={tr('engine.edit.delete')}
cancelLabel={tr('engine.cancel')}
onRemove={removeField}
disabled={locked}
/>
</DisplayPatchLock>
);

const headerActions = (
<div className="flex items-center gap-1">
{!ddlLocked && (
Expand All @@ -1405,21 +1435,10 @@ export function ObjectFieldInspector({
/>
</DisplayPatchLock>
)}
{moreMenu}
</div>
);

const footer = external ? undefined : (
<DisplayPatchLock>
<InspectorRemoveButton
label={tFormat('designer.field.remove', locale, {
label: typeof def.label === 'string' ? def.label : entry.name,
})}
onClick={removeField}
disabled={locked}
/>
</DisplayPatchLock>
);

const typeMetaLabel = typeMeta ? t(`engine.fieldType.${typeMeta.id}`, locale) : undefined;
// objectui#11786 — read off the field as it stands, for the hints below.
const heldNeed = locked ? null : guardHeldNeed(entry.name, def);
Expand All @@ -1444,7 +1463,6 @@ export function ObjectFieldInspector({
onClose={onClearSelection}
closeLabel={tr('designer.field.close')}
headerActions={headerActions}
footer={footer}
>
{/* Basic */}
<Section title={tr('designer.field.section.basic')}>
Expand All @@ -1462,16 +1480,8 @@ export function ObjectFieldInspector({
<ExternalFieldBadge binding={external} state={externalWriteState} locale={locale} />
</div>
)}
<DisplayPatchLock>
<FieldApiNameInput
label={tr('designer.field.apiName')}
value={entry.name}
takenNames={takenNames}
onRename={setKey}
disabled={ddlLocked}
locale={locale}
/>
</DisplayPatchLock>
{/* objectstack#34794 — the label leads; the API name is in the
collapsed Developer info section below. */}
<InspectorTextField
label={tr('designer.field.label')}
value={typeof def.label === 'string' ? (def.label as string) : ''}
Expand Down Expand Up @@ -1574,6 +1584,24 @@ export function ObjectFieldInspector({
placeholder={tr('designer.field.helpTextPlaceholder')}
/>
</Section>
{/* objectstack#34794 — the field's API name: how the API and formulas
refer to it. Collapsed by default, since an everyday edit never
needs it; the rename, its checks and its hints are unchanged. */}
<DeveloperSection
title={tr('designer.field.section.developer')}
hint={tr('designer.field.section.developerHint')}
>
<DisplayPatchLock>
<FieldApiNameInput
label={tr('designer.field.apiName')}
value={entry.name}
takenNames={takenNames}
onRename={setKey}
disabled={ddlLocked}
locale={locale}
/>
</DisplayPatchLock>
</DeveloperSection>

{/* Type-specific */}
{(isPicklist(type) || isLookup(type) || offersReferenceNameVisible(type) || isComputed(type) || isNumeric(type) || isTexty(type) || offersValueDomain(type)) && (
Expand Down Expand Up @@ -1968,7 +1996,7 @@ export function ObjectFieldInspector({
</Section>
</InspectorShell>
);
// The shell draws the header's reorder pair and the footer's Remove, so the
// The shell draws the header's reorder pair and the ⋯ menu's Remove, so the
// reason their locks read is provided above it.
return <DisplayPatchReasonContext.Provider value={displayPatchReason}>{shell}</DisplayPatchReasonContext.Provider>;
}
Expand All @@ -1986,6 +2014,117 @@ function Section({ title, children }: { title: string; children: React.ReactNode
);
}

/**
* objectstack#34794 — a section collapsed by default: its title is the toggle,
* its one-line hint says what is inside. The body stays mounted and is only
* hidden while collapsed, so a control inside keeps its state across a toggle.
* Ephemeral UI state (ui/AGENTS.md #8): each field opens with it collapsed.
*/
function DeveloperSection({ title, hint, children }: { title: string; hint: string; children: React.ReactNode }) {
const [open, setOpen] = React.useState(false);
const bodyId = React.useId();
return (
<div className="space-y-2" data-testid="field-developer-section">
<button
type="button"
aria-expanded={open}
aria-controls={bodyId}
onClick={() => setOpen((v) => !v)}
data-testid="field-developer-toggle"
className="flex w-full items-center justify-between border-b pb-1 text-[10px] font-semibold uppercase tracking-wider text-muted-foreground hover:text-foreground"
>
{title}
<ChevronRight className={cn('h-3.5 w-3.5 transition-transform', open && 'rotate-90')} aria-hidden="true" />
</button>
<p className="text-[11px] leading-snug text-muted-foreground">{hint}</p>
<div id={bodyId} hidden={!open} className="space-y-2">
{children}
</div>
</div>
);
}

/**
* objectstack#34794 — the field header's ⋯ menu. Its Delete asks first: the
* delete leaves the panel's footer, so a confirmation stands in for the
* visibility the button had there.
*/
function FieldMoreMenu({
label,
removeLabel,
confirmTitle,
confirmBody,
confirmAction,
cancelLabel,
onRemove,
disabled,
}: {
label: string;
removeLabel: string;
confirmTitle: string;
confirmBody: string;
confirmAction: string;
cancelLabel: string;
onRemove: () => void;
disabled?: boolean;
}) {
const [confirming, setConfirming] = React.useState(false);
return (
<>
<DropdownMenu>
<DropdownMenuTrigger asChild>
<Button
type="button"
variant="ghost"
size="sm"
className="h-7 w-7 p-0"
aria-label={label}
title={label}
data-testid="field-more-menu"
// Its one entry is Delete: a locked field offers the menu disabled,
// so the lock's reason wraps a disabled control.
disabled={disabled}
>
<MoreHorizontal className="h-4 w-4" />
</Button>
</DropdownMenuTrigger>
<DropdownMenuContent align="end" className="w-52">
<DropdownMenuItem
data-testid="field-remove"
disabled={disabled}
className="text-destructive focus:text-destructive"
onSelect={() => setConfirming(true)}
>
<Trash2 className="mr-2 h-3.5 w-3.5" aria-hidden="true" />
{removeLabel}
</DropdownMenuItem>
</DropdownMenuContent>
</DropdownMenu>
<AlertDialog open={confirming} onOpenChange={setConfirming}>
<AlertDialogContent data-testid="field-remove-confirm">
<AlertDialogHeader>
<AlertDialogTitle>{confirmTitle}</AlertDialogTitle>
<AlertDialogDescription>{confirmBody}</AlertDialogDescription>
</AlertDialogHeader>
<AlertDialogFooter>
<AlertDialogCancel data-testid="field-remove-confirm-cancel">{cancelLabel}</AlertDialogCancel>
<AlertDialogAction
className="bg-destructive text-destructive-foreground hover:bg-destructive/90"
data-testid="field-remove-confirm-action"
onClick={() => {
setConfirming(false);
onRemove();
}}
>
{confirmAction}
</AlertDialogAction>
</AlertDialogFooter>
</AlertDialogContent>
</AlertDialog>
</>
);
}

/**
* The label this field is SHOWN with, when a translation overrides the source
* label the Label input edits (objectui#11782).
Expand Down
Loading
Loading