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
12 changes: 12 additions & 0 deletions .changeset/37758-bulk-delete-refusal-reasons.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
---
'@object-ui/core': patch
'@object-ui/i18n': patch
'@object-ui/plugin-view': patch
---

fix(core): a list bulk Delete with refused records says why, not only "0 deleted, 4 failed"

Clause-②: no
Metadata-protocol: none

The built-in bulk Delete deletes each selected record and reports one summary toast. When records were refused (a restrict delete, a lock, a permission), the toast gave only the two counts and dropped each refusal's reason, which the one-record Delete shows. The summary keeps its counts, and its description now lists the reasons: one line per distinct reason, led by the names of the records it refused (up to three names, then `+N`), at most three reasons and then "And N more". An external datasource's refusal reads as the read-only sentence, as the one-record toast reads it. A refusal with no message adds no line, so a batch with no reason keeps the bare count. The one-record toast is unchanged. Two keys are added to every locale pack: `objectActions.bulkDeleteRefusedNamed` and `objectActions.bulkDeleteMoreReasons`.
94 changes: 94 additions & 0 deletions ui/packages/core/src/actions/__tests__/recordDelete.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -190,12 +190,106 @@ describe('recordDelete.run — several records', () => {
expect(toast.error).toHaveBeenCalledTimes(1);
expect(toast.error).toHaveBeenCalledWith(
'objectActions.bulkDeletePartial {"succeeded":1,"failed":1}',
{ description: 'refused b' },
);
expect(toast.success).not.toHaveBeenCalled();
expect(res).toEqual({ success: false });
});
});

/**
* objectstack-ai/objectstack#37758 — a batch with refusals said only
* "0 deleted, 4 failed": each refusal's reason (the server's localized
* sentence, which the one-record toast shows) was dropped. The summary title
* keeps its counts; the description gives the reasons, one line per distinct
* reason, led by the names of the records it refused.
*/
describe('recordDelete.run — a batch with refusals names the reasons (objectstack#37758)', () => {
const EVENT = { name: 'crm_event', label: 'Event', nameField: 'name', fields: { name: { type: 'text' } } };
const RESTRICT = 'This event is still referenced by attendee records. Delete or reassign them first.';

/** A data source that refuses the ids in `refusals` with the error given there. */
function refusing(refusals: Record<string, unknown>, objectDef: unknown = EVENT) {
const h = harness();
h.dataSource.delete.mockImplementation(async (_resource: string, id: string) => {
if (id in refusals) throw refusals[id];
return true;
});
return { ...h, deps: { ...h.deps, objectDef } };
}

const ev = (id: string, name?: string) => (name ? { id, name } : { id });

it('an all-refused batch for one reason reads as that reason, with the records it refused', async () => {
const c = refusing({ e1: new Error(RESTRICT), e2: new Error(RESTRICT), e3: new Error(RESTRICT), e4: new Error(RESTRICT) });
await recordDelete.run(c.deps, {
params: { records: [ev('e1', 'Kickoff'), ev('e2', 'Review'), ev('e3', 'Launch'), ev('e4', 'Retro')] },
});

expect(c.toast.error).toHaveBeenCalledTimes(1);
expect(c.toast.error).toHaveBeenCalledWith('objectActions.bulkDeletePartial {"succeeded":0,"failed":4}', {
description: `objectActions.bulkDeleteRefusedNamed {"names":"Kickoff, Review, Launch +1","reason":"${RESTRICT}"}`,
});
});

it('a mixed batch: one line per distinct reason, in the order handed in; the deleted record is not named', async () => {
const c = refusing({ e2: new Error(RESTRICT), e3: new Error('Record is locked'), e4: new Error(RESTRICT) });
await recordDelete.run(c.deps, {
params: { records: [ev('e1', 'Kickoff'), ev('e2', 'Review'), ev('e3', 'Launch'), ev('e4', 'Retro')] },
});

expect(c.toast.error).toHaveBeenCalledWith('objectActions.bulkDeletePartial {"succeeded":1,"failed":3}', {
description: [
`objectActions.bulkDeleteRefusedNamed {"names":"Review, Retro","reason":"${RESTRICT}"}`,
'objectActions.bulkDeleteRefusedNamed {"names":"Launch","reason":"Record is locked"}',
].join('\n'),
});
});

it('records with no name: the reason reads alone, since the title already counts them', async () => {
const c = refusing({ x1: new Error(RESTRICT), x2: new Error(RESTRICT) }, undefined);
await recordDelete.run(c.deps, { params: { records: [{ id: 'x1' }, { id: 'x2' }] } });

expect(c.toast.error).toHaveBeenCalledWith('objectActions.bulkDeletePartial {"succeeded":0,"failed":2}', {
description: RESTRICT,
});
});

it('past three reasons the rest are counted, not listed', async () => {
const c = refusing({ a: new Error('r1'), b: new Error('r2'), c: new Error('r3'), d: new Error('r4'), e: new Error('r5') }, undefined);
await recordDelete.run(c.deps, { params: { records: ['a', 'b', 'c', 'd', 'e'].map((id) => ({ id })) } });

expect(c.toast.error).toHaveBeenCalledWith('objectActions.bulkDeletePartial {"succeeded":0,"failed":5}', {
description: ['r1', 'r2', 'r3', 'objectActions.bulkDeleteMoreReasons {"more":2}'].join('\n'),
});
});

it("an external datasource's refusal reads as the read-only sentence, as the one-record toast reads it", async () => {
const external = Object.assign(new Error('EXTERNAL_WRITE_FORBIDDEN: datasource flags …'), { code: 'EXTERNAL_WRITE_FORBIDDEN' });
const c = refusing({ a: external, b: external }, undefined);
await recordDelete.run(c.deps, { params: { records: [{ id: 'a' }, { id: 'b' }] } });

expect(c.toast.error).toHaveBeenCalledWith('objectActions.bulkDeletePartial {"succeeded":0,"failed":2}', {
description: 'form.readOnlyExternalSource',
});
});

it('CONTROL — refusals that carry no message keep the bare count toast, with no description', async () => {
const c = refusing({ a: new Error(''), b: { status: 500 } }, undefined);
await recordDelete.run(c.deps, { params: { records: [{ id: 'a' }, { id: 'b' }] } });

expect(c.toast.error).toHaveBeenCalledTimes(1);
expect(c.toast.error).toHaveBeenCalledWith('objectActions.bulkDeletePartial {"succeeded":0,"failed":2}');
});

it('CONTROL — the one-record refusal toast is unchanged', async () => {
const c = refusing({ e1: new Error(RESTRICT) });
await recordDelete.run(c.deps, { params: { record: ev('e1', 'Kickoff') }, recordId: 'e1' });

expect(c.toast.error).toHaveBeenCalledWith('objectActions.deleteFailed {"label":"Lead"}', { description: RESTRICT });
});
});


