|
1 | 1 | "use client" |
2 | 2 |
|
3 | 3 | import { zodResolver } from "@hookform/resolvers/zod" |
4 | | -import { AlertCircle, ChevronLeft, Loader2, Save, Trash2 } from "lucide-react" |
| 4 | +import { |
| 5 | + AlertCircle, |
| 6 | + ChevronLeft, |
| 7 | + Loader2, |
| 8 | + Pencil, |
| 9 | + Save, |
| 10 | + Terminal, |
| 11 | + Trash2, |
| 12 | +} from "lucide-react" |
5 | 13 | import Link from "next/link" |
6 | 14 | import { useParams, useRouter } from "next/navigation" |
7 | 15 | import { useCallback, useState } from "react" |
8 | 16 | import { useForm } from "react-hook-form" |
9 | 17 | import { z } from "zod" |
10 | 18 | import type { MCPIntegrationRead } from "@/client" |
11 | 19 | import { ProviderIcon } from "@/components/icons" |
| 20 | +import { MCPIntegrationDialog } from "@/components/integrations/mcp-integration-dialog" |
12 | 21 | import { CenteredSpinner } from "@/components/loading/spinner" |
13 | 22 | import { |
14 | 23 | AlertDialog, |
@@ -167,6 +176,212 @@ function McpIntegrationDetailContent({ |
167 | 176 | mcpIntegration: MCPIntegrationRead |
168 | 177 | }) { |
169 | 178 | const workspaceId = useWorkspaceId() |
| 179 | + |
| 180 | + // Command-type integrations use the dialog for editing |
| 181 | + if (mcpIntegration.server_type === "command") { |
| 182 | + return ( |
| 183 | + <CommandTypeIntegrationView |
| 184 | + mcpIntegration={mcpIntegration} |
| 185 | + workspaceId={workspaceId} |
| 186 | + /> |
| 187 | + ) |
| 188 | + } |
| 189 | + |
| 190 | + // URL-type integrations use the inline form |
| 191 | + return ( |
| 192 | + <UrlTypeIntegrationForm |
| 193 | + mcpIntegration={mcpIntegration} |
| 194 | + workspaceId={workspaceId} |
| 195 | + /> |
| 196 | + ) |
| 197 | +} |
| 198 | + |
| 199 | +function CommandTypeIntegrationView({ |
| 200 | + mcpIntegration, |
| 201 | + workspaceId, |
| 202 | +}: { |
| 203 | + mcpIntegration: MCPIntegrationRead |
| 204 | + workspaceId: string |
| 205 | +}) { |
| 206 | + const router = useRouter() |
| 207 | + const { deleteMcpIntegration, deleteMcpIntegrationIsPending } = |
| 208 | + useDeleteMcpIntegration(workspaceId) |
| 209 | + const [deleteDialogOpen, setDeleteDialogOpen] = useState(false) |
| 210 | + const [deleteConfirmText, setDeleteConfirmText] = useState("") |
| 211 | + const [editDialogOpen, setEditDialogOpen] = useState(false) |
| 212 | + |
| 213 | + const handleDelete = useCallback(async () => { |
| 214 | + if (deleteConfirmText !== mcpIntegration.name) return |
| 215 | + try { |
| 216 | + await deleteMcpIntegration(mcpIntegration.id) |
| 217 | + router.push(`/workspaces/${workspaceId}/integrations`) |
| 218 | + } catch (error) { |
| 219 | + console.error("Failed to delete MCP integration:", error) |
| 220 | + } |
| 221 | + }, [ |
| 222 | + deleteConfirmText, |
| 223 | + mcpIntegration, |
| 224 | + deleteMcpIntegration, |
| 225 | + router, |
| 226 | + workspaceId, |
| 227 | + ]) |
| 228 | + |
| 229 | + const handleDeleteDialogOpenChange = (open: boolean) => { |
| 230 | + setDeleteDialogOpen(open) |
| 231 | + if (!open) { |
| 232 | + setDeleteConfirmText("") |
| 233 | + } |
| 234 | + } |
| 235 | + |
| 236 | + return ( |
| 237 | + <div className="container mx-auto max-w-4xl p-6 mb-20 mt-12"> |
| 238 | + {/* Header */} |
| 239 | + <div className="mb-8"> |
| 240 | + <Link |
| 241 | + href={`/workspaces/${workspaceId}/integrations`} |
| 242 | + className="inline-flex items-center text-sm text-muted-foreground hover:text-foreground mb-4" |
| 243 | + > |
| 244 | + <ChevronLeft className="mr-1 size-4" /> |
| 245 | + Back to integrations |
| 246 | + </Link> |
| 247 | + <div className="flex items-start justify-between"> |
| 248 | + <div className="flex items-start gap-4"> |
| 249 | + <div className="flex size-12 items-center justify-center rounded-lg border bg-muted"> |
| 250 | + <Terminal className="size-6 text-muted-foreground" /> |
| 251 | + </div> |
| 252 | + <div> |
| 253 | + <h1 className="text-3xl font-bold">{mcpIntegration.name}</h1> |
| 254 | + {mcpIntegration.description && ( |
| 255 | + <p className="mt-1 text-muted-foreground"> |
| 256 | + {mcpIntegration.description} |
| 257 | + </p> |
| 258 | + )} |
| 259 | + <div className="mt-2 flex gap-2"> |
| 260 | + <Badge variant="outline">Command</Badge> |
| 261 | + </div> |
| 262 | + </div> |
| 263 | + </div> |
| 264 | + </div> |
| 265 | + </div> |
| 266 | + |
| 267 | + {/* Configuration Card */} |
| 268 | + <Card> |
| 269 | + <CardContent className="pt-6 space-y-4"> |
| 270 | + <div> |
| 271 | + <Label className="text-muted-foreground text-xs">Command</Label> |
| 272 | + <p className="font-mono text-sm mt-1"> |
| 273 | + {mcpIntegration.command || "-"} |
| 274 | + </p> |
| 275 | + </div> |
| 276 | + {mcpIntegration.command_args && |
| 277 | + mcpIntegration.command_args.length > 0 && ( |
| 278 | + <div> |
| 279 | + <Label className="text-muted-foreground text-xs"> |
| 280 | + Arguments |
| 281 | + </Label> |
| 282 | + <p className="font-mono text-sm mt-1"> |
| 283 | + {mcpIntegration.command_args.join(" ")} |
| 284 | + </p> |
| 285 | + </div> |
| 286 | + )} |
| 287 | + {mcpIntegration.has_command_env && ( |
| 288 | + <div> |
| 289 | + <Label className="text-muted-foreground text-xs"> |
| 290 | + Environment |
| 291 | + </Label> |
| 292 | + <p className="text-sm text-muted-foreground mt-1"> |
| 293 | + Environment variables configured (hidden for security) |
| 294 | + </p> |
| 295 | + </div> |
| 296 | + )} |
| 297 | + {mcpIntegration.timeout && ( |
| 298 | + <div> |
| 299 | + <Label className="text-muted-foreground text-xs">Timeout</Label> |
| 300 | + <p className="text-sm mt-1">{mcpIntegration.timeout} seconds</p> |
| 301 | + </div> |
| 302 | + )} |
| 303 | + |
| 304 | + <div className="flex gap-2 pt-4 border-t"> |
| 305 | + <Button variant="outline" onClick={() => setEditDialogOpen(true)}> |
| 306 | + <Pencil className="mr-2 size-4" /> |
| 307 | + Edit |
| 308 | + </Button> |
| 309 | + <MCPIntegrationDialog |
| 310 | + mcpIntegrationId={mcpIntegration.id} |
| 311 | + open={editDialogOpen} |
| 312 | + onOpenChange={setEditDialogOpen} |
| 313 | + hideTrigger |
| 314 | + /> |
| 315 | + <Button |
| 316 | + variant="destructive" |
| 317 | + onClick={() => setDeleteDialogOpen(true)} |
| 318 | + disabled={deleteMcpIntegrationIsPending} |
| 319 | + > |
| 320 | + <Trash2 className="mr-2 size-4" /> |
| 321 | + Delete |
| 322 | + </Button> |
| 323 | + </div> |
| 324 | + </CardContent> |
| 325 | + </Card> |
| 326 | + |
| 327 | + {/* Delete Dialog */} |
| 328 | + <AlertDialog |
| 329 | + open={deleteDialogOpen} |
| 330 | + onOpenChange={handleDeleteDialogOpenChange} |
| 331 | + > |
| 332 | + <AlertDialogContent> |
| 333 | + <AlertDialogHeader> |
| 334 | + <AlertDialogTitle>Delete MCP integration?</AlertDialogTitle> |
| 335 | + <AlertDialogDescription> |
| 336 | + This will permanently delete the MCP integration " |
| 337 | + {mcpIntegration.name}". This action cannot be undone. |
| 338 | + </AlertDialogDescription> |
| 339 | + </AlertDialogHeader> |
| 340 | + <div className="py-4"> |
| 341 | + <Label htmlFor="confirm-delete" className="text-sm"> |
| 342 | + Type <strong>{mcpIntegration.name}</strong> to confirm |
| 343 | + </Label> |
| 344 | + <Input |
| 345 | + id="confirm-delete" |
| 346 | + value={deleteConfirmText} |
| 347 | + onChange={(e) => setDeleteConfirmText(e.target.value)} |
| 348 | + className="mt-2" |
| 349 | + placeholder={mcpIntegration.name} |
| 350 | + /> |
| 351 | + </div> |
| 352 | + <AlertDialogFooter> |
| 353 | + <AlertDialogCancel>Cancel</AlertDialogCancel> |
| 354 | + <AlertDialogAction |
| 355 | + onClick={handleDelete} |
| 356 | + disabled={ |
| 357 | + deleteConfirmText !== mcpIntegration.name || |
| 358 | + deleteMcpIntegrationIsPending |
| 359 | + } |
| 360 | + className="bg-destructive text-destructive-foreground hover:bg-destructive/90" |
| 361 | + > |
| 362 | + {deleteMcpIntegrationIsPending ? ( |
| 363 | + <> |
| 364 | + <Loader2 className="mr-2 size-4 animate-spin" /> |
| 365 | + Deleting... |
| 366 | + </> |
| 367 | + ) : ( |
| 368 | + "Delete integration" |
| 369 | + )} |
| 370 | + </AlertDialogAction> |
| 371 | + </AlertDialogFooter> |
| 372 | + </AlertDialogContent> |
| 373 | + </AlertDialog> |
| 374 | + </div> |
| 375 | + ) |
| 376 | +} |
| 377 | + |
| 378 | +function UrlTypeIntegrationForm({ |
| 379 | + mcpIntegration, |
| 380 | + workspaceId, |
| 381 | +}: { |
| 382 | + mcpIntegration: MCPIntegrationRead |
| 383 | + workspaceId: string |
| 384 | +}) { |
170 | 385 | const router = useRouter() |
171 | 386 | const { updateMcpIntegration, updateMcpIntegrationIsPending } = |
172 | 387 | useUpdateMcpIntegration(workspaceId) |
|
0 commit comments