Skip to content

Commit b88b94a

Browse files
committed
fix(app): preserve Side bar project and descendant activity state
1 parent af04a8b commit b88b94a

6 files changed

Lines changed: 223 additions & 9 deletions

File tree

‎packages/app/e2e/regression/tabs.spec.ts‎

Lines changed: 170 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,33 @@ const c = { id: "ses_tab_c", title: "Tab C session" }
2828

2929
test.use({ serviceWorkers: "block" })
3030

31+
for (const locale of ["en", "ar"] as const) {
32+
test(`Side bar keeps opposite-direction titles clear of the close affordance in ${locale}`, async ({ page }) => {
33+
await mockWorkspace(page, {
34+
name: "Mixed direction",
35+
sessions: [{ ...a, title: locale === "ar" ? "Project task" : "مهمة المشروع" }],
36+
seed: { locale, tabs: [a.id], settings: { appearance: { tabLayout: "sidebar" } } },
37+
})
38+
await page.goto(sessionHref(a.id))
39+
const link = page.locator(`[data-slot="vertical-tabs-sidebar"] a[href="${sessionHref(a.id)}"]`)
40+
await expect(link).toBeVisible()
41+
await link.hover()
42+
await expect
43+
.poll(() =>
44+
link.evaluate((element) => {
45+
const title = element.querySelector("[data-titlebar-tab-title]")
46+
if (!title) throw new Error("Missing session title")
47+
const range = document.createRange()
48+
range.selectNodeContents(title)
49+
const text = range.getBoundingClientRect()
50+
const row = element.getBoundingClientRect()
51+
return getComputedStyle(element).direction === "rtl" ? text.left - row.left : row.right - text.right
52+
}),
53+
)
54+
.toBeGreaterThan(40)
55+
})
56+
}
57+
3158
test("Side bar keeps project history and running sessions separate from the official interface modes", async ({
3259
page,
3360
}) => {
@@ -167,6 +194,149 @@ test("sidebar and Home share projects and history without opening session tabs",
167194
)
168195
})
169196

