Skip to content

Commit c9a4fc5

Browse files
feat(spaces): Order a Space's Conversations like In flight
One shared attentionOrder sorts In flight and the Conversation list of a Space's page: pins in the viewer's order, then what waits on the viewer, then the rest, then done. Space rows use In flight's state icons, plus a failed latest Turn. Co-Authored-By: David Cramer <[email protected]>
1 parent acbd95f commit c9a4fc5

5 files changed

Lines changed: 220 additions & 60 deletions

File tree

‎packages/junior-dashboard/e2e/spaces.spec.ts‎

Lines changed: 112 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
1+
import type { ConversationSummaryReport } from "@sentry/junior/api/schema";
2+
13
import { conversationMenuRow, viewAsParticipant } from "./conversationMenu";
24
import { desktop, mobile, screenshot } from "./screenshot";
35
import { expect, test } from "./test";
46

5-
const BILLING = "/spaces/6f1c2a7e-3b4d-4e5f-8a6b-7c8d9e0f1a21";
7+
const BILLING_ID = "6f1c2a7e-3b4d-4e5f-8a6b-7c8d9e0f1a21";
8+
const BILLING = `/spaces/${BILLING_ID}`;
69
const DOCS = "/spaces/6f1c2a7e-3b4d-4e5f-8a6b-7c8d9e0f1a23";
710
const MOBILE_APP_ID = "6f1c2a7e-3b4d-4e5f-8a6b-7c8d9e0f1a22";
811
// A private Space that the viewer and Avery are in.
@@ -76,7 +79,7 @@ test("the pane lists the viewer's Spaces, and a Space page shows its details", a
7679
await expect(page).toHaveURL(`${dashboard.baseURL}${BILLING}`);
7780
});
7881

