"use client"; import { useState, useCallback } from "react"; import { useRouter } from "next/navigation"; import { IconTrash, IconPlus, IconChevronRight } from "@tabler/icons-react"; import { Badge } from "@kandev/ui/badge"; import { Button } from "@kandev/ui/button"; import { Card, CardContent, CardHeader, CardTitle, CardDescription } from "@kandev/ui/card"; import { deleteExecutorProfile, listExecutorProfiles } from "@/lib/api/domains/settings-api"; import { ExecutorProfileDialog } from "@/components/settings/executor-profile-dialog"; import { useAppStore } from "@/components/state-provider"; import type { ExecutorProfile } from "@/lib/types/http"; type ExecutorProfilesCardProps = { executorId: string; profiles: ExecutorProfile[]; }; export function ExecutorProfilesCard({ executorId, profiles }: ExecutorProfilesCardProps) { const router = useRouter(); const [dialogOpen, setDialogOpen] = useState(false); const executors = useAppStore((state) => state.executors.items); const setExecutors = useAppStore((state) => state.setExecutors); const refreshProfiles = useCallback(async () => { try { const resp = await listExecutorProfiles(executorId, { cache: "no-store" }); setExecutors( executors.map((e) => (e.id === executorId ? { ...e, profiles: resp.profiles } : e)), ); } catch { // ignore refresh failure } }, [executorId, executors, setExecutors]); const handleCreate = useCallback(() => { setDialogOpen(true); }, []); const handleProfileCreated = useCallback( (profile: ExecutorProfile) => { refreshProfiles(); router.push(`/settings/executor/${executorId}/profile/${profile.id}`); }, [executorId, refreshProfiles, router], ); const handleDelete = useCallback( async (e: React.MouseEvent, profileId: string) => { e.stopPropagation(); try { await deleteExecutorProfile(executorId, profileId); await refreshProfiles(); } catch { // ignore delete failure } }, [executorId, refreshProfiles], ); return ( <>
Profiles Different configurations for this executor. Each profile can have its own prepare script, environment variables, and settings.
{profiles.length === 0 ? (

No profiles configured.

) : (
{profiles.map((profile) => (
router.push(`/settings/executor/${executorId}/profile/${profile.id}`) } >
{profile.name} {profile.prepare_script && ( Prepare script )}
))}
)}
); }