Skip to content

Commit f9de9ff

Browse files
committed
fix(es-app): sidebar marks the open session by host and session ID, so Local's same-ID row is not highlighted for a Mini session
1 parent 6e57ec0 commit f9de9ff

2 files changed

Lines changed: 90 additions & 12 deletions

File tree

‎packages/es-app/src/components/sidebar.tsx‎

Lines changed: 27 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* icon, then one status dot per session, still navigable. Archived sessions
44
* drop to a collapsed section at the bottom of the expanded view. */
55
import { createEffect, createMemo, createSignal, For, onCleanup, Show } from "solid-js"
6-
import { A } from "@solidjs/router"
6+
import { A, useLocation } from "@solidjs/router"
77
import { es, type SessionSearchResult } from "../api"
88
import { sessionHref, useDashboard, type DotState, type SessionRow } from "../state"
99
import { leftOpen, leftWidth, toggleLeft } from "../ui"
@@ -67,6 +67,17 @@ export default function Sidebar() {
6767
// carry their host and open on that host's own tab; a host that stops answering keeps its last
6868
// rows, dimmed and disabled, never emptied or merged into this host's.
6969
const hosted = () => work.feeds().length > 0
70+
// The open session's host-qualified key. The same session ID can exist on Local and on another host, so the
71+
// path alone cannot say which row is open; `?host=` (absent or "local": this page's Core) decides, as the
72+
// session page does.
73+
const location = useLocation()
74+
const openKey = createMemo(() => {
75+
const match = /^\/session\/([^/]+)/.exec(location.pathname)
76+
if (!match) return undefined
77+
const host = location.query.host
78+
return hostRowKey({ id: decodeURIComponent(match[1]), host: typeof host === "string" && host && host !== "local" ? host : undefined })
79+
})
80+
const isOpen = (s: SessionRow) => openKey() === hostRowKey(s)
7081
// Unified Work: this machine and every other Work host, all shown by default. Hiding a host is a per-page
7182
// choice stored as the hidden set, so a host added later is shown; Personal pages have no Work strip.
7283
const ownHost = () => host()?.work.find((item) => item.id === host()?.id) ?? { id: host()?.id ?? "local", label: "Local" }
@@ -282,31 +293,33 @@ export default function Sidebar() {
282293
if (s.host) return hostItem(s)
283294
const dot = createMemo(() => dotFor(s))
284295
return cls === "archived" ? (
285-
<A
296+
<a
286297
href={sessionHref(s.id, s.directory)}
287-
activeClass="active"
288298
class="nav-item archived"
299+
classList={{ active: isOpen(s) }}
300+
aria-current={isOpen(s) ? "page" : undefined}
289301
{...peekAttrs(s)}
290302
>
291303
<StatusDot state={dot()} label={dotText(s, dot())} />
292304
<span class="nav-title" dir="auto">{s.title || s.id}</span>
293305
{/* All scope: the project lives in the hover/focus card; screen readers still hear it here. */}
294306
<Show when={allProjects() && s.project}><span class="sr-only">, {s.project}</span></Show>
295-
</A>
307+
</a>
296308
) : (
297309
<div class="session-entry" {...peekAttrs(s)}>
298-
<A
310+
<a
299311
ref={(el) => observeSession(el, s.id)}
300312
href={sessionHref(s.id, s.directory)}
301-
activeClass="active"
302313
class="nav-item"
314+
classList={{ active: isOpen(s) }}
315+
aria-current={isOpen(s) ? "page" : undefined}
303316
>
304317
<StatusDot state={dot()} label={dotText(s, dot())} />
305318
<Show when={hosted()}><HostGlyph host="local" /></Show>
306319
<span class="nav-title" dir="auto">{s.title || s.id}</span>
307320
<Show when={allProjects() && s.project}><span class="sr-only">, {s.project}</span></Show>
308321
<Show when={hosted()}><span class="sr-only">, on Local</span></Show>
309-
</A>
322+
</a>
310323
<button type="button" class="pin-action" classList={{ pinned: isPinned(s) }}
311324
aria-label={`${isPinned(s) ? "Unpin" : "Pin"} ${s.title || s.id}`}
312325
title={`${isPinned(s) ? "Unpin" : "Pin"} ${s.title || s.id}`}
@@ -324,7 +337,8 @@ export default function Sidebar() {
324337
const name = () => `${s.title || s.id}, on ${label()}${down() ? ", unavailable" : ""}`
325338
return (
326339
<div class="session-entry host-entry" classList={{ unavailable: down() }}>
327-
<a href={feed ? hostSessionHref(feed.host, s) : undefined} class="nav-item" aria-label={name()} aria-disabled={down() || undefined}
340+
<a href={feed ? hostSessionHref(feed.host, s) : undefined} class="nav-item" classList={{ active: isOpen(s) }}
341+
aria-current={isOpen(s) ? "page" : undefined} aria-label={name()} aria-disabled={down() || undefined}
328342
title={down() ? `${label()} · unreachable since ${clock(feed?.state().since ?? Date.now())}; last-known list, actions disabled` : `${s.title || s.id} — on ${label()}`}
329343
data-host-key={hostRowKey(s)} onClick={(event) => { if (down()) event.preventDefault() }}>
330344
<StatusDot state={dot()} label={`${label()}: ${dot()}`} />
@@ -356,7 +370,8 @@ export default function Sidebar() {
356370
if (s.host) {
357371
const feed = feedOf(s)
358372
return <div class="mini-session" classList={{ unavailable: feed?.state().status === "unavailable" }}>
359-
<a href={feed ? hostSessionHref(feed.host, s) : undefined} class="mini-item" title={`${s.title} — on ${feed?.host.label ?? s.host}`}
373+
<a href={feed ? hostSessionHref(feed.host, s) : undefined} class="mini-item" classList={{ active: isOpen(s) }}
374+
aria-current={isOpen(s) ? "page" : undefined} title={`${s.title} — on ${feed?.host.label ?? s.host}`}
360375
aria-label={`${s.title || s.id}, on ${feed?.host.label ?? s.host}`}>
361376
<StatusDot state={work.dot(s)} />
362377
</a>
@@ -365,11 +380,11 @@ export default function Sidebar() {
365380
const dot = createMemo(() => dotFor(s))
366381
return (
367382
<div class="mini-session" {...peekAttrs(s)}>
368-
<A ref={(el) => observeSession(el, s.id)} href={sessionHref(s.id, s.directory)}
369-
activeClass="active" class="mini-item"
383+
<a ref={(el) => observeSession(el, s.id)} href={sessionHref(s.id, s.directory)}
384+
class="mini-item" classList={{ active: isOpen(s) }} aria-current={isOpen(s) ? "page" : undefined}
370385
title={`${s.title} (${dotText(s, dot())})${allProjects() ? ` · ${s.project}` : ""}`}>
371386
<StatusDot state={dot()} label={`${s.title || s.id}: ${dotText(s, dot())}`} />
372-
</A>
387+
</a>
373388
<button type="button" class="mini-pin" classList={{ pinned: isPinned(s) }}
374389
aria-label={`${isPinned(s) ? "Unpin" : "Pin"} ${s.title || s.id}`}
375390
title={`${isPinned(s) ? "Unpin" : "Pin"} ${s.title || s.id}`}
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
// Same session ID on two hosts: the sidebar marks only the open host's row as current. Local and the Mac Mini
2+
// both hold ses_a; opening ?host=mini highlights the Mini row (list and pinned band), never Local's, and back.
3+
// Run from packages/es-app: node test/sidebar-same-id.browser.mjs
4+
import { createRequire } from "node:module"
5+
import { startPanelPreview } from "./composer-panel-preview.mjs"
6+
import { directory } from "./composer-fixture.mjs"
7+
8+
const { chromium, expect } = createRequire(new URL("../../app/package.json", import.meta.url))("@playwright/test")
9+
const preview = await startPanelPreview()
10+
const browser = await chromium.launch({ headless: true,
11+
...(process.env.CHROMIUM_EXECUTABLE ? { executablePath: process.env.CHROMIUM_EXECUTABLE } : { channel: "chrome" }) })
12+
const page = await browser.newPage({ viewport: { width: 1280, height: 900 } })
13+
const errors = []
14+
page.on("pageerror", (error) => errors.push(error.message))
15+
const miniRoot = "/Users/mini/fixture"
16+
const miniSession = { id: "ses_a", title: "Mini copy of a", directory: miniRoot, time: { created: 1, updated: Date.now() } }
17+
await page.route("**/__es/host", (route) => route.fulfill({ json: { id: "local", label: "Local", remote: false, hosts: [], work: [
18+
{ id: "local", label: "Local", origin: preview.fixture.url },
19+
{ id: "mini", label: "Mac Mini", origin: "http://127.0.0.1:65001", default: true },
20+
] } }))
21+
await page.route("**/hosts/mini/**", (route) => {
22+
const path = new URL(route.request().url()).pathname
23+
if (path === "/hosts/mini/oc/experimental/session") return route.fulfill({ json: [miniSession] })
24+
if (path === "/hosts/mini/oc/session/ses_a") return route.fulfill({ json: { ...miniSession, slug: "a", projectID: "p", version: "1" } })
25+
if (path === "/hosts/mini/oc/session/status") return route.fulfill({ json: {} })
26+
if (path === "/hosts/mini/oc/session/ses_a/input") return route.fulfill({ json: { items: [], next: null } })
27+
if (path === "/hosts/mini/oc/config/providers") return route.fulfill({ json: { providers: [], default: {} } })
28+
if (path === "/hosts/mini/es/api/attention") return route.fulfill({ json: { records: [], projects: [], partial: false } })
29+
if (path === "/hosts/mini/es/api/editspaces") return route.fulfill({ json: { editspaces: [{ name: "fixture", root: `${miniRoot}/.editspace` }], default: "fixture" } })
30+
return route.fulfill({ json: [] })
31+
})
32+
const list = ".sidebar [role=tabpanel] > .session-entry"
33+
const miniRow = () => page.locator(`${list} .nav-item[data-host-key='mini:ses_a']`)
34+
const localRow = () => page.locator(`${list} .nav-item:not([data-host-key])`, { hasText: "Composer fixture" })
35+
const current = () => page.locator(".sidebar [aria-current=page]")
36+
try {
37+
await page.goto(`${preview.url.replace(/\/$/, "")}/session/ses_a?directory=${encodeURIComponent(directory)}&host=mini`)
38+
await expect(miniRow()).toHaveAttribute("aria-current", "page")
39+
await expect(miniRow()).toHaveClass(/\bactive\b/)
40+
await expect(localRow()).not.toHaveAttribute("aria-current", "page")
41+
await expect(localRow()).not.toHaveClass(/\bactive\b/)
42+
43+
// Opening Local's ses_a from the list moves the mark to Local only.
44+
await localRow().click()
45+
await expect(page).not.toHaveURL(/host=mini/)
46+
await expect(localRow()).toHaveAttribute("aria-current", "page")
47+
await expect(miniRow()).not.toHaveAttribute("aria-current", "page")
48+
await expect(miniRow()).not.toHaveClass(/\bactive\b/)
49+
50+
// Pinned band: both copies pinned; the mark follows the host there too.
51+
await page.locator(`${list}:has(.nav-item[data-host-key='mini:ses_a']) .pin-action`).click()
52+
await page.locator(`${list}:has(.nav-item:not([data-host-key]))`, { hasText: "Composer fixture" }).locator(".pin-action").click()
53+
await expect(page.locator(".sidebar .nav-item[data-host-key='mini:ses_a']")).toHaveCount(1)
54+
await miniRow().or(page.locator(".sidebar .nav-item[data-host-key='mini:ses_a']")).first().click()
55+
await expect(page).toHaveURL(/host=mini/)
56+
await expect(current()).toHaveCount(1)
57+
await expect(current()).toHaveAttribute("data-host-key", "mini:ses_a")
58+
expect(errors).toEqual([])
59+
console.log("sidebar-same-id: PASS")
60+
} finally {
61+
await browser.close()
62+
await preview.close()
63+
}

0 commit comments

Comments
 (0)