-
Notifications
You must be signed in to change notification settings - Fork 61
Expand file tree
/
Copy pathGroupWorktreesSection.tsx
More file actions
62 lines (58 loc) · 2.3 KB
/
Copy pathGroupWorktreesSection.tsx
File metadata and controls
62 lines (58 loc) · 2.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
import { GitBranch, Spinner, TreeStructure } from "@phosphor-icons/react";
import { SidebarItem } from "@posthog/ui/features/sidebar/components/SidebarItem";
import { SidebarSection } from "@posthog/ui/features/sidebar/components/SidebarSection";
import { useSidebarStore } from "@posthog/ui/features/sidebar/sidebarStore";
import { useAdoptableWorktrees } from "@posthog/ui/features/sidebar/useAdoptableWorktrees";
import { useStartTaskFromWorktree } from "@posthog/ui/features/sidebar/useStartTaskFromWorktree";
interface GroupWorktreesSectionProps {
groupId: string;
mainRepoPath: string;
}
/**
* Nested "Worktrees" dropdown at the bottom of a repo group listing the repo's
* task-less worktrees. Clicking one starts a task in that worktree and opens
* its chat + shell. Renders nothing when the repo has no adoptable worktrees.
*/
export function GroupWorktreesSection({
groupId,
mainRepoPath,
}: GroupWorktreesSectionProps) {
const worktrees = useAdoptableWorktrees(mainRepoPath);
const collapsedSections = useSidebarStore((state) => state.collapsedSections);
const toggleSection = useSidebarStore((state) => state.toggleSection);
const { startTask, startingBranches } =
useStartTaskFromWorktree(mainRepoPath);
if (worktrees.length === 0) return null;
const sectionId = `worktrees:${groupId}`;
return (
<SidebarSection
id={sectionId}
label={`Worktrees (${worktrees.length})`}
icon={<TreeStructure size={14} className="text-gray-10" />}
depth={1}
isExpanded={!collapsedSections.has(sectionId)}
onToggle={() => toggleSection(sectionId)}
tooltipContent="Worktrees without a task — click one to start a task there"
>
{worktrees.map((worktree) => {
const isStarting = startingBranches.has(worktree.branch);
return (
<SidebarItem
key={worktree.worktreePath}
depth={2}
icon={<GitBranch size={14} />}
label={worktree.branch}
isDimmed={isStarting}
disabled={isStarting}
endContent={
isStarting ? (
<Spinner size={12} className="animate-spin text-gray-10" />
) : undefined
}
onClick={() => void startTask(worktree.branch)}
/>
);
})}
</SidebarSection>
);
}