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

BranchToolbarEnvModeSelector.tsx

97 lines2.8 KB

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