Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
121 changes: 121 additions & 0 deletions apps/web/src/components/pullRequest/PullRequestListGroups.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
import type { EnvironmentId, PullRequestAction } from "@t3tools/contracts";
import { EyeIcon, LayersIcon, PenLineIcon, UsersIcon, type LucideIcon } from "lucide-react";
import type { RefCallback } from "react";

import { cn } from "~/lib/utils";
import { useShortcutModifierState } from "~/shortcutModifierState";
import { Separator } from "../ui/separator";
import {
pullRequestEntryKey,
scorePullRequestMatch,
type EnvironmentPullRequestEntry,
type PullRequestGroup,
} from "./pullRequestList.logic";
import { PullRequestRow, type PullRequestRowTarget } from "./PullRequestRow";
import type { PullRequestSpeedActionResult } from "./PullRequestSpeedActions";

const GROUP_ICONS: Record<string, LucideIcon> = {
authored: PenLineIcon,
reviewRequested: EyeIcon,
others: UsersIcon,
};

const MATCHED_ELSEWHERE_SCORE = 10;

function PullRequestGroupHeader({
group,
}: {
group: { key: string; label: string; entries: ReadonlyArray<unknown> };
}) {
const Icon = GROUP_ICONS[group.key] ?? LayersIcon;
return (
<div className="flex items-center gap-2 px-3 pb-1 text-xs font-medium text-muted-foreground/70">
<Icon aria-hidden className="size-3.5 shrink-0" />
<h2 className="shrink-0">{group.label}</h2>
<span className="shrink-0 tabular-nums text-muted-foreground/50">{group.entries.length}</span>
<Separator className="min-w-2 flex-1" />
</div>
);
}

/**
* The grouped rows. Holding Shift turns rows into speed actions, so the modifier subscription lives
* here: a key press re-renders the rows, not the page and its open pull request.
*/
export function PullRequestListGroups({
groups,
environmentLabels,
query,
selected,
showProvider,
statsRef,
onSelect,
hostActionsOf,
onActed,
closingKeys,
sweepingKeys,
onCloseSweepStart,
}: {
groups: ReadonlyArray<PullRequestGroup<EnvironmentPullRequestEntry>>;
/** Only when rows come from more than one server, so each says which. */
environmentLabels: ReadonlyMap<EnvironmentId, string> | null;
query: string;
selected: {
readonly environmentId: string | undefined;
readonly repository: string;
readonly host: string | undefined;
readonly number: number;
} | null;
showProvider: boolean;
statsRef: RefCallback<HTMLDivElement>;
onSelect: (entry: PullRequestRowTarget) => void;
hostActionsOf: (entry: EnvironmentPullRequestEntry) => ReadonlySet<PullRequestAction>;
onActed: (result: PullRequestSpeedActionResult) => void;
closingKeys: ReadonlySet<string>;
sweepingKeys: ReadonlySet<string>;
onCloseSweepStart: (entry: EnvironmentPullRequestEntry, event: PointerEvent) => void;
}) {
const modifiers = useShortcutModifierState(true);
const speedMode =
modifiers.shiftKey && !modifiers.metaKey && !modifiers.ctrlKey && !modifiers.altKey;
return (
<div className={cn("space-y-3", sweepingKeys.size > 0 && "**:pointer-events-none")}>
{groups.map((group) => (
<div key={group.key} className="space-y-0.5">
{group.label ? <PullRequestGroupHeader group={group} /> : null}
{group.entries.map((entry) => {
const entryKey = pullRequestEntryKey(entry);
const environmentLabel = environmentLabels?.get(entry.environmentId);
return (
<PullRequestRow
key={entryKey}
statsKey={entryKey}
statsRef={statsRef}
entry={entry}
showProjectTitle
showProvider={showProvider}
{...(environmentLabel !== undefined ? { environmentLabel } : {})}
matchedElsewhere={
query.length > 0 && scorePullRequestMatch(entry, query) <= MATCHED_ELSEWHERE_SCORE
}
selected={
selected?.environmentId === entry.environmentId &&
selected.repository === entry.repository &&
selected.host?.toLowerCase() === entry.host.toLowerCase() &&
selected.number === entry.number
}
onSelect={onSelect}
speedMode={speedMode}
hostActions={hostActionsOf(entry)}
onActed={onActed}
closing={closingKeys.has(entryKey)}
sweeping={sweepingKeys.has(entryKey)}
onCloseSweepStart={onCloseSweepStart}
/>
);
})}
</div>
))}
</div>
);
}
100 changes: 17 additions & 83 deletions apps/web/src/routes/_chat.pull-requests.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import {
parsePullRequestQuery,
} from "@t3tools/client-runtime/pull-request-query";
import { Spinner } from "~/components/ui/spinner";
import { useShortcutModifierState } from "~/shortcutModifierState";
import type { PullRequestSpeedActionResult } from "~/components/pullRequest/PullRequestSpeedActions";
import { usePullRequestCloseBatch } from "~/components/pullRequest/usePullRequestActions";
import { SidebarPointerSensor } from "~/components/Sidebar.pointer";
Expand All @@ -24,15 +23,7 @@ import type {
} from "@t3tools/contracts";
import { useAtomValue } from "@effect/atom-react";
import { createFileRoute, useNavigate } from "@tanstack/react-router";
import {
ArrowDownUpIcon,
EyeIcon,
LayersIcon,
PenLineIcon,
UsersIcon,
Plug2Icon,
type LucideIcon,
} from "lucide-react";
import { ArrowDownUpIcon, LayersIcon, Plug2Icon } from "lucide-react";
import { useEffect, useEffectEvent, useRef, useState, type ComponentProps } from "react";

