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/39439-recycle-bin-delete-toast.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
---
'@object-ui/core': patch
'@object-ui/app-shell': patch
'@object-ui/i18n': patch
---

fix(core, app-shell): the delete toast says the record went to the recycle bin; a position's Add holder leaves out people who already hold it

Clause-②: no
Metadata-protocol: none

Who sees it: anyone who deletes one record from a list or a record page, and an administrator adding holders to a position in Setup.

- **Deleting one record now says where it went.** When the delete's answer carries a recycle-bin entry, the success toast reads `Lead "Ada" moved to the recycle bin` (and its translation in every built-in language) instead of `Lead "Ada" deleted`, for every caller. Before, only a person allowed to restore their own deletes learned anything, through the toast's Undo. Undo is unchanged: it is still offered only to that person. A delete whose answer carries no entry (a platform object, a deployment without a recycle bin, a data source that answers none) keeps the old toast, word for word. The confirm question is not changed, and the toast names no restore-until date, which the delete's answer does not carry.
- **`recordDelete.run` and the record page now always pass `onRecycleBinEntry` to `DataSource.delete`** for a one-record delete, not only when Undo can be offered. The ObjectStack adapter sends the same request either way; an adapter whose backend has no recycle bin never calls it. A batch delete is unchanged.
- Two new keys, `objectActions.movedToRecycleBinNamed` and `objectActions.movedToRecycleBin`, are in every built-in language pack; a host with no translations reads the English sentence.
- **Setup → position → Add holder offers only people who do not hold the position yet**; the picker's title says holders are not listed, and when every member already holds it the picker stays closed and says so. It is the same shape a permission set's Add user takes.
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ type Pack = {
deleteConfirm: string;
deleteConfirmQuestion: string;
deletedNamed: string;
movedToRecycleBinNamed: string;
restoredNamed: string;
restoreFailed: string;
deleteConfirmTitle: string;
Expand Down Expand Up @@ -158,7 +159,7 @@ describe.each(['en', 'zh'] as const)('console list Delete in %s (objectui#11695)
expect(dataSource.delete).not.toHaveBeenCalled();

fireEvent.click(confirm);
await waitFor(() => expect(dataSource.delete).toHaveBeenCalledWith('crm_product', 'p1'));
await waitFor(() => expect(dataSource.delete).toHaveBeenCalledWith('crm_product', 'p1', { onRecycleBinEntry: expect.any(Function) }));
});

