Skip to content

Commit 92b3e86

Browse files
committed
refactor(plugin-grid): move ObjectGrid's authored-input diagnostics into a sibling hook (slice 3)
Move-only: the three console.warn effects for unreadable columns, unusable bulkActionDefs members and a non-positive page size move verbatim into useObjectGridDiagnostics(schema) in objectGridDiagnostics.ts. ObjectGrid calls the hook where the effects stood, so hook order does not change. Claude-Session: https://claude.ai/code/session_01Bdrd2yH4eqnz2QobtN3haE Co-authored-by: Claude <noreply@anthropic.com>
1 parent 222755e commit 92b3e86

3 files changed

Lines changed: 117 additions & 81 deletions

File tree

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
---
2+
'@object-ui/plugin-grid': patch
3+
---
4+
5+
refactor(plugin-grid): `ObjectGrid`'s authored-input diagnostics move into a sibling hook
6+
7+
Clause-②: no
8+
Metadata-protocol: none
9+
10+
The three `console.warn` effects that report an unreadable `columns` entry, an unusable `bulkActionDefs` member and a non-positive page size move verbatim out of `ObjectGrid.tsx` into `useObjectGridDiagnostics` (`objectGridDiagnostics.ts`). `ObjectGrid` calls the hook where the effects stood, so its hook order, its warnings and its rendered output do not change. No name is renamed, and the package entry is unchanged.
11+
12+
What to do: nothing.

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

Lines changed: 7 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -79,9 +79,9 @@ import { resolveRowCrudAffordances, resolveRowRecordCrudAffordance } from './row
7979
import { useRecordCrudVerdicts } from './hooks/useRecordCrudVerdicts';
8080
import { resolveLegacyRowActions } from './resolveLegacyRowActions';
8181
import { applyRelationalMeta } from './relationalMetaKeys';
82-
import { resolveBulkActions, describeUnusableBulkActionDefs, resolvePromotedBulkParams } from './resolveBulkActions';
82+
import { resolveBulkActions, resolvePromotedBulkParams } from './resolveBulkActions';
8383
import { partitionBulkRows } from './bulkEligibility';
84-
import { resolvesToDataColumn, describeUnresolvedColumns } from './columnSpellingDiagnostics';
84+
import { resolvesToDataColumn } from './columnSpellingDiagnostics';
8585
import { RowActionMenu, formatActionLabel, planRowActionMenu } from './components/RowActionMenu';
8686
import { BulkActionBar } from './components/BulkActionBar';
8787
import { BulkActionDialog } from './components/BulkActionDialog';
@@ -91,10 +91,11 @@ import { findParamsSignature, useResolvedGridFilters } from './objectGridQuery';
9191
import { type ObjectGridColumn, type ObjectGridColumnDraft, isChipFieldType, normalizeColumns, resolveColumnLabel } from './objectGridColumns';
9292
import { LinkCell, recordPointerFace, rowRecordId } from './objectGridLinkCell';
9393
import { useGridTranslation } from './objectGridTranslations';
94-
import { DEFAULT_DISPLAY_PAGE_SIZE, DEFAULT_FETCH_BATCH_SIZE, DEFAULT_SELECTION_TYPE, NO_GROUPING_REFUSAL, type RowHeightMode, describeNonPositivePageSize, resolvePageSize, resolveRowHeightMode } from './objectGridDefaults';
94+
import { DEFAULT_DISPLAY_PAGE_SIZE, DEFAULT_FETCH_BATCH_SIZE, DEFAULT_SELECTION_TYPE, NO_GROUPING_REFUSAL, type RowHeightMode, resolvePageSize, resolveRowHeightMode } from './objectGridDefaults';
9595
import { type BatchSaveOutcome, OCC_TOKEN_FIELD, type RowConflictChoice, type WrittenRowVersion, rowVersionOf, rowVersionToSend } from './objectGridRowVersion';
9696
import { type ObjectGridColumnState, type ObjectGridExternalPaginationProps, type ObjectGridFooterSummary } from './objectGridProps';
9797
import { FooterSummaryReport } from './objectGridFooterSummaryReport';
98+
import { useObjectGridDiagnostics } from './objectGridDiagnostics';
9899
export type { RetiredListColumnKey, ObjectGridColumnHolds, ObjectGridColumnDraft, ObjectGridColumn } from './objectGridColumns';
99100
export type { ObjectGridColumnState, ObjectGridFooterSummary, ObjectGridExternalPaginationProps } from './objectGridProps';
100101

