Skip to content

Commit 35b2c39

Browse files
committed
fix(app): auto-enable workspaces when opening sandbox
1 parent 2b8acfa commit 35b2c39

1 file changed

Lines changed: 42 additions & 0 deletions

File tree

packages/app/src/pages/layout.tsx

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1238,7 +1238,49 @@ export default function Layout(props: ParentProps) {
12381238
navigateWithSidebarReset(`/${base64Encode(session.directory)}/session/${session.id}`)
12391239
}
12401240

1241+
function autoEnableWorkspacesIfSandbox(directory: string) {
1242+
const dir = workspaceKey(directory)
1243+
const project = layout.projects
1244+
.list()
1245+
.find(
1246+
(item) => workspaceKey(item.worktree) === dir || item.sandboxes?.some((entry) => workspaceKey(entry) === dir),
1247+
)
1248+
1249+
if (project?.vcs === "git") {
1250+
const root = workspaceKey(project.worktree)
1251+
const sandbox = project.sandboxes?.some((item) => workspaceKey(item) === dir)
1252+
if (root === dir) return
1253+
if (sandbox) {
1254+
const enabled = layout.sidebar.workspaces(project.worktree)()
1255+
if (!enabled) {
1256+
layout.sidebar.setWorkspaces(project.worktree, true)
1257+
return
1258+
}
1259+
return
1260+
}
1261+
}
1262+
1263+
if (project && project.vcs && project.vcs !== "git") return
1264+
1265+
void globalSDK
1266+
.createClient({ directory, throwOnError: true })
1267+
.project.current()
1268+
.then((x) => x.data)
1269+
.then((item) => {
1270+
if (!item) return
1271+
if (item.vcs !== "git") return
1272+
const root = workspaceKey(item.worktree)
1273+
const sandbox = item.sandboxes?.some((entry) => workspaceKey(entry) === dir)
1274+
if (root === dir) return
1275+
if (!sandbox) return
1276+
if (layout.sidebar.workspaces(item.worktree)()) return
1277+
layout.sidebar.setWorkspaces(item.worktree, true)
1278+
})
1279+
.catch(() => undefined)
1280+
}
1281+
12411282
function openProject(directory: string, navigate = true) {
1283+
autoEnableWorkspacesIfSandbox(directory)
12421284
layout.projects.open(directory)
12431285
if (navigate) navigateToProject(directory)
12441286
}

0 commit comments

Comments
 (0)