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
104 changes: 104 additions & 0 deletions apps/web/src/components/Sidebar.logic.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ import {
resolveWorkingStartedAt,
pullRequestMatchesSearchQuery,
searchSidebarThreads,
shouldClearPersistedSidebarProjectScope,
shouldClearThreadSelectionOnMouseDown,
shouldShowSidebarV2Duration,
shouldRecedeSidebarThread,
Expand Down Expand Up @@ -1070,6 +1071,109 @@ describe("searchSidebarThreads", () => {
});
});

describe("shouldClearPersistedSidebarProjectScope", () => {
const local = EnvironmentId.make("env-local");
const remote = EnvironmentId.make("env-remote");
const remoteScratchRoot = "/home/user/.t3/scratch";
const scratchWorkspaceRootFor = (environmentId: EnvironmentId) =>
environmentId === remote ? remoteScratchRoot : "/Users/me/.t3/scratch";
const scratchGroup = {
memberProjects: [{ environmentId: remote, workspaceRoot: `${remoteScratchRoot}/` }],
};
const repoGroup = {
memberProjects: [{ environmentId: remote, workspaceRoot: "/home/user/src/t3code" }],
};

it("keeps the scope until project snapshots are ready", () => {
expect(
shouldClearPersistedSidebarProjectScope({
scopeKey: `${remote}:${remoteScratchRoot}`,
snapshotsReady: false,
scopedGroup: null,
scratchWorkspaceRootFor,
}),
).toBe(false);
expect(
shouldClearPersistedSidebarProjectScope({
scopeKey: `${remote}:${remoteScratchRoot}`,
snapshotsReady: false,
scopedGroup: scratchGroup,
scratchWorkspaceRootFor,
}),
).toBe(false);
});

it("keeps an empty scope", () => {
expect(
shouldClearPersistedSidebarProjectScope({
scopeKey: null,
snapshotsReady: true,
scopedGroup: null,
scratchWorkspaceRootFor,
}),
).toBe(false);
});

it("clears a scope whose catalog group is gone", () => {
expect(
shouldClearPersistedSidebarProjectScope({
scopeKey: "missing-project",
snapshotsReady: true,
scopedGroup: null,
scratchWorkspaceRootFor,
}),
).toBe(true);
});

it("clears a scope that resolves to a scratch workspace", () => {
expect(
shouldClearPersistedSidebarProjectScope({
scopeKey: `${remote}:${remoteScratchRoot}`,
snapshotsReady: true,
scopedGroup: scratchGroup,
scratchWorkspaceRootFor,
}),
).toBe(true);
});

it("keeps a scope that resolves to a normal project", () => {
expect(
shouldClearPersistedSidebarProjectScope({
scopeKey: "github.com/pingdotgg/t3code",
snapshotsReady: true,
scopedGroup: repoGroup,
scratchWorkspaceRootFor,
}),
).toBe(false);
});

it("compares each member with its own environment scratch root", () => {
expect(
shouldClearPersistedSidebarProjectScope({
scopeKey: `${local}:${remoteScratchRoot}`,
snapshotsReady: true,
scopedGroup: {
memberProjects: [{ environmentId: local, workspaceRoot: remoteScratchRoot }],
},
scratchWorkspaceRootFor,
}),
).toBe(false);
});

it("keeps a group that still contains a non-scratch checkout", () => {
expect(
shouldClearPersistedSidebarProjectScope({
scopeKey: "github.com/pingdotgg/t3code",
snapshotsReady: true,
scopedGroup: {
memberProjects: [...scratchGroup.memberProjects, ...repoGroup.memberProjects],
},
scratchWorkspaceRootFor,
}),
).toBe(false);
});
});

