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
17 changes: 17 additions & 0 deletions .changeset/36292-record-field-set-placeholder.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
---
'@object-ui/plugin-detail': patch
'@object-ui/i18n': patch
---

feat(console): on the record page's field list an empty field you can edit reads 「设置{字段名}」 and one click fills it in; an editable value offers the copy icon too

Clause-②: yes (widening)
Metadata-protocol: none

The synthesized record page's field area (the side preview, the phone's 「详情」 tab, the wide page's pinned left column and a full page alone):

- **Empty editable fields read 「设置」 plus their label.** An empty value the reader can edit is drawn as light text, 「设置」 plus the field's label (`Set Phone` in English), and a single click on it opens the field's editor, as a click on any editable value already does. A read-only field, a field the caller may not write and a record that is not inline-editable keep the shared 「—」 placeholder. Empty fields still fold into the list's one 「显示 N 个空字段」 row; shown, they read 「设置…」 instead of 「—」.
- **An editable value can be copied without editing.** Its copy icon is drawn on hover or keyboard focus at the value's right, as a read-only value's is; it copies the value and does not enter edit. A touch screen draws none, as before for read-only values. The keyboard's way into edit (the pencil, drawn on focus only) is unchanged.
- Authored record pages and every other DetailView keep their faces: an empty field there reads 「—」 and an editable row keeps its double-click and pencil.