import {
Expand All @@ -58,7 +49,6 @@ import {
resolveSelectedEnvironmentId,
withDiffStat,
writePullRequestListSnapshot,
scorePullRequestMatch,
pullRequestStatsRefreshBatches,
pullRequestStatsRequestBatches,
retainVisiblePullRequestStatsBatches,
Expand Down Expand Up @@ -104,12 +94,10 @@ import {
STATE_TABS,
} from "../components/pullRequest/pullRequestListOptions";
import { PullRequestsColumn } from "../components/pullRequest/PullRequestsColumn";
import { PullRequestListGroups } from "../components/pullRequest/PullRequestListGroups";
import { PullRequestListEmptyState } from "../components/pullRequest/PullRequestListEmptyState";
import { PullRequestListGhost } from "../components/pullRequest/PullRequestGhosts";
import {
PullRequestRow,
type PullRequestRowTarget,
} from "../components/pullRequest/PullRequestRow";
import { type PullRequestRowTarget } from "../components/pullRequest/PullRequestRow";
import { PullRequestsUnavailableState } from "../components/pullRequest/PullRequestsUnavailableState";
import { RightPanelTabs, type PullRequestTabStatusSeed } from "../components/RightPanelTabs";
import { isCommandPaletteOpen } from "../commandPaletteBus";
Expand Down Expand Up @@ -151,7 +139,6 @@ import {
} from "../state/pullRequests";
import { useAtomCommand } from "../state/use-atom-command";
import { cn } from "~/lib/utils";
import { Separator } from "~/components/ui/separator";
import { primaryServerKeybindingsAtom } from "~/state/server";
import { getSourceControlPresentationForKind } from "~/sourceControlPresentation";

Expand All @@ -178,30 +165,7 @@ export interface PullRequestsSearch extends PullRequestListPreferences {
readonly selectedEnvironmentId?: EnvironmentId;
}

const GROUP_ICONS: Record<string, LucideIcon> = {
authored: PenLineIcon,
reviewRequested: EyeIcon,
others: UsersIcon,
};

function PullRequestGroupHeader({
group,
}: {
group: { key: string; label: string; entries: ReadonlyArray<unknown> };
}) {
const Icon = GROUP_ICONS[group.key] ?? LayersIcon;
return (
<div className="flex items-center gap-2 px-3 pb-1 text-xs font-medium text-muted-foreground/70">
<Icon aria-hidden className="size-3.5 shrink-0" />
<h2 className="shrink-0">{group.label}</h2>
<span className="shrink-0 tabular-nums text-muted-foreground/50">{group.entries.length}</span>
<Separator className="min-w-2 flex-1" />
</div>
);
}

const SEARCH_DEBOUNCE_MS = 250;
const MATCHED_ELSEWHERE_SCORE = 10;
/**
* One whole page from the host and no more: every provider asks for one row beyond the page as
* its "is there more" probe, and GitHub serves a hundred per request — so asking for ninety-nine
Expand Down Expand Up @@ -292,9 +256,6 @@ export const Route = createFileRoute("/_chat/pull-requests")({

function PullRequestsRouteView() {
useEscapeToGoBack();
const modifiers = useShortcutModifierState(true);
const speedMode =
modifiers.shiftKey && !modifiers.metaKey && !modifiers.ctrlKey && !modifiers.altKey;
const search = Route.useSearch();
const sort = search.sort ?? "ready";
const statsPolicy: PullRequestStatsPolicy =
Expand Down Expand Up @@ -1302,47 +1263,20 @@ function PullRequestsRouteView() {
onLoadMore={loadMore}
/>
) : (
<div className={cn("space-y-3", closeSweepKeys.size > 0 && "**:pointer-events-none")}>
{displayGroups.map((group) => (
<div key={group.key} className="space-y-0.5">
{group.label ? <PullRequestGroupHeader group={group} /> : null}
{group.entries.map((entry) => {
const entryKey = pullRequestEntryKey(entry);
return (
<PullRequestRow
key={entryKey}
statsKey={entryKey}
statsRef={registerStatsRow}
entry={entry}
showProjectTitle
showProvider={showProvider}
{...(capableEnvironments.length > 1 &&
environmentLabels.get(entry.environmentId) !== undefined
? { environmentLabel: environmentLabels.get(entry.environmentId)! }
: {})}
matchedElsewhere={
typedParsed.text.length > 0 &&
scorePullRequestMatch(entry, typedParsed.text) <= MATCHED_ELSEWHERE_SCORE
}
selected={
selected?.environmentId === entry.environmentId &&
selected.repository === entry.repository &&
selected.host?.toLowerCase() === entry.host.toLowerCase() &&
selected.number === entry.number
}
onSelect={selectEntry}
speedMode={speedMode}
hostActions={hostActionsOf(entry)}
onActed={onSpeedAction}
closing={closingKeys.has(entryKey)}
sweeping={closeSweepKeys.has(entryKey)}
onCloseSweepStart={startCloseSweep}
/>
);
})}
</div>
))}
</div>
<PullRequestListGroups
groups={displayGroups}
environmentLabels={capableEnvironments.length > 1 ? environmentLabels : null}
query={typedParsed.text}
selected={selected}
showProvider={showProvider}
statsRef={registerStatsRow}
onSelect={selectEntry}
hostActionsOf={hostActionsOf}
onActed={onSpeedAction}
closingKeys={closingKeys}
sweepingKeys={closeSweepKeys}
onCloseSweepStart={startCloseSweep}
/>
)}

{listQuery.error && shownCount > 0 ? (
Expand Down
Loading