The best way to control Claude Code, Codex and more from any computer or phone
Mirrored from https://github.com/Camo67/t3code.git
Synced Nov 21, 04:45 UTC
| 1 | import { RegistryContext, useAtomValue } from "@effect/atom-react"; |
| 2 | import { issueEventSentence, issueWriteAccess } from "@t3tools/client-runtime/issue-presentation"; |
| 3 | import { createIssueCommentPager } from "@t3tools/client-runtime/state/issues"; |
| 4 | import { |
| 5 | issueAssigneeHeld, |
| 6 | issueAssigneesAfterPicks, |
| 7 | issueLabelsAfterPicks, |
| 8 | issuePicksAfterFailedWrite, |
| 9 | issuePicksFor, |
| 10 | issueWriteAfterPicks, |
| 11 | noIssuePicks, |
| 12 | } from "@t3tools/client-runtime/issue-selection"; |
| 13 | import { isSelected, toggleSelection } from "@t3tools/client-runtime/pull-request-selection"; |
| 14 | import { executeAtomQuery, squashAtomCommandFailure } from "@t3tools/client-runtime/state/runtime"; |
| 15 | import type { |
| 16 | EnvironmentId, |
| 17 | IssueAssigneeCandidate, |
| 18 | IssueComment, |
| 19 | IssueDetail, |
| 20 | IssueEvent, |
| 21 | IssueLabelCandidate, |
| 22 | IssueLinkedPullRequest, |
| 23 | IssueListEntry, |
| 24 | IssueReaction, |
| 25 | IssueRef, |
| 26 | PullRequestRef, |
| 27 | ScopedThreadRef, |
| 28 | } from "@t3tools/contracts"; |
| 29 | import { |
| 30 | CheckIcon, |
| 31 | ChevronDownIcon, |
| 32 | ExternalLinkIcon, |
| 33 | TagIcon, |
| 34 | UserPlusIcon, |
| 35 | UsersIcon, |
| 36 | } from "lucide-react"; |
| 37 | import { msg, T, useGT, useMessages, Var } from "gt-react"; |
| 38 | import { useContext, useState, type ReactNode } from "react"; |
| 39 | |
| 40 | import { RefreshIcon } from "~/components/ui/refresh-icon"; |
| 41 | import { m } from "~/i18n/messages"; |
| 42 | import { issueEnvironment, refreshIssueLists } from "~/state/issues"; |
| 43 | import { useProjects } from "~/state/entities"; |
| 44 | import { useEnvironmentQuery } from "~/state/query"; |
| 45 | import { useAtomCommand } from "~/state/use-atom-command"; |
| 46 | import { formatRelativeTimeLabel } from "~/timestampFormat"; |
| 47 | |
| 48 | import { Alert, AlertDescription, AlertTitle } from "../ui/alert"; |
| 49 | import { Button, InlineButton } from "../ui/button"; |
| 50 | import { Input } from "../ui/input"; |
| 51 | import { Menu, MenuItem, MenuPopup, MenuTrigger } from "../ui/menu"; |
| 52 | import { cn } from "~/lib/utils"; |
| 53 | import { PullRequestMetaRow, PullRequestSection } from "../pullRequest/PullRequestSummaryTab"; |
| 54 | import { toastManager } from "../ui/toast"; |
| 55 | import { PullRequestCandidatePicker } from "../pullRequest/PullRequestCandidatePicker"; |
| 56 | import { PullRequestCommentBody } from "../pullRequest/PullRequestCommentBody"; |
| 57 | import { PullRequestDetailTitleRow } from "../pullRequest/PullRequestDetailLayout"; |
| 58 | import { PullRequestEditButton } from "../pullRequest/PullRequestEditButton"; |
| 59 | import { PullRequestMarkdown } from "../pullRequest/PullRequestMarkdown"; |
| 60 | import { PullRequestMarkdownEditor } from "../pullRequest/PullRequestMarkdownEditor"; |
| 61 | import { readableFailure } from "../pullRequest/pullRequestDetail.logic"; |
| 62 | import { pullRequestLabelColor } from "../pullRequest/pullRequestList.logic"; |
| 63 | import { |
| 64 | PullRequestActorLabel, |
| 65 | PullRequestLabelChip, |
| 66 | PullRequestMetaLine, |
| 67 | PullRequestStateGlyph, |
| 68 | } from "../pullRequest/pullRequestPresentation"; |
| 69 | import { IssueCommentComposer } from "./IssueCommentComposer"; |
| 70 | import { IssueDetailGhost } from "./IssueDetailGhost"; |
| 71 | import { IssueThreadLinks } from "./IssueThreadLinks"; |
| 72 | import { ReactionBar } from "../pullRequest/PullRequestReactions"; |
| 73 | import { PullRequestsUnavailableState } from "../pullRequest/PullRequestsUnavailableState"; |
| 74 | import { issueTrackerPresentation, issueStatePresentation } from "./issuePresentation"; |
| 75 | |
| 76 | function IssueReactionBar({ |
| 77 | reactions, |
| 78 | canReact, |
| 79 | subjectId, |
| 80 | environmentId, |
| 81 | reference, |
| 82 | }: { |
| 83 | reactions: ReadonlyArray<IssueReaction>; |
| 84 | canReact: boolean; |
| 85 | subjectId?: string | undefined; |
| 86 | environmentId: EnvironmentId; |
| 87 | reference: IssueRef; |
| 88 | }) { |
| 89 | const react = useAtomCommand(issueEnvironment.react, { reportFailure: false }); |
| 90 | return ( |
| 91 | <ReactionBar |
| 92 | reactions={reactions} |
| 93 | canReact={canReact} |
| 94 | onReact={async (content, reacted) => { |
| 95 | const result = await react({ |
| 96 | environmentId, |
| 97 | input: { |
| 98 | ...reference, |
| 99 | ...(subjectId === undefined ? {} : { subjectId }), |
| 100 | content, |
| 101 | reacted, |
| 102 | }, |
| 103 | }); |
| 104 | return result._tag !== "Failure"; |
| 105 | }} |
| 106 | /> |
| 107 | ); |
| 108 | } |
| 109 | |
| 110 | function IssueLabelPicker({ |
| 111 | environmentId, |
| 112 | reference, |
| 113 | detail, |
| 114 | allowed, |
| 115 | disabledReason, |
| 116 | }: { |
| 117 | environmentId: EnvironmentId; |
| 118 | reference: IssueRef; |
| 119 | detail: IssueDetail; |
| 120 | allowed: boolean; |
| 121 | disabledReason: string; |
| 122 | }) { |
| 123 | const gt = useGT(); |
| 124 | const [open, setOpen] = useState(false); |
| 125 | const [query, setQuery] = useState(""); |
| 126 | const [picks, setPicks] = useState(noIssuePicks<IssueLabelCandidate>); |
| 127 | const current = issuePicksFor(picks, detail, open); |
| 128 | const draft = current.draft; |
| 129 | const candidatesQuery = useEnvironmentQuery( |
| 130 | open ? issueEnvironment.candidates({ environmentId, input: reference }) : null, |
| 131 | ); |
| 132 | const update = useAtomCommand(issueEnvironment.update, { reportFailure: false }); |
| 133 | const applied = new Set(detail.labels.map((label) => label.name)); |
| 134 | const needle = query.toLowerCase(); |
| 135 | const candidates = (candidatesQuery.data?.labels ?? []).filter( |
| 136 | (label) => |
| 137 | needle.length === 0 || |
| 138 | label.name.toLowerCase().includes(needle) || |
| 139 | (label.description ?? "").toLowerCase().includes(needle), |
| 140 | ); |
| 141 | const onOpenChange = (nextOpen: boolean) => { |
| 142 | setOpen(nextOpen); |
| 143 | if (nextOpen) { |
| 144 | // Picks made against an older read are not this picker's any more. |
| 145 | setPicks(issuePicksFor(picks, detail, false)); |
| 146 | return; |
| 147 | } |
| 148 | const labels = issueWriteAfterPicks( |
| 149 | issueLabelsAfterPicks(detail, draft), |
| 150 | detail.labels.map((label) => label.name), |
| 151 | current.written, |
| 152 | ); |
| 153 | if (labels === null) return; |
| 154 | const sent = { ...current, written: labels }; |
| 155 | setPicks(sent); |
| 156 | void update({ environmentId, input: { ...reference, labels } }).then((result) => { |
| 157 | if (result._tag !== "Failure") { |
| 158 | refreshIssueLists(environmentId); |
| 159 | return; |
| 160 | } |
| 161 | setPicks((latest) => issuePicksAfterFailedWrite(latest, sent)); |
| 162 | toastManager.add({ |
| 163 | type: "error", |
| 164 | title: m(msg("Could not change labels")), |
| 165 | description: readableFailure( |
| 166 | squashAtomCommandFailure(result), |
| 167 | m(msg("The tracker refused it.")), |
| 168 | ), |
| 169 | }); |
| 170 | }); |
| 171 | }; |
| 172 | return ( |
| 173 | <PullRequestCandidatePicker |
| 174 | icon={<TagIcon className="size-3.5" />} |
| 175 | label={gt("Change labels")} |
| 176 | allowed={allowed} |
| 177 | disabledReason={disabledReason} |
| 178 | open={open} |
| 179 | onOpenChange={onOpenChange} |
| 180 | query={query} |
| 181 | onQueryChange={setQuery} |
| 182 | searchLabel={gt("Search labels")} |
| 183 | isPending={candidatesQuery.isPending && candidatesQuery.data === null} |
| 184 | error={candidatesQuery.data === null ? candidatesQuery.error : null} |
| 185 | candidates={candidates} |
| 186 | emptyLabel={gt("This tracker has no labels.")} |
| 187 | noMatchLabel={gt("No label matches that.")} |
| 188 | errorLabel={gt("The labels could not be read.")} |
| 189 | truncated={candidatesQuery.data?.truncated === true} |
| 190 | truncatedLabel={gt("More labels exist than are listed here.")} |
| 191 | candidateKey={(candidate) => candidate.name} |
| 192 | onSelect={(candidate) => |
| 193 | setPicks({ |
| 194 | ...current, |
| 195 | draft: toggleSelection(draft, candidate.name, candidate, applied.has(candidate.name)), |
| 196 | }) |
| 197 | } |
| 198 | > |
| 199 | {(candidate) => { |
| 200 | const dot = pullRequestLabelColor(candidate.color); |
| 201 | return ( |
| 202 | <> |
| 203 | <span |
| 204 | aria-hidden |
| 205 | className="size-2 shrink-0 rounded-full bg-muted-foreground" |
| 206 | {...(dot ? { style: { backgroundColor: dot } } : {})} |
| 207 | /> |
| 208 | <span className="min-w-0 flex-1 truncate"> |
| 209 | {candidate.name} |
| 210 | {candidate.description ? ( |
| 211 | <span className="text-muted-foreground"> · {candidate.description}</span> |
| 212 | ) : null} |
| 213 | </span> |
| 214 | {isSelected(draft, candidate.name, applied.has(candidate.name)) ? ( |
| 215 | <CheckIcon |
| 216 | aria-label={gt("Applied", { $context: "label is applied to the issue" })} |
| 217 | className="size-3.5 shrink-0" |
| 218 | /> |
| 219 | ) : null} |
| 220 | </> |
| 221 | ); |
| 222 | }} |
| 223 | </PullRequestCandidatePicker> |
| 224 | ); |
| 225 | } |
| 226 | |
| 227 | function IssueAssigneePicker({ |
| 228 | environmentId, |
| 229 | reference, |
| 230 | detail, |
| 231 | allowed, |
| 232 | disabledReason, |
| 233 | }: { |
| 234 | environmentId: EnvironmentId; |
| 235 | reference: IssueRef; |
| 236 | detail: IssueDetail; |
| 237 | allowed: boolean; |
| 238 | disabledReason: string; |
| 239 | }) { |
| 240 | const gt = useGT(); |
| 241 | const [open, setOpen] = useState(false); |
| 242 | const [query, setQuery] = useState(""); |
| 243 | const [picks, setPicks] = useState(noIssuePicks<IssueAssigneeCandidate>); |
| 244 | const current = issuePicksFor(picks, detail, open); |
| 245 | const draft = current.draft; |
| 246 | const candidatesQuery = useEnvironmentQuery( |
| 247 | open ? issueEnvironment.candidates({ environmentId, input: reference }) : null, |
| 248 | ); |
| 249 | const update = useAtomCommand(issueEnvironment.update, { reportFailure: false }); |
| 250 | const needle = query.toLowerCase(); |
| 251 | const candidates = (candidatesQuery.data?.assignees ?? []).filter( |
| 252 | (candidate) => |
| 253 | needle.length === 0 || |
| 254 | candidate.login.toLowerCase().includes(needle) || |
| 255 | (candidate.name ?? "").toLowerCase().includes(needle), |
| 256 | ); |
| 257 | const onOpenChange = (nextOpen: boolean) => { |
| 258 | setOpen(nextOpen); |
| 259 | if (nextOpen) { |
| 260 | // Picks made against an older read are not this picker's any more. |
| 261 | setPicks(issuePicksFor(picks, detail, false)); |
| 262 | return; |
| 263 | } |
| 264 | const assignees = issueWriteAfterPicks( |
| 265 | issueAssigneesAfterPicks(detail, draft), |
| 266 | detail.assignees.map((actor) => actor.login), |
| 267 | current.written, |
| 268 | ); |
| 269 | if (assignees === null) return; |
| 270 | const sent = { ...current, written: assignees }; |
| 271 | setPicks(sent); |
| 272 | void update({ environmentId, input: { ...reference, assignees } }).then((result) => { |
| 273 | if (result._tag !== "Failure") { |
| 274 | refreshIssueLists(environmentId); |
| 275 | return; |
| 276 | } |
| 277 | setPicks((latest) => issuePicksAfterFailedWrite(latest, sent)); |
| 278 | toastManager.add({ |
| 279 | type: "error", |
| 280 | title: m(msg("Could not change assignees")), |
| 281 | description: readableFailure( |
| 282 | squashAtomCommandFailure(result), |
| 283 | m(msg("The tracker refused it.")), |
| 284 | ), |
| 285 | }); |
| 286 | }); |
| 287 | }; |
| 288 | return ( |
| 289 | <PullRequestCandidatePicker |
| 290 | icon={<UserPlusIcon className="size-3.5" />} |
| 291 | label={gt("Change assignees")} |
| 292 | allowed={allowed} |
| 293 | disabledReason={disabledReason} |
| 294 | open={open} |
| 295 | onOpenChange={onOpenChange} |
| 296 | query={query} |
| 297 | onQueryChange={setQuery} |
| 298 | searchLabel={gt("Search people")} |
| 299 | isPending={candidatesQuery.isPending && candidatesQuery.data === null} |
| 300 | error={candidatesQuery.data === null ? candidatesQuery.error : null} |
| 301 | candidates={candidates} |
| 302 | emptyLabel={gt("Nobody can be assigned here.")} |
| 303 | noMatchLabel={gt("Nobody matches that.")} |
| 304 | errorLabel={gt("The people could not be read.")} |
| 305 | truncated={candidatesQuery.data?.truncated === true} |
| 306 | truncatedLabel={gt("More people exist than are listed here.")} |
| 307 | candidateKey={(candidate) => candidate.id} |
| 308 | onSelect={(candidate) => |
| 309 | setPicks({ |
| 310 | ...current, |
| 311 | draft: toggleSelection( |
| 312 | draft, |
| 313 | candidate.id, |
| 314 | candidate, |
| 315 | issueAssigneeHeld(detail, candidate), |
| 316 | ), |
| 317 | }) |
| 318 | } |
| 319 | > |
| 320 | {(candidate) => ( |
| 321 | <> |
| 322 | <PullRequestActorLabel actor={candidate} tooltip={false} className="min-w-0 flex-1" /> |
| 323 | {isSelected(draft, candidate.id, issueAssigneeHeld(detail, candidate)) ? ( |
| 324 | <CheckIcon |
| 325 | aria-label={gt("Assigned", { $context: "person is assigned to the issue" })} |
| 326 | className="size-3.5 shrink-0" |
| 327 | /> |
| 328 | ) : null} |
| 329 | </> |
| 330 | )} |
| 331 | </PullRequestCandidatePicker> |
| 332 | ); |
| 333 | } |
| 334 | |
| 335 | type TimelineItem = |
| 336 | | { kind: "comment"; at: string; comment: IssueComment } |
| 337 | | { kind: "event"; at: string; event: IssueEvent }; |
| 338 | |
| 339 | function LinkedPullRequestRow({ |
| 340 | link, |
| 341 | scope, |
| 342 | onSelect, |
| 343 | }: { |
| 344 | link: IssueLinkedPullRequest; |
| 345 | /** The issue's own repository, left off a pull request that lives in it. */ |
| 346 | scope: string; |
| 347 | onSelect: (() => void) | null; |
| 348 | }) { |
| 349 | const body = ( |
| 350 | <> |
| 351 | <PullRequestStateGlyph state={link.state} isDraft={link.isDraft} /> |
| 352 | <span className="min-w-0 flex-1 truncate text-sm">{link.title}</span> |
| 353 | <PullRequestMetaLine className="shrink-0 text-xs text-muted-foreground"> |
| 354 | {link.closesIssue ? ( |
| 355 | <span> |
| 356 | <T>Closes this issue</T> |
| 357 | </span> |
| 358 | ) : null} |
| 359 | <span className="tabular-nums"> |
| 360 | {link.repository.toLowerCase() === scope.toLowerCase() ? "" : link.repository}# |
| 361 | {link.number} |
| 362 | </span> |
| 363 | </PullRequestMetaLine> |
| 364 | </> |
| 365 | ); |
| 366 | const className = |
| 367 | "flex w-full cursor-pointer items-center gap-2 rounded-md px-2 py-1.5 text-left hover:bg-accent"; |
| 368 | return onSelect ? ( |
| 369 | <button type="button" className={className} onClick={onSelect}> |
| 370 | {body} |
| 371 | </button> |
| 372 | ) : ( |
| 373 | <a href={link.url} target="_blank" rel="noopener noreferrer" className={className}> |
| 374 | {body} |
| 375 | </a> |
| 376 | ); |
| 377 | } |
| 378 | |
| 379 | export function IssueDetailPanel({ |
| 380 | environmentId, |
| 381 | reference, |
| 382 | threadRef = null, |
| 383 | listEntry = null, |
| 384 | onSelectPullRequest, |
| 385 | }: { |
| 386 | environmentId: EnvironmentId; |
| 387 | reference: IssueRef; |
| 388 | /** The list row this issue was opened from, shown until the detail arrives. */ |
| 389 | listEntry?: IssueListEntry | null; |
| 390 | threadRef?: ScopedThreadRef | null; |
| 391 | /** Opens a linked change request beside this one; absent, the link goes to the host. */ |
| 392 | onSelectPullRequest?: ((reference: PullRequestRef) => void) | undefined; |
| 393 | }) { |
| 394 | const gt = useGT(); |
| 395 | const messages = useMessages(); |
| 396 | const detailAtom = issueEnvironment.detail({ environmentId, input: reference }); |
| 397 | const detailQuery = useEnvironmentQuery(detailAtom); |
| 398 | const registry = useContext(RegistryContext); |
| 399 | const [pager] = useState(() => createIssueCommentPager(detailAtom)); |
| 400 | const { comments, nextCursor, loadingOlder, canLoadOlder } = useAtomValue(pager.view); |
| 401 | const detail = detailQuery.data; |
| 402 | const canWrite = useAtomValue(issueEnvironment.comment.permissionAtom(environmentId)); |
| 403 | const projects = useProjects(); |
| 404 | const cwd = |
| 405 | projects.find((p) => p.environmentId === environmentId && p.id === reference.projectId) |
| 406 | ?.workspaceRoot ?? ""; |
| 407 | |
| 408 | const loadComments = useAtomCommand(issueEnvironment.comments, { reportFailure: false }); |
| 409 | const update = useAtomCommand(issueEnvironment.update, { reportFailure: false }); |
| 410 | const setState = useAtomCommand(issueEnvironment.setState, { reportFailure: false }); |
| 411 | const [editing, setEditing] = useState<"title" | "body" | null>(null); |
| 412 | const [titleDraft, setTitleDraft] = useState(""); |
| 413 | const [saving, setSaving] = useState(false); |
| 414 | const [changingState, setChangingState] = useState(false); |
| 415 | |
| 416 | if (detail === null) { |
| 417 | if (detailQuery.error !== null && !detailQuery.isPending) { |
| 418 | return ( |
| 419 | <PullRequestsUnavailableState |
| 420 | title={gt("Could not load this issue")} |
| 421 | error={detailQuery.error} |
| 422 | onRetry={detailQuery.refresh} |
| 423 | /> |
| 424 | ); |
| 425 | } |
| 426 | return <IssueDetailGhost seed={listEntry} />; |
| 427 | } |
| 428 | |
| 429 | const timeline: ReadonlyArray<TimelineItem> = [ |
| 430 | ...comments.map((c): TimelineItem => ({ kind: "comment", at: c.createdAt, comment: c })), |
| 431 | ...detail.events.map((e): TimelineItem => ({ kind: "event", at: e.createdAt, event: e })), |
| 432 | ].sort((a, b) => Date.parse(a.at) - Date.parse(b.at)); |
| 433 | |
| 434 | const access = issueWriteAccess(detail, canWrite, messages); |
| 435 | const { blocked } = access; |
| 436 | const canComment = access.comment; |
| 437 | const canEdit = access.edit; |
| 438 | const canLabel = access.labels; |
| 439 | const canAssign = access.assignees; |
| 440 | const canReact = access.react; |
| 441 | const otherStates = access.states; |
| 442 | const tracker = issueTrackerPresentation(detail.tracker); |
| 443 | const currentState = issueStatePresentation(detail.state); |
| 444 | |
| 445 | const loadOlder = async () => { |
| 446 | const failure = await pager.loadOlder(registry, (cursor) => |
| 447 | loadComments({ environmentId, input: { ...reference, cursor } }), |
| 448 | ); |
| 449 | if (failure) { |
| 450 | toastManager.add({ type: "error", title: m(msg("Older comments could not be read")) }); |
| 451 | } |
| 452 | }; |
| 453 | |
| 454 | const save = async (patch: { title?: string; body?: string }) => { |
| 455 | setSaving(true); |
| 456 | const result = await update({ environmentId, input: { ...reference, ...patch } }); |
| 457 | setSaving(false); |
| 458 | if (result._tag === "Failure") { |
| 459 | toastManager.add({ |
| 460 | type: "error", |
| 461 | title: m(msg("The issue could not be updated")), |
| 462 | description: readableFailure( |
| 463 | squashAtomCommandFailure(result), |
| 464 | m(msg("The tracker refused it.")), |
| 465 | ), |
| 466 | }); |
| 467 | return; |
| 468 | } |
| 469 | refreshIssueLists(environmentId); |
| 470 | setEditing(null); |
| 471 | }; |
| 472 | |
| 473 | const moveTo = async (state: string) => { |
| 474 | if (changingState) return; |
| 475 | setChangingState(true); |
| 476 | const result = await setState({ |
| 477 | environmentId, |
| 478 | input: { ...reference, state }, |
| 479 | }); |
| 480 | setChangingState(false); |
| 481 | if (result._tag === "Failure") { |
| 482 | toastManager.add({ |
| 483 | type: "error", |
| 484 | title: m(msg("The state could not be changed")), |
| 485 | description: readableFailure( |
| 486 | squashAtomCommandFailure(result), |
| 487 | m(msg("The tracker refused it.")), |
| 488 | ), |
| 489 | }); |
| 490 | return; |
| 491 | } |
| 492 | refreshIssueLists(environmentId); |
| 493 | }; |
| 494 | |
| 495 | const currentStateIcon = ( |
| 496 | <currentState.Icon |
| 497 | aria-hidden |
| 498 | className={cn("size-3.5 shrink-0", currentState.toneClassName)} |
| 499 | /> |
| 500 | ); |
| 501 | const stateControl: ReactNode = |
| 502 | otherStates.length > 0 ? ( |
| 503 | <Menu> |
| 504 | <MenuTrigger |
| 505 | render={ |
| 506 | <Button |
| 507 | size="xs" |
| 508 | variant="outline" |
| 509 | aria-label={gt("Issue state, {state}", { state: currentState.label })} |
| 510 | disabled={changingState} |
| 511 | /> |
| 512 | } |
| 513 | > |
| 514 | {currentStateIcon} |
| 515 | {currentState.label} |
| 516 | <ChevronDownIcon aria-hidden className="size-3" /> |
| 517 | </MenuTrigger> |
| 518 | <MenuPopup align="end"> |
| 519 | {otherStates.map((state) => { |
| 520 | const presentation = issueStatePresentation(state); |
| 521 | return ( |
| 522 | <MenuItem key={state.name} onClick={() => void moveTo(state.name)}> |
| 523 | <presentation.Icon |
| 524 | aria-hidden |
| 525 | className={cn("size-3.5 shrink-0", presentation.toneClassName)} |
| 526 | /> |
| 527 | {state.name} |
| 528 | </MenuItem> |
| 529 | ); |
| 530 | })} |
| 531 | </MenuPopup> |
| 532 | </Menu> |
| 533 | ) : ( |
| 534 | <span className="flex shrink-0 items-center gap-1 font-medium"> |
| 535 | {currentStateIcon} |
| 536 | {currentState.label} |
| 537 | </span> |
| 538 | ); |
| 539 | |
| 540 | return ( |
| 541 | <div className="relative flex h-full min-h-0 flex-col"> |
| 542 | <div |
| 543 | className={cn( |
| 544 | "min-h-0 flex-1 overflow-y-auto", |
| 545 | // Room for the floating composer, so the last comment can scroll clear of it. |
| 546 | detail.capabilities.comment && "pb-32", |
| 547 | )} |
| 548 | data-pull-request-summary-scroll |
| 549 | > |
| 550 | <div className="px-4 pb-1"> |
| 551 | <PullRequestDetailTitleRow className="h-7 gap-1 text-sm sm:text-xs"> |
| 552 | <span className="min-w-0 truncate font-medium text-muted-foreground"> |
| 553 | {detail.scope} |
| 554 | </span> |
| 555 | <InlineButton |
| 556 | className={cn("shrink-0 font-medium", currentState.toneClassName)} |
| 557 | aria-label={gt("Open {issue} on {provider}", { |
| 558 | issue: detail.displayKey, |
| 559 | provider: tracker.providerName, |
| 560 | })} |
| 561 | render={<a href={detail.url} target="_blank" rel="noopener noreferrer" />} |
| 562 | > |
| 563 | {detail.displayKey} |
| 564 | <ExternalLinkIcon aria-hidden className="size-2.5" /> |
| 565 | </InlineButton> |
| 566 | <span className="flex-1" /> |
| 567 | {stateControl} |
| 568 | <IssueThreadLinks |
| 569 | key={`${environmentId}:${detail.url}`} |
| 570 | environmentId={environmentId} |
| 571 | reference={{ ...reference, host: reference.host ?? detail.host }} |
| 572 | issue={detail} |
| 573 | threadRef={threadRef} |
| 574 | /> |
| 575 | <Button |
| 576 | size="icon-xs" |
| 577 | variant="ghost" |
| 578 | aria-label={gt("Refresh issue")} |
| 579 | disabled={detailQuery.isPending} |
| 580 | onClick={() => |
| 581 | void pager.refresh(registry, () => |
| 582 | executeAtomQuery(registry, detailAtom, { refresh: true, reportFailure: false }), |
| 583 | ) |
| 584 | } |
| 585 | > |
| 586 | <RefreshIcon size="sm" refreshing={detailQuery.isPending} /> |
| 587 | </Button> |
| 588 | </PullRequestDetailTitleRow> |
| 589 | |
| 590 | {detailQuery.error !== null && !detailQuery.isPending ? ( |
| 591 | <div className="mt-2"> |
| 592 | <Alert variant="error"> |
| 593 | <AlertTitle>{gt("Could not refresh this issue")}</AlertTitle> |
| 594 | <AlertDescription>{detailQuery.error}</AlertDescription> |
| 595 | </Alert> |
| 596 | </div> |
| 597 | ) : null} |
| 598 | |
| 599 | {editing === "title" ? ( |
| 600 | <form |
| 601 | className="mt-1 flex items-center gap-2" |
| 602 | onSubmit={(event) => { |
| 603 | event.preventDefault(); |
| 604 | const next = titleDraft.trim(); |
| 605 | if (next.length > 0 && next !== detail.title) void save({ title: next }); |
| 606 | else setEditing(null); |
| 607 | }} |
| 608 | > |
| 609 | <Input |
| 610 | autoFocus |
| 611 | aria-label={gt("Issue title")} |
| 612 | value={titleDraft} |
| 613 | disabled={saving} |
| 614 | onChange={(event) => setTitleDraft(event.target.value)} |
| 615 | onKeyDown={(event) => { |
| 616 | if (event.key === "Escape") setEditing(null); |
| 617 | }} |
| 618 | /> |
| 619 | <Button type="submit" size="sm" disabled={saving}> |
| 620 | <T>Save</T> |
| 621 | </Button> |
| 622 | <Button |
| 623 | type="button" |
| 624 | size="sm" |
| 625 | variant="outline" |
| 626 | disabled={saving} |
| 627 | onClick={() => setEditing(null)} |
| 628 | > |
| 629 | <T>Cancel</T> |
| 630 | </Button> |
| 631 | </form> |
| 632 | ) : ( |
| 633 | <PullRequestDetailTitleRow className="group mt-1 gap-1"> |
| 634 | <h2 className="min-w-0 flex-1 text-base font-semibold leading-snug"> |
| 635 | {detail.title} |
| 636 | </h2> |
| 637 | {canEdit ? ( |
| 638 | <PullRequestEditButton |
| 639 | aria-label={gt("Edit title")} |
| 640 | onClick={() => { |
| 641 | setTitleDraft(detail.title); |
| 642 | setEditing("title"); |
| 643 | }} |
| 644 | /> |
| 645 | ) : null} |
| 646 | </PullRequestDetailTitleRow> |
| 647 | )} |
| 648 | |
| 649 | <PullRequestMetaLine className="mt-2 min-h-5 text-xs text-muted-foreground"> |
| 650 | <PullRequestActorLabel actor={detail.author} /> |
| 651 | <span> |
| 652 | <T> |
| 653 | opened <Var>{formatRelativeTimeLabel(detail.createdAt, undefined, messages)}</Var> |
| 654 | </T> |
| 655 | </span> |
| 656 | {detail.closedAt ? ( |
| 657 | <span> |
| 658 | <T> |
| 659 | closed <Var>{formatRelativeTimeLabel(detail.closedAt, undefined, messages)}</Var> |
| 660 | </T> |
| 661 | </span> |
| 662 | ) : null} |
| 663 | {detail.writable ? null : ( |
| 664 | <span> |
| 665 | <T>Read-only</T> |
| 666 | </span> |
| 667 | )} |
| 668 | </PullRequestMetaLine> |
| 669 | |
| 670 | <div className="mt-4 space-y-2"> |
| 671 | <PullRequestMetaRow icon={<TagIcon className="size-3.5" />} label={gt("Labels")}> |
| 672 | <span className="flex min-w-0 flex-wrap items-center gap-1"> |
| 673 | {detail.labels.length === 0 ? ( |
| 674 | <span className="text-muted-foreground"> |
| 675 | <T context="no labels">None</T> |
| 676 | </span> |
| 677 | ) : ( |
| 678 | detail.labels.map((label) => ( |
| 679 | <PullRequestLabelChip |
| 680 | key={label.name} |
| 681 | label={label} |
| 682 | size="default" |
| 683 | className="max-w-48" |
| 684 | /> |
| 685 | )) |
| 686 | )} |
| 687 | {detail.capabilities.labels ? ( |
| 688 | <IssueLabelPicker |
| 689 | environmentId={environmentId} |
| 690 | reference={reference} |
| 691 | detail={detail} |
| 692 | allowed={canLabel} |
| 693 | disabledReason={ |
| 694 | blocked ?? gt("Changing labels needs triage access on this tracker.") |
| 695 | } |
| 696 | /> |
| 697 | ) : null} |
| 698 | </span> |
| 699 | </PullRequestMetaRow> |
| 700 | <PullRequestMetaRow icon={<UsersIcon className="size-3.5" />} label={gt("Assignees")}> |
| 701 | <span className="flex min-w-0 flex-wrap items-center gap-1.5"> |
| 702 | {detail.assignees.length === 0 ? ( |
| 703 | <span className="text-muted-foreground"> |
| 704 | <T context="no assignees">None</T> |
| 705 | </span> |
| 706 | ) : ( |
| 707 | detail.assignees.map((actor) => ( |
| 708 | <PullRequestActorLabel key={actor.login} actor={actor} /> |
| 709 | )) |
| 710 | )} |
| 711 | {detail.capabilities.assignees ? ( |
| 712 | <IssueAssigneePicker |
| 713 | environmentId={environmentId} |
| 714 | reference={reference} |
| 715 | detail={detail} |
| 716 | allowed={canAssign} |
| 717 | disabledReason={ |
| 718 | blocked ?? gt("Changing assignees needs triage access on this tracker.") |
| 719 | } |
| 720 | /> |
| 721 | ) : null} |
| 722 | </span> |
| 723 | </PullRequestMetaRow> |
| 724 | </div> |
| 725 | </div> |
| 726 | |
| 727 | <PullRequestSection |
| 728 | key={`description:${detail.url}`} |
| 729 | title={gt("Description")} |
| 730 | keepMounted |
| 731 | actions={ |
| 732 | canEdit && editing !== "body" ? ( |
| 733 | <PullRequestEditButton |
| 734 | aria-label={gt("Edit description")} |
| 735 | onClick={() => setEditing("body")} |
| 736 | /> |
| 737 | ) : null |
| 738 | } |
| 739 | > |
| 740 | <div className="flex flex-col gap-2"> |
| 741 | {editing === "body" ? ( |
| 742 | <PullRequestMarkdownEditor |
| 743 | value={detail.body} |
| 744 | cwd={cwd} |
| 745 | environmentId={environmentId} |
| 746 | threadRef={threadRef} |
| 747 | label={gt("Description")} |
| 748 | completionScope={null} |
| 749 | saving={saving} |
| 750 | allowEmpty |
| 751 | onSave={(next) => void save({ body: next })} |
| 752 | onCancel={() => setEditing(null)} |
| 753 | /> |
| 754 | ) : ( |
| 755 | <PullRequestMarkdown |
| 756 | text={ |
| 757 | detail.body.trim().length > 0 ? detail.body : gt("_No description provided._") |
| 758 | } |
| 759 | cwd={cwd} |
| 760 | environmentId={environmentId} |
| 761 | threadRef={threadRef} |
| 762 | /> |
| 763 | )} |
| 764 | {detail.reactions !== undefined ? ( |
| 765 | <IssueReactionBar |
| 766 | reactions={detail.reactions} |
| 767 | canReact={canReact} |
| 768 | environmentId={environmentId} |
| 769 | reference={reference} |
| 770 | /> |
| 771 | ) : null} |
| 772 | </div> |
| 773 | </PullRequestSection> |
| 774 | |
| 775 | {detail.linkedPullRequests.length > 0 ? ( |
| 776 | <PullRequestSection key={`linked:${detail.url}`} title={gt("Linked pull requests")}> |
| 777 | <div className="flex flex-col gap-1"> |
| 778 | {detail.linkedPullRequests.map((link) => ( |
| 779 | <LinkedPullRequestRow |
| 780 | key={`${link.repository}#${link.number}`} |
| 781 | link={link} |
| 782 | scope={detail.scope} |
| 783 | onSelect={ |
| 784 | onSelectPullRequest |
| 785 | ? () => |
| 786 | onSelectPullRequest({ |
| 787 | projectId: reference.projectId, |
| 788 | ...(reference.host === undefined ? {} : { host: reference.host }), |
| 789 | repository: link.repository, |
| 790 | number: link.number, |
| 791 | }) |
| 792 | : null |
| 793 | } |
| 794 | /> |
| 795 | ))} |
| 796 | </div> |
| 797 | </PullRequestSection> |
| 798 | ) : null} |
| 799 | |
| 800 | <PullRequestSection |
| 801 | key={`activity:${detail.url}`} |
| 802 | title={ |
| 803 | detail.commentCount > 0 |
| 804 | ? gt("Activity ({count})", { count: detail.commentCount }) |
| 805 | : gt("Activity") |
| 806 | } |
| 807 | > |
| 808 | <div className="flex flex-col gap-3"> |
| 809 | {nextCursor !== null ? ( |
| 810 | <Button |
| 811 | size="sm" |
| 812 | variant="outline" |
| 813 | className="self-start" |
| 814 | disabled={!canLoadOlder} |
| 815 | onClick={() => void loadOlder()} |
| 816 | > |
| 817 | {loadingOlder ? <T>Loading…</T> : <T>Load older comments</T>} |
| 818 | </Button> |
| 819 | ) : null} |
| 820 | {timeline.length === 0 ? ( |
| 821 | <p className="text-sm text-muted-foreground"> |
| 822 | <T>Nothing has happened here yet.</T> |
| 823 | </p> |
| 824 | ) : null} |
| 825 | {timeline.map((item) => |
| 826 | item.kind === "comment" ? ( |
| 827 | <article |
| 828 | key={`c:${item.comment.id}`} |
| 829 | className="flex flex-col gap-2 rounded-lg border border-border/60 p-3" |
| 830 | > |
| 831 | <h3> |
| 832 | <PullRequestMetaLine className="text-xs text-muted-foreground"> |
| 833 | <PullRequestActorLabel actor={item.comment.author} /> |
| 834 | {item.comment.url ? ( |
| 835 | <InlineButton |
| 836 | tone="muted" |
| 837 | render={ |
| 838 | <a href={item.comment.url} target="_blank" rel="noopener noreferrer" /> |
| 839 | } |
| 840 | > |
| 841 | {formatRelativeTimeLabel(item.comment.createdAt, undefined, messages)} |
| 842 | </InlineButton> |
| 843 | ) : ( |
| 844 | <span> |
| 845 | {formatRelativeTimeLabel(item.comment.createdAt, undefined, messages)} |
| 846 | </span> |
| 847 | )} |
| 848 | </PullRequestMetaLine> |
| 849 | </h3> |
| 850 | <PullRequestCommentBody |
| 851 | text={item.comment.body} |
| 852 | cwd={cwd} |
| 853 | environmentId={environmentId} |
| 854 | threadRef={threadRef} |
| 855 | /> |
| 856 | {item.comment.reactions !== undefined ? ( |
| 857 | <IssueReactionBar |
| 858 | reactions={item.comment.reactions} |
| 859 | canReact={canReact} |
| 860 | subjectId={item.comment.id} |
| 861 | environmentId={environmentId} |
| 862 | reference={reference} |
| 863 | /> |
| 864 | ) : null} |
| 865 | </article> |
| 866 | ) : ( |
| 867 | <PullRequestMetaLine |
| 868 | key={`e:${item.event.id}`} |
| 869 | className="px-1 text-xs text-muted-foreground" |
| 870 | > |
| 871 | <PullRequestActorLabel actor={item.event.actor} /> |
| 872 | <span>{issueEventSentence(item.event, messages)}</span> |
| 873 | <span>{formatRelativeTimeLabel(item.event.createdAt, undefined, messages)}</span> |
| 874 | </PullRequestMetaLine> |
| 875 | ), |
| 876 | )} |
| 877 | </div> |
| 878 | </PullRequestSection> |
| 879 | </div> |
| 880 | |
| 881 | {detail.capabilities.comment ? ( |
| 882 | <IssueCommentComposer |
| 883 | environmentId={environmentId} |
| 884 | reference={reference} |
| 885 | blocked={canComment ? null : (blocked ?? gt("You cannot comment here."))} |
| 886 | /> |
| 887 | ) : null} |
| 888 | </div> |
| 889 | ); |
| 890 | } |