fix(web): show pull request state icons in tabs (#9112)
Co-authored-by: maria-rcks <[email protected]>
This commit is contained in:
1 parent
ba3cb07738
commit
1eb36b45ef
7 files changed
+86
-134
No files matched your search
@@ -150,7 +150,6 @@ import {
|
||||
selectActiveRightPanelSurface,
|
||||
selectThreadRightPanelState,
|
||||
type RightPanelSurface,
|
||||
updatePullRequestTabStatus,
|
||||
useRightPanelStore,
|
||||
} from "../rightPanelStore";
|
||||
import {
|
||||
@@ -1786,21 +1785,6 @@ function ChatViewContent(props: ChatViewProps) {
|
||||
const activeRightPanelSurface = useRightPanelStore((state) =>
|
||||
selectActiveRightPanelSurface(state.byThreadKey, activeThreadRef),
|
||||
);
|
||||
const [pullRequestTabStatuses, setPullRequestTabStatuses] = useState<
|
||||
Record<string, PullRequestTabStatus>
|
||||
>({});
|
||||
// Keyed by the surface the panel is showing rather than by a key rebuilt from the status, so
|
||||
// the tab is found again whether or not that surface was opened with an environment on it.
|
||||
const activePullRequestSurfaceId =
|
||||
activeRightPanelSurface?.kind === "pull-request" ? activeRightPanelSurface.id : undefined;
|
||||
const updatePullRequestTabStatusFromPanel = useCallback(
|
||||
(status: PullRequestTabStatus) => {
|
||||
const id = activePullRequestSurfaceId;
|
||||
if (id === undefined) return;
|
||||
setPullRequestTabStatuses((current) => updatePullRequestTabStatus(current, id, status));
|
||||
},
|
||||
[activePullRequestSurfaceId],
|
||||
);
|
||||
const refreshVcsStatus = useAtomCommand(vcsEnvironment.refreshStatus, { reportFailure: false });
|
||||
const sidebarPrRefreshKeyRef = useRef<string | null>(null);
|
||||
const activePreviewState = useThreadPreviewState(activeThreadRef);
|
||||
@@ -4683,7 +4667,6 @@ function ChatViewContent(props: ChatViewProps) {
|
||||
});
|
||||
const handlePullRequestTabStatusChange = useCallback(
|
||||
(status: PullRequestTabStatus) => {
|
||||
updatePullRequestTabStatusFromPanel(status);
|
||||
const source = threadPullRequestRefreshSource({
|
||||
panel: status,
|
||||
thread: {
|
||||
@@ -4734,7 +4717,6 @@ function ChatViewContent(props: ChatViewProps) {
|
||||
linkedThreadPullRequest,
|
||||
refreshVcsStatus,
|
||||
threadRepository,
|
||||
updatePullRequestTabStatusFromPanel,
|
||||
],
|
||||
);
|
||||
const activeThreadReferenceCopyTarget = useMemo(
|
||||
@@ -7719,6 +7701,7 @@ function ChatViewContent(props: ChatViewProps) {
|
||||
open={rightPanelOpen}
|
||||
maximized={rightPanelMaximized}
|
||||
surfaces={renderedRightPanelSurfaces}
|
||||
environmentId={activeThreadRef.environmentId}
|
||||
activeSurfaceId={renderedRightPanelSurface?.id ?? null}
|
||||
pendingSurfaceIds={pendingFileSurfaceIds}
|
||||
previewSessions={activePreviewState.sessions}
|
||||
@@ -7744,7 +7727,6 @@ function ChatViewContent(props: ChatViewProps) {
|
||||
filesAvailable={activeProject !== null}
|
||||
pullRequestAvailable={pullRequestSurfaceAvailable}
|
||||
agentsAvailable
|
||||
pullRequestStatuses={pullRequestTabStatuses}
|
||||
liveAgentCount={agentPanelModel.liveCount}
|
||||
>
|
||||
{rightPanelContent}
|
||||
@@ -7768,6 +7750,7 @@ function ChatViewContent(props: ChatViewProps) {
|
||||
) : null
|
||||
}
|
||||
surfaces={renderedRightPanelSurfaces}
|
||||
environmentId={activeThreadRef.environmentId}
|
||||
activeSurfaceId={renderedRightPanelSurface?.id ?? null}
|
||||
pendingSurfaceIds={pendingFileSurfaceIds}
|
||||
previewSessions={activePreviewState.sessions}
|
||||
@@ -7793,7 +7776,6 @@ function ChatViewContent(props: ChatViewProps) {
|
||||
filesAvailable={activeProject !== null}
|
||||
pullRequestAvailable={pullRequestSurfaceAvailable}
|
||||
agentsAvailable
|
||||
pullRequestStatuses={pullRequestTabStatuses}
|
||||
liveAgentCount={agentPanelModel.liveCount}
|
||||
>
|
||||
{rightPanelContent}
|
||||
|
||||
@@ -97,6 +97,7 @@ function renderTabs(
|
||||
<RightPanelTabs
|
||||
mode="inline"
|
||||
surfaces={second ? [previewSurface, secondSurface] : [previewSurface]}
|
||||
environmentId={null}
|
||||
activeSurfaceId={previewSurface.id}
|
||||
pendingSurfaceIds={new Set()}
|
||||
previewSessions={sessions}
|
||||
|
||||
@@ -1,4 +1,10 @@
|
||||
import type { ContextMenuItem, PreviewSessionSnapshot, PullRequestState } from "@t3tools/contracts";
|
||||
import type {
|
||||
ContextMenuItem,
|
||||
EnvironmentId,
|
||||
PreviewSessionSnapshot,
|
||||
ProjectId,
|
||||
PullRequestState,
|
||||
} from "@t3tools/contracts";
|
||||
import { getTerminalLabel } from "@t3tools/shared/terminalLabels";
|
||||
import {
|
||||
Bot,
|
||||
@@ -45,12 +51,15 @@ import { ScrollArea } from "~/components/ui/scroll-area";
|
||||
import { PanelTabCloseButton } from "~/components/ui/panel-tab-close-button";
|
||||
import { faviconUrlForOrigin } from "~/lib/favicon";
|
||||
import { useTheme } from "~/hooks/useTheme";
|
||||
import { pullRequestEnvironment } from "~/state/pullRequests";
|
||||
import { useEnvironmentQuery } from "~/state/query";
|
||||
import { COLLAPSED_SIDEBAR_TITLEBAR_INSET_CLASS } from "~/workspaceTitlebar";
|
||||
|
||||
import { PreviewPanelShell, type PreviewPanelMode } from "./preview/PreviewPanelShell";
|
||||
import { FaviconImage } from "./preview/PreviewFaviconIcon";
|
||||
import { previewBridge } from "./preview/previewBridge";
|
||||
import { PierreEntryIcon } from "./chat/PierreEntryIcon";
|
||||
import { resolvePullRequestState } from "./pullRequest/pullRequestPresentation";
|
||||
|
||||
interface RightPanelTabsProps {
|
||||
mode: PreviewPanelMode;
|
||||
@@ -62,6 +71,8 @@ interface RightPanelTabsProps {
|
||||
defaultWidth?: number;
|
||||
layoutControls?: ReactNode;
|
||||
surfaces: readonly RightPanelSurface[];
|
||||
/** Fallback environment for surfaces that do not carry their own. */
|
||||
environmentId: EnvironmentId | null;
|
||||
activeSurfaceId: string | null;
|
||||
pendingSurfaceIds: ReadonlySet<string>;
|
||||
previewSessions: Readonly<Record<string, PreviewSessionSnapshot>>;
|
||||
@@ -97,7 +108,7 @@ interface RightPanelTabsProps {
|
||||
filesAvailable: boolean;
|
||||
pullRequestAvailable: boolean;
|
||||
agentsAvailable: boolean;
|
||||
pullRequestStatuses?: Readonly<Record<string, PullRequestTabStatus>>;
|
||||
pullRequestStatusSeeds?: Readonly<Record<string, PullRequestTabStatusSeed>>;
|
||||
/** Running + waiting subagents; badges the Agents card in the empty state. */
|
||||
liveAgentCount: number;
|
||||
children: ReactNode;
|
||||
@@ -111,6 +122,8 @@ export interface PullRequestTabStatus {
|
||||
isDraft: boolean;
|
||||
}
|
||||
|
||||
export type PullRequestTabStatusSeed = Pick<PullRequestTabStatus, "state" | "isDraft">;
|
||||
|
||||
export function shouldOpenDefaultBrowserProfileFromMenuClick(
|
||||
pointerType: string | undefined,
|
||||
): boolean {
|
||||
@@ -570,13 +583,15 @@ function SurfaceIcon({
|
||||
sessions,
|
||||
desktopByTabId,
|
||||
theme,
|
||||
pullRequestStatuses,
|
||||
environmentId,
|
||||
pullRequestStatusSeeds,
|
||||
}: {
|
||||
surface: RightPanelSurface;
|
||||
sessions: Readonly<Record<string, PreviewSessionSnapshot>>;
|
||||
desktopByTabId: Readonly<Record<string, DesktopPreviewOverlay>>;
|
||||
theme: "light" | "dark";
|
||||
pullRequestStatuses: Readonly<Record<string, PullRequestTabStatus>> | undefined;
|
||||
environmentId: EnvironmentId | null;
|
||||
pullRequestStatusSeeds: Readonly<Record<string, PullRequestTabStatusSeed>> | undefined;
|
||||
}) {
|
||||
switch (surface.kind) {
|
||||
case "preview": {
|
||||
@@ -602,25 +617,53 @@ function SurfaceIcon({
|
||||
);
|
||||
case "terminal":
|
||||
return <TerminalSquare className="size-3 shrink-0" />;
|
||||
case "pull-request": {
|
||||
const status = pullRequestStatuses?.[surface.id] ?? null;
|
||||
const toneClassName =
|
||||
status?.state === "merged"
|
||||
? "text-violet-600 dark:text-violet-300/90"
|
||||
: status?.state === "closed"
|
||||
? "text-red-600 dark:text-red-300/90"
|
||||
: status?.isDraft
|
||||
? "text-zinc-500 dark:text-zinc-400/80"
|
||||
: status?.state === "open"
|
||||
? "text-emerald-600 dark:text-emerald-300/90"
|
||||
: "text-muted-foreground";
|
||||
return <GitPullRequest className={cn("size-3 shrink-0", toneClassName)} />;
|
||||
}
|
||||
case "pull-request":
|
||||
return (
|
||||
<PullRequestSurfaceIcon
|
||||
surface={surface}
|
||||
environmentId={environmentId}
|
||||
seed={pullRequestStatusSeeds?.[surface.id]}
|
||||
/>
|
||||
);
|
||||
case "agents":
|
||||
return <Bot className="size-3 shrink-0" />;
|
||||
}
|
||||
}
|
||||
|
||||
function PullRequestSurfaceIcon({
|
||||
surface,
|
||||
environmentId,
|
||||
seed,
|
||||
}: {
|
||||
surface: Extract<RightPanelSurface, { kind: "pull-request" }>;
|
||||
environmentId: EnvironmentId | null;
|
||||
seed: PullRequestTabStatusSeed | undefined;
|
||||
}) {
|
||||
const resolvedEnvironmentId =
|
||||
(surface.environmentId as EnvironmentId | undefined) ?? environmentId;
|
||||
const detail = useEnvironmentQuery(
|
||||
resolvedEnvironmentId === null
|
||||
? null
|
||||
: pullRequestEnvironment.detail({
|
||||
environmentId: resolvedEnvironmentId,
|
||||
input: {
|
||||
projectId: surface.projectId as ProjectId,
|
||||
repository: surface.repository,
|
||||
number: surface.number,
|
||||
},
|
||||
}),
|
||||
).data;
|
||||
// Only state and draft reach the tab. A list seed cannot know mergeability, so feeding the
|
||||
// full detail would flip an open tab to the conflict glyph the moment its read lands.
|
||||
const status =
|
||||
detail === null ? (seed ?? null) : { state: detail.state, isDraft: detail.isDraft };
|
||||
if (status === null) {
|
||||
return <GitPullRequest className="size-3 shrink-0 text-muted-foreground" />;
|
||||
}
|
||||
const presentation = resolvePullRequestState(status);
|
||||
return <presentation.Icon className={cn("size-3 shrink-0", presentation.toneClassName)} />;
|
||||
}
|
||||
|
||||
export function RightPanelTabs(props: RightPanelTabsProps) {
|
||||
const ownsDesktopTitleBar = isElectron && props.mode === "inline";
|
||||
const browserProfiles = useBrowserDefaults().profiles;
|
||||
@@ -859,7 +902,8 @@ export function RightPanelTabs(props: RightPanelTabsProps) {
|
||||
sessions={props.previewSessions}
|
||||
desktopByTabId={props.desktopByTabId}
|
||||
theme={resolvedTheme}
|
||||
pullRequestStatuses={props.pullRequestStatuses}
|
||||
environmentId={props.environmentId}
|
||||
pullRequestStatusSeeds={props.pullRequestStatusSeeds}
|
||||
/>
|
||||
{pending ? (
|
||||
<span
|
||||
|
||||
@@ -450,7 +450,7 @@ export function PullRequestDetailPanel({
|
||||
onActed?: () => void;
|
||||
/** Page-owned detail columns use this to clear the selected pull request. */
|
||||
onClose?: () => void;
|
||||
/** Keeps compact chrome, such as the right-panel tab, in step with refreshed host state. */
|
||||
/** Keeps surrounding thread state in step with refreshed host state. */
|
||||
onStateChange?: (status: {
|
||||
projectId: string;
|
||||
repository: string;
|
||||
|
||||
@@ -9,7 +9,6 @@ import {
|
||||
selectActiveRightPanelSurface,
|
||||
selectSelectedRightPanelSurface,
|
||||
selectThreadRightPanelState,
|
||||
updatePullRequestTabStatus,
|
||||
useRightPanelStore,
|
||||
} from "./rightPanelStore";
|
||||
|
||||
@@ -485,62 +484,6 @@ describe("rightPanelStore", () => {
|
||||
).toEqual([]);
|
||||
});
|
||||
|
||||
describe("updatePullRequestTabStatus", () => {
|
||||
const status = (isDraft: boolean) => ({
|
||||
projectId: "project-a",
|
||||
repository: "pingdotgg/t3code",
|
||||
number: 4909,
|
||||
state: "open" as const,
|
||||
isDraft,
|
||||
});
|
||||
|
||||
// Regression for the tab wearing no state: this failed when the status was written under a
|
||||
// key rebuilt from the pull request while the tab strip reads it under the surface's own id.
|
||||
it("keys a status under the same id a surface opened from an environment carries", () => {
|
||||
const target = {
|
||||
environmentId: "remote",
|
||||
projectId: "project-a",
|
||||
repository: "pingdotgg/t3code",
|
||||
number: 4909,
|
||||
};
|
||||
useRightPanelStore.getState().openPullRequest(refA, target);
|
||||
const surface = selectSelectedRightPanelSurface(
|
||||
useRightPanelStore.getState().byThreadKey,
|
||||
refA,
|
||||
);
|
||||
expect(surface).not.toBeNull();
|
||||
|
||||
const statuses = updatePullRequestTabStatus({}, surface!.id, status(false));
|
||||
expect(statuses[surface!.id]).toEqual(status(false));
|
||||
});
|
||||
|
||||
it("keys a status under the same id a thread surface with no environment carries", () => {
|
||||
const target = { projectId: "project-a", repository: "pingdotgg/t3code", number: 4909 };
|
||||
useRightPanelStore.getState().openPullRequest(refA, target);
|
||||
const surface = selectSelectedRightPanelSurface(
|
||||
useRightPanelStore.getState().byThreadKey,
|
||||
refA,
|
||||
);
|
||||
expect(surface).not.toBeNull();
|
||||
|
||||
const statuses = updatePullRequestTabStatus({}, surface!.id, status(false));
|
||||
expect(statuses[surface!.id]).toEqual(status(false));
|
||||
});
|
||||
|
||||
it("returns the identical map when the tab's state and draft flag are unchanged", () => {
|
||||
const first = updatePullRequestTabStatus({}, "pull-request:1", status(false));
|
||||
const second = updatePullRequestTabStatus(first, "pull-request:1", status(false));
|
||||
expect(second).toBe(first);
|
||||
});
|
||||
|
||||
it("replaces the entry when the draft flag changes", () => {
|
||||
const first = updatePullRequestTabStatus({}, "pull-request:1", status(false));
|
||||
const second = updatePullRequestTabStatus(first, "pull-request:1", status(true));
|
||||
expect(second).not.toBe(first);
|
||||
expect(second["pull-request:1"]).toEqual(status(true));
|
||||
});
|
||||
});
|
||||
|
||||
it("tracks one surface per terminal session", () => {
|
||||
useRightPanelStore.getState().openTerminal(refA, "term-1");
|
||||
useRightPanelStore.getState().openTerminal(refA, "term-2");
|
||||
|
||||
@@ -196,23 +196,6 @@ export function pullRequestSurface(target: {
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* A pull-request tab's status map with one entry set. Keyed by the surface the panel is showing
|
||||
* rather than by a key rebuilt from the status, so the tab is found again whether or not that
|
||||
* surface was opened with an environment on it. Returns the same map when the tab's own fields
|
||||
* have not changed, so a caller can skip a re-render.
|
||||
*/
|
||||
export function updatePullRequestTabStatus<Status extends { state: unknown; isDraft: boolean }>(
|
||||
statuses: Readonly<Record<string, Status>>,
|
||||
surfaceId: string,
|
||||
status: Status,
|
||||
): Readonly<Record<string, Status>> {
|
||||
return statuses[surfaceId]?.state === status.state &&
|
||||
statuses[surfaceId]?.isDraft === status.isDraft
|
||||
? statuses
|
||||
: { ...statuses, [surfaceId]: status };
|
||||
}
|
||||
|
||||
const upsertSurface = (
|
||||
current: ThreadRightPanelState,
|
||||
surface: RightPanelSurface,
|
||||
|
||||
@@ -91,7 +91,7 @@ import { PullRequestListEmptyState } from "../components/pullRequest/PullRequest
|
||||
import { PullRequestListGhost } from "../components/pullRequest/PullRequestGhosts";
|
||||
import { PullRequestRow } from "../components/pullRequest/PullRequestRow";
|
||||
import { PullRequestsUnavailableState } from "../components/pullRequest/PullRequestsUnavailableState";
|
||||
import { RightPanelTabs, type PullRequestTabStatus } from "../components/RightPanelTabs";
|
||||
import { RightPanelTabs, type PullRequestTabStatusSeed } from "../components/RightPanelTabs";
|
||||
import {
|
||||
WorkspaceBreadcrumb,
|
||||
WorkspaceBreadcrumbItem,
|
||||
@@ -109,10 +109,10 @@ import { useLiveRefresh } from "../hooks/useLiveRefresh";
|
||||
import { usePanelAnimationSettings, usePanelPresence } from "../panelAnimations";
|
||||
import { toSortableTimestamp } from "../lib/threadSort";
|
||||
import {
|
||||
pullRequestSurfaceId,
|
||||
selectActiveRightPanelSurface,
|
||||
selectSelectedRightPanelSurface,
|
||||
selectThreadRightPanelState,
|
||||
updatePullRequestTabStatus,
|
||||
useRightPanelStore,
|
||||
type PullRequestSurface,
|
||||
} from "../rightPanelStore";
|
||||
@@ -475,22 +475,6 @@ function PullRequestsRouteView() {
|
||||
(renderedPullRequestSurface?.environmentId as EnvironmentId | undefined) ??
|
||||
selectedProject?.environmentId ??
|
||||
null;
|
||||
const [pullRequestTabStatuses, setPullRequestTabStatuses] = useState<
|
||||
Record<string, PullRequestTabStatus>
|
||||
>({});
|
||||
// Keyed by the surface the panel is showing rather than by a key rebuilt from the status: a
|
||||
// surface opened from this page carries the environment its row was listed under, and a key
|
||||
// assembled from the pull request alone would never name that surface back.
|
||||
const activePullRequestSurfaceId = activePullRequestSurface?.id;
|
||||
const handlePullRequestTabStatusChange = useCallback(
|
||||
(status: PullRequestTabStatus) => {
|
||||
const id = activePullRequestSurfaceId;
|
||||
if (id === undefined) return;
|
||||
setPullRequestTabStatuses((current) => updatePullRequestTabStatus(current, id, status));
|
||||
},
|
||||
[activePullRequestSurfaceId],
|
||||
);
|
||||
|
||||
const updateSearch = useCallback(
|
||||
(patch: {
|
||||
[Key in keyof PullRequestsSearch]?: PullRequestsSearch[Key] | undefined;
|
||||
@@ -1182,6 +1166,21 @@ function PullRequestsRouteView() {
|
||||
viewers,
|
||||
]);
|
||||
|
||||
// Seed the first tab paint from list rows while each tab's cached detail read lands.
|
||||
const listedPullRequestTabStatuses = useMemo<Record<string, PullRequestTabStatusSeed>>(
|
||||
() =>
|
||||
Object.fromEntries(
|
||||
entries.map((entry) => [
|
||||
pullRequestSurfaceId(entry),
|
||||
{
|
||||
state: entry.state,
|
||||
isDraft: entry.isDraft,
|
||||
},
|
||||
]),
|
||||
),
|
||||
[entries],
|
||||
);
|
||||
|
||||
const scrollRef = useRef<HTMLDivElement>(null);
|
||||
const sentinelRef = useRef<HTMLDivElement>(null);
|
||||
useEffect(() => {
|
||||
@@ -1889,6 +1888,7 @@ function PullRequestsRouteView() {
|
||||
// it. SSR has no window, so fall back to a reasonable width.
|
||||
defaultWidth={typeof window === "undefined" ? 640 : Math.floor(window.innerWidth / 2)}
|
||||
surfaces={renderedRightPanelSurfaces}
|
||||
environmentId={panelEnvironmentId}
|
||||
activeSurfaceId={renderedPullRequestSurface.id}
|
||||
pendingSurfaceIds={EMPTY_PENDING_SURFACES}
|
||||
previewSessions={EMPTY_PREVIEW_SESSIONS}
|
||||
@@ -1922,7 +1922,7 @@ function PullRequestsRouteView() {
|
||||
pullRequestAvailable={false}
|
||||
agentsAvailable={false}
|
||||
liveAgentCount={0}
|
||||
pullRequestStatuses={pullRequestTabStatuses}
|
||||
pullRequestStatusSeeds={listedPullRequestTabStatuses}
|
||||
>
|
||||
<PullRequestDetailPanel
|
||||
key={renderedPullRequestSurface.id}
|
||||
@@ -1941,7 +1941,6 @@ function PullRequestsRouteView() {
|
||||
authoredQuery.refresh();
|
||||
reviewingQuery.refresh();
|
||||
}}
|
||||
onStateChange={handlePullRequestTabStatusChange}
|
||||
/>
|
||||
</RightPanelTabs>
|
||||
) : null}
|
||||
|
||||
Reference in new issue
Block a user