describe("filterSidebarProjectScopeItems", () => {
const items = [
{ value: "all", label: "All projects" },
Expand Down
35 changes: 35 additions & 0 deletions apps/web/src/components/Sidebar.logic.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { resolveThreadWorkingStartedAt } from "@t3tools/client-runtime/state/models";
import { isScratchProject } from "@t3tools/client-runtime/state/projects";
import { backgroundWorkHoldsCompletion } from "@t3tools/shared/orchestrationV2PendingBackgroundWork";
import { threadPullRequestSearchTerms } from "@t3tools/shared/threadPullRequests";
import * as React from "react";
Expand Down Expand Up @@ -567,6 +568,40 @@ export function isSidebarSubagentThread(thread: Pick<SidebarThreadSummary, "line
return thread.lineage.relationshipToParent === "subagent";
}

/**
* Whether a persisted new-sidebar project scope should be cleared once
* project snapshots are ready.
*
* Clears a scope whose catalog group is gone, and a scope whose group is
* only Scratch ("No project") workspaces. Scratch is a real catalog
* project, so leaving that key set keeps the sidebar filtered to it.
*/
export function shouldClearPersistedSidebarProjectScope(input: {
readonly scopeKey: string | null;
readonly snapshotsReady: boolean;
readonly scopedGroup: {
readonly memberProjects: ReadonlyArray<{
readonly environmentId: EnvironmentId;
readonly workspaceRoot: string;
}>;
} | null;
readonly scratchWorkspaceRootFor: (environmentId: EnvironmentId) => string | null | undefined;
}): boolean {
if (input.scopeKey === null || !input.snapshotsReady) {
return false;
}
const group = input.scopedGroup;
if (group === null) {
return true;
}
return (
group.memberProjects.length > 0 &&
group.memberProjects.every((member) =>
isScratchProject(member, input.scratchWorkspaceRootFor(member.environmentId)),
)
);
}

export function filterSidebarV2VisibleThreads<
T extends Pick<SidebarThreadSummary, "archivedAt" | "lineage"> & {
environmentId: string;
Expand Down
27 changes: 22 additions & 5 deletions apps/web/src/components/Sidebar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,7 @@ import {
resolveSidebarThreadStatus,
resolveThreadLastVisitedAt,
searchSidebarThreads,
shouldClearPersistedSidebarProjectScope,
shouldCreateNewThreadInCurrentProject,
shouldNavigateAfterThreadPark,
shouldRecedeSidebarThread,
Expand Down Expand Up @@ -2723,25 +2724,41 @@ export default function Sidebar() {
[scopedProjectGroup],
);
// Configs identify scratch projects, so both they and live project snapshots
// must arrive before a persisted scope can be considered missing.
// must arrive before a persisted scope can be considered missing. Scratch
// ("No project") is a live catalog project, so the same reset drops a scope
// that resolves only to those workspaces.
const allProjectSnapshotsReady = useAllEnvironmentProjectSnapshotsReady();
const allProjectConfigsReady = useAtomValue(environmentProjects.projectConfigsReadyAtom);
const projectCatalogReady = allProjectSnapshotsReady && allProjectConfigsReady;
useEffect(() => {
const nextKey = resolveSidebarProjectScopeKey({
const resolvedKey = resolveSidebarProjectScopeKey({
groups: projectGroups,
key: persistedProjectScopeKey,
settings: projectGroupingSettings,
canClearMissingScope: allProjectSnapshotsReady && allProjectConfigsReady,
canClearMissingScope: projectCatalogReady,
});
const resolvedGroup =
resolvedKey === null
? null
: (projectGroups.find((group) => group.projectKey === resolvedKey) ?? null);
const nextKey = shouldClearPersistedSidebarProjectScope({
scopeKey: resolvedKey,
snapshotsReady: projectCatalogReady,
scopedGroup: resolvedGroup,
scratchWorkspaceRootFor: (environmentId) =>
serverConfigs.get(environmentId)?.scratchWorkspaceRoot,
})
? null
: resolvedKey;
if (nextKey !== persistedProjectScopeKey) {
setProjectScopeKey(nextKey);
}
}, [
allProjectConfigsReady,
allProjectSnapshotsReady,
persistedProjectScopeKey,
projectCatalogReady,
projectGroups,
projectGroupingSettings,
serverConfigs,
setProjectScopeKey,
]);
// Count-only subscription: the parent needs "are there draft rows" for the
Expand Down
Loading