Skip to content

Commit 141a826

Browse files
feat(console): an app's docs page has one navigation — the docs column — with the path to its book and the previous and next article (#36000)
<!-- claude-projects-attribution: {"github_login":"os-sales"} --> _Requested by **Sales** · [project thread](https://claude.ai/code/project/chan_01D5bWFY3rFzgJcytD5gD4Uu?thread=cmsg_01D5bWFY3rFzgJcytD5gD4UuCS24S2hYG3SFdUpRMkrGmE)_ Part of #35424 repo:objectstack#1 · os-sales · session_01L6bhgWcCSnzHX9bYADvAVH · Area: b1-CX ## 维护者速读 - 用户看到的变化:在应用里打开一篇文档,左边不再有应用菜单,只剩文档自己的一栏(顶部「← 返回〈应用〉」、搜索、这个应用的全部手册、底部「全部文档 →」);只有一条顶栏「〈应用〉 / 文档」;正文 720 px、15 px;「本页目录」随滚动高亮;文末有上一篇和下一篇;流程图可放大。应用的文档首页、空手册和找不到的页面顶部也有「← 返回〈应用〉」。 - 为什么:#35424 指出同屏三套导航、两条顶栏、标题被截断、没有上一篇和下一篇、正文太窄。 - 最坏情况:只影响显示。某个文档页如果漏了返回入口,读者只能用顶栏的应用切换器或浏览器后退;撤回这个 PR 即恢复原样。 - 需要 Sales 做的:无。「全部文档」页(第 6–9 项)是下一个 PR。 ## What changes The reading page half of #35424 (its items 1–5, design figure 25). The "All docs" page (items 6–9, figure 26) is the next PR. Inside an app, a documentation page (`/apps/<app>/docs/…`): 1. **No app menu beside the docs.** `ConsoleLayout` mounts no `UnifiedSidebar` on an app's docs routes (`isAppDocsPath`, beside `isRecordPagePath`), and the app bar draws no sidebar toggle there (its slot is held empty, as off an app). The left column is the docs' own (`DocsNav`), headed by 「← Back to <app>」 (the app the route segment addresses, by the label the app bar shows). Every other docs page inside an app (the app's docs index, a book with no articles, a book or doc not found) carries the same link at its top (`DocShell` draws `AppDocsBackLink`; the reader turns it off because its column has it), so no docs page is left without a way back. 2. **One bar.** The app bar stays and reads 「<app> / Documentation」 (a `docs` crumb in `AppHeader`, from `help.documentation`). `DocShell` draws no bar of its own inside an app, so the separate 「Documentation / <title>」 strip is gone. Above the article, the path names the book: Documentation › <book>, both links. 3. **Every book of the package in the column.** The current book open, the others folded, each with its article count; long titles wrap instead of truncating (`BookSidebar`); a 「Search docs」 field filters the column by article title and summary; 「All documentation →」 at its foot (the existing `help.allDocs` key). (The full-text search of all docs is item 9, the next PR.) 4. **「On this page」 marks the section being read** as the page scrolls (`useActiveHeading`: the last heading at or above the bar plus the headings' scroll margin; the last one once the page is scrolled to its end), and the article ends with its book's **previous / next article** cards; at either end of the book the empty side says so. 5. **Article 720 px wide at 15 px** (was ~590 px at 14 px). A Mermaid diagram gets an 「Enlarge」 control that opens it full size in a dialog: `@object-ui/plugin-markdown` adds `MermaidEnlargeContext`, which the reader provides; with no provider (every other markdown surface) a diagram renders exactly as before. The dialog's copy renames the render-id prefix (root id, scoped styles, markers), so no id appears twice while it is open. The portal reader (`/docs/<book>/<doc>`) gets the same column, path and pager; its own header bar stays until the next PR gives that page the top bar. `@object-ui/app-shell` exports `matchAppBySegment` and `useServedAppLabel` for the back link. Twelve new `help.*` keys in all 11 shipped locales (real text in each). ## Why The maintainer's topic #34571, card #35424: three navigations side by side on one screen (the app's 30-odd menu entries, the book's contents, "On this page"), a second bar under the app bar, the other books of the app reachable only through the app menu, truncated titles, no previous / next, no current section, a narrow 14 px body. ## Verification - Browser, against the showcase app (`objectstack dev --fresh`, console on vite), zh-CN, 1440 × 900, `/apps/com.example.showcase/docs/manual/showcase_tour_ui`: - before: app menu drawn, two bars, article 592 px, body 14 px, no current section; - after: no app menu (`[data-sidebar=sidebar]` absent), one bar reading 「功能展示 / 文档」, article 720 px, body 15 px; scrolled to the end, 「本页目录」 marks 「Branding」 and the pager shows 上一篇 Tour · Data / 下一篇 Tour · Automation; 32 px below the pager at the end of the scroll (no blank screen; it was 24 px on `main` here too, so the hosted environment's blank screen was not reproduced on `main`). - At 900 px the column folds into the disclosure above the path, as the book sidebar did. - Screenshots (before / after) are kept with the card's evidence for the reviewer. - Tests (new pins in the existing harnesses): - `docs-portal.test.tsx` — the in-app reader: no bar of its own; back link and 「All documentation」; the path's two links; the pager at the first and last article; the search narrowing the column and its no-match line; a package with two books lists both (current open, other folded, unfolds on click) and no other package's book. The app's docs index and a not-found book lead back to the app; the reader carries the link once. - `docs-reading.test.ts` — reading order (a doc placed twice counted once, links and separators skipped), neighbours, the filter (title, summary, case, non-Latin), `pickActiveHeading`. - `ConsoleLayout.phoneRecordOneBar-28483.test.tsx` — docs routes draw no app menu and keep the app bar; other routes keep the menu; `isAppDocsPath` table. - `AppHeader.systemBreadcrumbs-10969.test.tsx` — 文档 / Documentation crumb on the docs routes; the empty toggle slot there, the toggle elsewhere. - `Mermaid.enlarge-35424.test.tsx` — the control and dialog with a provider (the dialog's copy under its own ids), nothing without one. - `DocPage.docLinkBasename-12686.test.tsx` — its portal control now reads every 「Documentation」 link (the header's and the path's); both name the portal. - `vitest`: `apps/console`, `packages/plugin-markdown`, `packages/i18n` in full: 1,399 files, 5,458 tests passed (one red on the first run, `zh-hant-generated.test.ts`: two zh-Hant strings were hand-written; regenerated with `gen:zh-hant`, now green). `packages/app-shell`: the 165 test files that import `AppHeader`, `ConsoleLayout`, the new exports or the package index, 1,458 tests passed (its full 2,356 files outran a 50-minute local budget; CI runs them). `tsc` for the four packages and `eslint` over the changed files: 0 errors, no new warnings. - `overlap-check.mjs`: clean against `origin/main` and the four open PRs sharing the locale files (#35918, #35968, #35984, #35994). Clause-②: yes (widening) — @object-ui/plugin-markdown exports MermaidEnlargeContext and MermaidEnlargeText; @object-ui/i18n adds 12 help.* keys; nothing removed Metadata-protocol: none Follow-ups (not in this PR): items 6–9 of #35424 (the "All docs" page: top bar, grouped by app, localized subtitle and counts, system packages named and shown to admins only, search all docs) — next PR, new thread. ## Human Minimum - [x] 1. Schemas start as Zod; `packages/spec` holds no runtime logic. (No spec change.) - [x] 2. Every name I added uses the casing for its kind. - [x] 3. No formatter ran; `pnpm lint` passes. - [x] 4. One issue, one branch off an up-to-date `main`, one pull request. - [x] 5. A change that publishes carries a changeset, and both declaration lines are filled in here and in the changeset. - [x] 6. `packages/spec` touched: n/a. - [x] 7. No hand edits to `content/docs/references/`, `packages/*/CHANGELOG.md` or `content/docs/releases/`. - [x] 8. Title, body and comments are in English. - [x] The *Before Submitting* list in CONTRIBUTING.md is done. 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_01L6bhgWcCSnzHX9bYADvAVH <!-- signed: repo:objectstack#1 · os-sales · session_01L6bhgWcCSnzHX9bYADvAVH --> --------- Co-authored-by: Claude <noreply@anthropic.com>
1 parent 32409a9 commit 141a826

32 files changed

Lines changed: 1210 additions & 74 deletions
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
---
2+
'@object-ui/console': patch
3+
'@object-ui/app-shell': patch
4+
'@object-ui/plugin-markdown': patch
5+
'@object-ui/i18n': patch
6+
---
7+
8+
feat(console): an app's docs page has one navigation — the docs column — with the path to its book and the previous and next article
9+
10+
Clause-②: yes (widening) — @object-ui/plugin-markdown exports MermaidEnlargeContext and MermaidEnlargeText; @object-ui/i18n adds 12 help.* keys; nothing removed
11+
Metadata-protocol: none
12+
13+
Inside an app, the documentation pages (`/apps/<app>/docs/…`) no longer draw the app menu beside the docs: the left column is the docs' own, with 「← Back to <app>」 at its top, a title filter, every book of the app's package (the current book open, the others folded, each with its article count; long titles wrap instead of truncating) and 「All documentation →」 at its foot. Every other docs page inside an app (the app's docs index, a book with no articles, a book or doc not found) carries the same 「← Back to <app>」 at its top. The app bar stays, and reads 「<app> / Documentation」; the separate 「Documentation / <title>」 bar under it is gone, and the path above the article names the book (Documentation › <book>). 「On this page」 marks the section being read as the page scrolls, and the article ends with its book's previous and next article. The article column is 720 px wide at 15 px, and a diagram carries an 「Enlarge」 control that opens it full size.
14+
15+
`@object-ui/plugin-markdown` adds `MermaidEnlargeContext`: a host that provides its words gets the enlarge control on every rendered diagram; with no provider a diagram renders exactly as before. `@object-ui/app-shell` exports `matchAppBySegment` and `useServedAppLabel`, and `isAppDocsPath` beside `isRecordPagePath` from its `ConsoleLayout` module. New `help.*` keys in every shipped locale. No doc content, doc metadata, route or API changes.
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/**
2+
* ObjectUI
3+
* Copyright (c) 2024-present ObjectStack Inc.
4+
*
5+
* This source code is licensed under the MIT license found in the
6+
* LICENSE file in the root directory of this source tree.
7+
*/
8+
9+
import { Link } from 'react-router-dom';
10+
import { ArrowLeft } from 'lucide-react';
11+
import { useObjectTranslation } from '@object-ui/i18n';
12+
import type { AppDocsBackTo } from './useAppDocsBackTo';
13+
14+
/**
15+
* 「← Back to APP」 (objectstack#35424). An app's docs routes draw no app
16+
* menu, so every docs page inside an app carries this link: the reader in
17+
* its docs column, every other page (the app's docs index, a book with no
18+
* articles, a book or doc not found) at the top, through `DocShell`.
19+
*/
20+
export function AppDocsBackLink({ backTo }: { backTo: AppDocsBackTo }) {
21+
const { t } = useObjectTranslation();
22+
return (
23+
<Link
24+
to={backTo.to}
25+
data-testid="docs-nav-back"
26+
className="inline-flex items-center gap-1.5 self-start rounded px-2 py-1 text-sm font-medium text-primary hover:bg-muted/50"
27+
>
28+
<ArrowLeft className="h-4 w-4 shrink-0" aria-hidden />
29+
<span>{t('help.backToApp', { defaultValue: 'Back to {{app}}', app: backTo.label })}</span>
30+
</Link>
31+
);
32+
}

‎ui/apps/console/src/pages/BookSidebar.tsx‎

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ import type { ResolvedBook } from './book-nav';
1616
* alongside the single-doc reader so a reader can move within the book
1717
* without losing their place.
1818
*
19+
* A long title wraps rather than truncating, so every entry is readable in
20+
* full (objectstack#35424).
21+
*
1922
* Routing is delegated: the parent supplies `docHref` so the same sidebar
2023
* works under the top-level `/docs/:name` route and the package-scoped
2124
* `/apps/:appName/docs/:name` route.
@@ -24,22 +27,31 @@ export function BookSidebar({
2427
book,
2528
activeDoc,
2629
docHref,
30+
showLabel = true,
31+
groupHeadings = 'always',
2732
}: {
2833
book: ResolvedBook;
2934
activeDoc?: string;
3035
docHref: (docName: string) => string;
36+
/** Draw the book's label above its groups; off where a parent already names the book (the docs column). */
37+
showLabel?: boolean;
38+
/** `multi`: a book of one group lists its entries under no heading, the book's name being the heading. */
39+
groupHeadings?: 'always' | 'multi';
3140
}) {
41+
const headings = groupHeadings === 'always' || book.groups.length > 1;
3242
return (
3343
<nav aria-label={book.label ?? book.name} className="text-sm">
34-
{book.label ? (
44+
{showLabel && book.label ? (
3545
<div className="mb-3 px-2 text-sm font-semibold text-foreground">{book.label}</div>
3646
) : null}
37-
<div className="space-y-5">
47+
<div className={headings ? 'space-y-5' : undefined}>
3848
{book.groups.map((group) => (
3949
<div key={group.key}>
40-
<div className="mb-1 px-2 text-xs font-semibold uppercase tracking-wide text-muted-foreground">
41-
{group.label}
42-
</div>
50+
{headings ? (
51+
<div className="mb-1 px-2 text-xs font-semibold uppercase tracking-wide text-muted-foreground">
52+
{group.label}
53+
</div>
54+
) : null}
4355
<ul className="space-y-0.5">
4456
{group.entries.map((entry, i) => {
4557
if (entry.separator) {
@@ -54,7 +66,7 @@ export function BookSidebar({
5466
rel="noreferrer"
5567
className="flex items-center gap-1.5 rounded px-2 py-1 text-muted-foreground hover:bg-muted/50 hover:text-foreground"
5668
>
57-
<span className="truncate">{entry.label ?? entry.href}</span>
69+
<span className="break-words">{entry.label ?? entry.href}</span>
5870
<ExternalLink className="h-3 w-3 shrink-0 opacity-60" />
5971
</a>
6072
</li>
@@ -67,9 +79,9 @@ export function BookSidebar({
6779
<Link
6880
to={docHref(entry.doc)}
6981
aria-current={active ? 'page' : undefined}
70-
className={`block truncate rounded px-2 py-1 transition ${
82+
className={`block break-words rounded px-2 py-1.5 leading-snug transition ${
7183
active
72-
? 'bg-primary/10 font-medium text-foreground'
84+
? 'bg-primary/10 font-medium text-primary'
7385
: 'text-muted-foreground hover:bg-muted/50 hover:text-foreground'
7486
}`}
7587
>

‎ui/apps/console/src/pages/DocPage.docLinkBasename-12686.test.tsx‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,9 @@ describe("a doc-to-doc link in an app's doc stays in that app's docs route (obje
193193
it('CONTROL: outside an app the header home link is still the portal', async () => {
194194
renderDoc('/_console');
195195
await screen.findByRole('link', { name: 'index' });
196-
expect(screen.getByRole('link', { name: 'Documentation' }).getAttribute('href')).toBe('/_console/docs');
196+
// The portal header's home link, and the path above the article
197+
// (objectstack#35424): both name the portal.
198+
const links = screen.getAllByRole('link', { name: 'Documentation' });
199+
expect(links.map((l) => l.getAttribute('href'))).toEqual(links.map(() => '/_console/docs'));
197200
});
198201
});

0 commit comments

Comments
 (0)