fix logical project scopes on mobile
Co-authored-by: codex <[email protected]>
This commit is contained in:
1 parent
d089f8f49f
commit
7e09d54f0e
3 files changed
+120
-61
No files matched your search
@@ -177,6 +177,55 @@ describe("buildHomeThreadGroups", () => {
|
||||
expect(groups[0]?.newThreadTarget?.id).toBe(canonicalRemote.id);
|
||||
});
|
||||
|
||||
it("keeps repository identity from an older duplicate when the freshness winner lacks it", () => {
|
||||
const localEnvironmentId = EnvironmentId.make("environment-local");
|
||||
const remoteEnvironmentId = EnvironmentId.make("environment-remote");
|
||||
const repositoryIdentity = {
|
||||
canonicalKey: "github.com/pingdotgg/t3code",
|
||||
locator: {
|
||||
source: "git-remote" as const,
|
||||
remoteName: "origin",
|
||||
remoteUrl: "[email protected]:pingdotgg/t3code.git",
|
||||
},
|
||||
};
|
||||
const projects = [
|
||||
makeProject({
|
||||
environmentId: localEnvironmentId,
|
||||
id: ProjectId.make("project-local"),
|
||||
title: "t3code",
|
||||
repositoryIdentity,
|
||||
}),
|
||||
makeProject({
|
||||
environmentId: remoteEnvironmentId,
|
||||
id: ProjectId.make("project-remote-with-identity"),
|
||||
title: "t3code",
|
||||
workspaceRoot: "/remote/t3code",
|
||||
repositoryIdentity,
|
||||
updatedAt: "2026-06-01T00:00:00.000Z",
|
||||
}),
|
||||
makeProject({
|
||||
environmentId: remoteEnvironmentId,
|
||||
id: ProjectId.make("project-remote-fresh"),
|
||||
title: "t3code",
|
||||
workspaceRoot: "/remote/t3code/",
|
||||
updatedAt: "2026-06-02T00:00:00.000Z",
|
||||
}),
|
||||
];
|
||||
|
||||
const scopes = buildHomeProjectScopes({
|
||||
projects,
|
||||
environmentId: null,
|
||||
projectGroupingMode: "repository",
|
||||
});
|
||||
|
||||
expect(scopes).toHaveLength(1);
|
||||
expect(scopes[0]?.representative.id).toBe(ProjectId.make("project-local"));
|
||||
expect(scopes[0]?.projects.map((project) => project.id)).toContain(
|
||||
ProjectId.make("project-remote-fresh"),
|
||||
);
|
||||
expect(scopes[0]?.projectRefs).toHaveLength(3);
|
||||
});
|
||||
|
||||
it("sorts v2 project scopes by their grouped thread activity", () => {
|
||||
const environmentId = EnvironmentId.make("environment-1");
|
||||
const olderProject = makeProject({
|
||||
|
||||
@@ -59,24 +59,31 @@ export function buildHomeProjectScopes(input: {
|
||||
const projects = input.projects.filter(
|
||||
(project) => input.environmentId === null || project.environmentId === input.environmentId,
|
||||
);
|
||||
const projectsByPhysicalKey = new Map<string, EnvironmentProject[]>();
|
||||
for (const project of projects) {
|
||||
const physicalKey = derivePhysicalProjectKey(project);
|
||||
const existing = projectsByPhysicalKey.get(physicalKey);
|
||||
if (existing) existing.push(project);
|
||||
else projectsByPhysicalKey.set(physicalKey, [project]);
|
||||
}
|
||||
|
||||
const winnersByPhysicalKey = new Map<
|
||||
string,
|
||||
{ readonly key: string; readonly project: EnvironmentProject }
|
||||
>();
|
||||
for (const project of projects) {
|
||||
const physicalKey = derivePhysicalProjectKey(project);
|
||||
const existing = winnersByPhysicalKey.get(physicalKey);
|
||||
if (
|
||||
!existing ||
|
||||
getProjectFreshnessTimestamp(project) > getProjectFreshnessTimestamp(existing.project) ||
|
||||
(getProjectFreshnessTimestamp(project) === getProjectFreshnessTimestamp(existing.project) &&
|
||||
project.id > existing.project.id)
|
||||
) {
|
||||
winnersByPhysicalKey.set(physicalKey, {
|
||||
key: deriveLogicalProjectKey(project, { groupingMode: input.projectGroupingMode }),
|
||||
project,
|
||||
});
|
||||
}
|
||||
for (const [physicalKey, members] of projectsByPhysicalKey) {
|
||||
const project = members.reduce((winner, candidate) => {
|
||||
const freshnessDelta =
|
||||
getProjectFreshnessTimestamp(candidate) - getProjectFreshnessTimestamp(winner);
|
||||
return freshnessDelta > 0 || (freshnessDelta === 0 && candidate.id > winner.id)
|
||||
? candidate
|
||||
: winner;
|
||||
});
|
||||
const identitySource = members.find((member) => member.repositoryIdentity !== null) ?? project;
|
||||
winnersByPhysicalKey.set(physicalKey, {
|
||||
key: deriveLogicalProjectKey(identitySource, { groupingMode: input.projectGroupingMode }),
|
||||
project,
|
||||
});
|
||||
}
|
||||
|
||||
const groups = new Map<string, EnvironmentProject[]>();
|
||||
|
||||
@@ -48,7 +48,7 @@ import {
|
||||
type HomeGroupDisplayState,
|
||||
type HomeListItem,
|
||||
} from "../home/homeListItems";
|
||||
import { buildHomeThreadGroups } from "../home/homeThreadList";
|
||||
import { buildHomeProjectScopes, buildHomeThreadGroups } from "../home/homeThreadList";
|
||||
import { SwipeableScrollGateProvider, useSwipeableScrollGate } from "../home/thread-swipe-actions";
|
||||
import { usePendingTaskListActions } from "../home/usePendingTaskListActions";
|
||||
import { useThreadListActions } from "../home/useThreadListActions";
|
||||
@@ -225,28 +225,29 @@ function ThreadNavigationSidebarPane(
|
||||
setThreadSortOrder,
|
||||
} = useHomeListOptions(availableEnvironmentIds);
|
||||
const [selectedProjectKey, setSelectedProjectKey] = useState<string | null>(null);
|
||||
const projectScopes = useMemo(
|
||||
() =>
|
||||
buildHomeProjectScopes({
|
||||
projects,
|
||||
environmentId: options.selectedEnvironmentId,
|
||||
projectGroupingMode: options.projectGroupingMode,
|
||||
}),
|
||||
[options.projectGroupingMode, options.selectedEnvironmentId, projects],
|
||||
);
|
||||
const projectFilterOptions = useMemo(
|
||||
() =>
|
||||
projects
|
||||
.filter(
|
||||
(project) =>
|
||||
options.selectedEnvironmentId === null ||
|
||||
project.environmentId === options.selectedEnvironmentId,
|
||||
)
|
||||
.map((project) => ({
|
||||
key: scopedProjectKey(project.environmentId, project.id),
|
||||
label: project.title,
|
||||
})),
|
||||
[options.selectedEnvironmentId, projects],
|
||||
projectScopes.map((scope) => ({
|
||||
key: scope.key,
|
||||
label: scope.title,
|
||||
})),
|
||||
[projectScopes],
|
||||
);
|
||||
const selectedProject = useMemo(
|
||||
const selectedProjectScope = useMemo(
|
||||
() =>
|
||||
selectedProjectKey === null
|
||||
? null
|
||||
: (projects.find(
|
||||
(project) => scopedProjectKey(project.environmentId, project.id) === selectedProjectKey,
|
||||
) ?? null),
|
||||
[projects, selectedProjectKey],
|
||||
: (projectScopes.find((scope) => scope.key === selectedProjectKey) ?? null),
|
||||
[projectScopes, selectedProjectKey],
|
||||
);
|
||||
useEffect(() => {
|
||||
if (
|
||||
@@ -257,30 +258,39 @@ function ThreadNavigationSidebarPane(
|
||||
}
|
||||
}, [projectFilterOptions, selectedProjectKey]);
|
||||
const scopedProjects = useMemo(
|
||||
() => (selectedProject === null ? projects : [selectedProject]),
|
||||
[projects, selectedProject],
|
||||
() => (selectedProjectScope === null ? projects : selectedProjectScope.projects),
|
||||
[projects, selectedProjectScope],
|
||||
);
|
||||
const selectedProjectRefs = useMemo(
|
||||
() =>
|
||||
selectedProjectScope === null
|
||||
? null
|
||||
: new Set(
|
||||
selectedProjectScope.projectRefs.map((projectRef) =>
|
||||
scopedProjectKey(projectRef.environmentId, projectRef.projectId),
|
||||
),
|
||||
),
|
||||
[selectedProjectScope],
|
||||
);
|
||||
const scopedThreads = useMemo(
|
||||
() =>
|
||||
selectedProject === null
|
||||
selectedProjectRefs === null
|
||||
? threads
|
||||
: threads.filter(
|
||||
(thread) =>
|
||||
thread.environmentId === selectedProject.environmentId &&
|
||||
thread.projectId === selectedProject.id,
|
||||
: threads.filter((thread) =>
|
||||
selectedProjectRefs.has(scopedProjectKey(thread.environmentId, thread.projectId)),
|
||||
),
|
||||
[selectedProject, threads],
|
||||
[selectedProjectRefs, threads],
|
||||
);
|
||||
const scopedPendingTasks = useMemo(
|
||||
() =>
|
||||
selectedProject === null
|
||||
selectedProjectRefs === null
|
||||
? pendingTasks
|
||||
: pendingTasks.filter(
|
||||
(pendingTask) =>
|
||||
pendingTask.message.environmentId === selectedProject.environmentId &&
|
||||
pendingTask.creation.projectId === selectedProject.id,
|
||||
: pendingTasks.filter((pendingTask) =>
|
||||
selectedProjectRefs.has(
|
||||
scopedProjectKey(pendingTask.message.environmentId, pendingTask.creation.projectId),
|
||||
),
|
||||
),
|
||||
[pendingTasks, selectedProject],
|
||||
[pendingTasks, selectedProjectRefs],
|
||||
);
|
||||
const groups = useMemo(
|
||||
() =>
|
||||
@@ -401,15 +411,7 @@ function ThreadNavigationSidebarPane(
|
||||
return buildThreadListV2Items({
|
||||
threads: threads.filter((thread) => thread.archivedAt === null),
|
||||
environmentId: options.selectedEnvironmentId,
|
||||
projectRefs:
|
||||
selectedProject === null
|
||||
? null
|
||||
: [
|
||||
{
|
||||
environmentId: selectedProject.environmentId,
|
||||
projectId: selectedProject.id,
|
||||
},
|
||||
],
|
||||
projectRefs: selectedProjectScope === null ? null : selectedProjectScope.projectRefs,
|
||||
searchQuery: props.searchQuery,
|
||||
changeRequestStateByKey,
|
||||
settlementEnvironmentIds,
|
||||
@@ -425,7 +427,7 @@ function ThreadNavigationSidebarPane(
|
||||
settlementEnvironmentIds,
|
||||
threadListV2Enabled,
|
||||
threads,
|
||||
selectedProject,
|
||||
selectedProjectScope,
|
||||
]);
|
||||
const listItems = useMemo<readonly SidebarListItem[]>(() => {
|
||||
if (!threadListV2Enabled) return listLayout.items;
|
||||
@@ -439,9 +441,10 @@ function ThreadNavigationSidebarPane(
|
||||
(pendingTask) =>
|
||||
(options.selectedEnvironmentId === null ||
|
||||
pendingTask.message.environmentId === options.selectedEnvironmentId) &&
|
||||
(selectedProject === null ||
|
||||
(pendingTask.message.environmentId === selectedProject.environmentId &&
|
||||
pendingTask.creation.projectId === selectedProject.id)) &&
|
||||
(selectedProjectRefs === null ||
|
||||
selectedProjectRefs.has(
|
||||
scopedProjectKey(pendingTask.message.environmentId, pendingTask.creation.projectId),
|
||||
)) &&
|
||||
(v2SearchQuery.length === 0 ||
|
||||
pendingTask.title.toLocaleLowerCase().includes(v2SearchQuery)),
|
||||
);
|
||||
@@ -471,7 +474,7 @@ function ThreadNavigationSidebarPane(
|
||||
options.selectedEnvironmentId,
|
||||
pendingTasks,
|
||||
props.searchQuery,
|
||||
selectedProject,
|
||||
selectedProjectRefs,
|
||||
threadListV2Enabled,
|
||||
threadListV2Layout,
|
||||
]);
|
||||
@@ -935,8 +938,8 @@ function ThreadNavigationSidebarPane(
|
||||
? "Loading threads…"
|
||||
: props.searchQuery.trim().length > 0
|
||||
? "No matching threads"
|
||||
: selectedProject !== null
|
||||
? `No threads in ${selectedProject.title}`
|
||||
: selectedProjectScope !== null
|
||||
? `No threads in ${selectedProjectScope.title}`
|
||||
: "No threads yet"}
|
||||
</Text>
|
||||
);
|
||||
|
||||
Reference in new issue
Block a user