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