|
| 1 | +import type { |
| 2 | + NativeApi, |
| 3 | + PrConflictAnalysis, |
| 4 | + PrReviewConfig, |
| 5 | + PrReviewThread, |
| 6 | +} from "@okcode/contracts"; |
| 7 | +import { useState } from "react"; |
| 8 | +import { MessageSquareIcon, ShieldCheckIcon, SparklesIcon, UsersIcon } from "lucide-react"; |
| 9 | +import { cn } from "~/lib/utils"; |
| 10 | +import { Button } from "~/components/ui/button"; |
| 11 | +import { ScrollArea } from "~/components/ui/scroll-area"; |
| 12 | +import { Toggle, ToggleGroup } from "~/components/ui/toggle-group"; |
| 13 | +import { SectionHeading } from "~/components/review/ReviewChrome"; |
| 14 | +import { projectLabel } from "~/components/review/reviewUtils"; |
| 15 | +import type { Project } from "~/types"; |
| 16 | +import type { InspectorTab } from "./pr-review-utils"; |
| 17 | +import { PrThreadCard } from "./PrThreadCard"; |
| 18 | +import { PrWorkflowPanel } from "./PrWorkflowPanel"; |
| 19 | +import { PrUserHoverCard } from "./PrUserHoverCard"; |
| 20 | + |
| 21 | +export function PrConversationInspector({ |
| 22 | + project, |
| 23 | + dashboard, |
| 24 | + config, |
| 25 | + conflicts, |
| 26 | + workflowId, |
| 27 | + onWorkflowIdChange, |
| 28 | + selectedFilePath, |
| 29 | + selectedThreadId, |
| 30 | + onSelectFilePath, |
| 31 | + onSelectThreadId, |
| 32 | + onResolveThread, |
| 33 | + onReplyToThread, |
| 34 | + onRunStep, |
| 35 | + onOpenRules, |
| 36 | + onOpenWorkflow, |
| 37 | + onOpenConflictDrawer, |
| 38 | +}: { |
| 39 | + project: Project; |
| 40 | + dashboard: Awaited<ReturnType<NativeApi["prReview"]["getDashboard"]>> | null | undefined; |
| 41 | + config: PrReviewConfig | undefined; |
| 42 | + conflicts: PrConflictAnalysis | undefined; |
| 43 | + workflowId: string | null; |
| 44 | + onWorkflowIdChange: (workflowId: string) => void; |
| 45 | + selectedFilePath: string | null; |
| 46 | + selectedThreadId: string | null; |
| 47 | + onSelectFilePath: (path: string | null) => void; |
| 48 | + onSelectThreadId: (threadId: string | null) => void; |
| 49 | + onResolveThread: (threadId: string, nextAction: "resolve" | "unresolve") => Promise<void>; |
| 50 | + onReplyToThread: (threadId: string, body: string) => Promise<void>; |
| 51 | + onRunStep: (stepId: string, requiresConfirmation: boolean, title: string) => Promise<void>; |
| 52 | + onOpenRules: () => void; |
| 53 | + onOpenWorkflow: (relativePath: string) => void; |
| 54 | + onOpenConflictDrawer: () => void; |
| 55 | +}) { |
| 56 | + const [tab, setTab] = useState<InspectorTab>("threads"); |
| 57 | + |
| 58 | + if (!dashboard) { |
| 59 | + return ( |
| 60 | + <div className="flex h-full items-center justify-center px-5 text-center text-sm text-muted-foreground"> |
| 61 | + Select a pull request to inspect conversations, repo rules, and workflow state. |
| 62 | + </div> |
| 63 | + ); |
| 64 | + } |
| 65 | + |
| 66 | + const visibleThreads = selectedFilePath |
| 67 | + ? dashboard.threads.filter((thread) => thread.path === selectedFilePath) |
| 68 | + : dashboard.threads; |
| 69 | + |
| 70 | + return ( |
| 71 | + <div className="flex min-h-0 min-w-0 flex-col bg-background/96"> |
| 72 | + <div className="border-b border-border/70 px-4 py-4"> |
| 73 | + <SectionHeading |
| 74 | + action={ |
| 75 | + <Button onClick={onOpenConflictDrawer} size="xs" variant="outline"> |
| 76 | + <ShieldCheckIcon className="size-3.5" /> |
| 77 | + Conflicts |
| 78 | + </Button> |
| 79 | + } |
| 80 | + detail={`Repo focus: ${projectLabel(project)}. ${selectedFilePath ? `Filtered to ${selectedFilePath}.` : "Showing all files."}`} |
| 81 | + eyebrow="Inspector" |
| 82 | + title="Conversations and rules" |
| 83 | + /> |
| 84 | + <ToggleGroup |
| 85 | + className="mt-4" |
| 86 | + size="xs" |
| 87 | + value={[tab]} |
| 88 | + variant="outline" |
| 89 | + onValueChange={(values) => { |
| 90 | + const nextValue = values[values.length - 1]; |
| 91 | + if (nextValue === "threads" || nextValue === "workflow" || nextValue === "people") { |
| 92 | + setTab(nextValue); |
| 93 | + } |
| 94 | + }} |
| 95 | + > |
| 96 | + <Toggle value="threads"> |
| 97 | + <MessageSquareIcon className="size-3.5" /> |
| 98 | + Threads |
| 99 | + </Toggle> |
| 100 | + <Toggle value="workflow"> |
| 101 | + <SparklesIcon className="size-3.5" /> |
| 102 | + Workflow |
| 103 | + </Toggle> |
| 104 | + <Toggle value="people"> |
| 105 | + <UsersIcon className="size-3.5" /> |
| 106 | + People |
| 107 | + </Toggle> |
| 108 | + </ToggleGroup> |
| 109 | + </div> |
| 110 | + |
| 111 | + <ScrollArea className="min-h-0 flex-1"> |
| 112 | + <div className="space-y-4 px-4 py-4"> |
| 113 | + {tab === "threads" ? ( |
| 114 | + <> |
| 115 | + {selectedFilePath ? ( |
| 116 | + <div className="flex items-center justify-between gap-3 rounded-2xl border border-border/70 bg-muted/25 px-3 py-3"> |
| 117 | + <div> |
| 118 | + <p className="text-sm font-medium text-foreground"> |
| 119 | + Filtered to {selectedFilePath} |
| 120 | + </p> |
| 121 | + <p className="text-xs text-muted-foreground"> |
| 122 | + Only conversations on the focused file are shown here. |
| 123 | + </p> |
| 124 | + </div> |
| 125 | + <Button |
| 126 | + onClick={() => { |
| 127 | + onSelectFilePath(null); |
| 128 | + onSelectThreadId(null); |
| 129 | + }} |
| 130 | + size="xs" |
| 131 | + variant="outline" |
| 132 | + > |
| 133 | + Clear focus |
| 134 | + </Button> |
| 135 | + </div> |
| 136 | + ) : null} |
| 137 | + {visibleThreads.length === 0 ? ( |
| 138 | + <div className="rounded-2xl border border-dashed border-border/70 bg-muted/18 px-4 py-6 text-sm text-muted-foreground"> |
| 139 | + No conversations are visible for the current scope. |
| 140 | + </div> |
| 141 | + ) : ( |
| 142 | + visibleThreads.map((thread) => ( |
| 143 | + <PrThreadCard |
| 144 | + dashboard={dashboard} |
| 145 | + key={thread.id} |
| 146 | + onReplyToThread={onReplyToThread} |
| 147 | + onResolveThread={onResolveThread} |
| 148 | + onSelectFilePath={onSelectFilePath} |
| 149 | + onSelectThreadId={onSelectThreadId} |
| 150 | + project={project} |
| 151 | + selectedThreadId={selectedThreadId} |
| 152 | + thread={thread} |
| 153 | + /> |
| 154 | + )) |
| 155 | + )} |
| 156 | + </> |
| 157 | + ) : null} |
| 158 | + |
| 159 | + {tab === "workflow" ? ( |
| 160 | + <PrWorkflowPanel |
| 161 | + conflicts={conflicts} |
| 162 | + config={config} |
| 163 | + onOpenRules={onOpenRules} |
| 164 | + onOpenWorkflow={onOpenWorkflow} |
| 165 | + onRunStep={onRunStep} |
| 166 | + onWorkflowIdChange={onWorkflowIdChange} |
| 167 | + workflowId={workflowId} |
| 168 | + workflowSteps={dashboard.workflowSteps} |
| 169 | + /> |
| 170 | + ) : null} |
| 171 | + |
| 172 | + {tab === "people" ? ( |
| 173 | + <div className="space-y-4"> |
| 174 | + <div className="rounded-2xl border border-border/70 bg-background/92 p-4"> |
| 175 | + <p className="text-[11px] font-medium uppercase tracking-[0.16em] text-muted-foreground"> |
| 176 | + Participants |
| 177 | + </p> |
| 178 | + <div className="mt-4 grid gap-3"> |
| 179 | + {dashboard.pullRequest.participants.map((participant) => ( |
| 180 | + <div |
| 181 | + className="flex items-center gap-3 rounded-2xl border border-border/70 bg-muted/22 px-3 py-3" |
| 182 | + key={`${participant.user.login}:${participant.role}`} |
| 183 | + > |
| 184 | + <img |
| 185 | + alt={participant.user.login} |
| 186 | + className="size-10 rounded-full border border-border/70" |
| 187 | + src={participant.user.avatarUrl} |
| 188 | + /> |
| 189 | + <div className="min-w-0 flex-1"> |
| 190 | + <PrUserHoverCard cwd={project.cwd} login={participant.user.login}> |
| 191 | + @{participant.user.login} |
| 192 | + </PrUserHoverCard> |
| 193 | + <p className="truncate text-xs text-muted-foreground">{participant.role}</p> |
| 194 | + </div> |
| 195 | + </div> |
| 196 | + ))} |
| 197 | + </div> |
| 198 | + </div> |
| 199 | + |
| 200 | + <div className="rounded-2xl border border-border/70 bg-background/92 p-4"> |
| 201 | + <p className="text-[11px] font-medium uppercase tracking-[0.16em] text-muted-foreground"> |
| 202 | + Repo Rules |
| 203 | + </p> |
| 204 | + <div className="mt-4 space-y-3"> |
| 205 | + {config?.rules.blockingRules.map((rule) => ( |
| 206 | + <div key={rule.id}> |
| 207 | + <p className="font-medium text-sm text-foreground">{rule.title}</p> |
| 208 | + {rule.description ? ( |
| 209 | + <p className="mt-1 text-sm text-muted-foreground">{rule.description}</p> |
| 210 | + ) : null} |
| 211 | + </div> |
| 212 | + ))} |
| 213 | + </div> |
| 214 | + </div> |
| 215 | + </div> |
| 216 | + ) : null} |
| 217 | + </div> |
| 218 | + </ScrollArea> |
| 219 | + </div> |
| 220 | + ); |
| 221 | +} |
0 commit comments