"use client"; import { useEffect, useState } from "react"; import { Checkbox } from "@kandev/ui/checkbox"; import { Label } from "@kandev/ui/label"; import { Input } from "@kandev/ui/input"; import { Switch } from "@kandev/ui/switch"; import { Tooltip, TooltipContent, TooltipTrigger } from "@kandev/ui/tooltip"; import { IconInfoCircle } from "@tabler/icons-react"; import { RepoFilterSelector } from "@/components/github/repo-filter-selector"; import type { RepoFilter } from "@/lib/types/github"; type GitHubPRConfigProps = { config: Record; onUpdate: (config: Record) => void; }; const PR_EVENTS = [ { value: "opened", label: "Opened", tooltip: "Fires once when a new open PR is detected. Each PR number is deduped — the same PR won't trigger again.", }, ] as const; export function GitHubPRConfig({ config, onUpdate }: GitHubPRConfigProps) { const events = (config.events as string[]) ?? []; const repos = (config.repos as RepoFilter[]) ?? []; const allRepos = (config.all_repos as boolean) ?? true; const configBranches = ((config.branches as string[]) ?? []).join(", "); const configAuthors = ((config.authors as string[]) ?? []).join(", "); const [branches, setBranches] = useState(configBranches); const [authors, setAuthors] = useState(configAuthors); useEffect(() => { setBranches(configBranches); }, [configBranches]); useEffect(() => { setAuthors(configAuthors); }, [configAuthors]); const excludeDraft = (config.exclude_draft as boolean) ?? false; const toggleEvent = (event: string) => { const next = events.includes(event) ? events.filter((e) => e !== event) : [...events, event]; onUpdate({ ...config, events: next }); }; const handleBranchesBlur = () => { const parsed = branches .split(",") .map((b) => b.trim()) .filter(Boolean); onUpdate({ ...config, branches: parsed }); }; const handleAuthorsBlur = () => { const parsed = authors .split(",") .map((a) => a.trim()) .filter(Boolean); onUpdate({ ...config, authors: parsed }); }; return (
{ onUpdate({ ...config, all_repos: checked, repos: checked ? [] : repos }); }} onSelectedReposChange={(next) => onUpdate({ ...config, repos: next })} />
setBranches(e.target.value)} onBlur={handleBranchesBlur} placeholder="main, develop" />
setAuthors(e.target.value)} onBlur={handleAuthorsBlur} placeholder="alice, bob" />
onUpdate({ ...config, exclude_draft: checked })} className="cursor-pointer" />
); } function EventsSection({ events, onToggle, }: { events: string[]; onToggle: (event: string) => void; }) { return (
{PR_EVENTS.map((evt) => ( ))}
); }