197+
test("project headers collapse every session independently of the recent preview and preserve the choice", async ({
198+
page,
199+
}) => {
200+
await mockWorkspace(page, {
201+
name: "Collapse project",
202+
sessions: Array.from({ length: 7 }, (_, index) => ({ id: `ses_collapse_${index}`, title: `Task ${index}` })),
203+
seed: { tabs: [], settings: { appearance: { tabLayout: "sidebar" } } },
204+
})
205+
await page.goto("/")
206+
const sidebar = page.locator('[data-slot="vertical-tabs-sidebar"]')
207+
const titles = sidebar.locator("[data-titlebar-tab-title]")
208+
const collapse = sidebar.getByRole("button", { name: "Collapse project Collapse project", exact: true })
209+
await expect(titles).toHaveCount(5)
210+
await expect(collapse).toHaveAttribute("aria-expanded", "true")
211+
await collapse.focus()
212+
await page.keyboard.press("Enter")
213+
await expect(titles).toHaveCount(0)
214+
await expect(sidebar.getByRole("button", { name: /Show 2 more sessions/ })).toHaveCount(0)
215+
await expect(sidebar.getByRole("heading", { name: "Collapse project", exact: true })).toBeVisible()
216+
await expect(sidebar.getByRole("region", { name: "Running sessions", exact: true })).toBeVisible()
217+
await page.reload()
218+
await expect(titles).toHaveCount(0)
219+
await sidebar.getByRole("button", { name: "Expand project Collapse project", exact: true }).click()
220+
await expect(titles).toHaveCount(5)
221+
await sidebar.getByRole("button", { name: "Show 2 more sessions in Collapse project", exact: true }).click()
222+
await expect(titles).toHaveCount(7)
223+
await collapse.click()
224+
await expect(titles).toHaveCount(0)
225+
await sidebar.getByRole("button", { name: "Group sessions By project", exact: true }).click()
226+
await page.getByRole("option", { name: "List", exact: true }).click()
227+
await expect(titles).toHaveCount(7)
228+
await sidebar.getByRole("button", { name: "Group sessions List", exact: true }).click()
229+
await page.getByRole("option", { name: "By project", exact: true }).click()
230+
await expect(titles).toHaveCount(0)
231+
await sidebar.getByRole("button", { name: "New session in Collapse project", exact: true }).click()
232+
await expect(collapse).toHaveAttribute("aria-expanded", "true")
233+
await expect(titles).toHaveCount(8)
234+
await expect(page.locator('[data-component="new-session"] [data-action="prompt-project"]')).toContainText(
235+
"Collapse project",
236+
)
237+
})
238+
239+
test("recent parents stay busy while descendants execute and busy icons resume after idle", async ({ page }) => {
240+
await page.emulateMedia({ reducedMotion: "no-preference" })
241+
const child = { id: "ses_busy_descendant", title: "Running child", parentID: a.id }
242+
const grandchild = { id: "ses_busy_grandchild", title: "Running grandchild", parentID: child.id }
243+
const workspace = await mockWorkspace(page, {
244+
name: "Family status",
245+
sessions: [
246+
a,
247+
child,
248+
grandchild,
249+
...Array.from({ length: 24 }, (_, index) => ({ id: `ses_scroll_${index}`, title: `Scroll task ${index}` })),
250+
],
251+
sessionStatus: { [grandchild.id]: { type: "running" } },
252+
seed: { tabs: [], settings: { appearance: { tabLayout: "sidebar", tabGrouping: "none" } } },
253+
})
254+
await page.goto("/")
255+
const sidebar = page.locator('[data-slot="vertical-tabs-sidebar"]')
256+
const tab = sidebar.locator(`[data-titlebar-tab-slot]:has(a[href="${sessionHref(a.id)}"])`)
257+
const spinner = tab.locator('[data-component="activity-ring"]')
258+
await expect(tab.locator("[data-titlebar-tab]")).toHaveAttribute("data-status", "busy")
259+
await expect(spinner).toBeVisible()
260+
await spinner.scrollIntoViewIfNeeded()
261+
await expect(
262+
page
263+
.locator('[data-component="home-session-row"]')
264+
.filter({ hasText: a.title })
265+
.locator('[data-component="activity-ring"]'),
266+
).toBeVisible()
267+
const animations = (target = spinner) =>
268+
target.evaluate((element) =>
269+
element
270+
.getAnimations({ subtree: true })
271+
.map((animation) => ({ state: animation.playState, time: Number(animation.currentTime) })),
272+
)
273+
await expect.poll(async () => (await animations()).every((animation) => animation.state === "running")).toBe(true)
274+
const childSpinner = sidebar
275+
.getByRole("region", { name: "Running sessions", exact: true })
276+
.getByRole("button")
277+
.filter({ hasText: grandchild.title })
278+
.locator('[data-component="activity-ring"]')
279+
await expect
280+
.poll(async () => {
281+
const values = await animations(childSpinner)
282+
return values.length > 0 && values.every((animation) => animation.state === "running")
283+
})
284+
.toBe(true)
285+
await workspace.push([
286+
{
287+
id: "evt_family_finish",
288+
created: 1700000002000,
289+
type: "session.execution.succeeded",
290+
durable: { aggregateID: grandchild.id, seq: 1, version: 1 },
291+
data: { sessionID: grandchild.id },
292+
},
293+
])
294+
await expect(tab.locator("[data-titlebar-tab]")).not.toHaveAttribute("data-status", "busy")
295+
await workspace.push([
296+
{
297+
id: "evt_family_restart",
298+
created: 1700000003000,
299+
type: "session.execution.started",
300+
durable: { aggregateID: grandchild.id, seq: 2, version: 1 },
301+
data: { sessionID: grandchild.id },
302+
},
303+
])
304+
await expect(spinner).toBeVisible()
305+
await expect
306+
.poll(async () => {
307+
const values = await animations()
308+
return values.length > 0 && values.every((animation) => animation.state === "running")
309+
})
310+
.toBe(true)
311+
const time = (await animations())[0]!.time
312+
await expect.poll(async () => (await animations())[0]!.time).toBeGreaterThan(time)
313+
const scroll = sidebar.locator('[data-slot="vertical-tabs-scroll"]')
314+
await scroll.evaluate((element) => {
315+
element.scrollTop = 0
316+
})
317+
await expect(spinner).toHaveAttribute("data-offscreen", "")
318+
await spinner.scrollIntoViewIfNeeded()
319+
await expect(spinner).not.toHaveAttribute("data-offscreen")
320+
await expect.poll(async () => (await animations()).every((animation) => animation.state === "running")).toBe(true)
321+
await page.emulateMedia({ reducedMotion: "reduce" })
322+
await expect(page.locator("html")).toHaveAttribute("data-motion", "reduce")
323+
await expect.poll(async () => (await animations()).length).toBe(0)
324+
await expect.poll(async () => (await animations(childSpinner)).length).toBe(0)
325+
await page.emulateMedia({ reducedMotion: "no-preference" })
326+
await expect
327+
.poll(async () => {
328+
const values = await animations()
329+
return values.length > 0 && values.every((animation) => animation.state === "running")
330+
})
331+
.toBe(true)
332+
await expect
333+
.poll(async () => {
334+
const values = await animations(childSpinner)
335+
return values.length > 0 && values.every((animation) => animation.state === "running")
336+
})
337+
.toBe(true)
338+
})
339+
170340
test("recent sessions caps each project at five and can reveal a selected overflow session", async ({ page }) => {
171341
const large = Array.from({ length: 10 }, (_, index) => ({ id: `ses_limit_${index}`, title: `Large task ${index}` }))
172342
const small = Array.from({ length: 3 }, (_, index) => ({

‎packages/app/src/runtime/i18n/en.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -770,6 +770,8 @@ export const dict = {
770770
"sidebar.session.branch": "Branch: {{branch}}",
771771
"sidebar.session.worktree": "Worktree: {{path}}",
772772
"sidebar.project.newSession": "New session in {{project}}",
773+
"sidebar.project.expand": "Expand project {{project}}",
774+
"sidebar.project.collapse": "Collapse project {{project}}",
773775
"sidebar.recent.hide": "Hide from recent sessions",
774776
"sidebar.recent.more.one": "More ({{count}})",
775777
"sidebar.recent.more.other": "More ({{count}})",

‎packages/app/src/runtime/server/runtime.tsx‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,15 @@ function createServerController(
227227
remove: (sessionID) => sdk.api.session.remove({ sessionID }),
228228
})
229229

230+
// The active index can arrive before session metadata. Load missing ancestors so a
231+
// descendant still keeps its root busy after reconnecting, without reading transcripts.
232+
createEffect(() => {
233+
new Set(data.session.active().map((id) => data.session.root(id))).forEach((id) => {
234+
if (data.session.get(id)) return
235+
void data.session.sync(id).catch(() => undefined)
236+
})
237+
})
238+
230239
// Transcripts otherwise stay loaded for every session this window ever opened. Open tabs and the three most
231240
// recently viewed sessions keep theirs; any other session reloads its transcript when it is opened again.
232241
createSessionRetention({

‎packages/app/src/shell/layout/project-avatar-state.ts‎

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,7 @@ export function useSessionTabAvatarState(
4242

4343
if (needsAttention()) return false
4444

45-
if (root?.())
46-
return data.session
47-
.list()
48-
.some((session) => data.session.root(session.id) === sessionId() && sessionBusy(data, session.id))
45+
if (root?.()) return [sessionId(), ...data.session.family(sessionId())].some((id) => sessionBusy(data, id))
4946

5047
return sessionBusy(data, sessionId())
5148
})

‎packages/app/src/shell/titlebar/sidebar-sessions.tsx‎

Lines changed: 32 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -478,6 +478,9 @@ export function SidebarSessions(props: {
478478
const sidebarOrder = props.grouping
479479
? persisted(Persist.window("sidebar.order"), Schema.Array(Schema.String), [])
480480
: undefined
481+
const collapsed = props.grouping
482+
? persisted(Persist.window("sidebar.collapsedProjects"), Schema.Array(Schema.String), [])
483+
: undefined
481484
const indexed = createMemo(
482485
() =>
483486
new Map(
@@ -627,6 +630,7 @@ export function SidebarSessions(props: {
627630
() =>
628631
new Map(
629632
groups().map((group) => {
633+
if (collapsed?.[0].includes(group.key)) return [group.key, [] as Tab[]] as const
630634
if (expanded[group.key]) return [group.key, group.tabs] as const
631635
const current = props.currentTab
632636
const active = current && group.tabs.find((tab) => tabKey(tab) === tabKey(current))
@@ -801,7 +805,7 @@ export function SidebarSessions(props: {
801805
<div
802806
data-slot={vertical() ? "vertical-tabs" : "titlebar-tabs"}
803807
data-orientation={vertical() ? "vertical" : "horizontal"}
804-
class="relative min-w-0"
808+
class="sidebar-sessions relative min-w-0"
805809
classList={{ "min-h-0 overflow-hidden": vertical() }}
806810
>
807811
<Show when={vertical() && props.grouping}>
@@ -922,10 +926,32 @@ export function SidebarSessions(props: {
922926
>
923927
<div class="flex min-w-0 items-center gap-2">
924928
<h3
925-
dir="auto"
926-
class="min-w-0 flex-1 truncate text-[13px] leading-4 font-medium text-v2-text-text-base"
929+
aria-label={group().name}
930+
class="min-w-0 flex-1 text-[13px] leading-4 font-medium text-v2-text-text-base"
927931
>
928-
{group().name}
932+
<button
933+
type="button"
934+
class="flex w-full min-w-0 items-center gap-1 rounded-sm text-start outline-none focus-visible:ring-1 focus-visible:ring-v2-border-border-focus"
935+
aria-label={language.t(
936+
collapsed?.[0].includes(key) ? "sidebar.project.expand" : "sidebar.project.collapse",
937+
{ project: group().name },
938+
)}
939+
aria-expanded={!collapsed?.[0].includes(key)}
940+
onClick={() => {
941+
if (!collapsed?.[3]()) return
942+
collapsed[1]((keys) =>
943+
keys.includes(key) ? keys.filter((item) => item !== key) : [...keys, key],
944+
)
945+
}}
946+
>
947+
<Icon
948+
name={collapsed?.[0].includes(key) ? "chevron-right" : "chevron-down"}
949+
class="shrink-0"
950+
/>
951+
<span dir="auto" class="min-w-0 flex-1 truncate">
952+
{group().name}
953+
</span>
954+
</button>
929955
</h3>
930956
<span class="shrink-0 rounded px-1 text-[11px] leading-4 tabular-nums text-v2-text-text-faint">
931957
{group().recent}/{group().total}
@@ -939,6 +965,7 @@ export function SidebarSessions(props: {
939965
aria-label={language.t("sidebar.project.newSession", { project: group().name })}
940966
title={language.t("sidebar.project.newSession", { project: group().name })}
941967
onClick={() => {
968+
collapsed?.[1]((keys) => keys.filter((item) => item !== key))
942969
global.serverCtx(group().connection)?.projects.touch(directory())
943970
void tabs.newDraft({ server: group().connection, directory: directory() })
944971
}}
@@ -961,7 +988,7 @@ export function SidebarSessions(props: {
961988
</Show>
962989
<Show when={grouped() && groupsByKey().get(key)}>
963990
{(group) => (
964-
<Show when={group().tabs.length > PROJECT_SESSION_LIMIT}>
991+
<Show when={!collapsed?.[0].includes(key) && group().tabs.length > PROJECT_SESSION_LIMIT}>
965992
<Button
966993
variant="ghost-muted"
967994
size="small"

‎packages/app/src/shell/titlebar/tab-nav.css‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,15 @@
156156
gap: 2px;
157157
}
158158

159+
/* Titles keep dir="auto", but align with the row so the close-button mask stays clear of their start. */
160+
.sidebar-sessions:dir(ltr) [data-titlebar-tab-title] {
161+
text-align: left;
162+
}
163+
164+
.sidebar-sessions:dir(rtl) [data-titlebar-tab-title] {
165+
text-align: right;
166+
}
167+
159168
[data-slot="vertical-tabs-sidebar"] [data-titlebar-tab-list][data-orientation="vertical"] {
160169
gap: 4px;
161170
}

0 commit comments

Comments
 (0)