Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
8580032a5f |
No files matched your search
@@ -15,6 +15,7 @@ import {
|
||||
resolveSidebarNewThreadSeedContext,
|
||||
resolveSidebarNewThreadEnvMode,
|
||||
resolveSidebarStageBadgeLabel,
|
||||
resolveSidebarThreadRowTransientProps,
|
||||
resolveThreadRowClassName,
|
||||
resolveThreadStatusPill,
|
||||
shouldClearThreadSelectionOnMouseDown,
|
||||
@@ -38,6 +39,51 @@ import {
|
||||
|
||||
const localEnvironmentId = EnvironmentId.make("environment-local");
|
||||
|
||||
describe("resolveSidebarThreadRowTransientProps", () => {
|
||||
it("only publishes rename state to the row being edited", () => {
|
||||
expect(
|
||||
resolveSidebarThreadRowTransientProps({
|
||||
threadKey: "thread-1",
|
||||
renamingThreadKey: "thread-1",
|
||||
renamingTitle: "Edited title",
|
||||
confirmingArchiveThreadKey: null,
|
||||
}),
|
||||
).toEqual({
|
||||
isRenaming: true,
|
||||
renamingTitle: "Edited title",
|
||||
isConfirmingArchive: false,
|
||||
});
|
||||
|
||||
expect(
|
||||
resolveSidebarThreadRowTransientProps({
|
||||
threadKey: "thread-2",
|
||||
renamingThreadKey: "thread-1",
|
||||
renamingTitle: "Edited title",
|
||||
confirmingArchiveThreadKey: null,
|
||||
}),
|
||||
).toEqual({
|
||||
isRenaming: false,
|
||||
renamingTitle: "",
|
||||
isConfirmingArchive: false,
|
||||
});
|
||||
});
|
||||
|
||||
it("only publishes archive confirmation state to its target row", () => {
|
||||
expect(
|
||||
resolveSidebarThreadRowTransientProps({
|
||||
threadKey: "thread-2",
|
||||
renamingThreadKey: null,
|
||||
renamingTitle: "",
|
||||
confirmingArchiveThreadKey: "thread-2",
|
||||
}),
|
||||
).toEqual({
|
||||
isRenaming: false,
|
||||
renamingTitle: "",
|
||||
isConfirmingArchive: true,
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe("resolveSidebarStageBadgeLabel", () => {
|
||||
it("returns Nightly for nightly primary server versions", () => {
|
||||
expect(
|
||||
|
||||
@@ -17,6 +17,25 @@ export const THREAD_JUMP_HINT_SHOW_DELAY_MS = 100;
|
||||
// nearby thread usually reuses an already-hot subscription.
|
||||
export const SIDEBAR_THREAD_PREWARM_LIMIT = 10;
|
||||
export type SidebarNewThreadEnvMode = "local" | "worktree";
|
||||
|
||||
export function resolveSidebarThreadRowTransientProps(input: {
|
||||
threadKey: string;
|
||||
renamingThreadKey: string | null;
|
||||
renamingTitle: string;
|
||||
confirmingArchiveThreadKey: string | null;
|
||||
}): {
|
||||
isRenaming: boolean;
|
||||
renamingTitle: string;
|
||||
isConfirmingArchive: boolean;
|
||||
} {
|
||||
const isRenaming = input.renamingThreadKey === input.threadKey;
|
||||
return {
|
||||
isRenaming,
|
||||
renamingTitle: isRenaming ? input.renamingTitle : "",
|
||||
isConfirmingArchive: input.confirmingArchiveThreadKey === input.threadKey,
|
||||
};
|
||||
}
|
||||
|
||||
type SidebarProject = {
|
||||
id: string;
|
||||
title: string;
|
||||
|
||||
@@ -192,6 +192,7 @@ import {
|
||||
resolveSidebarNewThreadSeedContext,
|
||||
resolveSidebarNewThreadEnvMode,
|
||||
resolveSidebarStageBadgeLabel,
|
||||
resolveSidebarThreadRowTransientProps,
|
||||
resolveThreadRowClassName,
|
||||
resolveThreadStatusPill,
|
||||
orderItemsByPreferredIds,
|
||||
@@ -324,13 +325,13 @@ interface SidebarThreadRowProps {
|
||||
isActive: boolean;
|
||||
jumpLabel: string | null;
|
||||
appSettingsConfirmThreadArchive: boolean;
|
||||
renamingThreadKey: string | null;
|
||||
isRenaming: boolean;
|
||||
renamingTitle: string;
|
||||
setRenamingTitle: (title: string) => void;
|
||||
startThreadRename: (threadKey: string, title: string) => void;
|
||||
renamingInputRef: React.RefObject<HTMLInputElement | null>;
|
||||
renamingCommittedRef: React.RefObject<boolean>;
|
||||
confirmingArchiveThreadKey: string | null;
|
||||
isConfirmingArchive: boolean;
|
||||
setConfirmingArchiveThreadKey: React.Dispatch<React.SetStateAction<string | null>>;
|
||||
confirmArchiveButtonRefs: React.RefObject<Map<string, HTMLButtonElement>>;
|
||||
handleThreadClick: (
|
||||
@@ -361,13 +362,13 @@ export const SidebarThreadRow = memo(function SidebarThreadRow(props: SidebarThr
|
||||
isActive,
|
||||
jumpLabel,
|
||||
appSettingsConfirmThreadArchive,
|
||||
renamingThreadKey,
|
||||
isRenaming,
|
||||
renamingTitle,
|
||||
setRenamingTitle,
|
||||
startThreadRename,
|
||||
renamingInputRef,
|
||||
renamingCommittedRef,
|
||||
confirmingArchiveThreadKey,
|
||||
isConfirmingArchive,
|
||||
setConfirmingArchiveThreadKey,
|
||||
confirmArchiveButtonRefs,
|
||||
handleThreadClick,
|
||||
@@ -468,8 +469,8 @@ export const SidebarThreadRow = memo(function SidebarThreadRow(props: SidebarThr
|
||||
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
|
||||
const showArchiveConfirmation = isConfirmingArchive && !isThreadRunning;
|
||||
const threadMetaClassName = showArchiveConfirmation
|
||||
? "pointer-events-none opacity-0"
|
||||
: !isThreadRunning
|
||||
? "pointer-events-none transition-opacity duration-150 max-sm:pr-6 group-hover/menu-sub-item:opacity-0 group-focus-within/menu-sub-item:opacity-0"
|
||||
@@ -502,7 +503,7 @@ export const SidebarThreadRow = memo(function SidebarThreadRow(props: SidebarThr
|
||||
(event: React.MouseEvent) => {
|
||||
// Already renaming this row: a double-click on the row chrome (outside the
|
||||
// input) must not restart and discard the in-progress edit.
|
||||
if (renamingThreadKey === threadKey) return;
|
||||
if (isRenaming) return;
|
||||
// On mobile the first tap navigates and closes the sidebar sheet, so the
|
||||
// inline rename can't be shown. Renaming there stays on the context menu.
|
||||
if (isMobile) return;
|
||||
@@ -514,7 +515,7 @@ export const SidebarThreadRow = memo(function SidebarThreadRow(props: SidebarThr
|
||||
event.preventDefault();
|
||||
startThreadRename(threadKey, thread.title);
|
||||
},
|
||||
[isMobile, renamingThreadKey, startThreadRename, threadKey, thread.title],
|
||||
[isMobile, isRenaming, startThreadRename, threadKey, thread.title],
|
||||
);
|
||||
const handleRowKeyDown = useCallback(
|
||||
(event: React.KeyboardEvent) => {
|
||||
@@ -709,7 +710,7 @@ export const SidebarThreadRow = memo(function SidebarThreadRow(props: SidebarThr
|
||||
</Tooltip>
|
||||
)}
|
||||
{threadStatus && <ThreadStatusLabel status={threadStatus} />}
|
||||
{renamingThreadKey === threadKey ? (
|
||||
{isRenaming ? (
|
||||
<input
|
||||
ref={handleRenameInputRef}
|
||||
className="min-w-0 flex-1 truncate text-base sm:text-xs bg-transparent outline-none border border-ring rounded px-0.5"
|
||||
@@ -783,7 +784,7 @@ export const SidebarThreadRow = memo(function SidebarThreadRow(props: SidebarThr
|
||||
isRemoteThread ? "max-sm:min-w-24" : "max-sm:min-w-20"
|
||||
}`}
|
||||
>
|
||||
{isConfirmingArchive ? (
|
||||
{showArchiveConfirmation ? (
|
||||
<button
|
||||
ref={handleConfirmArchiveRef}
|
||||
type="button"
|
||||
@@ -995,6 +996,12 @@ const SidebarProjectThreadList = memo(function SidebarProjectThreadList(
|
||||
{shouldShowThreadPanel &&
|
||||
renderedThreads.map((thread) => {
|
||||
const threadKey = scopedThreadKey(scopeThreadRef(thread.environmentId, thread.id));
|
||||
const transientProps = resolveSidebarThreadRowTransientProps({
|
||||
threadKey,
|
||||
renamingThreadKey,
|
||||
renamingTitle,
|
||||
confirmingArchiveThreadKey,
|
||||
});
|
||||
return (
|
||||
<SidebarThreadRow
|
||||
key={threadKey}
|
||||
@@ -1004,13 +1011,13 @@ const SidebarProjectThreadList = memo(function SidebarProjectThreadList(
|
||||
isActive={activeRouteThreadKey === threadKey}
|
||||
jumpLabel={threadJumpLabelByKey.get(threadKey) ?? null}
|
||||
appSettingsConfirmThreadArchive={appSettingsConfirmThreadArchive}
|
||||
renamingThreadKey={renamingThreadKey}
|
||||
renamingTitle={renamingTitle}
|
||||
isRenaming={transientProps.isRenaming}
|
||||
renamingTitle={transientProps.renamingTitle}
|
||||
setRenamingTitle={setRenamingTitle}
|
||||
startThreadRename={startThreadRename}
|
||||
renamingInputRef={renamingInputRef}
|
||||
renamingCommittedRef={renamingCommittedRef}
|
||||
confirmingArchiveThreadKey={confirmingArchiveThreadKey}
|
||||
isConfirmingArchive={transientProps.isConfirmingArchive}
|
||||
setConfirmingArchiveThreadKey={setConfirmingArchiveThreadKey}
|
||||
confirmArchiveButtonRefs={confirmArchiveButtonRefs}
|
||||
handleThreadClick={handleThreadClick}
|
||||
|
||||
Reference in new issue
Block a user