Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 11 additions & 12 deletions packages/app/src/pages/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ import {
effectiveWorkspaceOrder,
errorMessage,
latestRootSession,
resetArchiveSessions,
sortedRootSessions,
} from "./layout/helpers"
import {
Expand Down Expand Up @@ -1580,17 +1581,15 @@ export default function Layout(props: ParentProps) {

const archivedAt = Date.now()
await Promise.all(
sessions
.filter((session) => session.time.archived === undefined)
.map((session) =>
globalSDK.client.session
.update({
sessionID: session.id,
directory: session.directory,
time: { archived: archivedAt },
})
.catch(() => undefined),
),
resetArchiveSessions(sessions, directory).map((session) =>
globalSDK.client.session
.update({
sessionID: session.id,
directory: session.directory,
time: { archived: archivedAt },
})
.catch(() => undefined),
),
)

setBusy(directory, false)
Expand Down Expand Up @@ -1687,7 +1686,7 @@ export default function Layout(props: ParentProps) {
.list({ directory: props.directory })
.then((x) => x.data ?? [])
.catch(() => [])
const active = sessions.filter((session) => session.time.archived === undefined)
const active = resetArchiveSessions(sessions, props.directory)
setState({ sessions: active })
}

Expand Down
15 changes: 15 additions & 0 deletions packages/app/src/pages/layout/helpers.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
errorMessage,
hasProjectPermissions,
latestRootSession,
resetArchiveSessions,
} from "./helpers"
import { pathKey } from "@/utils/path-key"

Expand Down Expand Up @@ -199,6 +200,20 @@ describe("layout workspace helpers", () => {
expect(result?.id).toBe("root")
})

test("archives only active sessions in the reset workspace", () => {
const result = resetArchiveSessions(
[
session({ id: "target", directory: "/repo/worktree" }),
session({ id: "target-slash", directory: "/repo/worktree/" }),
session({ id: "other", directory: "/repo/other-worktree" }),
session({ id: "archived", directory: "/repo/worktree", time: { created: 0, updated: 0, archived: 1 } }),
],
"/repo/worktree",
)

expect(result.map((item) => item.id)).toEqual(["target", "target-slash"])
})

test("finds the direct child on the active session path", () => {
const list = [
session({ id: "root", directory: "/workspace" }),
Expand Down
3 changes: 3 additions & 0 deletions packages/app/src/pages/layout/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ export const sortedRootSessions = (store: SessionStore, now: number) => roots(st
export const latestRootSession = (stores: SessionStore[], now: number) =>
stores.flatMap(roots).sort(sortSessions(now))[0]

export const resetArchiveSessions = (sessions: Session[], directory: string) =>
sessions.filter((session) => pathKey(session.directory) === pathKey(directory) && session.time.archived === undefined)

export function hasProjectPermissions<T>(
request: Record<string, T[] | undefined> | undefined,
include: (item: T) => boolean = () => true,
Expand Down
Loading