diff --git a/.changeset/36112-sidebar-docking.md b/.changeset/36112-sidebar-docking.md new file mode 100644 index 00000000000..285f9c934e7 --- /dev/null +++ b/.changeset/36112-sidebar-docking.md @@ -0,0 +1,17 @@ +--- +'@object-ui/app-shell': patch +'@object-ui/i18n': patch +--- + +feat(console): the sidebar's docking model — 1280 px starts expanded, the expand/collapse button is the one control, and Recent lists this app's items + +Clause-②: no +Metadata-protocol: none + +- **Which state a window starts in.** From 768 px up, a browser with no choice kept starts with the sidebar expanded on a window 1280 px wide and up, and collapsed from 768 to 1279 px. The threshold was 1416 px, and below it the sidebar folded on its own. `CONSOLE_SIDEBAR_RAIL_BELOW_WIDTH` is now 1280 (one constant). +- **The reader's choice wins, on each side.** The sidebar's collapse button and, while it is collapsed, the page header's expand button are the one control, and this browser keeps each press: a wide-window choice and a narrow-window choice, kept apart as before. The expand button now docks the sidebar beside the page; before, it floated the menu over the page. Resting the pointer on the window's left edge and ⌘B still float the menu over a collapsed sidebar without changing the choice. Phone widths are unchanged, and the sidebar stays 256 px wide. +- **"Keep sidebar open" is gone.** Its stored choice (the workspace preference `console.sidebar.keepOpen`) is now the narrow-window choice, so a reader who kept the sidebar open starts expanded on a narrow window. Nothing to migrate. +- **Upgrade change.** On a 1280 to 1415 px window, a reader who never kept the sidebar open now starts with it expanded (it folded before), unless they collapsed it on a wide window. The accepted cost: on a 1280 px window with the sidebar expanded, the list beside an open record drawer is 304 px wide (560 before), and on 1280 to 1415 px, opening the record page's comment panel moves its fields back to the tab row; collapsing the sidebar gives the width back. +- **Recent is this app's.** From 768 px up, the sidebar's Recent group lists only the items opened in the current app. Home's "Recently accessed" and the phone drawer still list every app's. + +`@object-ui/i18n`: the `sidebar.keepOpen` key, which no surface reads any more, is dropped from all eleven packs (zh-Hant regenerated). diff --git a/docs/qa/platform-checklist/areas/platform-core.json b/docs/qa/platform-checklist/areas/platform-core.json index 38822ea39af..e9031e08b28 100644 --- a/docs/qa/platform-checklist/areas/platform-core.json +++ b/docs/qa/platform-checklist/areas/platform-core.json @@ -640,7 +640,7 @@ "title": "The built-in apps a stock boot REGISTERS (Setup / Account) render every merged-nav destination; app-level and entry-level gates are enforced, not errored — and Studio's deliberate absence is asserted, never hunted", "since": "v15", "status": "active", - "revision": 17, + "revision": 18, "priority": "P0", "surface": "browser", "personas": [ @@ -662,7 +662,7 @@ "steps": [ "as admin, GET /api/v1/meta/app?id=setup and extract every merged nav destination — Setup is a SHELL of empty group anchors (packages/platform-objects/src/apps/setup.app.ts: group_overview/apps/people_org/access_control/approvals/configuration/diagnostics/integrations/advanced) filled by SETUP_NAV_CONTRIBUTIONS (setup-nav.contributions.ts) plus capability-plugin contributions (plugin-security Positions/Permission Sets, plugin-sharing Sharing Rules/Record Shares, plugin-approvals, plugin-webhooks)", "GET /api/v1/meta/app with NO query first and record the names actually served — a stock boot answers exactly showcase_app, setup, account. Then GET /api/v1/meta/app?id=account (account.app.ts — Profile + Inbox/Security/Developer groups). ⚠️ GET /api/v1/meta/app?id=studio answers 200 {\"items\":[]} on every stock boot and that is the expected result (knownGap): record the absence as an assertion and move on — do NOT install @objectstack/studio to make the step runnable", - "as admin, hand-walk each destination in each app. At a window narrower than 1416 px (1280 px included) the console folds the sidebar, and Setup and Account open that way (ui/packages/app-shell/src/layout/consoleSidebarRail.ts CONSOLE_SIDEBAR_RAIL_BELOW_WIDTH, objectstack#27593; QA run #29877 met it at 1280 px). Folded, the sidebar is hidden, with no icon column (ruling 6973617688 on objectstack#35062): press the sidebar toggle at the app bar's left edge (Ctrl/⌘+B), or rest the pointer on the window's left edge, to float the full menu over the page before expanding any group. The float folds back after each chosen entry, so float it again for the next destination. EXPAND every nav group first: some render collapsed by default — Setup's Advanced group and Account's Developer group declare `expanded: false` (packages/platform-objects/src/apps/setup.app.ts, account.app.ts), and QA run #24557 found Setup's Configuration group collapsed as well — so a walk that never expands them never reaches their entries. Then navigate, wait for render, SCREENSHOT FIRST, then read the DOM — assert no pageerror, no 'failed to load', no blank
, no 'no actions configured' placeholder", + "as admin, hand-walk each destination in each app. At a window narrower than 1280 px a browser with no choice kept opens Setup and Account with the sidebar collapsed, and from 1280 px expanded (ui/packages/app-shell/src/layout/consoleSidebarRail.ts CONSOLE_SIDEBAR_RAIL_BELOW_WIDTH, ruling 7069868269 on objectstack#36112); a reader's own collapse or expand is kept per browser, on each side of that width. Collapsed, the sidebar is hidden, with no icon column (ruling 6973617688 on objectstack#35062): press the expand button at the page header's left edge to put it back beside the page before expanding any group — or press Ctrl/⌘+B, or rest the pointer on the window's left edge, to float the full menu over the page; the float folds back after each chosen entry, so float it again for the next destination. EXPAND every nav group first: some render collapsed by default — Setup's Advanced group and Account's Developer group declare `expanded: false` (packages/platform-objects/src/apps/setup.app.ts, account.app.ts), and QA run #24557 found Setup's Configuration group collapsed as well — so a walk that never expands them never reaches their entries. Then navigate, wait for render, SCREENSHOT FIRST, then read the DOM — assert no pageerror, no 'failed to load', no blank
, no 'no actions configured' placeholder", "Setup detail: confirm each settings URL entry (nav_settings_* → /apps/setup/system/settings/) opens the settings namespace form — the 11 namespaces of a stock single-posture boot, localization/company/branding/auth/access_policy/mail/sms/storage/ai/knowledge/lifecycle: the nav_settings_* entries of packages/platform-objects/src/apps/setup-nav.contributions.ts, plus nav_settings_branding, which packages/services/service-settings/src/settings-service-plugin.ts contributes only where no organization wall stands, and Users / Organization / Business Units / Teams / Sessions / OAuth Applications render. User preferences and identity links are not Setup destinations: open a user's record page, /_console/apps/setup/sys_user/record/ID (a row click on the Users list opens a side panel at ?recordId=, which is not that page: take the id from the row or the panel), and confirm the user page's Preferences and Linked Accounts tabs (packages/platform-objects/src/pages/sys-user.page.ts#SysUserDetailPage) render that user's rows", "Studio detail is NOT walked from here — the app is not registered on a stock boot (knownGap), so there is no merged nav to render. Its metadata:resource lists and component surfaces (App Builder, All Metadata Types, Packages, API Console, Flow Runs, Public Forms) are reached through the console surface at /_console/studio// and are covered by area studio-authoring. What THIS item asserts about Studio is the absence itself, per clause 6", "Account detail: confirm Profile (account:profile_card), Notifications (sys_inbox_message/mine), Approvals (nav_account_approvals, the approvals:inbox component, served as …/component/approvals/inbox — the Approvals Inbox, not the sys_approval_request grid; account.app.ts), Linked Accounts (sys_account), Active Sessions (sys_session/mine), API Keys (sys_api_key/mine), OAuth Applications (sys_oauth_application/mine) and Connect an Agent (nav_connect_agent) each render — 8 Account destinations and 47 Setup destinations for the admin on a stock single-org showcase boot, read from source after objectstack#34724 retired Setup › Packaged Actions (nav_packaged_actions; its switch moved onto the action in Studio); QA runs #32953 (at 5fb79bc0) and #33087 (at 8e3d4a54) read 48 before it (GET /api/v1/meta/app leaves, which match the nav source minus its gates). QA run #29877 read 46 at 589049b0, before Access policy (nav_settings_access_policy, the access_policy namespace) joined the Configuration group. Since QA run #28545's reading Setup's Packaged automation page retired under ADR-0146 D11, leaving Packaged Actions (nav_packaged_actions, automation:packaged-actions; #28785, itself retired by objectstack#34724), and its unfiltered Packages entry moved to Studio (#29547) (47 for #28927, 50 at eeec88d1 for QA run #28545, 48 re-measured at 3fd80337 for #28338, QA run #27481 read 44 and 8, QA run #24557 read 42 at 5b14b7f3, 45 on 2026-10-01, and #9453 recorded 43 and 7). Recount from the payload each run", @@ -822,6 +822,12 @@ "date": "2026-11-18", "change": "steps[2]: below 1416 px the fold now hides the sidebar instead of leaving its icon rail (ruling 6973617688 on #35062): the walk floats the full menu with the toggle (Ctrl/⌘+B) or by resting the pointer on the window's left edge, and floats it again after each chosen entry, since the float folds back on navigation. The walk is unchanged in substance. No clause changed. Read from source, and measured on a CRM boot (at 1280×800 the toggle floated the menu with focus on its entry; at 1600×900 choosing an entry in the float folded it); not yet re-run by a QA run.", "ref": "#35187" + }, + { + "revision": 18, + "date": "2026-11-22", + "change": "steps[2]: the threshold is 1280 px, not 1416 px, and it sets only where a browser with no choice kept starts — collapsed below it, expanded from it (ruling 7069868269 on #36112); the reader's own collapse or expand is kept per browser on each side, and the 'Keep sidebar open' switch is gone, so the walk docks the sidebar with the page header's expand button, or floats it with Ctrl/⌘+B or the window's left edge as before. The app bar named in revision 17 is gone from 768 px up (#36187). No clause changed. Read from source; not yet re-run by a QA run.", + "ref": "#36112" } ] }, diff --git a/examples/app-showcase/e2e/detail-shapes.spec.ts b/examples/app-showcase/e2e/detail-shapes.spec.ts index ba2fc5e7a5b..8e966126eae 100644 --- a/examples/app-showcase/e2e/detail-shapes.spec.ts +++ b/examples/app-showcase/e2e/detail-shapes.spec.ts @@ -178,30 +178,28 @@ test('related-heavy: body tables, the tab row and the rail on Contoso', async ({ // // The window and the sidebar are derived, not picked. A collapsed console // sidebar draws no icon rail from 768 px up — ruling 6973617688 on - // objectstack#35062: "Both collapsed states hide the sidebar completely: - // the manual collapse (`UnifiedSidebar` `collapsible="icon"`) and the - // automatic fold between 768 px and the record-drawer threshold (#27593, - // `consoleSidebarRail.ts`, below 1416 px). No icon column remains." So in a - // fresh browser context no desktop window stacks: measured on this harness, - // from a 768 px window (`MOBILE_BREAKPOINT`, the desktop shell) to 1415 px - // the sidebar folds hidden and the record view is the whole window (two - // columns at 768), and from 1416 px it is expanded and the view is at least - // 1160. The case therefore docks the sidebar the way a reader does — the - // app bar's trigger floats the menu and its "Keep sidebar open" keeps the - // 256 px sidebar beside the page — and the view is the window minus it: - // one column at 1015 px (759 of view), two at 1016 px (760), the same after - // a reload. So the docked stack tier is a window of 768 to 1015 px. 900 - // sits inside it with headroom on both sides: 644 px of view against the - // 760 floor, 132 px above the mobile breakpoint. ⛔ Not 780 px with the - // sidebar left as it comes up: that window now draws two columns (780 px of - // view). ⛔ Not below 768 px: that is the mobile shell, where the off-canvas - // sidebar gives the view the whole window (stack below 760), but where the - // details draw no Invoices body table (measured at 720 and 740 px). + // objectstack#35062: "Both collapsed states hide the sidebar completely" — + // and a browser with no choice kept starts it collapsed below 1280 px and + // expanded from 1280 px (ruling 7069868269 on objectstack#36112, + // `consoleSidebarRail.ts` CONSOLE_SIDEBAR_RAIL_BELOW_WIDTH). So in a fresh + // browser context no window below 1280 px stacks: the sidebar is hidden and + // the record view is the whole window (two columns at 768). The case + // therefore docks the sidebar the way a reader does — the page header's + // expand button puts the 256 px sidebar beside the page, and this browser + // keeps that choice — and the view is the window minus it: one column at + // 1015 px (759 of view), two at 1016 px (760). So the docked stack tier is + // a window of 768 to 1015 px. 900 sits inside it with headroom on both + // sides: 644 px of view against the 760 floor, 132 px above the mobile + // breakpoint. ⛔ Not 780 px with the sidebar left as it comes up: that + // window draws two columns (780 px of view). ⛔ Not below 768 px: that is + // the mobile shell, where the off-canvas sidebar gives the view the whole + // window (stack below 760), but where the details draw no Invoices body + // table (measured at 720 and 740 px). await page.setViewportSize({ width: 900, height: 800 }); const errors = await openRecord(page, recordUrl('showcase_account', contosoId)); - await page.locator('[data-sidebar="trigger"]').click(); - await page.getByTestId('sidebar-keep-open').click(); - await expect(page.getByTestId('sidebar-keep-open')).toHaveAttribute('aria-pressed', 'true'); + await page.getByTestId('shell-sidebar-expand').click(); + await expect(page.getByTestId('sidebar-collapse')).toBeVisible(); + await expect(page.getByTestId('shell-sidebar-expand')).toHaveCount(0); // objectstack#35891: no stage bar, no key-field strip; the heuristic stage // (account.status is a select named "status") is the header's tag. diff --git a/ui/packages/app-shell/src/hooks/__tests__/useResponsiveSidebar.test.tsx b/ui/packages/app-shell/src/hooks/__tests__/useResponsiveSidebar.test.tsx index 65ff8a2458c..64e85778223 100644 --- a/ui/packages/app-shell/src/hooks/__tests__/useResponsiveSidebar.test.tsx +++ b/ui/packages/app-shell/src/hooks/__tests__/useResponsiveSidebar.test.tsx @@ -1,12 +1,13 @@ // Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license. /** - * useResponsiveSidebar — the sidebar folds to its icon rail on a window - * narrower than `CONSOLE_SIDEBAR_RAIL_BELOW_WIDTH` and unfolds when it widens - * (objectstack#27593). The wide window's open state survives the fold, a - * reader's "keep open" turns the fold off, and the phone drawer is left alone. - * Only an open or close on a wide window is kept as the wide-window choice - * (objectstack#28079). + * useResponsiveSidebar — a window starts in the reader's choice for its side + * of `CONSOLE_SIDEBAR_RAIL_BELOW_WIDTH` (1280 px), else expanded on a wide + * window and collapsed on a narrow one (objectstack#27593, ruling 7069868269 + * on objectstack#36112). The two choices are kept apart: an open or close on a + * wide window is the wide-window choice (objectstack#28079), a close of the + * docked sidebar on a narrow window the narrow-window choice; the phone drawer + * is left alone. */ import '@testing-library/jest-dom/vitest'; @@ -15,10 +16,10 @@ import { SidebarProvider, useSidebar } from '@object-ui/components'; import { afterEach, beforeEach, describe, expect, it } from 'vitest'; import { useResponsiveSidebar } from '../useResponsiveSidebar'; import { - CONSOLE_SIDEBAR_KEEP_OPEN_PREFERENCE, + CONSOLE_SIDEBAR_NARROW_OPEN_PREFERENCE, readWideWindowOpen, } from '../../layout/consoleSidebarRail'; -import { writeWorkspacePreference } from '../../utils/workspacePreference'; +import { readWorkspacePreference, writeWorkspacePreference } from '../../utils/workspacePreference'; /** * Size the test window: happy-dom's own viewport, so `innerWidth`, the @@ -78,73 +79,76 @@ afterEach(() => { document.cookie = 'sidebar_state=; path=/; max-age=0'; }); -describe('useResponsiveSidebar (objectstack#27593)', () => { - it('folds the sidebar on a 1280 px window and leaves it open on a 1440 px one', () => { - renderAt(1280); +const narrowChoice = () => readWorkspacePreference(CONSOLE_SIDEBAR_NARROW_OPEN_PREFERENCE, 'user'); + +describe('useResponsiveSidebar (objectstack#27593, objectstack#36112)', () => { + it('starts collapsed on a 1279 px window and expanded on a 1280 px one', () => { + renderAt(1279); expect(openState()).toBe('false'); cleanup(); - renderAt(1440); + renderAt(1280); expect(openState()).toBe('true'); }); - it('keeps a manual expand on a narrow window (the rail expanded over the content)', () => { - renderAt(970); - expect(openState()).toBe('false'); - - fireEvent.click(screen.getByRole('button', { name: 'Expand sidebar' })); - expect(openState()).toBe('true'); + it('a state it gives a window is not a choice: nothing is kept until the reader toggles', () => { + renderAt(1440); + resizeTo(1024); + resizeTo(1440); + expect(readWideWindowOpen()).toBeUndefined(); + expect(narrowChoice()).toBeUndefined(); }); - it('hands the wide state back when the window widens, and folds again when it narrows', () => { + it('hands each side its own state as the window crosses the threshold', () => { renderAt(1440); expect(openState()).toBe('true'); - resizeTo(1280); + resizeTo(1279); expect(openState()).toBe('false'); - expect(readWideWindowOpen()).toBe(true); - resizeTo(1440); + resizeTo(1280); expect(openState()).toBe('true'); - expect(readWideWindowOpen()).toBe(true); }); - it('hands back a collapsed wide state as collapsed', () => { + it('keeps a collapse on a wide window, and gives it back when the window widens again', () => { renderAt(1440); fireEvent.click(screen.getByRole('button', { name: 'Toggle sidebar' })); expect(openState()).toBe('false'); + expect(readWideWindowOpen()).toBe(false); - resizeTo(1280); - // The reader expands the rail over the content on the narrow window… - fireEvent.click(screen.getByRole('button', { name: 'Expand sidebar' })); - expect(openState()).toBe('true'); - - // …and the wide window gets back the state the reader left it in. + resizeTo(1024); + expect(openState()).toBe('false'); resizeTo(1440); expect(openState()).toBe('false'); }); - it('a load that opens wide after a narrow one gets the wide state back, not the fold', () => { - renderAt(1280); - expect(openState()).toBe('false'); - cleanup(); - - // The primitive's cookie recorded the fold; the wide-window choice is kept apart. - renderAt(1440); + it('keeps a collapse of the docked sidebar on a narrow window as the narrow-window choice', () => { + writeWorkspacePreference(CONSOLE_SIDEBAR_NARROW_OPEN_PREFERENCE, 'user', 'on'); + renderAt(1024); expect(openState()).toBe('true'); - expect(readWideWindowOpen()).toBe(true); + + fireEvent.click(screen.getByRole('button', { name: 'Toggle sidebar' })); + expect(openState()).toBe('false'); + expect(narrowChoice()).toBe('off'); + // The wide-window choice is not touched. + expect(readWideWindowOpen()).toBeUndefined(); }); - it('"keep open" turns the fold off: a narrow window keeps the sidebar open', () => { - writeWorkspacePreference(CONSOLE_SIDEBAR_KEEP_OPEN_PREFERENCE, 'user', 'on'); - renderAt(1280); + it('a narrow-window choice turned collapsed elsewhere collapses an open sidebar', () => { + writeWorkspacePreference(CONSOLE_SIDEBAR_NARROW_OPEN_PREFERENCE, 'user', 'on'); + renderAt(1024); expect(openState()).toBe('true'); - expect(readWideWindowOpen()).toBeUndefined(); + + act(() => { + writeWorkspacePreference(CONSOLE_SIDEBAR_NARROW_OPEN_PREFERENCE, 'user', 'off'); + }); + expect(openState()).toBe('false'); }); it('leaves the open state alone below the phone breakpoint, where the drawer takes over', () => { renderAt(700); expect(openState()).toBe('true'); expect(readWideWindowOpen()).toBeUndefined(); + expect(narrowChoice()).toBeUndefined(); }); }); diff --git a/ui/packages/app-shell/src/hooks/useResponsiveSidebar.ts b/ui/packages/app-shell/src/hooks/useResponsiveSidebar.ts index e6776537b4a..c73fd4d8958 100644 --- a/ui/packages/app-shell/src/hooks/useResponsiveSidebar.ts +++ b/ui/packages/app-shell/src/hooks/useResponsiveSidebar.ts @@ -1,37 +1,37 @@ /** * useResponsiveSidebar * - * Folds the sidebar while the window is narrower than - * `CONSOLE_SIDEBAR_RAIL_BELOW_WIDTH` (and wider than the phone breakpoint, - * where the drawer takes over), and unfolds it when the window widens again - * (objectstack#27593). Folded, the console's sidebar is hidden, and its full - * menu floats over the content from the window's left edge or the app bar's - * trigger (ruling 6973617688 on objectstack#35062; `consoleSidebarRail.ts`). - * A reader who keeps the sidebar open is left alone. Must be called inside a - * SidebarProvider context. + * Gives the console sidebar the state a window starts in, as the page loads + * and as the window crosses `CONSOLE_SIDEBAR_RAIL_BELOW_WIDTH` (1280 px) or + * the phone breakpoint, where the drawer takes over: the reader's choice for + * that side of the threshold, else expanded on a wide window and collapsed on + * a narrow one (ruling 7069868269 on objectstack#36112). Collapsed, the + * console's sidebar is hidden, and its full menu floats over the content from + * the window's left edge or ⌘B (ruling 6973617688 on objectstack#35062; + * `consoleSidebarRail.ts`). Must be called inside a SidebarProvider context. * - * The fold is not the reader's choice, so it does not keep one: every open - * and close on a wide window is kept as the wide-window choice, and only - * those (objectstack#28079). A window that turns wide, or a load that opens - * wide, gets that choice back, whatever the fold, the float or a sidebar - * kept open on a narrow window did to the primitive's cookie meanwhile. + * It also keeps the reader's choices, each on its own side of the threshold: + * an open or close on a wide window is the wide-window choice + * (objectstack#28079), a close of the docked sidebar on a narrow window the + * narrow-window choice (the page header's expand button keeps the other + * half, `useConsoleSidebarRailPanel`). The float writes neither, and a state + * this hook gives a window is not a choice. * @module */ import { useLayoutEffect, useRef } from 'react'; import { useSidebar } from '@object-ui/components'; import { - readWideWindowOpen, - seedWideWindowOpen, + startingSidebarOpen, useConsoleSidebarRail, writeWideWindowOpen, } from '../layout/consoleSidebarRail.js'; export function useResponsiveSidebar() { const { open, setOpen } = useSidebar(); - const { wide, railMode } = useConsoleSidebarRail(); + const { desktop, wide, railMode, setNarrowOpen } = useConsoleSidebarRail(); const setOpenRef = useRef(setOpen); - const last = useRef<{ wide: boolean; railMode: boolean } | null>(null); + const last = useRef<{ desktop: boolean; wide: boolean; railMode: boolean; open: boolean } | null>(null); useLayoutEffect(() => { setOpenRef.current = setOpen; @@ -40,23 +40,25 @@ export function useResponsiveSidebar() { // A layout effect, so a window that opens narrow paints the hidden sidebar first. useLayoutEffect(() => { const previous = last.current; - last.current = { wide, railMode }; + last.current = { desktop, wide, railMode, open }; + if (!desktop) return; + // A load, or a window that crosses the threshold or leaves the phone: its starting state. + if (!previous || !previous.desktop || previous.wide !== wide) { + const start = startingSidebarOpen(wide); + last.current.open = start; + if (start !== open) setOpenRef.current(start); + return; + } if (wide) { - // A load that opens wide, or a window that turns wide: the reader's wide-window choice. - if (!previous?.wide) { - const wideOpen = readWideWindowOpen(); - if (wideOpen !== undefined && wideOpen !== open) { - setOpenRef.current(wideOpen); - return; - } - } - writeWideWindowOpen(open); + if (previous.open !== open) writeWideWindowOpen(open); return; } - // The fold takes over: a narrow load, a window that narrows, "keep open" turned off. - if (railMode && !previous?.railMode) { - seedWideWindowOpen(open); - setOpenRef.current(false); + // The narrow-window choice turned collapsed (in this tab or another) under an open sidebar. + if (railMode && !previous.railMode) { + if (open) setOpenRef.current(false); + return; } - }, [wide, railMode, open]); + // The reader collapsed the docked sidebar on a narrow window. + if (!railMode && previous.open && !open) setNarrowOpen(false); + }, [desktop, wide, railMode, open, setNarrowOpen]); } diff --git a/ui/packages/app-shell/src/layout/UnifiedSidebar.tsx b/ui/packages/app-shell/src/layout/UnifiedSidebar.tsx index 2ce69f7c464..2a546ffc5bc 100644 --- a/ui/packages/app-shell/src/layout/UnifiedSidebar.tsx +++ b/ui/packages/app-shell/src/layout/UnifiedSidebar.tsx @@ -39,7 +39,6 @@ import { ChevronRight, LayoutGrid, Layers, - Pin, Search, } from 'lucide-react'; import { NavigationRenderer, hasVisibleNavigationItems, type NavItemActionContext } from '@object-ui/layout'; @@ -56,6 +55,7 @@ import { useNavTargetColor, useNavTargetIcon } from '../hooks/useNavTargetIcon.j import { ContentItemTile, favoriteItemObject } from './contentItemTile.js'; import { recentItemObject } from '../console/home/recentItemTypeLabel.js'; import { readRecentObjects } from '../console/home/readRecentObjects.js'; +import { appSegmentOf } from '../console/home/appLastOpened.js'; import { useNavDocTargetCheck } from '../hooks/useNavDocTargetCheck.js'; import { useNavMemberGates } from '../hooks/useNavMemberGates.js'; import { matchAppBySegment } from '../utils/index.js'; @@ -200,12 +200,12 @@ export function UnifiedSidebar({ activeAppName, onAppChange, railOverlay = false const resolveNavTargetIcon = useNavTargetIcon(); const resolveNavTargetColor = useNavTargetColor(); // Collapsed, the console's sidebar is hidden and its menu floats over the - // content (objectstack#35062); below the fold width it collapses on its own - // (objectstack#27593), and `useResponsiveSidebar` folds and unfolds it. + // content (objectstack#35062); a window starts in the reader's choice for + // its side of the threshold, else expanded from 1280 px and collapsed below + // (objectstack#36112), and `useResponsiveSidebar` gives it that state. const rail = useConsoleSidebarRail({ enabled: railOverlay }); const sidebarRef = React.useRef(null); const railPanel = useConsoleSidebarRailPanel(rail, sidebarRef); - const keepOpenLabel = t('sidebar.keepOpen', { defaultValue: 'Keep sidebar open' }); // objectstack#36112 — from 768 px up the console draws no top bar: the // sidebar starts at the top of the window and carries the app menu, the // search and the bell in its head, and the account at its foot. @@ -249,10 +249,6 @@ export function UnifiedSidebar({ activeAppName, onAppChange, railOverlay = false }, [routeKey, isMobile, setOpenMobile]); const { recentItems: allRecentItems } = useRecentItems(); - // A Studio package entry is labelled from the package list (objectui#11863), - // which this sidebar does not load, so it is left out here rather than drawn - // as its id. The Studio landing lists the recent packages. - const recentItems = allRecentItems.filter(item => item.type !== 'package'); // A recent entry's text is the item's own, resolved on this render // (objectui#11678); the entry stores identity only. const recentLabel = useRecentItemLabel(); @@ -268,7 +264,19 @@ export function UnifiedSidebar({ activeAppName, onAppChange, railOverlay = false // direct navigation to /apps/account still renders. const activeApps = apps.filter((a: any) => a.active !== false && a.hidden !== true); // ADR-0048 (A) — route segment may be a package id; match by it (name fallback). - const activeApp = matchAppBySegment(apps.filter((a: any) => a.active !== false), activeAppName || currentAppName) || activeApps[0]; + const enabledApps = apps.filter((a: any) => a.active !== false); + const activeApp = matchAppBySegment(enabledApps, activeAppName || currentAppName) || activeApps[0]; + // A Studio package entry is labelled from the package list (objectui#11863), + // which this sidebar does not load, so it is left out here rather than drawn + // as its id. The Studio landing lists the recent packages. From 768 px up + // the list is this app's own (objectstack#36112, 「这个应用里的最近使用」): + // an entry was opened in the app its address names, resolved as the router + // resolves it; Home lists every app's. The phone drawer is unchanged. + const recentItems = allRecentItems.filter( + (item) => + item.type !== 'package' && + (isMobile || (!!activeApp && matchAppBySegment(enabledApps, appSegmentOf(item.href)) === activeApp)), + ); // `type: 'action'` nav items dispatch through here (framework#4509). The // sidebar renders inside ConsoleShell's GlobalActionRuntimeProvider, so this // resolves to the fully-wired console runner — confirm/param/result dialogs @@ -910,29 +918,9 @@ export function UnifiedSidebar({ activeAppName, onAppChange, railOverlay = false )} - {/* "Keep sidebar open": in the floated menu it puts the sidebar back - beside the content and keeps it there (on the fold, for this - browser); in a sidebar kept open on a narrow window it is pressed, - and turns the fold back on (objectstack#35062). */} - {(railPanel.keepOpenControl || shellChrome) && ( + {shellChrome && ( - {railPanel.keepOpenControl && ( - - - - - {keepOpenLabel} - - - - )} - {shellChrome && } + )} {/* No footer trigger: from 768 px up the trigger is the head's collapse diff --git a/ui/packages/app-shell/src/layout/__tests__/ConsoleLayout.sidebarFirstFrame-28077.test.tsx b/ui/packages/app-shell/src/layout/__tests__/ConsoleLayout.sidebarFirstFrame-28077.test.tsx index e8a7bb60da8..de0d3c6d602 100644 --- a/ui/packages/app-shell/src/layout/__tests__/ConsoleLayout.sidebarFirstFrame-28077.test.tsx +++ b/ui/packages/app-shell/src/layout/__tests__/ConsoleLayout.sidebarFirstFrame-28077.test.tsx @@ -1,8 +1,10 @@ // Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license. /** - * ConsoleLayout — on a window below the fold width the console sidebar's - * first frame is already the icon rail (objectstack#28077). + * ConsoleLayout — the console sidebar's first frame is already the state the + * window starts in (objectstack#28077): collapsed (hidden) below 1280 px and + * expanded from it, unless the reader's own choice for that side says + * otherwise (objectstack#36112). * * The sidebar provider takes its first open state from the `sidebar_state` * cookie the last page wrote. Before, a narrow window drew that state (the @@ -10,9 +12,11 @@ * transition in between. The probe stands in for the sidebar and records the * state of every render, the first one included. * - * Three ways in, all at 1280 px: a first visit (no cookie), a load after the - * sidebar was expanded on a wide window, and a reload while the overlay was - * shown (both leave the cookie expanded). At 1440 px nothing changes. + * Three ways in, all at 1279 px: a first visit (no cookie), a load after the + * sidebar was expanded on a wide window, and a reload while the float was + * shown (both leave the cookie expanded). From 1280 px the first frame is + * expanded, a collapsed cookie notwithstanding, unless the reader collapsed it + * there. */ import '@testing-library/jest-dom/vitest'; @@ -22,6 +26,9 @@ import { cleanup, render } from '@testing-library/react'; import { MemoryRouter } from 'react-router-dom'; import { createI18n, I18nProvider } from '@object-ui/i18n'; import { useSidebar } from '@object-ui/components'; +// Clocked windows measure behaviour, never loading (`check:test-source-alias`): the layout reaches +// `@objectstack/lint` through the draft preview bar's dynamic import, so its first load is paid here. +import '@objectstack/lint'; const renders: string[] = []; @@ -41,7 +48,7 @@ vi.mock('../../preview/UnpublishedAppBar', () => ({ UnpublishedAppBar: () => nul import { ConsoleLayout } from '../ConsoleLayout'; import { NavigationProvider } from '../../context/NavigationContext'; -import { CONSOLE_SIDEBAR_KEEP_OPEN_PREFERENCE } from '../consoleSidebarRail'; +import { CONSOLE_SIDEBAR_NARROW_OPEN_PREFERENCE, writeWideWindowOpen } from '../consoleSidebarRail'; import { writeWorkspacePreference } from '../../utils/workspacePreference'; const APP = { name: 'crm', label: 'CRM', active: true, navigation: [] }; @@ -85,39 +92,47 @@ afterEach(() => { clearCookie(); }); -describe('the narrow window’s first frame is the rail (objectstack#28077)', () => { - it('a first visit at 1280 px: every render, the first included, is the rail', () => { - load(1280); +describe('the first frame is the state the window starts in (objectstack#28077, objectstack#36112)', () => { + it('a first visit at 1279 px: every render, the first included, is collapsed', () => { + load(1279); expect(renders[0]).toBe('collapsed'); expect(new Set(renders)).toEqual(new Set(['collapsed'])); }); - it('a 1280 px load after the sidebar was expanded on a wide window', () => { + it('a 1279 px load after the sidebar was expanded on a wide window', () => { load(1440); expect(renders.at(-1)).toBe('expanded'); cleanup(); - load(1280); + load(1279); expect(renders[0]).toBe('collapsed'); expect(new Set(renders)).toEqual(new Set(['collapsed'])); }); - it('a 1280 px reload while the overlay was shown (the cookie says expanded)', () => { + it('a 1279 px reload while the float was shown (the cookie says expanded)', () => { document.cookie = 'sidebar_state=true; path=/'; - load(1280); + load(1279); expect(renders[0]).toBe('collapsed'); expect(new Set(renders)).toEqual(new Set(['collapsed'])); }); - it('at 1440 px nothing changes: expanded from the first render', () => { - load(1440); + it('a first visit at 1280 px is expanded from the first render, whatever the cookie says', () => { + document.cookie = 'sidebar_state=false; path=/'; + load(1280); expect(new Set(renders)).toEqual(new Set(['expanded'])); }); - it('a sidebar kept open on a narrow window keeps the state it had', () => { - writeWorkspacePreference(CONSOLE_SIDEBAR_KEEP_OPEN_PREFERENCE, 'user', 'on'); + it('a 1280 px load after the reader collapsed it on a wide window is collapsed from the first render', () => { + writeWideWindowOpen(false); document.cookie = 'sidebar_state=true; path=/'; load(1280); + expect(new Set(renders)).toEqual(new Set(['collapsed'])); + }); + + it('a 1279 px load after the reader expanded it on a narrow window is expanded from the first render', () => { + writeWorkspacePreference(CONSOLE_SIDEBAR_NARROW_OPEN_PREFERENCE, 'user', 'on'); + document.cookie = 'sidebar_state=false; path=/'; + load(1279); expect(new Set(renders)).toEqual(new Set(['expanded'])); }); }); diff --git a/ui/packages/app-shell/src/layout/__tests__/UnifiedSidebar.hiddenCollapse-35062.test.tsx b/ui/packages/app-shell/src/layout/__tests__/UnifiedSidebar.hiddenCollapse-35062.test.tsx index 5a185f3e93d..476bc320c47 100644 --- a/ui/packages/app-shell/src/layout/__tests__/UnifiedSidebar.hiddenCollapse-35062.test.tsx +++ b/ui/packages/app-shell/src/layout/__tests__/UnifiedSidebar.hiddenCollapse-35062.test.tsx @@ -5,27 +5,22 @@ * its full menu floats over the content (objectstack#35062, ruling 6973617688: * one collapsed look at 768 px and up). * - * - Collapsed by hand on a wide window, and folded on its own on a narrow one, - * the sidebar takes no width and leaves no icon column; nothing in it is - * reachable. + * - Collapsed by hand on a wide window, and collapsed by default on a narrow + * one (below 1280 px, objectstack#36112), the sidebar takes no width and + * leaves no icon column; nothing in it is reachable. * - Resting the pointer on the window's left edge floats the full menu, its * labels and groups, after the hover delay; moving away folds it back. A * press on the edge floats it at once. Neither changes the collapsed state, * which a reload keeps. - * - The app bar's trigger and ⌘B float the menu and move focus into it, on a - * sidebar the reader collapsed as on the fold; Esc folds it and gives focus - * back to the trigger. "Keep sidebar open", at the foot of the floated menu, - * puts the sidebar back beside the content, and a reload keeps it there; - * chosen from the keyboard, focus stays in the menu, and turning it off on - * the fold gives focus to the trigger. + * - ⌘B floats the menu and moves focus into it, on either window; Esc folds it + * and gives focus back where it was. + * - The page header's expand button (a sidebar trigger) docks the sidebar + * beside the content as the reader's choice, on either window, and a reload + * keeps it there (ruling 7069868269 on objectstack#36112): there is no + * "Keep sidebar open" control. * - Choosing an entry navigates, folds the menu and leaves the sidebar * collapsed. - * - "Keep sidebar open" still turns the fold off; the edge is drawn only while - * the sidebar is hidden, never on a phone. - * - * Ruling 6973617688 names the trigger beside the edge with no carve-out for a - * hand collapse; the area seat's order of 2026-11-18 on PR #35187 applies it to - * both collapsed states. + * - The edge is drawn only while the sidebar is hidden, never on a phone. * * The test DOM computes no Tailwind and no layout, so widths are read as the * class that sets them; the rendered widths are measured in a browser on the @@ -111,7 +106,7 @@ import { SidebarProvider, useSidebar } from '@object-ui/components'; import { UnifiedSidebar } from '../UnifiedSidebar'; import { useResponsiveSidebar } from '../../hooks/useResponsiveSidebar'; import { - CONSOLE_SIDEBAR_KEEP_OPEN_PREFERENCE, + CONSOLE_SIDEBAR_NARROW_OPEN_PREFERENCE, RAIL_OVERLAY_FRAME_NO_GAP, SIDEBAR_EDGE_ZONE, SIDEBAR_FLOAT_CLOSE_DELAY_MS, @@ -119,7 +114,7 @@ import { primeConsoleSidebarOpen, readWideWindowOpen, } from '../consoleSidebarRail'; -import { writeWorkspacePreference } from '../../utils/workspacePreference'; +import { readWorkspacePreference, writeWorkspacePreference } from '../../utils/workspacePreference'; /** * Size the test window: happy-dom's own viewport, so `innerWidth`, the @@ -138,7 +133,7 @@ function Fold() { return null; } -/** The app bar's trigger, reduced to what the sidebar reads: `data-sidebar="trigger"` and the toggle. */ +/** The page header's expand button, reduced to what the sidebar reads: `data-sidebar="trigger"` and the toggle. */ function Trigger() { const { toggleSidebar } = useSidebar(); return ( @@ -233,6 +228,9 @@ const frame = () => screen.getByTestId('console-sidebar-frame'); const edge = () => screen.queryByTestId('console-sidebar-edge'); const trigger = () => within(screen.getByTestId('app-bar')).getByRole('button', { name: 'Toggle sidebar' }); const keepOpen = () => screen.queryByTestId('sidebar-keep-open'); +const narrowChoice = () => readWorkspacePreference(CONSOLE_SIDEBAR_NARROW_OPEN_PREFERENCE, 'user'); +/** ⌘B, which the provider's listener answers on the window. */ +const commandB = () => fireEvent.keyDown(window, { key: 'b', metaKey: true }); const tokens = (el: Element) => el.className.split(/\s+/).filter(Boolean); const sidebarCookie = () => /(?:^|;\s*)sidebar_state=(\w+)/.exec(document.cookie)?.[1]; @@ -250,6 +248,14 @@ function expectHidden() { expect(edge()).not.toBeNull(); } +/** Docked beside the content: expanded, no float, no edge. */ +function expectDocked() { + expect(sidebarRoot()).toHaveAttribute('data-state', 'expanded'); + expect(panel()).not.toHaveAttribute('data-console-rail'); + expect(tokens(frame())).toEqual(['contents']); + expect(edge()).toBeNull(); +} + /** The full menu floats over the content: expanded, above the page, the gap still at no width. */ function expectFloat() { expect(sidebarRoot()).toHaveAttribute('data-state', 'expanded'); @@ -280,45 +286,41 @@ afterEach(() => { }); describe('a collapsed console sidebar is hidden, with no icon column (objectstack#35062)', () => { - it('collapsed by hand at 1600 px it takes no width and nothing in it is reachable; the trigger floats it, and "Keep sidebar open" docks it again, after a reload too', () => { + it('collapsed by hand at 1600 px it takes no width and nothing in it is reachable; ⌘B floats it, the expand button docks it again, after a reload too', () => { renderShell(1600); - expect(sidebarRoot()).toHaveAttribute('data-state', 'expanded'); - expect(edge(), 'no edge beside an expanded sidebar').toBeNull(); - expect(keepOpen(), 'no "Keep sidebar open" beside an expanded wide sidebar').toBeNull(); + expectDocked(); + expect(keepOpen(), 'no "Keep sidebar open" (objectstack#36112)').toBeNull(); fireEvent.click(trigger()); expectHidden(); expect(readWideWindowOpen()).toBe(false); - // The trigger floats the menu on a hand collapse too, and changes nothing the reader chose. - fireEvent.click(trigger()); + // ⌘B floats the menu on a hand collapse, and changes nothing the reader chose. + commandB(); expectFloat(); + expect(keepOpen()).toBeNull(); expect(readWideWindowOpen()).toBe(false); expect(sidebarCookie()).toBe('false'); + commandB(); + expectHidden(); - // The way back beside the content: "Keep sidebar open", at the foot of the float. - expect(keepOpen()).toHaveAttribute('aria-pressed', 'false'); - fireEvent.click(keepOpen()!); - expect(sidebarRoot()).toHaveAttribute('data-state', 'expanded'); - expect(panel()).not.toHaveAttribute('data-console-rail'); - expect(tokens(frame())).toEqual(['contents']); - expect(edge()).toBeNull(); - expect(keepOpen()).toBeNull(); + // The way back beside the content: the expand button. + fireEvent.click(trigger()); + expectDocked(); expect(readWideWindowOpen()).toBe(true); expect(sidebarCookie()).toBe('true'); reload(1600); - expect(sidebarRoot()).toHaveAttribute('data-state', 'expanded'); - expect(panel()).not.toHaveAttribute('data-console-rail'); + expectDocked(); }); - it('folded on its own at 1280 px it is hidden the same way', () => { - renderShell(1280); + it('collapsed by default at 1024 px it is hidden the same way', () => { + renderShell(1024); expectHidden(); }); it('the edge is a strip at the window’s left edge, its full height (no top bar above it, objectstack#36112)', () => { - renderShell(1280); + renderShell(1024); for (const token of SIDEBAR_EDGE_ZONE.split(' ')) expect(tokens(edge()!)).toContain(token); expect(tokens(edge()!)).toEqual(expect.arrayContaining(['top-0', 'h-svh'])); expect(tokens(edge()!)).not.toContain('!top-12'); @@ -333,47 +335,35 @@ describe('a collapsed console sidebar is hidden, with no icon column (objectstac expect(edge()).toBeNull(); }); - it('"Keep sidebar open" still turns the fold off at 1280 px', () => { - writeWorkspacePreference(CONSOLE_SIDEBAR_KEEP_OPEN_PREFERENCE, 'user', 'on'); - renderShell(1280); - expect(sidebarRoot()).toHaveAttribute('data-state', 'expanded'); - expect(panel()).not.toHaveAttribute('data-console-rail'); - expect(edge()).toBeNull(); - // Collapsed there by hand, it is hidden like any other collapse. - fireEvent.click(trigger()); + it('at 1024 px the expand button docks the sidebar as the narrow-window choice, after a reload too; the collapse button takes it back', () => { + renderShell(1024); expectHidden(); - // The trigger floats it; "Keep sidebar open" docks it, and a reload keeps it docked. fireEvent.click(trigger()); - expectFloat(); - expect(keepOpen()).toHaveAttribute('aria-pressed', 'false'); - fireEvent.click(keepOpen()!); - expect(sidebarRoot()).toHaveAttribute('data-state', 'expanded'); - expect(panel()).not.toHaveAttribute('data-console-rail'); - expect(keepOpen()).toHaveAttribute('aria-pressed', 'true'); - reload(1280); - expect(sidebarRoot()).toHaveAttribute('data-state', 'expanded'); - expect(panel()).not.toHaveAttribute('data-console-rail'); - }); + expectDocked(); + expect(narrowChoice()).toBe('on'); + expect(readWideWindowOpen(), 'the wide-window choice is not touched').toBeUndefined(); + reload(1024); + expectDocked(); - it('"Keep sidebar open" in the fold\'s float docks the sidebar and turns the fold off, after a reload too', () => { - renderShell(1280); + // The sidebar's own collapse button (a trigger too) collapses it, and that is kept. fireEvent.click(trigger()); - expectFloat(); - expect(sidebarCookie(), 'the float is not the reader’s state').toBe('false'); - fireEvent.click(keepOpen()!); - expect(sidebarRoot()).toHaveAttribute('data-state', 'expanded'); - expect(panel()).not.toHaveAttribute('data-console-rail'); - expect(keepOpen()).toHaveAttribute('aria-pressed', 'true'); - reload(1280); - expect(sidebarRoot()).toHaveAttribute('data-state', 'expanded'); - expect(panel()).not.toHaveAttribute('data-console-rail'); + expectHidden(); + expect(narrowChoice()).toBe('off'); + reload(1024); + expectHidden(); + }); + + it('a stored "keep open" from before reads as expanded on a narrow window', () => { + writeWorkspacePreference(CONSOLE_SIDEBAR_NARROW_OPEN_PREFERENCE, 'user', 'on'); + renderShell(1024); + expectDocked(); }); }); describe('the left edge floats the full menu over the content (objectstack#35062)', () => { it('after the hover delay, with its labels and groups; moving away folds it back', () => { vi.useFakeTimers(); - renderShell(1280); + renderShell(1024); hoverEdge(SIDEBAR_FLOAT_OPEN_DELAY_MS - 1); expectHidden(); act(() => { @@ -409,7 +399,7 @@ describe('the left edge floats the full menu over the content (objectstack#35062 it('a pointer that leaves the edge before the delay floats nothing', () => { vi.useFakeTimers(); - renderShell(1280); + renderShell(1024); hoverEdge(SIDEBAR_FLOAT_OPEN_DELAY_MS / 2); fireEvent.pointerLeave(edge()!, { pointerType: 'mouse' }); act(() => { @@ -420,7 +410,7 @@ describe('the left edge floats the full menu over the content (objectstack#35062 it('a press on the edge floats it at once, and it stays until a press outside', () => { vi.useFakeTimers(); - renderShell(1280); + renderShell(1024); fireEvent.click(edge()!); expectFloat(); fireEvent.pointerMove(screen.getByText('The page'), { pointerType: 'mouse' }); @@ -465,42 +455,42 @@ describe('the left edge floats the full menu over the content (objectstack#35062 expectHidden(); }); - it('a window that turns wide or narrow ends a float over a sidebar collapsed by hand, and it stays collapsed', () => { - writeWorkspacePreference(CONSOLE_SIDEBAR_KEEP_OPEN_PREFERENCE, 'user', 'on'); - renderShell(1280); + it('a window that turns narrow or wide ends a float over a sidebar collapsed by hand, and it stays collapsed', () => { + renderShell(1600); fireEvent.click(trigger()); fireEvent.click(edge()!); expectFloat(); - // Wide, with no wide-window choice kept yet: the float is not one. - resizeTo(1600); + // Narrow, with no narrow-window choice kept: collapsed, and the float is not one. + resizeTo(1024); expectHidden(); - expect(readWideWindowOpen()).toBe(false); + expect(narrowChoice()).toBeUndefined(); fireEvent.click(edge()!); expectFloat(); - // Narrow and kept open: the fold stays off, and so does the float. - resizeTo(1280); + // Wide again: the reader's wide-window choice, collapsed. + resizeTo(1600); expectHidden(); + expect(readWideWindowOpen()).toBe(false); }); - it('a window that narrows past the fold width under a float folds the sidebar, hidden', () => { + it('a window that narrows past the threshold under a float collapses the sidebar, hidden', () => { renderShell(1600); fireEvent.click(trigger()); fireEvent.click(edge()!); expectFloat(); - resizeTo(1280); + resizeTo(1279); expectHidden(); expect(readWideWindowOpen()).toBe(false); }); }); -describe('the trigger floats the collapsed menu, and the keyboard walks it (objectstack#35062)', () => { - it('collapsed by hand at 1600 px, the trigger floats it and moves focus in; Esc folds it and focus goes back to the trigger', () => { +describe('⌘B floats the collapsed menu, the expand button docks it, and the keyboard walks it (objectstack#35062, objectstack#36112)', () => { + it('collapsed by hand at 1600 px, ⌘B floats it and moves focus in; Esc folds it and focus goes back to the trigger', () => { renderShell(1600); fireEvent.click(trigger()); expectHidden(); act(() => trigger().focus()); - fireEvent.click(trigger()); + commandB(); expectFloat(); expect(panel(), 'focus moves into the floated menu').toContainElement(document.activeElement as HTMLElement); @@ -510,37 +500,11 @@ describe('the trigger floats the collapsed menu, and the keyboard walks it (obje expect(readWideWindowOpen()).toBe(false); }); - it('collapsed by hand at 1600 px, "Keep sidebar open" chosen from the keyboard docks it, and focus stays in the menu', () => { - renderShell(1600); - fireEvent.click(trigger()); - act(() => trigger().focus()); - fireEvent.click(trigger()); - expectFloat(); - act(() => keepOpen()!.focus()); - fireEvent.click(keepOpen()!); - expect(panel()).not.toHaveAttribute('data-console-rail'); - expect(keepOpen(), 'the control goes with the float').toBeNull(); - expect(panel(), 'focus stays in the docked menu').toContainElement(document.activeElement as HTMLElement); - }); - - it('at 1280 px, "Keep sidebar open" turned off from the keyboard folds it, and focus goes to the trigger', () => { - renderShell(1280); - fireEvent.click(trigger()); - fireEvent.click(keepOpen()!); - expect(keepOpen()).toHaveAttribute('aria-pressed', 'true'); - act(() => keepOpen()!.focus()); - fireEvent.click(keepOpen()!); - expectHidden(); - expect(keepOpen(), 'the control goes with the sidebar').toBeNull(); - expect(document.activeElement, 'focus goes to the trigger').toBe(trigger()); - }); - - it('collapsed by hand, the trigger floats it even when React renders between the capture phase and the trigger’s own click handler', () => { - renderShell(1600); - fireEvent.click(trigger()); + it('at 1024 px, the expand button docks it even when React renders between the capture phase and the trigger’s own click handler', () => { + renderShell(1024); expectHidden(); // A browser runs a microtask checkpoint after each listener, so React may - // render the capture phase's note before the trigger's own handler runs. + // render the capture phase's choice before the trigger's own handler runs. // Here the click stops after the capture phase and renders (act), and the // provider's toggle comes after, on its own. const stopAfterCapture = (event: Event) => event.stopPropagation(); @@ -551,47 +515,50 @@ describe('the trigger floats the collapsed menu, and the keyboard walks it (obje document.body.removeEventListener('click', stopAfterCapture, true); } expectHidden(); + expect(narrowChoice()).toBe('on'); fireEvent.click(screen.getByTestId('provider-toggle')); - expectFloat(); - expect(readWideWindowOpen()).toBe(false); + expectDocked(); + expect(narrowChoice()).toBe('on'); }); it('collapsed by hand at 1600 px, ⌘B floats it and folds it again', () => { renderShell(1600); - fireEvent.keyDown(window, { key: 'b', metaKey: true }); + commandB(); expectHidden(); - fireEvent.keyDown(window, { key: 'b', metaKey: true }); + commandB(); expectFloat(); expect(sidebarCookie()).toBe('false'); - fireEvent.keyDown(window, { key: 'b', metaKey: true }); + commandB(); expectHidden(); expect(readWideWindowOpen()).toBe(false); }); - it('at 1280 px the trigger floats it and moves focus in; Esc folds it and focus goes back to the trigger', () => { - renderShell(1280); + it('at 1024 px ⌘B floats it and moves focus in; Esc folds it and focus goes back to the trigger', () => { + renderShell(1024); act(() => trigger().focus()); - fireEvent.click(trigger()); + commandB(); expectFloat(); expect(panel(), 'focus moves into the floated menu').toContainElement(document.activeElement as HTMLElement); + expect(narrowChoice(), 'the float is not the reader’s choice').toBeUndefined(); fireEvent.keyDown(document.activeElement!, { key: 'Escape' }); expectHidden(); expect(document.activeElement, 'focus goes back to the trigger').toBe(trigger()); }); - it('⌘B floats it too', () => { - renderShell(1280); - fireEvent.keyDown(window, { key: 'b', metaKey: true }); + it('at 1024 px ⌘B floats it and folds it again', () => { + renderShell(1024); + commandB(); expectFloat(); - fireEvent.keyDown(window, { key: 'b', metaKey: true }); + commandB(); expectHidden(); + expect(narrowChoice()).toBeUndefined(); }); it('an entry chosen from the keyboard navigates, folds it, and gives focus back to the trigger', () => { - renderShell(1280); + renderShell(1024); act(() => trigger().focus()); - fireEvent.click(trigger()); + commandB(); const entry = within(panel()).getByRole('link', { name: 'Contacts' }); act(() => entry.focus()); // A keyboard activation's click counts no presses. diff --git a/ui/packages/app-shell/src/layout/__tests__/UnifiedSidebar.railOverlay-27593.test.tsx b/ui/packages/app-shell/src/layout/__tests__/UnifiedSidebar.railOverlay-27593.test.tsx index 3e2ced87216..5598d3c287a 100644 --- a/ui/packages/app-shell/src/layout/__tests__/UnifiedSidebar.railOverlay-27593.test.tsx +++ b/ui/packages/app-shell/src/layout/__tests__/UnifiedSidebar.railOverlay-27593.test.tsx @@ -1,27 +1,29 @@ // Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license. /** - * UnifiedSidebar — on a narrow window the console sidebar folds on its own, - * and the app bar's trigger floats its menu OVER the content - * (objectstack#27593). Folded, the sidebar is hidden, with no icon column + * UnifiedSidebar — on a narrow window (below 1280 px, objectstack#36112) the + * console sidebar starts collapsed, and ⌘B floats its menu OVER the content + * (objectstack#27593). Collapsed, the sidebar is hidden, with no icon column * (ruling 6973617688 on objectstack#35062, which replaced the icon rail; the * edge, the reader's own collapse and focus are pinned in * `UnifiedSidebar.hiddenCollapse-35062.test.tsx`). * - * - At 1280 px the sidebar mounts folded and hidden; at 1440 px nothing + * - At 1024 px the sidebar mounts collapsed and hidden; at 1440 px nothing * changes; at 700 px the phone drawer still mounts. - * - The app bar's trigger floats the menu: the panel takes the expanded width - * above the page while the in-flow gap keeps no width, so the content beside - * it does not move. Resting the pointer on the window's left edge floats it - * too (the ruling's change to "hover alone does not expand"). + * - ⌘B floats the menu: the panel takes the expanded width above the page + * while the in-flow gap keeps no width, so the content beside it does not + * move. Resting the pointer on the window's left edge floats it too (the + * ruling's change to "hover alone does not expand"). * - A navigation choice, a press outside it or Esc folds it again; a press in - * an entry's own menu (a portal) does not, and the app bar's trigger - * toggles it once. - * - "Keep sidebar open" ends the fold for this browser and survives a reload. + * an entry's own menu (a portal) does not, and a sidebar trigger toggles it + * once. + * - The page header's expand button (a sidebar trigger) docks it on a narrow + * window for this browser, and a reload keeps it docked (ruling 7069868269 + * on objectstack#36112, which retired "Keep sidebar open"). * - One Esc folds it wherever the pointer or focus is inside it: the hidden * tooltip an entry opens does not take the key (objectstack#28078). - * - "Keep sidebar open" on a narrow window and the wide-window choice are kept - * apart, across a resize and a reload (objectstack#28079). + * - The narrow-window choice and the wide-window choice are kept apart, across + * a resize and a reload (objectstack#28079). * - A group declared `expanded: false` stays collapsed, with its count, in the * floated menu as in the expanded sidebar, and its disclosure opens it to * the pointer and the keyboard (objectstack#32156 listed its entries in the @@ -221,14 +223,21 @@ const appBarTrigger = () => within(screen.getByTestId('app-bar')).getByRole('but const hiddenTooltip = () => Array.from(document.querySelectorAll('[role="tooltip"]')).find((el) => el.closest('[hidden]')); -/** The folded sidebar's menu, floated over the content from the app bar's trigger. */ +/** The collapsed sidebar's menu, floated over the content by ⌘B. */ function expandRail() { - fireEvent.click(appBarTrigger()); + fireEvent.keyDown(window, { key: 'b', metaKey: true }); expect(sidebarRoot()).toHaveAttribute('data-state', 'expanded'); expect(panel()).toHaveAttribute('data-console-rail', 'overlay'); } -/** Folded: hidden, with no icon column, and nothing in it reachable. */ +/** Docked beside the content: expanded, no float. */ +function expectDocked() { + expect(sidebarRoot()).toHaveAttribute('data-state', 'expanded'); + expect(panel()).not.toHaveAttribute('data-console-rail'); + expect(tokens(frame())).toEqual(['contents']); +} + +/** Collapsed: hidden, with no icon column, and nothing in it reachable. */ function expectRail() { expect(sidebarRoot()).toHaveAttribute('data-state', 'collapsed'); expect(sidebarRoot()).toHaveAttribute('data-collapsible', 'offcanvas'); @@ -249,17 +258,17 @@ afterEach(() => { document.cookie = 'sidebar_state=; path=/; max-age=0'; }); -describe('the narrow-window fold (objectstack#27593)', () => { - it('at 1280 px the sidebar mounts folded and hidden, reserving no width', () => { - renderShell(1280); +describe('the narrow window’s collapsed sidebar (objectstack#27593, objectstack#36112)', () => { + it('at 1024 px the sidebar mounts collapsed and hidden, reserving no width', () => { + renderShell(1024); expectRail(); // Collapsed, the gap takes no width: the content is the whole window, with no icon column. expect(tokens(gap())).toContain('group-data-[state=collapsed]:group-data-[collapsible=offcanvas]:w-0'); expect(keepOpen()).toBeNull(); }); - it('the app bar’s trigger floats the menu over the content; the gap keeps no width', () => { - renderShell(1280); + it('⌘B floats the menu over the content; the gap keeps no width', () => { + renderShell(1024); expandRail(); // The panel takes the expanded width above the page… @@ -277,7 +286,7 @@ describe('the narrow-window fold (objectstack#27593)', () => { it('resting the pointer on the window’s left edge floats it; nothing of the hidden panel answers the pointer', () => { vi.useFakeTimers(); try { - renderShell(1280); + renderShell(1024); // The hidden panel is inert: hovering it does nothing. fireEvent.pointerEnter(panel(), { pointerType: 'mouse' }); fireEvent.mouseOver(background()); @@ -288,7 +297,7 @@ describe('the narrow-window fold (objectstack#27593)', () => { // Ruling 6973617688 on objectstack#35062 changes this pin's "hover alone // does not expand": with the icon rail gone, the left edge floats the menu - // on hover, as the app bar's trigger does on a click. + // on hover, as ⌘B does. fireEvent.pointerEnter(screen.getByTestId('console-sidebar-edge'), { pointerType: 'mouse' }); act(() => { vi.advanceTimersByTime(SIDEBAR_FLOAT_OPEN_DELAY_MS); @@ -301,7 +310,7 @@ describe('the narrow-window fold (objectstack#27593)', () => { }); it('choosing a navigation item folds it', () => { - renderShell(1280); + renderShell(1024); expandRail(); fireEvent.click(within(panel()).getByRole('link', { name: 'Contacts' })); expectRail(); @@ -309,14 +318,14 @@ describe('the narrow-window fold (objectstack#27593)', () => { }); it('a navigation from anywhere else folds it', () => { - renderShell(1280); + renderShell(1024); expandRail(); act(() => navigateTo('/apps/crm/account')); expectRail(); }); - it('a press outside folds it; the app bar trigger toggles it exactly once', () => { - renderShell(1280); + it('a press outside folds it; a sidebar trigger toggles it exactly once, and pressed again docks it', () => { + renderShell(1024); expandRail(); fireEvent.pointerDown(screen.getByText('The page')); expectRail(); @@ -327,14 +336,14 @@ describe('the narrow-window fold (objectstack#27593)', () => { fireEvent.click(trigger); expectRail(); + // Pressed while the sidebar is hidden, the trigger is the expand button: it docks it. fireEvent.pointerDown(trigger); fireEvent.click(trigger); - expect(sidebarRoot()).toHaveAttribute('data-state', 'expanded'); - expect(panel()).toHaveAttribute('data-console-rail', 'overlay'); + expectDocked(); }); it('a press in an entry’s own menu, drawn in a portal, does not fold it', () => { - renderShell(1280); + renderShell(1024); expandRail(); fireEvent.keyDown(within(panel()).getByRole('button', { name: 'More actions for Accounts' }), { key: 'Enter' }); const item = screen.getAllByRole('menuitem')[0]; @@ -344,9 +353,9 @@ describe('the narrow-window fold (objectstack#27593)', () => { }); it('Esc folds it; an Esc another layer already handled does not', () => { - renderShell(1280); - // Floated by a press on the edge, which moves no focus: the trigger's - // float focuses an entry, whose hidden tooltip would take the Esc + renderShell(1024); + // Floated by a press on the edge, which moves no focus: ⌘B's float + // focuses an entry, whose hidden tooltip would take the Esc // (objectstack#28078, below). fireEvent.click(screen.getByTestId('console-sidebar-edge')); expect(panel()).toHaveAttribute('data-console-rail', 'overlay'); @@ -363,7 +372,7 @@ describe('the narrow-window fold (objectstack#27593)', () => { describe('one Esc folds it wherever the pointer or focus is inside it (objectstack#28078)', () => { it('with focus on an entry, whose hidden tooltip is open', () => { - renderShell(1280); + renderShell(1024); expandRail(); const entry = within(panel()).getByRole('link', { name: 'Contacts' }); act(() => entry.focus()); @@ -373,7 +382,7 @@ describe('the narrow-window fold (objectstack#27593)', () => { }); it('with the pointer on an entry', async () => { - renderShell(1280); + renderShell(1024); expandRail(); fireEvent.pointerMove(within(panel()).getByRole('link', { name: 'Accounts' }), { pointerType: 'mouse' }); await act(() => new Promise((resolve) => setTimeout(resolve, 10))); @@ -382,18 +391,8 @@ describe('the narrow-window fold (objectstack#27593)', () => { expectRail(); }); - it('with focus on "Keep sidebar open"', () => { - renderShell(1280); - expandRail(); - const toggle = keepOpen()!; - act(() => toggle.focus()); - expect(hiddenTooltip(), 'the toggle opened its hidden tooltip').toBeDefined(); - fireEvent.keyDown(toggle, { key: 'Escape' }); - expectRail(); - }); - it('an entry’s open menu still takes the Esc first', () => { - renderShell(1280); + renderShell(1024); expandRail(); const entry = within(panel()).getByRole('link', { name: 'Accounts' }); act(() => entry.focus()); @@ -404,17 +403,18 @@ describe('the narrow-window fold (objectstack#27593)', () => { }); }); - describe('"Keep sidebar open" leaves the wide-window choice alone (objectstack#28079)', () => { + describe('the narrow-window choice leaves the wide-window choice alone (objectstack#28079)', () => { it('a collapsed wide-window sidebar comes back collapsed, after a reload too', () => { renderShell(1440); fireEvent.click(appBarTrigger()); expect(sidebarRoot()).toHaveAttribute('data-state', 'collapsed'); - resizeTo(1280); - expandRail(); - fireEvent.click(keepOpen()!); - expect(keepOpen()).toHaveAttribute('aria-pressed', 'true'); - fireEvent.click(keepOpen()!); + resizeTo(1024); + expectRail(); + // Docked on the narrow window by the expand button, then collapsed there again. + fireEvent.click(appBarTrigger()); + expectDocked(); + fireEvent.click(appBarTrigger()); expectRail(); resizeTo(1440); @@ -427,14 +427,11 @@ describe('the narrow-window fold (objectstack#27593)', () => { renderShell(1440); expect(sidebarRoot()).toHaveAttribute('data-state', 'expanded'); - resizeTo(1280); - expandRail(); - fireEvent.click(keepOpen()!); - // Kept open on the narrow window, the reader collapses it there… + resizeTo(1024); + expectRail(); + fireEvent.click(appBarTrigger()); + expectDocked(); fireEvent.click(appBarTrigger()); - expect(sidebarRoot()).toHaveAttribute('data-state', 'collapsed'); - // …and turns "keep open" off again. - fireEvent.click(keepOpen()!); expectRail(); resizeTo(1440); @@ -444,27 +441,25 @@ describe('the narrow-window fold (objectstack#27593)', () => { }); }); - it('"Keep sidebar open" ends the fold for this browser, survives a reload, and gives it back', () => { - renderShell(1280); - expandRail(); - const toggle = keepOpen()!; - expect(toggle).toHaveAttribute('aria-pressed', 'false'); - fireEvent.click(toggle); + it('the expand button docks it on a narrow window for this browser, a reload keeps it, and collapsing gives the default back', () => { + renderShell(1024); + expectRail(); + fireEvent.click(appBarTrigger()); - // The wide-window sidebar on a narrow window: expanded beside the content, no overlay. - expect(sidebarRoot()).toHaveAttribute('data-state', 'expanded'); - expect(panel()).not.toHaveAttribute('data-console-rail'); - expect(tokens(frame())).toEqual(['contents']); - expect(keepOpen()).toHaveAttribute('aria-pressed', 'true'); + // Expanded beside the content, no float: a press outside leaves it. + expectDocked(); + expect(keepOpen(), 'no "Keep sidebar open" (objectstack#36112)').toBeNull(); fireEvent.pointerDown(screen.getByText('The page')); - expect(sidebarRoot()).toHaveAttribute('data-state', 'expanded'); + expectDocked(); cleanup(); - renderShell(1280); - expect(sidebarRoot()).toHaveAttribute('data-state', 'expanded'); - expect(keepOpen()).toHaveAttribute('aria-pressed', 'true'); + renderShell(1024); + expectDocked(); - fireEvent.click(keepOpen()!); + fireEvent.click(appBarTrigger()); + expectRail(); + cleanup(); + renderShell(1024); expectRail(); }); @@ -509,8 +504,8 @@ const disclosure = () => within(panel()).getByRole('button', { name: /^Developer const groupEntry = (name: string) => within(panel()).queryByRole('link', { name }); describe('a collapsed group in the folded sidebar (objectstack#32156)', () => { - it('at 1360 px the hidden sidebar offers none of its entries; the floated menu opens the group by its disclosure', () => { - renderShell(1360, COLLAPSED_GROUP_NAVIGATION); + it('at 1024 px the hidden sidebar offers none of its entries; the floated menu opens the group by its disclosure', () => { + renderShell(1024, COLLAPSED_GROUP_NAVIGATION); expectRail(); // objectstack#32156 listed the group's entries in the icon rail. With no // rail (ruling 6973617688 on objectstack#35062) the hidden panel is inert, @@ -524,13 +519,13 @@ describe('a collapsed group in the folded sidebar (objectstack#32156)', () => { expect(screen.getByTestId('route')).toHaveTextContent('/apps/crm/oauth_app'); }); - it('at 1360 px the keyboard floats the menu from the trigger, opens the group and Enter opens an entry', async () => { + it('at 1024 px the keyboard floats the menu with ⌘B, opens the group and Enter opens an entry', async () => { const user = userEvent.setup(); - renderShell(1360, COLLAPSED_GROUP_NAVIGATION); + renderShell(1024, COLLAPSED_GROUP_NAVIGATION); act(() => appBarTrigger().focus()); - await user.keyboard('{Enter}'); + fireEvent.keyDown(window, { key: 'b', metaKey: true }); expect(panel()).toHaveAttribute('data-console-rail', 'overlay'); - expect(panel(), 'the trigger moves focus into the floated menu').toContainElement( + expect(panel(), '⌘B moves focus into the floated menu').toContainElement( document.activeElement as HTMLElement, ); for (let press = 0; press < 8 && document.activeElement !== disclosure(); press++) { @@ -558,7 +553,7 @@ describe('a collapsed group in the folded sidebar (objectstack#32156)', () => { }); it('the floated menu keeps the group collapsed, with its count, every time it floats', () => { - renderShell(1360, COLLAPSED_GROUP_NAVIGATION); + renderShell(1024, COLLAPSED_GROUP_NAVIGATION); expandRail(); expect(disclosure()).toHaveAttribute('aria-expanded', 'false'); expect(disclosure()).toHaveTextContent('2'); diff --git a/ui/packages/app-shell/src/layout/__tests__/UnifiedSidebar.recentThisApp-36112.test.tsx b/ui/packages/app-shell/src/layout/__tests__/UnifiedSidebar.recentThisApp-36112.test.tsx new file mode 100644 index 00000000000..d41327e7b47 --- /dev/null +++ b/ui/packages/app-shell/src/layout/__tests__/UnifiedSidebar.recentThisApp-36112.test.tsx @@ -0,0 +1,194 @@ +// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license. + +/** + * UnifiedSidebar — from 768 px up the sidebar's Recent group lists only what + * was opened in the current app (objectstack#36112 item 5, + * 「这个应用里的最近使用」). The store is the one Home's "Recently accessed" + * reads and holds every app's entries; an entry belongs to the app its + * address names (`/apps/APP/…`), resolved as the router resolves a segment. + * An entry opened in another app, or outside every app (a Studio item), is + * left out. The phone drawer is unchanged: it still lists every app's. + * + * Harness: `UnifiedSidebar.recentRecordsAndViews-12604.test.tsx`'s, with two + * apps and the store's list swapped per test. + */ + +import '@testing-library/jest-dom/vitest'; +import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'; +import React from 'react'; +import { cleanup, fireEvent, render, screen, within } from '@testing-library/react'; +import { MemoryRouter } from 'react-router-dom'; + +const i18nState = vi.hoisted(() => ({ language: 'en' })); +/** What the store holds, swapped per test. */ +const recent = vi.hoisted(() => ({ items: [] as unknown[] })); + +vi.mock('@object-ui/i18n', async (importOriginal) => ({ + ...(await importOriginal>()), + useObjectTranslation: () => ({ + t: (key: string, options?: Record) => String(options?.defaultValue ?? key), + language: i18nState.language, + }), + // No translation bundle: every convention lookup answers its fallback. + useObjectLabel: () => ({ + objectLabel: ({ label }: { label?: string }) => label, + viewLabel: (_o: string, _v: string, fallback?: string) => fallback, + dashboardLabel: ({ label }: { label?: string }) => label, + appLabel: ({ label }: { label?: string }) => label, + }), +})); + +vi.mock('@object-ui/auth', async (importOriginal) => ({ + ...(await importOriginal>()), + useAuth: () => ({ user: null, activeOrganization: null }), + useWorkspaceAdminStatus: () => ({ isAdmin: false, isResolved: true }), +})); + +vi.mock('@object-ui/permissions', async (importOriginal) => ({ + ...(await importOriginal()), + usePermissions: () => ({ can: () => true, hasCapabilities: () => true }), +})); + +let metadataState: { apps: unknown[]; objects: unknown[] }; +vi.mock('../../providers/MetadataProvider', () => ({ + useMetadata: () => metadataState, +})); + +vi.mock('../../providers/ExpressionProvider', () => ({ + useExpressionContext: () => ({ evaluator: null }), + evaluateVisibility: (expr: unknown) => expr !== false && expr !== 'false', + evaluateNavigationVisibility: (expr: unknown) => expr !== false && expr !== 'false', + useHasExpressionScope: () => true, +})); + +vi.mock('../../utils', () => ({ + resolveKeyedI18nLabel: (label: unknown) => (typeof label === 'string' ? label : ''), + matchAppBySegment: (apps: Array<{ name?: string }>, segment?: string) => + apps.find((a) => a?.name === segment), + appRouteSegment: (app: { name?: string }) => app?.name, +})); + +vi.mock('../../utils/getIcon', () => ({ getIcon: () => () => null })); +vi.mock('../../hooks/useRecentItems', () => ({ useRecentItems: () => ({ recentItems: recent.items }) })); +vi.mock('../../hooks/useFavorites', () => ({ + useFavorites: () => ({ favorites: [], removeFavorite: vi.fn() }), +})); +vi.mock('../../hooks/useNavPins', () => ({ + useNavPins: () => ({ togglePin: vi.fn(), applyPins: (items: unknown) => items }), +})); +vi.mock('../../hooks/useNavActionDispatch', () => ({ + useNavActionDispatch: () => vi.fn(), +})); +vi.mock('../../context/NavigationContext', () => ({ + useNavigationContext: () => ({ context: 'app', currentAppName: 'crm' }), +})); +vi.mock('../ContextSelectors', () => ({ + useAppContextSelectors: () => ({ contextValues: {}, element: null }), + contextSelectorQueryKey: (id: string) => (id === 'active_package' ? 'package' : id), + STUDIO_PACKAGE_SELECTOR_ID: 'active_package', +})); +vi.mock('../LocalizedSidebarTrigger', () => ({ + LocalizedSidebarTrigger: () => null, +})); + +import { SidebarProvider } from '@object-ui/components'; +import { UnifiedSidebar } from '../UnifiedSidebar'; + +const at = '2026-11-22T09:00:00.000Z'; +const record = (app: string, id: string, label: string) => ({ + id: `record:${app}_account:${id}`, + type: 'record', + label, + href: `/apps/${app}/${app}_account/record/${id}`, + visitedAt: at, +}); +const CRM_RECORD = record('crm', 'a1', 'Acme Corporation'); +const CRM_RECORD_2 = record('crm', 'a2', 'Globex'); +const HR_RECORD = record('hr', 'e1', 'Jane Doe'); +const SETUP_ITEM = { id: 'object:sys_user', type: 'object', name: 'sys_user', href: '/apps/setup/sys_user', visitedAt: at }; +const STUDIO_ITEM = { + id: 'metadata:object:crm_account', + type: 'metadata', + label: 'crm_account', + href: '/studio/crm/data/object/crm_account', + visitedAt: at, +}; + +function setViewportWidth(width: number) { + (window as unknown as { happyDOM: { setViewport: (v: { width: number; height: number }) => void } }).happyDOM.setViewport({ + width, + height: 900, + }); +} + +function renderSidebar(width: number) { + setViewportWidth(width); + metadataState = { + apps: [ + { name: 'crm', label: 'CRM', active: true, navigation: [] }, + { name: 'hr', label: 'HR', active: true, navigation: [] }, + { name: 'setup', label: 'Setup', active: true, navigation: [] }, + ], + objects: [], + }; + return render( + + + + + , + ); +} + +/** The Recent group's entries, by their text, after opening it (it starts collapsed). */ +function recentEntries(): string[] { + const label = screen.getByText('Recent'); + fireEvent.click(label); + const group = label.closest('[data-sidebar="group"]') as HTMLElement; + return within(group) + .getAllByRole('link') + .map((a) => a.textContent?.replace(/^\W+/u, '').trim() ?? ''); +} + +beforeEach(() => { + localStorage.clear(); + i18nState.language = 'en'; + recent.items = []; +}); + +afterEach(() => { + cleanup(); + setViewportWidth(1024); +}); + +describe('the sidebar’s Recent lists this app’s items (objectstack#36112)', () => { + it('from 768 px up, only what was opened in the current app, newest first', () => { + recent.items = [HR_RECORD, CRM_RECORD, SETUP_ITEM, STUDIO_ITEM, CRM_RECORD_2]; + renderSidebar(1024); + expect(recentEntries()).toEqual(['Acme Corporation', 'Globex']); + }); + + it('the five it shows are this app’s newest five, not the store’s', () => { + recent.items = [ + ...Array.from({ length: 5 }, (_, i) => record('hr', `e${i}`, `HR ${i}`)), + ...Array.from({ length: 6 }, (_, i) => record('crm', `a${i}`, `CRM ${i}`)), + ]; + renderSidebar(1440); + expect(recentEntries()).toEqual(['CRM 0', 'CRM 1', 'CRM 2', 'CRM 3', 'CRM 4']); + }); + + it('with nothing opened in this app there is no Recent group', () => { + recent.items = [HR_RECORD, SETUP_ITEM]; + renderSidebar(1024); + expect(screen.queryByText('Recent')).toBeNull(); + }); + + it('the phone drawer is unchanged: it lists every app’s entries', () => { + recent.items = [HR_RECORD, CRM_RECORD]; + renderSidebar(700); + // The drawer is drawn on demand: open it as the phone's trigger does (the provider's toggle, ⌘B). + fireEvent.keyDown(window, { key: 'b', metaKey: true }); + expect(document.querySelector('[data-mobile="true"][data-sidebar="sidebar"]')).not.toBeNull(); + expect(recentEntries()).toEqual(['Jane Doe', 'Acme Corporation']); + }); +}); diff --git a/ui/packages/app-shell/src/layout/__tests__/consoleSidebarRail.docking-36112.test.tsx b/ui/packages/app-shell/src/layout/__tests__/consoleSidebarRail.docking-36112.test.tsx new file mode 100644 index 00000000000..c955f618f01 --- /dev/null +++ b/ui/packages/app-shell/src/layout/__tests__/consoleSidebarRail.docking-36112.test.tsx @@ -0,0 +1,142 @@ +// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license. + +/** + * consoleSidebarRail — the docking model of objectstack#36112 (ruling + * 7069868269): one threshold, 1280 px; with no choice kept a window 1280 px + * wide and up starts with the sidebar expanded and one from 768 to 1279 px + * collapsed; the reader's own choice wins on each side, and the two choices + * are kept apart; a "Keep sidebar open" stored before this change reads as + * "expanded on a narrow window"; and the switch itself is gone. + * + * The starting state is read where the console's first frame takes it + * (`primeConsoleSidebarOpen`, which writes the sidebar primitive's cookie) and + * where the layout hands it to a mounted provider (`useResponsiveSidebar`). + */ + +import '@testing-library/jest-dom/vitest'; +import { act, cleanup, render, screen } from '@testing-library/react'; +import { SidebarProvider, useSidebar } from '@object-ui/components'; +import { afterEach, beforeEach, describe, expect, it } from 'vitest'; +import { useResponsiveSidebar } from '../../hooks/useResponsiveSidebar'; +import { + CONSOLE_SIDEBAR_RAIL_BELOW_WIDTH, + primeConsoleSidebarOpen, + startingSidebarOpen, + writeWideWindowOpen, +} from '../consoleSidebarRail'; + +function setViewportWidth(width: number) { + (window as unknown as { happyDOM: { setViewport: (v: { width: number; height: number }) => void } }).happyDOM.setViewport({ + width, + height: 900, + }); +} + +const sidebarCookie = () => /(?:^|;\s*)sidebar_state=(\w+)/.exec(document.cookie)?.[1]; + +/** What the first frame of a page load at `width` draws: the cookie the console primes. */ +function firstFrameAt(width: number): string | undefined { + setViewportWidth(width); + primeConsoleSidebarOpen(); + return sidebarCookie(); +} + +/** + * The narrow-window choice exactly as the retired "Keep sidebar open" switch + * stored it: the workspace preference `console.sidebar.keepOpen`, a v1 switch + * record. Written raw, so a renamed key or a new record shape reds here. + */ +const KEEP_OPEN_STORAGE_KEY = 'os:pref:console.sidebar.keepOpen'; +const storeLegacyKeepOpen = (value: 'on' | 'off') => + localStorage.setItem(KEEP_OPEN_STORAGE_KEY, JSON.stringify({ value, v: 1 })); + +function Probe() { + useResponsiveSidebar(); + return
{String(useSidebar().open)}
; +} + +beforeEach(() => { + localStorage.clear(); + document.cookie = 'sidebar_state=; path=/; max-age=0'; +}); + +afterEach(() => { + cleanup(); + setViewportWidth(1024); + localStorage.clear(); + document.cookie = 'sidebar_state=; path=/; max-age=0'; +}); + +describe('the default each window starts in (objectstack#36112, ruling 7069868269)', () => { + it('the threshold is 1280 px', () => { + expect(CONSOLE_SIDEBAR_RAIL_BELOW_WIDTH).toBe(1280); + }); + + it('a 1279 px window starts collapsed, a 1280 px one expanded, whatever the last page left in the cookie', () => { + document.cookie = 'sidebar_state=true; path=/'; + expect(firstFrameAt(1279)).toBe('false'); + document.cookie = 'sidebar_state=false; path=/'; + expect(firstFrameAt(1280)).toBe('true'); + // Both edges of each side. + expect(firstFrameAt(768)).toBe('false'); + expect(firstFrameAt(1920)).toBe('true'); + }); + + it('the mounted layout hands a 1279 px window the collapsed sidebar and a 1280 px one the expanded sidebar', () => { + setViewportWidth(1279); + render( + + + , + ); + expect(screen.getByTestId('open')).toHaveTextContent('false'); + // happy-dom's `MediaQueryList` starts tracking at "no match", so a query that + // matched at mount reports no change on its first resize: a resize at the + // current width first sets it right (as `UnifiedSidebar.hiddenCollapse-35062`'s `resizeTo`). + act(() => { + window.dispatchEvent(new Event('resize')); + setViewportWidth(1280); + }); + expect(screen.getByTestId('open')).toHaveTextContent('true'); + }); + + it('below 768 px the phone keeps what the cookie says', () => { + document.cookie = 'sidebar_state=true; path=/'; + expect(firstFrameAt(767)).toBe('true'); + }); +}); + +describe('a choice the reader made wins over the default, on each side (objectstack#36112)', () => { + it('collapsed on a wide window: a 1280 px window starts collapsed; the narrow side keeps its own default', () => { + writeWideWindowOpen(false); + expect(startingSidebarOpen(true)).toBe(false); + expect(firstFrameAt(1280)).toBe('false'); + expect(firstFrameAt(1279)).toBe('false'); + }); + + it('expanded on a narrow window: a 1279 px window starts expanded; the wide side keeps its own choice', () => { + storeLegacyKeepOpen('on'); + writeWideWindowOpen(false); + expect(startingSidebarOpen(false)).toBe(true); + expect(firstFrameAt(1279)).toBe('true'); + expect(firstFrameAt(1280)).toBe('false'); + }); + + it('collapsed on a narrow window by choice: a 1279 px window starts collapsed', () => { + storeLegacyKeepOpen('off'); + expect(firstFrameAt(1279)).toBe('false'); + }); +}); + +describe('a "Keep sidebar open" stored before this change (objectstack#36112)', () => { + it('reads as "expanded on a narrow window", from the first frame and in the mounted layout', () => { + storeLegacyKeepOpen('on'); + expect(firstFrameAt(1024)).toBe('true'); + render( + + + , + ); + expect(screen.getByTestId('open')).toHaveTextContent('true'); + }); +}); diff --git a/ui/packages/app-shell/src/layout/__tests__/consoleSidebarRail.width-27593.test.tsx b/ui/packages/app-shell/src/layout/__tests__/consoleSidebarRail.width-27593.test.tsx index 426364dd80e..20de4b83616 100644 --- a/ui/packages/app-shell/src/layout/__tests__/consoleSidebarRail.width-27593.test.tsx +++ b/ui/packages/app-shell/src/layout/__tests__/consoleSidebarRail.width-27593.test.tsx @@ -1,13 +1,15 @@ // Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license. /** - * consoleSidebarRail — the fold width is derived from what covers the content - * and from the sidebar it folds (objectstack#27593, re-derived on - * objectstack#29109 once the split pane retired). `CONSOLE_EXPANDED_SIDEBAR_WIDTH` - * restates the sidebar primitive's `--sidebar-width` and `RECORD_DRAWER_WIDTH` - * restates plugin-view's default drawer width, so this reads both off their - * owners and holds them equal: a wider or narrower sidebar or drawer moves the - * fold width with it, or this goes red. + * consoleSidebarRail — the threshold and what it costs (objectstack#27593, + * objectstack#29109, objectstack#36112). The threshold was derived from the + * record drawer, the list beside it and the expanded sidebar (1416 px); the + * ruling on objectstack#36112 (7069868269) moved it to 1280 px and accepted + * the cost. `CONSOLE_EXPANDED_SIDEBAR_WIDTH` restates the sidebar primitive's + * `--sidebar-width` (fixed at 256, objectstack#36112 F2) and + * `RECORD_DRAWER_WIDTH` plugin-view's default drawer width, so this reads both + * off their owners and holds them equal, and the cost stated on the ruling is + * the one the code pays. */ import '@testing-library/jest-dom/vitest'; @@ -19,7 +21,6 @@ import { CONSOLE_EXPANDED_SIDEBAR_WIDTH, CONSOLE_SIDEBAR_RAIL_BELOW_WIDTH, LIST_MIN_COLUMNS_WIDTH, - RECORD_DRAWER_MIN_CONTENT_WIDTH, RECORD_DRAWER_WIDTH, } from '../consoleSidebarRail'; @@ -49,41 +50,32 @@ function listBesideDrawer(width: number, sidebar: number): number { return width - sidebar - RECORD_DRAWER_WIDTH; } -describe('the console sidebar fold width (objectstack#27593, #29109)', () => { - it('restates the primitive’s expanded sidebar width', () => { +describe('the console sidebar threshold (objectstack#27593, #29109, #36112)', () => { + it('restates the primitive’s expanded sidebar width, fixed at 256', () => { expect(primitiveSidebarWidths().expanded).toBe(CONSOLE_EXPANDED_SIDEBAR_WIDTH); + expect(CONSOLE_EXPANDED_SIDEBAR_WIDTH).toBe(256); }); it('restates the drawer a list record opens in (plugin-view’s md bucket)', () => { - // `min(92vw, 720px)`: the px term is the drawer's width on any window the fold applies to. + // `min(92vw, 720px)`: the px term is the drawer's width on any desktop window. const match = /^min\(92vw, (\d+)px\)$/.exec(overlayWidthFor('md', {})); expect(match, 'overlayWidthFor answers min(92vw, Npx)').not.toBeNull(); expect(Number(match![1])).toBe(RECORD_DRAWER_WIDTH); }); - it('is the drawer beside the narrowest list that draws its columns, plus the expanded sidebar', () => { - expect(RECORD_DRAWER_MIN_CONTENT_WIDTH).toBe(LIST_MIN_COLUMNS_WIDTH + RECORD_DRAWER_WIDTH); - expect(CONSOLE_SIDEBAR_RAIL_BELOW_WIDTH).toBe(RECORD_DRAWER_MIN_CONTENT_WIDTH + CONSOLE_EXPANDED_SIDEBAR_WIDTH); - // The value the maintainer kept when the split pane retired: 440 + 720 + 256. - expect(CONSOLE_SIDEBAR_RAIL_BELOW_WIDTH).toBe(1416); - // At the threshold the expanded sidebar leaves exactly the list's floor beside the drawer. - expect(listBesideDrawer(CONSOLE_SIDEBAR_RAIL_BELOW_WIDTH, CONSOLE_EXPANDED_SIDEBAR_WIDTH)).toBe( - LIST_MIN_COLUMNS_WIDTH, - ); + it('is 1280 px, the ruling’s number (7069868269)', () => { + expect(CONSOLE_SIDEBAR_RAIL_BELOW_WIDTH).toBe(1280); }); - it('folds a 1280 px and a 1366 px window, whose hidden sidebar leaves the list its columns beside the drawer', () => { + it('pays the cost the ruling accepted: at 1280 px the expanded sidebar leaves the list 304 px beside the drawer, the collapsed one 560', () => { const { expanded } = primitiveSidebarWidths(); - for (const width of [1280, 1366]) { - expect(width).toBeLessThan(CONSOLE_SIDEBAR_RAIL_BELOW_WIDTH); - expect(listBesideDrawer(width, expanded)).toBeLessThan(LIST_MIN_COLUMNS_WIDTH); - // Folded, the sidebar is hidden and takes no width (objectstack#35062). - expect(listBesideDrawer(width, 0)).toBeGreaterThanOrEqual(LIST_MIN_COLUMNS_WIDTH); - } + expect(listBesideDrawer(CONSOLE_SIDEBAR_RAIL_BELOW_WIDTH, expanded)).toBe(304); + expect(listBesideDrawer(CONSOLE_SIDEBAR_RAIL_BELOW_WIDTH, expanded)).toBeLessThan(LIST_MIN_COLUMNS_WIDTH); + // Collapsed, the sidebar is hidden and takes no width (objectstack#35062). + expect(listBesideDrawer(CONSOLE_SIDEBAR_RAIL_BELOW_WIDTH, 0)).toBe(560); }); - it('leaves a 1440 px window’s sidebar expanded', () => { - expect(1440).toBeGreaterThanOrEqual(CONSOLE_SIDEBAR_RAIL_BELOW_WIDTH); + it('a 1440 px window’s expanded sidebar still leaves the list its columns beside the drawer', () => { expect(listBesideDrawer(1440, CONSOLE_EXPANDED_SIDEBAR_WIDTH)).toBeGreaterThanOrEqual(LIST_MIN_COLUMNS_WIDTH); }); }); diff --git a/ui/packages/app-shell/src/layout/consoleSidebarRail.ts b/ui/packages/app-shell/src/layout/consoleSidebarRail.ts index c0e2ad1142e..a0b28815983 100644 --- a/ui/packages/app-shell/src/layout/consoleSidebarRail.ts +++ b/ui/packages/app-shell/src/layout/consoleSidebarRail.ts @@ -1,31 +1,32 @@ // Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license. /** - * consoleSidebarRail — how the console sidebar collapses, when it folds on its - * own, and the menu it floats over the content (objectstack#27593, - * objectstack#35062). + * consoleSidebarRail — how the console sidebar docks and collapses, which + * state a window starts in, and the menu it floats over the content + * (objectstack#27593, objectstack#35062, objectstack#36112). * - * From the phone breakpoint up a collapsed sidebar is hidden: it takes no - * width, and nothing of it is drawn, focusable or announced. Both ways of - * collapsing look the same (ruling 6973617688 on objectstack#35062: one - * collapsed look at 768 px and up): the reader's own collapse, and the fold - * below. The full menu, with its labels and groups, floats over the content - * instead, without changing what the reader chose: after the pointer rests on - * the window's left edge, after a press on that edge, and from the app bar's - * trigger or ⌘B, whichever way it collapsed. A pointer that floated it folds - * it back by moving away; a navigation choice, a press outside it or Esc folds - * it from any of them. "Keep sidebar open", at the foot of the floated menu, - * puts the sidebar back beside the content and keeps it there. + * From the phone breakpoint up the sidebar is docked beside the content or + * collapsed, and a collapsed sidebar is hidden: it takes no width, and nothing + * of it is drawn, focusable or announced (ruling 6973617688 on + * objectstack#35062: one collapsed look at 768 px and up). The sidebar's + * collapse button and, while it is collapsed, the page header's expand button + * are the one control (ruling 7069868269 on objectstack#36112): each press is + * the reader's choice, and this browser keeps it. * - * On a window too narrow for the record drawer and the list beside it next to - * an expanded sidebar, the sidebar folds on its own. A reader who keeps it - * open ({@link CONSOLE_SIDEBAR_KEEP_OPEN_PREFERENCE}) gets the wide-window - * behaviour at every width above the phone breakpoint, where the primitive's - * drawer takes over: the trigger collapses the sidebar, and floats its menu - * once it is collapsed. + * Which state a window starts in is that choice, kept separately for a wide + * window ({@link CONSOLE_SIDEBAR_RAIL_BELOW_WIDTH} and up) and a narrow one + * (from the phone breakpoint to below it). With no choice kept, a wide window + * starts expanded and a narrow one collapsed. * - * `useResponsiveSidebar` folds and unfolds the sidebar as the window crosses - * the width; `UnifiedSidebar` draws the hidden sidebar, its edge and the float. + * Collapsed, the full menu, with its labels and groups, floats over the + * content without changing what the reader chose: after the pointer rests on + * the window's left edge, after a press on that edge, and from ⌘B. A pointer + * that floated it folds it back by moving away; a navigation choice, a press + * outside it or Esc folds it from any of them. + * + * `useResponsiveSidebar` gives each window its state as it loads and as it + * crosses the width, and keeps the reader's choices; `UnifiedSidebar` draws + * the hidden sidebar, its edge and the float. */ import { @@ -53,7 +54,7 @@ import { * The expanded sidebar's width in CSS pixels: the sidebar primitive's * `--sidebar-width` (16rem) in `@object-ui/components`. * `consoleSidebarRail.width-27593.test.tsx` reads the primitive's value and - * holds this equal to it, so the derived threshold below follows the sidebar. + * holds this equal to it. The width is fixed (objectstack#36112 F2). */ export const CONSOLE_EXPANDED_SIDEBAR_WIDTH = 256; @@ -61,8 +62,7 @@ export const CONSOLE_EXPANDED_SIDEBAR_WIDTH = 256; * The record drawer's width in CSS pixels: a list record opens in the drawer * at plugin-view's `md` overlay bucket, `overlayWidthFor('md', …)` = * `min(92vw, 720px)` (objectstack#27545). `consoleSidebarRail.width-27593.test.tsx` - * reads that value and holds this equal to it, so the derived threshold below - * follows the drawer. + * reads that value and holds this equal to it. */ export const RECORD_DRAWER_WIDTH = 720; @@ -75,33 +75,35 @@ export const RECORD_DRAWER_WIDTH = 720; export const LIST_MIN_COLUMNS_WIDTH = 440; /** - * The content width the record drawer needs over the full-width list: the - * drawer (720) and, beside it, the narrowest list that still draws its - * columns (440). - */ -export const RECORD_DRAWER_MIN_CONTENT_WIDTH = LIST_MIN_COLUMNS_WIDTH + RECORD_DRAWER_WIDTH; - -/** - * Below this window width the sidebar folds on its own. + * Below this window width a window with no choice kept starts with the + * sidebar collapsed; at it and above, expanded (ruling 7069868269 on + * objectstack#36112, 「1280 起默认展开,更窄才收起」). The one threshold: the + * wide and the narrow choice are kept on either side of it. * - * Derived, not picked: a window narrower than the drawer's content plus the - * expanded sidebar cannot keep the list's columns beside the open drawer with - * the sidebar expanded, so the sidebar gives the content its width. - * 1160 + 256 = 1416: a 1280 px window folds (the hidden sidebar leaves the - * drawer 560 px of list beside it, where the expanded sidebar would leave - * 304), a 1440 px window keeps the sidebar expanded (464 left). The record - * page's own column tiers are measured on the container it gets, so they - * follow either way. + * Chosen, not derived. The record drawer beside the narrowest list that still + * draws its columns, next to an expanded sidebar, needs 440 + 720 + 256 = + * 1416 px, the threshold before; the ruling accepts the cost below that. A + * 1280 px window with the sidebar expanded leaves the list beside an open + * record drawer 1280 − 256 − 720 = 304 px (560 with the sidebar collapsed), + * and on 1280 to 1415 px with the sidebar expanded, opening the record page's + * comment panel returns its fields to the tab row; collapsing the sidebar + * gives the content the width back. The record page's own column tiers are + * measured on the container it gets, so they follow either way. */ -export const CONSOLE_SIDEBAR_RAIL_BELOW_WIDTH = RECORD_DRAWER_MIN_CONTENT_WIDTH + CONSOLE_EXPANDED_SIDEBAR_WIDTH; +export const CONSOLE_SIDEBAR_RAIL_BELOW_WIDTH = 1280; /** - * The reader's "keep the sidebar open": `on` turns the fold off, so a narrow - * window keeps the wide-window sidebar. A reader preference, per browser, - * never metadata (objectstack#27052). With no choice: off. It changes when - * the sidebar collapses, never how a collapsed sidebar looks. + * The reader's narrow-window choice: `on` keeps the sidebar expanded on a + * window below {@link CONSOLE_SIDEBAR_RAIL_BELOW_WIDTH}, `off` collapsed. A + * reader preference, per browser, never metadata (objectstack#27052). With no + * choice: collapsed. Only a collapse or expand on a narrow window by the + * reader writes it; the float never does. + * + * Kept under the name the retired "Keep sidebar open" switch used, which held + * the same choice: a reader who kept the sidebar open starts expanded on a + * narrow window (ruling 7069868269 on objectstack#36112). */ -export const CONSOLE_SIDEBAR_KEEP_OPEN_PREFERENCE = defineWorkspacePreference({ +export const CONSOLE_SIDEBAR_NARROW_OPEN_PREFERENCE = defineWorkspacePreference({ name: 'console.sidebar.keepOpen', codec: versionedPreferenceCodec({ version: 1, @@ -110,21 +112,24 @@ export const CONSOLE_SIDEBAR_KEEP_OPEN_PREFERENCE = defineWorkspacePreference