79-
test("each pane row shows what its Space's Conversations need", async ({
82+
test("each pane row shows what its Space's Conversations need, and the Space's page lists them in order", async ({
8083
dashboard,
8184
page,
8285
}) => {
@@ -130,6 +133,113 @@ test("each pane row shows what its Space's Conversations need", async ({
130133
lightTheme: true,
131134
view: "mobile",
132135
});
136+
137+
// The Space's page lists its Conversations in In flight's order: pins,
138+
// then what waits on the viewer, then the rest, then done. Each group
139+
// runs newest Message first.
140+
await page.route(
141+
(url) =>
142+
url.pathname === "/api/conversations" &&
143+
url.searchParams.get("spaceId") === BILLING_ID,
144+
async (route) => {
145+
const response = await route.fetch();
146+
const feed = await response.json();
147+
// Row `index` had its last Message `index` hours before the first.
148+
const newest = Date.parse(feed.conversations[0].lastSeenAt);
149+
const row = (
150+
index: number,
151+
displayTitle: string,
152+
fields: Partial<ConversationSummaryReport>,
153+
) => {
154+
const at = new Date(newest - index * 3_600_000).toISOString();
155+
return {
156+
...feed.conversations[0],
157+
conversationId: `internal:space-order-${index}`,
158+
displayTitle,
159+
lastMessageAt: at,
160+
lastSeenAt: at,
161+
latestTurnFailed: false,
162+
pinnedAt: null,
163+
status: "done",
164+
threads: undefined,
165+
treeState: "done",
166+
turnActive: false,
167+
watching: false,
168+
...fields,
169+
};
170+
};
171+
await route.fulfill({
172+
json: {
173+
...feed,
174+
conversations: [
175+
row(0, "Done recently", {}),
176+
row(1, "Running", {
177+
status: "working",
178+
treeState: "working",
179+
turnActive: true,
180+
}),
181+
row(2, "Failed", { latestTurnFailed: true }),
182+
row(3, "Asks you", {
183+
status: "needs_input",
184+
treeState: "needs_you",
185+
}),
186+
row(4, "Pinned", { pinnedAt: "2026-08-01T10:00:00.000Z" }),
187+
row(5, "Done earlier", {}),
188+
],
189+
nextCursor: undefined,
190+
},
191+
response,
192+
});
193+
},
194+
);
195+
await page.setViewportSize(desktop);
196+
await page.goto(`${dashboard.baseURL}${BILLING}`);
197+
const conversations = page
198+
.getByRole("complementary", { name: "Space details" })
199+
.getByRole("region", { exact: true, name: "Conversations" });
200+
await conversations.getByRole("button", { name: "Show 3 more" }).click();
201+
const rows = conversations.getByRole("listitem");
202+
await expect(rows).toHaveText([
203+
/Pinned/,
204+
/Asks you/,
205+
/Running/,
206+
/Failed/,
207+
/Done recently/,
208+
/Done earlier/,
209+
/Show fewer/,
210+
]);
211+
// Rows carry In flight's icons, and a failed Turn. Done rows show none.
212+
await expect(rows.nth(0).getByRole("img", { name: "Pinned" })).toBeVisible();
213+
await expect(
214+
rows.nth(1).getByRole("img", { name: "Waiting on you" }),
215+
).toBeVisible();
216+
await expect(
217+
rows.nth(2).getByRole("status", { name: "Working" }),
218+
).toBeVisible();
219+
await expect(rows.nth(3).getByRole("img", { name: "Failed" })).toBeVisible();
220+
await expect(rows.nth(4).getByRole("img")).toHaveCount(0);
221+
// No row shows its hover fill in the shot.
222+
await page.mouse.move(0, 0);
223+
await screenshot(page, "space-page-conversations", {
224+
lightTheme: true,
225+
target: conversations,
226+
view: "desktop",
227+
});
228+
229+
// A phone shows the same order in the details sheet.
230+
await page.setViewportSize(mobile);
231+
await page.goto(`${dashboard.baseURL}${BILLING}`);
232+
await page.getByRole("button", { name: "Space details" }).click();
233+
const sheet = page.getByRole("dialog", { name: "Space details" });
234+
await expect(
235+
sheet
236+
.getByRole("region", { exact: true, name: "Conversations" })
237+
.getByRole("listitem"),
238+
).toHaveText([/Pinned/, /Asks you/, /Running/, /Show 3 more/]);
239+
await screenshot(page, "space-page-conversations", {
240+
lightTheme: true,
241+
view: "mobile",
242+
});
133243
});
134244

135245
test("a Space's page shows its settings when they are opened", async ({

‎packages/junior-dashboard/src/client/conversations/conversationSections.ts‎

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import type { Conversation } from "../types";
2+
import { conversationDisplayState } from "./ConversationStateIcon";
23
import {
34
calendarDay,
45
calendarDaysAgo,
@@ -38,20 +39,36 @@ function groupSections(
3839
}
3940

4041
/**
41-
* Sort pinned conversations to the front: pins in the viewer's order, then
42-
* the newest Message first. Paginated lists call this before paging, so
43-
* page 1 holds every pin.
42+
* Order conversations by what they need from the viewer. In flight and a
43+
* Space's Conversation list both use this order:
44+
*
45+
* 1. Pins, in the viewer's order.
46+
* 2. Conversations that wait on the viewer: an open action Inbox item or a
47+
* sign-in in their tree.
48+
* 3. The rest that are not done: working, watching for an Event or Timer,
49+
* or with a failed latest Turn.
50+
* 4. Done.
51+
*
52+
* Each group after the pins runs newest Message first.
4453
*/
45-
export function pinnedFirst(conversations: Conversation[]): Conversation[] {
54+
export function attentionOrder(conversations: Conversation[]): Conversation[] {
4655
return newestFirst(conversations).sort((left, right) => {
47-
const leftRank = left.pinnedAt ? 0 : 1;
56+
const leftRank = attentionRank(left);
4857
return (
49-
leftRank - (right.pinnedAt ? 0 : 1) ||
58+
leftRank - attentionRank(right) ||
5059
(leftRank === 0 ? comparePinOrder(left, right) : 0)
5160
);
5261
});
5362
}
5463

64+
function attentionRank(conversation: Conversation): number {
65+
if (conversation.pinnedAt) return 0;
66+
const state = conversationDisplayState(conversation);
67+
if (state === "needs_you") return 1;
68+
if (state || conversation.latestTurnFailed) return 2;
69+
return 3;
70+
}
71+
5572
/** Sort conversations by their last Message, newest first. */
5673
export function newestFirst(conversations: Conversation[]): Conversation[] {
5774
return [...conversations].sort(

‎packages/junior-dashboard/src/client/inbox/inboxData.tsx‎

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ import type { InboxItemPayload } from "@sentry/junior/api/schema";
1111

1212
import { conversationDisplayState } from "../conversations/ConversationStateIcon";
1313
import {
14+
attentionOrder,
1415
newestFirst,
15-
pinnedFirst,
1616
} from "../conversations/conversationSections";
1717
import { useInboxConversations } from "../conversations/useInboxConversations";
1818
import type { Conversation } from "../types";
@@ -342,18 +342,16 @@ function useBuildInboxData(input: {
342342
const conversationRows = rowsByTime(inboxBundles(awake));
343343

344344
// In flight: every pin and every busy Conversation, whose tree waits on
345-
// the viewer, works, or watches for an Event or Timer. Pins come first,
346-
// busy or not, in the viewer's order, then the busy Conversations.
347-
// Collapsed, every pin shows, each one click away, and busy Conversations
348-
// fill the rows left, up to IN_FLIGHT_LIMIT.
349-
const pinned = pinnedFirst(
350-
conversations.filter((conversation) => conversation.pinnedAt),
351-
);
345+
// the viewer, works, or watches for an Event or Timer, in
346+
// `attentionOrder`. Collapsed, every pin shows, each one click away, and
347+
// busy Conversations fill the rows left, up to IN_FLIGHT_LIMIT.
348+
const ordered = attentionOrder(conversations);
349+
const pinned = ordered.filter((conversation) => conversation.pinnedAt);
352350
const busy = (conversation: Conversation) => {
353351
const state = conversationDisplayState(conversation);
354352
return state !== undefined && state !== "pinned";
355353
};
356-
const busyRows = conversations.filter(
354+
const busyRows = ordered.filter(
357355
(conversation) => busy(conversation) && !conversation.pinnedAt,
358356
);
359357
const inFlightFor = (unpinnedBusy: Conversation[]) => [

‎packages/junior-dashboard/src/client/shell/pages/spaces/SpaceDetails.tsx‎

Lines changed: 28 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,17 @@ import { DetailsPanel } from "../../../components/DetailsPanel";
66
import { Button } from "../../../components/ui/button";
77
import { Skeleton } from "../../../components/ui/skeleton";
88
import { conversationPath } from "../../../conversations/conversationRoutes";
9-
import { newestFirst } from "../../../conversations/conversationSections";
9+
import { attentionOrder } from "../../../conversations/conversationSections";
10+
import {
11+
ConversationStateIcon,
12+
conversationDisplayState,
13+
} from "../../../conversations/ConversationStateIcon";
1014
import {
1115
DetailsCard,
1216
DetailsList,
1317
DetailsRow,
1418
} from "../../../conversations/DetailsList";
1519
import { buildConversations, conversationDisplayTitle } from "../../../format";
16-
import {
17-
useWaitingConversations,
18-
useWaitingConversationsSettled,
19-
} from "../../../inbox/queries";
20-
import { leadWorkState, type LeadWorkState } from "../../../lead/leadWork";
2120
import { leadWorkStatus } from "../../../lead/LeadWorkStatus";
2221
import {
2322
useSpaceConversationsData,
@@ -26,6 +25,7 @@ import {
2625
} from "../../../spaces/queries";
2726
import { cn } from "../../../styles";
2827
import { formatCompactAge } from "../../../time";
28+
import type { Conversation } from "../../../types";
2929

3030
// The form opens only after a click, so it loads with the first open
3131
// instead of with every Space page.
@@ -89,10 +89,7 @@ export function SpaceOverview(props: { space: SpaceReport }) {
8989

9090
function SpaceConversations(props: { spaceId: string }) {
9191
const feed = useSpaceConversationsData(props.spaceId);
92-
const waitingMap = useWaitingConversations();
93-
// Until the Inbox items load, no row reads as Done before Needs you.
94-
const waiting = useWaitingConversationsSettled() ? waitingMap : undefined;
95-
const conversations = newestFirst(
92+
const conversations = attentionOrder(
9693
buildConversations(feed.data?.conversations ?? []),
9794
);
9895
return (
@@ -113,18 +110,7 @@ function SpaceConversations(props: { spaceId: string }) {
113110
items={conversations}
114111
renderItem={(conversation) => (
115112
<DetailsRow
116-
icon={
117-
<StateIcon
118-
state={
119-
waiting
120-
? leadWorkState(
121-
conversation,
122-
waiting.get(conversation.id),
123-
)
124-
: undefined
125-
}
126-
/>
127-
}
113+
icon={<RowStateIcon conversation={conversation} />}
128114
meta={formatCompactAge(conversation.lastSeenAt)}
129115
title={conversationDisplayTitle(conversation)}
130116
to={conversationPath(conversation.id)}
@@ -136,19 +122,26 @@ function SpaceConversations(props: { spaceId: string }) {
136122
);
137123
}
138124

139-
/** A Conversation's state as the Lead shows it, or a blank before it loads. */
140-
function StateIcon(props: { state: LeadWorkState | undefined }) {
141-
if (!props.state) return <span aria-hidden="true" className="size-4" />;
142-
const status = leadWorkStatus[props.state];
143-
const Icon = status.icon;
144-
return (
145-
<Icon
146-
aria-label={status.label}
147-
className={cn("size-4", status.text)}
148-
role="img"
149-
strokeWidth={2}
150-
/>
151-
);
125+
/**
126+
* A row's state icon, as In flight shows it. A failed latest Turn shows over
127+
* a pin, since the Space's own row points here to find it. An idle row
128+
* keeps a blank, so titles line up.
129+
*/
130+
function RowStateIcon(props: { conversation: Conversation }) {
131+
const state = conversationDisplayState(props.conversation);
132+
if (props.conversation.latestTurnFailed && (!state || state === "pinned")) {
133+
const { icon: Icon, label, text } = leadWorkStatus.failed;
134+
return (
135+
<Icon
136+
aria-label={label}
137+
className={cn("size-4", text)}
138+
role="img"
139+
strokeWidth={2}
140+
/>
141+
);
142+
}
143+
if (!state) return <span aria-hidden="true" className="size-4" />;
144+
return <ConversationStateIcon className="size-4" state={state} />;
152145
}
153146

154147
function SpaceMembers(props: { space: SpaceReport }) {

0 commit comments

Comments
 (0)