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
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ const read = mock(() => detail);
mock.module(`${root}/pull-requests/hooks/usePullRequestDetail`, () => ({
usePullRequestDetail: read,
}));
mock.module(`${root}/pull-requests/hooks/usePullRequestListPreview`, () => ({
usePullRequestListPreview: () => null,
}));
mock.module(`${root}/components/PageHeader`, () => ({
PageHeader: ({ children }: { children: ReactNode }) => <div>{children}</div>,
}));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
} from "renderer/routes/_authenticated/_dashboard/pull-requests/components/PullRequestDetailTabs";
import { PullRequestListToggle } from "renderer/routes/_authenticated/_dashboard/pull-requests/components/PullRequestListToggle";
import { usePullRequestDetail } from "renderer/routes/_authenticated/_dashboard/pull-requests/hooks/usePullRequestDetail";
import { usePullRequestListPreview } from "renderer/routes/_authenticated/_dashboard/pull-requests/hooks/usePullRequestListPreview";
import { useRefreshPullRequest } from "renderer/routes/_authenticated/_dashboard/pull-requests/hooks/useRefreshPullRequest";
import {
canActOnPullRequest,
Expand Down Expand Up @@ -47,6 +48,11 @@ function PullRequestDetailPage() {
prNumber,
repoFullName: search.repo,
});
const preview = usePullRequestListPreview({
Comment thread
AviPeltz marked this conversation as resolved.
Resolved
projectId,
repoFullName: search.repo ?? null,
prNumber,
});
const data = detail.data ?? null;
const diffStat =
data?.additions !== undefined && data.deletions !== undefined
Expand Down Expand Up @@ -106,6 +112,7 @@ function PullRequestDetailPage() {
hostUrl={hostUrl}
hostId={hostId}
commentTarget={commentTarget}
preview={preview}
/>
</div>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { lazy, type ReactNode, Suspense } from "react";
import { cloudTrpcClient } from "renderer/lib/cloud-trpc";
import { WorkItemDetailState } from "../../../components/WorkItemDetailState";
import type { PullRequestDetail } from "../../hooks/usePullRequestDetail";
import type { PullRequestPreview } from "../../hooks/usePullRequestListPreview";
import { needsGithubConnection } from "../../utils/pullRequestClient";
import type { PullRequestActivityThreads } from "../PullRequestActivity";
import type { PullRequestCommentTarget } from "../PullRequestConversationComposer";
Expand Down Expand Up @@ -32,6 +33,7 @@ export function PullRequestDetailContent({
threads,
summaryAside,
commentTarget = null,
preview = null,
}: {
activeTab: PullRequestDetailTab;
projectId: string | null;
Expand All @@ -51,6 +53,8 @@ export function PullRequestDetailContent({
summaryAside?: ReactNode;
/** Where a conversation comment posts; null hides the composer. */
commentTarget?: PullRequestCommentTarget | null;
/** Shown in the loading skeleton's header slot until the detail arrives. */
preview?: PullRequestPreview | null;
}) {
const { t } = useLingui();
if (prNumber === null || (!repoFullName && !projectId && !detail.isLoading)) {
Expand All @@ -61,14 +65,15 @@ export function PullRequestDetailContent({
/>
);
}
if (detail.isResolvingProject) return <PullRequestDetailSkeleton />;
if (detail.isResolvingProject)
return <PullRequestDetailSkeleton preview={preview} />;
const prUrl =
detail.data?.url ??
(repoFullName
? `https://github.com/${repoFullName}/pull/${prNumber}`
: null);
const detailState = detail.data ? null : detail.isLoading ? (
<PullRequestDetailSkeleton />
<PullRequestDetailSkeleton preview={preview} />
) : (
<WorkItemDetailState
message={
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { useLingui } from "@lingui/react/macro";
import { cn } from "@superset/ui/utils";
import type { PullRequestPreview } from "../../hooks/usePullRequestListPreview";
import { PullRequestSkeleton as Skeleton } from "../PullRequestSkeleton";
import { PullRequestPreviewHeader } from "./components/PullRequestPreviewHeader";

const BODY_LINES = [
{ id: "first", width: "w-full" },
Expand All @@ -13,12 +15,15 @@ const BODY_LINES = [
interface PullRequestDetailSkeletonProps {
/** True for the Changes tab: a file card shape instead of the summary page. */
variant?: "summary" | "diff";
/** The list's row for this pull request: its header shows at once. */
preview?: PullRequestPreview | null;
className?: string;
}

/** The page's shape while its detail (or the diff renderer) is on its way. */
export function PullRequestDetailSkeleton({
variant = "summary",
preview = null,
className,
}: PullRequestDetailSkeletonProps) {
const { t } = useLingui();
Expand Down Expand Up @@ -56,17 +61,23 @@ export function PullRequestDetailSkeleton({
>
<div className="mx-auto flex w-full max-w-[76rem] items-start gap-12 px-6 pt-4">
<div className="min-w-0 flex-1 space-y-4">
<div className="flex items-center gap-2">
<Skeleton className="h-6 w-16 rounded-full" />
<Skeleton className="h-3 w-24 rounded-full" />
</div>
<Skeleton className="h-8 w-4/5 rounded-md" />
<div className="flex items-center gap-2">
<Skeleton className="size-4 rounded-full" />
<Skeleton className="h-3 w-24 rounded-full" />
<Skeleton className="h-3 w-12 rounded-full" />
<Skeleton className="h-3 w-32 rounded-full" />
</div>
{preview ? (
<PullRequestPreviewHeader preview={preview} />
) : (
<>
<div className="flex items-center gap-2">
<Skeleton className="h-6 w-16 rounded-full" />
<Skeleton className="h-3 w-24 rounded-full" />
</div>
<Skeleton className="h-8 w-4/5 rounded-md" />
<div className="flex items-center gap-2">
<Skeleton className="size-4 rounded-full" />
<Skeleton className="h-3 w-24 rounded-full" />
<Skeleton className="h-3 w-12 rounded-full" />
<Skeleton className="h-3 w-32 rounded-full" />
</div>
</>
)}
<div className="space-y-2 pt-4">
<Skeleton className="h-4 w-24 rounded-full" />
{BODY_LINES.map(({ id, width }) => (
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import { Avatar, AvatarFallback, AvatarImage } from "@superset/ui/avatar";
import type { PullRequestPreview } from "../../../../hooks/usePullRequestListPreview";
import { PullRequestStatePill } from "../../../PullRequestStatePill";

/** PullRequestItemHeader's first lines, drawn from the list row before the detail arrives. */
export function PullRequestPreviewHeader({
preview,
}: {
preview: PullRequestPreview;
}) {
const repositoryName =
preview.repoFullName.split("/").pop() ?? preview.repoFullName;
return (
<header className="shrink-0 pb-4">
<div className="flex min-w-0 items-center gap-2">
<PullRequestStatePill
data={{
state: preview.state,
isDraft: preview.isDraft,
mergeability: "unknown",
}}
/>
<span
className="min-w-0 truncate text-xs text-muted-foreground"
title={preview.repoFullName}
>
{repositoryName} #{preview.number}
</span>
</div>
<h1 className="mt-3 select-text break-words text-[1.75rem] font-semibold leading-tight tracking-tight @max-[48rem]/detail:text-2xl @max-[36rem]/detail:mt-2 @max-[36rem]/detail:text-xl">
{preview.title}
</h1>
<div className="mt-3 flex min-w-0 flex-wrap items-center gap-x-1.5 gap-y-1 text-xs text-muted-foreground">
{preview.authorLogin ? (
<span
className="flex min-w-0 items-center gap-1.5 font-medium text-foreground"
title={preview.authorLogin}
>
<Avatar className="size-4 rounded-full ring-1 ring-border/50">
<AvatarImage
src={`https://github.com/${preview.authorLogin}.png?size=64`}
alt=""
/>
<AvatarFallback className="text-[8px]">
{preview.authorLogin.slice(0, 1).toUpperCase()}
</AvatarFallback>
</Avatar>
<span className="truncate">{preview.authorLogin}</span>
</span>
) : null}
{preview.headRef ? (
<>
<span aria-hidden>·</span>
<span
className="min-w-0 truncate text-[11px] text-muted-foreground/80"
title={preview.headRef}
>
{preview.headRef}
</span>
</>
) : null}
</div>
</header>
);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { PullRequestPreviewHeader } from "./PullRequestPreviewHeader";
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import type { PullRequestDetail } from "../../hooks/usePullRequestDetail";
import type { PullRequestActionTarget } from "../../hooks/usePullRequestDraftMutation";
import { PullRequestDraftStateMenu } from "../PullRequestDraftStateMenu";
import { PullRequestStatePill } from "../PullRequestStatePill";
import { PullRequestCopyText } from "./components/PullRequestCopyText";

interface PullRequestItemHeaderProps {
data: PullRequestDetail;
Expand Down Expand Up @@ -38,21 +39,23 @@ export function PullRequestItemHeader({
) : (
<PullRequestStatePill data={data} />
)}
<span
className="min-w-0 truncate text-xs text-muted-foreground"
title={data.repoFullName}
<PullRequestCopyText
value={data.url}
label={t({ message: "Copy link to pull request" })}
className="truncate text-xs text-muted-foreground"
>
{repositoryName} #{data.number}
</span>
</PullRequestCopyText>
</div>
<h1 className="mt-3 select-text break-words text-[1.75rem] font-semibold leading-tight tracking-tight @max-[48rem]/detail:text-2xl @max-[36rem]/detail:mt-2 @max-[36rem]/detail:text-xl">
{data.title}
</h1>
<div className="mt-3 flex min-w-0 flex-wrap items-center gap-x-1.5 gap-y-1 text-xs text-muted-foreground">
{data.author ? (
<span
className="flex min-w-0 items-center gap-1.5 font-medium text-foreground"
title={data.author.login}
<PullRequestCopyText
value={data.author.login}
label={t({ message: "Copy username" })}
className="flex items-center gap-1.5 font-medium text-foreground"
>
<Avatar className="size-4 rounded-full ring-1 ring-border/50">
<AvatarImage
Expand All @@ -67,36 +70,43 @@ export function PullRequestItemHeader({
</AvatarFallback>
</Avatar>
<span className="truncate">{data.author.login}</span>
</span>
</PullRequestCopyText>
) : null}
{createdAtValid ? (
<>
<span aria-hidden>·</span>
<time
dateTime={data.createdAt}
title={formatDateTime(createdAt)}
<PullRequestCopyText
value={formatDateTime(createdAt)}
label={formatDateTime(createdAt)}
className="shrink-0"
>
{formatRelativeTime(createdAt)}
</time>
<time dateTime={data.createdAt}>
{formatRelativeTime(createdAt)}
</time>
</PullRequestCopyText>
</>
) : null}
<span aria-hidden>·</span>
<span
className="flex min-w-0 items-center gap-1.5 text-[11px] text-muted-foreground/80"
title={t({
message: `${data.head.ref} into ${data.base.ref}`,
})}
>
<span className="min-w-0 truncate" title={data.head.ref}>
<span className="flex min-w-0 items-center gap-1.5 text-[11px] text-muted-foreground/80">
<PullRequestCopyText
value={data.head.ref}
Comment thread
AviPeltz marked this conversation as resolved.
Resolved
label={t({ message: "Copy branch name" })}
className="truncate"
>
{data.head.ref}
</span>
</PullRequestCopyText>
<ArrowRight
aria-hidden
strokeWidth={1.75}
className="size-3.5 shrink-0"
/>
<span className="shrink-0">{data.base.ref}</span>
<PullRequestCopyText
value={data.base.ref}
label={t({ message: "Copy branch name" })}
className="shrink-0"
>
{data.base.ref}
</PullRequestCopyText>
</span>
</div>
{data.labels && data.labels.length > 0 ? (
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
import { useLingui } from "@lingui/react/macro";
import { Tooltip, TooltipContent, TooltipTrigger } from "@superset/ui/tooltip";
import { cn } from "@superset/ui/utils";
import { type ReactNode, useState } from "react";
import { useCopyToClipboard } from "renderer/hooks/useCopyToClipboard";

const FEEDBACK_MS = 1500;

interface PullRequestCopyTextProps {
/** What lands on the clipboard; also shown in full in the tooltip, since the text may be truncated. */
value: string;
/** The action, under the value in the tooltip. */
label: string;
children: ReactNode;
className?: string;
}

/** Header text that copies on click and says so. */
export function PullRequestCopyText({
value,
label,
children,
className,
}: PullRequestCopyTextProps) {
const { t } = useLingui();
const { copyToClipboard, copied } = useCopyToClipboard(FEEDBACK_MS);
const [failed, setFailed] = useState(false);
const copy = () => {
setFailed(false);
copyToClipboard(value).catch((error: unknown) => {
console.warn("[PullRequestCopyText] copy failed", error);
setFailed(true);
setTimeout(() => setFailed(false), FEEDBACK_MS);
});
};
return (
<Tooltip open={copied || failed ? true : undefined}>
<TooltipTrigger asChild>
<button
type="button"
onClick={copy}
className={cn(
"-mx-1 min-w-0 cursor-pointer rounded px-1 text-left transition-colors hover:bg-accent hover:text-foreground focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring",
className,
)}
>
{children}
</button>
</TooltipTrigger>
<TooltipContent side="bottom" className="max-w-sm">
{failed ? (
t({ message: "Copy failed" })
) : copied ? (
t({ message: "Copied" })
) : value === label ? (
label
) : (
<span className="flex flex-col gap-0.5">
<span className="break-all font-medium">{value}</span>
<span className="opacity-70">{label}</span>
</span>
)}
</TooltipContent>
</Tooltip>
);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { PullRequestCopyText } from "./PullRequestCopyText";
Loading
Loading