diff --git a/.claude/skills/openbot-screen-layout/SKILL.md b/.claude/skills/openbot-screen-layout/SKILL.md index 2ca169bed6..c05acad653 100644 --- a/.claude/skills/openbot-screen-layout/SKILL.md +++ b/.claude/skills/openbot-screen-layout/SKILL.md @@ -54,8 +54,10 @@ PageShell the page: header (title, description, action, backButton) then `PageShell` takes a `width`: `prose` (`max-w-3xl`, 768px) is the default, and every configuration screen uses it so no screen is wider than another. Sentences inside it are held to `max-w-prose`, so the column has room for a label beside its control without stretching the text. -`wide` (`max-w-5xl`) exists for one screen — `admin/audit.tsx`, because an audit log is a table to be -scanned and prose width would wrap every row. It is not a licence for anything else to be wide. +`wide` (`max-w-4xl`, 896px) is for a grid of cards picked out by how they look: the Artifacts +gallery, three cards a row on a desktop window. `full` (no column) exists for one screen, the audit +log (`manage/audit-page.tsx`), because it is a table to be scanned and prose width would wrap every +row. Neither is a licence for rows or forms to be wide. ## The Rhythm @@ -227,7 +229,8 @@ is actually on screen. The root was once 15px, and every constant taken from the - A width, ratio or scale needs a number in pixels → the Units section. Measure, do not assume. - Choosing a margin or gap between blocks → the Rhythm table. If the frame already gives it, set none. - The screen genuinely does not fit this shape → say so in the response and comment the reason in the - code. There are two accepted precedents: a table (`admin/audit.tsx`, `width="wide"`), and the + code. There are three accepted precedents: a table (the audit log, `width="full"`), the + Artifacts gallery (`width="wide"`, a grid of cards), and the Connections tiles (`connections.index.tsx`), a grid of separate `variant="outline"` cards, 56px tall and 12px apart, because apps are picked out by their mark rather than read down as a list. - The question is which states the screen renders while loading or failing → not this skill; @@ -239,7 +242,7 @@ is actually on screen. The root was once 15px, and every constant taken from the |--------|---------------|------------| | A hand-written `rounded-lg border border-border bg-card` div wrapping rows | `PageRows` re-implemented, and it will drift from the other seven screens | Use `PageRows` | | Rows separated by `gap-*` instead of `` | A stack of cards rather than one card of rows | `` between rows, none after the last | -| `width="wide"` on anything that is not a table | Prose width is the default for a reason; wide was for the audit log | Leave `width` alone | +| `width="wide"` or `"full"` on rows or a form | Prose width is the default for a reason; the others are for a grid of cards and a table | Leave `width` alone | | A `max-w-*`, `p-*` or text size invented for one screen | A fifth container width, which is what this layout exists to stop | Reach for the existing component | | Children on an element passed to `Item`'s `render` | They replace the row's own children; the row draws empty | Pass a childless element | | `bg-card` on a row inside a dialog | `--card` equals `--popover`; the row is invisible | `variant="muted"` | diff --git a/app/src/components/artifacts/artifact-full-page.tsx b/app/src/components/artifacts/artifact-full-page.tsx new file mode 100644 index 0000000000..29b2a0905b --- /dev/null +++ b/app/src/components/artifacts/artifact-full-page.tsx @@ -0,0 +1,132 @@ +import { Link } from "@tanstack/react-router"; +import { type Ref, useEffect, useRef } from "react"; +import { IconChevronLeft } from "@/components/icons"; +import { SidebarToggle } from "@/components/layout/sidebar-toggle"; +import { Button } from "@/components/ui/button"; +import { + Tooltip, + TooltipContent, + TooltipTrigger, +} from "@/components/ui/tooltip"; +import { + ArtifactViewer, + type ArtifactViewerProps, +} from "./viewer/artifact-viewer"; + +const BACK_LABEL = "Back to Artifacts"; + +declare module "@tanstack/react-router" { + interface HistoryState { + /** + * Set by the panel's Open full screen: the artifact's own page was opened from the conversation + * beside it, so its Back goes back there. + */ + artifactFromConversation?: boolean; + } +} + +/** Escape closes the artifact, as the sheet it replaces did, unless something else takes it. */ +function escapeIsOurs(event: KeyboardEvent): boolean { + if (event.key !== "Escape" || event.defaultPrevented || event.isComposing) + return false; + const target = event.target instanceof Element ? event.target : null; + // A field keeps Escape: half a comment is not thrown away with the artifact. + if (target?.closest("input, textarea, select, [contenteditable=true]")) + return false; + // A menu, a select or a dialog over the viewer closes first, on its own Escape. + return !document.querySelector( + "[role=dialog], [role=alertdialog], [role=menu], [role=listbox]", + ); +} + +/** + * An artifact, opened full page in the app's main pane, edge to edge: the viewer with one header + * row, which starts with the sidebar's toggle (when the sidebar is hidden) and the way back to the + * Artifacts page. The sidebar stays where it is, so the person can go anywhere else from here too. + * + * Drawn over the Artifacts page when a tile opens it (`?artifact=`), and on its own address + * (`/artifacts/`). + * + * `onBack` is for a page that goes back in the history: the Artifacts page, so the list comes back + * as it was left, or the conversation it was opened from. Without it, Back is a link to the + * Artifacts page. Escape is Back too. + */ +export function ArtifactFullPage({ + onBack, + backLabel = BACK_LABEL, + focusBack = false, + ...viewer +}: Omit & { + onBack?: () => void; + /** What Back is called, to the eye and to a screen reader: where it goes. */ + backLabel?: string; + /** Move focus to Back once drawn: the tile that opened it is behind the viewer now. */ + focusBack?: boolean; +}) { + const back = useRef(null); + useEffect(() => { + const onKey = (event: KeyboardEvent) => { + if (!escapeIsOurs(event)) return; + event.preventDefault(); + back.current?.click(); + }; + document.addEventListener("keydown", onKey); + return () => document.removeEventListener("keydown", onKey); + }, []); + // The viewer draws its header once the artifact is read, so Back may come a moment later. + useEffect(() => { + if (!focusBack) return; + let frame = 0; + let tries = 0; + const focus = () => { + if (back.current) back.current.focus(); + else if (tries++ < 120) frame = requestAnimationFrame(focus); + }; + focus(); + return () => cancelAnimationFrame(frame); + }, [focusBack]); + + const backButton = ( + + } + size="icon" + variant="ghost" + /> + ) : ( + - ) : null} - - - - } + // Full page, everything sits in one header row; in the panel, whose own header holds the title, + // the version and the actions take a row and the tabs another. + const wide = place === "page"; + + const versionControl = outside ? ( +

