Skip to content

Commit 20dbe5a

Browse files
thomaspblockWrench
authored andcommitted
polish(projects): streamline overview navigation and state
Make the Projects overview section-aware, searchable, responsive, and consistent with sidebar and empty-state patterns while keeping list rendering bounded. Signed-off-by: Thomas Petersen <[email protected]> Co-authored-by: Thomas Petersen <[email protected]>
1 parent 07d2ce6 commit 20dbe5a

48 files changed

Lines changed: 1283 additions & 768 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎desktop/src/features/channels/ui/useChannelIntro.tsx‎

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -107,9 +107,9 @@ export function useChannelIntro({
107107

108108
if (onAddAgent) {
109109
actions.push({
110-
description: "Bring them in.",
111-
icon: <Bot aria-hidden className="h-6 w-6" />,
112-
label: "Add agents",
110+
description: "Add an agent here.",
111+
icon: <Bot aria-hidden className="h-5 w-5" />,
112+
label: "Add agent",
113113
onClick: onAddAgent,
114114
testId: "channel-intro-action-create-agent",
115115
});
@@ -118,7 +118,7 @@ export function useChannelIntro({
118118
if (onOpenMembers) {
119119
actions.push({
120120
description: "Invite members.",
121-
icon: <UserPlus aria-hidden className="h-6 w-6" />,
121+
icon: <UserPlus aria-hidden className="h-5 w-5" />,
122122
label: "Add people",
123123
onClick: onOpenMembers,
124124
testId: "channel-intro-action-add-people",
@@ -131,6 +131,7 @@ export function useChannelIntro({
131131
channelKindLabel: getChannelIntroKind(activeChannel, projectHome),
132132
channelName: activeChannel.name,
133133
description: getChannelIntroDescription(activeChannel),
134+
hideBeginning: projectHome,
134135
icon: projectHome ? (
135136
<ProjectChannelIcon className="h-7 w-7" />
136137
) : undefined,

‎desktop/src/features/messages/ui/ChannelIntroBlock.tsx‎

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ export type ChannelIntro = {
1616
channelKindLabel: string;
1717
channelName: string;
1818
description?: string | null;
19+
hideBeginning?: boolean;
1920
icon?: React.ReactNode;
2021
};
2122

@@ -50,13 +51,15 @@ export function ChannelIntroBlock({
5051
<p className="mt-4 max-w-2xl truncate text-xl font-semibold leading-7 tracking-tight text-foreground">
5152
#{intro.channelName}
5253
</p>
53-
<p className="mt-1 max-w-2xl text-sm leading-5 text-muted-foreground">
54-
This is the beginning of the{" "}
55-
<span className="font-medium text-foreground">
56-
{intro.channelKindLabel}
57-
</span>
58-
.
59-
</p>
54+
{intro.hideBeginning ? null : (
55+
<p className="mt-1 max-w-2xl text-sm leading-5 text-muted-foreground">
56+
This is the beginning of the{" "}
57+
<span className="font-medium text-foreground">
58+
{intro.channelKindLabel}
59+
</span>
60+
.
61+
</p>
62+
)}
6063
{intro.description ? (
6164
<p className="mt-2 max-w-xl text-sm leading-5 text-muted-foreground">
6265
{intro.description}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import assert from "node:assert/strict";
2+
import test from "node:test";
3+
4+
import { pickDefaultProjectsAgent } from "./projectAgentSelection.ts";
5+
6+
test("prefers Fizz over the first running agent", () => {
7+
const implementationPartner = {
8+
name: "Implementation Partner",
9+
personaId: "custom:implementation",
10+
};
11+
const fizz = { name: "Fizz", personaId: "builtin:fizz" };
12+
assert.equal(pickDefaultProjectsAgent([implementationPartner, fizz]), fizz);
13+
});
14+
15+
test("ignores an unmanaged agent using the Fizz display name", () => {
16+
const managed = { name: "Builder", personaId: "custom:builder" };
17+
const spoofedFizz = { name: "Fizz" };
18+
assert.equal(pickDefaultProjectsAgent([managed, spoofedFizz]), managed);
19+
assert.equal(pickDefaultProjectsAgent([managed]), managed);
20+
assert.equal(pickDefaultProjectsAgent([]), null);
21+
});
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
const WELCOME_GUIDE_PERSONA_ID = "builtin:fizz";
2+
3+
/** Prefers the built-in welcome lead for a new Projects conversation. */
4+
export function pickDefaultProjectsAgent<
5+
Agent extends { name: string; personaId?: string | null },
6+
>(agents: readonly Agent[]): Agent | null {
7+
return (
8+
agents.find((agent) => agent.personaId === WELCOME_GUIDE_PERSONA_ID) ??
9+
agents[0] ??
10+
null
11+
);
12+
}

‎desktop/src/features/projects/lib/projectRelatedChannels.test.mjs‎

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import assert from "node:assert/strict";
22
import { test } from "node:test";
33

44
import {
5+
collapseProjectRelatedChannelRows,
56
collectProjectRelatedChannelRows,
67
listProjectBoundChannels,
78
listProjectChildChannels,
@@ -106,6 +107,37 @@ test("collects one row per repository channel binding", () => {
106107
);
107108
});
108109

110+
test("collapses repositories sharing one project channel", () => {
111+
const rows = collectProjectRelatedChannelRows([
112+
makeProject({
113+
repositories: [
114+
makeRepository({ name: "web" }),
115+
makeRepository({ id: "repo-mobile", name: "mobile" }),
116+
makeRepository({
117+
channelId: CHANNEL_B,
118+
id: "repo-relay",
119+
name: "relay",
120+
}),
121+
],
122+
}),
123+
]);
124+
125+
assert.deepEqual(collapseProjectRelatedChannelRows(rows), [
126+
{
127+
channelId: CHANNEL_A,
128+
projectId: "project-buzz",
129+
projectName: "buzz",
130+
repositoryNames: ["web", "mobile"],
131+
},
132+
{
133+
channelId: CHANNEL_B,
134+
projectId: "project-buzz",
135+
projectName: "buzz",
136+
repositoryNames: ["relay"],
137+
},
138+
]);
139+
});
140+
109141
test("keeps a project channel only when no repository in that project shares it", () => {
110142
assert.deepEqual(
111143
collectProjectRelatedChannelRows([

‎desktop/src/features/projects/lib/projectRelatedChannels.ts‎

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,14 @@ export type ProjectRelatedChannelRow = {
2020
repositoryName: string | null;
2121
};
2222

23+
/** One display row per distinct channel within a project. */
24+
export type ProjectRelatedChannelDisplayRow = {
25+
channelId: string;
26+
projectId: string;
27+
projectName: string;
28+
repositoryNames: string[];
29+
};
30+
2331
function trimmedChannelId(value: string | null | undefined) {
2432
const channelId = value?.trim() ?? "";
2533
return channelId.length > 0 ? channelId : null;
@@ -88,6 +96,40 @@ export function projectRelatedChannelRowKey(row: ProjectRelatedChannelRow) {
8896
return `${row.channelId}:${row.projectId}:${row.repositoryId ?? "project"}`;
8997
}
9098

99+
/** Collapses repository bindings that point at the same project channel. */
100+
export function collapseProjectRelatedChannelRows(
101+
rows: readonly ProjectRelatedChannelRow[],
102+
): ProjectRelatedChannelDisplayRow[] {
103+
const collapsed = new Map<string, ProjectRelatedChannelDisplayRow>();
104+
for (const row of rows) {
105+
const key = `${row.projectId}:${row.channelId}`;
106+
const current = collapsed.get(key);
107+
if (current) {
108+
if (
109+
row.repositoryName &&
110+
!current.repositoryNames.includes(row.repositoryName)
111+
) {
112+
current.repositoryNames.push(row.repositoryName);
113+
}
114+
continue;
115+
}
116+
collapsed.set(key, {
117+
channelId: row.channelId,
118+
projectId: row.projectId,
119+
projectName: row.projectName,
120+
repositoryNames: row.repositoryName ? [row.repositoryName] : [],
121+
});
122+
}
123+
return [...collapsed.values()];
124+
}
125+
126+
/** Stable key for one collapsed project-channel row. */
127+
export function projectRelatedChannelDisplayRowKey(
128+
row: ProjectRelatedChannelDisplayRow,
129+
) {
130+
return `${row.channelId}:${row.projectId}`;
131+
}
132+
91133
export type ProjectBoundChannel = {
92134
channelId: string;
93135
repositoryId: string | null;
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
import assert from "node:assert/strict";
2+
import test from "node:test";
3+
4+
import { buildProjectsActivityDigest } from "./projectsActivityDigest.ts";
5+
6+
const NOW = 2_000_000_000;
7+
8+
test("summarizes recent activity in a short highlighted sentence", () => {
9+
const project = { id: "project-a" };
10+
const digest = buildProjectsActivityDigest({
11+
issues: [
12+
{ project, issue: { createdAt: NOW - 60 } },
13+
{ project, issue: { createdAt: NOW - 120 } },
14+
],
15+
nowSeconds: NOW,
16+
projects: [project],
17+
pullRequests: [{ project, pullRequest: { createdAt: NOW - 180 } }],
18+
snapshots: {
19+
"project-a": {
20+
commits: [
21+
{ timestamp: NOW - 30 },
22+
{ timestamp: NOW - 90 },
23+
{ timestamp: NOW - 8 * 24 * 60 * 60 },
24+
],
25+
},
26+
},
27+
});
28+
29+
assert.equal(digest.prefix, "This week:");
30+
assert.deepEqual(digest.highlights, [
31+
"2 new commits",
32+
"2 tasks opened",
33+
"1 review opened",
34+
"1 active project",
35+
]);
36+
assert.ok(
37+
`${digest.prefix} ${digest.highlights.join(", ")}${digest.suffix}`.split(
38+
/\s+/,
39+
).length <= 30,
40+
);
41+
});
42+
43+
test("falls back to current totals when no recent activity is loaded", () => {
44+
const digest = buildProjectsActivityDigest({
45+
issues: [],
46+
nowSeconds: NOW,
47+
projects: [{ id: "a" }, { id: "b" }],
48+
pullRequests: [],
49+
summaries: {
50+
a: { issueCount: 4, prCount: 2 },
51+
b: { issueCount: 1, prCount: 3 },
52+
},
53+
});
54+
55+
assert.equal(digest.prefix, "Currently tracking");
56+
assert.deepEqual(digest.highlights, ["2 projects", "5 tasks", "5 reviews"]);
57+
});
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
import type {
2+
Project,
3+
ProjectActivitySummary,
4+
ProjectIssueListItem,
5+
ProjectPullRequestListItem,
6+
ProjectRepoSnapshot,
7+
} from "@/features/projects/hooks";
8+
9+
const WEEK_SECONDS = 7 * 24 * 60 * 60;
10+
11+
export type ProjectsActivityDigest = {
12+
highlights: string[];
13+
prefix: string;
14+
suffix: string;
15+
};
16+
17+
function plural(count: number, singular: string, pluralForm = `${singular}s`) {
18+
return `${count} ${count === 1 ? singular : pluralForm}`;
19+
}
20+
21+
/** Builds a short, deterministic sentence from the currently loaded activity. */
22+
export function buildProjectsActivityDigest({
23+
issues,
24+
nowSeconds,
25+
projects,
26+
pullRequests,
27+
snapshots,
28+
summaries,
29+
}: {
30+
issues: ProjectIssueListItem[];
31+
nowSeconds: number;
32+
projects: Project[];
33+
pullRequests: ProjectPullRequestListItem[];
34+
snapshots?: Record<string, ProjectRepoSnapshot>;
35+
summaries?: Record<string, ProjectActivitySummary>;
36+
}): ProjectsActivityDigest {
37+
const since = nowSeconds - WEEK_SECONDS;
38+
const activeProjectIds = new Set<string>();
39+
let commitCount = 0;
40+
for (const [projectId, snapshot] of Object.entries(snapshots ?? {})) {
41+
const recent = snapshot.commits.filter(
42+
(commit) => commit.timestamp >= since,
43+
).length;
44+
commitCount += recent;
45+
if (recent > 0) activeProjectIds.add(projectId);
46+
}
47+
const taskCount = issues.filter(({ issue, project }) => {
48+
const recent = issue.createdAt >= since;
49+
if (recent) activeProjectIds.add(project.id);
50+
return recent;
51+
}).length;
52+
const reviewCount = pullRequests.filter(({ project, pullRequest }) => {
53+
const recent = pullRequest.createdAt >= since;
54+
if (recent) activeProjectIds.add(project.id);
55+
return recent;
56+
}).length;
57+
const highlights = [
58+
commitCount > 0 ? `${plural(commitCount, "new commit")}` : null,
59+
taskCount > 0 ? `${plural(taskCount, "task")} opened` : null,
60+
reviewCount > 0 ? `${plural(reviewCount, "review")} opened` : null,
61+
].filter((value): value is string => value !== null);
62+
63+
if (highlights.length > 0) {
64+
highlights.push(`${plural(activeProjectIds.size, "active project")}`);
65+
return {
66+
highlights,
67+
prefix: "This week:",
68+
suffix: ".",
69+
};
70+
}
71+
72+
const totals = Object.values(summaries ?? {}).reduce(
73+
(result, summary) => ({
74+
reviews: result.reviews + summary.prCount,
75+
tasks: result.tasks + summary.issueCount,
76+
}),
77+
{ reviews: 0, tasks: 0 },
78+
);
79+
return {
80+
highlights: [
81+
plural(projects.length, "project"),
82+
plural(totals.tasks, "task"),
83+
plural(totals.reviews, "review"),
84+
],
85+
prefix: "Currently tracking",
86+
suffix: ".",
87+
};
88+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import assert from "node:assert/strict";
2+
import test from "node:test";
3+
4+
import { matchesProjectsSearch } from "./projectsSearch.ts";
5+
6+
test("matches every case-insensitive token across fields", () => {
7+
assert.equal(
8+
matchesProjectsSearch("buzz mobile", [
9+
"Buzz Platform",
10+
"Desktop, relay, and mobile clients",
11+
]),
12+
true,
13+
);
14+
assert.equal(
15+
matchesProjectsSearch("buzz missing", [
16+
"Buzz Platform",
17+
"Desktop, relay, and mobile clients",
18+
]),
19+
false,
20+
);
21+
});
22+
23+
test("empty search matches everything", () => {
24+
assert.equal(matchesProjectsSearch(" ", []), true);
25+
});
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
/** Case-insensitive token matching for Projects-local search. */
2+
export function matchesProjectsSearch(
3+
query: string,
4+
values: ReadonlyArray<string | null | undefined>,
5+
) {
6+
const tokens = query.trim().toLocaleLowerCase().split(/\s+/).filter(Boolean);
7+
if (tokens.length === 0) return true;
8+
const haystack = values.filter(Boolean).join(" ").toLocaleLowerCase();
9+
return tokens.every((token) => haystack.includes(token));
10+
}

0 commit comments

Comments
 (0)