Skip to content

Commit 382682a

Browse files
committed
wip(plugin-grid): bare bulkActions/rowActions names the object does not declare draw nothing
1 parent 9afcd6a commit 382682a

5 files changed

Lines changed: 172 additions & 37 deletions

File tree

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

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ import { resolveRowCrudAffordances, resolveRowRecordCrudAffordance } from './row
7373
import { useRecordCrudVerdicts } from './hooks/useRecordCrudVerdicts';
7474
import { resolveLegacyRowActions } from './resolveLegacyRowActions';
7575
import { resolveBulkActions, resolvePromotedBulkParams } from './resolveBulkActions';
76+
import { useUndeclaredActionNamesWarning } from './undeclaredActionNames';
7677
import { partitionBulkRows } from './bulkEligibility';
7778
import { RowActionMenu, formatActionLabel } from './components/RowActionMenu';
7879
import { BulkActionBar } from './components/BulkActionBar';
@@ -997,9 +998,10 @@ export const ObjectGrid: React.FC<ObjectGridComponentProps> = ({
997998
// Legacy `rowActions` carry a bare action NAME, which the runner cannot
998999
// execute on its own — resolve each against the object's declared actions so
9991000
// it dispatches as a real def (and so a name that duplicates an existing
1000-
// `list_item` def stops rendering a dead twin of it). See
1001+
// `list_item` def stops rendering a dead twin of it). A name the object does
1002+
// not declare draws nothing and is reported below, in development. See
10011003
// `resolveLegacyRowActions` for the full rationale (objectui#2960).
1002-
const { defs: resolvedRowActionDefs, unresolved: customRowActions } = resolveLegacyRowActions({
1004+
const { defs: resolvedRowActionDefs, undeclared: undeclaredRowActions } = resolveLegacyRowActions({
10031005
rowActions: rowActionsList.filter(a => a !== 'edit' && a !== 'delete'),
10041006
rowActionDefs: rowActionDefsList,
10051007
objectActions: (objectSchema as any)?.actions,
@@ -1250,14 +1252,16 @@ export const ObjectGrid: React.FC<ObjectGridComponentProps> = ({
12501252
: declaredBulkActions?.filter((a: unknown) => String(a).toLowerCase() !== 'delete');
12511253
// `bulkActions` carries a bare action NAME, which the runner cannot execute
12521254
// on its own — resolve each against `objectDef.actions` so it dispatches as a
1253-
// real def. See `resolveBulkActions` (objectui#3002). The
1255+
// real def. See `resolveBulkActions` (objectui#3002). A name the object does
1256+
// not declare gets no button (spec: a bare name "names an action the object
1257+
// declares") and is reported below, in development. The
12541258
// canonical `'delete'` is held back: it routes to `onBulkDelete` (which owns
12551259
// confirm + refresh), not the runner, even if the object declares an action
12561260
// that happens to be named `delete`.
12571261
const legacyBulkNames = (explicitBulkActions ?? []).filter(
12581262
(a: unknown) => String(a).toLowerCase() !== 'delete',
12591263
);
1260-
const { defs: resolvedBulkDefs, unresolved: unresolvedBulkActions } = resolveBulkActions({
1264+
const { defs: resolvedBulkDefs, undeclared: undeclaredBulkActions } = resolveBulkActions({
12611265
bulkActions: legacyBulkNames,
12621266
bulkActionDefs: Array.isArray(schema.bulkActionDefs) ? schema.bulkActionDefs : [],
12631267
objectActions: (objectSchema as any)?.actions,
@@ -1277,18 +1281,33 @@ export const ObjectGrid: React.FC<ObjectGridComponentProps> = ({
12771281
(objectCanDelete || def?.operation !== 'delete')
12781282
&& (rowEditVerdict.allowed || def?.operation !== 'update'),
12791283
);
1280-
// Names still dispatched by string: the unresolved ones, plus `'delete'`
1281-
// when the author asked for it — or the implicit bulk-delete affordance.
1284+
// The one name still dispatched by string: `'delete'` when the author asked
1285+
// for it — or the implicit bulk-delete affordance. An undeclared name is not
1286+
// among them: it draws nothing.
12821287
const keptDeleteAction = (explicitBulkActions ?? []).filter(
12831288
(a: unknown) => String(a).toLowerCase() === 'delete',
12841289
);
12851290
const effectiveBulkActions: string[] =
12861291
explicitBulkActions && explicitBulkActions.length > 0
1287-
? [...unresolvedBulkActions, ...keptDeleteAction]
1292+
? keptDeleteAction
12881293
: canDelete && onBulkDelete && bulkActionDefs.length === 0
12891294
? ['delete']
12901295
: [];
12911296
const hasBulkActions = effectiveBulkActions.length > 0 || bulkActionDefs.length > 0;
1297+
// The names the two folds above did not draw, said once in development. Only
1298+
// once the object's actions are known: before that every name is undeclared.
1299+
const undeclaredNamesReady = objectSchema != null || !schema.objectName;
1300+
const undeclaredNamesAddress = {
1301+
blockType: (schema as { type?: unknown }).type,
1302+
objectName: schema.objectName,
1303+
label: schema.label ?? (schema as { title?: unknown }).title,
1304+
};
1305+
useUndeclaredActionNamesWarning({
1306+
key: 'bulkActions', names: undeclaredBulkActions, ready: undeclaredNamesReady, address: undeclaredNamesAddress,
1307+
});
1308+
useUndeclaredActionNamesWarning({
1309+
key: 'rowActions', names: undeclaredRowActions, ready: undeclaredNamesReady, address: undeclaredNamesAddress,
1310+
});
12921311
let selectionMode: 'none' | 'single' | 'multiple' | boolean = false;
12931312
if (schema.selection !== undefined) {
12941313
// "presence enables; an explicit off wins" — the ONE rule both
@@ -1676,7 +1695,7 @@ export const ObjectGrid: React.FC<ObjectGridComponentProps> = ({
16761695
columnsWithActions, hasActions, hasPinnedColumns, hasUserPinnedColumns, pinnedLeftCols,
16771696
pinnedRightCols, unpinnedCols, rightPinnedClasses, rightPinnedCellClasses, userLeftPinnedCount,
16781697
} = resolveObjectGridActionsColumn({
1679-
schema, data, objectSchema, persistedColumns, operations, customRowActions, resolvedRowActionDefs,
1698+
schema, data, objectSchema, persistedColumns, operations, resolvedRowActionDefs,
16801699
wantEditAction, wantDeleteAction, mayInvokeRowAction, rowOperations, canEdit, canDelete,
16811700
recordVerdict, predicateScope, onEdit, onDelete, editPredicates, deletePredicates, executeAction,
16821701
setRefreshKey, t,

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

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ type RowCrudAffordances = ReturnType<typeof resolveRowCrudAffordances>;
2727
* `ObjectGrid` calls it where these lines used to stand.
2828
*/
2929
export function resolveObjectGridActionsColumn({
30-
schema, data, objectSchema, persistedColumns, operations, customRowActions, resolvedRowActionDefs,
30+
schema, data, objectSchema, persistedColumns, operations, resolvedRowActionDefs,
3131
wantEditAction, wantDeleteAction, mayInvokeRowAction, rowOperations, canEdit, canDelete,
3232
recordVerdict, predicateScope, onEdit, onDelete, editPredicates, deletePredicates, executeAction,
3333
setRefreshKey, t,
@@ -37,7 +37,6 @@ export function resolveObjectGridActionsColumn({
3737
objectSchema: any;
3838
persistedColumns: ReturnType<typeof resolveObjectGridPersistedColumns>['persistedColumns'];
3939
operations: ObjectGridSchema['operations'] | { update: boolean; delete: boolean };
40-
customRowActions: ReturnType<typeof resolveLegacyRowActions>['unresolved'];
4140
resolvedRowActionDefs: ReturnType<typeof resolveLegacyRowActions>['defs'];
4241
wantEditAction: boolean;
4342
wantDeleteAction: boolean;
@@ -61,7 +60,7 @@ export function resolveObjectGridActionsColumn({
6160
// record-level verdict they feed is fetched by a hook, which may not sit
6261
// behind a conditional return.
6362
const hasActions = !!(operations && (operations.update || operations.delete));
64-
const hasRowActions = customRowActions.length > 0 || resolvedRowActionDefs.length > 0 || wantEditAction || wantDeleteAction;
63+
const hasRowActions = resolvedRowActionDefs.length > 0 || wantEditAction || wantDeleteAction;
6564

6665
// objectui#12708 — the Actions column is drawn only when a row on screen
6766
// OFFERS something: its plan, the one `RowActionMenu` renders the row's cell
@@ -86,7 +85,6 @@ export function resolveObjectGridActionsColumn({
8685
scope: predicateScope,
8786
actionDefs: rowActionDefsGated,
8887
maxInlineActions: maxInlineRowActions,
89-
rowActions: customRowActions,
9088
...rowCrudVerdicts(row),
9189
onEdit,
9290
onDelete,
@@ -116,7 +114,6 @@ export function resolveObjectGridActionsColumn({
116114
const rowVerdicts = rowCrudVerdicts(row);
117115
return {
118116
row,
119-
rowActions: customRowActions,
120117
rowActionDefs: resolvedRowActionDefs as any[],
121118
objectFields: objectSchema?.fields,
122119
// NON-AUTHOR SURFACE — `maxInlineRowActions` is deliberately

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

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -75,11 +75,20 @@
7575
* historical no-op-per-row meaning (callout handled by the consumer's
7676
* `onComplete`).
7777
*
78-
* Names that resolve to nothing stay in `unresolved` and are still dispatched
79-
* by name: consumers may have registered a runner handler under exactly that
80-
* name (`runner.registerHandler('my_action', …)`), and that path must keep
81-
* working. When no such handler exists the runner reports the dead end rather
82-
* than toasting success (#2996).
78+
* ## A name the object does not declare draws nothing
79+
*
80+
* `bulkActions: ['<action_name>']` "names an action the object declares"
81+
* (`packages/spec/src/ui/bulk-action.zod.ts`), and lint `action-name-undefined`
82+
* (ADR-0049) refuses any other name at authoring. The selection bar holds the
83+
* same line at render: a name with no match in `objectDef.actions` gets no
84+
* button. That covers a misspelling and an action a disabled package withholds
85+
* (the server leaves it out of the served object, so it reads exactly like a
86+
* name that never existed). The name comes back in `undeclared` only so the
87+
* grid can say, once and in development, which names it did not draw
88+
* (`describeUndeclaredActionNames`). A runner handler registered under a bare
89+
* name is not a declaration and does not bring the button back. The canonical
90+
* `'delete'` is not a name this fold sees: the grid routes it to
91+
* `onBulkDelete` before the call.
8392
*/
8493

8594
import type { BulkActionDef, BulkActionParam } from '@object-ui/types';
@@ -417,8 +426,11 @@ export function resolveBulkActions(opts: {
417426
* its identity across renders.
418427
*/
419428
defs: readonly BulkActionDef[];
420-
/** Names that matched no declared action; dispatched by name. */
421-
unresolved: string[];
429+
/**
430+
* Names that matched no declared action. NOT drawn and NOT dispatched: they
431+
* exist for the development warning only.
432+
*/
433+
undeclared: string[];
422434
} {
423435
// [objectui#8730] THE GUARD SITE. This is the one place where the authored
424436
// `bulkActionDefs` array becomes the list the selection bar maps over, so the
@@ -473,25 +485,25 @@ export function resolveBulkActions(opts: {
473485
);
474486

475487
const promoted: BulkActionDef[] = [];
476-
const unresolved: string[] = [];
488+
const undeclared: string[] = [];
477489
for (const name of names) {
478490
if (typeof name !== 'string' || name === '') continue;
479491
// Already surfaced (an authored def of the same name, or an earlier pass
480492
// over a repeated entry) — drop the duplicate rather than render a twin.
481-
// Both outcomes claim the name: the bar keys its buttons on it, so even
482-
// two dead-name entries would collide.
493+
// Both outcomes claim the name, so a repeated undeclared name is reported
494+
// once.
483495
if (claimed.has(name)) continue;
484496
claimed.add(name);
485497
const match = objectActions.find(a => a?.name === name);
486498
if (match) {
487499
promoted.push(toBulkActionDef(match, opts.localizeLabel));
488500
} else {
489-
unresolved.push(name);
501+
undeclared.push(name);
490502
}
491503
}
492504

493505
return {
494506
defs: promoted.length > 0 ? [...authored, ...promoted] : authored,
495-
unresolved,
507+
undeclared,
496508
};
497509
}

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

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,16 @@
3232
* declared elsewhere on the object — the case the legacy form exists to serve —
3333
* is PROMOTED to that def so it dispatches for real.
3434
*
35-
* Names that resolve to nothing stay in `unresolved` and are still dispatched
36-
* by name: consumers may have registered a runner handler under exactly that
37-
* name (`runner.registerHandler('my_action', …)`), and that path must keep
38-
* working. When no such handler exists the runner now reports the dead end
39-
* rather than toasting success.
35+
* A name that resolves to nothing draws nothing. The spec's own sentence is
36+
* the rule: a bare `rowActions` / `bulkActions` name "names an action the
37+
* object declares" (`bulk-action.zod.ts`), and lint `action-name-undefined`
38+
* (ADR-0049) refuses an undeclared one at authoring. An action a disabled
39+
* package withholds is absent from the served `objectDef.actions` for the same
40+
* reason, so it leaves the row menu with the rest of that package. The name
41+
* is returned in `undeclared` only so the grid can say, once and in
42+
* development, which names it did not draw (`describeUndeclaredActionNames`).
43+
* A handler a host registers under a bare name is not a declaration and does
44+
* not bring the entry back.
4045
*/
4146

4247
/** The subset of an `ActionDef` this fold needs: everything is passed through. */
@@ -63,20 +68,23 @@ export function resolveLegacyRowActions(opts: {
6368
* every render of a view that has no legacy names to fold.
6469
*/
6570
defs: readonly NamedActionDef[];
66-
/** Legacy names that matched no declared action; dispatched by name. */
67-
unresolved: string[];
71+
/**
72+
* Legacy names that matched no declared action. NOT drawn and NOT
73+
* dispatched: they exist for the development warning only.
74+
*/
75+
undeclared: string[];
6876
} {
6977
const defs = Array.isArray(opts.rowActionDefs) ? opts.rowActionDefs : [];
7078
const names = Array.isArray(opts.rowActions) ? opts.rowActions : [];
71-
if (names.length === 0) return { defs, unresolved: [] };
79+
if (names.length === 0) return { defs, undeclared: [] };
7280

7381
const objectActions = Array.isArray(opts.objectActions) ? opts.objectActions : [];
7482
const claimed = new Set(
7583
defs.map(d => d?.name).filter((n): n is string => typeof n === 'string' && n !== ''),
7684
);
7785

7886
const promoted: NamedActionDef[] = [];
79-
const unresolved: string[] = [];
87+
const undeclared: string[] = [];
8088

8189
for (const name of names) {
8290
if (typeof name !== 'string' || name === '') continue;
@@ -87,13 +95,13 @@ export function resolveLegacyRowActions(opts: {
8795
if (match) {
8896
claimed.add(name);
8997
promoted.push(match);
90-
} else {
91-
unresolved.push(name);
98+
} else if (!undeclared.includes(name)) {
99+
undeclared.push(name);
92100
}
93101
}
94102

95103
return {
96104
defs: promoted.length > 0 ? [...defs, ...promoted] : defs,
97-
unresolved,
105+
undeclared,
98106
};
99107
}
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
/**
2+
* ObjectUI
3+
* Copyright (c) 2024-present ObjectStack Inc.
4+
*
5+
* This source code is licensed under the MIT license found in the
6+
* LICENSE file in the root directory of this source tree.
7+
*/
8+
9+
/**
10+
* The development warning for a bare `bulkActions` / `rowActions` name that
11+
* matches no action the object declares.
12+
*
13+
* `resolveBulkActions` and `resolveLegacyRowActions` draw nothing for such a
14+
* name: the spec says a bare name "names an action the object declares"
15+
* (`packages/spec/src/ui/bulk-action.zod.ts`), and lint
16+
* `action-name-undefined` (ADR-0049) refuses any other at authoring. This
17+
* module is the half that keeps the drop from being silent. It warns once per
18+
* distinct list, only in development, and only once the object's actions are
19+
* known, so a list that is still loading its object is never reported.
20+
*/
21+
22+
import { useEffect } from 'react';
23+
24+
/** The two bare-name keys whose undeclared names this module reports. */
25+
export type UndeclaredActionNameKey = 'bulkActions' | 'rowActions';
26+
27+
/** Where the offending block lives, for the first line of the message. */
28+
export interface UndeclaredActionNamesAddress {
29+
/** The schema node's `type`: `object-grid`, or the `view:grid` alias. */
30+
blockType?: unknown;
31+
/** The object the grid queries, when it names one. */
32+
objectName?: unknown;
33+
/** The grid's authored label, when it has one. */
34+
label?: unknown;
35+
}
36+
37+
const SURFACE: Record<UndeclaredActionNameKey, string> = {
38+
bulkActions: 'the selection bar draws no button',
39+
rowActions: 'the row menu draws no entry',
40+
};
41+
42+
function describeAddress({ blockType, objectName, label }: UndeclaredActionNamesAddress): string {
43+
const block = typeof blockType === 'string' && blockType.length > 0 ? blockType : 'object-grid';
44+
const parts: string[] = [];
45+
if (typeof objectName === 'string' && objectName.length > 0) parts.push(`objectName: '${objectName}'`);
46+
else parts.push('no objectName');
47+
if (typeof label === 'string' && label.length > 0) parts.push(`label: '${label}'`);
48+
return `${block} (${parts.join(', ')})`;
49+
}
50+
51+
/**
52+
* The message for the names one fold did not draw, or `null` when there are
53+
* none. It names the key, the block, and every name, and says what to write.
54+
*/
55+
export function describeUndeclaredActionNames(
56+
key: UndeclaredActionNameKey,
57+
names: readonly string[],
58+
address: UndeclaredActionNamesAddress,
59+
): string | null {
60+
if (names.length === 0) return null;
61+
const count = names.length === 1 ? '1 name matches' : `${names.length} names match`;
62+
const them = names.length === 1 ? 'it' : 'them';
63+
return `[ObjectUI] ObjectGrid ${key}: ${describeAddress(address)} — ${count} no action the object `
64+
+ `declares, so ${SURFACE[key]} for ${them}: ${names.map((n) => `'${n}'`).join(', ')}.\n`
65+
+ ` A bare \`${key}\` name must name an action declared on the object. Declare the action on the `
66+
+ 'object, or remove the name. An action that a disabled package withholds is left out of the '
67+
+ 'object the same way, so it is not drawn either.';
68+
}
69+
70+
function isDevelopment(): boolean {
71+
return (globalThis as any).process?.env?.NODE_ENV !== 'production';
72+
}
73+
74+
/**
75+
* Logs {@link describeUndeclaredActionNames} once per distinct list, in
76+
* development only. `ready` is false until the object's actions are known:
77+
* before that every name is undeclared and none is worth reporting.
78+
*/
79+
export function useUndeclaredActionNamesWarning(input: {
80+
key: UndeclaredActionNameKey;
81+
names: readonly string[];
82+
ready: boolean;
83+
address: UndeclaredActionNamesAddress;
84+
}): void {
85+
const { key, ready } = input;
86+
// Keyed on the names' VALUES, never on the array the fold returns, which is
87+
// a fresh one on every render.
88+
const namesKey = ready ? JSON.stringify(input.names) : '';
89+
const { blockType, objectName, label } = input.address;
90+
useEffect(() => {
91+
if (!namesKey || !isDevelopment()) return;
92+
const message = describeUndeclaredActionNames(key, JSON.parse(namesKey) as string[], {
93+
blockType,
94+
objectName,
95+
label,
96+
});
97+
if (message) console.warn(message);
98+
}, [key, namesKey, blockType, objectName, label]);
99+
}

0 commit comments

Comments
 (0)