GeezerVison is showing github.com — feat(app): group Home sessions by project by liambreen · Pull Request #57895 · anomalyco/opencode
feat(app): group Home sessions by project
#57895
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and
privacy statement . We’ll occasionally send you account related emails.
Already on GitHub?
Sign in
to your account
Uh oh!
There was an error while loading. Please reload this page.
Show file tree
Hide file tree
Changes from all commits
Commits
File filter
Filter by extension
.ts
(4)
.tsx
(3)
All 2 file types selected
Viewed files
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Hide whitespace
Diff view
Hide whitespace
There are no files selected for viewing
Original file line number
Diff line number
Diff line change
Expand Up
@@ -104,6 +104,75 @@ test("the Home shortcut focuses session search, and the Home button leaves focus
await expect(search).not.toBeFocused()
})
test("the sessions list groups by project on demand and keeps the choice", async ({ page }) => {
const secondDirectory = "C:/OpenCode/SecondProject"
const secondSession = {
id: "ses_smoke_second",
slug: "second",
projectID: "proj_second",
directory: secondDirectory,
title: "Second project session",
version: "dev",
time: { created: 1700000003000, updated: 1700000003000 },
}
await mockStressTimeline(page, {
projects: [fixture.project, { ...fixture.project, id: "proj_second", worktree: secondDirectory, name: "second-project" }],
sessions: [...fixture.sessions.map((item) => ({ ...item })), secondSession],
})
await seed(page, {
projects: {
local: [
{ worktree: fixture.directory, expanded: true },
{ worktree: secondDirectory, expanded: true },
],
},
})
await page.goto("/")
const projectGroup = (name: string) =>
page.locator('[data-component="home-session-project-group"]').filter({ hasText: name })
const smokeRow = row(page, fixture.expected.sourceTitle)
const smokeGroup = projectGroup(fixture.project.name!)
const secondGroup = projectGroup("second-project")
// Date mode: rows carry the project suffix and no project headers exist.
await expect(smokeRow).toBeVisible()
await expect(smokeRow.locator('[data-component="home-session-project-name"]')).toBeVisible()
await expect(projectGroup(fixture.project.name!)).toHaveCount(0)
const grouping = page.getByRole("button", { name: "Group by project" })
await expect(grouping).toHaveAttribute("aria-pressed", "false")
await grouping.click()
await expect(page.getByRole("button", { name: "Group by date" })).toHaveAttribute("aria-pressed", "true")
// Project mode: one header per project, most recently active first, and rows drop the suffix.
await expect(secondGroup).toBeVisible()
await expect(smokeGroup).toBeVisible()
expect((await secondGroup.boundingBox())!.y).toBeLessThan((await smokeGroup.boundingBox())!.y)
await expect(smokeRow.locator('[data-component="home-session-project-name"]')).toBeHidden()
// Headers stay compact: sidebar-grade rows, clearly shorter than session rows.
await expect(smokeGroup).toHaveCSS("height", "20px")
// Collapsing a group hides its rows while other groups stay expanded.
await smokeGroup.click()
await expect(smokeGroup).toHaveAttribute("aria-expanded", "false")
await expect(secondGroup).toHaveAttribute("aria-expanded", "true")
await expect(smokeRow).toBeHidden()
// Both the grouping mode and the collapsed group survive a reload.
await page.reload()
await expect(smokeGroup).toHaveAttribute("aria-expanded", "false")
await expect(smokeRow).toBeHidden()
// Expanding brings the rows back, and the toggle returns the date view.
await smokeGroup.click()
await expect(smokeGroup).toHaveAttribute("aria-expanded", "true")
await expect(smokeRow).toBeVisible()
await page.getByRole("button", { name: "Group by date" }).click()
await expect(smokeGroup).toHaveCount(0)
await expect(smokeRow.locator('[data-component="home-session-project-name"]')).toBeVisible()
})
test("Home shows loaded sessions before the location request resolves", async ({ page }) => {
const location = await holdRoute(page, (url) => url.pathname === "/api/location")
await openHome(page)
Expand Down
Original file line number
Diff line number
Diff line change
Expand Up
@@ -24,20 +24,24 @@ import { fetchSessionExport, saveSessionExport, sessionExportFilename } from "@/
import { usePlatform } from "@/runtime/platform/platform"
import { sessionLabel, sessionTitle } from "@/session/title"
import { showToast } from "@/shell/notifications/toast"
import { Schema } from "effect"
import { Persist, persisted } from "@/runtime/persistence/storage"
import { Persistence } from "@/runtime/persistence/schema"
import { archiveHomeSession } from "./archive"
import type { HomeController } from "../model"
import { groupHomeSessionsByProject, type HomeSessionGroup } from "./grouping"
import { buildHomeSessionRecords, homeProjectForSession, homeSessionLocation, type HomeSessionRecord } from "./records"
export type { HomeSessionRecord } from "./records"
export type { HomeSessionGroup } from "./grouping"
// Keep the immutable result opaque so Solid Query does not recursively unwrap every session on mount.
const selectSessions = (sessions: SessionInfo[]) => () => sessions
export type HomeSessionGroup = {
id: "today" | "yesterday" | "older"
title: string
sessions: HomeSessionRecord[]
}
export const HomeSessionsViewSchema = Persistence.struct({
grouping: Schema.Literals(["date", "project"]),
collapsed: Persistence.record(Persistence.fallback(Schema.Boolean, () => false)),
})
export type OpenSessionOptions = { background?: boolean }
Expand All
@@ -49,6 +53,12 @@ export function createHomeSessionsController(home: HomeController) {
const platform = usePlatform()
const queryClient = useQueryClient()
const [storedView, setStoredView] = persisted(
Persist.global("home.sessions"),
Comment thread
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more .
collapsed is keyed by pathKey(worktree), but it's stored under Persist.global. So the same path on two servers (e.g. /home/me/app locally and on a remote) shares one collapsed state, and entries are never pruned. If Home can show other servers, Persist.serverGlobal(...) (used elsewhere for per-server state) might fit better, at least for collapsed.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
HomeSessionsViewSchema,
{ grouping: "date", collapsed: {} },
)
const projectDirectories = createMemo(() => {
const selected = home.selection.value().directory
Expand Down
Expand Up
@@ -101,7 +111,11 @@ export function createHomeSessionsController(home: HomeController) {
)
const records = createMemo(() => allRecords().slice(0, HOME_SESSION_LIMIT))
const groups = createMemo(() => groupSessions(records(), language))
// Selecting a project already scopes the list to it, so project grouping only applies to the all-projects view.
const byProject = createMemo(() => storedView.grouping === "project" && !home.project.selected())
const groups = createMemo(() =>
byProject() ? groupHomeSessionsByProject(records()) : groupSessions(records(), language),
)
const prefetched = new Set<string>()
const location = (record: HomeSessionRecord) => {
Expand Down
Expand Up
@@ -307,6 +321,13 @@ export function createHomeSessionsController(home: HomeController) {
loading: () => sessionLoad.isPending,
searchRecords: allRecords,
},
grouping: {
byProject,
available: () => !home.project.selected(),
toggle: () => setStoredView("grouping", storedView.grouping === "project" ? "date" : "project"),
collapsed: (id: string) => storedView.collapsed[id] ?? false,
toggleCollapsed: (id: string) => setStoredView("collapsed", id, !(storedView.collapsed[id] ?? false)),
},
platform: {
desktop: platform.platform === "desktop",
},
Expand Down
Original file line number
Diff line number
Diff line change
@@ -0,0 +1,53 @@
import { describe, expect, test } from "bun:test"
import type { SessionInfo } from "@opencode/client/promise"
import type { LocalProject } from "@/shell/state/layout"
import { pathKey } from "@/workspaces/path-key"
import { groupHomeSessionsByProject } from "./grouping"
import { buildHomeSessionRecords } from "./records"
const session = (id: string, directory: string, updated: number) =>
({
id,
title: id,
location: { directory },
time: { created: updated, updated },
}) as SessionInfo
describe("groupHomeSessionsByProject", () => {
test("orders groups by most recent session and keeps recency order inside each", () => {
const records = buildHomeSessionRecords({
sessions: () => [session("a-new", "/repo/a", 3), session("b-new", "/repo/b", 2), session("a-old", "/repo/a", 1)],
projectDirectories: () => undefined,
projects: () => [],
})
const groups = groupHomeSessionsByProject(records)
expect(groups.map((group) => group.id)).toEqual([pathKey("/repo/a"), pathKey("/repo/b")])
expect(groups.map((group) => group.title)).toEqual(["a", "b"])
expect(groups[0].sessions.map((record) => record.session.id)).toEqual(["a-new", "a-old"])
expect(groups[1].sessions.map((record) => record.session.id)).toEqual(["b-new"])
})
test("groups sandbox sessions under their parent project", () => {
const project = {
id: "project-a",
worktree: "/repo/a",
sandboxes: ["/repo/a/.sandbox"],
expanded: true,
} as LocalProject
const records = buildHomeSessionRecords({
sessions: () => [session("sandbox", "/repo/a/.sandbox", 2), session("main", "/repo/a", 1)],
projectDirectories: () => undefined,
projects: () => [project],
})
const groups = groupHomeSessionsByProject(records)
expect(groups).toHaveLength(1)
expect(groups[0].id).toBe(pathKey("/repo/a"))
expect(groups[0].project?.worktree).toBe("/repo/a")
expect(groups[0].sessions.map((record) => record.session.id)).toEqual(["sandbox", "main"])
})
})
Original file line number
Diff line number
Diff line change
@@ -0,0 +1,21 @@
import type { LocalProject } from "@/shell/state/layout"
import { pathKey } from "@/workspaces/path-key"
import type { HomeSessionRecord } from "./records"
export type HomeSessionGroup = {
id: string
title: string
sessions: HomeSessionRecord[]
project?: LocalProject
}
// Records arrive sorted by session time, so first-seen order puts the most
// recently active project first, and each group keeps that recency order.
export function groupHomeSessionsByProject(records: HomeSessionRecord[]): HomeSessionGroup[] {
return [...Map.groupBy(records, (record) => pathKey(record.project.worktree)).entries()].map(([id, sessions]) => ({
id,
title: sessions[0].projectName,
project: sessions[0].project,
sessions,
}))
}
Original file line number
Diff line number
Diff line change
Expand Up
@@ -20,6 +20,11 @@ export function HomeSessions(props: {
location={props.sessions.location.value}
onRevealLocations={props.sessions.location.sync}
showProjectName={props.sessions.session.showProjectName()}
groupedByProject={props.sessions.grouping.byProject()}
showGroupingToggle={props.sessions.grouping.available()}
onToggleGrouping={props.sessions.grouping.toggle}
isGroupCollapsed={props.sessions.grouping.collapsed}
onToggleGroup={props.sessions.grouping.toggleCollapsed}
server={server()}
canCreateSession={props.sessions.session.canCreate()}
searchValue={props.search.query.value()}
Expand Down
Loading
Oops, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Loading
Oops, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.