/**
* objectstack-ai/objectstack#27823 — the delete is permanent and the success
Expand Down
98 changes: 90 additions & 8 deletions ui/packages/core/src/actions/recordDelete.ts
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,80 @@ function nameOf(objectDef: unknown, record: Row | null | undefined): string {
return resolved && !(id !== null && id !== undefined && resolved === `Record #${id}`) ? resolved : '';
}

/**
* The text a refused delete gives the user: the external-datasource refusal
* reads as the read-only sentence (as the one-record toast reads it), any
* other error as its message.
*/
function refusalText(deps: Pick<RecordDeleteDeps, 't'>, err: unknown): string {
if (isExternalWriteRefusal(err)) {
return deps.t('form.readOnlyExternalSource', { defaultValue: READ_ONLY_EXTERNAL_SOURCE_EN });
}
const message = err instanceof Error ? err.message : typeof err === 'string' ? err : '';
return message.trim();
}

/** At most this many reasons are listed under a batch summary; the rest are counted. */
const MAX_REFUSAL_LINES = 3;
/** At most this many record names lead one reason's line; the rest are counted. */
const MAX_REFUSAL_NAMES = 3;

/**
* The description under a batch summary that had refusals
* (objectstack-ai/objectstack#37758): one line per distinct reason, in the
* order the records were handed in, led by the names of the records it
* refused (up to {@link MAX_REFUSAL_NAMES}, then `+N`). A reason whose records
* have no name reads alone; the summary title already counts them. A refusal
* with no message adds no line, so a batch that carries no reason at all keeps
* the bare count, as before. No line carries a counted noun, so no locale needs
* a plural family for it.
*/
function refusalSummary(
deps: Pick<RecordDeleteDeps, 't' | 'objectDef'>,
refused: Array<{ record: Row; err: unknown }>,
): string | undefined {
const groups = new Map<string, Row[]>();
for (const { record, err } of refused) {
const reason = refusalText(deps, err);
if (!reason) continue;
const rows = groups.get(reason);
if (rows) rows.push(record);
else groups.set(reason, [record]);
}
if (groups.size === 0) return undefined;
const lines: string[] = [];
for (const [reason, rows] of groups) {
if (lines.length === MAX_REFUSAL_LINES) break;
const names = rows.map((row) => nameOf(deps.objectDef, row)).filter(Boolean);
if (names.length === 0) {
lines.push(reason);
continue;
}
const shown = names.slice(0, MAX_REFUSAL_NAMES).join(', ');
const unnamed = rows.length - Math.min(names.length, MAX_REFUSAL_NAMES);
const who = unnamed > 0 ? `${shown} +${unnamed}` : shown;
lines.push(
deps.t('objectActions.bulkDeleteRefusedNamed', {
names: who,
reason,
defaultValue: `${who}: ${reason}`,
}),
);
}
const rest = groups.size - lines.length;
if (rest > 0) {
lines.push(
// `more`, not `count`: a `count` option sends i18next looking for a
// plural family this noun-free sentence does not have.
deps.t('objectActions.bulkDeleteMoreReasons', {
more: rest,
defaultValue: `And ${rest} more`,
}),
);
}
return lines.join('\n');
}

