"use client"; import { useState, useEffect, useCallback, useMemo } from "react"; import { Button } from "@kandev/ui/button"; import { Switch } from "@kandev/ui/switch"; import { Label } from "@kandev/ui/label"; import { Input } from "@kandev/ui/input"; import { Dialog, DialogContent, DialogHeader, DialogTitle, DialogDescription, DialogFooter, } from "@kandev/ui/dialog"; import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "@kandev/ui/select"; import { Textarea } from "@kandev/ui/textarea"; import { IconInfoCircle } from "@tabler/icons-react"; import { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger } from "@kandev/ui/tooltip"; import { useAppStore } from "@/components/state-provider"; import { useSettingsData } from "@/hooks/domains/settings/use-settings-data"; import { useWorkflows } from "@/hooks/use-workflows"; import { useWorkflowSteps, stepPlaceholder, type WorkflowStepOption, } from "@/hooks/use-workflow-steps"; import { DEFAULT_REVIEW_WATCH_PROMPT } from "@/components/github/review-watch-placeholders"; import { ReviewWatchPromptField } from "@/components/github/review-watch-prompt-field"; import { RepoFilterSelector } from "@/components/github/repo-filter-selector"; import type { RepoFilter, ReviewWatch, CreateReviewWatchRequest, UpdateReviewWatchRequest, } from "@/lib/types/github"; type ReviewWatchDialogProps = { open: boolean; onOpenChange: (open: boolean) => void; watch: ReviewWatch | null; // Pre-binds the dialog to one workspace; omit on the install-wide settings // page so the create flow shows a workspace picker. workspaceId?: string; onCreate: (req: CreateReviewWatchRequest) => Promise; onUpdate: (id: string, req: UpdateReviewWatchRequest) => Promise; }; const QUERY_TEMPLATES = { meAndTeams: "type:pr state:open review-requested:@me -is:draft", me: "type:pr state:open user-review-requested:@me -is:draft", } as const; type FormState = { workspaceId: string; selectedRepos: RepoFilter[]; allRepos: boolean; workflowId: string; workflowStepId: string; agentProfileId: string; executorProfileId: string; prompt: string; customQuery: string; enabled: boolean; pollInterval: number; }; function makeDefaultForm(workspaceId: string): FormState { return { workspaceId, selectedRepos: [], allRepos: false, workflowId: "", workflowStepId: "", agentProfileId: "", executorProfileId: "", prompt: DEFAULT_REVIEW_WATCH_PROMPT, customQuery: QUERY_TEMPLATES.meAndTeams, enabled: true, pollInterval: 300, }; } function formStateFromWatch(watch: ReviewWatch): FormState { const hasRepos = watch.repos && watch.repos.length > 0; return { workspaceId: watch.workspace_id, selectedRepos: hasRepos ? watch.repos : [], allRepos: !hasRepos, workflowId: watch.workflow_id, workflowStepId: watch.workflow_step_id, agentProfileId: watch.agent_profile_id, executorProfileId: watch.executor_profile_id, prompt: watch.prompt || DEFAULT_REVIEW_WATCH_PROMPT, customQuery: watch.custom_query || QUERY_TEMPLATES.meAndTeams, enabled: watch.enabled, pollInterval: watch.poll_interval_seconds, }; } // --- Generic select field with description --- type SelectFieldProps = { label: string; description?: string; value: string; onChange: (value: string) => void; placeholder: string; items: Array<{ id: string; label: string }>; disabled?: boolean; }; function SelectField({ label, description, value, onChange, placeholder, items, disabled, }: SelectFieldProps) { return (
{description &&

{description}

}
); } function WorkspacePicker({ value, onChange, disabled, }: { value: string; onChange: (v: string) => void; disabled?: boolean; }) { const workspaces = useAppStore((s) => s.workspaces.items); return ( ({ id: w.id, label: w.name }))} disabled={disabled} /> ); } // --- Hooks --- function useWatchFormData(workspaceId: string) { useSettingsData(true); useWorkflows(workspaceId, true); const allWorkflows = useAppStore((state) => state.workflows.items); const workflows = useMemo(() => allWorkflows.filter((w) => !w.hidden), [allWorkflows]); const agentProfiles = useAppStore((state) => state.agentProfiles.items); const executors = useAppStore((state) => state.executors.items); const allExecutorProfiles = useMemo( () => executors.filter((e) => e.type !== "local").flatMap((e) => e.profiles ?? []), [executors], ); // Filter out passthrough/TUI profiles — they don't accept initial prompts const filteredAgentProfiles = useMemo( () => agentProfiles.filter((p) => !p.cli_passthrough), [agentProfiles], ); return { workflows, agentProfiles: filteredAgentProfiles, allExecutorProfiles }; } // --- Section header --- function SectionHeader({ children }: { children: React.ReactNode }) { return (
{children}
); } // --- Form field groups --- function QueryField({ form, setForm, }: { form: FormState; setForm: React.Dispatch>; }) { const current = form.customQuery.trim(); const isMeAndTeams = current === QUERY_TEMPLATES.meAndTeams; const isMe = current === QUERY_TEMPLATES.me; return (
PRs where you or any of your teams are requested as reviewers Only PRs where you are explicitly requested as a reviewer (not via team membership)