it('a selection counts the batch in the title, with the same destructive Delete', async () => {
Expand Down Expand Up @@ -252,13 +253,14 @@ const MAY_NOT_RESTORE = grants({ crm_product: { allowRead: true, allowDelete: tr
describe.each(['en', 'zh'] as const)('console list Delete undo in %s (objectstack#30239)', (language) => {
const pack = PACKS[language];
const deleted = fill(pack.objectActions.deletedNamed, { label: 'Product', name: 'QA Widget 0' });
const recycled = fill(pack.objectActions.movedToRecycleBinNamed, { label: 'Product', name: 'QA Widget 0' });

it('round trip: Undo restores the entry the delete wrote, never re-creates, and names the record', async () => {
const dataSource = mountBin(language, MAY_RESTORE, { entryId: 'rb1' });
await confirmRowDelete(pack);
await waitFor(() => expect(toast.success).toHaveBeenCalledTimes(1));
const [message, data] = (toast.success as any).mock.calls[0];
expect(message).toBe(deleted);
expect(message).toBe(recycled);
expect(data.action.label).toBe(pack.actions.undo);

data.action.onClick();
Expand All @@ -285,12 +287,12 @@ describe.each(['en', 'zh'] as const)('console list Delete undo in %s (objectstac
});
});

it('control: without allowRestoreOwnDeleted the toast is today\'s, and no entry id is asked for', async () => {
it('without allowRestoreOwnDeleted no Undo is offered (objectstack#39439: the toast still says where the record went)', async () => {
const dataSource = mountBin(language, MAY_NOT_RESTORE, { entryId: 'rb1' });
await confirmRowDelete(pack);
await waitFor(() => expect(toast.success).toHaveBeenCalledTimes(1));
expect((toast.success as any).mock.calls[0]).toEqual([deleted]);
expect(dataSource.delete.mock.calls).toEqual([['crm_product', 'p1']]);
expect((toast.success as any).mock.calls[0]).toEqual([recycled]);
expect(dataSource.delete.mock.calls).toEqual([['crm_product', 'p1', { onRecycleBinEntry: expect.any(Function) }]]);
});

it('control: an answer with no recycle-bin entry keeps today\'s toast', async () => {
Expand All @@ -300,3 +302,48 @@ describe.each(['en', 'zh'] as const)('console list Delete undo in %s (objectstac
expect((toast.success as any).mock.calls[0]).toEqual([deleted]);
});
});

/**
* objectstack#39439 item 11 — the console list's one-record Delete, on the
* real chain and the shipped packs: the toast says the record went to the
* recycle bin whenever the delete's answer carries an entry, whoever deletes;
* Undo stays with a holder of `allowRestoreOwnDeleted`; an answer with none
* keeps today's toast byte for byte. The recycle-bin sentence is the pack's
* own row, distinct from today's, so a host that dropped it reads red.
*/
describe.each(['en', 'zh'] as const)('the list delete toast names the recycle bin in %s (objectstack#39439)', (language) => {
const pack = PACKS[language];
const deleted = fill(pack.objectActions.deletedNamed, { label: 'Product', name: 'QA Widget 0' });
const recycled = fill(pack.objectActions.movedToRecycleBinNamed, { label: 'Product', name: 'QA Widget 0' });

it('the two sentences differ, so the pins below can tell them apart', () => {
expect(recycled).not.toBe(deleted);
});

it('a caller who may not restore reads the recycle-bin sentence, with no Undo', async () => {
mountBin(language, MAY_NOT_RESTORE, { entryId: 'rb1' });
await confirmRowDelete(pack);
await waitFor(() => expect(toast.success).toHaveBeenCalledTimes(1));
expect((toast.success as any).mock.calls[0]).toEqual([recycled]);
});

it('a caller who may restore reads the same sentence, with Undo', async () => {
mountBin(language, MAY_RESTORE, { entryId: 'rb1' });
await confirmRowDelete(pack);
await waitFor(() => expect(toast.success).toHaveBeenCalledTimes(1));
const [message, data] = (toast.success as any).mock.calls[0];
expect(message).toBe(recycled);
expect(data.action.label).toBe(pack.actions.undo);
});

it('CONTROL: an answer with no entry keeps today\'s toast byte for byte, for either caller', async () => {
for (const permissions of [MAY_NOT_RESTORE, MAY_RESTORE]) {
mountBin(language, permissions, {});
await confirmRowDelete(pack);
await waitFor(() => expect(toast.success).toHaveBeenCalledTimes(1));
expect((toast.success as any).mock.calls[0]).toEqual([deleted]);
cleanup();
vi.clearAllMocks();
}
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ describe('useObjectActions — the delete confirmation names what it deletes (ob
confirmText: 'objectActions.deleteConfirmButton',
destructive: true,
});
expect(dataSource.delete).toHaveBeenCalledWith('crm_product', 'p1');
expect(dataSource.delete).toHaveBeenCalledWith('crm_product', 'p1', { onRecycleBinEntry: expect.any(Function) });
});

it('a batch: asks ONCE for all of them with the counting title, then deletes each', async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ type Pack = {
deleteConfirmTitle: string;
deleteConfirmButton: string;
deletedNamed: string;
movedToRecycleBinNamed: string;
deleteSuccess: string;
};
console: { objectView: { bulkDeleteConfirm: string } };
Expand Down Expand Up @@ -287,7 +288,7 @@ describe('record page Delete asks through the in-app confirm dialog (objectui#11
fireEvent.click(within(dialog).getByRole('button', { name: EN.objectActions.deleteConfirmButton }));

await waitFor(() => expect(dataSource.delete).toHaveBeenCalledTimes(1));
expect(dataSource.delete).toHaveBeenCalledWith(OBJECT_NAME, RECORD_ID);
expect(dataSource.delete).toHaveBeenCalledWith(OBJECT_NAME, RECORD_ID, { onRecycleBinEntry: expect.any(Function) });
await waitFor(() => expect(toast.success).toHaveBeenCalledTimes(1));
// objectstack-ai/objectstack#27823 — the toast names the deleted record the
// way the confirm title did, not a generic "Record deleted".
Expand Down Expand Up @@ -333,7 +334,7 @@ describe('record page Delete names the record in zh too (objectui#11695)', () =>
expect(confirm.className).toContain('bg-destructive');

fireEvent.click(confirm);
await waitFor(() => expect(dataSource.delete).toHaveBeenCalledWith(OBJECT_NAME, RECORD_ID));
await waitFor(() => expect(dataSource.delete).toHaveBeenCalledWith(OBJECT_NAME, RECORD_ID, { onRecycleBinEntry: expect.any(Function) }));
});
});

Expand All @@ -352,7 +353,7 @@ describe('record page Delete never re-reads the deleted record', () => {
const dialog = await screen.findByRole('alertdialog');
fireEvent.click(within(dialog).getByRole('button', { name: EN.objectActions.deleteConfirmButton }));

await waitFor(() => expect(dataSource.delete).toHaveBeenCalledWith(OBJECT_NAME, RECORD_ID));
await waitFor(() => expect(dataSource.delete).toHaveBeenCalledWith(OBJECT_NAME, RECORD_ID, { onRecycleBinEntry: expect.any(Function) }));
await waitFor(() => expect(currentPath()).toBe(`/${OBJECT_NAME}`));
await act(async () => {
for (let i = 0; i < 5; i++) await new Promise((resolve) => setTimeout(resolve, 0));
Expand All @@ -372,3 +373,43 @@ describe('record page Delete never re-reads the deleted record', () => {
expect(currentPath()).toBe(START_PATH);
});
});

/**
* objectstack#39439 item 11 — the record page's own delete call asks for the
* recycle-bin entry id whoever deletes, and the toast says the record went to
* the recycle bin when the answer carries one. This caller cannot restore (the
* data source offers no restore), so no Undo rides on it; an answer with no
* entry keeps today's toast byte for byte.
*/
describe('record page Delete says the record went to the recycle bin (objectstack#39439)', () => {
const ASK = { onRecycleBinEntry: expect.any(Function) };
async function deleteFromHeader(dataSource: ReturnType<typeof makeDataSource>) {
await mountRecordPage('en', dataSource);
await chooseHeaderDelete();
const dialog = await screen.findByRole('alertdialog');
fireEvent.click(within(dialog).getByRole('button', { name: EN.objectActions.deleteConfirmButton }));
await waitFor(() => expect(toast.success).toHaveBeenCalledTimes(1));
}

it('an answer with an entry reads the recycle-bin sentence, with no Undo for a caller who cannot restore', async () => {
const dataSource = makeDataSource();
dataSource.delete = vi.fn(async (_r: string, _id: string, o?: { onRecycleBinEntry?: (id: string) => void }) => {
o?.onRecycleBinEntry?.('rb1');
return true;
});
await deleteFromHeader(dataSource);
expect(dataSource.delete.mock.calls).toEqual([[OBJECT_NAME, RECORD_ID, ASK]]);
expect((toast.success as any).mock.calls[0]).toEqual([
fill(EN.objectActions.movedToRecycleBinNamed, { label: 'Call', name: 'Intro call' }),
]);
});

it('CONTROL: an answer with no entry keeps today\'s toast byte for byte', async () => {
const dataSource = makeDataSource();
await deleteFromHeader(dataSource);
expect(dataSource.delete.mock.calls).toEqual([[OBJECT_NAME, RECORD_ID, ASK]]);
expect((toast.success as any).mock.calls[0]).toEqual([
fill(EN.objectActions.deletedNamed, { label: 'Call', name: 'Intro call' }),
]);
});
});
22 changes: 10 additions & 12 deletions ui/packages/app-shell/src/views/RecordDetailView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4482,23 +4482,21 @@ export function RecordDetailView({ dataSource, objects, onEdit, objectNameOverri
destructive: true,
}))
) return;
// ADR-0148 — the toast offers Undo when the delete wrote a
// recycle-bin entry and the caller may restore its own deletes on
// the object; the undo restores the entry and comes back here.
// ADR-0148 — the delete always asks for the recycle-bin entry id:
// when one arrives the toast says the record went to the recycle
// bin, for every caller, and offers Undo when the caller may also
// restore its own deletes on the object; the undo restores the
// entry and comes back here.
const restore = recycleBinRestoreOf(dataSource, objectName!, perms.effectiveObjects);
const baseAppUrl = appName ? `/apps/${appName}` : '';
const recordUrl = `${location.pathname}${location.search}`;
try {
let entryId: string | undefined;
if (restore) {
await dataSource.delete(objectName!, pureRecordId!, {
onRecycleBinEntry: (id: string) => {
entryId = id;
},
});
} else {
await dataSource.delete(objectName!, pureRecordId!);
}
await dataSource.delete(objectName!, pureRecordId!, {
onRecycleBinEntry: (id: string) => {
entryId = id;
},
});
recordDelete.successToast(
{
...deleteDeps,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import { render, screen, waitFor, fireEvent, cleanup, within } from '@testing-li

interface PickerProps {
open: boolean;
title?: string;
baseFilter?: unknown;
onSelectRecords: (records: any[]) => void;
}
Expand All @@ -39,7 +40,7 @@ vi.mock('@object-ui/auth', async (importOriginal) => ({
useAuth: () => ({ activeOrganization: auth.activeOrganization }),
}));

const assignments = [{ id: 'up_1', user_id: 'u_1', position: 'auditor' }];
let assignments = [{ id: 'up_1', user_id: 'u_1', position: 'auditor' }];
const users = [{ id: 'u_1', name: 'Ada Auditor', email: 'ada@example.com' }];
/** `u_9` (QA Csv) was removed from `org_1`: no membership row names them there. */
let members: Array<{ id: string; user_id: string; organization_id: string }> = [];
Expand Down Expand Up @@ -83,6 +84,7 @@ beforeEach(() => {
auth.activeOrganization = { id: 'org_1' };
registered.objects = [{ name: 'sys_user_position' }, { name: 'sys_member' }];
membershipRead = null;
assignments = [{ id: 'up_1', user_id: 'u_1', position: 'auditor' }];
members = [
{ id: 'm_1', user_id: 'u_1', organization_id: 'org_1' },
{ id: 'm_3', user_id: 'u_3', organization_id: 'org_1' },
Expand Down Expand Up @@ -126,7 +128,8 @@ describe("the holder picker offers the organization's members only (objectui#133
expect(memberReads()).toEqual([
['sys_member', { $filter: { organization_id: 'org_1' }, $top: 500, $skip: 0 }],
]);
expect(picker!.baseFilter).toEqual({ id: { $in: ['u_1', 'u_3'] } });
// `u_1` already holds the position, so it is left out too (objectstack#39439).
expect(picker!.baseFilter).toEqual({ id: { $in: ['u_3'] } });
});

it('reads every page of the membership', async () => {
Expand All @@ -135,7 +138,8 @@ describe("the holder picker offers the organization's members only (objectui#133
fireEvent.click(screen.getByRole('button', { name: 'Add holder' }));
await waitFor(() => expect(picker?.open).toBe(true));
expect(memberReads().map(([, q]) => (q as { $skip: number }).$skip)).toEqual([0, 500]);
expect((picker!.baseFilter as { id: { $in: string[] } }).id.$in).toHaveLength(501);
// Every member but the holder `u_1` (objectstack#39439).
expect((picker!.baseFilter as { id: { $in: string[] } }).id.$in).toHaveLength(500);
});

it("a refused membership read is said in the server's words and the picker stays shut", async () => {
Expand All @@ -162,7 +166,8 @@ describe("the holder picker offers the organization's members only (objectui#133
await mount();
fireEvent.click(screen.getByRole('button', { name: 'Add holder' }));
await waitFor(() => expect(picker?.open).toBe(true));
expect(picker!.baseFilter).toBeUndefined();
// Unfiltered by membership; only the holders are left out (objectstack#39439).
expect(picker!.baseFilter).toEqual({ id: { $nin: ['u_1'] } });
expect(memberReads()).toHaveLength(0);
});

Expand All @@ -171,7 +176,46 @@ describe("the holder picker offers the organization's members only (objectui#133
await mount();
fireEvent.click(screen.getByRole('button', { name: 'Add holder' }));
await waitFor(() => expect(picker?.open).toBe(true));
expect(picker!.baseFilter).toBeUndefined();
// Unfiltered by membership; only the holders are left out (objectstack#39439).
expect(picker!.baseFilter).toEqual({ id: { $nin: ['u_1'] } });
expect(memberReads()).toHaveLength(0);
});
});

/**
* objectstack#39439 — the same shape as a permission set's Add user: Add skips
* a current holder, so the picker no longer offers one. Its title says holders
* are not listed; when every member already holds the position it stays shut
* and says so. With no holder there is nothing to leave out.
*/
describe('the holder picker leaves out people who already hold the position (objectstack#39439)', () => {
it("offers the organization's members who do not hold it, and its title says holders are left out", async () => {
await mount();
fireEvent.click(screen.getByRole('button', { name: 'Add holder' }));
await waitFor(() => expect(picker?.open).toBe(true));
expect(picker!.baseFilter).toEqual({ id: { $in: ['u_3'] } });
expect(picker!.title).toBe(
'Select organization members to assign this position to (people who already hold it are not listed)',
);
});

it('when every member already holds the position, the picker stays shut and says why', async () => {
members = [{ id: 'm_1', user_id: 'u_1', organization_id: 'org_1' }];
await mount();
fireEvent.click(screen.getByRole('button', { name: 'Add holder' }));
expect(await screen.findByRole('alert')).toHaveTextContent(
'Every member of this organization already holds this position.',
);
expect(picker?.open).toBe(false);
});

it('CONTROL: with no holder and no membership to judge, the picker opens unfiltered', async () => {
assignments = [];
registered.objects = [{ name: 'sys_user_position' }];
render(<PositionHoldersSection name="auditor" />);
await waitFor(() => expect(screen.getByText('Nobody holds this position yet.')).toBeInTheDocument());
fireEvent.click(screen.getByRole('button', { name: 'Add holder' }));
await waitFor(() => expect(picker?.open).toBe(true));
expect(picker!.baseFilter).toBeUndefined();
});
});
Loading
Loading