Skip to content

Commit 85a0312

Browse files
committed
fix(plugin-list): a non-grid view's selection bar draws only actions the object declares
The bar ListView draws itself for kanban, calendar, gallery and the other non-grid views mapped every bare `bulkActions` name to a button. It now folds the names through plugin-grid's `resolveBulkActions`, the grid's own fold: a declared name draws under its declared label, the built-in `delete` keeps its own path, and any other name draws nothing and is named once in development by plugin-grid's `useUndeclaredActionNamesWarning`. plugin-grid exports the two (and their types) for this, and the warning's address gains an optional `component`, defaulting to `ObjectGrid` so the grid's message is unchanged. plugin-list declares plugin-grid as a peer and dev dependency. Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01L6bhgVzvtWN68zb2r9z2zy
1 parent 6c4c43a commit 85a0312

10 files changed

Lines changed: 292 additions & 12 deletions
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
---
2+
'@object-ui/plugin-list': minor
3+
'@object-ui/plugin-grid': minor
4+
---
5+
6+
fix(plugin-list): a list's selection bar over a non-grid view (kanban, calendar, gallery, …) draws only actions the object declares, by the grid's own rule; an undeclared bare `bulkActions` name draws nothing and warns once in development (#30394)
7+
8+
Clause-②: yes (widening) — `@object-ui/plugin-grid` exports `resolveBulkActions` and `useUndeclaredActionNamesWarning` (with the `ActionLabelResolver`, `NamedActionDef`, `UndeclaredActionNameKey`, `UndeclaredActionNamesAddress` and `UndeclaredActionNamesBasis` types) so `@object-ui/plugin-list` reuses the grid's fold and warning instead of a second copy; the warning's address gains an optional `component`, defaulting to `ObjectGrid`, so the grid's message is byte-identical.
9+
Metadata-protocol: narrowed
10+
Skills-docs: no move — `skills/**` teaches no handler-only bulk action name (searched for `bulkActions` examples); `content/docs/ui/**` already names only declared actions.
11+
12+
- **Before.** The bar ListView draws itself for every view but the grid mapped each `bulkActions` member straight to a button, labelled by the humanized name, whether or not the object declared it. A name the object does not declare (a misspelling, or an action a disabled package withholds from the served object) showed a button that toasted "not executable" on click. The grid stopped drawing such names in #30169.
13+
- **Now.** The bar folds the names through the grid's `resolveBulkActions`: a name the object declares draws under that action's label (through the app's i18n bundle), the built-in `delete` keeps its own path and gate, and any other name draws nothing. In development the console logs one warning per list naming the key, the view and each name (`[ObjectUI] ListView bulkActions: kanban (objectName: …) — …`), the grid's own message. A bar with nothing left to draw is not shown.
14+
- **Remedy.** Declare the named action on the object, or remove the name from `bulkActions`. An action withheld by a disabled package needs nothing: it draws again when the package is enabled.

‎pnpm-lock.yaml‎

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎ui/packages/plugin-grid/src/__tests__/undeclaredActionNames.test.ts‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,16 @@ describe('describeUndeclaredActionNames', () => {
5959
expect(line).not.toContain('matches no action');
6060
});
6161

62+
it('heads the message with ObjectGrid unless the address names another component (objectstack#30394)', () => {
63+
const grid = describeUndeclaredActionNames('bulkActions', ['create_campaign'], ADDRESS);
64+
expect(grid?.startsWith('[ObjectUI] ObjectGrid bulkActions: object-grid (')).toBe(true);
65+
const list = describeUndeclaredActionNames('bulkActions', ['create_campaign'], {
66+
component: 'ListView', blockType: 'kanban', objectName: 'lead',
67+
});
68+
expect(list?.startsWith("[ObjectUI] ListView bulkActions: kanban (objectName: 'lead')")).toBe(true);
69+
expect(list).toContain('the selection bar draws no button');
70+
});
71+
6272
it('says nothing for no names', () => {
6373
expect(describeUndeclaredActionNames('bulkActions', [], ADDRESS)).toBeNull();
6474
});

‎ui/packages/plugin-grid/src/index.tsx‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,11 @@ export { useGroupedData } from './useGroupedData';
3232
export { GroupRow } from './GroupRow';
3333
export { RowActionMenu, formatActionLabel } from './components/RowActionMenu';
3434
export { BulkActionBar } from './components/BulkActionBar';
35+
// The bare-name fold and its development warning, for the one other surface
36+
// that draws a selection bar of its own: plugin-list's ListView over a
37+
// non-grid view (objectstack#30394). One rule, one copy.
38+
export { resolveBulkActions } from './resolveBulkActions';
39+
export { useUndeclaredActionNamesWarning } from './undeclaredActionNames';
3540
export { useCellClipboard } from './useCellClipboard';
3641
export { useGradientColor } from './useGradientColor';
3742
export { useGroupReorder } from './useGroupReorder';
@@ -55,6 +60,12 @@ export type { GroupEntry, UseGroupedDataResult, AggregationType, GroupAggregatio
5560
export type { GroupRowProps } from './GroupRow';
5661
export type { RowActionMenuProps } from './components/RowActionMenu';
5762
export type { BulkActionBarProps } from './components/BulkActionBar';
63+
export type { ActionLabelResolver, NamedActionDef } from './resolveBulkActions';
64+
export type {
65+
UndeclaredActionNameKey,
66+
UndeclaredActionNamesAddress,
67+
UndeclaredActionNamesBasis,
68+
} from './undeclaredActionNames';
5869
export type { CellRange, UseCellClipboardOptions, UseCellClipboardResult } from './useCellClipboard';
5970
export type { GradientStop, UseGradientColorOptions } from './useGradientColor';
6071
export type { UseGroupReorderOptions, UseGroupReorderResult } from './useGroupReorder';

‎ui/packages/plugin-grid/src/undeclaredActionNames.ts‎

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,16 @@ export type UndeclaredActionNameKey = 'bulkActions' | 'rowActions';
4646

4747
/** Where the offending block lives, for the first line of the message. */
4848
export interface UndeclaredActionNamesAddress {
49-
/** The schema node's `type`: `object-grid`, or the `view:grid` alias. */
49+
/**
50+
* The component whose bar or menu left the names undrawn, for the message's
51+
* head. Omitted: `ObjectGrid`. `@object-ui/plugin-list`'s ListView passes
52+
* `ListView` for the selection bar it draws itself over a non-grid view.
53+
*/
54+
component?: unknown;
55+
/**
56+
* The schema node's `type`: `object-grid`, or the `view:grid` alias; for
57+
* ListView, the view on screen (`kanban`, `calendar`, …).
58+
*/
5059
blockType?: unknown;
5160
/** The object the grid queries, when it names one. */
5261
objectName?: unknown;
@@ -67,6 +76,10 @@ const SURFACE: Record<UndeclaredActionNameKey, string> = {
6776
rowActions: 'the row menu draws no entry',
6877
};
6978

79+
function describeComponent(component: unknown): string {
80+
return typeof component === 'string' && component.length > 0 ? component : 'ObjectGrid';
81+
}
82+
7083
function describeAddress({ blockType, objectName, label }: UndeclaredActionNamesAddress): string {
7184
const block = typeof blockType === 'string' && blockType.length > 0 ? blockType : 'object-grid';
7285
const parts: string[] = [];
@@ -92,13 +105,13 @@ export function describeUndeclaredActionNames(
92105
const rule = ` A bare \`${key}\` name must name an action declared on the object.`;
93106
if (basis === 'unread') {
94107
const count = names.length === 1 ? '1 name' : `${names.length} names`;
95-
return `[ObjectUI] ObjectGrid ${key}: ${describeAddress(address)} — the object's schema could not `
108+
return `[ObjectUI] ${describeComponent(address.component)} ${key}: ${describeAddress(address)} — the object's schema could not `
96109
+ `be read (no getObjectSchema on the data source, or the read failed), so its declared actions `
97110
+ `are unknown and ${SURFACE[key]} for ${count}: ${listed}.\n`
98111
+ `${rule} Give the grid a data source that answers getObjectSchema, or check why the read failed.`;
99112
}
100113
const count = names.length === 1 ? '1 name matches' : `${names.length} names match`;
101-
return `[ObjectUI] ObjectGrid ${key}: ${describeAddress(address)} — ${count} no action the object `
114+
return `[ObjectUI] ${describeComponent(address.component)} ${key}: ${describeAddress(address)} — ${count} no action the object `
102115
+ `declares, so ${SURFACE[key]} for ${them}: ${listed}.\n`
103116
+ `${rule} Declare the action on the `
104117
+ 'object, or remove the name. An action that a disabled package withholds is left out of the '
@@ -141,16 +154,17 @@ export function useUndeclaredActionNamesWarning(input: {
141154
// Keyed on the names' VALUES, never on the array the fold returns, which is
142155
// a fresh one on every render.
143156
const namesKey = ready ? JSON.stringify(input.names) : '';
144-
const { blockType, objectName, label } = input.address;
157+
const { component, blockType, objectName, label } = input.address;
145158
useEffect(() => {
146159
if (!namesKey || !isDevelopment()) return;
147160
const message = describeUndeclaredActionNames(key, JSON.parse(namesKey) as string[], {
161+
component,
148162
blockType,
149163
objectName,
150164
label,
151165
}, basis);
152166
if (!message || warnedMessages.has(message)) return;
153167
warnedMessages.add(message);
154168
console.warn(message);
155-
}, [key, namesKey, basis, blockType, objectName, label]);
169+
}, [key, namesKey, basis, component, blockType, objectName, label]);
156170
}

‎ui/packages/plugin-list/package.json‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
"@object-ui/mobile": "workspace:^",
4949
"@object-ui/permissions": "workspace:^",
5050
"@object-ui/plugin-detail": "workspace:^",
51+
"@object-ui/plugin-grid": "workspace:^",
5152
"@object-ui/react": "workspace:^",
5253
"@object-ui/types": "workspace:^",
5354
"@objectstack/spec": "workspace:^",
@@ -62,6 +63,7 @@
6263
"@object-ui/mobile": "workspace:*",
6364
"@object-ui/permissions": "workspace:*",
6465
"@object-ui/plugin-detail": "workspace:*",
66+
"@object-ui/plugin-grid": "workspace:*",
6567
"@object-ui/react": "workspace:*",
6668
"@object-ui/test-support": "workspace:*",
6769
"@object-ui/types": "workspace:*",

‎ui/packages/plugin-list/src/ListView.tsx‎

Lines changed: 51 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ import { resolveInjectedSystemColumns, resolveSearchFieldResolution, type Search
5454
import { SystemFieldName } from '@objectstack/spec/system';
5555
import { usePermissions } from '@object-ui/permissions';
5656
import { RecordDetailPanel } from '@object-ui/plugin-detail';
57+
import { resolveBulkActions, useUndeclaredActionNamesWarning } from '@object-ui/plugin-grid';
5758

5859
/**
5960
* The `case 'map'` branch below builds an `object-map` schema by flattening
@@ -2535,6 +2536,51 @@ export const ListView = React.forwardRef<ListViewHandle, ListViewProps>(({
25352536
return declared.filter((a: unknown) => String(a).toLowerCase() !== 'delete');
25362537
}, [schema.bulkActions, bulkDeleteVerdict]);
25372538

2539+
/**
2540+
* [objectstack#30394] What the non-grid bar DRAWS out of `permittedBulkActions`:
2541+
* the grid's own rule (objectstack#30169, ruling C), folded by the grid's own
2542+
* `resolveBulkActions` so the two bars cannot drift.
2543+
*
2544+
* A bare name draws only when the object declares an action of that name,
2545+
* labelled from that declaration (through the app's i18n bundle, as the grid
2546+
* labels it). The canonical `delete` keeps its own path: it is not an object
2547+
* action but the built-in bulk delete, gated above by `bulkDeleteVerdict`,
2548+
* so it is held out of the fold exactly as the grid holds it out. Any other
2549+
* name draws nothing; `undeclared` exists only for the development warning
2550+
* below. Before this fold every member drew a button, so a name the object
2551+
* never declared, an action a disabled package withholds included, showed a
2552+
* button that only toasted "not executable" when pressed.
2553+
*/
2554+
const nonGridBulkBar = React.useMemo(() => {
2555+
const names = (permittedBulkActions ?? []).filter((a: unknown) => typeof a === 'string' && a !== '') as string[];
2556+
const { defs, undeclared } = resolveBulkActions({
2557+
bulkActions: names.filter((a) => a.toLowerCase() !== 'delete'),
2558+
objectActions: objectDef?.actions,
2559+
localizeLabel: (actionName, fallback) =>
2560+
schema.objectName && typeof resolveActionLabel === 'function'
2561+
? resolveActionLabel(schema.objectName, actionName, fallback)
2562+
: fallback,
2563+
});
2564+
const labels = new Map(defs.map((def) => [def.name, def.label]));
2565+
// Authored order, the built-in `delete` where the author put it.
2566+
const drawn = names
2567+
.filter((a) => a.toLowerCase() === 'delete' || labels.has(a))
2568+
.map((name) => ({ name, label: labels.get(name) }));
2569+
return { drawn, undeclared };
2570+
}, [permittedBulkActions, objectDef, schema.objectName, resolveActionLabel]);
2571+
// The grid says its own (ObjectGrid warns for the names it leaves undrawn),
2572+
// so this one speaks only while a non-grid view is on screen, and only once
2573+
// the object's schema read has settled. A list with an object but no schema
2574+
// in hand (no `getObjectSchema`, or the read failed) reports the names as
2575+
// unread, never as undeclared: the grid's own reading.
2576+
useUndeclaredActionNamesWarning({
2577+
key: 'bulkActions',
2578+
names: nonGridBulkBar.undeclared,
2579+
ready: objectDefLoaded && currentView !== 'grid',
2580+
basis: schema.objectName && objectDef == null ? 'unread' : 'declared',
2581+
address: { component: 'ListView', blockType: currentView, objectName: schema.objectName, label: schema.label },
2582+
});
2583+
25382584
/**
25392585
* [objectui#4420] The PER-RECORD half of the same key, for the same bar.
25402586
*
@@ -7352,7 +7398,7 @@ export const ListView = React.forwardRef<ListViewHandle, ListViewProps>(({
73527398
)}
73537399

73547400
{/* Bulk Actions Bar — skip for grid view since ObjectGrid renders its own BulkActionBar */}
7355-
{permittedBulkActions && permittedBulkActions.length > 0 && selectedRows.length > 0 && currentView !== 'grid' && (
7401+
{nonGridBulkBar.drawn.length > 0 && selectedRows.length > 0 && currentView !== 'grid' && (
73567402
<div
73577403
className="border-t border-primary/30 px-4 py-2 flex items-center gap-2 text-xs bg-primary/10 text-foreground shrink-0 shadow-sm"
73587404
role="region"
@@ -7364,8 +7410,8 @@ export const ListView = React.forwardRef<ListViewHandle, ListViewProps>(({
73647410
{selectedRows.length} {selectedRows.length === 1 ? 'item' : 'items'} selected
73657411
</span>
73667412
<div className="flex items-center gap-1.5 ml-3">
7367-
{permittedBulkActions.map((action: any) => {
7368-
const actionStr = String(action).toLowerCase();
7413+
{nonGridBulkBar.drawn.map(({ name: action, label }) => {
7414+
const actionStr = action.toLowerCase();
73697415
const isDestructive = actionStr.includes('delete') || actionStr.includes('remove') || actionStr.includes('destroy');
73707416
const Icon = isDestructive ? Trash2 : null;
73717417
// [objectui#4420] The built-in `delete` runs over the ALLOWED
@@ -7388,7 +7434,7 @@ export const ListView = React.forwardRef<ListViewHandle, ListViewProps>(({
73887434
data-testid={`bulk-action-${action}`}
73897435
>
73907436
{Icon && <Icon className="h-3 w-3" />}
7391-
{tActionLabel(action)}
7437+
{label ?? tActionLabel(action)}
73927438
</Button>
73937439
);
73947440
})}
@@ -7402,7 +7448,7 @@ export const ListView = React.forwardRef<ListViewHandle, ListViewProps>(({
74027448
the dialog's slot: one name for one fact, whichever surface says
74037449
it. */}
74047450
{bulkDeleteEligibility.skipped > 0
7405-
&& permittedBulkActions.some((a: any) => String(a).toLowerCase() === 'delete') && (
7451+
&& nonGridBulkBar.drawn.some(({ name }) => name.toLowerCase() === 'delete') && (
74067452
<span
74077453
className="text-muted-foreground ml-3"
74087454
data-testid="bulk-skipped-notice"

‎ui/packages/plugin-list/src/__tests__/ListView.bulkDeleteVisibleWhen.test.tsx‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,9 @@ function makeDataSource(userActionsDelete?: unknown) {
8080
name: { type: 'text' },
8181
status: { type: 'text' },
8282
},
83+
// `archive` is declared: the non-grid bar draws a bare `bulkActions`
84+
// name only when the object declares it (objectstack#30394).
85+
actions: [{ name: 'archive', label: 'Archive' }],
8386
...(userActionsDelete === undefined ? {} : { userActions: { delete: userActionsDelete } }),
8487
}),
8588
};

0 commit comments

Comments
 (0)