/**
* The record-delete core: `confirmText` is the question to ask before deleting
* one record, `run` performs the delete (one record, or several settled
Expand Down Expand Up @@ -355,7 +429,10 @@ export const recordDelete = Object.freeze({
const results = await Promise.allSettled(
records.map((r) => dataSource.delete(objectName, r.id as string)),
);
const failed = results.filter((r) => r.status === 'rejected').length;
const refused = results.flatMap((r, i) =>
r.status === 'rejected' ? [{ record: records[i], err: r.reason as unknown }] : [],
);
const failed = refused.length;
const succeeded = results.length - failed;
onRefresh?.();
if (failed === 0) {
Expand All @@ -370,13 +447,18 @@ export const recordDelete = Object.freeze({
// post-execution hook adds a second, generic success toast.
return { success: true, reload: true, silent: true };
}
toast.error(
t('objectActions.bulkDeletePartial', {
succeeded,
failed,
defaultValue: `${succeeded} deleted, ${failed} failed`,
}),
);
// objectstack-ai/objectstack#37758 — the counts alone told the user
// nothing to act on; each refusal's own reason (the server's localized
// sentence, e.g. a restrict delete's "referenced by N records") goes in
// the description, grouped. A batch with no reason keeps the bare count.
const description = refusalSummary(deps, refused);
const summary = t('objectActions.bulkDeletePartial', {
succeeded,
failed,
defaultValue: `${succeeded} deleted, ${failed} failed`,
});
if (description) toast.error(summary, { description });
else toast.error(summary);
// The summary above is authoritative; returning WITHOUT `error` keeps the
// runner from toasting the failure a second time.
return { success: false };
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ const LEGITIMATE_IDENTITIES: Record<string, string> = {
// `appTileOpenedLine-12601.test.ts`, not an omission.
'home.appOpened': 'Tile last-opened line — the bare `{{time}}` hole where no verb fits the tile.',
'detail.fieldChangeLabel': 'Activity field-change line label — the field hole and a separator, no prose; zh-Hans, zh-Hant and ja set a fullwidth colon, fr its space-before-colon, ko/ru/ar keep `:` as their punctuation (objectstack#36290).',
'objectActions.bulkDeleteRefusedNamed': 'Bulk delete refusal line — the record-names hole, a separator and the server\'s reason hole, no prose; zh-Hans, zh-Hant and ja set a fullwidth colon, fr its space-before-colon, ko/ru/ar keep `:` as their punctuation (objectstack#37758).',
'console.firstRunChecklist.pill.count': 'Sidebar 「Get started」 pill count — the done and total holes joined by a slash, a format string with no word to translate (objectstack#36739).',
'console.changeOwner.failure': 'Change Owner report row — the row id and the server\'s own sentence joined by a colon, a format string with no word to translate; zh-Hans and fr use their own colon (objectstack#35403).',
'grid.import.scopeEntry': 'Import Wizard scope entry — the column label and the row\'s cell in quotes, a format string with no word to translate; de, es, fr, ja, ru and ar use their own quotes, zh-Hans, zh-Hant and ko keep the straight quotes their `grid.import.*` lines use (objectstack#36794).',
Expand Down
2 changes: 2 additions & 0 deletions ui/packages/i18n/src/locales/ar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4303,6 +4303,8 @@ const ar = {
bulkDeleteSuccess_many: "تم حذف {{count}} من سجلات {{label}}",
bulkDeleteSuccess_other: "تم حذف {{count}} من سجلات {{label}}",
bulkDeletePartial: "تم حذف {{succeeded}}، فشل {{failed}}",
bulkDeleteRefusedNamed: "{{names}}: {{reason}}",
bulkDeleteMoreReasons: "و{{more}} أخرى",
},
objectViewActions: {
renameFailed: "تعذر إعادة تسمية العرض",
Expand Down
2 changes: 2 additions & 0 deletions ui/packages/i18n/src/locales/de.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3953,6 +3953,8 @@ const de = {
bulkDeleteSuccess_one: "{{count}} {{label}}-Datensatz gelöscht",
bulkDeleteSuccess_other: "{{count}} {{label}}-Datensätze gelöscht",
bulkDeletePartial: "{{succeeded}} gelöscht, {{failed}} fehlgeschlagen",
bulkDeleteRefusedNamed: "{{names}}: {{reason}}",
bulkDeleteMoreReasons: "Und {{more}} weitere",
},
objectViewActions: {
renameFailed: "Ansicht konnte nicht umbenannt werden",
Expand Down
2 changes: 2 additions & 0 deletions ui/packages/i18n/src/locales/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4925,6 +4925,8 @@ const en = {
bulkDeleteSuccess_one: 'Deleted {{count}} {{label}} record',
bulkDeleteSuccess_other: 'Deleted {{count}} {{label}} records',
bulkDeletePartial: '{{succeeded}} deleted, {{failed}} failed',
bulkDeleteRefusedNamed: '{{names}}: {{reason}}',
bulkDeleteMoreReasons: 'And {{more}} more',
},
objectViewActions: {
renameFailed: 'Failed to rename view',
Expand Down
2 changes: 2 additions & 0 deletions ui/packages/i18n/src/locales/es.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4041,6 +4041,8 @@ const es = {
bulkDeleteSuccess_many: "{{count}} de registros de {{label}} eliminados",
bulkDeleteSuccess_other: "{{count}} registros de {{label}} eliminados",
bulkDeletePartial: "{{succeeded}} eliminados, {{failed}} fallidos",
bulkDeleteRefusedNamed: "{{names}}: {{reason}}",
bulkDeleteMoreReasons: "Y {{more}} más",
},
objectViewActions: {
renameFailed: "No se pudo renombrar la vista",
Expand Down
2 changes: 2 additions & 0 deletions ui/packages/i18n/src/locales/fr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4037,6 +4037,8 @@ const fr = {
bulkDeleteSuccess_many: "{{count}} d'enregistrements {{label}} supprimés",
bulkDeleteSuccess_other: "{{count}} enregistrements {{label}} supprimés",
bulkDeletePartial: "{{succeeded}} supprimé(s), {{failed}} échoué(s)",
bulkDeleteRefusedNamed: "{{names}} : {{reason}}",
bulkDeleteMoreReasons: "Et {{more}} de plus",
},
objectViewActions: {
renameFailed: "Impossible de renommer la vue",
Expand Down
2 changes: 2 additions & 0 deletions ui/packages/i18n/src/locales/ja.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3955,6 +3955,8 @@ const ja = {
bulkDeleteSuccess_one: "{{count}} 件の {{label}} レコードを削除しました",
bulkDeleteSuccess_other: "{{count}} 件の {{label}} レコードを削除しました",
bulkDeletePartial: "{{succeeded}} 件削除、{{failed}} 件失敗",
bulkDeleteRefusedNamed: "{{names}}:{{reason}}",
bulkDeleteMoreReasons: "ほか {{more}} 件の理由",
},
objectViewActions: {
renameFailed: "ビューの名前変更に失敗しました",
Expand Down
2 changes: 2 additions & 0 deletions ui/packages/i18n/src/locales/ko.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3952,6 +3952,8 @@ const ko = {
bulkDeleteSuccess_one: "{{count}}개의 {{label}} 레코드 삭제됨",
bulkDeleteSuccess_other: "{{count}}개의 {{label}} 레코드 삭제됨",
bulkDeletePartial: "{{succeeded}}개 삭제됨, {{failed}}개 실패",
bulkDeleteRefusedNamed: "{{names}}: {{reason}}",
bulkDeleteMoreReasons: "외 {{more}}개 이유",
},
objectViewActions: {
renameFailed: "보기 이름 변경 실패",
Expand Down
2 changes: 2 additions & 0 deletions ui/packages/i18n/src/locales/pt-BR.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4036,6 +4036,8 @@ const pt = {
bulkDeleteSuccess_many: "{{count}} de registros de {{label}} excluídos",
bulkDeleteSuccess_other: "{{count}} registros de {{label}} excluídos",
bulkDeletePartial: "{{succeeded}} excluídos, {{failed}} com falha",
bulkDeleteRefusedNamed: "{{names}}: {{reason}}",
bulkDeleteMoreReasons: "E mais {{more}}",
},
objectViewActions: {
renameFailed: "Não foi possível renomear a exibição",
Expand Down
2 changes: 2 additions & 0 deletions ui/packages/i18n/src/locales/ru.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4138,6 +4138,8 @@ const ru = {
bulkDeleteSuccess_many: "Удалено {{count}} записей {{label}}",
bulkDeleteSuccess_other: "Удалено {{count}} записи {{label}}",
bulkDeletePartial: "{{succeeded}} удалено, {{failed}} не удалось",
bulkDeleteRefusedNamed: "{{names}}: {{reason}}",
bulkDeleteMoreReasons: "И ещё {{more}}",
},
objectViewActions: {
renameFailed: "Не удалось переименовать представление",
Expand Down
2 changes: 2 additions & 0 deletions ui/packages/i18n/src/locales/zh-Hans.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4291,6 +4291,8 @@ const zh = {
bulkDeleteSuccess_one: '已删除 {{count}} 条 {{label}} 记录',
bulkDeleteSuccess_other: '已删除 {{count}} 条 {{label}} 记录',
bulkDeletePartial: '成功 {{succeeded}} 条,失败 {{failed}} 条',
bulkDeleteRefusedNamed: '{{names}}:{{reason}}',
bulkDeleteMoreReasons: '另有 {{more}} 个原因',
},
objectViewActions: {
renameFailed: '重命名视图失败',
Expand Down
2 changes: 2 additions & 0 deletions ui/packages/i18n/src/locales/zh-Hant.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4291,6 +4291,8 @@ const zhHant = {
bulkDeleteSuccess_one: '已刪除 {{count}} 條 {{label}} 記錄',
bulkDeleteSuccess_other: '已刪除 {{count}} 條 {{label}} 記錄',
bulkDeletePartial: '成功 {{succeeded}} 條,失敗 {{failed}} 條',
bulkDeleteRefusedNamed: '{{names}}:{{reason}}',
bulkDeleteMoreReasons: '另有 {{more}} 個原因',
},
objectViewActions: {
renameFailed: '重新命名檢視失敗',
Expand Down
2 changes: 2 additions & 0 deletions ui/packages/plugin-view/src/ObjectView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -692,6 +692,8 @@ const VIEW_DEFAULT_TRANSLATIONS: Record<string, string> = {
'objectActions.bulkDeleteSuccess_one': 'Deleted {{count}} {{label}} record',
'objectActions.bulkDeleteSuccess_other': 'Deleted {{count}} {{label}} records',
'objectActions.bulkDeletePartial': '{{succeeded}} deleted, {{failed}} failed',
'objectActions.bulkDeleteRefusedNamed': '{{names}}: {{reason}}',
'objectActions.bulkDeleteMoreReasons': 'And {{more}} more',
};

const useObjectViewTranslation = createSafeTranslation(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,12 @@ describe('objectui#10383 — bulk Delete on the registered object-view path', ()
fireEvent.click(await screen.findByTestId('bulk-action-delete'));
await userEvent.click(within(await confirmDialog()).getByRole('button', { name: 'Delete' }));

await waitFor(() => expect(errorSpy).toHaveBeenCalledWith('1 deleted, 1 failed'));
// objectstack#37758: the refusal's own reason rides under the counts.
await waitFor(() =>
expect(errorSpy).toHaveBeenCalledWith('1 deleted, 1 failed', {
description: expect.stringContaining('refused r2'),
}),
);
expect(ds.delete).toHaveBeenCalledTimes(2);
await waitFor(() => expect(screen.queryByText('Alice')).not.toBeInTheDocument());
expect(screen.getByText('Bob')).toBeInTheDocument();
Expand Down
Loading