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
12 changes: 12 additions & 0 deletions .changeset/36820-staged-row-menu-order.md
Original file line number Diff line number Diff line change
@@ -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.
12 changes: 12 additions & 0 deletions ui/apps/console/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -603,6 +603,7 @@ const workspaceAliases: Record<string, string> = {
'@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
Expand Down Expand Up @@ -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)
//
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand All @@ -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<string>(),
// 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;

Expand Down Expand Up @@ -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', () => {
Expand Down Expand Up @@ -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) {
Expand Down
5 changes: 5 additions & 0 deletions ui/packages/app-shell/src/layout/ConsoleLayout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -302,6 +303,9 @@ export function ConsoleLayout({
its column into it). */}
<SidebarDocsNavSlotProvider>
<DesignModeProvider value={designMode}>
{/* objectstack#36820 — the row menus of every grid on the shell's pages
preview a staged header arrangement, as the header does. */}
<DesignModeStagedPinsBridge changes={designMode.changes}>
<AppShell
sidebar={
phoneDocsPage ? undefined : (
Expand Down Expand Up @@ -434,6 +438,7 @@ export function ConsoleLayout({
{/* Under `md` the drawer is a bottom sheet (no room for a rail on a phone). */}
{chatDock.sheet}
</AppShell>
</DesignModeStagedPinsBridge>
</DesignModeProvider>
</SidebarDocsNavSlotProvider>
</PhonePageBarProvider>
Expand Down
33 changes: 32 additions & 1 deletion ui/packages/app-shell/src/layout/DesignModeHeaderPins.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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'));

Expand All @@ -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<string, { readonly value: unknown }>;
readonly children?: React.ReactNode;
}) {
const staged = React.useMemo(() => stagedPinsByObject(changes), [changes]);
return <StagedActionLayoutProvider value={staged}>{children}</StagedActionLayoutProvider>;
}

export interface DesignModeHeaderPinsProps {
/** The object as served: its name, package, actions and `actionLayout`. */
readonly objectDef: ServedObject & { readonly actions?: unknown };
Expand Down
Original file line number Diff line number Diff line change
@@ -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: () => <nav /> }));
vi.mock('../AppHeader', () => ({ AppHeader: () => null }));
vi.mock('../ConsoleNotificationBanners', () => ({ ConsoleNotificationBanners: () => null }));
vi.mock('../../preview/DraftPreviewBar', () => ({ DraftPreviewBar: () => null }));
vi.mock('../../preview/UnpublishedAppBar', () => ({ UnpublishedAppBar: () => null }));

import { ConsoleLayout } from '../ConsoleLayout';
import { NavigationProvider } from '../../context/NavigationContext';
import { useDesignMode, useDesignModeChange } from '../designMode';
import { pinsChangeKey } from '../designModeHeaderPinsModel';

const APP = { name: 'crm', label: 'CRM', active: true, navigation: [] };
const STAGED = { record: { pinned: ['mark_won'], more: ['convert'] } };

/** A page under the route slot: it stages through the mode, and reads what a grid of two objects reads. */
function Page() {
const mode = useDesignMode();
const lead = useDesignModeChange<typeof STAGED>(pinsChangeKey('crm_lead'));
const leadReads = useStagedActionLayout('crm_lead');
const accountReads = useStagedActionLayout('crm_account');
return (
<div>
<button type="button" onClick={() => mode?.enter()}>enter</button>
<button type="button" onClick={() => lead.stage(STAGED, async () => {})}>stage</button>
<button type="button" onClick={() => mode?.cancel()}>cancel</button>
<output data-testid="lead">{leadReads === undefined ? 'none' : JSON.stringify(leadReads)}</output>
<output data-testid="account">{accountReads === undefined ? 'none' : JSON.stringify(accountReads)}</output>
</div>
);
}

function mountConsole() {
Object.defineProperty(window, 'innerWidth', { value: 1440, configurable: true, writable: true });
return render(
<I18nProvider instance={createI18n({ defaultLanguage: 'en', detectBrowserLanguage: false })} persistLanguage={false}>
<MemoryRouter initialEntries={['/apps/crm/crm_lead']}>
<NavigationProvider>
<ConsoleLayout activeAppName="crm" activeApp={APP} onAppChange={vi.fn()} objects={[]}>
<Page />
</ConsoleLayout>
</NavigationProvider>
</MemoryRouter>
</I18nProvider>,
);
}

const reads = (id: 'lead' | 'account') => screen.getByTestId(id).textContent;
const flush = () => act(async () => { await new Promise((r) => setTimeout(r, 0)); });

afterEach(() => {
cleanup();
Object.defineProperty(window, 'innerWidth', { value: 1024, configurable: true, writable: true });
});

describe('the console shell hands a staged header arrangement to its grids (objectstack#36820)', () => {
it('an arrangement staged under the mode reaches the grid hook on the page, for its object only', async () => {
mountConsole();
expect(reads('lead')).toBe('none');
fireEvent.click(screen.getByText('enter'));
fireEvent.click(screen.getByText('stage'));
await flush();
expect(JSON.parse(reads('lead') ?? '')).toEqual(STAGED);
expect(reads('account')).toBe('none');
});

it('Cancel drops it: the grid hook reads none again', async () => {
mountConsole();
fireEvent.click(screen.getByText('enter'));
fireEvent.click(screen.getByText('stage'));
await flush();
expect(reads('lead')).not.toBe('none');
fireEvent.click(screen.getByText('cancel'));
await flush();
expect(reads('lead')).toBe('none');
});

it('control: outside the mode a stage writes nothing, and the grid hook reads none', async () => {
mountConsole();
fireEvent.click(screen.getByText('stage'));
await flush();
expect(reads('lead')).toBe('none');
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,8 @@ vi.mock('../../views/studio-design/packages-io', async (importOriginal) => ({

import { DesignModeProvider, useDesignMode, useDesignModeController } from '../designMode';
import { DesignModeBar } from '../DesignModeBar';
import { DesignModeHeaderPins, useObjectPins } from '../DesignModeHeaderPins';
import { DesignModeHeaderPins, DesignModeStagedPinsBridge, useObjectPins } from '../DesignModeHeaderPins';
import { useStagedActionLayout } from '@object-ui/plugin-grid/core';

const ACTIONS = [
{ name: 'convert', label: 'Convert', locations: ['record_page'], order: 1 },
Expand All @@ -78,10 +79,15 @@ function Harness({ objectDef }: { objectDef: Record<string, unknown> }) {
const mode = useDesignModeController({ appName: 'crm', appBasePath: '/apps/crm', enabled: true });
return (
<DesignModeProvider value={mode}>
{mode.active && <DesignModeBar mode={mode} />}
<Enter />
<HeaderReadout objectDef={objectDef} />
<DesignModeHeaderPins objectDef={objectDef} page="record" actions={ACTIONS} />
{/* Mounted as `ConsoleLayout` mounts it (objectstack#36820). */}
<DesignModeStagedPinsBridge changes={mode.changes}>
{mode.active && <DesignModeBar mode={mode} />}
<Enter />
<HeaderReadout objectDef={objectDef} />
<GridReadout name={String(objectDef.name)} />
<GridReadout name="crm_account" />
<DesignModeHeaderPins objectDef={objectDef} page="record" actions={ACTIONS} />
</DesignModeStagedPinsBridge>
</DesignModeProvider>
);
}
Expand All @@ -92,6 +98,12 @@ function HeaderReadout({ objectDef }: { objectDef: Record<string, unknown> }) {
return <output data-testid="header-pins">{JSON.stringify(pins)}</output>;
}

/** What a grid under the shell reads for `name` (objectstack#36820): the staged arrangement, or none. */
function GridReadout({ name }: { name: string }) {
const staged = useStagedActionLayout(name);
return <output data-testid={`grid-staged-${name}`}>{staged === undefined ? 'none' : JSON.stringify(staged)}</output>;
}

function Enter() {
const mode = useDesignMode();
return (
Expand Down Expand Up @@ -243,3 +255,32 @@ describe('「Header buttons」 under the design mode (objectstack#36366)', () =>
expect(screen.queryByTestId('design-header-pins-stale')).toBeNull();
});
});

describe('the row menus preview the staged arrangement too (objectstack#36820)', () => {
const gridReads = (name = 'crm_lead') => screen.getByTestId(`grid-staged-${name}`).textContent;

it('a staged change reaches the grids under the shell, for its object only, as the header draws it', async () => {
start({ ...SERVED, actionLayout: { record: { pinned: ['log_call'] } } });
expect(gridReads()).toBe('none');
await openPanel();
toggle('convert');
expect(gridReads()).toBe(screen.getByTestId('header-pins').textContent);
expect(JSON.parse(gridReads() ?? '')).toEqual({ record: { pinned: ['log_call', 'convert'], more: ['mark_won', 'clone'] } });
expect(gridReads('crm_account')).toBe('none');
});

it('「Cancel」 drops it: the grids read the object as served again', async () => {
start({ ...SERVED, actionLayout: { record: { pinned: ['log_call'] } } });
await openPanel();
toggle('convert');
expect(gridReads()).not.toBe('none');
fireEvent.click(screen.getByTestId('design-mode-cancel'));
await flush();
expect(gridReads()).toBe('none');
});

it('control: outside the mode nothing is staged, and the grids read the object as served', () => {
start({ ...SERVED, actionLayout: { record: { pinned: ['clone'] } } }, false);
expect(gridReads()).toBe('none');
});
});
Loading
Loading