Skip to content

Commit 8ef6d6e

Browse files
committed
fix(ui): the related tab's bulk delete goes in one batch and the held tab is the reader's
Bulk delete sends the selection to the data source's bulkDelete in one call and falls back to the row delete only without one; the tab shows how many rows were deleted and how many failed. The tab's held sort, filter and footer picks are keyed by the reader as well as the record. Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01L6bhgTKEPqtmiK9SGpHsmW
1 parent 5bad102 commit 8ef6d6e

4 files changed

Lines changed: 103 additions & 17 deletions

File tree

‎.changeset/35892-related-tab-full-list.md‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,17 @@
88

99
feat(ui): a record page's related tab is the child object's full list
1010

11-
Clause-②: yes (widening) — a new export `ListConditionsBlock` (`@object-ui/plugin-list`, the condition row as a host element, not a registered node type) and its `ListConditionsHostProps`; a new slot `RelatedListConditionsSlotContext` and its `RelatedListConditionsProps` (`@object-ui/plugin-detail`), which the record page fills (`@object-ui/app-shell`); new exports `ConditionDiscardButton` (`@object-ui/plugin-list`) and `withHeaderSortPick` (`@object-ui/core`); new i18n keys in every `@object-ui/i18n` locale pack (`listConditions.chips.discard`, `listConditions.chips.discardHint`, `detail.relatedNoMatches`, `detail.deleteRowsTitle`, `detail.deleteRowsConfirmation_*`, a count family); nothing removed or renamed
11+
Clause-②: yes (widening) — a new export `ListConditionsBlock` (`@object-ui/plugin-list`, the condition row as a host element, not a registered node type) and its `ListConditionsHostProps`; a new slot `RelatedListConditionsSlotContext` and its `RelatedListConditionsProps` (`@object-ui/plugin-detail`), which the record page fills (`@object-ui/app-shell`); new exports `ConditionDiscardButton` and its type `ConditionDiscardButtonProps` (`@object-ui/plugin-list`) and `withHeaderSortPick` (`@object-ui/core`); new i18n keys in every `@object-ui/i18n` locale pack (`listConditions.chips.discard`, `listConditions.chips.discardHint`, `detail.relatedNoMatches`, `detail.deleteRowsTitle`, and the count family `detail.deleteRowsConfirmation` with its plural slots `_zero`, `_one`, `_two`, `_few`, `_many`, `_other` as each pack needs them); nothing removed or renamed
1212
Metadata-protocol: none
1313

1414
On a record page, a related list opened as its own tab now works like the object's list page:
1515

1616
- The first row names the child list (its tile and title) on the left and keeps **+ Add** on the right. The **Open in list** button is gone.
1717
- The second row is the list page's own condition row: **Sort** (several levels) and **Filter**, with no view switch, view settings or search. On a narrow tab or in the drawer their labels fold to icons.
18-
- The table is the list page's grid: the column menu, cell editing as on the list page wherever the reader may edit the child object, row selection with the floating bulk bar (bulk delete asks once), and the footer row, whose calculations cover every matching row, not just the loaded ones. A tab grouped by status draws no footer row.
18+
- The table is the list page's grid: the column menu, cell editing as on the list page wherever the reader may edit the child object, row selection with the floating bulk bar (bulk delete asks once, deletes the selection in one batch call where the data source has one, and says how many rows went and how many did not), and the footer row, whose calculations cover every matching row, not just the loaded ones. A tab grouped by status draws no footer row.
1919
- Rows load as the page scrolls instead of in pages.
2020
- The tab title still counts every child; the footer counts the rows the filter keeps.
21-
- What the reader changes (sort, filter, footer calculations) lasts while they stay on the record, across its tabs and between its page and its drawer, and is gone after a reload or on another record. **Discard** appears once something changed and puts the tab back; there is no Save. The list page's Discard and this one are one button.
21+
- What the reader changes (sort, filter, footer calculations) lasts while they stay on the record, for that reader only, across its tabs and between its page and its drawer, and is gone after a reload or on another record. **Discard** appears once something changed and puts the tab back; there is no Save. The list page's Discard and this one are one button.
2222

2323
Upgrade note: the header sort and the column widths and order that an earlier version remembered for a related tab in a reader's record-page preference (`sys_user_preference`) no longer apply: the tab opens in its declared order, and its column widths and order are now kept in the reader's browser, as the list page's are, so they start from the default once. Nothing stored is deleted. The default sort and columns of every related list are unchanged.
2424

‎ui/packages/plugin-detail/src/RelatedList.tsx‎

