refactor(web): remove unused sidebar selectors (#10034)
This commit is contained in:
1 parent
83a2897ed6
commit
5cb696595c
2 files changed
-226
No files matched your search
@@ -9,11 +9,9 @@ import {
|
||||
createThreadJumpHintVisibilityController,
|
||||
filterSidebarProjectScopeItems,
|
||||
getSidebarThreadIdsToPrewarm,
|
||||
getVisibleSidebarThreadIds,
|
||||
resolveAdjacentThreadId,
|
||||
reduceSidebarProjectScopeMenuState,
|
||||
getFallbackThreadIdAfterDelete,
|
||||
getVisibleThreadsForProject,
|
||||
getProjectSortTimestamp,
|
||||
hasUnseenCompletion,
|
||||
isContextMenuPointerDown,
|
||||
@@ -27,7 +25,6 @@ import {
|
||||
resolveWorkingStartedAt,
|
||||
searchSidebarThreadsByTitle,
|
||||
formatWorkingDurationLabel,
|
||||
shouldNavigateAfterProjectRemoval,
|
||||
shouldClearThreadSelectionOnMouseDown,
|
||||
shouldRecedeSidebarThread,
|
||||
sortLogicalProjectsForSidebar,
|
||||
@@ -84,56 +81,6 @@ describe("animatePinnedLayoutChanges", () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe("shouldNavigateAfterProjectRemoval", () => {
|
||||
const projectThreads = [{ environmentId: "environment-local", id: "thread-1" }];
|
||||
|
||||
it("navigates away from a draft route owned by the removed project", () => {
|
||||
expect(
|
||||
shouldNavigateAfterProjectRemoval({
|
||||
routeTarget: { kind: "draft", draftId: "draft-1" as never },
|
||||
projectThreads,
|
||||
projectDraftId: "draft-1",
|
||||
}),
|
||||
).toBe(true);
|
||||
});
|
||||
|
||||
it("does not navigate away from a different draft route", () => {
|
||||
expect(
|
||||
shouldNavigateAfterProjectRemoval({
|
||||
routeTarget: { kind: "draft", draftId: "draft-2" as never },
|
||||
projectThreads,
|
||||
projectDraftId: "draft-1",
|
||||
}),
|
||||
).toBe(false);
|
||||
});
|
||||
|
||||
it("navigates away from a server thread owned by the removed project", () => {
|
||||
expect(
|
||||
shouldNavigateAfterProjectRemoval({
|
||||
routeTarget: {
|
||||
kind: "server",
|
||||
threadRef: {
|
||||
environmentId: EnvironmentId.make("environment-local"),
|
||||
threadId: ThreadId.make("thread-1"),
|
||||
},
|
||||
},
|
||||
projectThreads,
|
||||
projectDraftId: null,
|
||||
}),
|
||||
).toBe(true);
|
||||
});
|
||||
|
||||
it("does not navigate from an unrelated route", () => {
|
||||
expect(
|
||||
shouldNavigateAfterProjectRemoval({
|
||||
routeTarget: null,
|
||||
projectThreads,
|
||||
projectDraftId: null,
|
||||
}),
|
||||
).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
describe("archiveSelectedThreadEntries", () => {
|
||||
const entries = [{ threadKey: "one" }, { threadKey: "two" }, { threadKey: "three" }] as const;
|
||||
const success = { _tag: "Success" } as const;
|
||||
@@ -644,46 +591,6 @@ describe("resolveAdjacentThreadId", () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe("getVisibleSidebarThreadIds", () => {
|
||||
it("returns only the rendered visible thread order across projects", () => {
|
||||
expect(
|
||||
getVisibleSidebarThreadIds([
|
||||
{
|
||||
renderedThreadIds: [
|
||||
ThreadId.make("thread-12"),
|
||||
ThreadId.make("thread-11"),
|
||||
ThreadId.make("thread-10"),
|
||||
],
|
||||
},
|
||||
{
|
||||
renderedThreadIds: [ThreadId.make("thread-8"), ThreadId.make("thread-6")],
|
||||
},
|
||||
]),
|
||||
).toEqual([
|
||||
ThreadId.make("thread-12"),
|
||||
ThreadId.make("thread-11"),
|
||||
ThreadId.make("thread-10"),
|
||||
ThreadId.make("thread-8"),
|
||||
ThreadId.make("thread-6"),
|
||||
]);
|
||||
});
|
||||
|
||||
it("skips threads from collapsed projects whose thread panels are not shown", () => {
|
||||
expect(
|
||||
getVisibleSidebarThreadIds([
|
||||
{
|
||||
shouldShowThreadPanel: false,
|
||||
renderedThreadIds: [ThreadId.make("thread-hidden-2"), ThreadId.make("thread-hidden-1")],
|
||||
},
|
||||
{
|
||||
shouldShowThreadPanel: true,
|
||||
renderedThreadIds: [ThreadId.make("thread-12"), ThreadId.make("thread-11")],
|
||||
},
|
||||
]),
|
||||
).toEqual([ThreadId.make("thread-12"), ThreadId.make("thread-11")]);
|
||||
});
|
||||
});
|
||||
|
||||
describe("isContextMenuPointerDown", () => {
|
||||
it("treats secondary-button presses as context menu gestures on all platforms", () => {
|
||||
expect(
|
||||
@@ -1362,57 +1269,6 @@ describe("resolveProjectStatusIndicator", () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe("getVisibleThreadsForProject", () => {
|
||||
it("includes the active thread even when it falls below the folded preview", () => {
|
||||
const threads = Array.from({ length: 8 }, (_, index) =>
|
||||
makeThread({
|
||||
id: ThreadId.make(`thread-${index + 1}`),
|
||||
title: `Thread ${index + 1}`,
|
||||
}),
|
||||
);
|
||||
|
||||
const result = getVisibleThreadsForProject({
|
||||
threads,
|
||||
activeThreadId: ThreadId.make("thread-8"),
|
||||
isThreadListExpanded: false,
|
||||
previewLimit: 6,
|
||||
});
|
||||
|
||||
expect(result.hasHiddenThreads).toBe(true);
|
||||
expect(result.visibleThreads.map((thread) => thread.id)).toEqual([
|
||||
ThreadId.make("thread-1"),
|
||||
ThreadId.make("thread-2"),
|
||||
ThreadId.make("thread-3"),
|
||||
ThreadId.make("thread-4"),
|
||||
ThreadId.make("thread-5"),
|
||||
ThreadId.make("thread-6"),
|
||||
ThreadId.make("thread-8"),
|
||||
]);
|
||||
expect(result.hiddenThreads.map((thread) => thread.id)).toEqual([ThreadId.make("thread-7")]);
|
||||
});
|
||||
|
||||
it("returns all threads when the list is expanded", () => {
|
||||
const threads = Array.from({ length: 8 }, (_, index) =>
|
||||
makeThread({
|
||||
id: ThreadId.make(`thread-${index + 1}`),
|
||||
}),
|
||||
);
|
||||
|
||||
const result = getVisibleThreadsForProject({
|
||||
threads,
|
||||
activeThreadId: ThreadId.make("thread-8"),
|
||||
isThreadListExpanded: true,
|
||||
previewLimit: 6,
|
||||
});
|
||||
|
||||
expect(result.hasHiddenThreads).toBe(true);
|
||||
expect(result.visibleThreads.map((thread) => thread.id)).toEqual(
|
||||
threads.map((thread) => thread.id),
|
||||
);
|
||||
expect(result.hiddenThreads).toEqual([]);
|
||||
});
|
||||
});
|
||||
|
||||
function makeProject(overrides: Partial<Project> = {}): Project {
|
||||
const { defaultModelSelection, ...rest } = overrides;
|
||||
return {
|
||||
|
||||
@@ -12,7 +12,6 @@ import {
|
||||
type ThreadSortInput,
|
||||
} from "../lib/threadSort";
|
||||
import type { SidebarThreadSummary, Thread } from "../types";
|
||||
import type { ThreadRouteTarget } from "../threadRoutes";
|
||||
import { cn } from "../lib/utils";
|
||||
import { isLatestTurnSettled } from "../session-logic";
|
||||
|
||||
@@ -407,17 +406,6 @@ export function orderItemsByPreferredIds<TItem, TId>(input: {
|
||||
return [...ordered, ...remaining];
|
||||
}
|
||||
|
||||
export function getVisibleSidebarThreadIds<TThreadId>(
|
||||
renderedProjects: readonly {
|
||||
shouldShowThreadPanel?: boolean;
|
||||
renderedThreadIds: readonly TThreadId[];
|
||||
}[],
|
||||
): TThreadId[] {
|
||||
return renderedProjects.flatMap((renderedProject) =>
|
||||
renderedProject.shouldShowThreadPanel === false ? [] : renderedProject.renderedThreadIds,
|
||||
);
|
||||
}
|
||||
|
||||
export function getSidebarThreadIdsToPrewarm<TThreadId>(
|
||||
visibleThreadIds: readonly TThreadId[],
|
||||
limit = SIDEBAR_THREAD_PREWARM_LIMIT,
|
||||
@@ -452,28 +440,6 @@ export function resolveAdjacentThreadId<T>(input: {
|
||||
return currentIndex < threadIds.length - 1 ? (threadIds[currentIndex + 1] ?? null) : null;
|
||||
}
|
||||
|
||||
export function shouldNavigateAfterProjectRemoval(input: {
|
||||
routeTarget: ThreadRouteTarget | null;
|
||||
projectThreads: readonly {
|
||||
environmentId: string;
|
||||
id: string;
|
||||
}[];
|
||||
projectDraftId: string | null;
|
||||
}): boolean {
|
||||
const { projectDraftId, projectThreads, routeTarget } = input;
|
||||
if (routeTarget?.kind === "draft") {
|
||||
return projectDraftId === routeTarget.draftId;
|
||||
}
|
||||
if (routeTarget?.kind !== "server") {
|
||||
return false;
|
||||
}
|
||||
return projectThreads.some(
|
||||
(thread) =>
|
||||
thread.environmentId === routeTarget.threadRef.environmentId &&
|
||||
thread.id === routeTarget.threadRef.threadId,
|
||||
);
|
||||
}
|
||||
|
||||
export function isContextMenuPointerDown(input: {
|
||||
button: number;
|
||||
ctrlKey: boolean;
|
||||
@@ -838,54 +804,6 @@ export function resolveProjectStatusIndicator(
|
||||
return highestPriorityStatus;
|
||||
}
|
||||
|
||||
export function getVisibleThreadsForProject<T extends Pick<Thread, "id">>(input: {
|
||||
threads: readonly T[];
|
||||
activeThreadId: T["id"] | undefined;
|
||||
isThreadListExpanded: boolean;
|
||||
previewLimit: number;
|
||||
}): {
|
||||
hasHiddenThreads: boolean;
|
||||
visibleThreads: T[];
|
||||
hiddenThreads: T[];
|
||||
} {
|
||||
const { activeThreadId, isThreadListExpanded, previewLimit, threads } = input;
|
||||
const hasHiddenThreads = threads.length > previewLimit;
|
||||
|
||||
if (!hasHiddenThreads || isThreadListExpanded) {
|
||||
return {
|
||||
hasHiddenThreads,
|
||||
hiddenThreads: [],
|
||||
visibleThreads: [...threads],
|
||||
};
|
||||
}
|
||||
|
||||
const previewThreads = threads.slice(0, previewLimit);
|
||||
if (!activeThreadId || previewThreads.some((thread) => thread.id === activeThreadId)) {
|
||||
return {
|
||||
hasHiddenThreads: true,
|
||||
hiddenThreads: threads.slice(previewLimit),
|
||||
visibleThreads: previewThreads,
|
||||
};
|
||||
}
|
||||
|
||||
const activeThread = threads.find((thread) => thread.id === activeThreadId);
|
||||
if (!activeThread) {
|
||||
return {
|
||||
hasHiddenThreads: true,
|
||||
hiddenThreads: threads.slice(previewLimit),
|
||||
visibleThreads: previewThreads,
|
||||
};
|
||||
}
|
||||
|
||||
const visibleThreadIds = new Set([...previewThreads, activeThread].map((thread) => thread.id));
|
||||
|
||||
return {
|
||||
hasHiddenThreads: true,
|
||||
hiddenThreads: threads.filter((thread) => !visibleThreadIds.has(thread.id)),
|
||||
visibleThreads: threads.filter((thread) => visibleThreadIds.has(thread.id)),
|
||||
};
|
||||
}
|
||||
|
||||
export function getFallbackThreadIdAfterDelete<
|
||||
T extends Pick<Thread, "id" | "projectId" | "createdAt" | "updatedAt"> & ThreadSortInput,
|
||||
>(input: {
|
||||
|
||||
Reference in new issue
Block a user