The best way to control Claude Code, Codex and more from any computer or phone
| 1 | import { useAtomValue } from "@effect/atom-react"; |
| 2 | import { |
| 3 | continueIssuePage, |
| 4 | groupIssues, |
| 5 | holdIssuePages, |
| 6 | issueCursorsForHost, |
| 7 | issueFilterScopes, |
| 8 | issueTrackerKey, |
| 9 | type HeldIssuePage, |
| 10 | } from "@t3tools/client-runtime/issue-list"; |
| 11 | import { issueTrackerDetailText } from "@t3tools/client-runtime/state/issue-trackers"; |
| 12 | import { issueEntryKey } from "@t3tools/client-runtime/state/issues"; |
| 13 | import type { |
| 14 | EnvironmentId, |
| 15 | IssueInvolvement, |
| 16 | IssueListInput, |
| 17 | IssueListSort, |
| 18 | IssueListState, |
| 19 | IssueTrackerKind, |
| 20 | IssueTrackerSummary, |
| 21 | ProjectId, |
| 22 | } from "@t3tools/contracts"; |
| 23 | import { useNavigate, useSearch } from "@tanstack/react-router"; |
| 24 | import { |
| 25 | ArrowDownUpIcon, |
| 26 | AtSignIcon, |
| 27 | CalendarArrowDownIcon, |
| 28 | CircleCheckIcon, |
| 29 | ClockIcon, |
| 30 | LayersIcon, |
| 31 | PenLineIcon, |
| 32 | Plug2Icon, |
| 33 | UserCheckIcon, |
| 34 | UsersIcon, |
| 35 | } from "lucide-react"; |
| 36 | import { msg, T, useGT, useMessages, Var } from "gt-react"; |
| 37 | import { Fragment, useEffect, useEffectEvent, useState, type ReactNode } from "react"; |
| 38 | |
| 39 | import { RefreshIcon } from "~/components/ui/refresh-icon"; |
| 40 | import { IssueDetailPanel } from "~/components/issue/IssueDetailPanel"; |
| 41 | import { IssueRow, type IssueRowTarget } from "~/components/issue/IssueRow"; |
| 42 | import { |
| 43 | issueListPreferences, |
| 44 | writeIssueListPreferences, |
| 45 | type IssueListPreferences, |
| 46 | } from "~/components/issue/issueListPreferences"; |
| 47 | import { IssueGlyph, issueTrackerPresentation } from "~/components/issue/issuePresentation"; |
| 48 | import { PullRequestDetailPanel } from "~/components/pullRequest/PullRequestDetailPanel"; |
| 49 | import { PullRequestListGhost } from "~/components/pullRequest/PullRequestGhosts"; |
| 50 | import { |
| 51 | PullRequestFilterOptionIcon, |
| 52 | pullRequestProjectKey, |
| 53 | PullRequestSearchInput, |
| 54 | type PullRequestFilterOption, |
| 55 | } from "~/components/pullRequest/PullRequestListFilters"; |
| 56 | import { m, type MessageResolver } from "~/i18n/messages"; |
| 57 | import { resolveFilterOptions } from "../pullRequest/pullRequestListOptions"; |
| 58 | import { IssueFiltersMenu } from "./IssueListFilterPickers"; |
| 59 | import { issueFilterProjects, issueListTargets, issueProjectKeys } from "./issuesSearch.logic"; |
| 60 | import { ISSUE_SAVED_VIEWS } from "./issueSavedViews"; |
| 61 | import { SavedViewsMenu } from "~/components/SavedViewsMenu"; |
| 62 | import { PullRequestCompactFilterMenu } from "../pullRequest/PullRequestCompactFilterMenu"; |
| 63 | import { PullRequestsUnavailableState } from "~/components/pullRequest/PullRequestsUnavailableState"; |
| 64 | import { RightPanelTabs } from "~/components/RightPanelTabs"; |
| 65 | import { WorkspaceBreadcrumb, WorkspaceBreadcrumbItem } from "~/components/WorkspaceBreadcrumb"; |
| 66 | import { WorkspacePageContainer } from "~/components/WorkspacePageContainer"; |
| 67 | import { WorkspacePageHeader } from "~/components/WorkspacePageHeader"; |
| 68 | import { PanelLayoutControls } from "~/components/chat/PanelLayoutControls"; |
| 69 | import { Button } from "~/components/ui/button"; |
| 70 | import { |
| 71 | Empty, |
| 72 | EmptyContent, |
| 73 | EmptyDescription, |
| 74 | EmptyHeader, |
| 75 | EmptyMedia, |
| 76 | EmptyTitle, |
| 77 | } from "~/components/ui/empty"; |
| 78 | import { Menu, MenuPopup, MenuRadioGroup, MenuRadioItem, MenuTrigger } from "~/components/ui/menu"; |
| 79 | import { SidebarInset } from "~/components/ui/sidebar"; |
| 80 | import { isCommandPaletteOpen } from "~/commandPaletteBus"; |
| 81 | import { isElectron } from "~/env"; |
| 82 | import { useLiveRefresh } from "~/hooks/useLiveRefresh"; |
| 83 | import { resolveShortcutCommand, shortcutLabelForCommand } from "~/keybindings"; |
| 84 | import { isTerminalFocused } from "~/lib/terminalFocus"; |
| 85 | import { usePanelAnimationSettings, usePanelPresence } from "~/panelAnimations"; |
| 86 | import { |
| 87 | ISSUES_PANEL_REF, |
| 88 | selectActiveRightPanelSurface, |
| 89 | selectSelectedRightPanelSurface, |
| 90 | selectThreadRightPanelState, |
| 91 | useRightPanelStore, |
| 92 | type PullRequestSurface, |
| 93 | type RightPanelSurface, |
| 94 | } from "~/rightPanelStore"; |
| 95 | import { useAtomCommand } from "~/state/use-atom-command"; |
| 96 | import { squashAtomCommandFailure } from "@t3tools/client-runtime/state/runtime"; |
| 97 | import { useProjects } from "~/state/entities"; |
| 98 | import { useEnvironments, useIssuesSupported } from "~/state/environments"; |
| 99 | import { issueEnvironment, useIssueList } from "~/state/issues"; |
| 100 | import { useDebouncedValue } from "~/state/queries"; |
| 101 | import { primaryServerKeybindingsAtom } from "~/state/server"; |
| 102 | |
| 103 | export interface IssuesSearch extends IssueListPreferences { |
| 104 | readonly selectedEnvironmentId?: EnvironmentId | undefined; |
| 105 | readonly selectedProjectId?: ProjectId | undefined; |
| 106 | /** Part of the panel tab's identity, so a link reopens the tab a row press opened. */ |
| 107 | readonly selectedHost?: string | undefined; |
| 108 | readonly tracker?: string | undefined; |
| 109 | readonly scope?: string | undefined; |
| 110 | readonly key?: string | undefined; |
| 111 | } |
| 112 | |
| 113 | const STATE_TABS = [ |
| 114 | { value: "open", label: msg("Open", { $context: "issue state" }), Icon: IssueGlyph.issue }, |
| 115 | { value: "closed", label: msg("Closed", { $context: "issue state" }), Icon: CircleCheckIcon }, |
| 116 | { value: "all", label: msg("All", { $context: "issue filter" }), Icon: LayersIcon }, |
| 117 | ] as const satisfies ReadonlyArray<PullRequestFilterOption<IssueListState>>; |
| 118 | |
| 119 | const INVOLVEMENT_TABS = [ |
| 120 | { value: "all", label: msg("Everyone", { $context: "issue filter" }), Icon: UsersIcon }, |
| 121 | { value: "assigned", label: msg("Assigned to me"), Icon: UserCheckIcon }, |
| 122 | { value: "authored", label: msg("Opened by me"), Icon: PenLineIcon }, |
| 123 | { value: "mentioned", label: msg("Mentioning me"), Icon: AtSignIcon }, |
| 124 | ] as const satisfies ReadonlyArray<PullRequestFilterOption<IssueInvolvement>>; |
| 125 | |
| 126 | const SORT_OPTIONS = [ |
| 127 | { value: "updated", label: msg("Recently updated"), Icon: ClockIcon }, |
| 128 | { |
| 129 | value: "created", |
| 130 | label: msg("Newest", { $context: "sort order" }), |
| 131 | Icon: CalendarArrowDownIcon, |
| 132 | }, |
| 133 | ] as const satisfies ReadonlyArray<PullRequestFilterOption<IssueListSort>>; |
| 134 | |
| 135 | const PAGE_SIZE = 50; |
| 136 | const EMPTY_SET: ReadonlySet<string> = new Set(); |
| 137 | const EMPTY_RECORD = {} as const; |
| 138 | const EMPTY_MAP = new Map<string, string>(); |
| 139 | |
| 140 | function getShortcutContext() { |
| 141 | return { |
| 142 | terminalFocus: isTerminalFocused(), |
| 143 | terminalOpen: false, |
| 144 | previewFocus: false, |
| 145 | previewOpen: false, |
| 146 | modelPickerOpen: false, |
| 147 | isWeb: !isElectron, |
| 148 | isDesktop: isElectron, |
| 149 | }; |
| 150 | } |
| 151 | |
| 152 | function hostOptionsFor( |
| 153 | trackers: ReadonlyArray<IssueTrackerSummary>, |
| 154 | chosen: string | undefined, |
| 155 | resolve: MessageResolver, |
| 156 | ) { |
| 157 | const hosts = new Map<string, IssueTrackerSummary>(); |
| 158 | const ordered = [...trackers].sort((a, b) => |
| 159 | issueTrackerKey(a).localeCompare(issueTrackerKey(b)), |
| 160 | ); |
| 161 | for (const tracker of ordered) { |
| 162 | const existing = hosts.get(tracker.host); |
| 163 | if (existing === undefined || (!existing.configured && tracker.configured)) |
| 164 | hosts.set(tracker.host, tracker); |
| 165 | } |
| 166 | return [ |
| 167 | { value: "", label: resolve(msg("All", { $context: "issue filter" })), Icon: Plug2Icon }, |
| 168 | // A remembered host no project is on any more stays listed, so the filter can be taken off. |
| 169 | ...(chosen !== undefined && !hosts.has(chosen) |
| 170 | ? [{ value: chosen, label: chosen, Icon: Plug2Icon }] |
| 171 | : []), |
| 172 | ...[...hosts.values()].map((tracker) => ({ |
| 173 | value: tracker.host, |
| 174 | label: |
| 175 | hosts.size > 1 && issueTrackerPresentation(tracker.tracker).providerName === tracker.host |
| 176 | ? tracker.host |
| 177 | : `${issueTrackerPresentation(tracker.tracker).providerName} (${tracker.host})`, |
| 178 | Icon: issueTrackerPresentation(tracker.tracker).Icon, |
| 179 | ...(tracker.configured |
| 180 | ? {} |
| 181 | : { |
| 182 | unavailable: |
| 183 | tracker.detail === null |
| 184 | ? resolve(msg("Unavailable")) |
| 185 | : issueTrackerDetailText(tracker.detail, resolve), |
| 186 | }), |
| 187 | })), |
| 188 | ]; |
| 189 | } |
| 190 | |
| 191 | export function IssuesPage() { |
| 192 | const gt = useGT(); |
| 193 | const resolve = useMessages(); |
| 194 | const navigate = useNavigate({ from: "/issues" }); |
| 195 | const search = useSearch({ from: "/_chat/issues" }); |
| 196 | const { environments } = useEnvironments(); |
| 197 | const projects = useProjects(); |
| 198 | const issuesSupported = useIssuesSupported(); |
| 199 | const keybindings = useAtomValue(primaryServerKeybindingsAtom); |
| 200 | |
| 201 | const capableEnvironments = environments.filter( |
| 202 | (environment) => environment.serverConfig?.environment.capabilities.issues === true, |
| 203 | ); |
| 204 | const environmentLabels = new Map(environments.map((e) => [e.environmentId, e.label] as const)); |
| 205 | const filterProjects = issueFilterProjects( |
| 206 | projects.filter((project) => |
| 207 | capableEnvironments.some((e) => e.environmentId === project.environmentId), |
| 208 | ), |
| 209 | environmentLabels, |
| 210 | ); |
| 211 | const hiddenProjects = issueProjectKeys(search.hideProjects); |
| 212 | |
| 213 | const debouncedQuery = useDebouncedValue(search.q ?? "", 300); |
| 214 | const listInput: IssueListInput = { |
| 215 | state: search.status, |
| 216 | involvement: search.who, |
| 217 | limit: PAGE_SIZE, |
| 218 | ...(search.host ? { host: search.host } : {}), |
| 219 | ...(debouncedQuery ? { query: debouncedQuery } : {}), |
| 220 | ...(search.label?.length ? { labels: search.label } : {}), |
| 221 | ...(search.assignee ? { assignee: search.assignee } : {}), |
| 222 | ...(search.order ? { sort: search.order } : {}), |
| 223 | }; |
| 224 | const everyProjectHidden = |
| 225 | filterProjects.length > 0 && |
| 226 | filterProjects.every((project) => hiddenProjects.has(pullRequestProjectKey(project))); |
| 227 | const targets = everyProjectHidden |
| 228 | ? [] |
| 229 | : issueListTargets( |
| 230 | capableEnvironments.map((e) => e.environmentId), |
| 231 | filterProjects, |
| 232 | search.hideProjects, |
| 233 | listInput, |
| 234 | ); |
| 235 | const list = useIssueList(targets); |
| 236 | // Refreshing a list still loading would cancel it and start over, losing the scopes already read. |
| 237 | useLiveRefresh( |
| 238 | () => { |
| 239 | if (!list.isPending) list.reload(); |
| 240 | }, |
| 241 | { key: JSON.stringify(targets) }, |
| 242 | ); |
| 243 | |
| 244 | const [pages, setPages] = useState<ReadonlyMap<EnvironmentId, HeldIssuePage>>(new Map()); |
| 245 | const held = holdIssuePages(list.answers, pages); |
| 246 | const loadPage = useAtomCommand(issueEnvironment.listPage, { reportFailure: false }); |
| 247 | const [loadingMore, setLoadingMore] = useState<string | null>(null); |
| 248 | // One tracker group's button carries on that tracker's scopes only. |
| 249 | const loadMore = async (environmentId: EnvironmentId, host: string) => { |
| 250 | const page = held.get(environmentId); |
| 251 | const cursors = page ? issueCursorsForHost(page.nextCursors, host) : {}; |
| 252 | if (!page || Object.keys(cursors).length === 0 || loadingMore !== null) return; |
| 253 | setLoadingMore(`${environmentId} ${host}`); |
| 254 | const input = targets.find((target) => target.environmentId === environmentId)?.input; |
| 255 | if (!input) return; |
| 256 | const result = await loadPage({ environmentId, input: { ...input, cursors } }); |
| 257 | setLoadingMore(null); |
| 258 | const failure = result._tag === "Failure" ? squashAtomCommandFailure(result) : null; |
| 259 | setPages((current) => { |
| 260 | const next = new Map(current); |
| 261 | next.set( |
| 262 | environmentId, |
| 263 | continueIssuePage( |
| 264 | page, |
| 265 | result._tag === "Failure" |
| 266 | ? { |
| 267 | failure: |
| 268 | failure instanceof Error ? failure.message : m(msg("The next page failed.")), |
| 269 | } |
| 270 | : result.value, |
| 271 | cursors, |
| 272 | ), |
| 273 | ); |
| 274 | return next; |
| 275 | }); |
| 276 | }; |
| 277 | |
| 278 | // Rows grouped per tracker account, so a tracker that cannot be read says so where its rows |
| 279 | // would be, and each tracker's rows carry on from their own cursors. |
| 280 | // The server names every tracker so the menu can switch hosts, but reads only the chosen one. |
| 281 | const chosenHost = search.host?.toLowerCase(); |
| 282 | // A server older than `excludeProjectIds` still answers for hidden projects. |
| 283 | const shown = |
| 284 | chosenHost || hiddenProjects.size > 0 |
| 285 | ? new Map( |
| 286 | [...held].map(([environmentId, page]) => [ |
| 287 | environmentId, |
| 288 | { |
| 289 | ...page, |
| 290 | entries: page.entries.filter( |
| 291 | (entry) => |
| 292 | !hiddenProjects.has( |
| 293 | pullRequestProjectKey({ environmentId, id: entry.projectId }), |
| 294 | ), |
| 295 | ), |
| 296 | errors: page.errors.filter( |
| 297 | (error) => |
| 298 | !hiddenProjects.has( |
| 299 | pullRequestProjectKey({ environmentId, id: error.projectId }), |
| 300 | ), |
| 301 | ), |
| 302 | answer: { |
| 303 | ...page.answer, |
| 304 | scopes: page.answer.scopes?.filter( |
| 305 | (scope) => |
| 306 | !hiddenProjects.has( |
| 307 | pullRequestProjectKey({ environmentId, id: scope.projectId }), |
| 308 | ), |
| 309 | ), |
| 310 | trackers: chosenHost |
| 311 | ? page.answer.trackers.filter( |
| 312 | (tracker) => tracker.host.toLowerCase() === chosenHost, |
| 313 | ) |
| 314 | : page.answer.trackers, |
| 315 | }, |
| 316 | }, |
| 317 | ]), |
| 318 | ) |
| 319 | : held; |
| 320 | const groups = groupIssues(shown, debouncedQuery, projects, search.order ?? "updated"); |
| 321 | const filterScopes = issueFilterScopes( |
| 322 | shown, |
| 323 | projects.filter((project) => !hiddenProjects.has(pullRequestProjectKey(project))), |
| 324 | ); |
| 325 | |
| 326 | const hostOptions = hostOptionsFor( |
| 327 | [...held.values()].flatMap((page) => page.answer.trackers), |
| 328 | search.host, |
| 329 | resolve, |
| 330 | ); |
| 331 | |
| 332 | const updateSearch = (patch: { [Key in keyof IssuesSearch]?: IssuesSearch[Key] | undefined }) => { |
| 333 | const merged = { ...search, ...patch }; |
| 334 | const next: IssuesSearch = { |
| 335 | who: merged.who ?? search.who, |
| 336 | status: merged.status ?? search.status, |
| 337 | ...(merged.hideProjects?.length ? { hideProjects: merged.hideProjects } : {}), |
| 338 | ...(merged.host ? { host: merged.host } : {}), |
| 339 | q: merged.q || undefined, |
| 340 | ...(merged.label?.length ? { label: merged.label } : {}), |
| 341 | ...(merged.assignee ? { assignee: merged.assignee } : {}), |
| 342 | ...(merged.order ? { order: merged.order } : {}), |
| 343 | ...(merged.selectedEnvironmentId |
| 344 | ? { selectedEnvironmentId: merged.selectedEnvironmentId } |
| 345 | : {}), |
| 346 | ...(merged.selectedProjectId ? { selectedProjectId: merged.selectedProjectId } : {}), |
| 347 | ...(merged.selectedHost ? { selectedHost: merged.selectedHost } : {}), |
| 348 | ...(merged.tracker ? { tracker: merged.tracker } : {}), |
| 349 | ...(merged.scope ? { scope: merged.scope } : {}), |
| 350 | ...(merged.key ? { key: merged.key } : {}), |
| 351 | }; |
| 352 | writeIssueListPreferences(issueListPreferences(next)); |
| 353 | void navigate({ search: next }); |
| 354 | }; |
| 355 | const clearedSelection = { |
| 356 | selectedEnvironmentId: undefined, |
| 357 | selectedProjectId: undefined, |
| 358 | selectedHost: undefined, |
| 359 | tracker: undefined, |
| 360 | scope: undefined, |
| 361 | key: undefined, |
| 362 | } as const; |
| 363 | |
| 364 | // One shared panel for the page, with a fixed sentinel ref, as the pull-request page does. |
| 365 | const rightPanelRef = capableEnvironments.length === 0 ? null : ISSUES_PANEL_REF; |
| 366 | const rightPanelState = useRightPanelStore((state) => |
| 367 | selectThreadRightPanelState(state.byThreadKey, rightPanelRef), |
| 368 | ); |
| 369 | const selectedSurface = useRightPanelStore((state) => |
| 370 | selectSelectedRightPanelSurface(state.byThreadKey, rightPanelRef), |
| 371 | ); |
| 372 | const panelSurface = |
| 373 | selectedSurface?.kind === "issue" || selectedSurface?.kind === "pull-request" |
| 374 | ? selectedSurface |
| 375 | : null; |
| 376 | const { active: panelAnimationsActive, durationMs } = usePanelAnimationSettings(); |
| 377 | const presenceValue = { activeSurface: panelSurface, surfaces: rightPanelState.surfaces }; |
| 378 | const presence = usePanelPresence( |
| 379 | rightPanelState.isOpen && panelSurface !== null, |
| 380 | presenceValue, |
| 381 | panelAnimationsActive, |
| 382 | rightPanelRef?.threadId ?? null, |
| 383 | durationMs, |
| 384 | ); |
| 385 | const renderedSurface = presence.value?.activeSurface ?? null; |
| 386 | const panelEnvironmentId = |
| 387 | (renderedSurface?.environmentId as EnvironmentId | undefined) ?? |
| 388 | capableEnvironments[0]?.environmentId ?? |
| 389 | null; |
| 390 | |
| 391 | const panelListEntry = |
| 392 | renderedSurface?.kind === "issue" |
| 393 | ? (groups |
| 394 | .flatMap((group) => group.rows) |
| 395 | .find( |
| 396 | (row) => |
| 397 | row.environmentId === panelEnvironmentId && |
| 398 | issueEntryKey(row) === |
| 399 | issueEntryKey({ |
| 400 | ...renderedSurface, |
| 401 | host: renderedSurface.host ?? row.host, |
| 402 | projectId: renderedSurface.projectId as ProjectId, |
| 403 | }), |
| 404 | ) ?? null) |
| 405 | : null; |
| 406 | |
| 407 | const selectSurfaceInUrl = (surface: RightPanelSurface | null) => |
| 408 | updateSearch( |
| 409 | surface?.kind === "issue" |
| 410 | ? { |
| 411 | selectedEnvironmentId: surface.environmentId as EnvironmentId | undefined, |
| 412 | selectedProjectId: surface.projectId as ProjectId, |
| 413 | selectedHost: surface.host, |
| 414 | tracker: surface.tracker, |
| 415 | scope: surface.scope, |
| 416 | key: surface.key, |
| 417 | } |
| 418 | : clearedSelection, |
| 419 | ); |
| 420 | |
| 421 | const selectEntry = (entry: IssueRowTarget) => { |
| 422 | if (rightPanelRef === null) return; |
| 423 | useRightPanelStore.getState().openIssue(rightPanelRef, entry); |
| 424 | updateSearch({ |
| 425 | selectedEnvironmentId: entry.environmentId, |
| 426 | selectedProjectId: entry.projectId, |
| 427 | selectedHost: entry.host, |
| 428 | tracker: entry.tracker, |
| 429 | scope: entry.scope, |
| 430 | key: entry.key, |
| 431 | }); |
| 432 | }; |
| 433 | |
| 434 | // A link into the page names an issue before any row was pressed. |
| 435 | // oxlint-disable-next-line t3code/no-unreasoned-state-sync -- opens the URL-linked issue in the right panel store |
| 436 | useEffect(() => { |
| 437 | if ( |
| 438 | rightPanelRef === null || |
| 439 | !search.tracker || |
| 440 | !search.scope || |
| 441 | !search.key || |
| 442 | !search.selectedProjectId |
| 443 | ) |
| 444 | return; |
| 445 | useRightPanelStore.getState().openIssue(rightPanelRef, { |
| 446 | ...(search.selectedEnvironmentId === undefined |
| 447 | ? {} |
| 448 | : { environmentId: search.selectedEnvironmentId }), |
| 449 | projectId: search.selectedProjectId, |
| 450 | ...(search.selectedHost === undefined ? {} : { host: search.selectedHost }), |
| 451 | tracker: search.tracker, |
| 452 | scope: search.scope, |
| 453 | key: search.key, |
| 454 | }); |
| 455 | }, [ |
| 456 | rightPanelRef, |
| 457 | search.tracker, |
| 458 | search.scope, |
| 459 | search.key, |
| 460 | search.selectedProjectId, |
| 461 | search.selectedHost, |
| 462 | search.selectedEnvironmentId, |
| 463 | ]); |
| 464 | |
| 465 | const closeSurface = (surface: RightPanelSurface) => { |
| 466 | if (rightPanelRef === null) return; |
| 467 | useRightPanelStore.getState().closeSurface(rightPanelRef, surface.id); |
| 468 | selectSurfaceInUrl( |
| 469 | selectActiveRightPanelSurface(useRightPanelStore.getState().byThreadKey, rightPanelRef), |
| 470 | ); |
| 471 | }; |
| 472 | const toggleRightPanel = () => { |
| 473 | if (rightPanelRef === null) return; |
| 474 | if (rightPanelState.isOpen) { |
| 475 | useRightPanelStore.getState().close(rightPanelRef); |
| 476 | updateSearch(clearedSelection); |
| 477 | return; |
| 478 | } |
| 479 | if (panelSurface === null) return; |
| 480 | useRightPanelStore.getState().show(rightPanelRef); |
| 481 | selectSurfaceInUrl(panelSurface); |
| 482 | }; |
| 483 | |
| 484 | const onRightPanelKeyDown = useEffectEvent((event: KeyboardEvent) => { |
| 485 | if (event.defaultPrevented || isCommandPaletteOpen() || panelSurface === null) return; |
| 486 | const command = resolveShortcutCommand(event, keybindings, { |
| 487 | context: { ...getShortcutContext(), rightPanelOpen: rightPanelState.isOpen }, |
| 488 | }); |
| 489 | if (command !== "rightPanel.toggle") return; |
| 490 | event.preventDefault(); |
| 491 | event.stopPropagation(); |
| 492 | if (!event.repeat) toggleRightPanel(); |
| 493 | }); |
| 494 | |
| 495 | // oxlint-disable-next-line t3code/no-unreasoned-state-sync -- subscribes to the document right panel shortcut |
| 496 | useEffect(() => { |
| 497 | document.addEventListener("keydown", onRightPanelKeyDown); |
| 498 | return () => document.removeEventListener("keydown", onRightPanelKeyDown); |
| 499 | }, []); |
| 500 | |
| 501 | // Every writable scope the workspace has, for the composer. |
| 502 | |
| 503 | const showTracker = groups.length > 1; |
| 504 | const noneAnswered = list.answers.length === 0; |
| 505 | |
| 506 | const listBody: ReactNode = !issuesSupported ? ( |
| 507 | <PullRequestsUnavailableState |
| 508 | title={gt("Issues unavailable")} |
| 509 | error={gt("Update this environment's T3 Code server to browse issues.")} |
| 510 | /> |
| 511 | ) : noneAnswered && list.isPending ? ( |
| 512 | <PullRequestListGhost /> |
| 513 | ) : noneAnswered && list.error ? ( |
| 514 | <PullRequestsUnavailableState |
| 515 | error={list.error} |
| 516 | onRetry={list.retry} |
| 517 | refreshing={list.isPending} |
| 518 | /> |
| 519 | ) : everyProjectHidden ? ( |
| 520 | <Empty> |
| 521 | <EmptyMedia variant="icon"> |
| 522 | <IssueGlyph.issue /> |
| 523 | </EmptyMedia> |
| 524 | <EmptyHeader> |
| 525 | <EmptyTitle> |
| 526 | <T>Every project is hidden</T> |
| 527 | </EmptyTitle> |
| 528 | </EmptyHeader> |
| 529 | <EmptyContent> |
| 530 | <Button variant="outline" onClick={() => updateSearch({ hideProjects: undefined })}> |
| 531 | <T>Show all projects</T> |
| 532 | </Button> |
| 533 | </EmptyContent> |
| 534 | </Empty> |
| 535 | ) : groups.length === 0 ? ( |
| 536 | <Empty> |
| 537 | <EmptyMedia variant="icon"> |
| 538 | <IssueGlyph.issue /> |
| 539 | </EmptyMedia> |
| 540 | <EmptyHeader> |
| 541 | <EmptyTitle> |
| 542 | <T>No trackers to read</T> |
| 543 | </EmptyTitle> |
| 544 | <EmptyDescription> |
| 545 | <T>Add a project whose remote is on a supported tracker.</T> |
| 546 | </EmptyDescription> |
| 547 | </EmptyHeader> |
| 548 | </Empty> |
| 549 | ) : ( |
| 550 | <div className="flex flex-col gap-6"> |
| 551 | {list.error ? ( |
| 552 | <div className="flex items-center justify-between gap-3 rounded-lg border border-warning/30 bg-warning-surface px-3 py-2 text-xs"> |
| 553 | <span> |
| 554 | <T> |
| 555 | <Var>{list.error}</Var> Showing the issues that loaded. |
| 556 | </T> |
| 557 | </span> |
| 558 | <Button size="xs" variant="outline" onClick={list.retry}> |
| 559 | <T>Retry</T> |
| 560 | </Button> |
| 561 | </div> |
| 562 | ) : null} |
| 563 | {groups.map((group) => { |
| 564 | const presentation = issueTrackerPresentation(group.tracker.tracker); |
| 565 | const showScope = new Set(group.rows.map((row) => row.scope.toLowerCase())).size > 1; |
| 566 | return ( |
| 567 | <section key={issueTrackerKey(group.tracker)} className="flex flex-col gap-1"> |
| 568 | <h2 className="flex items-center gap-1.5 px-3 text-xs font-medium text-muted-foreground"> |
| 569 | <presentation.Icon aria-hidden className="size-3.5" /> |
| 570 | {presentation.providerName} |
| 571 | {presentation.providerName.toLowerCase() !== group.tracker.host ? ( |
| 572 | <span className="font-normal">· {group.tracker.host}</span> |
| 573 | ) : null} |
| 574 | <span className="font-normal"> |
| 575 | ·{" "} |
| 576 | {gt("{count, plural, one {{count} project} other {{count} projects}}", { |
| 577 | count: group.tracker.projectCount, |
| 578 | })} |
| 579 | </span> |
| 580 | </h2> |
| 581 | {!group.tracker.configured ? ( |
| 582 | <p className="px-3 text-sm text-muted-foreground"> |
| 583 | {group.tracker.detail === null |
| 584 | ? gt("This tracker cannot be read right now.") |
| 585 | : issueTrackerDetailText(group.tracker.detail, resolve)} |
| 586 | </p> |
| 587 | ) : null} |
| 588 | {group.errors.map((error) => ( |
| 589 | <p |
| 590 | key={`${error.environmentId}:${error.projectTitle}`} |
| 591 | className="px-3 text-xs text-destructive" |
| 592 | > |
| 593 | {error.projectTitle}: {error.message} |
| 594 | </p> |
| 595 | ))} |
| 596 | {group.tracker.configured && group.rows.length === 0 && group.errors.length === 0 ? ( |
| 597 | <p className="px-3 text-sm text-muted-foreground"> |
| 598 | {debouncedQuery ? ( |
| 599 | <T>Nothing matches that.</T> |
| 600 | ) : ( |
| 601 | <T>No issues under these filters.</T> |
| 602 | )} |
| 603 | </p> |
| 604 | ) : null} |
| 605 | {group.rows.map((row) => { |
| 606 | const key = issueEntryKey(row); |
| 607 | const selected = |
| 608 | renderedSurface?.kind === "issue" && |
| 609 | renderedSurface.environmentId === row.environmentId && |
| 610 | issueEntryKey({ |
| 611 | ...renderedSurface, |
| 612 | host: renderedSurface.host ?? "", |
| 613 | projectId: renderedSurface.projectId as ProjectId, |
| 614 | }) === key; |
| 615 | return ( |
| 616 | <IssueRow |
| 617 | key={`${row.environmentId}:${key}`} |
| 618 | entry={row} |
| 619 | selected={selected} |
| 620 | showScope={showScope} |
| 621 | showTracker={showTracker} |
| 622 | {...(capableEnvironments.length > 1 && environmentLabels.has(row.environmentId) |
| 623 | ? { environmentLabel: environmentLabels.get(row.environmentId) } |
| 624 | : {})} |
| 625 | onSelect={selectEntry} |
| 626 | /> |
| 627 | ); |
| 628 | })} |
| 629 | {group.more.map((environmentId) => { |
| 630 | const moreFailure = held.get(environmentId)?.moreFailure ?? null; |
| 631 | return ( |
| 632 | <Fragment key={environmentId}> |
| 633 | {moreFailure === null ? null : ( |
| 634 | <p className="px-3 text-xs text-destructive">{moreFailure}</p> |
| 635 | )} |
| 636 | <Button |
| 637 | size="sm" |
| 638 | variant="ghost-muted" |
| 639 | className="self-start" |
| 640 | disabled={loadingMore !== null} |
| 641 | onClick={() => void loadMore(environmentId, group.tracker.host)} |
| 642 | > |
| 643 | {loadingMore === `${environmentId} ${group.tracker.host}` ? ( |
| 644 | <T>Loading…</T> |
| 645 | ) : moreFailure === null ? ( |
| 646 | <T>Load more</T> |
| 647 | ) : ( |
| 648 | <T>Retry</T> |
| 649 | )} |
| 650 | </Button> |
| 651 | </Fragment> |
| 652 | ); |
| 653 | })} |
| 654 | </section> |
| 655 | ); |
| 656 | })} |
| 657 | </div> |
| 658 | ); |
| 659 | |
| 660 | return ( |
| 661 | <SidebarInset className="h-dvh min-h-0 overflow-hidden overscroll-y-none"> |
| 662 | <div className="relative flex min-h-0 flex-1"> |
| 663 | <div className="@container/issue-list flex min-h-0 min-w-0 flex-1 flex-col overflow-x-hidden bg-background"> |
| 664 | <WorkspacePageHeader |
| 665 | electron={isElectron} |
| 666 | reserveNativeControls={!rightPanelState.isOpen} |
| 667 | className="relative bg-background" |
| 668 | > |
| 669 | <WorkspaceBreadcrumb ariaLabel={gt("Issues breadcrumb")}> |
| 670 | <WorkspaceBreadcrumbItem current> |
| 671 | <h1 className="truncate"> |
| 672 | <T context="page title, list of issues">Issues</T> |
| 673 | </h1> |
| 674 | </WorkspaceBreadcrumbItem> |
| 675 | </WorkspaceBreadcrumb> |
| 676 | <div className="min-w-0 flex-1" /> |
| 677 | <div |
| 678 | className="flex items-center gap-1 [-webkit-app-region:no-drag]" |
| 679 | data-workspace-titlebar-controls |
| 680 | > |
| 681 | <PanelLayoutControls |
| 682 | showTerminalControl={false} |
| 683 | showThreadPanelControl={false} |
| 684 | terminalAvailable={false} |
| 685 | terminalOpen={false} |
| 686 | terminalShortcutLabel={null} |
| 687 | threadPanelOpen={false} |
| 688 | threadPanelPresentation="inline" |
| 689 | threadPanelShortcutLabel={null} |
| 690 | onToggleThreadPanel={() => undefined} |
| 691 | rightPanelAvailable={panelSurface !== null} |
| 692 | rightPanelOpen={rightPanelState.isOpen} |
| 693 | rightPanelShortcutLabel={shortcutLabelForCommand(keybindings, "rightPanel.toggle")} |
| 694 | rightPanelUnavailableLabel={gt("Select an issue first")} |
| 695 | onToggleTerminal={() => undefined} |
| 696 | onToggleRightPanel={toggleRightPanel} |
| 697 | /> |
| 698 | </div> |
| 699 | </WorkspacePageHeader> |
| 700 | |
| 701 | <div className="topbar-scroll-fade scrollbar-gutter-both min-h-0 flex-1 overflow-y-auto"> |
| 702 | <WorkspacePageContainer width="expanded" className="min-h-full gap-4"> |
| 703 | <div className="flex flex-wrap items-center gap-2"> |
| 704 | <div className="min-w-0 basis-full @lg/issue-list:min-w-48 @lg/issue-list:basis-0 @lg/issue-list:flex-1"> |
| 705 | <PullRequestSearchInput |
| 706 | value={search.q ?? ""} |
| 707 | label={gt("Search issues")} |
| 708 | placeholder={gt("Search issues")} |
| 709 | busy={ |
| 710 | (search.q ?? "") !== debouncedQuery || |
| 711 | (debouncedQuery.length > 0 && list.isPending) |
| 712 | } |
| 713 | onChange={(q) => updateSearch({ q: q || undefined })} |
| 714 | onSubmit={(q) => updateSearch({ q: q || undefined })} |
| 715 | /> |
| 716 | </div> |
| 717 | <PullRequestCompactFilterMenu |
| 718 | label={gt("Sort issues")} |
| 719 | triggerIcon={<ArrowDownUpIcon aria-hidden className="size-4" />} |
| 720 | triggerLabel={gt("Sort", { $context: "verb, button that sorts a list" })} |
| 721 | outlined |
| 722 | value={search.order ?? "updated"} |
| 723 | options={resolveFilterOptions(SORT_OPTIONS, resolve)} |
| 724 | onChange={(order) => |
| 725 | updateSearch({ order: order === "created" ? "created" : undefined }) |
| 726 | } |
| 727 | /> |
| 728 | <IssueFiltersMenu |
| 729 | state={search.status} |
| 730 | stateOptions={resolveFilterOptions(STATE_TABS, resolve)} |
| 731 | onState={(status) => updateSearch({ status })} |
| 732 | involvement={search.who} |
| 733 | involvementOptions={resolveFilterOptions(INVOLVEMENT_TABS, resolve)} |
| 734 | onInvolvement={(who) => updateSearch({ who })} |
| 735 | scopes={filterScopes} |
| 736 | labels={search.label ?? []} |
| 737 | onLabels={(label) => updateSearch({ label })} |
| 738 | assignee={search.assignee} |
| 739 | onAssignee={(assignee) => updateSearch({ assignee })} |
| 740 | projects={filterProjects} |
| 741 | hiddenProjects={hiddenProjects} |
| 742 | onHiddenProjects={(hideProjects) => updateSearch({ hideProjects })} |
| 743 | /> |
| 744 | <SavedViewsMenu |
| 745 | kind={ISSUE_SAVED_VIEWS} |
| 746 | preferences={search} |
| 747 | onApply={(view) => |
| 748 | // Explicit clears replace the old list scope; the selected issue stays open. |
| 749 | updateSearch({ |
| 750 | who: view.who, |
| 751 | status: view.status, |
| 752 | hideProjects: view.hideProjects, |
| 753 | host: view.host, |
| 754 | q: view.q, |
| 755 | label: view.label, |
| 756 | assignee: view.assignee, |
| 757 | order: view.order, |
| 758 | }) |
| 759 | } |
| 760 | /> |
| 761 | {hostOptions.length > 1 ? ( |
| 762 | <FilterMenu |
| 763 | label={gt("Filter by tracker")} |
| 764 | value={search.host ?? ""} |
| 765 | options={hostOptions} |
| 766 | onChange={(host) => updateSearch({ host: host || undefined })} |
| 767 | /> |
| 768 | ) : null} |
| 769 | <Button |
| 770 | size="icon" |
| 771 | variant="outline" |
| 772 | aria-label={gt("Refresh issues")} |
| 773 | onClick={list.refresh} |
| 774 | disabled={list.isPending} |
| 775 | > |
| 776 | <RefreshIcon size="md" refreshing={list.isPending} /> |
| 777 | </Button> |
| 778 | </div> |
| 779 | {listBody} |
| 780 | </WorkspacePageContainer> |
| 781 | </div> |
| 782 | </div> |
| 783 | |
| 784 | {presence.present && |
| 785 | renderedSurface && |
| 786 | panelEnvironmentId !== null && |
| 787 | rightPanelRef !== null ? ( |
| 788 | <RightPanelTabs |
| 789 | mode="inline" |
| 790 | open={rightPanelState.isOpen} |
| 791 | keybindings={keybindings} |
| 792 | getShortcutContext={getShortcutContext} |
| 793 | widthStorageKey="t3code:issue-panel-width" |
| 794 | defaultWidth={typeof window === "undefined" ? 640 : Math.floor(window.innerWidth / 2)} |
| 795 | surfaces={presence.value?.surfaces ?? []} |
| 796 | environmentId={panelEnvironmentId} |
| 797 | activeSurfaceId={renderedSurface.id} |
| 798 | pendingSurfaceIds={EMPTY_SET} |
| 799 | previewSessions={EMPTY_RECORD} |
| 800 | desktopByTabId={EMPTY_RECORD} |
| 801 | terminalLabelsById={EMPTY_MAP} |
| 802 | onActivate={(surface) => { |
| 803 | useRightPanelStore.getState().activateSurface(rightPanelRef, surface.id); |
| 804 | selectSurfaceInUrl(surface); |
| 805 | }} |
| 806 | onCloseSurface={closeSurface} |
| 807 | onCloseOtherSurfaces={(surface) => { |
| 808 | useRightPanelStore.getState().closeOtherSurfaces(rightPanelRef, surface.id); |
| 809 | selectSurfaceInUrl(surface); |
| 810 | }} |
| 811 | onCloseSurfacesToRight={(surface) => { |
| 812 | useRightPanelStore.getState().closeSurfacesToRight(rightPanelRef, surface.id); |
| 813 | selectSurfaceInUrl( |
| 814 | selectActiveRightPanelSurface( |
| 815 | useRightPanelStore.getState().byThreadKey, |
| 816 | rightPanelRef, |
| 817 | ), |
| 818 | ); |
| 819 | }} |
| 820 | onCloseAllSurfaces={() => { |
| 821 | useRightPanelStore.getState().closeAllSurfaces(rightPanelRef); |
| 822 | selectSurfaceInUrl(null); |
| 823 | }} |
| 824 | onMoveSurface={(surfaceId, toIndex) => |
| 825 | useRightPanelStore.getState().moveSurface(rightPanelRef, surfaceId, toIndex) |
| 826 | } |
| 827 | onCopyFilePath={() => undefined} |
| 828 | onAddBrowser={() => undefined} |
| 829 | onAddBrowserInProfile={() => undefined} |
| 830 | onAddTerminal={() => undefined} |
| 831 | onAddDiff={() => undefined} |
| 832 | onAddFiles={() => undefined} |
| 833 | onAddPullRequest={() => undefined} |
| 834 | onAddPullRequests={() => undefined} |
| 835 | onAddDevice={() => undefined} |
| 836 | browserAvailable={false} |
| 837 | terminalAvailable={false} |
| 838 | diffAvailable={false} |
| 839 | filesAvailable={false} |
| 840 | pullRequestAvailable={false} |
| 841 | pullRequestsAvailable={false} |
| 842 | deviceAvailable={false} |
| 843 | > |
| 844 | {renderedSurface.kind === "issue" ? ( |
| 845 | <IssueDetailPanel |
| 846 | key={`${panelEnvironmentId}:${renderedSurface.id}`} |
| 847 | environmentId={panelEnvironmentId} |
| 848 | listEntry={panelListEntry} |
| 849 | reference={{ |
| 850 | projectId: renderedSurface.projectId as ProjectId, |
| 851 | tracker: renderedSurface.tracker as IssueTrackerKind, |
| 852 | ...(renderedSurface.host ? { host: renderedSurface.host } : {}), |
| 853 | scope: renderedSurface.scope, |
| 854 | key: renderedSurface.key, |
| 855 | }} |
| 856 | onSelectPullRequest={(reference) => { |
| 857 | useRightPanelStore.getState().openPullRequest(rightPanelRef, { |
| 858 | projectId: reference.projectId, |
| 859 | repository: reference.repository, |
| 860 | number: reference.number, |
| 861 | ...(reference.host === undefined ? {} : { host: reference.host }), |
| 862 | environmentId: panelEnvironmentId, |
| 863 | }); |
| 864 | }} |
| 865 | /> |
| 866 | ) : ( |
| 867 | <PullRequestDetailPanel |
| 868 | key={renderedSurface.id} |
| 869 | getShortcutContext={getShortcutContext} |
| 870 | shortcutsEnabled={panelSurface?.id === renderedSurface.id} |
| 871 | environmentId={panelEnvironmentId} |
| 872 | reference={{ |
| 873 | projectId: (renderedSurface as PullRequestSurface).projectId as ProjectId, |
| 874 | repository: (renderedSurface as PullRequestSurface).repository, |
| 875 | number: (renderedSurface as PullRequestSurface).number, |
| 876 | ...((renderedSurface as PullRequestSurface).host |
| 877 | ? { host: (renderedSurface as PullRequestSurface).host } |
| 878 | : {}), |
| 879 | }} |
| 880 | /> |
| 881 | )} |
| 882 | </RightPanelTabs> |
| 883 | ) : null} |
| 884 | </div> |
| 885 | </SidebarInset> |
| 886 | ); |
| 887 | } |
| 888 | |
| 889 | function FilterMenu<Value extends string>({ |
| 890 | label, |
| 891 | value, |
| 892 | options, |
| 893 | onChange, |
| 894 | }: { |
| 895 | label: string; |
| 896 | value: Value; |
| 897 | options: ReadonlyArray<PullRequestFilterOption<Value>>; |
| 898 | onChange: (value: Value) => void; |
| 899 | }) { |
| 900 | const current = options.find((option) => option.value === value) ?? options[0]; |
| 901 | if (!current) return null; |
| 902 | return ( |
| 903 | <Menu> |
| 904 | <MenuTrigger aria-label={`${label}: ${current.label}`} render={<Button variant="outline" />}> |
| 905 | <PullRequestFilterOptionIcon option={current} /> |
| 906 | <span className="truncate">{current.label}</span> |
| 907 | </MenuTrigger> |
| 908 | <MenuPopup align="start"> |
| 909 | <MenuRadioGroup value={value} onValueChange={(next) => onChange(next as Value)}> |
| 910 | {options.map((option) => ( |
| 911 | <MenuRadioItem |
| 912 | key={option.value} |
| 913 | value={option.value} |
| 914 | disabled={option.unavailable !== undefined} |
| 915 | > |
| 916 | <span className="flex min-w-0 items-center gap-2"> |
| 917 | <PullRequestFilterOptionIcon option={option} /> |
| 918 | <span className="min-w-0 flex-1 truncate">{option.label}</span> |
| 919 | </span> |
| 920 | </MenuRadioItem> |
| 921 | ))} |
| 922 | </MenuRadioGroup> |
| 923 | </MenuPopup> |
| 924 | </Menu> |
| 925 | ); |
| 926 | } |