Skip to content
Draft
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
93 changes: 46 additions & 47 deletions apps/web/src/components/Sidebar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,6 @@ function buildThreadJumpLabelMap(input: {

interface SidebarThreadRowProps {
thread: SidebarThreadSummary;
projectCwd: string | null;
orderedProjectThreadKeys: readonly string[];
isActive: boolean;
jumpLabel: string | null;
Expand Down Expand Up @@ -313,6 +312,49 @@ interface SidebarThreadRowProps {
openPrLink: (event: React.MouseEvent<HTMLElement>, prUrl: string) => void;
}

function SidebarThreadPrStatusButton({
thread,
openPrLink,
}: {
thread: SidebarThreadSummary;
openPrLink: (event: React.MouseEvent<HTMLElement>, prUrl: string) => void;
}) {
const threadProjectCwd = useStore(
(state: import("../store").AppState) =>
selectProjectByRef(state, scopeProjectRef(thread.environmentId, thread.projectId))?.cwd ??
null,
);
const gitCwd = thread.worktreePath ?? threadProjectCwd;
const gitStatus = useGitStatus({
environmentId: thread.environmentId,
cwd: thread.branch != null ? gitCwd : null,
});
const pr = resolveThreadPr(thread.branch, gitStatus.data);
const prStatus = prStatusIndicator(pr, gitStatus.data?.sourceControlProvider);

if (!prStatus) {
return null;
}

return (
<Tooltip>
<TooltipTrigger
render={
<button
type="button"
aria-label={prStatus.tooltip}
className={`inline-flex items-center justify-center ${prStatus.colorClass} cursor-pointer rounded-sm outline-hidden focus-visible:ring-1 focus-visible:ring-ring`}
onClick={(event) => openPrLink(event, prStatus.url)}
>
<ChangeRequestStatusIcon className="size-3" />
</button>
}
/>
<TooltipPopup side="top">{prStatus.tooltip}</TooltipPopup>
</Tooltip>
);
}

const SidebarThreadRow = memo(function SidebarThreadRow(props: SidebarThreadRowProps) {
const {
orderedProjectThreadKeys,
Expand Down Expand Up @@ -358,22 +400,6 @@ const SidebarThreadRow = memo(function SidebarThreadRow(props: SidebarThreadRowP
const threadEnvironmentLabel = isRemoteThread
? (remoteEnvLabel ?? remoteEnvSavedLabel ?? "Remote")
: null;
// For grouped projects, the thread may belong to a different environment
// than the representative project. Look up the thread's own project cwd
// so git status (and thus PR detection) queries the correct path.
const threadProjectCwd = useStore(
useMemo(
() => (state: import("../store").AppState) =>
selectProjectByRef(state, scopeProjectRef(thread.environmentId, thread.projectId))?.cwd ??
null,
[thread.environmentId, thread.projectId],
),
);
const gitCwd = thread.worktreePath ?? threadProjectCwd ?? props.projectCwd;
const gitStatus = useGitStatus({
environmentId: thread.environmentId,
cwd: thread.branch != null ? gitCwd : null,
});
const isHighlighted = isActive || isSelected;
const isThreadRunning =
thread.session?.status === "running" && thread.session.activeTurnId != null;
Expand All @@ -383,8 +409,6 @@ const SidebarThreadRow = memo(function SidebarThreadRow(props: SidebarThreadRowP
lastVisitedAt,
},
});
const pr = resolveThreadPr(thread.branch, gitStatus.data);
const prStatus = prStatusIndicator(pr, gitStatus.data?.sourceControlProvider);
const terminalStatus = terminalStatusFromRunningIds(runningTerminalIds);
const isConfirmingArchive = confirmingArchiveThreadKey === threadKey && !isThreadRunning;
const threadMetaClassName = isConfirmingArchive
Expand Down Expand Up @@ -446,13 +470,6 @@ const SidebarThreadRow = memo(function SidebarThreadRow(props: SidebarThreadRowP
},
[clearSelection, handleMultiSelectContextMenu, handleThreadContextMenu, isSelected, threadRef],
);
const handlePrClick = useCallback(
(event: React.MouseEvent<HTMLButtonElement>) => {
if (!prStatus) return;
openPrLink(event, prStatus.url);
},
[openPrLink, prStatus],
);
const handleRenameInputRef = useCallback(
(element: HTMLInputElement | null) => {
if (element && renamingInputRef.current !== element) {
Expand Down Expand Up @@ -559,23 +576,9 @@ const SidebarThreadRow = memo(function SidebarThreadRow(props: SidebarThreadRowP
onContextMenu={handleRowContextMenu}
>
<div className="flex min-w-0 flex-1 items-center gap-1.5 text-left">
{prStatus && (
<Tooltip>
<TooltipTrigger
render={
<button
type="button"
aria-label={prStatus.tooltip}
className={`inline-flex items-center justify-center ${prStatus.colorClass} cursor-pointer rounded-sm outline-hidden focus-visible:ring-1 focus-visible:ring-ring`}
onClick={handlePrClick}
>
<ChangeRequestStatusIcon className="size-3" />
</button>
}
/>
<TooltipPopup side="top">{prStatus.tooltip}</TooltipPopup>
</Tooltip>
)}
{thread.branch !== null ? (
<SidebarThreadPrStatusButton thread={thread} openPrLink={openPrLink} />
) : null}
{threadStatus && <ThreadStatusLabel status={threadStatus} />}
{renamingThreadKey === threadKey ? (
<input
Expand Down Expand Up @@ -728,7 +731,6 @@ interface SidebarProjectThreadListProps {
showEmptyThreadState: boolean;
shouldShowThreadPanel: boolean;
isThreadListExpanded: boolean;
projectCwd: string;
activeRouteThreadKey: string | null;
threadJumpLabelByKey: ReadonlyMap<string, string>;
appSettingsConfirmThreadArchive: boolean;
Expand Down Expand Up @@ -778,7 +780,6 @@ const SidebarProjectThreadList = memo(function SidebarProjectThreadList(
showEmptyThreadState,
shouldShowThreadPanel,
isThreadListExpanded,
projectCwd,
activeRouteThreadKey,
threadJumpLabelByKey,
appSettingsConfirmThreadArchive,
Expand Down Expand Up @@ -828,7 +829,6 @@ const SidebarProjectThreadList = memo(function SidebarProjectThreadList(
<SidebarThreadRow
key={threadKey}
thread={thread}
projectCwd={projectCwd}
orderedProjectThreadKeys={orderedProjectThreadKeys}
isActive={activeRouteThreadKey === threadKey}
jumpLabel={threadJumpLabelByKey.get(threadKey) ?? null}
Expand Down Expand Up @@ -2082,7 +2082,6 @@ const SidebarProjectItem = memo(function SidebarProjectItem(props: SidebarProjec
showEmptyThreadState={showEmptyThreadState}
shouldShowThreadPanel={shouldShowThreadPanel}
isThreadListExpanded={isThreadListExpanded}
projectCwd={project.cwd}
activeRouteThreadKey={activeRouteThreadKey}
threadJumpLabelByKey={threadJumpLabelByKey}
appSettingsConfirmThreadArchive={appSettingsConfirmThreadArchive}
Expand Down
Binary file not shown.
Binary file not shown.
Loading