diff --git a/.changeset/36820-staged-row-menu-order.md b/.changeset/36820-staged-row-menu-order.md new file mode 100644 index 00000000000..8c003478dbb --- /dev/null +++ b/.changeset/36820-staged-row-menu-order.md @@ -0,0 +1,12 @@ +--- +'@object-ui/plugin-grid': patch +--- + +fix(plugin-grid): in design mode, a grid's row menus preview the staged record action order, as the record header does + +Clause-②: yes (widening) — new exports only: `StagedActionLayoutProvider`, `useStagedActionLayout` and the types `StagedActionLayout`, `StagedActionLayouts`, `StagedActionLayoutProviderProps` on `@object-ui/plugin-grid`, and the same five on its new side-effect-free subpath `@object-ui/plugin-grid/core` (a new `./core` entry in the `exports` map); nothing removed or renamed +Metadata-protocol: none + +An administrator who rearranges an object's record actions in the Console's design mode saw the staged order in the record header at once, while the grid's row "⋮" menu and its right-click menu kept the saved order until the change was saved. Both row menus now list in the staged order while the change is staged, and go back to the saved order when it is cancelled. + +`@object-ui/plugin-grid` (and its side-effect-free `@object-ui/plugin-grid/core` subpath, which registers nothing and reaches no grid renderer) exports `StagedActionLayoutProvider`, a context a host fills with the arrangements it has staged, by object name, and `useStagedActionLayout(objectName)`, which reads one. The grid reads the staged arrangement ahead of the object's served `actionLayout.record`. A staged value replaces the served one whole, as the record header reads it. With no provider, or nothing staged for the object, the grid lists by the served arrangement exactly as before. The Console mounts the provider once around its pages, fed by the design mode's staged changes, so every grid under it (list pages, related lists, split panes) previews the same order. The Console imports it from the `/core` subpath, so the grid itself stays out of the first load. The package's ESM build now emits `dist/index.js` and `dist/core.js` from one pass with one file per source module, so both entries share the one context; the UMD build is unchanged. diff --git a/ui/apps/console/vite.config.ts b/ui/apps/console/vite.config.ts index 57e419a9f93..1a38a582739 100644 --- a/ui/apps/console/vite.config.ts +++ b/ui/apps/console/vite.config.ts @@ -603,6 +603,7 @@ const workspaceAliases: Record = { '@object-ui/plugin-report': path.resolve(import.meta.dirname, '../../packages/plugin-report/src'), '@object-ui/plugin-form/core': path.resolve(import.meta.dirname, '../../packages/plugin-form/src/core.ts'), '@object-ui/plugin-form': path.resolve(import.meta.dirname, '../../packages/plugin-form/src'), + '@object-ui/plugin-grid/core': path.resolve(import.meta.dirname, '../../packages/plugin-grid/src/core.ts'), '@object-ui/plugin-grid': path.resolve(import.meta.dirname, '../../packages/plugin-grid/src'), '@object-ui/react': path.resolve(import.meta.dirname, '../../packages/react/src'), // The `/zod` subpath must be aliased BEFORE the bare package: a vite string @@ -1581,6 +1582,17 @@ export default defineConfig({ priority: 71, includeDependenciesRecursively: false, }, + // The grid's `/core` (objectstack#36820): the design mode's + // staged-arrangement provider, which `ConsoleLayout` mounts around + // every page. Same reason as the three above; without this group + // the two modules ride in `plugin-grid` and pull the whole grid + // into every first load. + { + name: 'plugin-grid-core', + test: /[\\/]packages[\\/]plugin-grid[\\/]src[\\/](core|stagedActionLayout)\.tsx?$/, + priority: 71, + includeDependenciesRecursively: false, + }, // // ## The chatbot's side-effect-free half stays out of its chunk (objectui#13410) // diff --git a/ui/packages/app-shell/src/__tests__/pluginCoreSubpaths-33581.test.ts b/ui/packages/app-shell/src/__tests__/pluginCoreSubpaths-33581.test.ts index 1f474da185e..67aba423555 100644 --- a/ui/packages/app-shell/src/__tests__/pluginCoreSubpaths-33581.test.ts +++ b/ui/packages/app-shell/src/__tests__/pluginCoreSubpaths-33581.test.ts @@ -40,6 +40,7 @@ import { fileURLToPath } from 'node:url'; import * as formCore from '@object-ui/plugin-form/core'; import * as viewCore from '@object-ui/plugin-view/core'; import * as detailCore from '@object-ui/plugin-detail/core'; +import * as gridCore from '@object-ui/plugin-grid/core'; // @ts-expect-error — plain-JS shared helper, intentionally untyped (`allowJs: false`) import { maskComments } from '../../../../scripts/js-comment-mask.mjs'; @@ -53,8 +54,9 @@ const ENTRIES = { '@object-ui/plugin-form': new Set(Object.keys(formCore)), '@object-ui/plugin-view': new Set(Object.keys(viewCore)), '@object-ui/plugin-detail': new Set(Object.keys(detailCore)), - // No `/core` subpath: listed so the eager-module pin below sees its entry. - '@object-ui/plugin-grid': new Set(), + // objectstack#36820 — the design mode's staged-arrangement provider, which + // `ConsoleLayout` mounts around every page. + '@object-ui/plugin-grid': new Set(Object.keys(gridCore)), } as const; type Entry = keyof typeof ENTRIES; @@ -119,12 +121,17 @@ describe('the form, view and detail helpers come from the /core subpaths (object for (const name of ['isRefusedFeedRead', 'relatedListEntryNames', 'seedRecordVerdict', 'relatedCountTargetsIn']) { expect(ENTRIES['@object-ui/plugin-detail'].has(name), name).toBe(true); } + for (const name of ['StagedActionLayoutProvider', 'useStagedActionLayout']) { + expect(ENTRIES['@object-ui/plugin-grid'].has(name), name).toBe(true); + } expect(FILES.length).toBeGreaterThan(500); // The scan must see the subpath imports it protects, or it is reading nothing. const coreImporters = FILES.filter((f) => /from\s*['"]@object-ui\/plugin-(form|view)\/core['"]/.test(readFileSync(f, 'utf8'))); expect(coreImporters.length).toBeGreaterThanOrEqual(10); const detailCoreImporters = FILES.filter((f) => /from\s*['"]@object-ui\/plugin-detail\/core['"]/.test(readFileSync(f, 'utf8'))); expect(detailCoreImporters.length).toBeGreaterThanOrEqual(9); + const gridCoreImporters = FILES.filter((f) => /from\s*['"]@object-ui\/plugin-grid\/core['"]/.test(readFileSync(f, 'utf8'))); + expect(gridCoreImporters.length).toBeGreaterThanOrEqual(1); }); it('no shell or console source imports a /core helper from a package entry', () => { @@ -160,6 +167,10 @@ describe('the form, view and detail helpers come from the /core subpaths (object 'packages/app-shell/src/views/lazyDetailSurfaces.tsx', 'packages/app-shell/src/views/record-preview/RecordPreviewCard.tsx', 'packages/app-shell/src/views/approval-decision/SubmittedRecord.tsx', + // objectstack#36820 — the shell's layout mounts the staged-arrangement + // bridge on every first load; the grid comes in only through `/core`. + 'packages/app-shell/src/layout/ConsoleLayout.tsx', + 'packages/app-shell/src/layout/DesignModeHeaderPins.tsx', ]; const offenders: string[] = []; for (const r of EAGER) { diff --git a/ui/packages/app-shell/src/layout/ConsoleLayout.tsx b/ui/packages/app-shell/src/layout/ConsoleLayout.tsx index 7f737be0629..5190f388a61 100644 --- a/ui/packages/app-shell/src/layout/ConsoleLayout.tsx +++ b/ui/packages/app-shell/src/layout/ConsoleLayout.tsx @@ -39,6 +39,7 @@ import { useHomePath } from '../hooks/useHomePath.js'; import { AppHeader } from './AppHeader.js'; import { DesignModeProvider, useDesignModeController } from './designMode.js'; import { DesignModeBar } from './DesignModeBar.js'; +import { DesignModeStagedPinsBridge } from './DesignModeHeaderPins.js'; import { useDesignModeArrival } from './useDesignModeArrival.js'; import { useResponsiveSidebar } from '../hooks/useResponsiveSidebar.js'; import { usePhoneNavDrawerHistory } from './usePhoneNavDrawerHistory.js'; @@ -302,6 +303,9 @@ export function ConsoleLayout({ its column into it). */} + {/* objectstack#36820 — the row menus of every grid on the shell's pages + preview a staged header arrangement, as the header does. */} + + diff --git a/ui/packages/app-shell/src/layout/DesignModeHeaderPins.tsx b/ui/packages/app-shell/src/layout/DesignModeHeaderPins.tsx index ae58e8d04be..aa48a312e97 100644 --- a/ui/packages/app-shell/src/layout/DesignModeHeaderPins.tsx +++ b/ui/packages/app-shell/src/layout/DesignModeHeaderPins.tsx @@ -17,7 +17,18 @@ import * as React from 'react'; import { useDesignModeActive, useDesignModeChange } from './designMode.js'; -import { pinsChangeKey, servedPins, type ObjectPins, type PinCandidate, type PinPage } from './designModeHeaderPinsModel.js'; +// The side-effect-free subpath, never the package root: `ConsoleLayout` mounts +// the bridge below on every first load, and the root would bring every grid +// renderer with it (`pluginCoreSubpaths-33581.test.ts`). +import { StagedActionLayoutProvider } from '@object-ui/plugin-grid/core'; +import { + pinsChangeKey, + servedPins, + stagedPinsByObject, + type ObjectPins, + type PinCandidate, + type PinPage, +} from './designModeHeaderPinsModel.js'; const HeaderPinsPanel = React.lazy(() => import('./DesignModeHeaderPinsPanel.js')); @@ -34,6 +45,26 @@ export function useObjectPins(objectDef: ServedObject | null | undefined): Objec return React.useMemo(() => staged ?? servedPins(objectDef), [staged, objectDef]); } +/** + * The other surfaces the arrangement governs (objectstack#36820): a grid's row + * menus list the record scope's actions in the arm's order, so while a change + * is staged they preview it as the header does. Mounted once, around the + * shell's pages, with the mode's staged `changes` (none while the mode is + * off); it hands every grid under it the staged arrangements by object name + * (`StagedActionLayoutProvider`), which a grid reads ahead of the object as + * served. Cancel or a save empties `changes`, and the menus list as saved. + */ +export function DesignModeStagedPinsBridge({ + changes, + children, +}: { + readonly changes: ReadonlyMap; + readonly children?: React.ReactNode; +}) { + const staged = React.useMemo(() => stagedPinsByObject(changes), [changes]); + return {children}; +} + export interface DesignModeHeaderPinsProps { /** The object as served: its name, package, actions and `actionLayout`. */ readonly objectDef: ServedObject & { readonly actions?: unknown }; diff --git a/ui/packages/app-shell/src/layout/__tests__/ConsoleLayout.stagedPins-36820.test.tsx b/ui/packages/app-shell/src/layout/__tests__/ConsoleLayout.stagedPins-36820.test.tsx new file mode 100644 index 00000000000..7b7c8a37cd3 --- /dev/null +++ b/ui/packages/app-shell/src/layout/__tests__/ConsoleLayout.stagedPins-36820.test.tsx @@ -0,0 +1,119 @@ +// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license. + +/** + * objectstack#36820 — the console shell hands the design mode's staged header + * arrangement to every grid on its pages. + * + * `ConsoleLayout` mounts `DesignModeStagedPinsBridge` once, inside the mode's + * provider and around the page, so a grid anywhere under the route slot reads + * the arrangement staged for its object (`useStagedActionLayout`) and its row + * menus preview it. Pinned here through the real layout: a page that stages an + * arrangement under the mode reads it back through the grid's hook, for its + * object only; Cancel drops it; and outside the mode nothing is staged. + * + * ## Real subjects + * + * `ConsoleLayout` with its real design-mode controller, bridge and + * `@object-ui/plugin-grid/core` provider. The chrome is stubbed, as in + * `ConsoleLayout.skipToContent-13130.test.tsx`. + */ + +import '@testing-library/jest-dom/vitest'; +// The layout reaches `import('@objectstack/lint')` (the draft bar's publish +// preflight); pay its first load at collection, never inside a clocked case. +import '@objectstack/lint'; +// The layout's chat dock reaches `import('@object-ui/plugin-grid')`; same reason. +import '@object-ui/plugin-grid'; +import { describe, it, expect, vi, afterEach } from 'vitest'; +import React from 'react'; +import { render, screen, cleanup, fireEvent, act } from '@testing-library/react'; +import { MemoryRouter } from 'react-router-dom'; +import { createI18n, I18nProvider } from '@object-ui/i18n'; +import { useStagedActionLayout } from '@object-ui/plugin-grid/core'; + +vi.mock('../../hooks/useAiSurface', () => ({ + useAiSurfaceEnabled: () => ({ enabled: false, isLoading: false }), +})); +vi.mock('../UnifiedSidebar', () => ({ UnifiedSidebar: () =>