-
Notifications
You must be signed in to change notification settings - Fork 66
Expand file tree
/
Copy pathSelectRepoStep.tsx
More file actions
259 lines (251 loc) · 9.98 KB
/
Copy pathSelectRepoStep.tsx
File metadata and controls
259 lines (251 loc) · 9.98 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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
import {
ArrowLeft,
ArrowRight,
CheckCircle,
CircleNotch,
FolderOpen,
Lightbulb,
} from "@phosphor-icons/react";
import { repoMatchesGitHubRepos } from "@posthog/core/onboarding/repoProvider";
import { cn } from "@posthog/quill";
import { useHostCapabilities } from "@posthog/ui/shell/useHostCapabilities";
import { Box, Button, Flex, Text } from "@radix-ui/themes";
import { AnimatePresence, motion } from "framer-motion";
import { useMemo } from "react";
import { builderHog } from "../../../assets/hedgehogs";
import { OnboardingHogTip } from "../../../primitives/OnboardingHogTip";
import { FolderPicker } from "../../folder-picker/FolderPicker";
import { GitHubRepoPicker } from "../../folder-picker/GitHubRepoPicker";
import { useUserRepositoryIntegration } from "../../integrations/useIntegrations";
import type { DetectedRepo } from "../types";
import { OptionalBadge } from "./OptionalBadge";
import { PANEL_SHADOW } from "./onboardingStyles";
import { StepActions } from "./StepActions";
interface SelectRepoStepProps {
onComplete: (skipped: boolean) => void;
onBack: () => void;
selectedDirectory: string;
detectedRepo: DetectedRepo | null;
isDetectingRepo: boolean;
onDirectoryChange: (path: string) => void;
}
export function SelectRepoStep({
onComplete,
onBack,
selectedDirectory,
detectedRepo,
isDetectingRepo,
onDirectoryChange,
}: SelectRepoStepProps) {
const { localWorkspaces } = useHostCapabilities();
const {
repositories,
isLoadingRepos,
isRefreshingRepos,
refreshRepositories,
} = useUserRepositoryIntegration();
const repoMatchesGitHub = useMemo(
() => repoMatchesGitHubRepos(detectedRepo, repositories),
[detectedRepo, repositories],
);
return (
<Flex align="center" height="100%" px="8">
<Flex
direction="column"
align="center"
className="h-full w-full pt-[24px] pb-[40px]"
>
<Flex direction="column" className="min-h-0 flex-1 overflow-y-auto">
<Flex
direction="column"
gap="5"
className="m-auto w-full max-w-[560px]"
>
<Flex direction="column" gap="5" className="w-full">
<motion.div
initial={{ opacity: 0, y: 8 }}
animate={{ opacity: 1, y: 0 }}
transition={{ duration: 0.3 }}
>
<Flex direction="column" gap="2">
<Flex align="center" gap="2">
<Text className="font-bold text-(--gray-12) text-2xl">
Pick a repo to get started
</Text>
<OptionalBadge />
</Flex>
<Text className="text-(--gray-11) text-sm">
We'll scan it and suggest some first things to work on. You
can also skip this and start from a blank task.
</Text>
</Flex>
</motion.div>
<motion.div
initial={{ opacity: 0, y: 8 }}
animate={{ opacity: 1, y: 0 }}
transition={{ duration: 0.3, delay: 0.05 }}
>
<Box
p="5"
style={{ boxShadow: PANEL_SHADOW }}
className="rounded-[12px] border border-(--gray-a3) bg-(--color-panel-solid)"
>
<Flex direction="column" gap="4">
<Flex direction="column" gap="1">
<Flex align="center" gap="2">
<FolderOpen size={18} className="text-(--gray-12)" />
<Text className="font-bold text-(--gray-12) text-base">
Choose your repository
</Text>
</Flex>
<Text className="text-(--gray-11) text-sm">
{localWorkspaces
? "Select a single repository folder, not a parent folder that contains multiple repos."
: "Pick a repository from your connected GitHub organizations."}
</Text>
</Flex>
{localWorkspaces ? (
<FolderPicker
variant="field"
value={selectedDirectory}
onChange={onDirectoryChange}
placeholder="Select repository..."
/>
) : (
<GitHubRepoPicker
value={selectedDirectory || null}
onChange={(repo) => onDirectoryChange(repo ?? "")}
repositories={repositories}
isLoading={isLoadingRepos}
onRefresh={refreshRepositories}
isRefreshing={isRefreshingRepos}
placeholder="Select repository..."
/>
)}
<AnimatePresence mode="wait">
{localWorkspaces && isDetectingRepo && (
<motion.div
key="detecting"
initial={{ opacity: 0 }}
animate={{ opacity: 1 }}
exit={{ opacity: 0 }}
transition={{ duration: 0.15 }}
>
<Flex align="center" gap="2">
<CircleNotch
size={14}
className="animate-spin text-(--gray-9)"
/>
<Text className="text-(--gray-9) text-[13px]">
Detecting repository...
</Text>
</Flex>
</motion.div>
)}
{localWorkspaces &&
!isDetectingRepo &&
selectedDirectory &&
detectedRepo && (
<motion.div
key="detected"
initial={{ opacity: 0, y: 4 }}
animate={{ opacity: 1, y: 0 }}
exit={{ opacity: 0 }}
transition={{ duration: 0.2 }}
>
<Flex align="center" gap="2">
<CheckCircle
size={14}
weight="fill"
className={
repoMatchesGitHub
? "text-(--green-9)"
: "text-(--gray-9)"
}
/>
<Text
className={cn(
"text-[13px]",
repoMatchesGitHub
? "text-(--green-11)"
: "text-(--gray-11)",
)}
>
{repoMatchesGitHub
? `Linked to ${detectedRepo.fullName} on GitHub`
: `Detected ${detectedRepo.fullName}`}
</Text>
</Flex>
</motion.div>
)}
{localWorkspaces &&
!isDetectingRepo &&
selectedDirectory &&
!detectedRepo && (
<motion.div
key="no-repo"
initial={{ opacity: 0, y: 4 }}
animate={{ opacity: 1, y: 0 }}
exit={{ opacity: 0 }}
transition={{ duration: 0.2 }}
>
<Text className="text-(--gray-9) text-[13px]">
No git remote detected. You can still continue.
</Text>
</motion.div>
)}
</AnimatePresence>
</Flex>
</Box>
</motion.div>
<motion.div
initial={{ opacity: 0, y: 8 }}
animate={{ opacity: 1, y: 0 }}
transition={{ duration: 0.3, delay: 0.08 }}
>
<Flex align="start" gap="2">
<Lightbulb
size={16}
className="mt-[2px] shrink-0 text-(--gray-10)"
/>
<Text className="text-(--gray-10) text-[13px]">
Once you pick a repo we'll look for things like stale
feature flags, missing tracking, and other low-effort wins
to start from.
</Text>
</Flex>
</motion.div>
</Flex>
<OnboardingHogTip
hogSrc={builderHog}
message="No repo? No problem. You can always add one later from the home screen."
delay={0.15}
/>
</Flex>
</Flex>
<StepActions>
<Button size="3" variant="outline" color="gray" onClick={onBack}>
<ArrowLeft size={16} weight="bold" />
Back
</Button>
{selectedDirectory ? (
<Button size="3" onClick={() => onComplete(false)}>
Get started
<ArrowRight size={16} weight="bold" />
</Button>
) : (
<Button
size="3"
variant="outline"
color="gray"
onClick={() => onComplete(true)}
>
Skip & get started
<ArrowRight size={16} weight="bold" />
</Button>
)}
</StepActions>
</Flex>
</Flex>
);
}