Skip to content

Commit d5465ae

Browse files
sebbonitjuliusmarmingecodex
authored
fix(web): retain terminal PR badges after checkout switch (pingdotgg#4755)
Co-authored-by: Julius Marminge <[email protected]> Co-authored-by: codex <[email protected]>
1 parent d715c2e commit d5465ae

4 files changed

Lines changed: 618 additions & 36 deletions

File tree

‎apps/web/src/components/ChatView.tsx‎

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,10 @@ import {
276276
shouldShowThreadErrorBanner,
277277
ThreadErrorBanner,
278278
} from "./chat/ThreadErrorBanner";
279-
import { resolveThreadPr } from "./ThreadStatusIndicators";
279+
import {
280+
resolveDisplayedThreadPr,
281+
threadChangeRequestSnapshotsAtom,
282+
} from "./ThreadStatusIndicators";
280283
import { ComposerBannerStack, type ComposerBannerStackItem } from "./chat/ComposerBannerStack";
281284
import { ThreadSyncStatusPill } from "./chat/ThreadSyncStatusPill";
282285
import {
@@ -1596,6 +1599,7 @@ function ChatViewContent(props: ChatViewProps) {
15961599
[activeThreadEnvironmentId, activeThreadId],
15971600
);
15981601
const activeThreadKey = activeThreadRef ? scopedThreadKey(activeThreadRef) : null;
1602+
const changeRequestSnapshotByKey = useAtomValue(threadChangeRequestSnapshotsAtom);
15991603
const [timelineAnchor, setTimelineAnchor] = useState<{
16001604
readonly threadKey: string | null;
16011605
readonly messageId: MessageId | null;
@@ -4124,9 +4128,11 @@ function ChatViewContent(props: ChatViewProps) {
41244128
const activeThreadShell = useThreadShell(isServerThread ? activeThreadRef : null);
41254129
const autoSettleAfterDays = useClientSettings((settings) => settings.sidebarAutoSettleAfterDays);
41264130
const autoSettleOnMerge = useClientSettings((settings) => settings.sidebarAutoSettleOnMerge);
4127-
const activeThreadPr = resolveThreadPr({
4131+
const activeThreadPr = resolveDisplayedThreadPr({
41284132
threadBranch: activeThread?.branch ?? null,
41294133
gitStatus: gitStatusQuery.data ?? null,
4134+
snapshot: activeThreadKey ? changeRequestSnapshotByKey.get(activeThreadKey) : undefined,
4135+
retainTerminalOnBranchMismatch: activeThread?.worktreePath === null,
41304136
});
41314137
// The right panel offers the thread's own change request, so it can only offer it once the
41324138
// branch has one; until then the picker says so rather than opening an empty panel.
@@ -4208,6 +4214,7 @@ function ChatViewContent(props: ChatViewProps) {
42084214
activeThreadShell,
42094215
autoSettleAfterDays,
42104216
autoSettleOnMerge,
4217+
changeRequestSnapshotByKey,
42114218
nowMinute,
42124219
supportsSettlement,
42134220
]);

‎apps/web/src/components/Sidebar.tsx‎

Lines changed: 49 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -143,10 +143,15 @@ import {
143143
import { resolveLocalCheckoutBranchMismatch } from "./BranchToolbar.logic";
144144
import {
145145
ThreadWorktreeIndicator,
146+
nextThreadChangeRequestSnapshot,
146147
prStatusIndicator,
147-
resolveThreadPr,
148+
resolveDisplayedThreadPr,
149+
resolveDisplayedThreadPrProvider,
150+
setThreadChangeRequestSnapshot,
148151
settledPrHoverColorClass,
149152
terminalStatusFromRunningIds,
153+
threadChangeRequestSnapshotsAtom,
154+
type ThreadChangeRequestSnapshot,
150155
type TerminalStatusIndicator,
151156
} from "./ThreadStatusIndicators";
152157
import {
@@ -729,11 +734,16 @@ const SidebarThreadRow = memo(function SidebarThreadRow(props: {
729734
onUnsnooze: (threadRef: ScopedThreadRef) => void;
730735
onUnpin: (threadRef: ScopedThreadRef) => void;
731736
onAcknowledgeWoke: (threadRef: ScopedThreadRef, visitedAt: string) => void;
732-
onChangeRequestState: (threadKey: string, state: "open" | "closed" | "merged" | null) => void;
737+
changeRequestSnapshot: ThreadChangeRequestSnapshot | null;
738+
onChangeRequestSnapshot: (
739+
threadKey: string,
740+
snapshot: ThreadChangeRequestSnapshot | null,
741+
) => void;
733742
}) {
734743
const {
735744
isRenaming,
736-
onChangeRequestState,
745+
changeRequestSnapshot,
746+
onChangeRequestSnapshot,
737747
onCancelRename,
738748
onCommitRename,
739749
onContextMenu,
@@ -778,9 +788,12 @@ const SidebarThreadRow = memo(function SidebarThreadRow(props: {
778788
})
779789
: null,
780790
);
781-
const pr = resolveThreadPr({
791+
const retainTerminalOnBranchMismatch = thread.worktreePath === null;
792+
const pr = resolveDisplayedThreadPr({
782793
threadBranch: thread.branch,
783794
gitStatus: gitStatus.data,
795+
snapshot: changeRequestSnapshot,
796+
retainTerminalOnBranchMismatch,
784797
});
785798
const prState = pr?.state ?? null;
786799

@@ -874,13 +887,31 @@ const SidebarThreadRow = memo(function SidebarThreadRow(props: {
874887
activeThreadBranch: thread.branch,
875888
currentGitBranch: gitStatus.data?.refName ?? null,
876889
});
877-
const prStatus = prStatusIndicator(pr, gitStatus.data?.sourceControlProvider);
890+
const prProvider = resolveDisplayedThreadPrProvider({
891+
threadBranch: thread.branch,
892+
gitStatus: gitStatus.data,
893+
snapshot: changeRequestSnapshot,
894+
retainTerminalOnBranchMismatch,
895+
});
896+
const prStatus = prStatusIndicator(pr, prProvider);
878897
const settledPrHoverClass = pr ? settledPrHoverColorClass(pr.state) : undefined;
879-
// Report the PR state so the parent can apply the configured merge rule
880-
// and the always-on close rule during partitioning.
881898
useEffect(() => {
882-
onChangeRequestState(threadKey, prState);
883-
}, [onChangeRequestState, prState, threadKey]);
899+
const nextSnapshot = nextThreadChangeRequestSnapshot({
900+
threadBranch: thread.branch,
901+
gitStatus: gitStatus.data,
902+
snapshot: changeRequestSnapshot,
903+
retainTerminalOnBranchMismatch,
904+
});
905+
if (nextSnapshot === undefined) return;
906+
onChangeRequestSnapshot(threadKey, nextSnapshot);
907+
}, [
908+
changeRequestSnapshot,
909+
gitStatus.data,
910+
onChangeRequestSnapshot,
911+
retainTerminalOnBranchMismatch,
912+
thread.branch,
913+
threadKey,
914+
]);
884915

885916
const modelInstanceId = thread.session?.providerInstanceId ?? thread.modelSelection.instanceId;
886917
const providerEntry = props.providerEntryByInstanceId.get(modelInstanceId) ?? null;
@@ -1858,26 +1889,7 @@ export default function Sidebar() {
18581889
// fresh clock whenever it recomputes.
18591890
const [snoozeWakeTick, bumpSnoozeWakeTick] = useState(0);
18601891

1861-
// PR states stream in per-row. The next partition applies the configured
1862-
// merge rule and the always-on close rule.
1863-
const [changeRequestStateByKey, setChangeRequestStateByKey] = useState<
1864-
ReadonlyMap<string, "open" | "closed" | "merged">
1865-
>(() => new Map());
1866-
const handleChangeRequestState = useCallback(
1867-
(threadKey: string, state: "open" | "closed" | "merged" | null) => {
1868-
setChangeRequestStateByKey((current) => {
1869-
if ((current.get(threadKey) ?? null) === state) return current;
1870-
const next = new Map(current);
1871-
if (state === null) {
1872-
next.delete(threadKey);
1873-
} else {
1874-
next.set(threadKey, state);
1875-
}
1876-
return next;
1877-
});
1878-
},
1879-
[],
1880-
);
1892+
const changeRequestSnapshotByKey = useAtomValue(threadChangeRequestSnapshotsAtom);
18811893

18821894
// Project scope: one menu above the list. Scoping filters the list without
18831895
// making the header width depend on the number or length of project names.
@@ -1993,7 +2005,11 @@ export default function Sidebar() {
19932005
const supportsSnooze =
19942006
serverConfigs.get(thread.environmentId)?.environment.capabilities.threadSnooze === true;
19952007
const threadKey = scopedThreadKey(scopeThreadRef(thread.environmentId, thread.id));
1996-
const changeRequestState = changeRequestStateByKey.get(threadKey) ?? null;
2008+
const snapshot = changeRequestSnapshotByKey.get(threadKey);
2009+
const changeRequestState =
2010+
snapshot != null && (thread.worktreePath === null || snapshot.branch === thread.branch)
2011+
? snapshot.pr.state
2012+
: null;
19972013
// Snooze outranks everything, including a pin: "hide until Tuesday"
19982014
// temporarily suspends "keep on top". The pin survives underneath —
19992015
// and so does its pinOrderKey, so on wake the thread reappears at
@@ -2051,7 +2067,7 @@ export default function Sidebar() {
20512067
}, [
20522068
autoSettleAfterDays,
20532069
autoSettleOnMerge,
2054-
changeRequestStateByKey,
2070+
changeRequestSnapshotByKey,
20552071
nowMinute,
20562072
scopedProjectKeys,
20572073
serverConfigs,
@@ -3686,7 +3702,8 @@ export default function Sidebar() {
36863702
onUnsnooze={attemptUnsnooze}
36873703
onUnpin={attemptUnpin}
36883704
onAcknowledgeWoke={acknowledgeWoke}
3689-
onChangeRequestState={handleChangeRequestState}
3705+
changeRequestSnapshot={changeRequestSnapshotByKey.get(threadKey) ?? null}
3706+
onChangeRequestSnapshot={setThreadChangeRequestSnapshot}
36903707
/>
36913708
);
36923709
};

0 commit comments

Comments
 (0)