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

IssuesPage.tsx

992 lines39.0 KB

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