TypeScript
fix(web): urgent and warning notices no longer hide behind activity banners (#18919)
Madhav Gautam09b464cf83df
diff --git a/apps/web/src/components/chat/ComposerBannerStack.browser.test.tsx b/apps/web/src/components/chat/ComposerBannerStack.browser.test.tsxindex 887f61abcbe..9e03a177ad3 100644--- a/apps/web/src/components/chat/ComposerBannerStack.browser.test.tsx+++ b/apps/web/src/components/chat/ComposerBannerStack.browser.test.tsx@@ -3,6 +3,7 @@ import "../../index.css";import { act } from "react";import { createRoot, type Root } from "react-dom/client";import { afterEach, beforeEach, expect, it, vi } from "vite-plus/test";+import { page, userEvent } from "vite-plus/test/browser";import { ComposerBannerStack } from "./ComposerBannerStack";@@ -58,3 +59,53 @@ it("only offers notice details when the description cannot fit", async () => {await nextFrame();expect(hasDetails()).toBe(true);});++it("keeps only the usage limit attached while an active goal waits in the collapsible stack", async () => {+ await act(async () =>+ root.render(+ <ComposerBannerStack+ items={[+ {+ id: "goal",+ variant: "default",+ priority: "activity",+ icon: null,+ title: "Goal active",+ description: "Finish the banner fix",+ },+ {+ id: "limit",+ variant: "default",+ priority: "urgent",+ icon: null,+ title: "Usage limit reached",+ },+ ]}+ />,+ ),+ );++ const visibleBanners = () =>+ Array.from(container.querySelectorAll('[data-slot="composer-banner"]')).filter((banner) =>+ banner.checkVisibility({ checkOpacity: true, checkVisibilityCSS: true }),+ );+ const limit = page.getByText("Usage limit reached", { exact: true });+ const goal = page.getByText("Goal active", { exact: true });++ expect(visibleBanners()).toHaveLength(1);+ await expect.element(limit).toBeVisible();+ await expect.element(goal).not.toBeVisible();+ expect(container.querySelector('[data-slot="composer-banner-attachment"]')?.textContent).toBe(+ "Usage limit reached",+ );++ await act(async () => page.getByRole("button", { name: "Show other notices" }).click());+ await expect.element(goal).toBeVisible();+ await expect.element(limit).toBeVisible();+ await expect.poll(visibleBanners).toHaveLength(2);++ await act(async () => userEvent.keyboard("{Escape}"));+ await expect.element(goal).not.toBeVisible();+ await expect.element(limit).toBeVisible();+ expect(visibleBanners()).toHaveLength(1);+});diff --git a/apps/web/src/components/chat/ComposerBannerStack.tsx b/apps/web/src/components/chat/ComposerBannerStack.tsxindex 6f710d91231..dd9d7c570db 100644--- a/apps/web/src/components/chat/ComposerBannerStack.tsx+++ b/apps/web/src/components/chat/ComposerBannerStack.tsx@@ -31,10 +31,10 @@ export type ComposerBannerStackContent = Pick<type ComposerBannerStackEntry = ComposerBannerStackItem | ComposerBannerStackContent;function bannerPriority(item: ComposerBannerStackEntry) {- if (item.priority === "activity") {+ if (item.priority === "urgent" || item.variant === "error" || item.variant === "warning") {return 0;}- if (item.priority === "urgent" || item.variant === "error" || item.variant === "warning") {+ if (item.priority === "activity") {return 1;}return 2;