Skip to content

Commit b448dc8

Browse files
fix(web): prioritize urgent composer notices in one stack
1 parent 72fc95c commit b448dc8

2 files changed

Lines changed: 55 additions & 58 deletions

File tree

‎apps/web/src/components/chat/ComposerBannerStack.browser.test.tsx‎

Lines changed: 26 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -60,46 +60,52 @@ it("only offers notice details when the description cannot fit", async () => {
6060
expect(hasDetails()).toBe(true);
6161
});
6262

63-
it("keeps urgent, warning and error notices visible while ordinary notices collapse behind activity", async () => {
63+
it("keeps only the usage limit attached while an active goal waits in the collapsible stack", async () => {
6464
await act(async () =>
6565
root.render(
6666
<ComposerBannerStack
6767
items={[
6868
{
69-
id: "limit",
69+
id: "goal",
7070
variant: "default",
71-
priority: "urgent",
71+
priority: "activity",
7272
icon: null,
73-
title: "Usage limit reached",
73+
title: "Goal active",
74+
description: "Finish the banner fix",
7475
},
75-
{ id: "usage", variant: "info", priority: "notice", icon: null, title: "Usage limits" },
76-
{ id: "offline", variant: "warning", icon: null, title: "Server is reconnecting" },
77-
{ id: "clone", variant: "error", icon: null, title: "Failed to clone repo" },
7876
{
79-
id: "work",
77+
id: "limit",
8078
variant: "default",
81-
priority: "activity",
79+
priority: "urgent",
8280
icon: null,
83-
title: "Waiting on 2 subagents",
81+
title: "Usage limit reached",
8482
},
8583
]}
8684
/>,
8785
),
8886
);
8987

90-
for (const title of ["Usage limit reached", "Server is reconnecting", "Failed to clone repo"]) {
91-
await expect.element(page.getByText(title, { exact: true })).toBeVisible();
92-
}
93-
await expect.element(page.getByText("Waiting on 2 subagents", { exact: true })).toBeVisible();
88+
const visibleBanners = () =>
89+
Array.from(container.querySelectorAll('[data-slot="composer-banner"]')).filter((banner) =>
90+
banner.checkVisibility({ checkOpacity: true, checkVisibilityCSS: true }),
91+
);
92+
const limit = page.getByText("Usage limit reached", { exact: true });
93+
const goal = page.getByText("Goal active", { exact: true });
94+
95+
expect(visibleBanners()).toHaveLength(1);
96+
await expect.element(limit).toBeVisible();
97+
await expect.element(goal).not.toBeVisible();
9498
expect(container.querySelector('[data-slot="composer-banner-attachment"]')?.textContent).toBe(
95-
"Waiting on 2 subagents",
99+
"Usage limit reached",
96100
);
97101

98-
const ordinaryNotice = page.getByText("Usage limits", { exact: true });
99-
await expect.element(ordinaryNotice).not.toBeVisible();
100102
await act(async () => page.getByRole("button", { name: "Show other notices" }).click());
101-
await expect.element(ordinaryNotice).toBeVisible();
103+
await expect.element(goal).toBeVisible();
104+
await expect.element(limit).toBeVisible();
105+
await expect.poll(visibleBanners).toHaveLength(2);
106+
102107
await act(async () => userEvent.keyboard("{Escape}"));
103-
await expect.element(ordinaryNotice).not.toBeVisible();
104-
await expect.element(page.getByText("Usage limit reached", { exact: true })).toBeVisible();
108+
await expect.element(goal).not.toBeVisible();
109+
await expect.element(limit).toBeVisible();
110+
expect(visibleBanners()).toHaveLength(1);
105111
});

‎apps/web/src/components/chat/ComposerBannerStack.tsx‎

Lines changed: 29 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,10 @@ export type ComposerBannerStackContent = Pick<
3131
type ComposerBannerStackEntry = ComposerBannerStackItem | ComposerBannerStackContent;
3232

3333
function bannerPriority(item: ComposerBannerStackEntry) {
34-
if (item.priority === "activity") {
34+
if (item.priority === "urgent" || item.variant === "error" || item.variant === "warning") {
3535
return 0;
3636
}
37-
if (item.priority === "urgent" || item.variant === "error" || item.variant === "warning") {
37+
if (item.priority === "activity") {
3838
return 1;
3939
}
4040
return 2;
@@ -68,16 +68,8 @@ export function ComposerBannerStack({ className, items, attachedAbove }: Compose
6868
};
6969
}, []);
7070

71-
const [frontItem, ...stackedItems] = items.toSorted(
72-
(a, b) => bannerPriority(a) - bannerPriority(b),
73-
);
74-
// Keep notices needing attention visible while activity occupies the attached slot.
75-
const pinnedItems = stackedItems.filter((item) => bannerPriority(item) === 1);
76-
const collapsibleItems = stackedItems.filter((item) => bannerPriority(item) !== 1);
77-
const hasStack = collapsibleItems.length > 0;
78-
79-
// A stack with nothing left to collapse closes, so the next stack starts collapsed.
80-
if (!hasStack && stackExpanded) {
71+
// A stack that shrinks to one banner collapses, so the next stack starts collapsed.
72+
if (items.length < 2 && stackExpanded) {
8173
setStackExpanded(false);
8274
}
8375

@@ -94,6 +86,8 @@ export function ComposerBannerStack({ className, items, attachedAbove }: Compose
9486
}
9587
}, [stackExpanded]);
9688

89+
const orderedItems = items.toSorted((a, b) => bannerPriority(a) - bannerPriority(b));
90+
const frontItem = orderedItems[0];
9791
if (!frontItem) {
9892
return (
9993
<>
@@ -103,8 +97,10 @@ export function ComposerBannerStack({ className, items, attachedAbove }: Compose
10397
</>
10498
);
10599
}
100+
const stackedItems = orderedItems.slice(1);
101+
const hasStack = stackedItems.length > 0;
106102
const showCollapsedStackCap = hasStack && exitingItemId !== frontItem.id;
107-
const firstCollapsibleItem = collapsibleItems[0];
103+
const firstStackedItem = stackedItems[0];
108104

109105
const requestDismiss = (item: ComposerBannerStackEntry) => {
110106
if (!("onDismiss" in item) || !item.onDismiss || exitingItemId) {
@@ -120,30 +116,8 @@ export function ComposerBannerStack({ className, items, attachedAbove }: Compose
120116
}, DISMISS_TRANSITION_MS);
121117
};
122118

123-
const renderStackedItem = (item: ComposerBannerStackEntry) => (
124-
<div
125-
key={item.id}
126-
className={cn(
127-
"transition-[opacity,translate] duration-220 ease-in",
128-
exitingItemId === item.id ? "pointer-events-none translate-y-28 opacity-0" : "opacity-100",
129-
)}
130-
>
131-
<ComposerBannerStackAlert
132-
item={item}
133-
attached={false}
134-
exiting={exitingItemId === item.id}
135-
onDismissRequest={() => requestDismiss(item)}
136-
/>
137-
</div>
138-
);
139-
140119
return (
141120
<>
142-
{pinnedItems.length > 0 ? (
143-
<div data-chat-composer-collapsed-controls="true" className="relative z-20 space-y-2 pb-2">
144-
{pinnedItems.map(renderStackedItem)}
145-
</div>
146-
) : null}
147121
{hasStack ? (
148122
<div
149123
ref={noticesRef}
@@ -175,10 +149,10 @@ export function ComposerBannerStack({ className, items, attachedAbove }: Compose
175149
setStackExpanded(false);
176150
}}
177151
>
178-
{showCollapsedStackCap && firstCollapsibleItem ? (
152+
{showCollapsedStackCap && firstStackedItem ? (
179153
<ComposerBanner.Peek
180154
ref={peekRef}
181-
variant={firstCollapsibleItem.variant}
155+
variant={firstStackedItem.variant}
182156
aria-label="Show other notices"
183157
aria-expanded={stackExpanded}
184158
aria-controls={expandedItemsId}
@@ -215,7 +189,24 @@ export function ComposerBannerStack({ className, items, attachedAbove }: Compose
215189
: "pointer-events-none invisible translate-y-1 opacity-0",
216190
)}
217191
>
218-
{collapsibleItems.map(renderStackedItem)}
192+
{stackedItems.map((item) => (
193+
<div
194+
key={item.id}
195+
className={cn(
196+
"transition-[opacity,translate] duration-220 ease-in",
197+
exitingItemId === item.id
198+
? "pointer-events-none translate-y-28 opacity-0"
199+
: "opacity-100",
200+
)}
201+
>
202+
<ComposerBannerStackAlert
203+
item={item}
204+
attached={false}
205+
exiting={exitingItemId === item.id}
206+
onDismissRequest={() => requestDismiss(item)}
207+
/>
208+
</div>
209+
))}
219210
</div>
220211
</div>
221212
</div>

0 commit comments

Comments
 (0)