diff --git a/.changeset/37150-docs-pages-in-app-shell.md b/.changeset/37150-docs-pages-in-app-shell.md index 4557ba70067..33811c1ca06 100644 --- a/.changeset/37150-docs-pages-in-app-shell.md +++ b/.changeset/37150-docs-pages-in-app-shell.md @@ -13,4 +13,4 @@ From 768 px up every app page lost the top bar and keeps the app menu, search, n The documentation still has one navigation, its own: the sidebar's body carries the docs column (「← Back to APP」, every book of the app with the current one open, a title filter and 「All documentation」) in place of the app's menu. The reader no longer draws that column inside the page there. The app's other docs pages (its docs index, a book with no articles, a book or doc that is not found) carry the same column in the sidebar instead of a back link above the page. -Unchanged: every docs address resolves to the same page as before, and a phone keeps its app bar, no sidebar and the in-page column. The `/docs` portal is not changed by this release. Nothing to migrate. +Unchanged: every docs address resolves to the same page as before, and a phone keeps its app bar, no sidebar and the in-page column. The `/docs` portal draws in the same frame from 768 px up too, in a variant that belongs to no app (its own entry describes it). Nothing to migrate. diff --git a/.changeset/37197-docs-portal-app-less-shell.md b/.changeset/37197-docs-portal-app-less-shell.md new file mode 100644 index 00000000000..44cf64df4e1 --- /dev/null +++ b/.changeset/37197-docs-portal-app-less-shell.md @@ -0,0 +1,18 @@ +--- +'@object-ui/app-shell': patch +'@object-ui/console': patch +'@objectstack/console': patch +--- + +feat(console): the documentation portal draws in the app shell's frame from 768 px up, belonging to no app + +Clause-②: no +Metadata-protocol: none + +The documentation portal (`/docs`, a book, an article) was the one documentation page that still drew a top bar on a desktop, in a frame of its own, while an app's documentation pages draw in the app shell. From 768 px up the portal now draws in the same frame, in a variant that belongs to no app: no top bar; the sidebar with search (when there is an app to search) and notifications in its head and the account at its foot; standing notices (impersonation, usage, storage, a lost connection) at the top of the page's content, beside the sidebar rather than over it; the page header's assistant and help buttons at the top right. Where an app's name sits in its sidebar, the portal's sidebar shows a neutral 「Documentation」 heading; it opens the list of your apps (none marked current) and 「Add app」, and choosing an app opens it. The sidebar's body is the documentation tree: 「All documentation」 first, a title filter, then every book under the heading of the app that carries it, as the portal's index groups them, with the book being read open. Books are named as the index names them, so a platform app's book reads as the app does (for example 「系统设置」) instead of its package's short name. + +Opening the portal does not pick an app: no app's colours are applied, and the app you last used, and the one you had open, stay what they were. + +「All documentation」 is now also the first documentation row of an app's documentation sidebar, right under 「← Back to APP」 and above the title filter and the books, so the two documentation sidebars match. + +Unchanged: every documentation address resolves to the same page as before, and a phone keeps the portal's documentation bar and the in-page column, with 「All documentation」 at its foot. Nothing to migrate. diff --git a/content/docs/frontend/app-shell.mdx b/content/docs/frontend/app-shell.mdx index 1f910474601..ca5346569dd 100644 --- a/content/docs/frontend/app-shell.mdx +++ b/content/docs/frontend/app-shell.mdx @@ -75,10 +75,12 @@ of its own to it, in particular **no sidebar toggle**. If you want one, render i Pass `showHeader={false}` to draw no header at all, for a page that draws its own top bar: the shell then renders no `
` element and does not mount `navbar`. It defaults to `true`, and leaving `navbar` out alone still draws the (empty) bar. The Console draws the -app bar only on a phone (below 768 px) and on an app's docs pages, which mount no sidebar. -From 768 px up an app page starts at the window's top: the sidebar's head carries the app -menu, search and the notification bell, its foot the account menu, the content area the -standing banners, and the page header its own buttons (objectstack#36112). On a phone a +app bar only on a phone (below 768 px). From 768 px up an app page, its docs pages included, +starts at the window's top: the sidebar's head carries the app menu, search and the +notification bell, its foot the account menu, the content area the standing banners, and +the page header its own buttons (objectstack#36112). The documentation portal (`/docs`), +which belongs to no app, draws the same frame there with a neutral 「Documentation」 head +in place of the app menu and the docs tree as the sidebar's body (objectstack#37197). On a phone a record page's own top bar, with its back link to the object's list, is the page's only bar, and every other route keeps the app bar. diff --git a/ui/apps/console/src/App.tsx b/ui/apps/console/src/App.tsx index 315c2dc747a..03609ffe331 100644 --- a/ui/apps/console/src/App.tsx +++ b/ui/apps/console/src/App.tsx @@ -31,6 +31,7 @@ import { ConsoleToaster, LoadingScreen, DefaultHomeLayout, + DocsPortalShell, DefaultHomePage, DefaultOrganizationsLayout, DefaultOrganizationsPage, @@ -225,16 +226,18 @@ function HomeRoute() { } /** - * The docs portal's frame (objectstack#35424): Home's layout with the docs bar, - * around the lazily loaded docs layout, so the bar is up while the portal's - * chunk loads. + * The docs portal's frame, around the lazily loaded docs layout, so the frame + * is up while the portal's chunk loads. From 768 px up it is the app-less + * variant of the app shell (objectstack#37197): the sidebar with a neutral + * 「Documentation」 head and the docs tree, no top bar, no app guessed. A + * phone keeps Home's layout with the docs bar (objectstack#35424). */ function DocsPortalRoute() { const { user } = useAuth(); return ( - + }> - + ); } diff --git a/ui/apps/console/src/__tests__/App.docsPortalLazy.test.tsx b/ui/apps/console/src/__tests__/App.docsPortalLazy.test.tsx index 70e528a4a1a..05e2205d175 100644 --- a/ui/apps/console/src/__tests__/App.docsPortalLazy.test.tsx +++ b/ui/apps/console/src/__tests__/App.docsPortalLazy.test.tsx @@ -98,6 +98,8 @@ vi.mock('@object-ui/app-shell', async (importOriginal) => ({ RequireOrganization: passthrough, SystemRedirect: () => null, DefaultHomeLayout: passthrough, + // objectstack#37197: the portal's frame, around the lazy docs layout. + DocsPortalShell: passthrough, DefaultHomePage: stub('home-page'), DefaultOrganizationsLayout: passthrough, DefaultOrganizationsPage: stub('organizations-page'), diff --git a/ui/apps/console/src/pages/DocPage.tsx b/ui/apps/console/src/pages/DocPage.tsx index 0a82d5e5354..4d141106082 100644 --- a/ui/apps/console/src/pages/DocPage.tsx +++ b/ui/apps/console/src/pages/DocPage.tsx @@ -16,7 +16,7 @@ import { rewriteDocLinks } from './doc-links'; import { conflictCandidates, readsByNameAfter } from './doc-address'; import { DocShell } from './DocShell'; import { useAppDocsBackTo } from './useAppDocsBackTo'; -import { DocsNav, usePackageDocsNavBooks } from './DocsNav'; +import { DocsNav, PortalDocsNav, usePackageDocsNavBooks } from './DocsNav'; import { DocRefusal } from './BookPage'; import { useBookData } from './use-book-data'; import { useActiveHeading } from './useActiveHeading'; @@ -395,12 +395,16 @@ export default function DocPage() { const docsLabel = t('help.documentation', { defaultValue: 'Documentation' }); const pageNav = sidebarNav ? null : docsNav; + // The shell sidebar's column: the package's books inside an app; in the + // portal's app-less shell every app's books, this one open (objectstack#37197). + const sidebarColumn = appName ? docsNav ?? undefined : ; return ( - + {/* objectstack#35424 — the docs column is the page's one navigation. - * Inside an app from 768 px up it is the shell sidebar's body, where the - * app menu would be (objectstack#37150); elsewhere it sits full height + * From 768 px up it is the shell sidebar's body, where the app menu + * would be: an app's (objectstack#37150) and the portal's app-less + * shell (objectstack#37197); elsewhere (a phone) it sits full height * beside the article, and on narrow screens it folds into a disclosure * above it. */}
diff --git a/ui/apps/console/src/pages/DocShell.tsx b/ui/apps/console/src/pages/DocShell.tsx index 04e5c0ae755..7810242652c 100644 --- a/ui/apps/console/src/pages/DocShell.tsx +++ b/ui/apps/console/src/pages/DocShell.tsx @@ -15,7 +15,7 @@ import { useSidebarDocsNavSlot, } from '@object-ui/app-shell'; import { AppDocsBackLink } from './AppDocsBackLink'; -import { AppDocsNav, DocsNavLandmark } from './DocsNav'; +import { AppDocsNav, DocsNavLandmark, PortalDocsNav } from './DocsNav'; import { useAppDocsBackTo } from './useAppDocsBackTo'; /** @@ -34,7 +34,11 @@ import { useAppDocsBackTo } from './useAppDocsBackTo'; * page carries 「← Back to APP」 itself: at the top here, on every page but * the reader, which carries it in its in-page column and passes * `backLink={false}`. - * - The portal (`/docs/...`) is drawn in Home's frame, whose bar reads + * - The portal (`/docs/...`), from 768 px up, is drawn in the app-less + * variant of the shell (`DocsPortalShell`, objectstack#37197): the same + * sidebar and page header, and the sidebar's body is the portal's column + * (`PortalDocsNav`, every app's books) unless the page hands its own. + * - The portal on a phone is drawn in Home's frame, whose bar reads * 「PRODUCT / Documentation」 and links to the portal's index (`App.tsx`, * the `docs` variant of `AppHeader`). */ @@ -45,11 +49,11 @@ export function DocShell({ }: { /** Without the shell sidebar: draw 「← Back to APP」 above the page. The reader turns it off when its column has it. */ backLink?: boolean; - /** The page's own docs column, for the shell sidebar (the reader's); else every book of the app. */ + /** The page's own docs column, for the shell sidebar (the reader's); else every book of the app, or of the portal. */ nav?: ReactNode; children: ReactNode; }) { - const { appName } = useParams<{ appName?: string }>(); + const { appName, slug } = useParams<{ appName?: string; slug?: string }>(); const backTo = useAppDocsBackTo(); const sidebarNav = useSidebarDocsNavSlot() !== null; const renderActions = useShellPageActionsSlot(); @@ -58,7 +62,7 @@ export function DocShell({
{sidebarNav ? ( - {nav ?? } + {nav ?? (appName ? : )} ) : null} {renderActions || renderExpand ? ( diff --git a/ui/apps/console/src/pages/DocsNav.tsx b/ui/apps/console/src/pages/DocsNav.tsx index 9c0071d4126..94d5b710498 100644 --- a/ui/apps/console/src/pages/DocsNav.tsx +++ b/ui/apps/console/src/pages/DocsNav.tsx @@ -7,14 +7,16 @@ */ import { useCallback, useId, useMemo, useState, type ReactNode } from 'react'; -import { Link, useParams } from 'react-router-dom'; -import { ArrowRight, ChevronDown, ChevronRight, Search } from 'lucide-react'; +import { Link, useLocation, useParams } from 'react-router-dom'; +import { ArrowRight, ChevronDown, ChevronRight, Library, Search } from 'lucide-react'; +import { filterActiveApps, useMetadata, useServedAppLabel, useSidebarDocsNavSlot } from '@object-ui/app-shell'; import { useObjectTranslation } from '@object-ui/i18n'; import { AppDocsBackLink } from './AppDocsBackLink'; import { useAppDocsBackTo, type AppDocsBackTo } from './useAppDocsBackTo'; import { BookSidebar } from './BookSidebar'; import { bookArticles, filterBookArticles } from './docs-reading'; -import { bookSlug, labelUncategorized, pkgOfBook, resolveBookTree, type ResolvedBook } from './book-nav'; +import { bookSlug, buildBookCards, labelUncategorized, pkgOfBook, resolveBookTree, type ResolvedBook } from './book-nav'; +import { groupBooksByApp, type DocsIndexApp } from './docs-index'; import { useBookData } from './use-book-data'; /** One book of the column: its resolved spine and its URL segment. */ @@ -23,15 +25,32 @@ export interface DocsNavBook { book: ResolvedBook; } +/** A run of the column's books under one heading: the portal's books of one app. */ +export interface DocsNavSection { + key: string; + label: string; + books: readonly DocsNavBook[]; +} + /** * The docs reader's one navigation column (objectstack#35424): a way back to - * the app the reader came from, a title filter, every book of the package - * (the current one open, the others folded, each with its article count), - * and a link to all documentation. Inside an app it takes the app menu's - * place; the shell draws no menu beside it. + * the app the reader came from, 「All documentation」, a title filter, and + * the books (the current one open, the others folded, each with + * its article count) — the package's, or, in the portal, every app's under + * its app's heading (`sections`). Inside an app it takes the app menu's place; + * the shell draws no menu beside it. + * + * objectstack#37197 — in the shell sidebar (from 768 px up, an app's docs + * pages and the portal alike) 「All documentation」 is the first row of the + * docs entries, marked while it is the page in view: under the way back to the + * app, which is the shell's navigation and not a docs row, and above the + * filter and the books. The same column drawn in the page — + * which only a phone draws, since from 768 px up both docs frames carry it in + * the sidebar — keeps it at the foot, unchanged. */ export function DocsNav({ books, + sections, currentSlug, activeDoc, docHref, @@ -39,6 +58,8 @@ export function DocsNav({ allDocsHref, }: { books: readonly DocsNavBook[]; + /** The books under headings (the portal's, by app); `books` is then not read. */ + sections?: readonly DocsNavSection[]; currentSlug?: string; activeDoc?: string; docHref: (slug: string, doc: string) => string; @@ -47,20 +68,42 @@ export function DocsNav({ allDocsHref: string; }) { const { t } = useObjectTranslation(); + const { pathname } = useLocation(); + const inSidebar = useSidebarDocsNavSlot() !== null; const [query, setQuery] = useState(''); // A book the reader folded or unfolded; every other book follows the rule: // the current book open, the rest folded. const [toggled, setToggled] = useState>({}); const searchId = useId(); const searching = query.trim() !== ''; - const shown = books - .map((entry) => ({ ...entry, filtered: filterBookArticles(entry.book, query) })) - .filter((entry) => !searching || entry.filtered.groups.length > 0); + const shownSections = (sections ?? [{ key: '', label: '', books }]) + .map((section) => ({ + ...section, + shown: section.books + .map((entry) => ({ ...entry, filtered: filterBookArticles(entry.book, query) })) + .filter((entry) => !searching || entry.filtered.groups.length > 0), + })) + .filter((section) => section.shown.length > 0); const searchLabel = t('help.searchDocs', { defaultValue: 'Search docs' }); + const allDocsLabel = t('help.allDocs', { defaultValue: 'All documentation' }); + const allDocsInView = pathname.replace(/\/+$/, '') === allDocsHref; return (
{backTo ? : null} + {inSidebar ? ( + + + {allDocsLabel} + + ) : null}
- {shown.length === 0 ? ( + {shownSections.length === 0 ? (

{t('help.noDocsMatch', { defaultValue: 'No articles match.' })}

) : ( -
    - {shown.map(({ slug, book, filtered }) => { - const open = searching || (toggled[slug] ?? slug === currentSlug); - const label = book.label ?? book.name; - const count = bookArticles(book).length; - const Chevron = open ? ChevronDown : ChevronRight; - return ( -
  • - - {open ? ( -
    - docHref(slug, doc)} - showLabel={false} - groupHeadings="multi" - /> -
    - ) : null} -
  • - ); - })} -
+
+ {shownSections.map((section) => ( +
+ {section.label ? ( +
+ {section.label} +
+ ) : null} +
    + {section.shown.map(({ slug, book, filtered }) => { + const open = searching || (toggled[slug] ?? slug === currentSlug); + const label = book.label ?? book.name; + const count = bookArticles(book).length; + const Chevron = open ? ChevronDown : ChevronRight; + return ( +
  • + + {open ? ( +
    + docHref(slug, doc)} + showLabel={false} + groupHeadings="multi" + /> +
    + ) : null} +
  • + ); + })} +
+
+ ))} +
+ )} + {inSidebar ? null : ( +
+ + {allDocsLabel} + + +
)} -
- - {t('help.allDocs', { defaultValue: 'All documentation' })} - - -
); } @@ -181,3 +237,56 @@ export function AppDocsNav() { ); } + +/** An app as the portal's index lists it, from the served app list. */ +type ServedApp = { name: string; label?: unknown; _packageId?: unknown; navigation?: unknown; areas?: unknown } & Record; + +/** + * The portal's column (objectstack#37197), in the app-less shell's sidebar: + * every book the portal's index lists, under the heading of the app that + * carries it and in the index's order (`groupBooksByApp`, the index's own + * grouping), each named as its index card names it — an implicit book by its + * app's label, never by its package id's last segment. The book being read is + * open. No way back to an app: the portal is in none. + */ +export function PortalDocsNav({ currentSlug, activeDoc }: { currentSlug?: string; activeDoc?: string }) { + const { t } = useObjectTranslation(); + const { books, authoredBooks, docs } = useBookData(); + const { apps } = useMetadata(); + const { appLabel } = useServedAppLabel(); + const uncategorizedLabel = t('help.uncategorized', { defaultValue: 'Uncategorized' }); + const otherLabel = t('help.otherDocs', { defaultValue: 'Other documentation' }); + const sections = useMemo(() => { + const indexApps: DocsIndexApp[] = filterActiveApps(apps as ServedApp[] | undefined) + .filter((app) => typeof app.name === 'string' && app.name !== '') + .map((app) => ({ + name: app.name, + label: appLabel(app), + _packageId: typeof app._packageId === 'string' ? app._packageId : undefined, + navigation: app.navigation, + areas: app.areas, + })); + const byName = new Map(books.map((b) => [b.name, b])); + return groupBooksByApp(books, buildBookCards(books, docs), docs, indexApps).map((group) => ({ + key: group.app ?? '', + label: group.label ?? otherLabel, + books: group.cards.flatMap((card) => { + const book = byName.get(card.name); + if (!book) return []; + const resolved = labelUncategorized(resolveBookTree(book, docs, undefined, authoredBooks), uncategorizedLabel); + return [{ slug: bookSlug(book), book: { ...resolved, label: card.label } }]; + }), + })); + }, [apps, appLabel, books, docs, authoredBooks, uncategorizedLabel, otherLabel]); + const docHref = useCallback((bookSegment: string, doc: string) => `/docs/${bookSegment}/${doc}`, []); + return ( + + ); +} diff --git a/ui/apps/console/src/pages/docs-portal.test.tsx b/ui/apps/console/src/pages/docs-portal.test.tsx index c2962ab9f4d..8fd4babb817 100644 --- a/ui/apps/console/src/pages/docs-portal.test.tsx +++ b/ui/apps/console/src/pages/docs-portal.test.tsx @@ -1098,3 +1098,207 @@ describe('objectstack#37150 — from 768 px up an app\'s docs pages draw in the expect(screen.queryByTestId('sidebar-docs-nav')).toBeNull(); }); }); + +describe('objectstack#37197 — the portal\'s tree in the app-less shell, 「All documentation」 the first docs row in both docs sidebars', () => { + function Where() { + return
{useLocation().pathname}
; + } + /** + * The portal's routes (`App.tsx`'s `/docs` tree) inside the shell's docs + * place, as `DocsPortalShell` mounts it from 768 px up: the sidebar's body + * (`UnifiedSidebar` draws the target) and the page header's group. + */ + function InPortalShell({ entry }: { entry: string }) { + return ( + + + +
+ + + }> + } /> + } /> + } /> + + }> + } /> + } /> + } /> + + +
+
+
+ ); + } + /** The phone's portal: no shell sidebar, so the page draws its column itself. */ + function OnPhone({ entry }: { entry: string }) { + return ( + + + + }> + } /> + } /> + } /> + + }> + } /> + } /> + + + + ); + } + const sidebar = () => screen.getByTestId('shell-sidebar'); + const page = () => screen.getByTestId('shell-route'); + const column = () => within(sidebar()).getByTestId('docs-nav'); + /** The column's rows in reading order: links and book buttons, by their test id or name. */ + const firstRow = (nav: HTMLElement) => nav.querySelector('a, button, input'); + /** The first docs entry: the first row after the way back to an app, which is the shell's navigation, not a docs row. */ + const firstDocsRow = (nav: HTMLElement) => + [...nav.querySelectorAll('a, button, input')].find((el) => el.getAttribute('data-testid') !== 'docs-nav-back'); + const precedes = (a: Element, b: Element) => (a.compareDocumentPosition(b) & Node.DOCUMENT_POSITION_FOLLOWING) !== 0; + const lastLink = (nav: HTMLElement) => [...nav.querySelectorAll('a')].pop(); + /** The headings of the tree's sections and each section's books, in order. */ + const treeSections = () => + within(column()) + .getAllByTestId('docs-nav-section') + .map((section) => [ + within(section).getByTestId('docs-nav-section-label').textContent, + within(section) + .getAllByRole('button') + .map((b) => b.firstElementChild?.textContent), + ]); + const SETUP_APP = { name: 'setup', label: 'System settings', _packageId: 'com.objectstack.setup', navigation: [] }; + + beforeEach(() => { + WORLD.authored = true; + WORLD.shellActions = true; + WORLD.apps = [ + { name: 'showcase_app', label: 'Showcase', _packageId: 'com.example.showcase', navigation: [] }, + { + name: 'alpha_app', + label: 'Alpha', + _packageId: 'com.example.alpha', + navigation: [{ id: 'help', type: 'group', children: [{ id: 'nav_beta', type: 'doc', book: 'handbook' }] }], + }, + ]; + }); + afterEach(() => { + WORLD.authored = false; + WORLD.shellActions = false; + WORLD.platform = false; + WORLD.apps = []; + }); + + it('/docs: the sidebar carries the tree, every book under its app\'s heading in the index\'s order, 「All documentation」 first and current', async () => { + render(); + await within(page()).findByRole('heading', { level: 2, name: 'Showcase' }); + const nav = column(); + expect(firstRow(nav)).toBe(within(nav).getByTestId('docs-nav-all-docs')); + expect(within(nav).getByTestId('docs-nav-all-docs')).toHaveAttribute('href', '/docs'); + expect(within(nav).getByTestId('docs-nav-all-docs')).toHaveAttribute('aria-current', 'page'); + expect(treeSections()).toEqual([ + ['Showcase', ['Showcase Manual', 'Leads Book']], + ['Alpha', ['Alpha Manual', 'Beta Handbook']], + ['Other documentation', ['Acme Manual', 'Ops']], + ]); + // The portal is in no app: no way back to one, and no column in the page. + expect(within(nav).queryByTestId('docs-nav-back')).toBeNull(); + expect(within(page()).queryByTestId('docs-nav')).toBeNull(); + expect(screen.getAllByTestId('docs-nav')).toHaveLength(1); + expect(within(sidebar()).getByRole('navigation', { name: 'Documentation navigation' })).toContainElement(nav); + }); + + it('a book open: the reader in the page, its book open in the tree with the article current, 「All documentation」 first and not current', async () => { + render(); + expect(await screen.findByTestId('doc-content')).toHaveTextContent('LEAD BODY'); + const nav = column(); + expect(firstRow(nav)).toBe(within(nav).getByTestId('docs-nav-all-docs')); + expect(within(nav).getByTestId('docs-nav-all-docs')).not.toHaveAttribute('aria-current'); + expect(within(nav).getByRole('button', { name: /Showcase Manual/ })).toHaveAttribute('aria-expanded', 'true'); + expect(within(nav).getByRole('button', { name: /Alpha Manual/ })).toHaveAttribute('aria-expanded', 'false'); + const current = within(nav).getAllByRole('link', { name: 'Lead Guide' }).filter((l) => l.getAttribute('aria-current') === 'page'); + expect(current.map((l) => l.getAttribute('href'))).toEqual(['/docs/manual/showcase_lead_guide']); + expect(within(page()).queryByTestId('docs-nav')).toBeNull(); + expect(within(screen.getByTestId('docs-page-header')).getByTestId('shell-page-actions-stub')).toBeInTheDocument(); + }); + + it('a book named by its app in the index is named the same in the tree, not by its package id', async () => { + WORLD.platform = true; + WORLD.apps = [...WORLD.apps, SETUP_APP]; + render(); + await within(page()).findByRole('heading', { level: 2, name: 'System settings' }); + expect(treeSections()).toContainEqual(['System settings', ['System settings']]); + expect(within(column()).queryByRole('button', { name: /^Setup/ })).toBeNull(); + }); + + // ADR-0046 section 6: every portal URL keeps its answer in the new frame. + it.each([ + ['the index', '/docs', '/docs', null], + ['a book SLUG', '/docs/manual', '/docs/manual/showcase_index', 'INDEX BODY'], + ['a book NAME', '/docs/showcase_manual', '/docs/manual/showcase_index', 'INDEX BODY'], + ['a book NAME with its doc', '/docs/showcase_manual/showcase_lead_guide', '/docs/manual/showcase_lead_guide', 'LEAD BODY'], + ['a doc name that is also a book name (the doc permalink wins)', '/docs/showcase_lead_guide', '/docs/manual/showcase_lead_guide', 'LEAD BODY'], + ['the canonical SLUG/DOC', '/docs/manual/showcase_lead_guide', '/docs/manual/showcase_lead_guide', 'LEAD BODY'], + ['an implicit package book', '/docs/com.example.ops', '/docs/com.example.ops/ops_setup', 'OPS BODY'], + ['a slug that is another book\'s name', '/docs/handbook', '/docs/handbook/alpha_welcome', 'ALPHA BODY'], + ])('%s, %s, lands on %s in the shell', async (_what, entry, where, body) => { + render(); + if (body) expect(await screen.findByTestId('doc-content')).toHaveTextContent(body); + else await within(page()).findByRole('heading', { level: 2, name: 'Showcase' }); + expect(screen.getByTestId('where')).toHaveTextContent(where); + expect(within(sidebar()).getByTestId('docs-nav')).toBeInTheDocument(); + expect(within(page()).queryByTestId('docs-nav')).toBeNull(); + }); + + it('an app\'s docs sidebar puts 「All documentation」 first among the docs entries: under the way back to the app, above the filter and the books', async () => { + render(); + await screen.findByTestId('doc-content'); + const nav = column(); + const allDocs = within(nav).getByTestId('docs-nav-all-docs'); + const back = within(nav).getByTestId('docs-nav-back'); + expect(allDocs).toHaveAttribute('href', '/docs'); + // The way back is the shell's navigation and stays the column's top row. + expect(firstRow(nav)).toBe(back); + expect(precedes(back, allDocs)).toBe(true); + // 「All documentation」 is the first docs row: before the filter and the first book. + expect(firstDocsRow(nav)).toBe(allDocs); + expect(precedes(allDocs, within(nav).getByTestId('docs-nav-search'))).toBe(true); + expect(precedes(allDocs, within(nav).getAllByRole('button')[0])).toBe(true); + // The app's column is one package's books, with no app headings. + expect(within(nav).queryAllByTestId('docs-nav-section')).toHaveLength(0); + }); + + it('…and so does an app\'s docs page that is not the reader (its docs index)', async () => { + render(); + await within(page()).findByText('Leads Book'); + const nav = column(); + expect(firstRow(nav)).toBe(within(nav).getByTestId('docs-nav-back')); + expect(firstDocsRow(nav)).toBe(within(nav).getByTestId('docs-nav-all-docs')); + expect(precedes(within(nav).getByTestId('docs-nav-all-docs'), within(nav).getAllByRole('button')[0])).toBe(true); + }); + + it('PHONE CONTROL — the column the page draws itself keeps 「All documentation」 at its foot, the portal\'s and an app\'s alike', async () => { + WORLD.shellActions = false; + for (const entry of ['/docs/manual/showcase_lead_guide', '/apps/com.example.showcase/docs/manual/showcase_lead_guide']) { + render(); + await screen.findByTestId('doc-content'); + const navs = screen.getAllByTestId('docs-nav'); + expect(navs.length, entry).toBeGreaterThan(0); + for (const nav of navs) { + const allDocs = within(nav).getByTestId('docs-nav-all-docs'); + expect(lastLink(nav), entry).toBe(allDocs); + expect(firstDocsRow(nav), entry).not.toBe(allDocs); + // The phone's column is one package's books, as before. + expect(within(nav).queryAllByTestId('docs-nav-section'), entry).toHaveLength(0); + } + expect(screen.queryByTestId('docs-page-header'), entry).toBeNull(); + cleanup(); + } + }); +}); diff --git a/ui/packages/app-shell/src/chrome/unsavedEditsLeave.census-13253.test.ts b/ui/packages/app-shell/src/chrome/unsavedEditsLeave.census-13253.test.ts index 576994b2c4c..7bb042aa604 100644 --- a/ui/packages/app-shell/src/chrome/unsavedEditsLeave.census-13253.test.ts +++ b/ui/packages/app-shell/src/chrome/unsavedEditsLeave.census-13253.test.ts @@ -84,15 +84,16 @@ describe('every shell departure in the four files goes through confirmUnsavedLea expect(bareCalls(code('chrome/CommandPalette.tsx'), 'onAppChange')).toEqual([]); }); - it('UnifiedSidebar: its one read of onAppChange, the app menu\'s switch, goes through the seam (objectstack#36112)', () => { - // Declared on the props interface, destructured, and read once: the app - // menu in the sidebar's head hands it on wrapped (that line names it - // twice, the menu's prop and the call). A second read must be wrapped - // too, and this count makes it a visible change. + it('UnifiedSidebar: its two reads of onAppChange, the head menus\' switches, go through the seam (objectstack#36112, objectstack#37197)', () => { + // Declared on the props interface, destructured, and read twice: the app + // menu in the sidebar's head, and the docs portal's 「Documentation」 head + // in its place on `/docs` (objectstack#37197), each hand it on wrapped + // (each line names it twice, the menu's prop and the call). A third read + // must be wrapped too, and this count makes it a visible change. const sidebar = code('layout/UnifiedSidebar.tsx'); - expect(sidebar.match(/\bonAppChange\b/g) ?? []).toHaveLength(4); + expect(sidebar.match(/\bonAppChange\b/g) ?? []).toHaveLength(6); expect(sidebar).toMatch(/onAppChange\?: \(name: string\) => void;/); - expect(sidebar).toMatch(/onAppChange=\{\(segment\) => confirmUnsavedLeave\(\(\) => onAppChange\?\.\(segment\)\)\}/); + expect(sidebar.match(/onAppChange=\{\(segment\) => confirmUnsavedLeave\(\(\) => onAppChange\?\.\(segment\)\)\}/g) ?? []).toHaveLength(2); }); it('CONTROL: the census sees a bare call, and does not count a wrapped one or a commented one', () => { diff --git a/ui/packages/app-shell/src/console/docs/DocsPortalShell.tsx b/ui/packages/app-shell/src/console/docs/DocsPortalShell.tsx new file mode 100644 index 00000000000..85f82c838a3 --- /dev/null +++ b/ui/packages/app-shell/src/console/docs/DocsPortalShell.tsx @@ -0,0 +1,183 @@ +// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license. + +/** + * DocsPortalShell — the frame of the documentation portal (`/docs…`, + * ADR-0046 §6), the docs route that names no app. + * + * From 768 px up it is an app-less variant of the app shell (ruling B, + * 7151721568 on objectstack#37150; design approved on objectstack#37197): the + * same `AppShell` and `UnifiedSidebar` an app's docs pages draw in + * (objectstack#37150), so the two entry points to the same documents share one + * frame (ruling A on objectstack#36107). No top bar; the sidebar's head carries + * search (when there is an app to search) and the bell, its foot the account, + * and the collapse button works as on every app page. The standing banners + * (impersonation, read rate, storage) and the connection notice sit at the top + * of the content area, the content's width, as in an app (`ChromeBannerHost`, + * `ConnectionBanner`): drawn above the route they would span the sidebar's + * column and cover its head. Two things differ from an app's docs pages: + * + * - the head is a neutral 「Documentation」 menu (`SidebarDocsPortalMenu`) + * that lists the viewer's apps and 「Add app」, none of them checked, in + * place of an app's name menu; + * - the body is the portal's docs tree, every book under its app's heading, + * which the page draws through the docs-navigation slot + * (`sidebarDocsNavSlot.tsx`). + * + * ⭐ No app is guessed (objectui#4280 refused a guessed-app sidebar on an + * app-less route): the navigation context is `home`, as Home's frame sets it; + * nothing is written to the current or the last app; no app's branding is + * applied, so the accent is the console's default. Choosing an app in the + * head opens that app. The command palette is Home's (`HomeCommandPalette`, + * scoped as on Home and in the portal's phone frame), the AI drawer is Home's + * (no app, so a build thread starts unbound), and the page header's button + * group is the app-less one (`ShellPageActionsScope appless`). + * + * A phone keeps Home's frame with the docs bar (`HomeLayout variant="docs"`), + * unchanged. + * + * @module + */ + +import React, { useCallback, useEffect, useMemo, useState, useSyncExternalStore } from 'react'; +import type { ConnectionState } from '@object-ui/data-objectstack'; +import { useNavigate } from 'react-router-dom'; +import { AppShell } from '@object-ui/layout'; +import { useAuth } from '@object-ui/auth'; +import { useNavigationContext } from '../../context/NavigationContext.js'; +import { CommandPaletteProvider } from '../../context/CommandPaletteProvider.js'; +import { useMetadata } from '../../providers/MetadataProvider.js'; +import { useAdapter } from '../../providers/AdapterProvider.js'; +import { filterActiveApps, matchAppBySegment, resolveHostAppSegment } from '../../utils/index.js'; +import { ExpressionProvider } from '../../providers/ExpressionProvider.js'; +import { buildExpressionUser } from '../../providers/expressionUser.js'; +import { useAiSurfaceEnabled } from '../../hooks/useAiSurface.js'; +import { useResponsiveSidebar } from '../../hooks/useResponsiveSidebar.js'; +import { usePhoneViewport } from '../../hooks/usePhoneViewport.js'; +import { useConsoleChatDock } from '../../layout/useConsoleChatDock.js'; +import { ChatDockControlProvider } from '../../layout/chatDockControl.js'; +import { UnifiedSidebar } from '../../layout/UnifiedSidebar.js'; +import { SidebarDocsNavSlotProvider } from '../../layout/sidebarDocsNavSlot.js'; +import { ShellPageActionsScope, ShellSidebarExpandFallback } from '../../layout/ShellPageActions.js'; +import { primeConsoleSidebarOpen } from '../../layout/consoleSidebarRail.js'; +import { ChromeBannerHost } from '../../layout/chromeBannerHost.js'; +import { ConnectionBanner } from '../../layout/ConnectionBanner.js'; +import { HomeCommandPalette, HomeLayout } from '../home/HomeLayout.js'; + +/** Home's `app`, `data` and `features`: none (module constants, as Home's). */ +const NO_SCOPE_INPUT: Record = {}; + +export interface DocsPortalShellProps { + children: React.ReactNode; + /** Signed-in user id, for the AI drawer (as `HomeLayout` takes it). */ + userId?: string; +} + +/** + * The data adapter's connection state, as `AppContent` reads it for an app's + * layout: its current answer, then each change it reports. `undefined` with no + * adapter, or one that reports none. + */ +function useAdapterConnectionState(dataSource: unknown): ConnectionState | undefined { + const adapter = dataSource as { + getConnectionState?: () => ConnectionState; + onConnectionStateChange?: (listener: (event: { state: ConnectionState }) => void) => () => void; + } | null; + const subscribe = useCallback( + (onChange: () => void) => adapter?.onConnectionStateChange?.(() => onChange()) ?? (() => {}), + [adapter], + ); + const read = useCallback(() => adapter?.getConnectionState?.(), [adapter]); + return useSyncExternalStore(subscribe, read, read); +} + +/** Inside the sidebar provider: the window's width decides the sidebar's start state, as in an app. */ +function DocsPortalShellInner({ children }: { children: React.ReactNode }) { + useResponsiveSidebar(); + return <>{children}; +} + +function DesktopDocsPortalShell({ children, userId }: DocsPortalShellProps) { + // Before `AppShell`'s sidebar provider reads its cookie, as `ConsoleLayout` + // does: a narrow window's first frame is already collapsed. + useState(primeConsoleSidebarOpen); + const { setContext, currentAppName } = useNavigationContext(); + const { user } = useAuth(); + const expressionUser = useMemo(() => buildExpressionUser(user), [user]); + const { apps } = useMetadata(); + const dataSource = useAdapter(); + const connectionState = useAdapterConnectionState(dataSource); + const navigate = useNavigate(); + const { enabled: showChatbot } = useAiSurfaceEnabled(); + const chatDock = useConsoleChatDock({ enabled: showChatbot, userId: userId ?? user?.id }); + + // Outside every app, as Home: the context names none, and the current app + // is read below, never set. + useEffect(() => { + setContext('home'); + }, [setContext]); + + // The app the palette searches: Home's host app, read only. With none (no + // openable app, or the list still loading) no palette is mounted and the + // sidebar draws no search field that would open nothing. + const activeApps = filterActiveApps(apps); + const hostApp = + activeApps.length > 0 + ? matchAppBySegment(activeApps, resolveHostAppSegment(activeApps, currentAppName)) + : undefined; + const openApp = (segment: string) => navigate(`/apps/${segment}`); + + return ( + + + + + } + showHeader={false} + navbar={null} + className="!p-0 overflow-y-auto overflow-x-hidden bg-muted/5 lg:flex lg:flex-col" + rightRail={chatDock.rail} + > + + + {/* The standing banners and the connection notice, at the top + of the content area and the content's width, as + `ConsoleLayout` draws them; the box keeps its height in + the inset's `lg` flex column. */} +
+ + +
+
+ + {children} +
+
+
+ {chatDock.sheet} +
+ {hostApp ? ( + + ) : null} +
+
+
+
+ ); +} + +/** + * `/docs…`'s frame: the app-less shell from 768 px up, Home's docs frame on a + * phone (see the module doc). + */ +export function DocsPortalShell({ children, userId }: DocsPortalShellProps) { + const phone = usePhoneViewport(); + if (phone) { + return ( + + {children} + + ); + } + return {children}; +} diff --git a/ui/packages/app-shell/src/console/docs/__tests__/DocsPortalShell-37197.test.tsx b/ui/packages/app-shell/src/console/docs/__tests__/DocsPortalShell-37197.test.tsx new file mode 100644 index 00000000000..1ddd68e8ed1 --- /dev/null +++ b/ui/packages/app-shell/src/console/docs/__tests__/DocsPortalShell-37197.test.tsx @@ -0,0 +1,323 @@ +// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license. + +/** + * objectstack#37197 — the docs portal (`/docs…`) draws in an app-less variant + * of the app shell from 768 px up: the shell's sidebar in its `docsPortal` + * mode (a neutral head, the docs tree as the body), no top bar, the page + * header's app-less button group and the expand button, and no app guessed — + * the navigation context stays Home's, nothing is written to the current or + * the last app, and the help menu names no app's docs whatever the URL or the + * app open before. A phone keeps Home's frame with the docs bar (the PHONE + * CONTROL in every block). + * + * Harness: the real `DocsPortalShell`, `@object-ui/layout`'s real `AppShell`, + * the real `ShellPageActionsScope`, the real docs-navigation slot and the real + * `NavigationProvider`. The sidebar, Home's layout and palette, the help menu + * and the AI drawer are stubs that report what they were handed. + */ + +import '@testing-library/jest-dom/vitest'; +import { afterEach, 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'; +import { useSidebar } from '@object-ui/components'; +// The shell's reach includes the palette's lazy record preview +// (`import('@object-ui/plugin-detail')`): pay that load during collection. +import '@object-ui/plugin-detail'; + +const rememberApp = vi.hoisted(() => vi.fn()); +/** The data adapter the shell reads its connection state from; none unless a test sets one. */ +const adapter = vi.hoisted(() => ({ value: null as null | { getConnectionState: () => string; onConnectionStateChange: () => () => void } })); + +vi.mock('../../../hooks/useAiSurface', () => ({ + useAiSurfaceEnabled: () => ({ enabled: false, isLoading: false }), +})); +vi.mock('../../../layout/useConsoleChatDock', () => ({ + useConsoleChatDock: () => ({ control: null, rail: null, sheet: null }), +})); +// The one app carries its own brand: the portal must not take it (design point 5). +vi.mock('../../../providers/MetadataProvider', () => ({ + useMetadata: () => ({ + apps: [ + { + name: 'crm', + label: 'CRM', + active: true, + _packageId: 'com.acme.crm', + navigation: [], + branding: { primaryColor: '#e11d48', accentColor: '#f59e0b' }, + }, + ], + }), +})); +vi.mock('../../../providers/AdapterProvider', () => ({ useAdapter: () => adapter.value })); +vi.mock('../../../providers/ExpressionProvider', () => ({ + ExpressionProvider: ({ children }: { children: React.ReactNode }) => <>{children}, +})); +// A tripwire only: nothing the portal draws calls it, and the last-app check in +// storage is what carries the "no app remembered" pin. A frame that remembers +// an app (as an app's layout does) would call it, and the assertions on it +// would go red with the storage check. +vi.mock('../../../context/LastAppProvider', () => ({ + useLastApp: () => ({ lastApp: null, rememberApp }), +})); +vi.mock('../../../layout/UnifiedSidebar', async () => { + const { SidebarDocsNavTarget } = await import('../../../layout/sidebarDocsNavSlot'); + return { + UnifiedSidebar: (props: { docsPortal?: boolean; activeAppName?: string; docsNav?: boolean }) => ( +
+ +
+ ), + }; +}); +vi.mock('../../home/HomeLayout', () => ({ + HomeLayout: ({ variant, children }: { variant?: string; children: React.ReactNode }) => ( +
+
+ {children} +
+ ), + HomeCommandPalette: () =>
, +})); +vi.mock('../../../layout/HelpMenu', () => ({ + HelpMenu: (props: { inApp: boolean; appPackageId?: string }) => ( +
+ ), +})); + +import { DocsPortalShell } from '../DocsPortalShell'; +import { NavigationProvider, useNavigationContext } from '../../../context/NavigationContext'; +import { SidebarDocsNav } from '../../../layout/sidebarDocsNavSlot'; +import { useShellPageActionsSlot, useShellSidebarExpandSlot } from '../../../layout/shellPageActionsSlot'; +import { ChromeBannerSlot } from '../../../layout/chromeBannerHost'; + +function setWidth(width: number) { + Object.defineProperty(window, 'innerWidth', { value: width, configurable: true, writable: true }); +} + +/** What the navigation context says while the portal is up. */ +function ContextProbe() { + const { context, currentAppName } = useNavigationContext(); + return
; +} + +/** An app the person had open before the portal, as an app's layout leaves it. */ +function OpenedBefore({ app }: { app: string }) { + const { setCurrentAppName } = useNavigationContext(); + React.useEffect(() => setCurrentAppName(app), [app, setCurrentAppName]); + return null; +} + +/** A docs page as `DocShell` draws one: its tree into the sidebar, its header from the shell's slots. */ +function DocsPageStandIn() { + const renderActions = useShellPageActionsSlot(); + const renderExpand = useShellSidebarExpandSlot(); + const { setOpen } = useSidebar(); + return ( +
+ + + + {renderActions || renderExpand ? ( +
+ {renderExpand?.()} + {renderActions?.({})} +
+ ) : null} + +
+ ); +} + +function PhonePageStandIn() { + const renderActions = useShellPageActionsSlot(); + return ( +
+ + + + {renderActions ?
: null} +
+ ); +} + +function mountAt(path: string, width: number, options: { openedBefore?: string; banner?: boolean } = {}) { + setWidth(width); + const phone = width < 768; + return render( + + + {options.openedBefore ? : null} + {/* A standing banner, mounted above the routes as `ConsoleShell` mounts them. */} + {options.banner ? ( +
+ +
Impersonating
+
+
+ ) : null} + + {phone ? : } +
+
, + ); +} + +const PORTAL_PATHS = ['/docs', '/docs/crm', '/docs/crm/crm_intro']; + +afterEach(() => { + cleanup(); + rememberApp.mockClear(); + adapter.value = null; + for (const name of ['--primary', '--accent', '--ring', '--brand-primary']) document.documentElement.style.removeProperty(name); + document.cookie = 'sidebar_state=; path=/; max-age=0'; + window.localStorage.clear(); + setWidth(1440); +}); + +describe('the docs portal draws in the app-less shell from 768 px up (objectstack#37197)', () => { + it.each(PORTAL_PATHS)('%s at 768 and 1440 px: the shell sidebar in its portal mode, the docs tree as its body, no top bar', (path) => { + for (const width of [768, 1440]) { + mountAt(path, width); + expect(document.querySelectorAll('header'), `${width} px`).toHaveLength(0); + expect(screen.queryByTestId('home-layout'), `${width} px`).toBeNull(); + const sidebar = screen.getByTestId('sidebar-stub'); + expect(sidebar, `${width} px`).toHaveAttribute('data-docs-portal', 'true'); + expect(sidebar, `${width} px`).toHaveAttribute('data-active-app', ''); + expect(sidebar, `${width} px`).toHaveAttribute('data-docs-nav', 'false'); + expect(within(sidebar).getByTestId('portal-tree'), `${width} px`).toBeInTheDocument(); + expect(within(screen.getByTestId('page')).queryByTestId('portal-tree'), `${width} px`).toBeNull(); + expect(screen.getByTestId('docs-portal-shell'), `${width} px`).toContainElement(screen.getByTestId('page')); + cleanup(); + } + }); + + it.each(PORTAL_PATHS)('PHONE CONTROL — %s at 390 px keeps Home\'s frame with the docs bar, no sidebar', (path) => { + mountAt(path, 390); + expect(screen.getByTestId('home-layout')).toHaveAttribute('data-variant', 'docs'); + expect(screen.getByTestId('docs-bar-stub')).toBeInTheDocument(); + expect(screen.queryByTestId('sidebar-stub')).toBeNull(); + expect(screen.queryByTestId('docs-portal-shell')).toBeNull(); + // No sidebar, so the page keeps nothing in a sidebar and draws no shell header. + expect(screen.queryByTestId('portal-tree')).toBeNull(); + expect(screen.queryByTestId('docs-page-header')).toBeNull(); + }); +}); + +describe('the portal guesses no app (objectstack#37197)', () => { + it('opened cold, the context is Home\'s and no current or last app is written', () => { + for (const width of [1440, 390]) { + mountAt('/docs/crm/crm_intro', width); + const probe = screen.getByTestId('nav-context'); + expect(probe, `${width} px`).toHaveAttribute('data-context', 'home'); + expect(probe, `${width} px`).toHaveAttribute('data-current-app', ''); + expect(rememberApp, `${width} px`).not.toHaveBeenCalled(); + expect(Object.keys(window.localStorage).filter((key) => /last.?app/i.test(key)), `${width} px`).toEqual([]); + cleanup(); + } + }); + + it('after an app was open, the head names none and the help menu offers no app\'s docs, even on a package-named path', () => { + mountAt('/docs/com.acme.crm/crm_intro', 1440, { openedBefore: 'crm' }); + expect(screen.getByTestId('sidebar-stub')).toHaveAttribute('data-active-app', ''); + const help = within(screen.getByTestId('docs-page-header')).getByTestId('help-stub'); + expect(help).toHaveAttribute('data-in-app', 'false'); + expect(help).toHaveAttribute('data-app-package', ''); + // The app open before stays what it was: read, never rewritten. + expect(screen.getByTestId('nav-context')).toHaveAttribute('data-current-app', 'crm'); + expect(rememberApp).not.toHaveBeenCalled(); + }); + + it('the palette is Home\'s, scoped as on Home', () => { + mountAt('/docs', 1440); + expect(screen.getByTestId('home-palette-stub')).toBeInTheDocument(); + }); +}); + +describe('the portal\'s page header carries the shell\'s group and expand button (objectstack#37197)', () => { + it('the app-less group is drawn; collapsed, the header carries the expand button and the corner fallback stays away', () => { + mountAt('/docs/crm/crm_intro', 1440); + const header = screen.getByTestId('docs-page-header'); + expect(within(header).getByTestId('shell-page-actions')).toBeInTheDocument(); + expect(screen.queryByTestId('shell-sidebar-expand')).toBeNull(); + fireEvent.click(screen.getByTestId('collapse')); + expect(header).toContainElement(screen.getByTestId('shell-sidebar-expand')); + expect(screen.queryByTestId('shell-sidebar-expand-fallback')).toBeNull(); + expect(screen.getAllByTestId('shell-sidebar-expand')).toHaveLength(1); + }); + + it('PHONE CONTROL — no group and no expand button on a phone (its bar carries them)', () => { + mountAt('/docs/crm/crm_intro', 390); + expect(screen.queryByTestId('shell-page-actions')).toBeNull(); + expect(screen.queryByTestId('shell-sidebar-expand')).toBeNull(); + }); +}); + +describe('the portal takes no app\'s brand: the default accent (objectstack#37197, design point 5)', () => { + /** The accent variables an app's brand sets on the document root (`AppShell`'s branding). */ + const brand = () => ({ + primary: document.documentElement.style.getPropertyValue('--primary'), + accent: document.documentElement.style.getPropertyValue('--accent'), + }); + + it('after an app with a brand was open, the portal draws the default accent: no --primary, no --accent on the root', () => { + // What an app's shell leaves on the root while its page is up. + document.documentElement.style.setProperty('--primary', '347 77% 50%'); + document.documentElement.style.setProperty('--accent', '38 92% 50%'); + mountAt('/docs/crm/crm_intro', 1440, { openedBefore: 'crm' }); + expect(screen.getByTestId('docs-portal-shell')).toBeInTheDocument(); + expect(brand()).toEqual({ primary: '', accent: '' }); + }); + + it('PHONE CONTROL — Home\'s docs frame sets no brand either', () => { + mountAt('/docs/crm/crm_intro', 390, { openedBefore: 'crm' }); + expect(screen.getByTestId('home-layout')).toHaveAttribute('data-variant', 'docs'); + expect(brand()).toEqual({ primary: '', accent: '' }); + }); +}); + +describe('the portal\'s standing banners and connection notice sit at the top of its content (objectstack#37197)', () => { + it('at 1440 px a standing banner is drawn once, in the box at the top of the content, not above the shell', () => { + mountAt('/docs/crm/crm_intro', 1440, { banner: true }); + const banners = screen.getAllByTestId('impersonation-banner-stub'); + expect(banners).toHaveLength(1); + const box = screen.getByTestId('docs-portal-banners'); + expect(box).toContainElement(banners[0]); + expect(screen.getByTestId('shell-banner-slot')).not.toContainElement(banners[0]); + // The box comes before the page, at the top of the content area. + expect(box.compareDocumentPosition(screen.getByTestId('page')) & Node.DOCUMENT_POSITION_FOLLOWING).toBeTruthy(); + }); + + it('a lost connection is a notice in that box; a live one draws nothing', () => { + adapter.value = { getConnectionState: () => 'disconnected', onConnectionStateChange: () => () => {} }; + mountAt('/docs/crm/crm_intro', 1440); + const notice = screen.getByTestId('console-connection-banner'); + expect(screen.getByTestId('docs-portal-banners')).toContainElement(notice); + expect(notice).toHaveTextContent(/disconnected/i); + cleanup(); + adapter.value = { getConnectionState: () => 'connected', onConnectionStateChange: () => () => {} }; + mountAt('/docs/crm/crm_intro', 1440); + expect(screen.queryByTestId('console-connection-banner')).toBeNull(); + }); + + it('PHONE CONTROL — on a phone the banner stays where the shell mounts it, drawn once, and no notice box is mounted', () => { + adapter.value = { getConnectionState: () => 'disconnected', onConnectionStateChange: () => () => {} }; + mountAt('/docs/crm/crm_intro', 390, { banner: true }); + const banners = screen.getAllByTestId('impersonation-banner-stub'); + expect(banners).toHaveLength(1); + expect(screen.getByTestId('shell-banner-slot')).toContainElement(banners[0]); + expect(screen.queryByTestId('docs-portal-banners')).toBeNull(); + expect(screen.queryByTestId('console-connection-banner')).toBeNull(); + }); +}); diff --git a/ui/packages/app-shell/src/console/home/HomeLayout.tsx b/ui/packages/app-shell/src/console/home/HomeLayout.tsx index eb58f7446c3..9a447ca08bb 100644 --- a/ui/packages/app-shell/src/console/home/HomeLayout.tsx +++ b/ui/packages/app-shell/src/console/home/HomeLayout.tsx @@ -97,7 +97,7 @@ function useHostAppPaletteObjects(hostApp: Record): any[] { return metadata.objects ?? NO_OBJECTS; } -interface HomeCommandPaletteProps { +export interface HomeCommandPaletteProps { apps: any[]; hostApp: Record; onAppChange: (segment: string) => void; @@ -118,8 +118,12 @@ function OpenedHomeCommandPalette({ apps, hostApp, onAppChange, dataSource }: Ho ); } -/** Home's palette: mounted from its first open (see the module doc). */ -function HomeCommandPalette(props: HomeCommandPaletteProps) { +/** + * Home's palette: mounted from its first open (see the module doc). The docs + * portal's desktop frame (`DocsPortalShell`) mounts the same one, for the same + * reason: it is outside every app too. + */ +export function HomeCommandPalette(props: HomeCommandPaletteProps) { const { open } = useCommandPalette(); const [opened, setOpened] = useState(open); if (open && !opened) setOpened(true); diff --git a/ui/packages/app-shell/src/index.ts b/ui/packages/app-shell/src/index.ts index fc5897709a5..72adc251433 100644 --- a/ui/packages/app-shell/src/index.ts +++ b/ui/packages/app-shell/src/index.ts @@ -366,6 +366,9 @@ export { export { useInvitationSignUpJoin, type InvitationSignUpJoin } from './console/auth/invitationSignUpJoin.js'; export { ForgotPasswordPage as DefaultForgotPasswordPage } from './console/auth/ForgotPasswordPage.js'; export { HomeLayout as DefaultHomeLayout, HomeLayout } from './console/home/HomeLayout.js'; +// objectstack#37197 — the docs portal's frame: the app-less shell from 768 px up. +export { DocsPortalShell } from './console/docs/DocsPortalShell.js'; +export type { DocsPortalShellProps } from './console/docs/DocsPortalShell.js'; export { HomePage as DefaultHomePage, HomePage } from './console/home/HomePage.js'; // Whether the signed-in person has connected an AI assistant (or holds a // working API key), and where Connect an AI Assistant opens: the one read and diff --git a/ui/packages/app-shell/src/layout/ShellPageActions.tsx b/ui/packages/app-shell/src/layout/ShellPageActions.tsx index 96c94afa33e..af74d95ef8e 100644 --- a/ui/packages/app-shell/src/layout/ShellPageActions.tsx +++ b/ui/packages/app-shell/src/layout/ShellPageActions.tsx @@ -28,9 +28,13 @@ * headers gets the same button at the content's top-left corner * (`ShellSidebarExpandFallback`). * - * Outside a scope (Home, the organization pages, Studio, the docs frame, a - * test that mounts a page bare) the group is never drawn, and on a phone - * neither: the phone has its own bar. + * Outside a scope (Home, the organization pages, Studio, a test that mounts a + * page bare) the group is never drawn, and on a phone neither: the phone has + * its own bar. The docs portal's desktop frame (`DocsPortalShell`, + * objectstack#37197) mounts an `appless` scope: the page is in no app, so the + * group names none — its help menu offers no app's docs and no app's + * shortcuts, as the portal's old bar did — however the URL reads or whichever + * app was open before. * * The parts are the top bar's own: the AI button IS `AssistantTopBarButton`, * and the help menu IS `HelpMenu`. @@ -100,17 +104,22 @@ const ExpandHeaderRegistryContext = React.createContext - + {children} @@ -218,6 +227,23 @@ function renderShellPageActionsGroup(props: ShellPageActionsSlotProps): React.Re return ; } +/** The app-less scope's slot value: one stable function, never remade. */ +function renderApplessShellPageActionsGroup(props: ShellPageActionsSlotProps): React.ReactNode { + return ; +} + +/** The group on a page in no app: the assistant, and help without an app's docs or shortcuts. */ +function ApplessShellPageActionsGroup({ comments }: ShellPageActionsProps) { + const { enabled: aiEnabled } = useAiSurfaceEnabled(); + return ( +
+ {comments} + {aiEnabled && } + +
+ ); +} + function ShellPageActionsGroup({ comments }: ShellPageActionsProps) { // The app only: the group draws no Studio entry, so it reads no gate. const { currentApp } = useAppStudioEntry(false); diff --git a/ui/packages/app-shell/src/layout/SidebarAppMenu.tsx b/ui/packages/app-shell/src/layout/SidebarAppMenu.tsx index ab346d49f42..d862bb30dcc 100644 --- a/ui/packages/app-shell/src/layout/SidebarAppMenu.tsx +++ b/ui/packages/app-shell/src/layout/SidebarAppMenu.tsx @@ -43,7 +43,7 @@ import { DropdownMenuTrigger, Input, } from '@object-ui/components'; -import { Check, ChevronDown, Eye, Pencil, PencilRuler, Plus } from 'lucide-react'; +import { BookOpen, Check, ChevronDown, Eye, Pencil, PencilRuler, Plus } from 'lucide-react'; import { useObjectTranslation } from '@object-ui/i18n'; import { useAuth } from '@object-ui/auth'; import { useMetadata } from '../providers/MetadataProvider.js'; @@ -156,6 +156,77 @@ function AddAppSubmenu() { ); } +/** + * The menu's app list: the viewer's apps, with a search field above them once + * there are more than {@link APP_MENU_SEARCH_FROM}. `activeAppName` is checked + * and choosing it does nothing; without one (the docs portal, which is in no + * app) no row is checked. + */ +function AppMenuList({ + apps, + launcherApps, + activeAppName, + query, + onQueryChange, + onAppChange, +}: { + apps: NonNullable['apps']>; + launcherApps: ReturnType['apps']; + activeAppName?: string; + query: string; + onQueryChange: (query: string) => void; + onAppChange: (segment: string) => void; +}) { + const { t } = useObjectTranslation(); + const { appLabel } = useServedAppLabel(); + const searchable = launcherApps.length > APP_MENU_SEARCH_FROM; + const needle = query.trim().toLocaleLowerCase(); + const listed = searchable && needle + ? launcherApps.filter((app: any) => appLabel(app).toLocaleLowerCase().includes(needle)) + : launcherApps; + return ( + <> + {searchable && ( +
event.stopPropagation()}> + onQueryChange(event.target.value)} + placeholder={t('layout.appSwitcher.searchApps', { defaultValue: 'Search apps…' })} + aria-label={t('layout.appSwitcher.searchApps', { defaultValue: 'Search apps…' })} + data-testid="sidebar-app-menu-search" + className="h-8" + autoFocus + /> +
+ )} +
+ {listed.map((app: any) => { + const isActive = activeAppName !== undefined && app.name === activeAppName; + return ( + { + if (!isActive) onAppChange(appAddressSegment(apps, app) ?? app.name); + }} + className="flex items-center gap-2.5 py-2" + data-testid={`sidebar-app-menu-row-${app.name}`} + > + + {appLabel(app)} + {isActive && } + + ); + })} + {listed.length === 0 && ( +
+ {t('layout.appSwitcher.noAppsMatch', { defaultValue: 'No apps match' })} +
+ )} +
+ + ); +} + export interface SidebarAppMenuProps { activeAppName: string; /** Opens the app at this address segment (the host asks first about unsaved edits). */ @@ -163,7 +234,6 @@ export interface SidebarAppMenuProps { } export function SidebarAppMenu({ activeAppName, onAppChange }: SidebarAppMenuProps) { - const { t } = useObjectTranslation(); const { appLabel } = useServedAppLabel(); const { apps: metadataApps } = useMetadata(); const apps = metadataApps || []; @@ -181,12 +251,6 @@ export function SidebarAppMenu({ activeAppName, onAppChange }: SidebarAppMenuPro if (!activeApp) return null; const activeLabel = appLabel(activeApp); - const searchable = launcherApps.length > APP_MENU_SEARCH_FROM; - const needle = query.trim().toLocaleLowerCase(); - const listed = searchable && needle - ? launcherApps.filter((app: any) => appLabel(app).toLocaleLowerCase().includes(needle)) - : launcherApps; - return ( { if (!open) setQuery(''); }}> @@ -202,43 +266,14 @@ export function SidebarAppMenu({ activeAppName, onAppChange }: SidebarAppMenuPro - {searchable && ( -
event.stopPropagation()}> - setQuery(event.target.value)} - placeholder={t('layout.appSwitcher.searchApps', { defaultValue: 'Search apps…' })} - aria-label={t('layout.appSwitcher.searchApps', { defaultValue: 'Search apps…' })} - data-testid="sidebar-app-menu-search" - className="h-8" - autoFocus - /> -
- )} -
- {listed.map((app: any) => { - const isActive = app.name === activeApp.name; - return ( - { - if (!isActive) onAppChange(appAddressSegment(apps, app) ?? app.name); - }} - className="flex items-center gap-2.5 py-2" - data-testid={`sidebar-app-menu-row-${app.name}`} - > - - {appLabel(app)} - {isActive && } - - ); - })} - {listed.length === 0 && ( -
- {t('layout.appSwitcher.noAppsMatch', { defaultValue: 'No apps match' })} -
- )} -
+ {(enterDesignMode || studioEntry || mayAddApp) && } {enterDesignMode && } {studioEntry && } @@ -247,3 +282,53 @@ export function SidebarAppMenu({ activeAppName, onAppChange }: SidebarAppMenuPro
); } + +/** + * objectstack#37197 — the docs portal's first row (`DocsPortalShell`): a + * neutral 「Documentation」 head where an app's name is, since the portal is + * in no app. It opens the same app list as the app menu, under 「Your apps」, + * with no row checked, and 「Add app」 for the viewers who may build. The + * app-scoped rows (「Design layout」, 「Edit app」) are not drawn: there is no + * app here for them to act on. Choosing an app opens it. + */ +export function SidebarDocsPortalMenu({ onAppChange }: { onAppChange: (segment: string) => void }) { + const { t } = useObjectTranslation(); + const { apps: metadataApps } = useMetadata(); + const apps = metadataApps || []; + const { apps: launcherApps } = useLauncherApps(apps); + const mayAddApp = useMayAddApp(); + const [query, setQuery] = React.useState(''); + const label = t('help.documentation', { defaultValue: 'Documentation' }); + return ( + { if (!open) setQuery(''); }}> + + + + +
+ {t('layout.appSwitcher.yourApps', { defaultValue: 'Your apps' })} +
+ + {mayAddApp && } + {mayAddApp && } +
+
+ ); +} diff --git a/ui/packages/app-shell/src/layout/UnifiedSidebar.tsx b/ui/packages/app-shell/src/layout/UnifiedSidebar.tsx index 68c20d7ded9..4af4adf5a5e 100644 --- a/ui/packages/app-shell/src/layout/UnifiedSidebar.tsx +++ b/ui/packages/app-shell/src/layout/UnifiedSidebar.tsx @@ -80,7 +80,7 @@ import { import { AppMark } from './AppMark.js'; import { CONSOLE_BELOW_TOP_BAR } from './consoleTopBar.js'; import { LocalizedSidebarTrigger } from './LocalizedSidebarTrigger.js'; -import { SidebarAppMenu } from './SidebarAppMenu.js'; +import { SidebarAppMenu, SidebarDocsPortalMenu } from './SidebarAppMenu.js'; import { InboxBell } from './InboxBell.js'; import { AccountMenu } from './AccountMenu.js'; import { useCommandPalette, useCommandPaletteProviderMounted } from '../context/CommandPaletteProvider.js'; @@ -194,6 +194,19 @@ interface UnifiedSidebarProps { * recent items (objectstack#35424). The head and the foot are unchanged. */ docsNav?: boolean; + /** + * objectstack#37197 — the docs portal (`/docs…`, `DocsPortalShell`), a page + * in no app: from 768 px up the shell's head and foot as in an app, with a + * neutral 「Documentation」 menu (the viewer's apps, none checked) where an + * app's name menu is, and the docs tree the page draws as the body. Nothing + * here resolves, marks or remembers an app. + */ + docsPortal?: boolean; + /** + * With `docsPortal`: whether a command palette is mounted for the search + * field to open (the portal mounts Home's, which needs a host app). + */ + docsPortalSearch?: boolean; } function isMetadataDirectoryItem(item: NavigationItem): boolean { @@ -211,7 +224,14 @@ function isOverviewGroup(item: NavigationItem): boolean { return id === 'overview' || label === 'overview'; } -export function UnifiedSidebar({ activeAppName, onAppChange, railOverlay = false, docsNav = false }: UnifiedSidebarProps) { +export function UnifiedSidebar({ + activeAppName, + onAppChange, + railOverlay = false, + docsNav = false, + docsPortal = false, + docsPortalSearch = false, +}: UnifiedSidebarProps) { const { isMobile, setOpenMobile } = useSidebar(); const location = useLocation(); const { t, language } = useObjectTranslation(); @@ -244,14 +264,16 @@ export function UnifiedSidebar({ activeAppName, onAppChange, railOverlay = false const sidebarWidth = dragWidth ?? keptWidth; // 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. - const shellChrome = rail.desktop && context === 'app'; + // search and the bell in its head, and the account at its foot. The docs + // portal is the one page in no app that draws the same (objectstack#37197). + const shellChrome = rail.desktop && (context === 'app' || docsPortal); // objectstack#36362 — while the design mode is on, its bar is above the // sidebar, and the menu shows the app's own entries only: the person's // Favorites are not the app's to change. const designMode = useDesignModeActive(); const { openCommandPalette } = useCommandPalette(); - const hasCommandPalette = useCommandPaletteProviderMounted(); + const paletteMounted = useCommandPaletteProviderMounted(); + const hasCommandPalette = paletteMounted && (!docsPortal || docsPortalSearch); // Swipe-from-left-edge gesture to open sidebar on mobile React.useEffect(() => { @@ -805,13 +827,19 @@ export function UnifiedSidebar({ activeAppName, onAppChange, railOverlay = false
)} - {shellChrome && activeApp && ( + {shellChrome && (activeApp || docsPortal) && (
- confirmUnsavedLeave(() => onAppChange?.(segment))} - /> + {docsPortal ? ( + // objectstack#37197 — the portal is in no app: a neutral head + // that opens the app list, with no app checked. + confirmUnsavedLeave(() => onAppChange?.(segment))} /> + ) : ( + confirmUnsavedLeave(() => onAppChange?.(segment))} + /> + )} )} - {docsNav && context === 'app' && activeApp ? ( + {docsPortal || (docsNav && context === 'app' && activeApp) ? ( // objectstack#37150 — an app's docs page: the docs' own navigation, - // drawn here by the page (it carries its own landmark). + // drawn here by the page (it carries its own landmark). The docs + // portal's tree, likewise (objectstack#37197). ) : ( <> diff --git a/ui/packages/app-shell/src/layout/__tests__/ConsoleLayout.noTopBar-36112.test.tsx b/ui/packages/app-shell/src/layout/__tests__/ConsoleLayout.noTopBar-36112.test.tsx index c4492563164..4a9c8e1eee8 100644 --- a/ui/packages/app-shell/src/layout/__tests__/ConsoleLayout.noTopBar-36112.test.tsx +++ b/ui/packages/app-shell/src/layout/__tests__/ConsoleLayout.noTopBar-36112.test.tsx @@ -6,7 +6,10 @@ * the top of the content area, the page header carries the sidebar's expand * button while the sidebar is collapsed, and a route with no shell header gets * that button at the content's corner. A phone keeps its bar. An app's docs - * pages are no exception from 768 px up (objectstack#37150). + * pages are no exception from 768 px up (objectstack#37150): the connection + * notice is drawn above them too, and their own header (`DocShell`'s, drawn + * from the shell's expand slot) carries the expand button, so the corner + * fallback stays away (objectstack#37197 pins both). * * Harness: the real `ConsoleLayout` with its real `@object-ui/layout` * `AppShell` and the real `ShellPageActionsScope`; the sidebar, the app bar @@ -41,6 +44,7 @@ import { ConsoleLayout } from '../ConsoleLayout'; import { ChromeBannerSlot } from '../chromeBannerHost'; import { PageHeader } from '../PageHeader'; import { NavigationProvider } from '../../context/NavigationContext'; +import { useShellSidebarExpandSlot } from '../shellPageActionsSlot'; const APP = { name: 'crm', label: 'CRM', active: true, navigation: [] }; @@ -170,3 +174,40 @@ describe('an app draws no top bar from 768 px up (objectstack#36112)', () => { expect(fallback).toContainElement(screen.getByTestId('shell-sidebar-expand')); }); }); + +/** + * The docs pages' header as `DocShell` draws it (the console's docs frame, + * outside this package): the shell's expand slot at its left edge. + */ +function DocsPageHeaderStandIn() { + const renderExpand = useShellSidebarExpandSlot(); + return renderExpand ?
{renderExpand()}
: null; +} + +describe('an app\'s docs pages keep the shell\'s notices and expand button from 768 px up (objectstack#37150, pinned by objectstack#37197)', () => { + it('a lost connection is a notice at the top of the content area on a docs page; a phone draws none there', () => { + mountAt('/apps/crm/docs/crm_manual/intro', 1440,
Manual
, { connectionState: 'disconnected' }); + const notice = screen.getByTestId('console-connection-banner'); + expect(screen.getByTestId('console-banners')).toContainElement(notice); + expect(notice).toHaveTextContent('Disconnected'); + cleanup(); + // PHONE CONTROL — the app bar carries the connection there; no notice in the content. + mountAt('/apps/crm/docs/crm_manual/intro', 390,
Manual
, { connectionState: 'disconnected' }); + expect(screen.queryByTestId('console-connection-banner')).toBeNull(); + expect(screen.getByTestId('app-bar')).toBeInTheDocument(); + }); + + it('collapsed, the docs header carries the expand button and the corner fallback is not drawn; a phone draws neither', () => { + mountAt('/apps/crm/docs/crm_manual/intro', 1440, ); + expect(screen.queryByTestId('shell-sidebar-expand')).toBeNull(); + fireEvent.click(screen.getByTestId('collapse')); + expect(screen.getByTestId('docs-page-header')).toContainElement(screen.getByTestId('shell-sidebar-expand')); + expect(screen.queryByTestId('shell-sidebar-expand-fallback')).toBeNull(); + expect(screen.getAllByTestId('shell-sidebar-expand')).toHaveLength(1); + cleanup(); + // PHONE CONTROL — no sidebar on a phone's docs page, so no expand slot and no fallback. + mountAt('/apps/crm/docs/crm_manual/intro', 390, ); + expect(screen.queryByTestId('docs-page-header')).toBeNull(); + expect(screen.queryByTestId('shell-sidebar-expand-fallback')).toBeNull(); + }); +}); diff --git a/ui/packages/app-shell/src/layout/__tests__/SidebarAppMenu-36112.test.tsx b/ui/packages/app-shell/src/layout/__tests__/SidebarAppMenu-36112.test.tsx index 6c95e33cd90..7b4e2480009 100644 --- a/ui/packages/app-shell/src/layout/__tests__/SidebarAppMenu-36112.test.tsx +++ b/ui/packages/app-shell/src/layout/__tests__/SidebarAppMenu-36112.test.tsx @@ -35,6 +35,11 @@ * closed the catalog keeps `ask` and drops `build`: the door gives way to 「New * in Studio」, the template and the marketplace stay. The real * `useAiSurfaceEnabled` reads a stubbed catalog (`useAgents`). + * + * objectstack#37197 — the docs portal's head (`SidebarDocsPortalMenu`): a + * neutral 「Documentation」 where an app's name is, opening the same list + * under 「Your apps」 with no row checked, and 「Add app」 only; no + * app-scoped row. Real subject added: `SidebarDocsPortalMenu`. */ import '@testing-library/jest-dom/vitest'; @@ -115,7 +120,7 @@ vi.mock('../../runtime-config', async (importOriginal) => ({ })); import { builtInLocales } from '@object-ui/i18n/locales'; -import { SidebarAppMenu, APP_MENU_SEARCH_FROM } from '../SidebarAppMenu'; +import { SidebarAppMenu, SidebarDocsPortalMenu, APP_MENU_SEARCH_FROM } from '../SidebarAppMenu'; import { DesignModeProvider, useDesignModeController, useHoldDesignModeOut } from '../designMode'; const CRM = { name: 'crm', label: 'CRM', icon: 'flame', _packageId: 'com.acme.crm' }; @@ -536,3 +541,56 @@ describe('「Design layout」 refuses while a dashboard or report editor is open expect(packs['zh-Hans'].designMode.editorOpen).toContain(packs['zh-Hans'].designMode.title); }); }); + +describe('the docs portal\'s head names no app and only switches apps (objectstack#37197)', () => { + function renderPortalMenu(onAppChange = vi.fn()) { + render( + + + , + ); + return onAppChange; + } + const portalMenu = () => within(screen.getByTestId('sidebar-docs-portal-menu')); + + it('reads 「Documentation」, not an app, and lists every app under 「Your apps」 with none checked', () => { + apps = [CRM, SERVICE, SETUP]; + renderPortalMenu(); + const trigger = screen.getByTestId('sidebar-docs-portal-menu-trigger'); + expect(trigger).toHaveTextContent('Documentation'); + for (const app of [CRM, SERVICE, SETUP]) expect(trigger).not.toHaveTextContent(app.label); + expect(portalMenu().getByText('Your apps')).toBeInTheDocument(); + for (const name of ['crm', 'service', 'setup']) { + const row = portalMenu().getByTestId(`sidebar-app-menu-row-${name}`); + expect(row.querySelector('svg.lucide-check'), name).toBeNull(); + } + // The app menu itself is not drawn here. + expect(screen.queryByTestId('sidebar-app-menu-trigger')).toBeNull(); + }); + + it('choosing any app opens it by its address', () => { + apps = [CRM, SERVICE]; + const onAppChange = renderPortalMenu(); + fireEvent.click(portalMenu().getByTestId('sidebar-app-menu-row-crm')); + fireEvent.click(portalMenu().getByTestId('sidebar-app-menu-row-service')); + expect(onAppChange.mock.calls).toEqual([['com.acme.crm'], ['service']]); + }); + + it('a workspace admin who may author gets 「Add app」 and no app-scoped row', () => { + apps = [CRM]; + admin = true; + renderPortalMenu(); + expect(portalMenu().getByTestId('sidebar-app-menu-add')).toHaveTextContent('Add app'); + for (const id of ['sidebar-app-menu-design-layout', 'sidebar-app-menu-edit-app', 'sidebar-app-menu-view-in-studio']) { + expect(portalMenu().queryByTestId(id), id).toBeNull(); + } + for (const text of ['Design layout', 'Edit app', 'View in Studio']) expect(portalMenu().queryByText(text)).toBeNull(); + }); + + it('control: a member gets the list and no 「Add app」', () => { + apps = [CRM]; + renderPortalMenu(); + expect(portalMenu().getByTestId('sidebar-app-menu-row-crm')).toBeInTheDocument(); + expect(portalMenu().queryByTestId('sidebar-app-menu-add')).toBeNull(); + }); +}); diff --git a/ui/packages/app-shell/src/layout/__tests__/UnifiedSidebar.footerSlot-36739.test.tsx b/ui/packages/app-shell/src/layout/__tests__/UnifiedSidebar.footerSlot-36739.test.tsx index 40cd941a4f4..b8e4f5f308d 100644 --- a/ui/packages/app-shell/src/layout/__tests__/UnifiedSidebar.footerSlot-36739.test.tsx +++ b/ui/packages/app-shell/src/layout/__tests__/UnifiedSidebar.footerSlot-36739.test.tsx @@ -8,6 +8,10 @@ * after the app's menu on the app's home page (`'phoneAppHome'`). Dropping * either line in `UnifiedSidebar` fails one of the tests below. * + * objectstack#37197 — the docs portal (`docsPortal`), in no app: the shell's + * head with a neutral 「Documentation」 menu instead of the app's, the docs + * tree as the body, the account foot; the remembered app is never named. + * * Harness: the mocks of `UnifiedSidebar.phoneAppHome-35881.test.tsx`; * `@object-ui/layout` and `@object-ui/components` stay REAL, under the real * `SidebarProvider`. @@ -129,8 +133,10 @@ vi.mock('../../hooks/useNavPins', async () => { vi.mock('../../hooks/useNavActionDispatch', () => ({ useNavActionDispatch: () => vi.fn(), })); +// An app route's context by default; the docs portal's block sets Home's. +const nav = vi.hoisted(() => ({ value: { context: 'app', currentAppName: 'sales' as string | undefined } })); vi.mock('../../context/NavigationContext', () => ({ - useNavigationContext: () => ({ context: 'app', currentAppName: 'sales' }), + useNavigationContext: () => nav.value, })); vi.mock('../ContextSelectors', () => ({ useAppContextSelectors: () => ({ contextValues: {}, element: null }), @@ -146,6 +152,7 @@ import { UnifiedSidebar } from '../UnifiedSidebar'; import { PhoneAppHome, PhoneAppHomeSlotProvider } from '../PhoneAppHome'; import { SidebarFooterSlotProvider, type SidebarFooterSlotPlace } from '../sidebarFooterSlot'; import { SidebarDocsNav, SidebarDocsNavSlotProvider } from '../sidebarDocsNavSlot'; +import { CommandPaletteProvider } from '../../context/CommandPaletteProvider'; function setViewport(width: number, height: number) { Object.defineProperty(window, 'innerWidth', { configurable: true, writable: true, value: width }); @@ -176,6 +183,7 @@ function renderSidebar({ width, slot = hostSlot as ((where: SidebarFooterSlotPla afterEach(() => { cleanup(); + nav.value = { context: 'app', currentAppName: 'sales' }; drawn.length = 0; initialPins = []; setViewport(1024, 768); @@ -250,3 +258,66 @@ describe('an app\'s docs page: the sidebar\'s body holds the docs\' navigation ( expect(screen.getByText('Leads')).toBeInTheDocument(); }); }); + +describe('the docs portal: the shell\'s head and foot in no app, the docs tree as the body (objectstack#37197)', () => { + /** The sidebar as `DocsPortalShell` mounts it, Home's context with a remembered app, and the page's tree. */ + function renderPortal({ search = true }: { search?: boolean } = {}) { + setViewport(1440, 812); + nav.value = { context: 'home', currentAppName: 'sales' }; + return render( + + + + + + + + + + + + , + ); + } + + it('the head is 「Documentation」, not the remembered app; the body is the page\'s tree; the foot stays', () => { + renderPortal(); + const head = screen.getByTestId('sidebar-shell-head'); + expect(within(head).getByTestId('sidebar-docs-portal-menu-trigger')).toHaveTextContent('Documentation'); + expect(within(head).queryByTestId('sidebar-app-menu-trigger')).toBeNull(); + expect(within(head).queryByText('Sales')).toBeNull(); + expect(within(head).getByTestId('action:command-palette:open')).toBeInTheDocument(); + const column = screen.getByTestId('page-docs-column'); + expect(column.closest('[data-sidebar="content"]')).not.toBeNull(); + expect(screen.queryByRole('navigation', { name: 'App navigation' })).toBeNull(); + expect(screen.queryByText('Leads')).toBeNull(); + expect(document.querySelector('[data-sidebar="footer"]')).not.toBeNull(); + }); + + it('with no palette to open (no host app) the head draws no search field', () => { + renderPortal({ search: false }); + expect(within(screen.getByTestId('sidebar-shell-head')).queryByTestId('action:command-palette:open')).toBeNull(); + expect(screen.getByTestId('sidebar-docs-portal-menu-trigger')).toBeInTheDocument(); + }); + + it('CONTROL — Home\'s context without `docsPortal` draws no shell head and no docs place', () => { + setViewport(1440, 812); + nav.value = { context: 'home', currentAppName: 'sales' }; + render( + + + + + + + + + + , + ); + expect(screen.queryByTestId('sidebar-shell-head')).toBeNull(); + expect(screen.queryByTestId('page-docs-column')).toBeNull(); + }); +}); diff --git a/ui/packages/app-shell/src/providers/expressionUser.mountSites.ratchet.test.ts b/ui/packages/app-shell/src/providers/expressionUser.mountSites.ratchet.test.ts index 3854679b06c..01ae20e072e 100644 --- a/ui/packages/app-shell/src/providers/expressionUser.mountSites.ratchet.test.ts +++ b/ui/packages/app-shell/src/providers/expressionUser.mountSites.ratchet.test.ts @@ -196,14 +196,15 @@ describe('objectui#6515 — every expression mount site binds the shared `curren // against in itself — it would pass forever. The production sites are // `AppContent` and `RecordFormPage` (the provider kind; their imperative // field-list evaluators retired with objectstack#35249, when the field list - // stopped evaluating `visibleWhen`), the console's `InternalFormRoute`, and - // Home's `HomeLayout` (objectui#12700). + // stopped evaluating `visibleWhen`), the console's `InternalFormRoute`, + // Home's `HomeLayout` (objectui#12700), and the docs portal's desktop frame + // `DocsPortalShell`, which binds Home's scope (objectstack#37197). const sites = files .filter((f) => !EXEMPT.has(path.relative(repoRoot, f))) .flatMap((f) => collectSites(f, stripComments(readFileSync(f, 'utf8')))); - expect(sites.length).toBeGreaterThanOrEqual(4); + expect(sites.length).toBeGreaterThanOrEqual(5); expect(new Set(sites.map((s) => path.basename(s.file)))).toEqual( - new Set(['AppContent.tsx', 'RecordFormPage.tsx', 'InternalFormRoute.tsx', 'HomeLayout.tsx']), + new Set(['AppContent.tsx', 'RecordFormPage.tsx', 'InternalFormRoute.tsx', 'HomeLayout.tsx', 'DocsPortalShell.tsx']), ); });