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
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
|
import { useState, useEffect } from "react";
import type {
ContractRepository,
RepositorySourceType,
RepositoryStatus,
DaemonDirectory,
RepositoryHistoryEntry,
} from "../../lib/api";
import { getDaemonDirectories, getRepositorySuggestions } from "../../lib/api";
import { DirectoryInput } from "../mesh/DirectoryInput";
interface RepositoryPanelProps {
repositories: ContractRepository[];
onAddRemote: (name: string, url: string, isPrimary: boolean) => void;
onAddLocal: (name: string, path: string, isPrimary: boolean) => void;
onCreateManaged: (name: string, isPrimary: boolean) => void;
onDelete: (repoId: string) => void;
onSetPrimary: (repoId: string) => void;
}
type AddMode = "remote" | "local" | "managed" | null;
const sourceTypeLabels: Record<RepositorySourceType, string> = {
remote: "Remote",
local: "Local",
managed: "Managed",
};
const sourceTypeIcons: Record<RepositorySourceType, string> = {
remote: "GH",
local: "FS",
managed: "MK",
};
const statusColors: Record<RepositoryStatus, string> = {
ready: "text-green-400",
pending: "text-yellow-400",
creating: "text-cyan-400",
failed: "text-red-400",
};
export function RepositoryPanel({
repositories,
onAddRemote,
onAddLocal,
onCreateManaged,
onDelete,
onSetPrimary,
}: RepositoryPanelProps) {
const [addMode, setAddMode] = useState<AddMode>(null);
const [name, setName] = useState("");
const [url, setUrl] = useState("");
const [path, setPath] = useState("");
const [isPrimary, setIsPrimary] = useState(false);
// Daemon directory suggestions for local repositories
const [suggestedDirectories, setSuggestedDirectories] = useState<DaemonDirectory[]>([]);
// Repository history suggestions
const [repoSuggestions, setRepoSuggestions] = useState<RepositoryHistoryEntry[]>([]);
const [showSuggestions, setShowSuggestions] = useState(false);
// Fetch daemon directories when "local" mode is selected
useEffect(() => {
if (addMode === "local") {
getDaemonDirectories()
.then((res) => setSuggestedDirectories(res.directories))
.catch(() => setSuggestedDirectories([]));
}
}, [addMode]);
// Fetch repository suggestions when mode changes to remote or local
useEffect(() => {
if (addMode === "remote" || addMode === "local") {
getRepositorySuggestions(addMode, undefined, 10)
.then((res) => {
setRepoSuggestions(res.entries);
setShowSuggestions(res.entries.length > 0);
})
.catch(() => {
setRepoSuggestions([]);
setShowSuggestions(false);
});
} else {
setRepoSuggestions([]);
setShowSuggestions(false);
}
}, [addMode]);
// Apply a suggestion to the form
const applySuggestion = (suggestion: RepositoryHistoryEntry) => {
setName(suggestion.name);
if (suggestion.repositoryUrl) {
setUrl(suggestion.repositoryUrl);
}
if (suggestion.localPath) {
setPath(suggestion.localPath);
}
setShowSuggestions(false);
};
const handleAdd = () => {
if (!name.trim()) return;
if (addMode === "remote" && url.trim()) {
onAddRemote(name.trim(), url.trim(), isPrimary);
} else if (addMode === "local" && path.trim()) {
onAddLocal(name.trim(), path.trim(), isPrimary);
} else if (addMode === "managed") {
onCreateManaged(name.trim(), isPrimary);
}
// Reset form
setAddMode(null);
setName("");
setUrl("");
setPath("");
setIsPrimary(false);
};
const handleCancel = () => {
setAddMode(null);
setName("");
setUrl("");
setPath("");
setIsPrimary(false);
};
return (
<div className="space-y-4">
{/* Repository list */}
{repositories.length === 0 ? (
<p className="font-mono text-xs text-[#555]">
No repositories configured
</p>
) : (
<div className="space-y-2">
{repositories.map((repo) => (
<div
key={repo.id}
className="flex items-center gap-3 p-3 border border-[rgba(117,170,252,0.2)]"
>
{/* Type icon */}
<span className="font-mono text-[10px] text-[#555] uppercase w-6">
{sourceTypeIcons[repo.sourceType]}
</span>
{/* Name and details */}
<div className="flex-1 min-w-0">
<div className="flex items-center gap-2">
<span className="font-mono text-sm text-[#dbe7ff] truncate">
{repo.name}
</span>
{repo.isPrimary && (
<span className="px-1 py-0.5 text-[8px] font-mono uppercase bg-[rgba(117,170,252,0.1)] text-[#75aafc] border border-[rgba(117,170,252,0.3)]">
Primary
</span>
)}
</div>
<div className="font-mono text-[10px] text-[#555] truncate">
{repo.repositoryUrl || repo.localPath || "(pending creation)"}
</div>
</div>
{/* Status */}
<span
className={`font-mono text-[10px] uppercase ${
statusColors[repo.status]
}`}
>
{repo.status}
</span>
{/* Actions */}
<div className="flex items-center gap-1">
{!repo.isPrimary && repo.status === "ready" && (
<button
onClick={() => onSetPrimary(repo.id)}
className="p-1 font-mono text-[10px] text-[#555] hover:text-[#75aafc] transition-colors"
title="Set as primary"
>
*
</button>
)}
<button
onClick={() => onDelete(repo.id)}
className="p-1 font-mono text-[10px] text-[#555] hover:text-red-400 transition-colors"
title="Remove"
>
x
</button>
</div>
</div>
))}
</div>
)}
{/* Add repository form */}
{addMode ? (
<div className="p-3 border border-[rgba(117,170,252,0.3)] space-y-3">
<div className="flex items-center justify-between mb-2">
<span className="font-mono text-xs text-[#75aafc] uppercase">
Add {sourceTypeLabels[addMode]} Repository
</span>
{repoSuggestions.length > 0 && (
<button
onClick={() => setShowSuggestions(!showSuggestions)}
className="font-mono text-[10px] text-[#555] hover:text-[#9bc3ff] transition-colors"
>
{showSuggestions ? "Hide suggestions" : `${repoSuggestions.length} suggestions`}
</button>
)}
</div>
{/* Suggestions dropdown */}
{showSuggestions && repoSuggestions.length > 0 && (
<div className="border border-[rgba(117,170,252,0.2)] bg-[#0a1525] max-h-32 overflow-y-auto">
{repoSuggestions.map((suggestion) => (
<button
key={suggestion.id}
onClick={() => applySuggestion(suggestion)}
className="w-full text-left px-3 py-2 font-mono text-xs hover:bg-[rgba(117,170,252,0.1)] transition-colors border-b border-[rgba(117,170,252,0.1)] last:border-b-0"
>
<div className="flex items-center justify-between">
<span className="text-[#9bc3ff] truncate">{suggestion.name}</span>
<span className="text-[10px] text-[#556677]">
{suggestion.useCount}×
</span>
</div>
<div className="text-[10px] text-[#556677] truncate">
{addMode === "local" ? suggestion.localPath : suggestion.repositoryUrl}
</div>
</button>
))}
</div>
)}
<input
type="text"
value={name}
onChange={(e) => setName(e.target.value)}
placeholder="Repository name"
className="w-full px-3 py-2 bg-[#0d1b2d] border border-[#3f6fb3] text-[#dbe7ff] font-mono text-xs focus:outline-none focus:border-[#75aafc]"
/>
{addMode === "remote" && (
<input
type="text"
value={url}
onChange={(e) => setUrl(e.target.value)}
placeholder="https://github.com/owner/repo"
className="w-full px-3 py-2 bg-[#0d1b2d] border border-[#3f6fb3] text-[#dbe7ff] font-mono text-xs focus:outline-none focus:border-[#75aafc]"
/>
)}
{addMode === "local" && (
<DirectoryInput
value={path}
onChange={setPath}
suggestions={suggestedDirectories}
placeholder="/path/to/repository"
/>
)}
{addMode === "managed" && (
<p className="font-mono text-xs text-[#555]">
Makima will create this repository via the daemon.
</p>
)}
<label className="flex items-center gap-2 cursor-pointer">
<input
type="checkbox"
checked={isPrimary}
onChange={(e) => setIsPrimary(e.target.checked)}
className="w-3 h-3"
/>
<span className="font-mono text-xs text-[#9bc3ff]">
Set as primary repository
</span>
</label>
<div className="flex gap-2">
<button
onClick={handleCancel}
className="px-3 py-1.5 font-mono text-xs text-[#555] hover:text-[#9bc3ff] transition-colors"
>
Cancel
</button>
<button
onClick={handleAdd}
disabled={
!name.trim() ||
(addMode === "remote" && !url.trim()) ||
(addMode === "local" && !path.trim())
}
className="px-3 py-1.5 font-mono text-xs text-[#dbe7ff] bg-[#0f3c78] border border-[#3f6fb3] hover:bg-[#153667] transition-colors disabled:opacity-50 disabled:cursor-not-allowed"
>
Add Repository
</button>
</div>
</div>
) : (
<div className="flex gap-2">
<button
onClick={() => setAddMode("remote")}
className="px-3 py-1.5 font-mono text-xs text-[#9bc3ff] border border-[rgba(117,170,252,0.25)] hover:border-[#3f6fb3] transition-colors"
>
+ Remote
</button>
<button
onClick={() => setAddMode("local")}
className="px-3 py-1.5 font-mono text-xs text-[#9bc3ff] border border-[rgba(117,170,252,0.25)] hover:border-[#3f6fb3] transition-colors"
>
+ Local
</button>
<button
onClick={() => setAddMode("managed")}
className="px-3 py-1.5 font-mono text-xs text-[#9bc3ff] border border-[rgba(117,170,252,0.25)] hover:border-[#3f6fb3] transition-colors"
>
+ Managed
</button>
</div>
)}
</div>
);
}
|