+ {wide ? null : `${kindName(artifact.kind)} · `} + Version {shown} +

+ ) : ( + + ); + + const actions = ( + <> + {together ? ( + + ) : null} + {artifact.canShare && !outside ? ( + + ) : null} + + + + } + > + + + + {fullScreen && inApp ? ( + + } + > + + Open full screen + + ) : null} + void doCopy()} > - -
- - {fullScreen && inApp ? ( + + {sourceTabName(artifact.kind) === "Code" + ? "Copy code" + : "Copy contents"} + + {outside ? null : ( + <> + {inApp ? ( + + + Duplicate + + ) : null} + onClick={() => + pin.mutate({ + artifactId: artifact.id, + pinned: !artifact.pinned, + }) } > - - Open full screen + {artifact.pinned ? : } + {artifact.pinned ? "Unpin" : "Pin"} - ) : null} - void doCopy()} - > - - {sourceTabName(artifact.kind) === "Code" - ? "Copy code" - : "Copy contents"} - - {outside ? null : ( - <> - {inApp ? ( + {artifact.kind === "page" ? ( + setPermissionsOpen(true)}> + + Page permissions + + ) : null} + {artifact.source && inApp ? ( + <> + + } > - - Duplicate + + Go to conversation - ) : null} - - pin.mutate({ - artifactId: artifact.id, - pinned: !artifact.pinned, - }) - } - > - {artifact.pinned ? : } - {artifact.pinned ? "Unpin" : "Pin"} - - {artifact.kind === "page" ? ( - setPermissionsOpen(true)}> - - Page permissions + + ) : null} + {canDelete ? ( + <> + + setDeleting(true)} + variant="destructive" + > + + Delete - ) : null} - {artifact.source && inApp ? ( - <> - - - } - > - - Go to conversation - - - ) : null} - {canDelete ? ( - <> - - setDeleting(true)} - variant="destructive" - > - - Delete - - - ) : null} - - )} - -
- - + + ) : null} + + )} + + + ); const preview = content.data ? ( @@ -457,7 +465,6 @@ function Opened({ ); // Full screen has room for the comments beside the artifact; the panel keeps them in a tab. - const wide = place === "page"; const comments = together ? ( ) : null; + // Wide, Comments sits beside the artifact, so its tab is for a window too narrow for that. + const tabsList = ( + + Preview + {sourceTabName(artifact.kind)} + Changes + + Comments + + + ); + const commentOnThis = + selection && tab !== "comments" ? ( + + ) : null; + const older = + shown < latest && !outside ? ( + onVersionChange(undefined)} + onRestore={doRestore} + restoring={restore.isPending} + shown={shown} + /> + ) : null; + + const header = wide ? ( +
+ {/* One row: the title on the left, the tabs, then the version and what can be done with it. + A narrow window wraps it, the tabs first. */} +
+ {leading ? ( +
{leading}
+ ) : null} + + {outside ? null : ( +
+ {tabsList} + {commentOnThis} +
+ )} +
+ {versionControl} + {actions} +
+
+ {older ?
{older}
: null} +
+ ) : ( +
+
+ {versionControl} +
{actions}
+
+ {older} +
+ ); + return (
{said}

-
- {place === "page" ? ( - - ) : null} - {toolbar} - {shown < latest && !outside ? ( - onVersionChange(undefined)} - onRestore={doRestore} - restoring={restore.isPending} - shown={shown} - /> - ) : null} -
{outside ? ( - -
{preview}
-
+ <> + {header} + +
{preview}
+
+ ) : ( -
setTab(value as Tab)} + value={tab} > - setTab(value as Tab)} - value={tab} + {header} +
-
- - Preview - - {sourceTabName(artifact.kind)} - - Changes - + {wide ? null : ( +
+ {tabsList} + {commentOnThis} +
+ )} + + + {/* Where words picked in a document, deck or dashboard become a comment's quote. */} +
+ {preview} +
+
+ - Comments -
-
- {selection && tab !== "comments" ? ( - - ) : null} + + +
- - - {/* Where words picked in a document, deck or dashboard become a comment's quote. */} -
- {preview} -
-
- {comments} - - - - - - - -
- - {wide ? ( - // Full screen and wide, the comments sit beside the artifact rather than behind a tab. - - ) : null} -
+ + ) : null} +
+ )} {together && artifact.kind === "page" ? ( @@ -714,7 +767,10 @@ function OlderVersion({ ); } -/** Full screen, the viewer names the artifact itself: its kind, its title, who can open it. */ +/** + * Full screen, the viewer names the artifact itself, at the start of its header row: its kind, its + * title, and then who can open it and whose it is, which give way first when the row is short. + */ function ViewerTitle({ artifact, outside, @@ -723,21 +779,23 @@ function ViewerTitle({ outside: boolean; }) { const owner = artifact.owner.name; + const about = [ + kindName(artifact.kind), + outside ? null : visibilityName(artifact.visibility), + outside || !owner ? null : owner, + ] + .filter(Boolean) + .join(" · "); return ( -
- - - -
-

- {artifact.title} -

-

- {kindName(artifact.kind)} - {outside ? null : ` · ${visibilityName(artifact.visibility)}`} - {outside || !owner ? null : ` · ${owner}`} -

-
+
+ +

{artifact.title}

+

+ {about} +

); } diff --git a/app/src/components/artifacts/viewer/version-bar.tsx b/app/src/components/artifacts/viewer/version-bar.tsx index 095180936b..1572e0e1c8 100644 --- a/app/src/components/artifacts/viewer/version-bar.tsx +++ b/app/src/components/artifacts/viewer/version-bar.tsx @@ -21,7 +21,8 @@ import { relativeTime } from "@/lib/relative-time"; /** * Which version is on screen, and the way to every other: back and forward a version at a time, or * straight to any of them from the list, each with who made it, when, and what changed. Under it, - * who made the one on screen and their note. + * who made the one on screen and their note, except `compact`, in a header row with no room for a + * second line: there the list says it. */ export function VersionBar({ shown, @@ -29,6 +30,7 @@ export function VersionBar({ versions, me, onShow, + compact = false, }: { shown: number; latest: number; @@ -37,6 +39,8 @@ export function VersionBar({ me: string | undefined; /** Show a version; undefined follows the newest. */ onShow: (version: number | undefined) => void; + /** One line, no "who made it" under the stepper. */ + compact?: boolean; }) { const current = versions?.find((one) => one.number === shown); const go = (version: number) => @@ -117,7 +121,7 @@ export function VersionBar({
- {current ? ( + {current && !compact ? (

{authorName(current.author, me)} diff --git a/app/src/components/layout/page-parts.tsx b/app/src/components/layout/page-parts.tsx index 1e7969c99b..e74a4dc11e 100644 --- a/app/src/components/layout/page-parts.tsx +++ b/app/src/components/layout/page-parts.tsx @@ -20,8 +20,16 @@ import { * at the pane's left edge, lined up with the table's first column rather than centred above a table * that is not, and the children fill what is left, so the table can be the one thing that scrolls. * It is not a licence for anything else to be wide. It is no column, so `PageShell` draws it itself. + * + * `wide` is `max-w-4xl`, 896px, for a gallery of cards that a person picks out by how they look + * (Artifacts). In the prose column such a gallery holds two cards a row with empty space beside + * them; this column holds three on a desktop window. It is for a grid of cards, not for rows or + * forms, which keep `prose`. `PageShell` widens the column with its class (`WIDE_COLUMN`). */ -export type ShellWidth = "prose" | "full"; +export type ShellWidth = "prose" | "wide" | "full"; + +/** The `wide` column's measure, over the column's own `max-w-3xl`. */ +export const WIDE_COLUMN = "max-w-4xl"; /** * The scroller and the centred `prose` column every configuration screen sits in, without the bar. The diff --git a/app/src/components/layout/page-shell.tsx b/app/src/components/layout/page-shell.tsx index e51a0be7a0..d6d1868dc2 100644 --- a/app/src/components/layout/page-shell.tsx +++ b/app/src/components/layout/page-shell.tsx @@ -3,7 +3,12 @@ import { Link, type LinkProps } from "@tanstack/react-router"; import type * as React from "react"; import { cn } from "@/lib/utils"; import { Button } from "../ui/button"; -import { PageColumn, PageHeader, type ShellWidth } from "./page-parts"; +import { + PageColumn, + PageHeader, + type ShellWidth, + WIDE_COLUMN, +} from "./page-parts"; import { SidebarToggle, useSidebarToggleVisible } from "./sidebar-toggle"; /** @@ -25,7 +30,7 @@ import { SidebarToggle, useSidebarToggleVisible } from "./sidebar-toggle"; export function PageShell({ action, children, - className, + className: given, description, title, width = "prose", @@ -45,6 +50,8 @@ export function PageShell({ disabled?: boolean; }; }) { + // `wide` is the prose column made wider: its class comes after the column's own, and wins. + const className = width === "wide" ? cn(WIDE_COLUMN, given) : given; /* * The bar carries the toggle and the Back link, and is drawn when it has at least one of them. * The screens with a Back link already drew exactly this bar, so for them nothing changes; what diff --git a/app/src/routes/_authed/_app/artifacts.tsx b/app/src/routes/_authed/_app/artifacts.tsx index 1908ad725d..2eadfd67f3 100644 --- a/app/src/routes/_authed/_app/artifacts.tsx +++ b/app/src/routes/_authed/_app/artifacts.tsx @@ -1,26 +1,22 @@ -import { createFileRoute } from "@tanstack/react-router"; -import { useCallback } from "react"; +import { createFileRoute, useRouter } from "@tanstack/react-router"; +import { useCallback, useEffect, useRef } from "react"; import { z } from "zod"; -import { - ARTIFACT_PANEL_WIDTH, - ArtifactPanelViewer, - artifactPanelSearch, -} from "@/components/artifacts/artifact-panel"; +import { ArtifactFullPage } from "@/components/artifacts/artifact-full-page"; +import { artifactPanelSearch } from "@/components/artifacts/artifact-panel"; import { type ArtifactsFilter, ArtifactsPage, } from "@/components/artifacts/artifacts-page"; -import { ArtifactPanelTitle } from "@/components/artifacts/viewer/artifact-viewer"; -import { DetailPanel } from "@/components/layout/detail-panel"; import type { ArtifactKind } from "@/lib/artifacts/queries"; import { KINDS } from "@/lib/artifacts/words"; import { searchText } from "@/lib/search-text"; +import { cn } from "@/lib/utils"; /** * The Artifacts page, under Conversations: everything Bots made that the person can open. Which list * (`show`), the kind, the search (`q`) and grid or list (`layout`) are in the address, so the page - * comes back as it was left; an artifact opened from it shows in the panel beside the list - * (`?artifact=`). + * comes back as it was left. An artifact opened from it (`?artifact=`) shows full page, over the + * list. The list stays drawn under it, hidden, so Back finds it scrolled where it was. */ const artifactsSearchSchema = z.object({ show: z.enum(["all", "mine", "shared", "pinned"]).optional().catch(undefined), @@ -65,7 +61,12 @@ function ArtifactsRoute() { }), [navigate], ); - const open = (artifactId: string | undefined) => + const router = useRouter(); + // Opened from a tile here, the list is the entry before this one: Back goes back to it. Opened from + // a link or a reload, there is no such entry, and Back goes to the list in its place. + const openedHere = useRef(false); + const open = (artifactId: string) => { + openedHere.current = true; void navigate({ search: (previous) => ({ ...previous, @@ -73,13 +74,90 @@ function ArtifactsRoute() { artifactVersion: undefined, }), }); + }; + const back = () => { + if (openedHere.current) { + openedHere.current = false; + router.history.back(); + return; + } + void navigate({ + replace: true, + search: (previous) => ({ + ...previous, + artifact: undefined, + artifactVersion: undefined, + }), + }); + }; + + // Closed, focus goes back to the tile or row that opened it, under the viewer until now. + const opened = search.artifact; + const last = useRef(undefined); + useEffect(() => { + if (opened) { + last.current = opened; + return; + } + openedHere.current = false; + const id = last.current; + last.current = undefined; + if (!id) return; + const target = document.querySelector( + `[data-artifact-id="${CSS.escape(id)}"]`, + ); + const control = target?.matches("button") + ? target + : target?.querySelector("button"); + (control as HTMLElement | null | undefined)?.focus({ preventScroll: true }); + }, [opened]); return ( - + {/* Hidden, not taken away, while an artifact is open over it: it keeps its scroll. */} +

+ +
+ {opened ? ( +
+ + navigate({ + replace: true, + search: (previous) => ({ + ...previous, + artifact: undefined, + artifactVersion: undefined, + }), + }) + } + // A duplicate takes the original's place, so Back still leads to the list. + onOpenArtifact={(copy) => + void navigate({ + replace: true, + search: (previous) => ({ + ...previous, + artifact: copy, + artifactVersion: undefined, + }), + }) + } onVersionChange={(version) => void navigate({ replace: true, @@ -91,25 +169,8 @@ function ArtifactsRoute() { } version={search.artifactVersion} /> - ) : null - } - detailWidth={ARTIFACT_PANEL_WIDTH} - onClose={() => open(undefined)} - open={search.artifact !== undefined} - title={ - search.artifact ? ( - - ) : undefined - } - > -
- -
- +
+ ) : null} +
); } diff --git a/app/src/routes/_authed/_app/artifacts_.$artifactId.tsx b/app/src/routes/_authed/_app/artifacts_.$artifactId.tsx index a1155e5cee..bbee606ee2 100644 --- a/app/src/routes/_authed/_app/artifacts_.$artifactId.tsx +++ b/app/src/routes/_authed/_app/artifacts_.$artifactId.tsx @@ -1,14 +1,17 @@ -import { IconChevronLeft } from "@/components/icons"; -import { createFileRoute, Link } from "@tanstack/react-router"; +import { + createFileRoute, + useLocation, + useRouter, +} from "@tanstack/react-router"; import { z } from "zod"; +import { ArtifactFullPage } from "@/components/artifacts/artifact-full-page"; import { versionSearch } from "@/components/artifacts/artifact-panel"; -import { ArtifactViewer } from "@/components/artifacts/viewer/artifact-viewer"; -import { SidebarToggle } from "@/components/layout/sidebar-toggle"; -import { Button } from "@/components/ui/button"; /** - * One artifact, full screen in the app: the same viewer as the panel, with the room to read a deck - * or a dashboard. `?version=` opens an older version, as a chat card's Open does. + * One artifact, on its own address: the same full page the Artifacts page opens over its list, with + * the room to read a deck or a dashboard. `?version=` opens an older version, as a chat card's + * Open does. Back is a link to the Artifacts page, or, opened with the panel's Open full screen, + * "Back" to the conversation it came from. */ export const Route = createFileRoute("/_authed/_app/artifacts_/$artifactId")({ validateSearch: z.object({ version: versionSearch }), @@ -19,39 +22,29 @@ function FullScreenArtifact() { const { artifactId } = Route.useParams(); const { version } = Route.useSearch(); const navigate = Route.useNavigate(); + const router = useRouter(); + const fromConversation = useLocation({ + select: (location) => location.state.artifactFromConversation === true, + }); return ( -
-
- - -
-
- - void navigate({ - params: { artifactId: copy }, - search: {}, - to: "/artifacts/$artifactId", - }) - } - // Deleted: back to the Artifacts page, in place of the page that showed it. - onDeleted={() => navigate({ replace: true, to: "/artifacts" })} - onVersionChange={(next) => - void navigate({ replace: true, search: { version: next } }) - } - place="page" - version={version} - /> -
-
+ router.history.back() : undefined} + key={artifactId} + onOpenArtifact={(copy) => + void navigate({ + params: { artifactId: copy }, + search: {}, + to: "/artifacts/$artifactId", + }) + } + // Deleted: back to the Artifacts page, in place of the page that showed it. + onDeleted={() => navigate({ replace: true, to: "/artifacts" })} + onVersionChange={(next) => + void navigate({ replace: true, search: { version: next } }) + } + version={version} + /> ); } diff --git a/app/tests/artifacts-app.fixture.tsx b/app/tests/artifacts-app.fixture.tsx index b23aaad67d..ea61e3c0b1 100644 --- a/app/tests/artifacts-app.fixture.tsx +++ b/app/tests/artifacts-app.fixture.tsx @@ -15,6 +15,9 @@ import { router } from "@/router"; * full screen, and the panel they open. Served with the artifacts host's meta tag, it boots the * artifacts host's own page instead, as main.tsx does. The server is `artifacts-browser.ts`'s. */ +// For a test to navigate as a link elsewhere in the app would, history state included. +(window as unknown as { appRouter: typeof router }).appRouter = router; + const root = document.getElementById("root"); const host = artifactsHostOrganization(document); if (root && host !== undefined) bootArtifactsHost(root, host); diff --git a/app/tests/artifacts-screens.test.tsx b/app/tests/artifacts-screens.test.tsx index 5e9ef2dde7..d5d7dd7c15 100644 --- a/app/tests/artifacts-screens.test.tsx +++ b/app/tests/artifacts-screens.test.tsx @@ -632,7 +632,7 @@ describe.skipIf(!asked)("artifacts in a conversation", () => { }); describe.skipIf(!asked)("the Artifacts page and full screen", () => { - test("lists, narrows, opens into the panel, pins", async () => { + test("lists, narrows, opens full page, pins", async () => { const { page } = await open({ entry: "app", path: "/artifacts", @@ -683,14 +683,21 @@ describe.skipIf(!asked)("the Artifacts page and full screen", () => { await page.getByRole("button", { name: "List" }).click(); await page.getByRole("button", { name: /Pipeline dashboard/ }).click(); await page.getByRole("tab", { name: "Preview" }).waitFor(); + // The viewer's classes came after the page's stylesheet was made: make it again. + await restyle(page); await inViewer(page).getByText("Deals by stage").first().waitFor(); expect(new URL(page.url()).searchParams.get("artifact")).toBe( DASHBOARD_ID, ); - // Pinned from the viewer's menu: it joins the Pinned list. + // Pinned from the viewer's menu: it joins the Pinned list, back on the page. await page.getByRole("button", { name: "More actions" }).click(); await page.getByRole("menuitem", { name: "Pin" }).click(); + await page.keyboard.press("Escape"); + await page.getByRole("button", { name: "Back to Artifacts" }).click(); + await page.waitForFunction( + () => new URL(location.href).searchParams.get("artifact") === null, + ); await page.getByRole("combobox", { name: "Kind" }).click(); await page.getByRole("option", { name: "Every kind" }).click(); await page.getByRole("button", { name: "Pinned", exact: true }).click(); @@ -806,8 +813,9 @@ describe.skipIf(!asked)("the Artifacts page and full screen", () => { }); try { const tiles = page.locator("[data-slot=artifact-tile]"); - // However many the list holds (the fixtures grow), Delete takes exactly one away. - await tiles.first().waitFor(); + // However many the list holds (the fixtures grow), Delete takes exactly one away. The list is + // there under the open artifact, hidden. + await tiles.first().waitFor({ state: "attached" }); const before = await tiles.count(); await page.getByRole("button", { name: "More actions" }).click(); await page.getByRole("menuitem", { name: "Delete" }).click(); @@ -819,7 +827,7 @@ describe.skipIf(!asked)("the Artifacts page and full screen", () => { expect(await measured(page)).toEqual(HOLDS); await shoot(page, "artifact-delete-confirm-light-1440"); await dialog.getByRole("button", { name: "Delete", exact: true }).click(); - // The panel closes, the list stays, without it. + // The artifact closes, and the list shows, without it. await page.waitForFunction( () => new URL(location.href).searchParams.get("artifact") === null, ); @@ -851,24 +859,231 @@ describe.skipIf(!asked)("the Artifacts page and full screen", () => { } }, 60_000); - test("full screen, from the panel's menu", async () => { + /* + * FROM THE SCREEN-BY-SCREEN AUDIT. The gallery held two cards a row in the prose column, with + * empty space on both sides, and an artifact opened in a 560px panel, as a sheet over a dimmed page + * on a narrower window, under three rows of controls. + */ + test("three cards a row; an artifact opens full page under one header row, and Back finds the list as it was", async () => { const { page } = await open({ entry: "app", - path: `/artifacts?artifact=${PLAN_ID}`, + path: "/artifacts", theme: "light", window: WIDE, ready: (one) => - one.getByRole("button", { name: "More actions" }).waitFor(), + one.getByRole("button", { name: "Pricing calculator" }).waitFor(), }); try { - await page.getByRole("button", { name: "More actions" }).click(); - await page.getByRole("menuitem", { name: "Open full screen" }).click(); - // The viewer's own title, above the document's first heading. + const columns = () => + page.evaluate(() => { + const tops = [ + ...document.querySelectorAll("[data-slot=artifact-tile]"), + ].map((tile) => Math.round(tile.getBoundingClientRect().top)); + return tops.filter((top) => top === tops[0]).length; + }); + expect(await columns()).toBe(3); + await page.setViewportSize(NARROW); + await page.waitForFunction( + () => + document + .querySelectorAll("[data-slot=artifact-tile]")[1] + ?.getBoundingClientRect().top === + document + .querySelectorAll("[data-slot=artifact-tile]")[0] + ?.getBoundingClientRect().top, + ); + expect(await columns()).toBe(2); + await page.setViewportSize(PHONE); + await page.waitForFunction( + () => + (document + .querySelectorAll("[data-slot=artifact-tile]")[1] + ?.getBoundingClientRect().top ?? 0) > + (document + .querySelectorAll("[data-slot=artifact-tile]")[0] + ?.getBoundingClientRect().top ?? 0), + ); + expect(await columns()).toBe(1); + // Short enough that the list scrolls. + await page.setViewportSize({ width: WIDE.width, height: 600 }); + + // Scrolled down the list, a tile in the last row opens: one of the person's own, so Share is there. + const last = page + .locator("[data-slot=artifact-tile]") + .filter({ hasText: "Launch countdown" }); + await last.scrollIntoViewIfNeeded(); + const scroller = () => + page.evaluate(() => { + let element = document.querySelector( + "[data-slot=artifact-tile]", + )?.parentElement; + while (element && getComputedStyle(element).overflowY !== "auto") + element = element.parentElement; + return element?.scrollTop ?? -1; + }); + const scrolled = await scroller(); + expect(scrolled).toBeGreaterThan(0); + const title = "Launch countdown"; + await last.getByRole("button").click(); + await page.getByRole("tab", { name: "Preview" }).waitFor(); + await restyle(page); + + // Full page: the main pane, edge to edge, with the sidebar beside it as it was. + const placed = await page.evaluate(() => { + const full = document + .querySelector("[data-slot=artifact-full-page]") + ?.getBoundingClientRect(); + const pane = document + .querySelector("[data-slot=artifact-full-page]") + ?.parentElement?.getBoundingClientRect(); + const header = document + .querySelector("[data-slot=artifact-viewer-header]") + ?.getBoundingClientRect(); + return { + full: full && pane ? full.width === pane.width : false, + header: header?.height ?? 0, + sidebar: [...document.querySelectorAll("[data-sidebar=sidebar]")] + .length, + }; + }); + expect(placed.full).toBe(true); + expect(placed.header).toBeGreaterThan(0); + expect(placed.header).toBeLessThanOrEqual(48); + expect(placed.sidebar).toBeGreaterThan(0); + // One row: the title, the tabs, the version and Share, each named for a screen reader. + const header = page.locator("[data-slot=artifact-viewer-header]"); + await header.getByRole("heading", { name: title, level: 1 }).waitFor(); + await header.getByRole("tablist").waitFor(); + await header.getByRole("button", { name: /Choose a version/ }).waitFor(); + await header.getByRole("button", { name: "Share" }).waitFor(); + await header.getByRole("button", { name: "More actions" }).waitFor(); + // The tabs work from the keyboard. + await header.getByRole("tab", { name: "Preview" }).focus(); + await page.keyboard.press("ArrowRight"); + await page.keyboard.press("Enter"); await page - .getByRole("heading", { name: "Q3 launch plan", level: 1 }) - .first() + .getByRole("tab", { name: /Source|Code/, selected: true }) .waitFor(); - expect(new URL(page.url()).pathname).toBe(`/artifacts/${PLAN_ID}`); + expect(await measured(page)).toEqual(HOLDS); + + // Back: the list, scrolled where it was, with focus on the tile that opened it. + await page.getByRole("button", { name: "Back to Artifacts" }).click(); + await page.waitForFunction( + () => new URL(location.href).searchParams.get("artifact") === null, + ); + expect(await scroller()).toBe(scrolled); + expect( + await page.evaluate( + () => + document.activeElement + ?.closest("[data-slot=artifact-tile]") + ?.textContent?.includes("Launch countdown") ?? false, + ), + ).toBe(true); + expect(await unanswered(page)).toEqual([]); + } finally { + await page.close(); + } + }, 90_000); + + test("a link to an artifact still opens it, full page; Back leads to the list", async () => { + for (const path of [ + `/artifacts?artifact=${PLAN_ID}`, + `/artifacts/${PLAN_ID}`, + ]) { + const { page } = await open({ + entry: "app", + path, + theme: "light", + window: WIDE, + ready: (one) => + one + .getByRole("heading", { name: "Q3 launch plan", level: 1 }) + .first() + .waitFor(), + }); + try { + await page.getByRole("button", { name: "More actions" }).waitFor(); + await page + .getByRole("link", { name: "Back to Artifacts" }) + .or(page.getByRole("button", { name: "Back to Artifacts" })) + .click(); + await page + .getByRole("button", { name: "Pricing calculator" }) + .waitFor(); + const url = new URL(page.url()); + expect(url.pathname).toBe("/artifacts"); + expect(url.searchParams.get("artifact")).toBeNull(); + } finally { + await page.close(); + } + } + }, 60_000); + + /* + * FROM THE DESIGN REVIEW. On a narrow window the panel was a sheet, and Escape closed it. Full + * page, Escape still closes the artifact, unless a menu or a field has it. + */ + test("Escape closes the artifact, after closing a menu over it first", async () => { + const { page } = await open({ + entry: "app", + path: `/artifacts?artifact=${PLAN_ID}`, + theme: "light", + window: NARROW, + ready: (one) => + one.getByRole("button", { name: "More actions" }).waitFor(), + }); + try { + await page.getByRole("button", { name: "More actions" }).click(); + await page.getByRole("menu").waitFor(); + await page.keyboard.press("Escape"); + await page.getByRole("menu").waitFor({ state: "detached" }); + expect(new URL(page.url()).searchParams.get("artifact")).toBe(PLAN_ID); + await page.keyboard.press("Escape"); + await page.waitForFunction( + () => new URL(location.href).searchParams.get("artifact") === null, + ); + await page.getByRole("button", { name: "Pricing calculator" }).waitFor(); + } finally { + await page.close(); + } + }, 60_000); + + test("opened full screen from a conversation, Back says Back and goes back there", async () => { + const { page } = await open({ + entry: "app", + path: "/artifacts", + theme: "light", + window: WIDE, + ready: (one) => + one.getByRole("button", { name: "Pricing calculator" }).waitFor(), + }); + try { + // As the panel's Open full screen navigates: with the state that says where it came from. + await page.evaluate( + (artifactId) => + ( + window as unknown as { + appRouter: { + navigate: (options: Record) => Promise; + }; + } + ).appRouter.navigate({ + to: "/artifacts/$artifactId", + params: { artifactId }, + state: { artifactFromConversation: true }, + }), + PLAN_ID, + ); + await page.getByRole("button", { name: "Back", exact: true }).waitFor(); + expect( + await page.getByRole("button", { name: "Back to Artifacts" }).count(), + ).toBe(0); + await page.getByRole("button", { name: "Back", exact: true }).click(); + await page.waitForFunction(() => location.pathname === "/artifacts"); + // A link from anywhere else keeps "Back to Artifacts". + await page.goto(`${ORIGIN}/artifacts/${PLAN_ID}`); + await page.getByLabel("Back to Artifacts").waitFor(); } finally { await page.close(); } @@ -1512,7 +1727,7 @@ const SCREENS: Screen[] = [ ready: (page) => page.getByText("No artifacts yet").waitFor(), }, { - name: "artifacts-with-panel", + name: "artifacts-open", entry: "app", path: `/artifacts?artifact=${DASHBOARD_ID}`, ready: (page) => @@ -1533,7 +1748,7 @@ const SCREENS: Screen[] = [ }, // A person's cream theme on the deck and the dashboard: the content takes it, the viewer doesn't. { - name: "panel-themed-slides", + name: "open-themed-slides", entry: "app", path: `/artifacts?themed=1&artifact=Zx3Ty8Wq1Pk6Lm2Nb7Vc4D`, ready: (page) => inViewer(page).getByText("Board update").first().waitFor(), @@ -1545,7 +1760,7 @@ const SCREENS: Screen[] = [ ready: (page) => inViewer(page).getByText("Board update").first().waitFor(), }, { - name: "panel-themed-dashboard", + name: "open-themed-dashboard", entry: "app", path: `/artifacts?themed=1&artifact=${DASHBOARD_ID}`, ready: (page) =>