Skip to content
Merged
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
54 changes: 45 additions & 9 deletions apps/web/src/components/sidebar/SidebarThreadFilterMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,14 @@ import {
import { SidebarHeaderIconButton } from "./SidebarThreadHeader";
import {
changedThreadListFilters,
EMPTY_THREAD_LIST_FILTER_BUCKETS,
inboxMenuOrder,
threadListFilterCounts,
threadListFilterOf,
toggleFilterOption,
toggleHiddenEnvironment,
type ThreadListFilter,
type ThreadListFilterBucketCounts,
} from "./threadListFilter.logic";

const INBOX_LABELS: Record<InboxChoice, string> = {
Expand Down Expand Up @@ -114,7 +116,7 @@ function SidebarThreadFilterOptions<T extends CountedThread>({
isChanged: boolean;
}) {
const connectedEnvironmentIds = useConnectedEnvironmentIds();
const counts = threadListFilterCounts(countedThreads(), filter, attributionOf);
const counts = threadListFilterCounts(countedThreads(), filter, attributionOf, owner);
const shownAttributions = THREAD_ATTRIBUTIONS.filter(
(from) => !filter.hiddenAttributions.includes(from),
);
Expand All @@ -130,13 +132,13 @@ function SidebarThreadFilterOptions<T extends CountedThread>({
{inboxOrder.map((inbox) => {
const checked = filter.inboxes.includes(inbox);
const isLast = checked && filter.inboxes.length === 1;
const count = counts.inboxes.get(inbox) ?? 0;
const count = counts.inboxes.get(inbox) ?? EMPTY_THREAD_LIST_FILTER_BUCKETS;
return (
<MenuCheckboxItem
key={inbox}
checked={checked}
disabled={isLast}
aria-label={`${INBOX_LABELS[inbox]}, ${count} active${isLast ? LAST_OPTION_NOTE : ""}`}
aria-label={`${INBOX_LABELS[inbox]}, ${stateCountPhrase(count)}${isLast ? LAST_OPTION_NOTE : ""}`}
onCheckedChange={() =>
void updateClientSettings({
founderInboxFilter: toggleFilterOption(filter.inboxes, inbox, inboxOrder),
Expand All @@ -154,13 +156,13 @@ function SidebarThreadFilterOptions<T extends CountedThread>({
{THREAD_ATTRIBUTIONS.map((from) => {
const checked = shownAttributions.includes(from);
const isLast = checked && shownAttributions.length === 1;
const count = counts.from.get(from) ?? 0;
const count = counts.from.get(from) ?? EMPTY_THREAD_LIST_FILTER_BUCKETS;
return (
<MenuCheckboxItem
key={from}
checked={checked}
disabled={isLast}
aria-label={`From ${THREAD_ATTRIBUTION_LABELS[from]}, ${count} active${isLast ? LAST_OPTION_NOTE : ""}`}
aria-label={`From ${THREAD_ATTRIBUTION_LABELS[from]}, ${stateCountPhrase(count)}${isLast ? LAST_OPTION_NOTE : ""}`}
onCheckedChange={() => {
const shown = toggleFilterOption(shownAttributions, from, THREAD_ATTRIBUTIONS);
void updateClientSettings({
Expand All @@ -184,13 +186,15 @@ function SidebarThreadFilterOptions<T extends CountedThread>({
const checked = shownEnvironmentIds.includes(environment.environmentId);
const isLast = checked && shownEnvironmentIds.length === 1;
const connected = connectedEnvironmentIds.includes(environment.environmentId);
const count = counts.environments.get(environment.environmentId) ?? 0;
const count =
counts.environments.get(environment.environmentId) ??
EMPTY_THREAD_LIST_FILTER_BUCKETS;
return (
<MenuCheckboxItem
key={environment.environmentId}
checked={checked}
disabled={isLast}
aria-label={`${environment.label}, ${connected ? "connected" : "not connected"}, ${count} active${isLast ? LAST_OPTION_NOTE : ""}`}
aria-label={`${environment.label}, ${connected ? "connected" : "not connected"}, ${stateCountPhrase(count)}${isLast ? LAST_OPTION_NOTE : ""}`}
onCheckedChange={() =>
void updateClientSettings({
sidebarHiddenEnvironmentIds: toggleHiddenEnvironment(
Expand Down Expand Up @@ -240,20 +244,52 @@ function SidebarThreadFilterOptions<T extends CountedThread>({
);
}

const STATE_COUNT_COLUMNS = [
["working", "working"],
["done", "done"],
["needsMe", "needs me"],
] as const satisfies ReadonlyArray<readonly [keyof ThreadListFilterBucketCounts, string]>;

function stateCountPhrase(counts: ThreadListFilterBucketCounts) {
return STATE_COUNT_COLUMNS.map(([key, label]) => `${counts[key]} ${label}`).join(", ");
}

function FilterOptionRow({
label,
count,
indicator,
}: {
label: string;
count: number;
count: ThreadListFilterBucketCounts;
indicator?: ReactNode;
}) {
return (
<span className="flex min-w-0 items-center gap-2">
{indicator}
<span className="min-w-0 flex-1 truncate">{label}</span>
<span className="shrink-0 text-muted-foreground text-xs tabular-nums">{count}</span>
<span className="grid shrink-0 grid-cols-3 gap-x-1.5 text-center">
{STATE_COUNT_COLUMNS.map(([key, name]) => {
const value = count[key];
return (
<span
key={key}
className={cn(
"text-3xs leading-tight tabular-nums",
value === 0
? "text-muted-foreground/40"
: key === "working"
? "text-info-foreground"
: key === "done"
? "text-success-foreground"
: "text-warning-foreground",
)}
>
<span className="block">{value}</span>
<span className="block">{name}</span>
</span>
);
})}
</span>
</span>
);
}
167 changes: 159 additions & 8 deletions apps/web/src/components/sidebar/threadListFilter.logic.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
changedThreadListFilters,
inboxMenuOrder,
matchesThreadListFilter,
threadListFilterBucket,
threadListFilterCounts,
threadListFilterOf,
toggleFilterOption,
Expand Down Expand Up @@ -42,21 +43,31 @@ describe("thread list filter", () => {
});

it("counts each section within the other sections' selection", () => {
const finished = { runtime: { status: "completed" }, latestRun: { status: "completed" } };
const threads = [
{ ...thread(laptop, kameron), from: "kameron" as const },
{ ...thread(laptop, bot), from: "kameron-agents" as const },
{ ...thread(crown, jeff), from: "jeff" as const },
{ ...thread(crown, kameron), from: "kameron" as const },
{ ...thread(laptop, kameron), from: "unknown" as const },
{ ...thread(laptop, kameron), ...finished, from: "kameron" as const },
{ ...thread(laptop, bot), ...finished, from: "kameron-agents" as const },
{ ...thread(crown, jeff), ...finished, from: "jeff" as const },
{ ...thread(crown, kameron), ...finished, from: "kameron" as const },
{ ...thread(laptop, kameron), ...finished, from: "unknown" as const },
];
const counts = threadListFilterCounts(
threads,
{ inboxes: ["kameron"], hiddenEnvironmentIds: [crown], hiddenAttributions: ["unknown"] },
(candidate) => candidate.from,
);
expect(Object.fromEntries(counts.inboxes)).toEqual({ kameron: 1, agents: 1 });
expect(Object.fromEntries(counts.environments)).toEqual({ laptop: 1, crown: 1 });
expect(Object.fromEntries(counts.from)).toEqual({ kameron: 1, unknown: 1 });
expect(Object.fromEntries(counts.inboxes)).toEqual({
kameron: { working: 0, done: 1, needsMe: 0 },
agents: { working: 0, done: 1, needsMe: 0 },
});
expect(Object.fromEntries(counts.environments)).toEqual({
laptop: { working: 0, done: 1, needsMe: 0 },
crown: { working: 0, done: 1, needsMe: 0 },
});
expect(Object.fromEntries(counts.from)).toEqual({
kameron: { working: 0, done: 1, needsMe: 0 },
unknown: { working: 0, done: 1, needsMe: 0 },
});
expect(
matchesThreadListFilter(
threads[4]!,
Expand Down Expand Up @@ -107,4 +118,144 @@ describe("thread list filter", () => {
expect(toggleHiddenEnvironment([offline, crown], crown, [laptop, crown])).toEqual([offline]);
expect(toggleHiddenEnvironment([crown], laptop, [laptop, crown])).toEqual([crown]);
});

it("buckets working, done and needs-me the same way on every row", () => {
const finished = { runtime: { status: "completed" }, latestRun: { status: "completed" } };
const quiet = {
...thread(laptop, kameron),
source: {
inbox: makeThreadInbox({
actor: kameron,
routing: { attentionKind: "FYI", reason: "fyi" },
}),
},
};
const asked = {
...quiet,
source: {
inbox: {
...quiet.source.inbox,
decisionRequest: {
founder: "kameron" as const,
kind: "decision" as const,
question: "Ship it?",
requestedAt: "2026-11-20T00:00:00.000Z",
},
},
},
};
const attention = {
...thread(laptop, bot),
...finished,
source: {
inbox: makeThreadInbox({
actor: bot,
routing: {
owner: "kameron",
assignee: { kind: "human", id: "kameron" },
audience: "kameron",
attentionKind: "action",
reason: "review",
},
}),
},
};
const otherAsk = {
...thread(laptop, jeff),
...finished,
source: {
inbox: {
...makeThreadInbox({
actor: jeff,
routing: { attentionKind: "FYI", reason: "fyi" },
}),
decisionRequest: {
founder: "jeff" as const,
kind: "decision" as const,
question: "Your call?",
requestedAt: "2026-11-20T00:00:00.000Z",
},
},
},
};
const fixtures = {
queued: {
...quiet,
runtime: { status: "queued" },
latestRun: { status: "queued" },
},
running: {
...quiet,
runtime: { status: "running" },
latestRun: { status: "running" },
},
done: { ...quiet, ...finished },
failed: {
...quiet,
runtime: { status: "failed" },
latestRun: { status: "failed" },
},
approval: {
...quiet,
runtime: { status: "running" },
latestRun: { status: "running" },
hasPendingApprovals: true,
},
question: {
...quiet,
runtime: { status: "waiting" },
latestRun: { status: "waiting" },
hasPendingUserInput: true,
},
decision: { ...asked, ...finished },
attention,
parked: {
...quiet,
runtime: { status: "idle" },
latestRun: { status: "completed" },
},
parkedAttention: {
...attention,
runtime: { status: "idle" },
latestRun: { status: "completed" },
},
settled: { ...quiet, ...finished, settledOverride: "settled" as const },
otherFounder: otherAsk,
unstarted: quiet,
};
expect(threadListFilterBucket(fixtures.queued, "kameron")).toBe("working");
expect(threadListFilterBucket(fixtures.running, "kameron")).toBe("working");
expect(threadListFilterBucket(fixtures.done, "kameron")).toBe("done");
expect(threadListFilterBucket(fixtures.failed, "kameron")).toBe("done");
expect(threadListFilterBucket(fixtures.approval, "kameron")).toBe("needsMe");
expect(threadListFilterBucket(fixtures.question, "kameron")).toBe("needsMe");
expect(threadListFilterBucket(fixtures.decision, "kameron")).toBe("needsMe");
expect(threadListFilterBucket(fixtures.attention, "kameron")).toBe("needsMe");
expect(threadListFilterBucket(fixtures.parked, "kameron")).toBe("working");
expect(threadListFilterBucket(fixtures.parkedAttention, "kameron")).toBe("working");
expect(threadListFilterBucket(fixtures.settled, "kameron")).toBeNull();
expect(threadListFilterBucket(fixtures.otherFounder, "kameron")).toBe("done");
expect(threadListFilterBucket(fixtures.unstarted, "kameron")).toBeNull();

const threads = Object.values(fixtures).map((candidate) => ({
...candidate,
from: "kameron" as const,
}));
const counts = threadListFilterCounts(
threads,
{
inboxes: ["kameron", "jeff", "agents", "shared"],
hiddenEnvironmentIds: [],
hiddenAttributions: [],
},
(candidate) => candidate.from,
"kameron",
);
const kameronRow = { working: 4, done: 2, needsMe: 4 };
const everyRow = { working: 4, done: 3, needsMe: 4 };
expect(counts.inboxes.get("kameron")).toEqual(kameronRow);
expect(counts.inboxes.get("jeff")).toEqual({ working: 0, done: 1, needsMe: 0 });
expect(counts.environments.get(laptop)).toEqual(everyRow);
expect(counts.from.get("kameron")).toEqual(everyRow);
});
});
Loading
Loading