`@object-ui/i18n` widens: one new key in every pack, `detail.setField` (`Set {{field}}` / `设置{{field}}`).
1 change: 1 addition & 0 deletions ui/packages/i18n/src/locales/ar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1441,6 +1441,7 @@ const ar = {
updatedTime: "تاريخ التعديل",
recordNumber: "معرّف السجل",
clickToEdit: "انقر للتحرير",
setField: "تعيين {{field}}",
back: "رجوع",
edit: "تحرير",
editInline: "تحرير",
Expand Down
1 change: 1 addition & 0 deletions ui/packages/i18n/src/locales/de.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1659,6 +1659,7 @@ const de = {
updatedTime: "Geändert am",
recordNumber: "Datensatz-ID",
clickToEdit: "Zum Bearbeiten klicken",
setField: "{{field}} festlegen",
// objectui#3863 — base key. de's categories are exactly `one`/`other`, so this
// slot is unreachable here and equals `_other` for key-set parity.
showEmptyRelated: "+ {{count}} leer",
Expand Down
1 change: 1 addition & 0 deletions ui/packages/i18n/src/locales/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1906,6 +1906,7 @@ const en = {
updatedTime: 'Updated on',
recordNumber: 'Record ID',
clickToEdit: 'Click to edit',
setField: 'Set {{field}}',
// Attachments
dropFilesToUpload: 'Drop files here or click to upload',
attachmentCount: '{{count}} attachment',
Expand Down
1 change: 1 addition & 0 deletions ui/packages/i18n/src/locales/es.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1713,6 +1713,7 @@ const es = {
updatedTime: "Fecha de modificación",
recordNumber: "ID del registro",
clickToEdit: "Haga clic para editar",
setField: "Establecer {{field}}",
// objectui#3863 — base key, answering only a call made without a count. es's
// `many` (exact millions) has its own slot since objectui#11432; it repeats
// `_other` here because the count governs no noun complement.
Expand Down
1 change: 1 addition & 0 deletions ui/packages/i18n/src/locales/fr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1336,6 +1336,7 @@ const fr = {
updatedTime: "Modifié le",
recordNumber: "ID de l’enregistrement",
clickToEdit: "Cliquez pour modifier",
setField: "Définir {{field}}",
back: "Retour",
edit: "Modifier",
editInline: "Modifier",
Expand Down
1 change: 1 addition & 0 deletions ui/packages/i18n/src/locales/ja.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1659,6 +1659,7 @@ const ja = {
updatedTime: "更新日時",
recordNumber: "レコード ID",
clickToEdit: "クリックで編集",
setField: "{{field}}を設定",
// objectui#3863 — base key. ja has a single plural category (`other`), so this
// slot is unreachable here and equals `_other` for key-set parity.
showEmptyRelated: "+ {{count}} 件(空)",
Expand Down
1 change: 1 addition & 0 deletions ui/packages/i18n/src/locales/ko.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1659,6 +1659,7 @@ const ko = {
updatedTime: "수정 일시",
recordNumber: "레코드 ID",
clickToEdit: "클릭하여 편집",
setField: "{{field}} 설정",
// objectui#3863 — base key. ko has a single plural category (`other`), so this
// slot is unreachable here and equals `_other` for key-set parity.
showEmptyRelated: "+ {{count}}개 비어 있음",
Expand Down
1 change: 1 addition & 0 deletions ui/packages/i18n/src/locales/pt-BR.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1336,6 +1336,7 @@ const pt = {
updatedTime: "Atualizado em",
recordNumber: "ID do registro",
clickToEdit: "Clique para editar",
setField: "Definir {{field}}",
back: "Voltar",
edit: "Editar",
editInline: "Editar",
Expand Down
1 change: 1 addition & 0 deletions ui/packages/i18n/src/locales/ru.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1374,6 +1374,7 @@ const ru = {
updatedTime: "Дата изменения",
recordNumber: "ID записи",
clickToEdit: "Нажмите, чтобы изменить",
setField: "Указать «{{field}}»",
back: "Назад",
edit: "Редактировать",
editInline: "Редактировать",
Expand Down
1 change: 1 addition & 0 deletions ui/packages/i18n/src/locales/zh-Hans.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1606,6 +1606,7 @@ const zh = {
updatedTime: '修改时间',
recordNumber: '记录编号',
clickToEdit: '点击编辑',
setField: '设置{{field}}',
// Attachments
dropFilesToUpload: '拖拽文件到此处或点击上传',
attachmentCount: '{{count}} 个附件',
Expand Down
1 change: 1 addition & 0 deletions ui/packages/i18n/src/locales/zh-Hant.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1606,6 +1606,7 @@ const zhHant = {
updatedTime: '修改時間',
recordNumber: '記錄編號',
clickToEdit: '點選編輯',
setField: '設定{{field}}',
// Attachments
dropFilesToUpload: '拖拽檔案到此處或點選上傳',
attachmentCount: '{{count}} 個附件',
Expand Down
32 changes: 25 additions & 7 deletions ui/packages/plugin-detail/src/DetailSection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -628,9 +628,22 @@ export const DetailSection: React.FC<DetailSectionProps> = ({
const fieldEditable =
!isReadonly && !isComputedField && !isSystemField && !isInlineExcluded && isWriteGranted;
const canInlineEditField = fieldEditable && !!onEnterInlineEdit;
const fieldLabelText = fieldLabel(objectName || '', field.name, field.label || field.name);

const displayValue = (() => {
const isEmpty = !hasCellValue(value);
// On the record page's field face an empty value the reader can fill in
// reads "Set <label>", light, and the row's one click opens its editor.
// Only where a click edits: a read-only field, a field without the
// write grant and a record that is not inline-editable keep the shared
// placeholder below, and so does every face that edits on a double-click.
if (isEmpty && frameless && canInlineEditField) {
return (
<span className="text-muted-foreground/70" data-detail-set-field="">
{t('detail.setField', { field: fieldLabelText, defaultValue: 'Set {{field}}' })}
</span>
);
}
if (isEmpty) {
// The SHARED placeholder (objectui#8506). The span that stood here
// spelled its own em-dash and resolved its own `aria-label` from
Expand Down Expand Up @@ -844,9 +857,10 @@ export const DetailSection: React.FC<DetailSectionProps> = ({
// (the desktop row, its Enter/Space, its hover button, and the mobile
// grouped-inset row's click and Enter/Space).
const copyOffered = canCopy && !isMaskedField;
// An editable field surfaces the pencil (edit) affordance instead of the
// copy affordance, and reserves single-click for text selection — so
// click-to-copy only applies to non-editable fields.
// An editable field surfaces the pencil (edit) affordance, and its click
// is never a copy — so click-to-copy only applies to non-editable fields.
// Off the field face the pencil stands instead of the copy button; on it
// the copy button stands beside the keyboard-only pencil.
// The frameless face (the record page's field list, objectstack#36147)
// takes no click on a read-only row: a click there selects text, and the
// value is copied from its hover / focus button. An editable row's click
Expand All @@ -860,7 +874,6 @@ export const DetailSection: React.FC<DetailSectionProps> = ({
? t('detail.clickToEdit', { defaultValue: 'Click to edit' })
: t('detail.editInlineHint');
const isCopied = copiedField === field.name;
const fieldLabelText = fieldLabel(objectName || '', field.name, field.label || field.name);

// iOS-style grouped-inset row (mobile, read mode): label left, value right,
// hairline-separated rows inside the section card. The native-feeling
Expand Down Expand Up @@ -995,7 +1008,7 @@ export const DetailSection: React.FC<DetailSectionProps> = ({
>
{displayValue}
</div>
{canInlineEditField ? (
{canInlineEditField && (
<TooltipProvider>
<Tooltip>
<TooltipTrigger asChild>
Expand All @@ -1018,7 +1031,12 @@ export const DetailSection: React.FC<DetailSectionProps> = ({
</TooltipContent>
</Tooltip>
</TooltipProvider>
) : copyOffered ? (
)}
{/* On the field face an editable value is copied from the same
hover / focus button a read-only one is: its click is the
way into edit, so the button is the way to copy. Elsewhere
an editable row keeps the pencil alone. */}
{copyOffered && (!canInlineEditField || frameless) && (
<TooltipProvider>
<Tooltip>
<TooltipTrigger asChild>
Expand Down Expand Up @@ -1055,7 +1073,7 @@ export const DetailSection: React.FC<DetailSectionProps> = ({
</TooltipContent>
</Tooltip>
</TooltipProvider>
) : null}
)}
</div>
)}
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ import { DetailSection } from '../DetailSection';
import { DefaultRecordPageContext, DetailsColumnCapContext } from '../defaultRecordPage';
import { createEmptyFieldTally, RecordFieldListContext, type RecordFieldList } from '../recordFieldList';
import { EmptyFieldsRow } from '../EmptySectionsFold';
import { I18nProvider } from '@object-ui/i18n';
import { MePermissionsProvider, type MePermissionsAuthenticatedResponse } from '@object-ui/permissions';

const objectSchema = {
fields: {
Expand Down Expand Up @@ -294,3 +296,152 @@ describe('empty fields fold into the list’s one last row (objectstack#36147 it
expect(container.querySelector('[data-empty-fields-row]')).toBeNull();
});
});

/**
* objectstack#36292 — on the field list an empty value the reader can fill in
* reads "Set <label>" and its one click opens the editor; a value the reader
* cannot edit keeps the shared "No value" placeholder; and an editable value
* offers the same hover / focus copy button a read-only one does.
*/
describe('an empty editable value reads "Set <label>" and one click edits it (objectstack#36292)', () => {
const setOf = (container: HTMLElement) => Array.from(container.querySelectorAll('[data-detail-set-field]'));
const noValueIn = (row: HTMLElement) => row.querySelector('[title="No value"]');

it('an empty editable value reads "Set Note", and a click on it enters edit', () => {
const onEnter = vi.fn();
const { container } = render(
<Page list={makeList(true)}>
<DetailSection section={section} data={data} objectSchema={objectSchema} onEnterInlineEdit={onEnter} />
</Page>,
);
expect(setOf(container).map((n) => n.textContent)).toEqual(['Set Note', 'Set Phone']);
expect(noValueIn(rowOf('Note'))).toBeNull();
fireEvent.click(screen.getByText('Set Note'));
expect(onEnter).toHaveBeenCalledWith('note');
});

it('control: a non-empty value reads as before', () => {
render(
<Page list={makeList(true)}>
<DetailSection section={section} data={data} objectSchema={objectSchema} onEnterInlineEdit={vi.fn()} />
</Page>,
);
expect(rowOf('Name').querySelector('[data-detail-set-field]')).toBeNull();
expect(rowOf('Name').textContent).toContain('Atlas deal');
});

it('control: a read-only field keeps the "No value" placeholder and takes no click', () => {
const onEnter = vi.fn();
const readonlySchema = { fields: { ...objectSchema.fields, note: { type: 'text', label: 'Note', readonly: true } } };
const { container } = render(
<Page list={makeList(true)}>
<DetailSection section={section} data={data} objectSchema={readonlySchema} onEnterInlineEdit={onEnter} />
</Page>,
);
expect(noValueIn(rowOf('Note'))).not.toBeNull();
expect(setOf(container).map((n) => n.textContent)).toEqual(['Set Phone']);
fireEvent.click(noValueIn(rowOf('Note'))!);
expect(onEnter).not.toHaveBeenCalled();
});

it('control: a record that is not inline-editable keeps the placeholder on every empty row', () => {
const { container } = render(
<Page list={makeList(true)}>
<DetailSection section={section} data={data} objectSchema={objectSchema} />
</Page>,
);
expect(setOf(container)).toHaveLength(0);
expect(noValueIn(rowOf('Note'))).not.toBeNull();
expect(noValueIn(rowOf('Phone'))).not.toBeNull();
});

it('control: a field the caller may not write keeps the placeholder', () => {
const OBJECT = 'crm_account';
const perms: MePermissionsAuthenticatedResponse = {
authenticated: true,
userId: 'u-rep',
tenantId: null,
hasAnyQueue: false,
objectsUsingQueues: [],
positions: [],
permissionSets: ['rep'],
objects: { [OBJECT]: { allowRead: true, allowCreate: false, allowEdit: true, allowDelete: false, allowTransfer: false } },
fields: { [`${OBJECT}.note`]: { readable: true, editable: false } },
};
const { container } = render(
<MePermissionsProvider initialPermissions={perms}>
<Page list={makeList(true)}>
<DetailSection section={section} data={data} objectSchema={objectSchema} objectName={OBJECT} onEnterInlineEdit={vi.fn()} />
</Page>
</MePermissionsProvider>,
);
expect(noValueIn(rowOf('Note'))).not.toBeNull();
expect(setOf(container).map((n) => n.textContent)).toEqual(['Set Phone']);
});

it('control: outside the record page’s field face an empty editable value keeps the placeholder', () => {
const { container } = render(
<DetailSection section={section} data={data} objectSchema={objectSchema} onEnterInlineEdit={vi.fn()} />,
);
// The section's own toggle shows its empty rows off the field face.
fireEvent.click(screen.getByRole('button', { name: /Show 2 empty fields/ }));
expect(setOf(container)).toHaveLength(0);
// CONTROL: the empty row is on screen, so the count above is not vacuous.
const noteRow = screen.getByText('Note', { exact: true }).closest('.group') as HTMLElement;
expect(noValueIn(noteRow)).not.toBeNull();
});

it('reads in the reader’s language: 设置备注 in Chinese', () => {
const { container } = render(
<I18nProvider config={{ defaultLanguage: 'zh-CN', detectBrowserLanguage: false }} persistLanguage={false}>
<Page list={makeList(true)}>
<DetailSection
section={{ title: 'Overview', fields: [{ name: 'note', label: '备注' }] } as unknown as DetailViewSection}
data={data}
objectSchema={objectSchema}
onEnterInlineEdit={vi.fn()}
/>
</Page>
</I18nProvider>,
);
expect(setOf(container).map((n) => n.textContent)).toEqual(['设置备注']);
});
});

describe('an editable value offers the hover / focus copy button too (objectstack#36292 item 2)', () => {
it('the copy button sits beside an editable value, copies it, and does not enter edit', () => {
const onEnter = vi.fn();
const writeText = vi.fn().mockResolvedValue(undefined);
Object.defineProperty(navigator, 'clipboard', { configurable: true, value: { writeText } });
render(
<Page list={makeList()}>
<DetailSection section={section} data={data} objectSchema={objectSchema} onEnterInlineEdit={onEnter} />
</Page>,
);
const copy = rowOf('Name').querySelector('[data-detail-copy]') as HTMLButtonElement;
expect(copy).not.toBeNull();
// Hidden at rest, drawn on hover or focus, and never on a touch screen (ruling 1).
expect(copy.className.split(/\s+/)).toEqual(expect.arrayContaining(['opacity-0', 'group-hover:opacity-100', 'pointer-coarse:hidden']));
fireEvent.click(copy);
expect(writeText).toHaveBeenCalledWith('Atlas deal');
expect(onEnter).not.toHaveBeenCalled();
});

it('control: an empty editable value offers no copy button', () => {
render(
<Page list={makeList(true)}>
<DetailSection section={section} data={data} objectSchema={objectSchema} onEnterInlineEdit={vi.fn()} />
</Page>,
);
expect(rowOf('Note').querySelector('[data-detail-copy]')).toBeNull();
});

it('control: outside the field face an editable row keeps the pencil alone', () => {
const { container } = render(
<DetailSection section={section} data={data} objectSchema={objectSchema} onEnterInlineEdit={vi.fn()} />,
);
const nameRow = screen.getByText('Atlas deal').closest('.group') as HTMLElement;
expect(nameRow.querySelector('[data-detail-copy]')).toBeNull();
expect(container.querySelector('button[aria-label="Double-click to edit"]')).not.toBeNull();
});
});
Loading