Skip to content
Open
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
53 changes: 52 additions & 1 deletion apps/web/src/components/Sidebar.browser.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import { makeThreadFixture } from "../test-fixtures";
import { useHandleNewThread } from "../hooks/useHandleNewThread";
import { __setClientSettingsForTests, getClientSettings } from "../hooks/useSettings";
import { useThreadRouteTarget } from "../hooks/useThreadRouteTarget";
import { useProjects, useQuietThreadShells } from "../state/entities";
import { useProjects, useQuietThreadShells, useServerConfigs } from "../state/entities";
import { useTerminalUiStateStore } from "../terminalUiStateStore";
import type { Project } from "../types";
import Sidebar from "./Sidebar";
Expand Down Expand Up @@ -112,6 +112,57 @@ describe("sidebar header new thread", () => {
});
});

describe("sidebar settled shelf", () => {
// regression: #34291 changing the project filter collapsed an expanded Settled shelf back to 10
it("keeps its expanded length when the project filter changes", async () => {
using stack = new DisposableStack();
localStorage.setItem("t3code:sidebar:settled-expanded", "true");
stack.defer(() => localStorage.removeItem("t3code:sidebar:settled-expanded"));
const projectA = project("a");
const projectB = project("b");
const settled = (projectId: ProjectId, index: number) => ({
...threadShell(projectId, index),
settledOverride: "settled" as const,
});
const threads = [
...Array.from({ length: 14 }, (_, index) => settled(projectA.id, index)),
...Array.from({ length: 2 }, (_, index) => settled(projectB.id, 14 + index)),
];
vi.mocked(useProjects).mockReturnValue([projectA, projectB]);
vi.mocked(useQuietThreadShells).mockReturnValue(threads);
// Threads only count as settled once their environment's config has loaded.
vi.mocked(useServerConfigs).mockReturnValue(
new Map([[projectA.environmentId, { environment: { capabilities: {} } } as never]]),
);
vi.mocked(useThreadRouteTarget).mockReturnValue(null);
vi.mocked(useHandleNewThread).mockReturnValue({
activeDraftThread: null,
activeThread: null,
defaultProjectRef: { environmentId: projectA.environmentId, projectId: projectA.id },
defaultProjectFallbackReady: true,
handleNewThread: vi.fn().mockResolvedValue(null),
routeDraftId: null,
routeThreadRef: null,
});
await using screen = await render(
<SidebarProvider>
<Sidebar routeReveal={{ observedKey: null, pendingKey: null }} />
</SidebarProvider>,
);

await userEvent.click(screen.getByRole("button", { name: "Show 6 more" }));
await expect.element(screen.getByText("Thread 15").first()).toBeInTheDocument();

await userEvent.click(screen.getByRole("combobox", { name: "Filter threads by project" }));
await userEvent.click(screen.getByRole("option", { name: "a" }));
await expect.element(screen.getByRole("button", { name: "Settled14" })).toBeInTheDocument();
expect(
screen.getByRole("button", { name: /^Thread \d+, a$/ }).elements(),
"the Settled shelf fell back to its first page",
).toHaveLength(14);
});
});

function threadShell(projectId: ProjectId, index: number): EnvironmentThreadShell {
return makeThreadFixture({
environmentId: EnvironmentId.make("local"),
Expand Down
20 changes: 2 additions & 18 deletions apps/web/src/components/Sidebar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -412,7 +412,6 @@ function routeThreadOnly(

// Separate hooks cache maps independently of later Sidebar hooks and preserve dnd-kit inputs.
function useSidebarThreads(input: {
readonly projectScopeKey: string | null;
readonly scopedProjectKeys: ReadonlySet<string> | null;
readonly serverConfigs: ReadonlyMap<EnvironmentId, EnvironmentServerConfig>;
readonly connectedEnvironmentIds: readonly EnvironmentId[];
Expand All @@ -426,7 +425,6 @@ function useSidebarThreads(input: {
readonly keepEmptyFolders: (group: SidebarProjectSnapshot) => boolean;
}) {
const {
projectScopeKey,
scopedProjectKeys,
serverConfigs,
connectedEnvironmentIds,
Expand Down Expand Up @@ -465,15 +463,7 @@ function useSidebarThreads(input: {
// Shared with the old per-project sidebar, so folders keep their open state.
const projectExpandedById = useUiStateStore((store) => store.projectExpandedById);
const setProjectExpanded = useUiStateStore((store) => store.setProjectExpanded);
const [settledTail, setSettledTail] = useState({
scopeKey: projectScopeKey,
count: SETTLED_TAIL_INITIAL_COUNT,
});
if (settledTail.scopeKey !== projectScopeKey) {
setSettledTail({ scopeKey: projectScopeKey, count: SETTLED_TAIL_INITIAL_COUNT });
}
const settledVisibleCount =
settledTail.scopeKey === projectScopeKey ? settledTail.count : SETTLED_TAIL_INITIAL_COUNT;
const [settledVisibleCount, setSettledVisibleCount] = useState(SETTLED_TAIL_INITIAL_COUNT);

const partition = partitionSidebarThreads({
threads,
Expand Down Expand Up @@ -575,11 +565,7 @@ function useSidebarThreads(input: {
settledCount,
olderSettledShelf,
hiddenSettledCount: Math.max(0, settledCount - visibleSettledThreads.length),
showMoreSettled: () =>
setSettledTail((current) => ({
scopeKey: current.scopeKey,
count: current.count + SETTLED_TAIL_PAGE_COUNT,
})),
showMoreSettled: () => setSettledVisibleCount((count) => count + SETTLED_TAIL_PAGE_COUNT),
settledShelfExpanded,
toggleSettledShelf: () => setSettledShelfExpanded((value) => !value),
snoozedShelfExpanded,
Expand Down Expand Up @@ -1138,7 +1124,6 @@ export default function Sidebar({ routeReveal }: { routeReveal: SidebarRouteReve
findThread: (key) => threads.find((candidate) => threadShellKey(candidate) === key),
});
const projectScopeKeys = revealWidensScope ? [] : chosenProjectScopeKeys;
const projectScopeKey = projectScopeKeys.length === 0 ? null : projectScopeKeys.join("\n");
const toggleProjectScopeKey = (key: string) =>
setProjectScopeKeys(
projectScopeKeys.includes(key)
Expand Down Expand Up @@ -1336,7 +1321,6 @@ export default function Sidebar({ routeReveal }: { routeReveal: SidebarRouteReve
pinnedKeysById,
activeKeysById,
} = useSidebarThreads({
projectScopeKey,
scopedProjectKeys,
serverConfigs,
connectedEnvironmentIds,
Expand Down