Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

BranchToolbarEnvModeSelector.tsx

98 lines2.8 KB

1import { FolderGit2Icon, FolderGitIcon, FolderIcon } from "lucide-react";
2import { memo, useMemo } from "react";
3​
4import {
5 resolveCurrentWorkspaceLabel,
6 resolveEnvModeLabel,
7 resolveLockedWorkspaceLabel,
8 type EnvMode,
9} from "./BranchToolbar.logic";
10import {
11 Select,
12 SelectGroup,
13 SelectGroupLabel,
14 SelectItem,
15 SelectPopup,
16 SelectTrigger,
17 SelectValue,
18} from "./ui/select";
19​
20interface BranchToolbarEnvModeSelectorProps {
21 envLocked: boolean;
22 effectiveEnvMode: EnvMode;
23 activeWorktreePath: string | null;
24 onEnvModeChange: (mode: EnvMode) => void;
26​
27export const BranchToolbarEnvModeSelector = memo(function BranchToolbarEnvModeSelector({
28 envLocked,
29 effectiveEnvMode,
30 activeWorktreePath,
31 onEnvModeChange,
32}: BranchToolbarEnvModeSelectorProps) {
33 const envModeItems = useMemo(
34 () => [
35 { value: "local", label: resolveCurrentWorkspaceLabel(activeWorktreePath) },
36 { value: "worktree", label: resolveEnvModeLabel("worktree") },
37 ],
38 [activeWorktreePath],
39 );
40​
41 if (envLocked) {
42 return (
43 <span className="inline-flex items-center gap-1 border border-transparent px-[calc(--spacing(3)-1px)] text-sm font-medium text-muted-foreground/70 sm:text-xs">
44 {activeWorktreePath ? (
45 <>
46 <FolderGitIcon className="size-3" />
47 {resolveLockedWorkspaceLabel(activeWorktreePath)}
48 </>
49 ) : (
50 <>
51 <FolderIcon className="size-3" />
52 {resolveLockedWorkspaceLabel(activeWorktreePath)}
53 </>
54 )}
55 </span>
56 );
57 }
58​
59 return (
60 <Select
61 value={effectiveEnvMode}
62 onValueChange={(value) => onEnvModeChange(value as EnvMode)}
63 items={envModeItems}
64 >
65 <SelectTrigger variant="ghost" size="xs" className="font-medium" aria-label="Workspace">
66 {effectiveEnvMode === "worktree" ? (
67 <FolderGit2Icon className="size-3" />
68 ) : activeWorktreePath ? (
69 <FolderGitIcon className="size-3" />
70 ) : (
71 <FolderIcon className="size-3" />
72 )}
73 <SelectValue />
74 </SelectTrigger>
75 <SelectPopup>
76 <SelectGroup>
77 <SelectGroupLabel>Workspace</SelectGroupLabel>
78 <SelectItem value="local">
79 <span className="inline-flex items-center gap-1.5">
80 {activeWorktreePath ? (
81 <FolderGitIcon className="size-3" />
82 ) : (
83 <FolderIcon className="size-3" />
84 )}
85 {resolveCurrentWorkspaceLabel(activeWorktreePath)}
86 </span>
87 </SelectItem>
88 <SelectItem value="worktree">
89 <span className="inline-flex items-center gap-1.5">
90 <FolderGit2Icon className="size-3" />
91 {resolveEnvModeLabel("worktree")}
92 </span>
93 </SelectItem>
94 </SelectGroup>
95 </SelectPopup>
96 </Select>
97 );
98});