Lines changed: 40 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ import {
8989
} from '@object-ui/core';
9090
import { useSafeFieldLabel, useRecordContext, useRecordPagePreferences, type RelatedListPreference } from '@object-ui/react';
9191
import { usePermissions } from '@object-ui/permissions';
92-
import { useDisplayLocale, useLocalization, resolveFieldCurrency, recordCurrencyField, recordCurrencyPath, withFollowedParent } from '@object-ui/i18n';
92+
import { useObjectLabel, useDisplayLocale, useLocalization, resolveFieldCurrency, recordCurrencyField, recordCurrencyPath, withFollowedParent } from '@object-ui/i18n';
9393
import { useDetailTranslation } from './useDetailTranslation';
9494
import { isMaskedDetailFieldType } from './fieldEnrichment';
9595
import {
@@ -1565,10 +1565,13 @@ export const RelatedList: React.FC<RelatedListProps> = ({
15651565
// reads. What the reader changes there holds while they stay on this record
15661566
// (another tab, or the record's drawer, keeps it) and is gone on a reload or
15671567
// another record; 「Discard」 clears it (`./relatedTabConditions`). Keyed by
1568-
// the parent record and this list's relationship.
1568+
// the reader, the parent record and this list's relationship, as the list
1569+
// page's draft is keyed by its reader: another account signed in on the
1570+
// same tab starts from the default.
1571+
const readerScope = useFilterScope();
15691572
const tabRecord = enlargedFace && !schema && (type === 'grid' || type === 'table')
15701573
&& ownRelationshipId && parentId !== undefined && parentId !== null && parentId !== ''
1571-
? `${preferenceObject ?? ''}:${String(parentId)}`
1574+
? `${readerScope.currentUserId ?? ''}|${preferenceObject ?? ''}:${String(parentId)}`
15721575
: null;
15731576
const tabList = tabRecord !== null;
15741577
const {
@@ -2559,23 +2562,37 @@ export const RelatedList: React.FC<RelatedListProps> = ({
25592562
setDeleteTarget(null);
25602563
}, [deleteTarget, onRowDelete]);
25612564
// objectstack#35892 — the related tab's floating bar deletes the selected
2562-
// rows: one confirm that counts them, then the row delete this list was
2563-
// handed, row by row, and one re-read. A row that fails stops the rest and
2564-
// the re-read shows what was removed.
2565+
// rows (up to every matching row, with "select all"): one confirm that
2566+
// counts them, then the data source's batch delete in one call where it
2567+
// has one, else every row through the row delete this list was handed,
2568+
// settled together as the list page settles them. One re-read, and the
2569+
// outcome stays on screen: how many went, and how many did not.
25652570
const [bulkDeleteTargets, setBulkDeleteTargets] = React.useState<any[] | null>(null);
2571+
const [bulkDeleteOutcome, setBulkDeleteOutcome] = React.useState<{ succeeded: number; failed: number } | null>(null);
2572+
const { objectLabel } = useObjectLabel();
25662573
const handleBulkDeleteRows = React.useCallback((rows: any[]) => {
25672574
if (rows.length > 0) setBulkDeleteTargets(rows);
25682575
}, []);
25692576
const handleConfirmBulkDelete = React.useCallback(async () => {
2570-
const rows = bulkDeleteTargets ?? [];
2577+
const rows = (bulkDeleteTargets ?? []).filter((row) => row?.id != null || row?._id != null);
25712578
setBulkDeleteTargets(null);
2572-
try {
2573-
for (const row of rows) await onRowDelete?.(row);
2574-
} catch (err) {
2575-
console.error('[RelatedList] remove failed', err);
2579+
if (rows.length === 0) return;
2580+
const ids = rows.map((row) => String(row.id ?? row._id));
2581+
let succeeded = 0;
2582+
if (typeof dataSource?.bulkDelete === 'function') {
2583+
try {
2584+
const answer = await dataSource.bulkDelete(api, ids);
2585+
succeeded = Math.min(ids.length, typeof answer === 'number' ? answer : answer.succeeded);
2586+
} catch (err) {
2587+
console.error('[RelatedList] bulk delete failed', err);
2588+
}
2589+
} else if (onRowDelete) {
2590+
const settled = await Promise.allSettled(rows.map((row) => Promise.resolve(onRowDelete(row))));
2591+
succeeded = settled.filter((result) => result.status === 'fulfilled').length;
25762592
}
2593+
setBulkDeleteOutcome({ succeeded, failed: ids.length - succeeded });
25772594
setRefreshNonce((n) => n + 1);
2578-
}, [bulkDeleteTargets, onRowDelete]);
2595+
}, [bulkDeleteTargets, onRowDelete, dataSource, api]);
25792596

25802597
/**
25812598
* May the caller Add existing here? The write's row of the affordance-to-grant
@@ -4353,6 +4370,17 @@ export const RelatedList: React.FC<RelatedListProps> = ({
43534370
</div>
43544371
</div>
43554372
{conditionRow && <div className="min-w-0" data-related-enlarged-conditions="">{conditionRow}</div>}
4373+
{bulkDeleteOutcome && (
4374+
<p
4375+
role="status"
4376+
data-related-bulk-delete-outcome=""
4377+
className={cn('text-xs', bulkDeleteOutcome.failed > 0 ? 'text-destructive' : 'text-muted-foreground')}
4378+
>
4379+
{bulkDeleteOutcome.failed > 0
4380+
? t('objectActions.bulkDeletePartial', { succeeded: bulkDeleteOutcome.succeeded, failed: bulkDeleteOutcome.failed })
4381+
: t('objectActions.bulkDeleteSuccess', { count: bulkDeleteOutcome.succeeded, label: objectLabel({ name: api, label: objectSchema?.label ?? api }) })}
4382+
</p>
4383+
)}
43564384
{loadFailure ? (
43574385
<RelatedListLoadFailed error={loadFailure.error} onRetry={handleRetryRead} />
43584386
) : loading && relatedData.length === 0 ? (

‎ui/packages/plugin-detail/src/__tests__/RelatedList.tab-35892.test.tsx‎

Lines changed: 55 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import { describe, it, expect, vi, afterEach, beforeAll } from 'vitest';
2020
import { act, cleanup, fireEvent, render, screen, waitFor } from '@testing-library/react';
2121
import '@testing-library/jest-dom';
2222
import * as React from 'react';
23+
import { FilterScopeProvider } from '@object-ui/react';
2324
import { RelatedList } from '../RelatedList';
2425
import {
2526
RelatedListConditionsSlotContext,
@@ -78,14 +79,16 @@ function dataSourceFor() {
7879

7980
const renderCapturing = (props: RelatedListConditionsProps) => <CapturingConditions {...props} />;
8081

81-
function Tab({ parentId = 'O-1', dataSource, onTotal, onRowDelete, slot = renderCapturing }: {
82+
function Tab({ parentId = 'O-1', dataSource, onTotal, onRowDelete, slot = renderCapturing, reader = 'u-1' }: {
8283
parentId?: string;
84+
reader?: string;
8385
dataSource: ReturnType<typeof dataSourceFor>;
8486
onTotal?: (n: number) => void;
8587
onRowDelete?: (row: any) => Promise<void> | void;
8688
slot?: ((props: RelatedListConditionsProps) => React.ReactNode) | null;
8789
}) {
8890
return (
91+
<FilterScopeProvider currentUserId={reader}>
8992
<RelatedListConditionsSlotContext.Provider value={slot}>
9093
<RelatedListTotalReportContext.Provider value={onTotal}>
9194
<RelatedListEnlargedContext.Provider value>
@@ -104,6 +107,7 @@ function Tab({ parentId = 'O-1', dataSource, onTotal, onRowDelete, slot = render
104107
</RelatedListEnlargedContext.Provider>
105108
</RelatedListTotalReportContext.Provider>
106109
</RelatedListConditionsSlotContext.Provider>
110+
</FilterScopeProvider>
107111
);
108112
}
109113

@@ -225,7 +229,7 @@ describe('the related tab is the child object\'s full list (objectstack#35892)',
225229
expect(document.querySelector('[data-related-enlarged-conditions]')).not.toBeNull();
226230
});
227231

228-
it('the bulk bar\'s delete asks once, counting the rows, then deletes each and reads again', async () => {
232+
it('the bulk bar\'s delete asks once, counting the rows; without a batch delete it deletes each row, then reads again', async () => {
229233
const ds = dataSourceFor();
230234
const onRowDelete = vi.fn(async () => undefined);
231235
render(<Tab dataSource={ds} onRowDelete={onRowDelete} />);
@@ -237,5 +241,54 @@ describe('the related tab is the child object\'s full list (objectstack#35892)',
237241
fireEvent.click(document.querySelector('[data-related-bulk-delete-confirm]')!);
238242
await waitFor(() => expect(onRowDelete).toHaveBeenCalledTimes(3));
239243
await waitFor(() => expect(ds.find.mock.calls.length).toBeGreaterThan(reads));
244+
expect((await screen.findByRole('status')).textContent).toBe('Deleted 3 quote records');
245+
});
246+
247+
it('with the data source\'s batch delete, the selection goes in ONE call, not row by row', async () => {
248+
const ds = Object.assign(dataSourceFor(), { bulkDelete: vi.fn(async () => 3) });
249+
const onRowDelete = vi.fn(async () => undefined);
250+
render(<Tab dataSource={ds} onRowDelete={onRowDelete} />);
251+
await waitFor(() => expect(grid()?.schema.data.items).toHaveLength(12));
252+
act(() => grid().props.onBulkDelete(ROWS.slice(0, 3)));
253+
fireEvent.click(await screen.findByText('Delete', { selector: '[data-related-bulk-delete-confirm]' }));
254+
await waitFor(() => expect(ds.bulkDelete).toHaveBeenCalledTimes(1));
255+
expect(ds.bulkDelete).toHaveBeenCalledWith('quote', ['q1', 'q2', 'q3']);
256+
expect(onRowDelete).not.toHaveBeenCalled();
257+
expect((await screen.findByRole('status')).textContent).toBe('Deleted 3 quote records');
258+
});
259+
260+
it('a partial failure says how many went and how many did not, on the batch path and row by row', async () => {
261+
const batch = Object.assign(dataSourceFor(), {
262+
bulkDelete: vi.fn(async () => ({ succeeded: 2, errors: [{ id: 'q3', error: 'refused' }] })),
263+
});
264+
const first = render(<Tab dataSource={batch} onRowDelete={vi.fn()} />);
265+
await waitFor(() => expect(grid()?.schema.data.items).toHaveLength(12));
266+
act(() => grid().props.onBulkDelete(ROWS.slice(0, 3)));
267+
fireEvent.click(await screen.findByText('Delete', { selector: '[data-related-bulk-delete-confirm]' }));
268+
expect((await screen.findByRole('status')).textContent).toBe('2 deleted, 1 failed');
269+
first.unmount();
270+
h.byType = {};
271+
272+
const rowByRow = dataSourceFor();
273+
const onRowDelete = vi.fn(async (row: any) => { if (row.id === 'q2') throw new Error('refused'); });
274+
render(<Tab dataSource={rowByRow} onRowDelete={onRowDelete} />);
275+
await waitFor(() => expect(grid()?.schema.data.items).toHaveLength(12));
276+
act(() => grid().props.onBulkDelete(ROWS.slice(0, 3)));
277+
fireEvent.click(await screen.findByText('Delete', { selector: '[data-related-bulk-delete-confirm]' }));
278+
await waitFor(() => expect(onRowDelete).toHaveBeenCalledTimes(3));
279+
expect((await screen.findByRole('status')).textContent).toBe('2 deleted, 1 failed');
280+
});
281+
282+
it('is held per reader: another account signed in on the same record starts from the default', async () => {
283+
const ds = dataSourceFor();
284+
const first = render(<Tab dataSource={ds} reader="u-1" />);
285+
await waitFor(() => expect(grid()?.schema.data.items).toHaveLength(12));
286+
act(() => conditions().props.onFiltersChange(AMOUNT_GROUP, AMOUNT_OVER_600));
287+
await waitFor(() => expect(grid().schema.data.items).toHaveLength(6));
288+
first.unmount();
289+
h.byType = {};
290+
render(<Tab dataSource={ds} reader="u-2" />);
291+
await waitFor(() => expect(grid()?.schema.data.items).toHaveLength(12));
292+
expect(conditions().props.filters.conditions).toEqual([]);
240293
});
241294
});

‎ui/packages/plugin-detail/src/useDetailTranslation.ts‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,11 @@ export const DETAIL_DEFAULT_TRANSLATIONS: Record<string, string> = {
127127
'detail.deleteRowsConfirmation': '{{count}} records will be deleted. This cannot be undone.',
128128
'detail.deleteRowsConfirmation_one': '{{count}} record will be deleted. This cannot be undone.',
129129
'detail.deleteRowsConfirmation_other': '{{count}} records will be deleted. This cannot be undone.',
130+
// The bulk delete's outcome, in the list page's own words (`objectActions`).
131+
'objectActions.bulkDeleteSuccess': 'Deleted {{count}} {{label}} records',
132+
'objectActions.bulkDeleteSuccess_one': 'Deleted {{count}} {{label}} record',
133+
'objectActions.bulkDeleteSuccess_other': 'Deleted {{count}} {{label}} records',
134+
'objectActions.bulkDeletePartial': '{{succeeded}} deleted, {{failed}} failed',
130135
'detail.actions': 'Actions',
131136
'detail.previousPage': 'Previous',
132137
'detail.nextPage': 'Next',

0 commit comments

Comments
 (0)