Skip to content

AutoGPT is the vision of accessible AI for everyone, to use and to build on. Our mission is to provide the tools, so that you can focus on what matters.

fix(frontend): line up mobile expert pill with the floating controls (#15455)

Ubbe3bd56ebada4a
diff --git a/autogpt_platform/frontend/src/app/(platform)/copilot/CopilotChatHost.tsx b/autogpt_platform/frontend/src/app/(platform)/copilot/CopilotChatHost.tsx
index 2d6610349e..51efbec934 100644
--- a/autogpt_platform/frontend/src/app/(platform)/copilot/CopilotChatHost.tsx
+++ b/autogpt_platform/frontend/src/app/(platform)/copilot/CopilotChatHost.tsx
@@ -1,5 +1,6 @@
"use client";
import { ChatContainer } from "./components/ChatContainer/ChatContainer";
+import type { FloatingControls } from "./components/ChatMessagesContainer/components/ThreadHeader";
import { ProviderLimitDialog } from "./components/ProviderLimitDialog/ProviderLimitDialog";
import { RateLimitGate } from "./components/RateLimitResetDialog/RateLimitGate";
import { useCopilotPage } from "./useCopilotPage";
@@ -10,9 +11,9 @@ import { Flag, useGetFlag } from "@/services/feature-flags/use-get-flag";
interface Props {
droppedFiles: File[];
onDroppedFilesConsumed: () => void;
- /** The new layout floats its sidebar/files controls over the chat's
- * top-left corner on small viewports. */
- hasFloatingControls?: boolean;
+ /** Which layout floats its controls over the chat's top-left corner on
+ * small viewports. */
+ floatingControls?: FloatingControls;
}
/**
@@ -35,7 +36,7 @@ export function CopilotChatHost(props: Props) {
function ChatHostBody({
droppedFiles,
onDroppedFilesConsumed,
- hasFloatingControls,
+ floatingControls,
isStreamRuntime,
}: Props & { isStreamRuntime: boolean }) {
const {
@@ -128,7 +129,7 @@ function ChatHostBody({
isAdoptingExpertSession={isAdoptingExpertSession}
isKickoffStarting={isKickoffStarting}
onBackendTurn={followBackendTurn}
- hasFloatingControls={hasFloatingControls}
+ floatingControls={floatingControls}
/>
</div>
<RateLimitGate
diff --git a/autogpt_platform/frontend/src/app/(platform)/copilot/CopilotPage.tsx b/autogpt_platform/frontend/src/app/(platform)/copilot/CopilotPage.tsx
index 8d641a580d..c869d3118c 100644
--- a/autogpt_platform/frontend/src/app/(platform)/copilot/CopilotPage.tsx
+++ b/autogpt_platform/frontend/src/app/(platform)/copilot/CopilotPage.tsx
@@ -141,7 +141,9 @@ function MainArea({
key={`chat-host-${sessionId ?? "new"}`}
droppedFiles={droppedFiles}
onDroppedFilesConsumed={() => setDroppedFiles([])}
- hasFloatingControls={isMobile || showNewLayout}
+ floatingControls={
+ showNewLayout ? "newLayout" : isMobile ? "classic" : undefined
+ }
/>
{/* Owns the session-entry reset that forgets the previous chat's
artifact. */}
diff --git a/autogpt_platform/frontend/src/app/(platform)/copilot/components/ChatContainer/ChatContainer.tsx b/autogpt_platform/frontend/src/app/(platform)/copilot/components/ChatContainer/ChatContainer.tsx
index d802b12375..f431e99dd4 100644
--- a/autogpt_platform/frontend/src/app/(platform)/copilot/components/ChatContainer/ChatContainer.tsx
+++ b/autogpt_platform/frontend/src/app/(platform)/copilot/components/ChatContainer/ChatContainer.tsx
@@ -13,6 +13,7 @@ import type { TurnStatsMap } from "../../helpers/convertChatSessionToUiMessages"
import type { WorkspaceAttachment } from "../../helpers/workspaceAttachments";
import type { PendingUploadSend } from "../../copilotStreamStore";
import { ChatMessagesContainer } from "../ChatMessagesContainer/ChatMessagesContainer";
+import type { FloatingControls } from "../ChatMessagesContainer/components/ThreadHeader";
import { CopilotChatActionsProvider } from "../CopilotChatActionsProvider/CopilotChatActionsProvider";
import { NewChatOnboarding } from "../ExpertOnboardingCard/NewChatOnboarding";
import { EmptySession } from "../EmptySession/EmptySession";
@@ -118,9 +119,9 @@ export interface ChatContainerProps {
isKickoffStarting?: boolean;
/** Follow a turn the server started, e.g. after an approval card is answered. */
onBackendTurn?: () => void;
- /** The layout floats its sidebar/files controls over the chat's top-left
- * corner on small viewports; the thread header clears them. */
- hasFloatingControls?: boolean;
+ /** Which layout floats its controls over the chat's top-left corner on
+ * small viewports; the thread header lines up with them. */
+ floatingControls?: FloatingControls;
}
const NO_OP_SEND = () => undefined;
@@ -162,7 +163,7 @@ export const ChatContainer = ({
isAdoptingExpertSession,
isKickoffStarting,
onBackendTurn,
- hasFloatingControls,
+ floatingControls,
}: ChatContainerProps) => {
const isTaskBarEnabled = useGetFlag(Flag.TASK_PROGRESS_BAR);
useAutoOpenArtifacts({
@@ -393,7 +394,7 @@ export const ChatContainer = ({
bottomContentPadding={usageCardHeight}
expertIdentity={expertIdentity}
isResolvingExpertIdentity={isResolvingExpertIdentity}
- hasFloatingControls={hasFloatingControls}
+ floatingControls={floatingControls}
/>
</NewChatOnboarding>
{archivedExpertIdentity ? (
diff --git a/autogpt_platform/frontend/src/app/(platform)/copilot/components/ChatMessagesContainer/ChatMessagesContainer.tsx b/autogpt_platform/frontend/src/app/(platform)/copilot/components/ChatMessagesContainer/ChatMessagesContainer.tsx
index b6327daa6f..4ded8b8713 100644
--- a/autogpt_platform/frontend/src/app/(platform)/copilot/components/ChatMessagesContainer/ChatMessagesContainer.tsx
+++ b/autogpt_platform/frontend/src/app/(platform)/copilot/components/ChatMessagesContainer/ChatMessagesContainer.tsx
@@ -53,7 +53,7 @@ import { TailSpacer } from "./components/TailSpacer";
import { MessageAttachments } from "./components/MessageAttachments";
import { MessagePartRenderer } from "./components/MessagePartRenderer";
import { QueueBadge } from "./components/QueueBadge";
-import { ThreadHeader } from "./components/ThreadHeader";
+import { ThreadHeader, type FloatingControls } from "./components/ThreadHeader";
import {
PENDING_UPLOAD_MESSAGE_ID,
PendingUploadMessage,
@@ -133,9 +133,9 @@ interface Props {
* metadata). Shown on the row that opened the thread (DB sequence 0) when
* that row carries no provenance of its own. */
sessionSentFrom?: SentFrom | null;
- /** The layout floats its sidebar/files controls over the chat's top-left
- * corner on small viewports (see ThreadHeader). */
- hasFloatingControls?: boolean;
+ /** Which layout floats its controls over the chat's top-left corner on
+ * small viewports (see ThreadHeader). */
+ floatingControls?: FloatingControls;
/** Compact thread for side panels: smaller text, tighter bubbles and
* spacing. */
variant?: "default" | "compact";
@@ -299,7 +299,7 @@ export function ChatMessagesContainer({
expertIdentity,
isResolvingExpertIdentity = false,
sessionSentFrom = null,
- hasFloatingControls = false,
+ floatingControls,
variant = "default",
showThreadHeader = true,
}: Props) {
@@ -470,7 +470,7 @@ export function ChatMessagesContainer({
<ThreadHeader
expertIdentity={expertIdentity}
isResolvingExpertIdentity={isResolvingExpertIdentity}
- hasFloatingControls={hasFloatingControls}
+ floatingControls={floatingControls}
/>
)}
{!isCompact && <ChatMinimap messages={messages} />}
@@ -488,7 +488,7 @@ export function ChatMessagesContainer({
className={cn(
"mx-auto flex min-h-full w-full max-w-3xl flex-1 flex-col gap-6 px-6 pb-4 pt-14",
isCompact && "gap-4 px-4 pt-4",
- showThreadHeader && hasFloatingControls && "max-lg:pt-32",
+ showThreadHeader && floatingControls && "max-lg:pt-20",
!showThreadHeader && "pt-4",
)}
style={
diff --git a/autogpt_platform/frontend/src/app/(platform)/copilot/components/ChatMessagesContainer/components/ThreadHeader.tsx b/autogpt_platform/frontend/src/app/(platform)/copilot/components/ChatMessagesContainer/components/ThreadHeader.tsx
index 7b40d9047a..c21e8bc277 100644
--- a/autogpt_platform/frontend/src/app/(platform)/copilot/components/ChatMessagesContainer/components/ThreadHeader.tsx
+++ b/autogpt_platform/frontend/src/app/(platform)/copilot/components/ChatMessagesContainer/components/ThreadHeader.tsx
@@ -16,12 +16,25 @@ import { ExpertAvatar } from "./ExpertAvatar/ExpertAvatar";
// Otto's product-facing title when a session carries no expert identity.
const DEFAULT_EXPERT_ROLE = "Head of AI";
+export type FloatingControls = "classic" | "newLayout";
+
+// Below `lg` the chip joins the floating controls' row: centred on their
+// height, one button gap after the last one. Classic: MobileHeader's 46px
+// buttons sit 20px down and 16px in; the chat column starts 8px in. New
+// layout: the inset header's 36px buttons sit 24px down and in (32px in from
+// `md`, where only the files button shows).
+const floatingControlsClassName: Record<FloatingControls, string> = {
+ classic: "max-lg:top-5 max-lg:pl-[116px]",
+ newLayout: "max-lg:top-[19px] max-md:pl-[104px] md:max-lg:pl-[68px]",
+};
+
interface Props {
expertIdentity?: ExpertIdentity | null;
/** The roster has not settled yet for an expert-scoped session. */
isResolvingExpertIdentity?: boolean;
- /** Floating mobile controls need a separate row above the chip. */
- hasFloatingControls?: boolean;
+ /** Which layout floats its controls over the chat's top-left corner on
+ * small viewports; the chip lines up with them. */
+ floatingControls?: FloatingControls;
}
/** Floats as a translucent chip pinned to the pane's top-left gutter — the
@@ -32,7 +45,7 @@ interface Props {
export function ThreadHeader({
expertIdentity,
isResolvingExpertIdentity = false,
- hasFloatingControls = false,
+ floatingControls,
}: Props) {
// While the roster loads, the chip shows a quiet placeholder rather than
// Otto's identity, which would be wrong for an expert session.
@@ -47,7 +60,7 @@ export function ThreadHeader({
<div
className={cn(
"pointer-events-none absolute inset-x-0 top-3 flex justify-start px-4",
- hasFloatingControls && "max-lg:top-16",
+ floatingControls && floatingControlsClassName[floatingControls],
)}
>
<TooltipProvider>
diff --git a/autogpt_platform/frontend/src/app/(platform)/copilot/components/ContextPanel/ContextPanelToggle.tsx b/autogpt_platform/frontend/src/app/(platform)/copilot/components/ContextPanel/ContextPanelToggle.tsx
index 7fcb3d464e..25e36d6090 100644
--- a/autogpt_platform/frontend/src/app/(platform)/copilot/components/ContextPanel/ContextPanelToggle.tsx
+++ b/autogpt_platform/frontend/src/app/(platform)/copilot/components/ContextPanel/ContextPanelToggle.tsx
@@ -46,8 +46,10 @@ export function ContextPanelToggle({ sessionId = null, expert = null }: Props) {
const openComputer = useCopilotUIStore((s) => s.openComputer);
const closeComputer = useCopilotUIStore((s) => s.closeComputer);
const isMobile = useIsMobile();
- // The mobile sheet has no computer face to open.
+ // The mobile sheet has no computer face to open, and mobile already floats
+ // a files button over the chat's top-left corner.
const showComputerToggle = !!sessionId && !isMobile;
+ const showFilesToggle = !isMobile;
function handleComputerToggle() {
// Back to whatever the computer was covering: the preview, the tab, or
@@ -56,6 +58,8 @@ export function ContextPanelToggle({ sessionId = null, expert = null }: Props) {
else openComputer();
}
+ if (!expert && !showComputerToggle && !showFilesToggle) return null;
+
return (
// With the side panel open the chat column narrows under these controls,
// so they lift off the messages instead of blending into them.
@@ -82,34 +86,36 @@ export function ContextPanelToggle({ sessionId = null, expert = null }: Props) {
/>
</Button>
)}
- <Button
- type="button"
- variant="ghost"
- size="icon"
- onClick={() => toggleContextPanelTab("files")}
- aria-label={`${isFilesOpen ? "Hide" : "Open"} files${
- documentCount > 0
- ? ` (${documentCount} ${documentCount === 1 ? "document" : "documents"})`
- : ""
- }`}
- aria-pressed={isFilesOpen}
- className={cn(
- toggleClass,
- "h-8",
- documentCount > 0 ? "w-auto gap-1 px-2" : "w-8",
- isFilesOpen && "bg-zinc-100",
- )}
- >
- <Icon
- icon={LicenseDraftIcon}
- className="!size-4 text-sidebar-foreground/90"
- />
- {documentCount > 0 && (
- <span className="text-xs font-medium tabular-nums text-sidebar-foreground/90">
- {documentCount}
- </span>
- )}
- </Button>
+ {showFilesToggle && (
+ <Button
+ type="button"
+ variant="ghost"
+ size="icon"
+ onClick={() => toggleContextPanelTab("files")}
+ aria-label={`${isFilesOpen ? "Hide" : "Open"} files${
+ documentCount > 0
+ ? ` (${documentCount} ${documentCount === 1 ? "document" : "documents"})`
+ : ""
+ }`}
+ aria-pressed={isFilesOpen}
+ className={cn(
+ toggleClass,
+ "h-8",
+ documentCount > 0 ? "w-auto gap-1 px-2" : "w-8",
+ isFilesOpen && "bg-zinc-100",
+ )}
+ >
+ <Icon
+ icon={LicenseDraftIcon}
+ className="!size-4 text-sidebar-foreground/90"
+ />
+ {documentCount > 0 && (
+ <span className="text-xs font-medium tabular-nums text-sidebar-foreground/90">
+ {documentCount}
+ </span>
+ )}
+ </Button>
+ )}
</div>
);
}
diff --git a/autogpt_platform/frontend/src/app/(platform)/copilot/components/ContextPanel/__tests__/ContextPanelToggle.test.tsx b/autogpt_platform/frontend/src/app/(platform)/copilot/components/ContextPanel/__tests__/ContextPanelToggle.test.tsx
index fd130b8ad9..0328ec4b14 100644
--- a/autogpt_platform/frontend/src/app/(platform)/copilot/components/ContextPanel/__tests__/ContextPanelToggle.test.tsx
+++ b/autogpt_platform/frontend/src/app/(platform)/copilot/components/ContextPanel/__tests__/ContextPanelToggle.test.tsx
@@ -295,6 +295,14 @@ describe("ContextPanelToggle computer button", () => {
render(<ContextPanelToggle sessionId="s1" />);
expect(screen.queryByLabelText("Open computer")).toBeNull();
- expect(screen.getByLabelText("Open files")).toBeDefined();
+ });
+});
+
+describe("files toggle on mobile", () => {
+ test("is hidden, since mobile floats its own files button", () => {
+ setMobile(true);
+ render(<ContextPanelToggle sessionId="s1" />);
+
+ expect(screen.queryByLabelText(/files/)).toBeNull();
});
});
diff --git a/autogpt_platform/frontend/src/app/(platform)/copilot/components/MobileHeader/MobileHeader.tsx b/autogpt_platform/frontend/src/app/(platform)/copilot/components/MobileHeader/MobileHeader.tsx
index 95f98c0574..35f5cbaca3 100644
--- a/autogpt_platform/frontend/src/app/(platform)/copilot/components/MobileHeader/MobileHeader.tsx
+++ b/autogpt_platform/frontend/src/app/(platform)/copilot/components/MobileHeader/MobileHeader.tsx
@@ -6,7 +6,9 @@ import { Icon } from "@/components/atoms/Icon/Icon";
export function MobileHeader() {
const setDrawerOpen = useCopilotUIStore((s) => s.setDrawerOpen);
- const toggleContextPanel = useCopilotUIStore((s) => s.toggleContextPanel);
+ const toggleContextPanelTab = useCopilotUIStore(
+ (s) => s.toggleContextPanelTab,
+ );
return (
<div
className="fixed z-50 flex gap-2"
@@ -25,7 +27,7 @@ export function MobileHeader() {
variant="icon"
size="icon"
aria-label="Open workspace files"
- onClick={toggleContextPanel}
+ onClick={() => toggleContextPanelTab("files")}
className="bg-white shadow-md"
>
<Icon icon={Folder01Icon} width="1.25rem" height="1.25rem" />
diff --git a/autogpt_platform/frontend/src/app/(platform)/copilot/components/WorkspaceFilesTrigger/WorkspaceFilesTrigger.tsx b/autogpt_platform/frontend/src/app/(platform)/copilot/components/WorkspaceFilesTrigger/WorkspaceFilesTrigger.tsx
index 65719eee69..c48e0eec52 100644
--- a/autogpt_platform/frontend/src/app/(platform)/copilot/components/WorkspaceFilesTrigger/WorkspaceFilesTrigger.tsx
+++ b/autogpt_platform/frontend/src/app/(platform)/copilot/components/WorkspaceFilesTrigger/WorkspaceFilesTrigger.tsx
@@ -12,14 +12,16 @@ interface Props {
// Sits next to the sidebar toggle in the new-layout inset header and mirrors
// SidebarTrigger's ghost styling (no border, no shadow).
export function WorkspaceFilesTrigger({ className }: Props) {
- const toggleContextPanel = useCopilotUIStore((s) => s.toggleContextPanel);
+ const toggleContextPanelTab = useCopilotUIStore(
+ (s) => s.toggleContextPanelTab,
+ );
return (
<Button
variant="ghost"
size="icon"
className={className}
- onClick={toggleContextPanel}
+ onClick={() => toggleContextPanelTab("files")}
aria-label="Open workspace files"
>
<Icon icon={Folder01Icon} className="!size-5" />
diff --git a/autogpt_platform/frontend/src/app/(platform)/copilot/components/WorkspaceFilesTrigger/__tests__/WorkspaceFilesTrigger.test.tsx b/autogpt_platform/frontend/src/app/(platform)/copilot/components/WorkspaceFilesTrigger/__tests__/WorkspaceFilesTrigger.test.tsx
index 867b249be1..1d633aa982 100644
--- a/autogpt_platform/frontend/src/app/(platform)/copilot/components/WorkspaceFilesTrigger/__tests__/WorkspaceFilesTrigger.test.tsx
+++ b/autogpt_platform/frontend/src/app/(platform)/copilot/components/WorkspaceFilesTrigger/__tests__/WorkspaceFilesTrigger.test.tsx
@@ -1,22 +1,26 @@
import { render, screen, fireEvent } from "@/tests/integrations/test-utils";
-import { beforeEach, describe, expect, it, vi } from "vitest";
-
-const { toggleContextPanelMock } = vi.hoisted(() => ({
- toggleContextPanelMock: vi.fn(),
-}));
-
-vi.mock("../../../store", () => ({
- useCopilotUIStore: (selector: (state: unknown) => unknown) =>
- selector({ toggleContextPanel: toggleContextPanelMock }),
-}));
-
+import { beforeEach, describe, expect, it } from "vitest";
+import { useCopilotUIStore } from "../../../store";
+import { MobileHeader } from "../../MobileHeader/MobileHeader";
import { WorkspaceFilesTrigger } from "../WorkspaceFilesTrigger";
-describe("WorkspaceFilesTrigger", () => {
- beforeEach(() => {
- toggleContextPanelMock.mockClear();
- });
+beforeEach(() => {
+ useCopilotUIStore.setState((state) => ({
+ contextPanelExpert: null,
+ artifactPanel: {
+ ...state.artifactPanel,
+ isOpen: false,
+ activeTab: "files",
+ activeArtifact: null,
+ lastArtifact: null,
+ history: [],
+ mode: "artifact",
+ isComputerOpen: false,
+ },
+ }));
+});
+describe("WorkspaceFilesTrigger", () => {
it("offers workspace files without a feature flag", () => {
render(<WorkspaceFilesTrigger />);
expect(
@@ -31,7 +35,7 @@ describe("WorkspaceFilesTrigger", () => {
screen.getByRole("button", { name: /open workspace files/i }),
);
- expect(toggleContextPanelMock).toHaveBeenCalledTimes(1);
+ expect(useCopilotUIStore.getState().artifactPanel.isOpen).toBe(true);
});
it("forwards className so the header can restyle it", () => {
@@ -42,3 +46,42 @@ describe("WorkspaceFilesTrigger", () => {
).toContain("rounded-full");
});
});
+
+describe.each([
+ ["classic layout", MobileHeader],
+ ["new layout", WorkspaceFilesTrigger],
+] as const)("workspace files button in the %s", (_layout, Controls) => {
+ it.each([true, false])(
+ "opens files after integrations when the panel is open: %s",
+ (isOpen) => {
+ useCopilotUIStore.getState().toggleIntegrationsPanel({
+ id: "expert-maria",
+ name: "Maria",
+ });
+ if (!isOpen)
+ useCopilotUIStore.getState().toggleContextPanelTab("integrations");
+ render(<Controls />);
+
+ fireEvent.click(
+ screen.getByRole("button", { name: /open workspace files/i }),
+ );
+
+ expect(useCopilotUIStore.getState().artifactPanel).toMatchObject({
+ isOpen: true,
+ activeTab: "files",
+ });
+ },
+ );
+
+ it("closes files when clicked again", () => {
+ render(<Controls />);
+ const button = screen.getByRole("button", {
+ name: /open workspace files/i,
+ });
+
+ fireEvent.click(button);
+ fireEvent.click(button);
+
+ expect(useCopilotUIStore.getState().artifactPanel.isOpen).toBe(false);
+ });
+});