Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

IssuesPage.tsx

885 lines34.8 KB

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