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
14 changes: 14 additions & 0 deletions .changeset/28865-enlarged-related-list-grid.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
---
'@object-ui/plugin-detail': patch
---

fix(plugin-detail): on a desktop the record page's enlarged related tab draws the child object's list grid, as the phone already does

Clause-②: no
Metadata-protocol: none

The enlarged related tab (the record page's active tab) drew a generic `data-table` on a desktop: rows about 65 px tall where the child object's list page draws 41 px, a name in plain text that did not open the record, and the count twice (on the 全部 chip and on the line under the toolbar). It now renders `object-grid` over the rows the related list already read, the branch the phone has taken since the phone card rows landed, so the tab is the child object's list face: the list page's row height and density, the name as a link that opens the record, and the grid's row actions.

The related list stays the source of truth. Its window, page and sort reach the grid as host props (the ones the list view hands the same grid), so paging and sort are still the server's `$top` / `$skip` / `$orderby`, and its own pager stays the one pager. The filter box, the 全部 / 我的 / 逾期 chips, 新建 and 导出 are unchanged. The host's row actions (`list_item`, and `record_related` inside a parent record) ride to the grid's row menu and still dispatch through the host against the child object and its row, which refreshes the list. While the 全部 chip is on and nothing narrows the rows, the line under the toolbar no longer repeats the chip's count.

One behaviour changes: while the filter box has text, the grid offers no header sort on a relational column (its stored value is an id), as on every list page; the data-table sorted that column by its label in that state. Compact panels in the right column and lists that are not enlarged are unchanged.
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,9 @@ describe('RecordDetailView — a child write in a related list refreshes the par
expect(headerBefore).toBeTruthy();

const row = screen.getByText('Seat licence').closest('tr')!;
await userEvent.click(within(row).getByRole('button', { name: 'Row actions' }));
// The enlarged tab draws the child object's list grid (objectstack#28865),
// so the row menu is the grid's.
await userEvent.click(within(row).getByTestId('row-action-trigger'));
await userEvent.click(await screen.findByTestId('row-action-builtin-delete'));
const dialog = await screen.findByRole('alertdialog');
await userEvent.click(within(dialog).getByRole('button', { name: /delete/i }));
Expand Down
174 changes: 152 additions & 22 deletions ui/packages/plugin-detail/src/RelatedList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import {
useIsMobile,
RelatedCountStore,
} from '@object-ui/components';
import { SchemaRenderer, useCapabilityGate, useCondition, toPredicateInput, useSettledSchema, useFilterScope, useResolvedFilter, usePredicateScope, classifyLoadError, declaredUserMessage, extractWriteErrorMessage, type LoadErrorKind, type RelatedRowActionDef } from '@object-ui/react';
import { SchemaRenderer, ActionCtxReact, useCapabilityGate, useCondition, toPredicateInput, useSettledSchema, useFilterScope, useResolvedFilter, usePredicateScope, classifyLoadError, declaredUserMessage, extractWriteErrorMessage, type LoadErrorKind, type RelatedRowActionDef } from '@object-ui/react';
import {
Plus,
ExternalLink,
Expand Down Expand Up @@ -80,6 +80,9 @@ import {
resolveAffordance,
isDeadlineSettled,
isActionSwitchedOff,
ActionRunner,
type ActionDef,
type ActionResult,
type FilterNode,
} from '@object-ui/core';
import { useSafeFieldLabel } from '@object-ui/react';
Expand Down Expand Up @@ -408,6 +411,26 @@ type FieldReadPolicy = ReturnType<typeof usePermissions>;
* so the field the card reads and the field the request carries cannot drift
* apart. The value is `ObjectGallery`'s own default, so the cover is unchanged.
*/
/**
* The action context a component reading `useAction()` gets when no
* `ActionProvider` is above it: a local runner, in the shape `useAction()`'s
* own fallback returns. The enlarged grid's routed context
* (`enlargedGridActions`) hands every dispatch that is not this list's row
* action to it, so the grid behaves under the routed context exactly as it
* would have without one.
*/
function localActionContext(runner: ActionRunner): React.ContextType<typeof ActionCtxReact> & object {
return {
execute: (action) => runner.execute(action),
executeChain: (actions, mode) => runner.executeChain(actions, mode),
loading: false,
error: null,
result: null,
runner,
updateContext: (ctx) => runner.updateContext(ctx),
};
}

const MOBILE_GALLERY_COVER_FIELD = 'image';

/**
Expand Down Expand Up @@ -2728,28 +2751,45 @@ export const RelatedList: React.FC<RelatedListProps> = ({
const viewSchema = React.useMemo(() => {
if (schema) return schema;

// objectstack#28865 (#27524 item 9) — the ENLARGED tab is the child
// object's list face, on a desktop as on a phone (objectstack#28484): the
// list page's grid, `object-grid`, over the rows this list already read.
// The grid draws the row height and density, the name link, the row
// actions and (under 768 px) the phone list's card rows. Resolved through
// the registry: `plugin-grid` depends on this package, so it cannot be
// imported here.
//
// This list stays the source of truth for everything the rows came from.
// Its window, page and sort reach the grid on the grid's HOST channel
// (`enlargedGridHost`, the React props `plugin-list`'s `ListView` hands
// it), never as node keys; the filter box, the chips, 新建 and 导出 stay
// in this list's toolbar; its own pager stays the one pager, so the
// grid's is off.
if (enlargedFace && (type === 'grid' || type === 'table')) {
return {
type: 'object-grid',
objectName: api,
data: { provider: 'value', items: paginatedData },
columns: effectiveColumns
.map((c: any) => c.accessorKey || columnIdentity(c))
.filter(Boolean),
showSearch: false,
showPagination: false,
// The host's row actions (`list_item`, and `record_related` inside a
// parent record), already localized — the non-author host key the
// console's object page hands the same grid. A dispatch from them is
// routed back to `onRowAction` (`enlargedGridActions`).
...(hasCustomRowActions && onRowAction ? { rowActionDefs: rowActions } : {}),
onRowClick: handleRowClick,
};
}

// Mobile: render grid/table data as a card gallery — single-column,
// tap-friendly, visually consistent with the standalone gallery view.
// Reuses the registered `object-gallery` schema so we don't ship a
// duplicate renderer. Falls back to the data-table on desktop and
// when explicit `type='list'` is requested (legacy path).
if (isMobile && (type === 'grid' || type === 'table')) {
// objectstack#28484 — the ENLARGED tab's phone cards are the phone
// list's card rows (`object-grid`'s card face: the name, one subtitle
// line, one status chip) at the body's full width, over the rows this
// list already read. Resolved through the registry: `plugin-grid`
// depends on this package, so it cannot be imported here.
if (enlargedFace) {
return {
type: 'object-grid',
objectName: api,
data: { provider: 'value', items: paginatedData },
columns: effectiveColumns
.map((c: any) => c.accessorKey || columnIdentity(c))
.filter(Boolean),
onRowClick: handleRowClick,
};
}
const titleField = effectiveColumns[0]?.accessorKey || columnIdentity(effectiveColumns[0]);
const visibleFields = effectiveColumns
.slice(1, 4)
Expand Down Expand Up @@ -2827,6 +2867,80 @@ export const RelatedList: React.FC<RelatedListProps> = ({
}
}, [type, paginatedData, tableColumns, effectiveColumns, schema, effectivePageSize, hasRowActions, hasCustomRowActions, rowActions, onRowAction, onRowEdit, onRowDelete, handleDeleteRow, handleRowClick, isMobile, compact, enlargedFace, api, objectSchema, activeSort, handleTableSort]);

const enlargedGrid = enlargedFace && !schema && (type === 'grid' || type === 'table');

/**
* objectstack#28865 — the enlarged face's grid, driven by this list on the
* grid's host channel: the React props `ObjectGrid` reads when a host owns
* the rows (`ObjectGridExternalPaginationProps`), the channel `plugin-list`'s
* `ListView` uses. Spread on `SchemaRenderer` as props, never node keys.
*
* - `manualPagination` with this list's page and count: `data` IS the page
* this list holds, so the grid neither slices nor re-pages it. The grid's
* pager is off (`showPagination: false` on the node); this list's pager
* answers a window whose total the server did not send (`hasMore`), which
* a pager over a row count cannot.
* - `sort` / `onSortChange` are this list's sort (objectui#3106), in BOTH
* of its modes: windowed it is the server's `$orderby`; while the filter
* box has text the list sorts its in-memory rows itself. Under a host
* sort the grid offers no header sort on a relational column (the stored
* value is an id, not the name the cell shows), in either mode.
* - `objectFields`: the definition this list already read, so no column
* paints withheld while the grid reads its own (objectui#10657).
* - `onEdit` / `onDelete`: this list's row Edit and its confirm-then-delete.
*/
const enlargedGridHost = React.useMemo(() => {
if (!enlargedGrid) return undefined;
const heldBefore = currentPage * (effectivePageSize || 0);
const rowCount = windowed
? total ?? heldBefore + relatedData.length + (hasMore ? 1 : 0)
: sortedData.length;
return {
manualPagination: true,
rowCount,
page: currentPage + 1,
pageSize: Math.max(1, effectivePageSize || paginatedData.length),
onPageChange: (page: number) => setCurrentPage(Math.max(0, page - 1)),
sort: activeSort,
onSortChange: handleTableSort,
...(objectSchema?.fields ? { objectFields: objectSchema.fields } : {}),
...(onRowEdit ? { onEdit: onRowEdit } : {}),
...(onRowDelete ? { onDelete: handleDeleteRow } : {}),
};
}, [enlargedGrid, windowed, total, currentPage, effectivePageSize, relatedData.length, hasMore, sortedData.length, paginatedData.length, activeSort, handleTableSort, objectSchema, onRowEdit, onRowDelete, handleDeleteRow]);

/**
* objectstack#28865 — where a row action the enlarged grid dispatches goes.
*
* The grid runs a row action def through the surrounding action runner with
* the row under `params._rowRecord` and no object of its own: on the record
* page that runner's object is the PARENT's, and nothing tells this list to
* read its rows again afterwards. The host that handed this list its row
* actions also handed it `onRowAction`, which dispatches against the child
* object and its row and signals the child object changed — the path the
* row menu of the table this face drew before took. So a dispatch carrying
* one of THIS list's action defs and a row goes there; every other dispatch
* (a bulk action, anything the grid runs without a row) reaches the
* surrounding runner unchanged — or, with no `ActionProvider` above, the
* local runner the grid's own `useAction()` would have made.
*/
const outerActions = React.useContext(ActionCtxReact);
const enlargedGridActions = React.useMemo(() => {
if (!enlargedGrid || !hasCustomRowActions || !onRowAction) return null;
const surrounding = outerActions ?? localActionContext(new ActionRunner());
const execute = async (action: ActionDef): Promise<ActionResult> => {
const params = action?.params as Record<string, unknown> | undefined;
const row = params?._rowRecord;
const def = row && typeof action?.name === 'string'
? rowActions!.find((candidate) => candidate.name === action.name)
: undefined;
if (!def) return surrounding.execute(action);
await onRowAction(def, row);
return { success: true };
};
return { ...surrounding, execute };
}, [enlargedGrid, hasCustomRowActions, rowActions, onRowAction, outerActions]);

const headerClassName = isCollapsible ? 'cursor-pointer select-none' : undefined;
const handleHeaderClick = isCollapsible ? () => setCollapsed((c) => !c) : undefined;

Expand Down Expand Up @@ -3165,6 +3279,12 @@ export const RelatedList: React.FC<RelatedListProps> = ({
// tab names the list, and its count is the 全部 chip's.
if (enlargedFace) {
const shownCount = filterActive ? filteredData.length : recordCount;
// objectstack#28865 — one count: while the 全部 chip is on and nothing
// narrows the rows, the chip already says how many there are, so the
// line under the toolbar does not say it again. A chip that narrows (我的,
// 逾期) or a filter text keeps the line's count, which is then a
// different number from the chip's.
const countOnChip = chips.length > 1 && enlargedChip === 'all' && !filterActive && allCount !== null && allCount === shownCount;
const chipLabel: Record<EnlargedChip, string> = {
all: t('detail.relatedChipAll', { defaultValue: 'All' }),
mine: t('detail.relatedChipMine', { defaultValue: 'Mine' }),
Expand Down Expand Up @@ -3308,12 +3428,22 @@ export const RelatedList: React.FC<RelatedListProps> = ({
</div>
) : (
<>
<div className="text-xs text-muted-foreground" data-related-enlarged-status="">
{t('detail.relatedRows', { count: shownCount, defaultValue: '{{count}} rows' })}
{showPagination && ` · ${t('detail.pageOf', { current: currentPage + 1, total: totalPages })}`}
</div>
{(!countOnChip || showPagination) && (
<div className="text-xs text-muted-foreground" data-related-enlarged-status="">
{[
countOnChip ? null : t('detail.relatedRows', { count: shownCount, defaultValue: '{{count}} rows' }),
showPagination ? t('detail.pageOf', { current: currentPage + 1, total: totalPages }) : null,
].filter(Boolean).join(' · ')}
</div>
)}
<div className={cn('min-w-0', loading && 'pointer-events-none opacity-60 transition-opacity')}>
<SchemaRenderer schema={viewSchema} />
{enlargedGridActions ? (
<ActionCtxReact.Provider value={enlargedGridActions}>
<SchemaRenderer schema={viewSchema} {...enlargedGridHost} />
</ActionCtxReact.Provider>
) : (
<SchemaRenderer schema={viewSchema} {...enlargedGridHost} />
)}
</div>
{showPagination && (
<div className="flex items-center justify-end gap-2">
Expand Down
Loading
Loading