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/39435-list-row-actions-no-selection.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
---
'@object-ui/plugin-grid': patch
---

fix(plugin-grid): list pages lift record_row actions without a selection column

Clause-②: no
Metadata-protocol: none

On an object's list page the rows draw no actions of their own: one selected row brings up its actions in the selection bar. A list with no selection had no way to select a row, so its declared row actions (`locations: ['record_row']`) could be reached only through the row's right-click menu. Setup lists such as sessions, invitations and API keys were affected: their rows had no checkbox and no selection bar, so Revoke session, Copy invitation link and Revoke API key were hidden.

- A list page grid whose view declares no `selection` (and no legacy `selectable`), and whose bulk actions open no selection, now lets you select one row at a time when a row on screen offers a declared row action. Selecting a row brings up its actions in the selection bar.
- A list page grid whose view switches selection off (`selection: { type: 'none' }`, or legacy `selectable: false`) draws the row's own actions menu at the end of each row instead, because no selection can show them there.
- Nothing changes on a list whose rows offer only the built-in Edit or Delete, or nothing at all. The same goes for a view that declares its own selection, and for a grid outside a list page (a related list, a page block, the record drawer).
37 changes: 30 additions & 7 deletions ui/packages/plugin-grid/src/ObjectGrid.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ import { useObjectGridColumnState } from './objectGridColumnState';
import { useObjectGridMobile } from './objectGridMobile';
import { useObjectGridGenerateColumns } from './objectGridGenerateColumns';
import { resolveObjectGridPersistedColumns } from './objectGridPersistedColumns';
import { resolveObjectGridActionsColumn } from './objectGridActionsColumn';
import { resolveObjectGridActionsColumn, resolveObjectGridRowActionOffer } from './objectGridActionsColumn';
import { useInlineRowActionFold } from './objectGridInlineActionFold';
import { BULK_SELECT_ALL_MATCHING_CAP } from './bulkSelectAllMatchingCap';
import { CHANGE_OWNER_BULK_ACTION } from './components/BulkActionBar';
Expand Down Expand Up @@ -1993,6 +1993,20 @@ export const ObjectGrid: React.FC<ObjectGridComponentProps> = ({
key: 'rowActions', names: undeclaredRowActions, ready: !objectSchemaAwaited,
basis: undeclaredNamesBasis, address: undeclaredNamesAddress,
});
// The host predicate scope (row-action visibility, conditional formatting
// below) and objectui#12708's capability gate, the one `RowActionMenu`
// applies per row: read here, above the early returns where no hook may
// sit, so the selection mode below and the Actions column's verdict see the
// same declared set.
const predicateScope = usePredicateScope();
const mayInvokeRowAction = useCapabilityGate();
// Whether a row offers an action (`./objectGridActionsColumn`): the same
// plan the Actions column and the row's menus are drawn from.
const rowActionOffer = resolveObjectGridRowActionOffer({
schema, data, objectSchema, operations, resolvedRowActionDefs, wantEditAction, wantDeleteAction,
mayInvokeRowAction, rowOperations, canEdit, canDelete, recordVerdict, approvalLocks, predicateScope,
onEdit, onDelete, editPredicates, deletePredicates, foldInlineRowActions: inlineActionFold.folded,
});
let selectionMode: 'none' | 'single' | 'multiple' | boolean = false;
if (schema.selection !== undefined) {
// "presence enables; an explicit off wins" — the ONE rule both
Expand All @@ -2016,7 +2030,20 @@ export const ObjectGrid: React.FC<ObjectGridComponentProps> = ({
// wires the bulk Change Owner whose grant it reads only once a selection
// is open (objectstack#35403): without the selection it never gets asked.
selectionMode = 'multiple';
} else if (listPageGrid && rowActionOffer.anyRowOffersDeclaredAction()) {
// objectstack#39435 — a list page's rows draw no actions of their own
// (objectstack#35554); one selected row lifts them into the selection bar.
// So where no author asked for selection and no bulk action opened one,
// rows that offer a declared row action are selectable one at a time —
// otherwise the row's context menu would be the only way to reach it. The
// built-in Edit / Delete alone open nothing: the opened record offers them.
selectionMode = 'single';
}
// objectstack#39435 — the author switched selection off (`selection.type:
// 'none'`, legacy `selectable: false`): no selection can lift a row's
// actions, so a list page's rows keep their own row controls.
const selectionAuthoredOff =
!selectionMode && (schema.selection !== undefined || schema.selectable !== undefined);
// `selection.type: 'single'` caps the selection at one row (the data-table
// enforces replace-on-select, #2941), so the cross-page "select all N
// matching" escalation must never be offered.
Expand Down Expand Up @@ -2065,11 +2092,7 @@ export const ObjectGrid: React.FC<ObjectGridComponentProps> = ({
// and ListView reach the identical verdict and the whole platform speaks one
// expression dialect. The host predicate scope is bound so `features.*`
// predicates resolve, mirroring row-action visibility.
const predicateScope = usePredicateScope();
// objectui#12708 — the row actions' capability gate, the one `RowActionMenu`
// applies per row, read here too so the Actions column's verdict (below the
// early returns, where no hook may sit) sees the same declared set.
const mayInvokeRowAction = useCapabilityGate();
// (`predicateScope` is read above, beside the selection mode.)
const getRowStyle = useCallback((row: Record<string, unknown>): React.CSSProperties | undefined => {
const rules = schema.conditionalFormatting;
if (!rules || rules.length === 0) return undefined;
Expand Down Expand Up @@ -2543,7 +2566,7 @@ export const ObjectGrid: React.FC<ObjectGridComponentProps> = ({
wantEditAction, wantDeleteAction, mayInvokeRowAction, rowOperations, canEdit, canDelete,
recordVerdict, approvalLocks, demandRowActions, predicateScope, onEdit, onDelete, editPredicates,
deletePredicates, executeAction, setRefreshKey, t, foldInlineRowActions: inlineActionFold.folded,
drawRowControls: !listPageGrid,
drawRowControls: !listPageGrid || selectionAuthoredOff,
});

// Density-driven cell padding/font (applied to every column so it actually reaches <td>).
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,181 @@
/**
* ObjectUI
* Copyright (c) 2024-present ObjectStack Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/

/**
* objectstack#39435 — a list page's row actions stay reachable without the
* browser's right-click.
*
* A list page's rows draw no actions of their own (objectstack#35554); one
* selected row lifts them into the selection bar. A grid whose author asked
* for no selection and whose bulk actions opened none had no selection, so
* its `record_row` actions were reachable only through the row's context
* menu. Now:
*
* - rows that offer an action are selectable one at a time, and one selected
* row brings up its actions in the bar;
* - where the author switched selection off, the rows keep their row-end
* controls instead;
* - CONTROL: a list page grid whose rows offer nothing, or only the built-in
* Edit (which the opened record offers too), gains no selection column, and
* a grid outside a list page keeps the face it had.
*
* The page column is a fixture built on the same `useListPageScope` the
* Console page bars call; the grid, its table, the selection bar and the menus
* are real.
*/
import { describe, it, expect, beforeEach } from 'vitest';
import { render, screen, waitFor, fireEvent, within } from '@testing-library/react';
import '@testing-library/jest-dom';
import React from 'react';

import { ObjectGrid } from '../ObjectGrid';
import { useListPageScope } from '../listPageScope';
import { registerAllFields } from '@object-ui/fields';
import { ActionProvider, SchemaRendererProvider, useAction } from '@object-ui/react';
import { __clearRecordCrudVerdictCache } from '../hooks/useRecordCrudVerdicts';

registerAllFields();
beforeEach(() => __clearRecordCrudVerdictCache());

const apiFetch = async (): Promise<Response> =>
({ ok: true, status: 200, json: async () => ({ allowed: true, layers: [] }) }) as unknown as Response;

const ROWS = [
{ id: 's1', name: 'Laptop session' },
{ id: 's2', name: 'Phone session' },
];

/** A Setup list such as 在线会话: one `record_row` action, no Edit, no Delete, no bulk action. */
function schemaOf(extra: Record<string, unknown> = {}): any {
return {
type: 'object-grid',
objectName: 'sys_session',
columns: [{ field: 'name', label: 'Name' }],
data: { provider: 'value', items: ROWS },
operations: { update: false, delete: false },
rowActionDefs: [{ name: 'revoke_session', label: 'Revoke session' }],
...extra,
};
}

/** The fixture page bar: it registers its page column as a list page scope. */
const PageBar: React.FC = () => {
const [scope, setScope] = React.useState<HTMLElement | null>(null);
useListPageScope(scope);
return <div ref={(el) => setScope(el?.parentElement ?? null)} data-testid="page-bar" />;
};

/** Reads what the grid publishes into the action context. */
const SelectionAvailableProbe: React.FC = () => {
const { runner } = useAction();
const read = React.useCallback(() => String(runner.getContext().selectionAvailable), [runner]);
const value = React.useSyncExternalStore(
React.useCallback((listener: () => void) => runner.subscribeContext(listener), [runner]),
read,
);
return <span data-testid="selection-available">{value}</span>;
};

function renderGrid(schema: any, { listPage, onEdit }: { listPage: boolean; onEdit?: (record: any) => void }) {
return render(
<SchemaRendererProvider dataSource={undefined} apiFetch={apiFetch}>
<ActionProvider>
<div data-testid="page-column">
{listPage && <PageBar />}
<ObjectGrid schema={schema} onEdit={onEdit} />
</div>
<SelectionAvailableProbe />
</ActionProvider>
</SchemaRendererProvider>,
);
}

const rowOf = (name: string) => screen.getByText(name).closest('tr')!;
const actionsHeader = (container: HTMLElement) => container.querySelector('th[data-column-key="_actions"]');
const bar = () => screen.getByTestId('bulk-actions-bar');

describe('objectstack#39435 — a list page grid with row actions and no authored selection', () => {
it('its rows are selectable, and one selected row brings up its actions in the selection bar', async () => {
const { container } = renderGrid(schemaOf(), { listPage: true });
await waitFor(() => expect(screen.getByText('Laptop session')).toBeInTheDocument());
// Still no row-end control on a list page.
expect(actionsHeader(container)).toBeNull();
expect(screen.queryAllByTestId('row-action-trigger')).toHaveLength(0);
// The row-level entry point: the row's checkbox.
await waitFor(() => expect(within(rowOf('Laptop session')).getByRole('checkbox')).toBeInTheDocument());
expect(screen.getByTestId('selection-available')).toHaveTextContent('true');

fireEvent.click(within(rowOf('Laptop session')).getByRole('checkbox'));
await waitFor(() => expect(bar()).toBeInTheDocument());
expect(within(bar()).getByTestId('bulk-selection-count')).toHaveTextContent('1');
expect(within(bar()).getByTestId('row-action-inline-revoke_session')).toBeInTheDocument();
});

it('the selection is single: picking a second row replaces the first', async () => {
renderGrid(schemaOf(), { listPage: true });
await waitFor(() => expect(within(rowOf('Laptop session')).getByRole('checkbox')).toBeInTheDocument());
fireEvent.click(within(rowOf('Laptop session')).getByRole('checkbox'));
await waitFor(() => expect(bar()).toBeInTheDocument());
fireEvent.click(within(rowOf('Phone session')).getByRole('checkbox'));
await waitFor(() =>
expect(within(rowOf('Phone session')).getByRole('checkbox')).toHaveAttribute('data-state', 'checked'),
);
expect(within(rowOf('Laptop session')).getByRole('checkbox')).not.toHaveAttribute('data-state', 'checked');
expect(within(bar()).getByTestId('bulk-selection-count')).toHaveTextContent('1');
expect(within(bar()).getByTestId('row-action-inline-revoke_session')).toBeInTheDocument();
});
});

describe('objectstack#39435 — a list page grid whose author switched selection off', () => {
it.each([
['selection.type: none', { selection: { type: 'none' } }],
['selectable: false', { selectable: false }],
])('%s: the rows keep their row-end controls and draw no checkbox', async (_label, extra) => {
const { container } = renderGrid(schemaOf(extra), { listPage: true });
await waitFor(() => expect(screen.getByText('Laptop session')).toBeInTheDocument());
await waitFor(() => expect(actionsHeader(container)).not.toBeNull());
expect(within(rowOf('Laptop session')).getByTestId('row-action-trigger')).toBeInTheDocument();
expect(screen.queryAllByRole('checkbox')).toHaveLength(0);
expect(screen.getByTestId('selection-available')).toHaveTextContent('false');
});
});

describe('objectstack#39435 — CONTROLS', () => {
it('a list page grid whose rows offer no action gains no selection column and no row control', async () => {
const { container } = renderGrid(schemaOf({ rowActionDefs: [] }), { listPage: true });
await waitFor(() => expect(screen.getByText('Laptop session')).toBeInTheDocument());
expect(screen.queryAllByRole('checkbox')).toHaveLength(0);
expect(actionsHeader(container)).toBeNull();
expect(screen.getByTestId('selection-available')).toHaveTextContent('false');
});

it('a list page grid whose rows offer only the built-in Edit gains no selection column', async () => {
const editOnly = schemaOf({ rowActionDefs: [], operations: { update: true, delete: false } });
renderGrid(editOnly, { listPage: true, onEdit: () => {} });
await waitFor(() => expect(screen.getByText('Laptop session')).toBeInTheDocument());
expect(screen.queryAllByRole('checkbox')).toHaveLength(0);
expect(screen.getByTestId('selection-available')).toHaveTextContent('false');
});

it('a list page grid whose only row action is hidden on every row gains no selection column', async () => {
const hidden = schemaOf({
rowActionDefs: [{ name: 'revoke_session', label: 'Revoke session', visible: 'false' }],
});
renderGrid(hidden, { listPage: true });
await waitFor(() => expect(screen.getByText('Laptop session')).toBeInTheDocument());
expect(screen.queryAllByRole('checkbox')).toHaveLength(0);
});

it('a grid outside a list page keeps its Actions column and gains no selection', async () => {
const { container } = renderGrid(schemaOf(), { listPage: false });
await waitFor(() => expect(screen.getByText('Laptop session')).toBeInTheDocument());
await waitFor(() => expect(actionsHeader(container)).not.toBeNull());
expect(screen.queryAllByRole('checkbox')).toHaveLength(0);
expect(screen.getByTestId('selection-available')).toHaveTextContent('false');
});
});
Loading
Loading