@@ -2622,84 +2623,9 @@ export const ObjectGrid: React.FC<ObjectGridComponentProps> = ({
26222623
wholeSetSummary.row,
26232624
);
26242625

2625-
// An authored column the renderer cannot read now says so, instead of just
2626-
// not being there (objectui#5349 — the Q2 objectui#5068 deferred).
2627-
//
2628-
// #5068 made `ListColumnSchema`'s `field` / `label` the only spelling read
2629-
// here, which is right; what it left behind was the receipt. A column
2630-
// authored `{ accessorKey, header }` (or with no `field` at all) is dropped
2631-
// by `resolvesToDataColumn` above, and until this effect landed the author
2632-
// saw no error, no warning and no empty header — just a grid with its
2633-
// row-number column and no data columns. Same defect shape #5068 exists to
2634-
// fix, one level down: renderer and author disagree, author gets a success
2635-
// receipt.
2636-
//
2637-
// Scope, deliberately narrow: this reads the `columns` INPUT and nothing
2638-
// else. It never asks whether the grid found ROWS, because a grid legitimately
2639-
// draws them from five different places (inline `data` array, `data.provider:
2640-
// 'value'`, legacy `staticData`, `bind`, or a host that owns the fetch and
2641-
// passes the window down as a `data` React prop). A predicate that consulted
2642-
// those would eventually paint a configuration error over a working grid.
2643-
// `hidden: true` is authored intent and is never reported.
2644-
//
2645-
// Channel: the same one `ObjectGrid` already uses for "you declared it, the
2646-
// renderer dropped it" — a `useEffect` keyed on the schema slice and one
2647-
// `console.warn` prefixed `[ObjectUI] ObjectGrid <topic>:` (see the export
2648-
// format warning below) — rather than a second, differently-shaped one.
2649-
const columnDiagnosticBlockType = (schema as { type?: unknown }).type;
2650-
const columnDiagnosticLabel = schema.label ?? (schema as { title?: unknown }).title;
2651-
useEffect(() => {
2652-
const message = describeUnresolvedColumns(schema.columns, {
2653-
blockType: columnDiagnosticBlockType,
2654-
objectName: schema.objectName,
2655-
label: columnDiagnosticLabel,
2656-
});
2657-
if (message) console.warn(message);
2658-
}, [schema.columns, columnDiagnosticBlockType, schema.objectName, columnDiagnosticLabel]);
2659-
2660-
// [objectui#8730] The same channel, for the sibling failure on
2661-
// `bulkActionDefs`. A member that is not a usable def (a bare action name —
2662-
// the OTHER key's vocabulary — or `null`, a number, `{}`, `{ name: '' }`) is
2663-
// skipped by `resolveBulkActions`; before that guard it reached the bar and
2664-
// `formatActionLabel(undefined)` threw during render, so the author's first
2665-
// multi-row selection lost the whole selection bar.
2666-
//
2667-
// The skip alone would only relocate the failure into silence — which is what
2668-
// the mirror direction already does (`bulkActions: [{ name: 'approve' }]`,
2669-
// stepped over by the `typeof name !== 'string'` guard). Saying which member
2670-
// was dropped, and that a bare name belongs in `bulkActions`, is what makes
2671-
// this a diagnosis rather than a quieter version of the same defect. One
2672-
// `console.warn` per authored array, keyed on it — NOT a second guard: the
2673-
// predicate lives once, in `resolveBulkActions`, and this reads it.
2674-
const bulkDefsDiagnosticSlice = (schema as { bulkActionDefs?: unknown }).bulkActionDefs;
2675-
useEffect(() => {
2676-
const message = describeUnusableBulkActionDefs(bulkDefsDiagnosticSlice, {
2677-
blockType: columnDiagnosticBlockType,
2678-
objectName: schema.objectName,
2679-
label: columnDiagnosticLabel,
2680-
});
2681-
if (message) console.warn(message);
2682-
}, [bulkDefsDiagnosticSlice, columnDiagnosticBlockType, schema.objectName, columnDiagnosticLabel]);
2683-
2684-
// [objectui#9853] The same channel again, for a `pagination.pageSize` (or the
2685-
// deprecated flat shorthand) that is not a positive integer. `resolvePageSize`
2686-
// drops such a value at all three read points and uses the site's default; on
2687-
// its own that is a quieter version of the defect, because substituting a
2688-
// number the author never wrote is exactly what the flat site already did in
2689-
// silence. This is the half that makes it a diagnosis.
2690-
//
2691-
// Keyed on the authored slice, so it is one warning per declaration and not
2692-
// one per render. NOT a second guard — the predicate lives once, in
2693-
// `isUsablePageSize`, and this reads it.
2694-
const pageSizeDiagnosticObject = schema.pagination;
2695-
const pageSizeDiagnosticFlat = schema.pageSize;
2696-
useEffect(() => {
2697-
const message = describeNonPositivePageSize(
2698-
{ pagination: pageSizeDiagnosticObject, pageSize: pageSizeDiagnosticFlat },
2699-
{ blockType: columnDiagnosticBlockType, objectName: schema.objectName },
2700-
);
2701-
if (message) console.warn(message);
2702-
}, [pageSizeDiagnosticObject, pageSizeDiagnosticFlat, columnDiagnosticBlockType, schema.objectName]);
2626+
// The authored-input diagnostics (`columns`, `bulkActionDefs`, page size),
2627+
// three `console.warn` effects, run here in hook order (`./objectGridDiagnostics`).
2628+
useObjectGridDiagnostics(schema);
27032629

27042630
const generateColumns = useCallback((): ObjectGridColumnDraft[] => {
27052631
// objectui#11815 — the host's verdict on a declared deadline's
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
/**
2+
* The authored-input diagnostics of `ObjectGrid` (`./ObjectGrid.tsx`): the three
3+
* `console.warn` effects that report an unreadable `columns` entry, an unusable
4+
* `bulkActionDefs` member and a non-positive page size, moved out of that file
5+
* verbatim into a hook (objectstack#25994, slice 3).
6+
*/
7+
8+
import { useEffect } from 'react';
9+
import type { ObjectGridSchema } from '@object-ui/types';
10+
import { describeUnresolvedColumns } from './columnSpellingDiagnostics';
11+
import { describeUnusableBulkActionDefs } from './resolveBulkActions';
12+
import { describeNonPositivePageSize } from './objectGridDefaults';
13+
14+
/**
15+
* Runs `ObjectGrid`'s authored-input diagnostics. It declares no state and
16+
* returns nothing. `ObjectGrid` calls it where the three effects used to stand,
17+
* so the order of the component's hooks does not change.
18+
*/
19+
export function useObjectGridDiagnostics(schema: ObjectGridSchema): void {
20+
// An authored column the renderer cannot read now says so, instead of just
21+
// not being there (objectui#5349 — the Q2 objectui#5068 deferred).
22+
//
23+
// #5068 made `ListColumnSchema`'s `field` / `label` the only spelling read
24+
// here, which is right; what it left behind was the receipt. A column
25+
// authored `{ accessorKey, header }` (or with no `field` at all) is dropped
26+
// by `resolvesToDataColumn` above, and until this effect landed the author
27+
// saw no error, no warning and no empty header — just a grid with its
28+
// row-number column and no data columns. Same defect shape #5068 exists to
29+
// fix, one level down: renderer and author disagree, author gets a success
30+
// receipt.
31+
//
32+
// Scope, deliberately narrow: this reads the `columns` INPUT and nothing
33+
// else. It never asks whether the grid found ROWS, because a grid legitimately
34+
// draws them from five different places (inline `data` array, `data.provider:
35+
// 'value'`, legacy `staticData`, `bind`, or a host that owns the fetch and
36+
// passes the window down as a `data` React prop). A predicate that consulted
37+
// those would eventually paint a configuration error over a working grid.
38+
// `hidden: true` is authored intent and is never reported.
39+
//
40+
// Channel: the same one `ObjectGrid` already uses for "you declared it, the
41+
// renderer dropped it" — a `useEffect` keyed on the schema slice and one
42+
// `console.warn` prefixed `[ObjectUI] ObjectGrid <topic>:` (see the export
43+
// format warning below) — rather than a second, differently-shaped one.
44+
const columnDiagnosticBlockType = (schema as { type?: unknown }).type;
45+
const columnDiagnosticLabel = schema.label ?? (schema as { title?: unknown }).title;
46+
useEffect(() => {
47+
const message = describeUnresolvedColumns(schema.columns, {
48+
blockType: columnDiagnosticBlockType,
49+
objectName: schema.objectName,
50+
label: columnDiagnosticLabel,
51+
});
52+
if (message) console.warn(message);
53+
}, [schema.columns, columnDiagnosticBlockType, schema.objectName, columnDiagnosticLabel]);
54+
55+
// [objectui#8730] The same channel, for the sibling failure on
56+
// `bulkActionDefs`. A member that is not a usable def (a bare action name —
57+
// the OTHER key's vocabulary — or `null`, a number, `{}`, `{ name: '' }`) is
58+
// skipped by `resolveBulkActions`; before that guard it reached the bar and
59+
// `formatActionLabel(undefined)` threw during render, so the author's first
60+
// multi-row selection lost the whole selection bar.
61+
//
62+
// The skip alone would only relocate the failure into silence — which is what
63+
// the mirror direction already does (`bulkActions: [{ name: 'approve' }]`,
64+
// stepped over by the `typeof name !== 'string'` guard). Saying which member
65+
// was dropped, and that a bare name belongs in `bulkActions`, is what makes
66+
// this a diagnosis rather than a quieter version of the same defect. One
67+
// `console.warn` per authored array, keyed on it — NOT a second guard: the
68+
// predicate lives once, in `resolveBulkActions`, and this reads it.
69+
const bulkDefsDiagnosticSlice = (schema as { bulkActionDefs?: unknown }).bulkActionDefs;
70+
useEffect(() => {
71+
const message = describeUnusableBulkActionDefs(bulkDefsDiagnosticSlice, {
72+
blockType: columnDiagnosticBlockType,
73+
objectName: schema.objectName,
74+
label: columnDiagnosticLabel,
75+
});
76+
if (message) console.warn(message);
77+
}, [bulkDefsDiagnosticSlice, columnDiagnosticBlockType, schema.objectName, columnDiagnosticLabel]);
78+
79+
// [objectui#9853] The same channel again, for a `pagination.pageSize` (or the
80+
// deprecated flat shorthand) that is not a positive integer. `resolvePageSize`
81+
// drops such a value at all three read points and uses the site's default; on
82+
// its own that is a quieter version of the defect, because substituting a
83+
// number the author never wrote is exactly what the flat site already did in
84+
// silence. This is the half that makes it a diagnosis.
85+
//
86+
// Keyed on the authored slice, so it is one warning per declaration and not
87+
// one per render. NOT a second guard — the predicate lives once, in
88+
// `isUsablePageSize`, and this reads it.
89+
const pageSizeDiagnosticObject = schema.pagination;
90+
const pageSizeDiagnosticFlat = schema.pageSize;
91+
useEffect(() => {
92+
const message = describeNonPositivePageSize(
93+
{ pagination: pageSizeDiagnosticObject, pageSize: pageSizeDiagnosticFlat },
94+
{ blockType: columnDiagnosticBlockType, objectName: schema.objectName },
95+
);
96+
if (message) console.warn(message);
97+
}, [pageSizeDiagnosticObject, pageSizeDiagnosticFlat, columnDiagnosticBlockType, schema.objectName]);
98+
}

0 commit comments

Comments
 (0)