feat(web): add pull request list filters (#8809)
Co-authored-by: maria-rcks <[email protected]>
This commit is contained in:
1 parent
b17cc3d1bf
commit
d35c71d1b9
7 files changed
+585
-154
No files matched your search
@@ -34,7 +34,8 @@ function findLabeledGroup(node: ReactNode, label: string): ReactNode {
|
||||
if (!isValidElement(child)) continue;
|
||||
const props = child.props as { readonly children?: ReactNode; readonly label?: string };
|
||||
if (props.label === label && typeof child.type === "function") {
|
||||
return (child.type as (properties: unknown) => ReactNode)(child.props);
|
||||
const rendered = (child.type as (properties: unknown) => ReactNode)(child.props);
|
||||
return findLabeledGroup(rendered, label) ?? rendered;
|
||||
}
|
||||
const nested = findLabeledGroup(props.children, label);
|
||||
if (nested !== undefined) return nested;
|
||||
@@ -126,7 +127,7 @@ describe("pull request filters menu", () => {
|
||||
projectEnvironmentId: environmentId,
|
||||
onProject,
|
||||
});
|
||||
const radioGroup = findValueChange(view);
|
||||
const radioGroup = findValueChange(findLabeledGroup(view, "Project"));
|
||||
expect(radioGroup).toBeDefined();
|
||||
|
||||
radioGroup?.props.onValueChange(pullRequestProjectKey({ id: projectId, environmentId }));
|
||||
@@ -156,7 +157,7 @@ describe("pull request filters menu", () => {
|
||||
],
|
||||
onProject,
|
||||
});
|
||||
const radioGroup = findValueChange(view);
|
||||
const radioGroup = findValueChange(findLabeledGroup(view, "Project"));
|
||||
expect(radioGroup).toBeDefined();
|
||||
|
||||
radioGroup?.props.onValueChange(
|
||||
|
||||
@@ -18,10 +18,11 @@ import {
|
||||
ListFilterIcon,
|
||||
LoaderIcon,
|
||||
SearchIcon,
|
||||
TagIcon,
|
||||
UserRoundIcon,
|
||||
} from "lucide-react";
|
||||
import type { ElementType } from "react";
|
||||
import { type ElementType, useState } from "react";
|
||||
|
||||
import { cn } from "~/lib/utils";
|
||||
import { getSourceControlPresentationForKind } from "~/sourceControlPresentation";
|
||||
import { ProjectFavicon } from "../ProjectFavicon";
|
||||
import { InputGroup, InputGroupAddon, InputGroupInput } from "../ui/input-group";
|
||||
@@ -29,27 +30,56 @@ import { Button } from "../ui/button";
|
||||
|
||||
import {
|
||||
Menu,
|
||||
MenuCheckboxItem,
|
||||
MenuGroupLabel,
|
||||
MenuItem,
|
||||
MenuPopup,
|
||||
MenuRadioGroup,
|
||||
MenuRadioItem,
|
||||
MenuSeparator,
|
||||
MenuSub,
|
||||
MenuSubPopup,
|
||||
MenuSubTrigger,
|
||||
MenuTrigger,
|
||||
} from "../ui/menu";
|
||||
import { Tooltip, TooltipPopup, TooltipTrigger } from "../ui/tooltip";
|
||||
import {
|
||||
pullRequestLabelColor,
|
||||
type PullRequestAuthorFacet,
|
||||
type PullRequestLabelFacet,
|
||||
} from "./pullRequestList.logic";
|
||||
import { PullRequestActorAvatar } from "./pullRequestPresentation";
|
||||
|
||||
export interface PullRequestFilterOption<Value extends string> {
|
||||
readonly value: Value;
|
||||
readonly label: string;
|
||||
/**
|
||||
* Carries the option's own tone, so an icon reads the same here as it does on a row. Left
|
||||
* uncoloured, which lets the item's selected state stay the thing the eye follows.
|
||||
*/
|
||||
/** Uses the option's native icon tone. */
|
||||
readonly Icon: ElementType<{ className?: string }>;
|
||||
readonly favicon?: {
|
||||
readonly environmentId: EnvironmentId;
|
||||
readonly cwd: string;
|
||||
};
|
||||
/** Why it cannot be chosen, carried onto the item as its title. */
|
||||
readonly unavailable?: string | undefined;
|
||||
}
|
||||
|
||||
export function PullRequestFilterOptionIcon<Value extends string>({
|
||||
option,
|
||||
}: {
|
||||
option: PullRequestFilterOption<Value>;
|
||||
}) {
|
||||
return option.favicon ? (
|
||||
<ProjectFavicon
|
||||
environmentId={option.favicon.environmentId}
|
||||
cwd={option.favicon.cwd}
|
||||
fallbackIcon={FolderGit2Icon}
|
||||
className="size-3.5"
|
||||
/>
|
||||
) : (
|
||||
<option.Icon aria-hidden className="size-3.5" />
|
||||
);
|
||||
}
|
||||
|
||||
export interface PullRequestExpectedHost {
|
||||
readonly host: string;
|
||||
readonly kind: SourceControlProviderKind;
|
||||
@@ -98,10 +128,8 @@ export function PullRequestSearchInput({
|
||||
}
|
||||
|
||||
/**
|
||||
* Every list filter lives behind the one filter icon so the control row stays two controls
|
||||
* wide: the search and this. The trigger carries a dot whenever any filter is off its
|
||||
* default, so a narrowed list is never a mystery. Same menu chrome as the detail panel's
|
||||
* actions, which also owns its own spacing.
|
||||
* List narrowings live behind one filter control, separate from sorting. The trigger carries a
|
||||
* count whenever any filter is off its default, so a narrowed list is never a mystery.
|
||||
*/
|
||||
const ALL_PROJECTS_VALUE = "all";
|
||||
/** MenuRadioGroup wants a string, so "every host" wears the one value no host can be. */
|
||||
@@ -169,8 +197,9 @@ function PullRequestFilterRadioGroup<Value extends string>({
|
||||
disabled={option.unavailable !== undefined}
|
||||
>
|
||||
<span className="flex min-w-0 items-center gap-2">
|
||||
<option.Icon aria-hidden className="size-3.5" />
|
||||
{option.label}
|
||||
<PullRequestFilterOptionIcon option={option} />
|
||||
<span className="min-w-0 flex-1 truncate">{option.label}</span>
|
||||
{option.unavailable ? <span className="shrink-0">· Unavailable</span> : null}
|
||||
</span>
|
||||
</MenuRadioItem>
|
||||
);
|
||||
@@ -188,7 +217,185 @@ function PullRequestFilterRadioGroup<Value extends string>({
|
||||
);
|
||||
}
|
||||
|
||||
function PullRequestFilterRadioSubmenu<Value extends string>({
|
||||
label,
|
||||
value,
|
||||
options,
|
||||
onChange,
|
||||
}: {
|
||||
label: string;
|
||||
value: Value;
|
||||
options: ReadonlyArray<PullRequestFilterOption<Value>>;
|
||||
onChange: (value: Value) => void;
|
||||
}) {
|
||||
const current = options.find((option) => option.value === value) ?? options[0];
|
||||
if (!current) return null;
|
||||
return (
|
||||
<MenuSub>
|
||||
<MenuSubTrigger>
|
||||
<PullRequestFilterOptionIcon option={current} />
|
||||
<span className="flex-1">{label}</span>
|
||||
<span className="min-w-0 max-w-32 truncate text-xs text-muted-foreground">
|
||||
{current.label}
|
||||
</span>
|
||||
</MenuSubTrigger>
|
||||
<MenuSubPopup className="min-w-56">
|
||||
<PullRequestFilterRadioGroup
|
||||
label={label}
|
||||
value={value}
|
||||
options={options}
|
||||
onChange={onChange}
|
||||
/>
|
||||
</MenuSubPopup>
|
||||
</MenuSub>
|
||||
);
|
||||
}
|
||||
|
||||
function PullRequestAuthorFilter({
|
||||
value,
|
||||
options,
|
||||
onChange,
|
||||
}: {
|
||||
value: string | undefined;
|
||||
options: ReadonlyArray<PullRequestAuthorFacet>;
|
||||
onChange: (author: string | undefined) => void;
|
||||
}) {
|
||||
const [query, setQuery] = useState("");
|
||||
const needle = query.trim().toLowerCase();
|
||||
const login = value?.toLowerCase() ?? "";
|
||||
const selected = options.find((option) => option.actor.login.toLowerCase() === login);
|
||||
const visible = [
|
||||
...(selected ? [selected] : []),
|
||||
...options.filter(
|
||||
(option) =>
|
||||
option !== selected &&
|
||||
(needle.length === 0 ||
|
||||
option.actor.login.toLowerCase().includes(needle) ||
|
||||
option.actor.name?.toLowerCase().includes(needle)),
|
||||
),
|
||||
].slice(0, 10);
|
||||
const select = (next: string) => next.toLowerCase() !== login && onChange(next || undefined);
|
||||
return (
|
||||
<MenuSub>
|
||||
<MenuSubTrigger>
|
||||
<UserRoundIcon aria-hidden className="size-3.5" />
|
||||
<span className="flex-1">Author</span>
|
||||
<span className="min-w-0 max-w-32 truncate text-xs text-muted-foreground">
|
||||
{value ?? "Anyone"}
|
||||
</span>
|
||||
</MenuSubTrigger>
|
||||
<MenuSubPopup className="w-80">
|
||||
<div className="p-1 pb-2">
|
||||
<InputGroup>
|
||||
<InputGroupAddon>
|
||||
<SearchIcon aria-hidden />
|
||||
</InputGroupAddon>
|
||||
<InputGroupInput
|
||||
autoFocus
|
||||
size="compact"
|
||||
value={query}
|
||||
onChange={(event) => setQuery(event.currentTarget.value)}
|
||||
onKeyDown={(event) => {
|
||||
if (event.key !== "ArrowDown" && event.key !== "Escape") event.stopPropagation();
|
||||
}}
|
||||
placeholder="Search authors"
|
||||
aria-label="Search authors"
|
||||
/>
|
||||
</InputGroup>
|
||||
</div>
|
||||
<MenuRadioGroup value={selected?.actor.login ?? value ?? ""} onValueChange={select}>
|
||||
<MenuRadioItem value="">
|
||||
<span className="flex min-w-0 items-center gap-2">
|
||||
<LayersIcon aria-hidden className="size-3.5" />
|
||||
Anyone
|
||||
</span>
|
||||
</MenuRadioItem>
|
||||
{visible.map((option) => (
|
||||
<MenuRadioItem key={option.actor.login.toLowerCase()} value={option.actor.login}>
|
||||
<span className="flex min-w-0 items-center gap-2">
|
||||
<PullRequestActorAvatar actor={option.actor} />
|
||||
<span className="min-w-0 flex-1 truncate">{option.actor.login}</span>
|
||||
<span className="shrink-0 text-xs text-muted-foreground tabular-nums">
|
||||
{option.mergedCount} merges loaded
|
||||
</span>
|
||||
</span>
|
||||
</MenuRadioItem>
|
||||
))}
|
||||
{visible.length === 0 ? <MenuItem disabled>No authors found</MenuItem> : null}
|
||||
</MenuRadioGroup>
|
||||
</MenuSubPopup>
|
||||
</MenuSub>
|
||||
);
|
||||
}
|
||||
|
||||
function PullRequestLabelFilter({
|
||||
value,
|
||||
options,
|
||||
onChange,
|
||||
}: {
|
||||
value: ReadonlyArray<string>;
|
||||
options: ReadonlyArray<PullRequestLabelFacet>;
|
||||
onChange: (labels: ReadonlyArray<string>) => void;
|
||||
}) {
|
||||
const selected = new Set(value.map((name) => name.toLowerCase()));
|
||||
const visible = [
|
||||
...value
|
||||
.filter((name) => !options.some((option) => option.name.toLowerCase() === name.toLowerCase()))
|
||||
.map((name) => ({ name, color: null, count: 0 })),
|
||||
...options,
|
||||
];
|
||||
return (
|
||||
<MenuSub>
|
||||
<MenuSubTrigger>
|
||||
<TagIcon aria-hidden className="size-3.5" />
|
||||
<span className="flex-1">Labels</span>
|
||||
<span className="text-xs text-muted-foreground">
|
||||
{value.length === 0 ? "Any" : `${value.length} selected`}
|
||||
</span>
|
||||
</MenuSubTrigger>
|
||||
<MenuSubPopup className="w-72">
|
||||
{visible.length === 0 ? (
|
||||
<MenuItem disabled>No labels in this view</MenuItem>
|
||||
) : (
|
||||
visible.map((option) => {
|
||||
const key = option.name.toLowerCase();
|
||||
const checked = selected.has(key);
|
||||
const dot = pullRequestLabelColor(option.color);
|
||||
return (
|
||||
<MenuCheckboxItem
|
||||
key={key}
|
||||
className="grid-cols-[1rem_minmax(0,1fr)]"
|
||||
checked={checked}
|
||||
onCheckedChange={(next) =>
|
||||
onChange(
|
||||
next
|
||||
? [...value, option.name]
|
||||
: value.filter((name) => name.toLowerCase() !== option.name.toLowerCase()),
|
||||
)
|
||||
}
|
||||
>
|
||||
<span className="flex min-w-0 items-center gap-2">
|
||||
<span
|
||||
aria-hidden
|
||||
className="size-2.5 shrink-0 rounded-full bg-muted-foreground"
|
||||
{...(dot ? { style: { backgroundColor: dot } } : {})}
|
||||
/>
|
||||
<span className="min-w-0 flex-1 truncate">{option.name}</span>
|
||||
<span className="shrink-0 text-xs text-muted-foreground tabular-nums">
|
||||
{option.count}
|
||||
</span>
|
||||
</span>
|
||||
</MenuCheckboxItem>
|
||||
);
|
||||
})
|
||||
)}
|
||||
</MenuSubPopup>
|
||||
</MenuSub>
|
||||
);
|
||||
}
|
||||
|
||||
export function PullRequestFiltersMenu({
|
||||
onOpenChange,
|
||||
state,
|
||||
stateOptions,
|
||||
onState,
|
||||
@@ -197,6 +404,8 @@ export function PullRequestFiltersMenu({
|
||||
onInvolvement,
|
||||
filters,
|
||||
onFilters,
|
||||
authorOptions = [],
|
||||
labelOptions = [],
|
||||
host,
|
||||
hostOptions,
|
||||
onHost,
|
||||
@@ -209,6 +418,7 @@ export function PullRequestFiltersMenu({
|
||||
unavailable,
|
||||
onProject,
|
||||
}: {
|
||||
onOpenChange?: (open: boolean) => void;
|
||||
state: PullRequestListState;
|
||||
stateOptions: ReadonlyArray<PullRequestFilterOption<PullRequestListState>>;
|
||||
onState: (state: PullRequestListState) => void;
|
||||
@@ -218,6 +428,8 @@ export function PullRequestFiltersMenu({
|
||||
/** The narrowings beyond state and involvement; an absent field is that group unfiltered. */
|
||||
filters: PullRequestListFilters;
|
||||
onFilters: (filters: PullRequestListFilters) => void;
|
||||
authorOptions?: ReadonlyArray<PullRequestAuthorFacet>;
|
||||
labelOptions?: ReadonlyArray<PullRequestLabelFacet>;
|
||||
host: string | undefined;
|
||||
/**
|
||||
* Includes the "all hosts" entry, whose value is the empty string. With fewer than two real
|
||||
@@ -254,82 +466,119 @@ export function PullRequestFiltersMenu({
|
||||
/** The environment comes with the project id, since picking a row picks a specific server's copy of it. */
|
||||
onProject: (projectId: ProjectId | undefined, environmentId: EnvironmentId | undefined) => void;
|
||||
}) {
|
||||
const filtered =
|
||||
state !== "open" ||
|
||||
involvement !== "all" ||
|
||||
host !== undefined ||
|
||||
server !== undefined ||
|
||||
projectId !== undefined ||
|
||||
Object.keys(filters).length > 0;
|
||||
/**
|
||||
* Rebuilt rather than spread so an unfiltered group leaves the record instead of lingering in
|
||||
* it as an explicit `undefined`, which the listing input does not accept.
|
||||
*/
|
||||
const withFilter = (key: keyof PullRequestListFilters, value: string): PullRequestListFilters =>
|
||||
Object.fromEntries(
|
||||
Object.entries({ ...filters, [key]: value === UNFILTERED_VALUE ? undefined : value }).filter(
|
||||
([, held]) => held !== undefined,
|
||||
),
|
||||
) as PullRequestListFilters;
|
||||
const selectedLabels = (filters.labels ?? []).flatMap((group) => group);
|
||||
const filterCount = [
|
||||
state !== "open",
|
||||
involvement !== "all",
|
||||
host,
|
||||
server,
|
||||
projectId,
|
||||
filters.draft,
|
||||
filters.review,
|
||||
filters.checks,
|
||||
filters.author,
|
||||
...selectedLabels,
|
||||
].filter(Boolean).length;
|
||||
const updateFilters = (next: Partial<PullRequestListFilters>) =>
|
||||
onFilters(
|
||||
Object.fromEntries(
|
||||
Object.entries({ ...filters, ...next }).filter(([, value]) => value !== undefined),
|
||||
) as PullRequestListFilters,
|
||||
);
|
||||
const updateFilter = (key: keyof PullRequestListFilters, value: string) =>
|
||||
updateFilters({
|
||||
[key]: value === UNFILTERED_VALUE ? undefined : value,
|
||||
} as Partial<PullRequestListFilters>);
|
||||
const projectValue =
|
||||
projectId === undefined || projectEnvironmentId === undefined
|
||||
? ALL_PROJECTS_VALUE
|
||||
: pullRequestProjectKey({ id: projectId, environmentId: projectEnvironmentId });
|
||||
const projectOptions: ReadonlyArray<PullRequestFilterOption<string>> = [
|
||||
{ value: ALL_PROJECTS_VALUE, label: "All projects", Icon: LayersIcon },
|
||||
...projects
|
||||
.toSorted(
|
||||
(left, right) =>
|
||||
Number(unavailable.has(pullRequestProjectKey(left))) -
|
||||
Number(unavailable.has(pullRequestProjectKey(right))),
|
||||
)
|
||||
.map((project) => ({
|
||||
value: pullRequestProjectKey(project),
|
||||
label: project.title,
|
||||
Icon: FolderGit2Icon,
|
||||
favicon: { environmentId: project.environmentId, cwd: project.workspaceRoot },
|
||||
...(unavailable.has(pullRequestProjectKey(project))
|
||||
? { unavailable: unavailable.get(pullRequestProjectKey(project)) }
|
||||
: {}),
|
||||
})),
|
||||
];
|
||||
return (
|
||||
<Menu>
|
||||
<Menu onOpenChange={onOpenChange}>
|
||||
<MenuTrigger
|
||||
render={
|
||||
<Button
|
||||
className={cn("relative", filtered && "[--control-icon-color:currentColor]")}
|
||||
size="icon"
|
||||
className={filterCount > 0 ? "[--control-icon-color:currentColor]" : undefined}
|
||||
variant="outline"
|
||||
aria-label="Filter pull requests"
|
||||
/>
|
||||
}
|
||||
>
|
||||
<ListFilterIcon className="size-4" />
|
||||
{filtered ? (
|
||||
<span
|
||||
aria-hidden
|
||||
className="absolute top-0.5 right-0.5 size-1.5 rounded-full bg-primary"
|
||||
/>
|
||||
<span>Filters</span>
|
||||
{filterCount > 0 ? (
|
||||
<span className="rounded-full bg-primary/10 px-1.5 text-xs text-primary tabular-nums">
|
||||
{filterCount}
|
||||
</span>
|
||||
) : null}
|
||||
</MenuTrigger>
|
||||
<MenuPopup align="end" side="bottom" className="min-w-56">
|
||||
<PullRequestFilterRadioGroup
|
||||
<MenuPopup align="end" side="bottom" className="w-56">
|
||||
<PullRequestFilterRadioSubmenu
|
||||
label="State"
|
||||
value={state}
|
||||
options={stateOptions}
|
||||
onChange={onState}
|
||||
/>
|
||||
<MenuSeparator />
|
||||
<PullRequestFilterRadioGroup
|
||||
<PullRequestFilterRadioSubmenu
|
||||
label="Involvement"
|
||||
value={involvement}
|
||||
options={involvementOptions}
|
||||
onChange={onInvolvement}
|
||||
/>
|
||||
<MenuSeparator />
|
||||
<PullRequestFilterRadioGroup
|
||||
<PullRequestAuthorFilter
|
||||
value={filters.author}
|
||||
options={authorOptions}
|
||||
onChange={(author) => updateFilters({ author })}
|
||||
/>
|
||||
<PullRequestLabelFilter
|
||||
value={selectedLabels}
|
||||
options={labelOptions}
|
||||
onChange={(labels) =>
|
||||
updateFilters({
|
||||
labels: labels.length === 0 ? undefined : labels.slice(0, 10).map((label) => [label]),
|
||||
})
|
||||
}
|
||||
/>
|
||||
<PullRequestFilterRadioSubmenu
|
||||
label="Draft"
|
||||
value={filters.draft ?? UNFILTERED_VALUE}
|
||||
options={DRAFT_OPTIONS}
|
||||
onChange={(next) => onFilters(withFilter("draft", next))}
|
||||
onChange={(draft) => updateFilter("draft", draft)}
|
||||
/>
|
||||
<MenuSeparator />
|
||||
<PullRequestFilterRadioGroup
|
||||
<PullRequestFilterRadioSubmenu
|
||||
label="Review"
|
||||
value={filters.review ?? UNFILTERED_VALUE}
|
||||
options={REVIEW_OPTIONS}
|
||||
onChange={(next) => onFilters(withFilter("review", next))}
|
||||
onChange={(review) => updateFilter("review", review)}
|
||||
/>
|
||||
<MenuSeparator />
|
||||
<PullRequestFilterRadioGroup
|
||||
<PullRequestFilterRadioSubmenu
|
||||
label="Checks"
|
||||
value={filters.checks ?? UNFILTERED_VALUE}
|
||||
options={CHECKS_OPTIONS}
|
||||
onChange={(next) => onFilters(withFilter("checks", next))}
|
||||
onChange={(checks) => updateFilter("checks", checks)}
|
||||
/>
|
||||
{hostOptions.length > 2 ? (
|
||||
<>
|
||||
<MenuSeparator />
|
||||
<PullRequestFilterRadioGroup
|
||||
<PullRequestFilterRadioSubmenu
|
||||
label="Host"
|
||||
value={host ?? ALL_HOSTS_VALUE}
|
||||
options={hostOptions}
|
||||
@@ -340,7 +589,7 @@ export function PullRequestFiltersMenu({
|
||||
{serverOptions.length > 2 ? (
|
||||
<>
|
||||
<MenuSeparator />
|
||||
<PullRequestFilterRadioGroup
|
||||
<PullRequestFilterRadioSubmenu
|
||||
label="Server"
|
||||
value={server ?? ALL_SERVERS_VALUE}
|
||||
options={serverOptions}
|
||||
@@ -351,79 +600,16 @@ export function PullRequestFiltersMenu({
|
||||
</>
|
||||
) : null}
|
||||
<MenuSeparator />
|
||||
<MenuRadioGroup
|
||||
value={
|
||||
projectId === undefined || projectEnvironmentId === undefined
|
||||
? ALL_PROJECTS_VALUE
|
||||
: pullRequestProjectKey({ id: projectId, environmentId: projectEnvironmentId })
|
||||
}
|
||||
onValueChange={(next) => {
|
||||
if (next === ALL_PROJECTS_VALUE) {
|
||||
if (projectId !== undefined) onProject(undefined, undefined);
|
||||
return;
|
||||
}
|
||||
// The value carries both halves, since the id alone cannot tell two servers' rows
|
||||
// apart once they share one.
|
||||
<PullRequestFilterRadioSubmenu
|
||||
label="Project"
|
||||
value={projectValue}
|
||||
options={projectOptions}
|
||||
onChange={(next) => {
|
||||
const project = projects.find((candidate) => pullRequestProjectKey(candidate) === next);
|
||||
if (
|
||||
project !== undefined &&
|
||||
(project.id !== projectId || project.environmentId !== projectEnvironmentId)
|
||||
) {
|
||||
onProject(project.id, project.environmentId);
|
||||
}
|
||||
if (project) onProject(project.id, project.environmentId);
|
||||
else if (projectId !== undefined) onProject(undefined, undefined);
|
||||
}}
|
||||
>
|
||||
<MenuGroupLabel>Project</MenuGroupLabel>
|
||||
<MenuRadioItem value={ALL_PROJECTS_VALUE}>
|
||||
<span className="flex min-w-0 items-center gap-2">
|
||||
<LayersIcon aria-hidden className="size-3.5" />
|
||||
All projects
|
||||
</span>
|
||||
</MenuRadioItem>
|
||||
{/* The ones that can be chosen first: a list that opens with three disabled rows reads
|
||||
as a broken menu rather than as a workspace with three unreadable repositories. */}
|
||||
{projects
|
||||
.toSorted(
|
||||
(left, right) =>
|
||||
Number(unavailable.has(pullRequestProjectKey(left))) -
|
||||
Number(unavailable.has(pullRequestProjectKey(right))),
|
||||
)
|
||||
.map((project) => {
|
||||
const reason = unavailable.get(pullRequestProjectKey(project));
|
||||
const item = (
|
||||
<MenuRadioItem
|
||||
key={pullRequestProjectKey(project)}
|
||||
value={pullRequestProjectKey(project)}
|
||||
className={reason !== undefined ? "data-disabled:pointer-events-auto" : undefined}
|
||||
disabled={reason !== undefined}
|
||||
>
|
||||
<span className="flex min-w-0 flex-1 items-center gap-2">
|
||||
<ProjectFavicon
|
||||
environmentId={project.environmentId}
|
||||
cwd={project.workspaceRoot}
|
||||
fallbackIcon={FolderGit2Icon}
|
||||
className="size-3.5 shrink-0"
|
||||
/>
|
||||
<span className="min-w-0 flex-1 truncate">{project.title}</span>
|
||||
{reason === undefined ? null : (
|
||||
<span className="shrink-0 rounded-full border border-amber-500/40 bg-amber-500/10 px-1.5 py-px text-[10px] font-medium text-amber-600 dark:text-amber-400/90">
|
||||
Unavailable
|
||||
</span>
|
||||
)}
|
||||
</span>
|
||||
</MenuRadioItem>
|
||||
);
|
||||
if (reason === undefined) return item;
|
||||
return (
|
||||
<Tooltip key={pullRequestProjectKey(project)}>
|
||||
<TooltipTrigger render={item} />
|
||||
<TooltipPopup side="top" className="max-w-80">
|
||||
{reason}
|
||||
</TooltipPopup>
|
||||
</Tooltip>
|
||||
);
|
||||
})}
|
||||
</MenuRadioGroup>
|
||||
/>
|
||||
</MenuPopup>
|
||||
</Menu>
|
||||
);
|
||||
|
||||
@@ -7,7 +7,7 @@ import { formatRelativeTimeLabel } from "~/timestampFormat";
|
||||
|
||||
import { Tooltip, TooltipPopup, TooltipTrigger } from "../ui/tooltip";
|
||||
import { PullRequestChecksPopover } from "./PullRequestChecksPopover";
|
||||
import type { EnvironmentPullRequestEntry } from "./pullRequestList.logic";
|
||||
import { pullRequestLabelColor, type EnvironmentPullRequestEntry } from "./pullRequestList.logic";
|
||||
import { openOnHostLabel, showPullRequestLinkContextMenu } from "./pullRequestLinkContextMenu";
|
||||
import {
|
||||
PullRequestActorLabel,
|
||||
@@ -16,6 +16,23 @@ import {
|
||||
PullRequestStateGlyph,
|
||||
} from "./pullRequestPresentation";
|
||||
|
||||
function PullRequestRowLabels({ labels }: { labels: EnvironmentPullRequestEntry["labels"] }) {
|
||||
const label = labels[0];
|
||||
if (!label) return null;
|
||||
const dot = pullRequestLabelColor(label.color);
|
||||
return (
|
||||
<span className="inline-flex max-w-40 min-w-0 items-center gap-1 rounded-full border border-border/70 bg-muted/40 py-0 pl-1 pr-1.5 text-[10px] leading-3.5 text-muted-foreground">
|
||||
<span
|
||||
aria-hidden
|
||||
className="size-2 shrink-0 rounded-full bg-muted-foreground"
|
||||
{...(dot ? { style: { backgroundColor: dot } } : {})}
|
||||
/>
|
||||
<span className="truncate">{label.name}</span>
|
||||
{labels.length > 1 ? <span className="shrink-0">+{labels.length - 1}</span> : null}
|
||||
</span>
|
||||
);
|
||||
}
|
||||
|
||||
function PullRequestRowImpl({
|
||||
entry,
|
||||
selected,
|
||||
@@ -118,6 +135,7 @@ function PullRequestRowImpl({
|
||||
className="min-w-4 max-w-40"
|
||||
labelClassName="sr-only @xs/pr-row-meta:not-sr-only @xs/pr-row-meta:truncate"
|
||||
/>
|
||||
{entry.labels.length > 0 ? <PullRequestRowLabels labels={entry.labels} /> : null}
|
||||
{/* Only a verdict somebody has actually given: "review required" is the absence of
|
||||
one, and saying so on every unreviewed row would say nothing. */}
|
||||
{entry.reviewDecision === "approved" || entry.reviewDecision === "changes-requested" ? (
|
||||
|
||||
@@ -57,6 +57,7 @@ import { PullRequestMarkdown } from "./PullRequestMarkdown";
|
||||
import { PullRequestMarkdownEditor } from "./PullRequestMarkdownEditor";
|
||||
import { PullRequestReactionBar } from "./PullRequestReactions";
|
||||
import { PullRequestConversationGhost } from "./PullRequestGhosts";
|
||||
import { pullRequestLabelColor } from "./pullRequestList.logic";
|
||||
import { sectionCollapseAnchorScrollTop } from "./pullRequestSummaryScroll.logic";
|
||||
|
||||
/** One reviewer, however a host happens to have cased their login this time. */
|
||||
@@ -64,12 +65,6 @@ function reviewerKey(login: string): string {
|
||||
return login.toLowerCase();
|
||||
}
|
||||
|
||||
/** A host colour only when it is one, so a malformed value falls back to the neutral dot. */
|
||||
function labelDotColor(color: string | null): string | null {
|
||||
const hex = color?.trim().replace(/^#/, "") ?? "";
|
||||
return /^[0-9a-fA-F]{6}$/.test(hex) ? `#${hex}` : null;
|
||||
}
|
||||
|
||||
/** The avatar carries the attribution alone; who it is arrives on hover, like the reviewer row. */
|
||||
function CommentAuthor({ actor }: { actor: PullRequestActor | null }) {
|
||||
const login = actor?.login ?? "ghost";
|
||||
@@ -619,7 +614,7 @@ export function PullRequestSummaryTab({
|
||||
<MetaRow icon={<TagIcon className="size-3.5" />} label="Labels">
|
||||
<span className="flex min-w-0 flex-wrap items-center gap-1">
|
||||
{detail.labels.map((label) => {
|
||||
const dot = labelDotColor(label.color);
|
||||
const dot = pullRequestLabelColor(label.color);
|
||||
return (
|
||||
<span
|
||||
key={label.name}
|
||||
|
||||
@@ -8,8 +8,10 @@ import {
|
||||
resolvePullRequestAuthorFilter,
|
||||
} from "@t3tools/contracts";
|
||||
import type {
|
||||
PullRequestActor,
|
||||
PullRequestDiffStat,
|
||||
PullRequestInvolvement,
|
||||
PullRequestLabel,
|
||||
PullRequestListCursors,
|
||||
PullRequestListFilters,
|
||||
PullRequestListState,
|
||||
@@ -40,6 +42,16 @@ export interface PullRequestGroup<Entry extends PullRequestListEntry = PullReque
|
||||
readonly entries: ReadonlyArray<Entry>;
|
||||
}
|
||||
|
||||
export interface PullRequestAuthorFacet {
|
||||
readonly actor: PullRequestActor;
|
||||
readonly count: number;
|
||||
readonly mergedCount: number;
|
||||
}
|
||||
|
||||
export interface PullRequestLabelFacet extends PullRequestLabel {
|
||||
readonly count: number;
|
||||
}
|
||||
|
||||
/**
|
||||
* The signed-in account per host. Keyed `"<environmentId> <host>"` once a listing spans more than
|
||||
* one environment: two machines can both reach github.com signed in as different people, and a
|
||||
@@ -65,6 +77,59 @@ function normalize(value: string | null | undefined): string | null {
|
||||
return trimmed.length > 0 ? trimmed : null;
|
||||
}
|
||||
|
||||
export function pullRequestLabelColor(color: string | null): string | null {
|
||||
const hex = color?.trim().replace(/^#/, "") ?? "";
|
||||
return /^[0-9a-fA-F]{6}$/.test(hex) ? `#${hex}` : null;
|
||||
}
|
||||
|
||||
export function collectPullRequestListFacets(
|
||||
entries: ReadonlyArray<PullRequestListEntry>,
|
||||
state: PullRequestListState,
|
||||
) {
|
||||
const authors = new Map<string, PullRequestAuthorFacet>();
|
||||
const labels = new Map<string, PullRequestLabelFacet>();
|
||||
const uniqueEntries = new Map(entries.map((entry) => [pullRequestEntryKey(entry), entry]));
|
||||
for (const entry of uniqueEntries.values()) {
|
||||
const inState = state === "all" || entry.state === state;
|
||||
if (entry.author !== null) {
|
||||
const key = normalize(entry.author.login);
|
||||
if (key !== null) {
|
||||
const held = authors.get(key);
|
||||
authors.set(key, {
|
||||
actor: held?.actor ?? entry.author,
|
||||
count: (held?.count ?? 0) + Number(inState),
|
||||
mergedCount: (held?.mergedCount ?? 0) + Number(entry.state === "merged"),
|
||||
});
|
||||
}
|
||||
}
|
||||
if (!inState) continue;
|
||||
for (const label of entry.labels) {
|
||||
const key = normalize(label.name);
|
||||
if (key === null) continue;
|
||||
const held = labels.get(key);
|
||||
labels.set(key, {
|
||||
...label,
|
||||
name: held?.name ?? label.name,
|
||||
color: held?.color ?? label.color,
|
||||
count: (held?.count ?? 0) + 1,
|
||||
});
|
||||
}
|
||||
}
|
||||
return {
|
||||
authors: [...authors.values()]
|
||||
.filter((author) => author.count > 0)
|
||||
.toSorted(
|
||||
(left, right) =>
|
||||
right.mergedCount - left.mergedCount ||
|
||||
right.count - left.count ||
|
||||
left.actor.login.localeCompare(right.actor.login),
|
||||
),
|
||||
labels: [...labels.values()].toSorted(
|
||||
(left, right) => right.count - left.count || left.name.localeCompare(right.name),
|
||||
),
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* The signed-in login for the host a row came from, or null where none was given. Shared by
|
||||
* authorship matching here and by `author:me` resolution wherever a row's own viewer is needed.
|
||||
@@ -433,13 +498,16 @@ export function mergePullRequestDiffStats(
|
||||
if (stats.length === 0) return previous;
|
||||
const next = new Map(previous);
|
||||
for (const stat of stats) {
|
||||
next.set(diffStatKey(stat), { additions: stat.additions, deletions: stat.deletions });
|
||||
next.set(pullRequestDiffStatKey(stat), {
|
||||
additions: stat.additions,
|
||||
deletions: stat.deletions,
|
||||
});
|
||||
}
|
||||
return next;
|
||||
}
|
||||
|
||||
/** A project id only names a project within its own environment, so the key carries both. */
|
||||
const diffStatKey = (row: {
|
||||
export const pullRequestDiffStatKey = (row: {
|
||||
readonly environmentId: string;
|
||||
readonly projectId: string;
|
||||
readonly number: number;
|
||||
@@ -792,6 +860,6 @@ export function withDiffStat<
|
||||
statsByRow: ReadonlyMap<string, { readonly additions: number; readonly deletions: number }>,
|
||||
): Entry {
|
||||
if (entry.additions !== 0 || entry.deletions !== 0) return entry;
|
||||
const stat = statsByRow.get(diffStatKey(entry));
|
||||
const stat = statsByRow.get(pullRequestDiffStatKey(entry));
|
||||
return stat === undefined ? entry : { ...entry, ...stat };
|
||||
}
|
||||
@@ -13,7 +13,11 @@ import type {
|
||||
} from "@t3tools/contracts";
|
||||
import { createFileRoute, useNavigate } from "@tanstack/react-router";
|
||||
import {
|
||||
ArrowDownUpIcon,
|
||||
CalendarArrowDownIcon,
|
||||
CalendarArrowUpIcon,
|
||||
ChevronDownIcon,
|
||||
ClockIcon,
|
||||
EyeIcon,
|
||||
MonitorIcon,
|
||||
ServerIcon,
|
||||
@@ -23,6 +27,8 @@ import {
|
||||
LayersIcon,
|
||||
PenLineIcon,
|
||||
LoaderIcon,
|
||||
Maximize2Icon,
|
||||
Minimize2Icon,
|
||||
RefreshCwIcon,
|
||||
SearchIcon,
|
||||
} from "lucide-react";
|
||||
@@ -31,6 +37,7 @@ import { useCallback, useEffect, useMemo, useRef, useState, type ReactNode } fro
|
||||
import {
|
||||
filterPullRequestsByInvolvement,
|
||||
findScopedProject,
|
||||
collectPullRequestListFacets,
|
||||
groupPullRequestsByInvolvement,
|
||||
matchesPullRequestFilters,
|
||||
matchesPullRequestQuery,
|
||||
@@ -38,6 +45,7 @@ import {
|
||||
narrowPullRequestsToFilters,
|
||||
mergePullRequestDiffStats,
|
||||
partitionPullRequestsWithPriority,
|
||||
pullRequestDiffStatKey,
|
||||
pullRequestEntryKey,
|
||||
pullRequestEntryViewer,
|
||||
rankPullRequestMatches,
|
||||
@@ -58,6 +66,7 @@ import { assignProjectsToEnvironments } from "../components/pullRequest/pullRequ
|
||||
import { PullRequestDetailPanel } from "../components/pullRequest/PullRequestDetailPanel";
|
||||
import {
|
||||
PullRequestFiltersMenu,
|
||||
PullRequestFilterOptionIcon,
|
||||
PullRequestSearchInput,
|
||||
pullRequestHostLabel,
|
||||
pullRequestProjectKey,
|
||||
@@ -83,6 +92,7 @@ import { Menu, MenuPopup, MenuRadioGroup, MenuRadioItem, MenuTrigger } from "../
|
||||
import { SidebarInset } from "../components/ui/sidebar";
|
||||
import { Tooltip, TooltipPopup, TooltipTrigger } from "../components/ui/tooltip";
|
||||
import { useLiveRefresh } from "../hooks/useLiveRefresh";
|
||||
import { toSortableTimestamp } from "../lib/threadSort";
|
||||
import {
|
||||
selectActiveRightPanelSurface,
|
||||
selectSelectedRightPanelSurface,
|
||||
@@ -136,8 +146,13 @@ export interface PullRequestsSearch {
|
||||
readonly draft?: "only" | "hide";
|
||||
readonly review?: NonNullable<PullRequestListFilters["review"]>;
|
||||
readonly checks?: NonNullable<PullRequestListFilters["checks"]>;
|
||||
readonly author?: string;
|
||||
readonly labels?: ReadonlyArray<string>;
|
||||
readonly sort?: PullRequestListSort;
|
||||
}
|
||||
|
||||
type PullRequestListSort = "updated" | "newest" | "oldest" | "largest" | "smallest";
|
||||
|
||||
// The state filters wear the same glyphs the rows do, so the two read as one vocabulary.
|
||||
const INVOLVEMENT_TABS = [
|
||||
{ value: "all", label: "All", Icon: LayersIcon },
|
||||
@@ -152,6 +167,14 @@ const STATE_TABS = [
|
||||
{ value: "merged", label: "Merged", Icon: GitMergeIcon },
|
||||
] as const satisfies ReadonlyArray<PullRequestFilterOption<PullRequestListState>>;
|
||||
|
||||
const SORT_OPTIONS = [
|
||||
{ value: "updated", label: "Recently updated", Icon: ClockIcon },
|
||||
{ value: "newest", label: "Newest shown", Icon: CalendarArrowDownIcon },
|
||||
{ value: "oldest", label: "Oldest shown", Icon: CalendarArrowUpIcon },
|
||||
{ value: "largest", label: "Largest shown", Icon: Maximize2Icon },
|
||||
{ value: "smallest", label: "Smallest shown", Icon: Minimize2Icon },
|
||||
] as const satisfies ReadonlyArray<PullRequestFilterOption<PullRequestListSort>>;
|
||||
|
||||
/** Long enough that a keystroke does not become a request, short enough to feel answered. */
|
||||
const SEARCH_DEBOUNCE_MS = 250;
|
||||
/** What `scorePullRequestMatch` gives a row none of whose own fields carry the search text. */
|
||||
@@ -181,6 +204,26 @@ const EMPTY_PREVIEW_SESSIONS = {};
|
||||
const EMPTY_PREVIEW_DESKTOP_STATE = {};
|
||||
const EMPTY_TERMINAL_LABELS = new Map<string, string>();
|
||||
const EMPTY_PENDING_SURFACES = new Set<string>();
|
||||
const MAX_SEARCH_LABEL_CANDIDATES = 100;
|
||||
|
||||
function pullRequestSearchLabels(raw: unknown): Partial<Pick<PullRequestsSearch, "labels">> {
|
||||
const values = (Array.isArray(raw) ? raw : typeof raw === "string" ? [raw] : []).slice(
|
||||
0,
|
||||
MAX_SEARCH_LABEL_CANDIDATES,
|
||||
);
|
||||
const labels: Array<string> = [];
|
||||
const seen = new Set<string>();
|
||||
for (const rawValue of values) {
|
||||
if (typeof rawValue !== "string") continue;
|
||||
const value = rawValue.trim().slice(0, 200);
|
||||
const key = value.toLowerCase();
|
||||
if (value.length === 0 || seen.has(key)) continue;
|
||||
labels.push(value);
|
||||
seen.add(key);
|
||||
if (labels.length === 10) break;
|
||||
}
|
||||
return labels.length === 0 ? {} : { labels };
|
||||
}
|
||||
|
||||
export const Route = createFileRoute("/_chat/pull-requests")({
|
||||
validateSearch: (raw: Record<string, unknown>): PullRequestsSearch => ({
|
||||
@@ -188,6 +231,9 @@ export const Route = createFileRoute("/_chat/pull-requests")({
|
||||
raw.involvement === "reviewing" || raw.involvement === "authored" ? raw.involvement : "all",
|
||||
state:
|
||||
raw.state === "closed" || raw.state === "merged" || raw.state === "all" ? raw.state : "open",
|
||||
...(SORT_OPTIONS.some((option) => option.value === raw.sort)
|
||||
? { sort: raw.sort as PullRequestListSort }
|
||||
: {}),
|
||||
...(typeof raw.repository === "string" && raw.repository
|
||||
? { repository: raw.repository.slice(0, 200) }
|
||||
: {}),
|
||||
@@ -216,12 +262,17 @@ export const Route = createFileRoute("/_chat/pull-requests")({
|
||||
? { review: raw.review }
|
||||
: {}),
|
||||
...(raw.checks === "passing" || raw.checks === "failing" ? { checks: raw.checks } : {}),
|
||||
...(typeof raw.author === "string" && raw.author.trim()
|
||||
? { author: raw.author.trim().slice(0, 200) }
|
||||
: {}),
|
||||
...pullRequestSearchLabels(raw.labels),
|
||||
}),
|
||||
component: PullRequestsRouteView,
|
||||
});
|
||||
|
||||
function PullRequestsRouteView() {
|
||||
const search = Route.useSearch();
|
||||
const sort = search.sort ?? "updated";
|
||||
const navigate = useNavigate({ from: Route.fullPath });
|
||||
const { environments } = useEnvironments();
|
||||
// Every connected environment that has said it can list pull requests. Sorted, so the query
|
||||
@@ -416,6 +467,7 @@ function PullRequestsRouteView() {
|
||||
return {
|
||||
involvement: next.involvement ?? previous.involvement,
|
||||
state: next.state ?? previous.state,
|
||||
...(next.sort && next.sort !== "updated" ? { sort: next.sort } : {}),
|
||||
...(next.repository ? { repository: next.repository } : {}),
|
||||
...(next.number ? { number: next.number } : {}),
|
||||
...(next.projectId ? { projectId: next.projectId } : {}),
|
||||
@@ -429,6 +481,8 @@ function PullRequestsRouteView() {
|
||||
...(next.draft ? { draft: next.draft } : {}),
|
||||
...(next.review ? { review: next.review } : {}),
|
||||
...(next.checks ? { checks: next.checks } : {}),
|
||||
...(next.author ? { author: next.author } : {}),
|
||||
...(next.labels && next.labels.length > 0 ? { labels: next.labels } : {}),
|
||||
};
|
||||
},
|
||||
replace: true,
|
||||
@@ -458,6 +512,7 @@ function PullRequestsRouteView() {
|
||||
// it is sent. Until it lands, the rows already on screen are narrowed locally: the answer is
|
||||
// late but the page is not.
|
||||
const typedQuery = (search.q ?? "").trim();
|
||||
const [filtersOpen, setFiltersOpen] = useState(false);
|
||||
const sentQuery = useDebouncedValue(typedQuery, SEARCH_DEBOUNCE_MS);
|
||||
const querySettled = typedQuery === sentQuery;
|
||||
// What was typed, split into the qualifiers the hosts can act on and the words that are left.
|
||||
@@ -472,12 +527,14 @@ function PullRequestsRouteView() {
|
||||
...(search.draft ? { draft: search.draft } : {}),
|
||||
...(search.review ? { review: search.review } : {}),
|
||||
...(search.checks ? { checks: search.checks } : {}),
|
||||
...(search.author ? { author: search.author } : {}),
|
||||
...(search.labels ? { labels: search.labels.map((label) => [label]) } : {}),
|
||||
}),
|
||||
[search.checks, search.draft, search.review],
|
||||
[search.author, search.checks, search.draft, search.labels, search.review],
|
||||
);
|
||||
const menuFiltered = Object.keys(menuFilters).length > 0;
|
||||
// A typed qualifier wins over the menu's own answer for the same thing, since it is the more
|
||||
// recent word on it; labels only ever come from the query, so there is nothing to overrule.
|
||||
// recent word on it, including a typed author or label over its menu counterpart.
|
||||
const filters = useMemo(
|
||||
(): PullRequestListFilters => ({ ...menuFilters, ...sentParsed.filters }),
|
||||
[menuFilters, sentParsed.filters],
|
||||
@@ -548,7 +605,7 @@ function PullRequestsRouteView() {
|
||||
[environmentQueries],
|
||||
);
|
||||
// Page size is view state, not a URL concern: a shared link should open the first page.
|
||||
const scopeKey = `${environmentKey}:${assignmentKey}:${search.state}:${search.involvement}:${scopedProjectId ?? ""}:${search.host ?? ""}:${search.draft ?? ""}:${search.review ?? ""}:${search.checks ?? ""}`;
|
||||
const scopeKey = `${environmentKey}:${assignmentKey}:${search.state}:${search.involvement}:${scopedProjectId ?? ""}:${search.host ?? ""}:${search.draft ?? ""}:${search.review ?? ""}:${search.checks ?? ""}:${search.author ?? ""}:${search.labels?.join("\u0000") ?? ""}`;
|
||||
const filterKey = `${scopeKey}:${sentQuery}`;
|
||||
// Where the next slice carries on from, per repository within each environment, as that
|
||||
// environment handed it back. Sending it is what makes a second page cost a second page rather
|
||||
@@ -660,6 +717,21 @@ function PullRequestsRouteView() {
|
||||
],
|
||||
);
|
||||
const baselineQuery = usePullRequestList(baselineTargets);
|
||||
const facetTargets = useMemo(() => {
|
||||
if (!filtersOpen) return NO_LIST_TARGETS;
|
||||
return environmentQueries.map(({ environmentId, projectIds }) => ({
|
||||
environmentId,
|
||||
input: {
|
||||
state: "all",
|
||||
involvement: search.involvement,
|
||||
limit: PAGE_SIZE,
|
||||
...(scopedProjectId ? { projectId: scopedProjectId } : {}),
|
||||
...(projectIds ? { projectIds } : {}),
|
||||
...(search.host ? { host: search.host } : {}),
|
||||
} satisfies PullRequestListInput,
|
||||
}));
|
||||
}, [environmentQueries, filtersOpen, scopedProjectId, search.host, search.involvement]);
|
||||
const facetQuery = usePullRequestList(facetTargets);
|
||||
// The priority groups' own reads. The feed below is paginated by recency, so an older authored
|
||||
// or review-requested row can be missing from its first page; partitioned from these
|
||||
// server-filtered reads instead, the priority view is complete up front and a continuation can
|
||||
@@ -720,6 +792,7 @@ function PullRequestsRouteView() {
|
||||
}
|
||||
refreshList();
|
||||
baselineQuery.refresh();
|
||||
facetQuery.refresh();
|
||||
authoredQuery.refresh();
|
||||
reviewingQuery.refresh();
|
||||
statsQuery.refresh();
|
||||
@@ -982,6 +1055,17 @@ function PullRequestsRouteView() {
|
||||
|
||||
const viewers = baselineQuery.data?.viewers ?? listData?.viewers ?? EMPTY_VIEWERS;
|
||||
const listErrors = baselineQuery.data?.errors ?? listData?.errors ?? [];
|
||||
const facets = useMemo(
|
||||
() =>
|
||||
collectPullRequestListFacets(
|
||||
[
|
||||
...(facetQuery.data?.entries ?? []),
|
||||
...(baselineQuery.data?.entries ?? listData?.entries ?? []),
|
||||
],
|
||||
search.state,
|
||||
),
|
||||
[baselineQuery.data?.entries, facetQuery.data?.entries, listData?.entries, search.state],
|
||||
);
|
||||
|
||||
/** The hosts that narrowed the listing themselves, so their answer is not narrowed again. */
|
||||
const searchingHosts = useMemo(
|
||||
@@ -1170,6 +1254,40 @@ function PullRequestsRouteView() {
|
||||
if (stats === null) return;
|
||||
setStatsByRow((previous) => mergePullRequestDiffStats(previous, stats));
|
||||
}, [statsQuery.stats]);
|
||||
const displayGroups = useMemo(() => {
|
||||
const enriched = groups.map((group) => ({
|
||||
...group,
|
||||
entries: group.entries.map((entry) => withDiffStat(entry, statsByRow)),
|
||||
}));
|
||||
if (sort === "updated") return enriched;
|
||||
const entries = enriched.flatMap((group) => group.entries);
|
||||
const hasSize = (entry: (typeof entries)[number]) =>
|
||||
entry.additions + entry.deletions > 0 || statsByRow.has(pullRequestDiffStatKey(entry));
|
||||
const timestamp = (entry: (typeof entries)[number]) =>
|
||||
toSortableTimestamp(entry.updatedAt) ?? toSortableTimestamp(entry.createdAt) ?? 0;
|
||||
return [
|
||||
{
|
||||
key: "others" as const,
|
||||
label: "",
|
||||
entries: entries.toSorted((left, right) => {
|
||||
if (sort === "newest" || sort === "oldest") {
|
||||
const leftCreated = toSortableTimestamp(left.createdAt);
|
||||
const rightCreated = toSortableTimestamp(right.createdAt);
|
||||
const measured = Number(rightCreated !== null) - Number(leftCreated !== null);
|
||||
const dated = (leftCreated ?? 0) - (rightCreated ?? 0);
|
||||
return (
|
||||
measured || (sort === "newest" ? -dated : dated) || timestamp(right) - timestamp(left)
|
||||
);
|
||||
}
|
||||
const measured = Number(hasSize(right)) - Number(hasSize(left));
|
||||
const sized = left.additions + left.deletions - (right.additions + right.deletions);
|
||||
return (
|
||||
measured || (sort === "largest" ? -sized : sized) || timestamp(right) - timestamp(left)
|
||||
);
|
||||
}),
|
||||
},
|
||||
];
|
||||
}, [groups, sort, statsByRow]);
|
||||
|
||||
const linkedSelection = useMemo(
|
||||
() =>
|
||||
@@ -1347,6 +1465,7 @@ function PullRequestsRouteView() {
|
||||
onRefresh={() => void refreshFromHost()}
|
||||
query={typedQuery}
|
||||
filtered={
|
||||
menuFiltered ||
|
||||
search.state !== "open" ||
|
||||
search.involvement !== "all" ||
|
||||
scopedProjectId !== undefined ||
|
||||
@@ -1360,7 +1479,7 @@ function PullRequestsRouteView() {
|
||||
/>
|
||||
) : (
|
||||
<div className="space-y-3">
|
||||
{groups.map((group) => (
|
||||
{displayGroups.map((group) => (
|
||||
<div key={group.key} className="space-y-0.5">
|
||||
{group.label ? (
|
||||
<h2 className="px-3 pb-0.5 text-xs font-medium text-muted-foreground/70">
|
||||
@@ -1370,10 +1489,7 @@ function PullRequestsRouteView() {
|
||||
{group.entries.map((entry) => (
|
||||
<PullRequestRow
|
||||
key={pullRequestEntryKey(entry)}
|
||||
// A row whose host reported its line counts keeps them; one whose host left
|
||||
// them for later takes whatever has arrived since, and draws without them
|
||||
// until it does.
|
||||
entry={withDiffStat(entry, statsByRow)}
|
||||
entry={entry}
|
||||
showProjectTitle
|
||||
showProvider={showProvider}
|
||||
{...(capableEnvironments.length > 1 &&
|
||||
@@ -1449,8 +1565,20 @@ function PullRequestsRouteView() {
|
||||
Icon: environment.displayUrl === null ? MonitorIcon : ServerIcon,
|
||||
})),
|
||||
];
|
||||
const sortMenu = (
|
||||
<CompactFilterMenu
|
||||
label="Sort pull requests"
|
||||
triggerIcon={<ArrowDownUpIcon aria-hidden className="size-4" />}
|
||||
triggerLabel="Sort"
|
||||
outlined
|
||||
value={sort}
|
||||
options={SORT_OPTIONS}
|
||||
onChange={(next) => updateSearch({ sort: next })}
|
||||
/>
|
||||
);
|
||||
const filtersMenu = (
|
||||
<PullRequestFiltersMenu
|
||||
onOpenChange={setFiltersOpen}
|
||||
state={search.state}
|
||||
stateOptions={STATE_TABS}
|
||||
onState={(state) => updateListScope({ state })}
|
||||
@@ -1459,8 +1587,16 @@ function PullRequestsRouteView() {
|
||||
onInvolvement={(involvement) => updateListScope({ involvement })}
|
||||
filters={menuFilters}
|
||||
onFilters={(next) =>
|
||||
updateListScope({ draft: next.draft, review: next.review, checks: next.checks })
|
||||
updateListScope({
|
||||
draft: next.draft,
|
||||
review: next.review,
|
||||
checks: next.checks,
|
||||
author: next.author,
|
||||
labels: next.labels?.flatMap((group) => group),
|
||||
})
|
||||
}
|
||||
authorOptions={facets.authors}
|
||||
labelOptions={facets.labels}
|
||||
host={search.host}
|
||||
hostOptions={hostMenuOptions}
|
||||
onHost={(host) => updateListScope({ host })}
|
||||
@@ -1493,6 +1629,7 @@ function PullRequestsRouteView() {
|
||||
onState: (state: PullRequestListState) => updateListScope({ state }),
|
||||
onHost: (host: string | undefined) => updateListScope({ host }),
|
||||
searchInput,
|
||||
sortMenu,
|
||||
filtersMenu,
|
||||
rightPanelControl:
|
||||
// Footprint reserve while the panel is closed: the toggle itself stays
|
||||
@@ -1625,12 +1762,18 @@ function PullRequestsRouteView() {
|
||||
/** A compact stand-in for one pill group when the header is narrow. */
|
||||
function CompactFilterMenu<Value extends string>({
|
||||
label,
|
||||
triggerIcon,
|
||||
triggerLabel,
|
||||
outlined = false,
|
||||
value,
|
||||
options,
|
||||
onChange,
|
||||
className,
|
||||
}: {
|
||||
label: string;
|
||||
triggerIcon?: ReactNode;
|
||||
triggerLabel?: string;
|
||||
outlined?: boolean;
|
||||
value: Value;
|
||||
options: ReadonlyArray<PullRequestFilterOption<Value>>;
|
||||
onChange: (value: Value) => void;
|
||||
@@ -1641,14 +1784,28 @@ function CompactFilterMenu<Value extends string>({
|
||||
return (
|
||||
<Menu>
|
||||
<MenuTrigger
|
||||
aria-label={label}
|
||||
className={cn(
|
||||
"inline-flex h-7 min-w-0 items-center gap-1 rounded-md px-1.5 text-sm font-medium text-muted-foreground hover:bg-accent hover:text-foreground",
|
||||
className,
|
||||
)}
|
||||
aria-label={triggerLabel ? `${label}: ${current.label}` : label}
|
||||
render={outlined ? <Button variant="outline" /> : undefined}
|
||||
className={
|
||||
outlined
|
||||
? className
|
||||
: cn(
|
||||
"inline-flex h-7 min-w-0 items-center gap-1 rounded-md px-1.5 text-sm font-medium text-muted-foreground hover:bg-accent hover:text-foreground",
|
||||
className,
|
||||
)
|
||||
}
|
||||
>
|
||||
<span className="truncate">{current.label}</span>
|
||||
<ChevronDownIcon aria-hidden className="size-3 shrink-0 text-muted-foreground/70" />
|
||||
{triggerLabel ? (
|
||||
<>
|
||||
{triggerIcon}
|
||||
<span>{triggerLabel}</span>
|
||||
</>
|
||||
) : (
|
||||
<>
|
||||
<span className="truncate">{current.label}</span>
|
||||
<ChevronDownIcon aria-hidden className="size-3 shrink-0 text-muted-foreground/70" />
|
||||
</>
|
||||
)}
|
||||
</MenuTrigger>
|
||||
<MenuPopup align="start" side="bottom" className="min-w-40">
|
||||
<MenuRadioGroup value={value} onValueChange={(next) => onChange(next as Value)}>
|
||||
@@ -1661,7 +1818,7 @@ function CompactFilterMenu<Value extends string>({
|
||||
className="data-disabled:pointer-events-auto"
|
||||
>
|
||||
<span className="flex min-w-0 items-center gap-2">
|
||||
<option.Icon aria-hidden className="size-3.5" />
|
||||
<PullRequestFilterOptionIcon option={option} />
|
||||
{option.label}
|
||||
</span>
|
||||
</MenuRadioItem>
|
||||
@@ -1769,6 +1926,7 @@ function PullRequestsColumn({
|
||||
onState,
|
||||
onHost,
|
||||
searchInput,
|
||||
sortMenu,
|
||||
filtersMenu,
|
||||
rightPanelControl,
|
||||
titlebarControls,
|
||||
@@ -1786,6 +1944,7 @@ function PullRequestsColumn({
|
||||
onState: (state: PullRequestListState) => void;
|
||||
onHost: (host: string | undefined) => void;
|
||||
searchInput: ReactNode;
|
||||
sortMenu: ReactNode;
|
||||
filtersMenu: ReactNode;
|
||||
rightPanelControl: ReactNode;
|
||||
titlebarControls: ReactNode;
|
||||
@@ -1934,6 +2093,7 @@ function PullRequestsColumn({
|
||||
<div className="flex flex-col gap-3">
|
||||
<div ref={inFlowSearchRef} className="flex items-center gap-2">
|
||||
{searchInput}
|
||||
{sortMenu}
|
||||
{filtersMenu}
|
||||
{!condensed ? (
|
||||
<PullRequestRefreshControl refreshing={refreshing} onRefresh={onRefresh} />
|
||||
|
||||
@@ -41,6 +41,9 @@ T3 Code works with the platforms your team already uses:
|
||||
|
||||
- See if your current branch already has an open PR/MR
|
||||
- Open several reviews from the **Pull requests** page as tabs in the right panel
|
||||
- Filter the list by author or labels, rank authors by merges in the loaded results, see label and
|
||||
change-size context on each row, and sort the results currently shown by update time, creation
|
||||
time, or change size
|
||||
- While working in a thread, open linked reviews in the same compact right-panel tabs without
|
||||
leaving the conversation
|
||||
- Open the review directly in your browser with one click
|
||||
|
||||
Reference in new issue
Block a user