Open-source Grok Bot alternative with a virtual machine that bots can use
TypeScript ai-agentsclaude-codecodexcomputer-usedockerelectrongrokgrok-botgrok-bot-alternativeself-hostedtypescript
Sidebar: keep the + menu inside the sidebar with a long bot name
AdityaUmale0da0f82349d9
diff --git a/src/components/Sidebar.plus-menu.test.ts b/src/components/Sidebar.plus-menu.test.tsindex df5ba31a7a..ea412a652b 100644--- a/src/components/Sidebar.plus-menu.test.ts+++ b/src/components/Sidebar.plus-menu.test.ts@@ -2,7 +2,7 @@import { Children, isValidElement, type ReactElement, type ReactNode } from "react";import { describe, expect, it, vi } from "vitest";-const fixture = vi.hoisted(() => ({ values: [] as unknown[], index: 0, admin: true as boolean | null, team: false }));+const fixture = vi.hoisted(() => ({ values: [] as unknown[], index: 0, admin: true as boolean | null, team: false, state: {} as Record<string, unknown> }));vi.mock("react", async (original) => ({...await original<typeof import("react")>(),useState: (initial: unknown) => {@@ -37,13 +37,13 @@ vi.mock("@/lib/interface-mode", () => ({ useAdvancedMode: () => false, setAdvancvi.mock("@/state/store-select", async (importOriginal) => (await import("@/testing/plain-store-select")).plainStoreSelect(await importOriginal()));vi.mock("@/state/store", async (importOriginal) => {const original = await importOriginal<typeof import("@/state/store")>();- return { ...original, useStore: () => ({ state: fixture.team ? { ...original.initialState, config: { team: { id: "acme", name: "Acme" } } } : original.initialState, dispatch: vi.fn() }) };+ return { ...original, useStore: () => ({ state: { ...original.initialState, ...fixture.team ? { config: { team: { id: "acme", name: "Acme" } } } : {}, ...fixture.state }, dispatch: vi.fn() }) };});import { Sidebar } from "./Sidebar";const drawSidebar = (Sidebar as unknown as { type: (props: import("react").ComponentProps<typeof Sidebar>) => import("react").ReactNode }).type;-type Props = { children?: ReactNode; onClick?: () => void; role?: string; [key: string]: unknown };+type Props = { children?: ReactNode; onClick?: () => void; role?: string; className?: string; [key: string]: unknown };function nodes(value: ReactNode): ReactElement<Props>[] {return Children.toArray(value).flatMap((child) => {if (!isValidElement<Props>(child)) return [];@@ -60,12 +60,16 @@ function render() {fixture.index = 0;return nodes(drawSidebar({ open: true, onClose: () => {} }));}-function plusMenu(admin: boolean | null, team = false) {+function openPlusMenu(admin: boolean | null, team = false, state: Record<string, unknown> = {}) {fixture.values = [];fixture.admin = admin;fixture.team = team;+ fixture.state = state;render().find((node) => node.type === "button" && String(node.props["aria-label"]).startsWith("New"))!.props.onClick!();- return render().filter((node) => node.props.role === "menuitem").map((node) => words(node.props.children));+ return render();+}+function plusMenu(admin: boolean | null, team = false) {+ return openPlusMenu(admin, team).filter((node) => node.props.role === "menuitem").map((node) => words(node.props.children));}describe("the sidebar's + menu", () => {@@ -82,3 +86,21 @@ describe("the sidebar's + menu", () => {expect(plusMenu(false)).toEqual(["New group chat"]);});});++describe("the sidebar's + menu with a long bot name (simple mode)", () => {+ const longName = "A bot with a very long name that would push the menu past the window edge";+ const withLongBot = () => openPlusMenu(true, false, { bots: [{ id: "long", threadId: "t", name: longName, title: "", description: "", notifications: true, color: "green", unread: false, modelSelection: { instanceId: "fake", model: "test" }, messages: [], tasks: [] }], selectedId: "long", activeView: "chat" });++ it("keeps the right-anchored menu no wider than the sidebar, so it can't run off the left edge", () => {+ const menu = withLongBot().find((node) => node.props.role === "menu")!;+ expect(menu.props.className).toContain("right-0");+ expect(menu.props.className).toContain("md:max-w-[calc(var(--sidebar-width)_-_48px)]");+ });++ it("truncates the bot's name in New conversation with … and keeps the full name on hover", () => {+ const item = withLongBot().filter((node) => node.props.role === "menuitem")[0];+ const label = nodes(item.props.children).find((node) => node.type === "span" && node.props.title === longName);+ expect(label?.props.className).toContain("truncate");+ expect(label?.props.className).toContain("min-w-0");+ });+});diff --git a/src/components/Sidebar.tsx b/src/components/Sidebar.tsxindex 24d7aff825..830c94734c 100644--- a/src/components/Sidebar.tsx+++ b/src/components/Sidebar.tsx@@ -1163,7 +1163,7 @@ export const Sidebar = memo(function Sidebar({ open, onClose, collapseToIcons =<><div role="menu" aria-label={remoteClient ? t("sidebar.new") : t("sidebar.newOrShare")} onKeyDown={navigateThreadMenu} className={cn("absolute z-40 w-max min-w-[200px] overflow-hidden", MENU_SHEET,- rail ? "left-full top-0 ml-4" : cn("top-full", advanced ? "mt-1" : "mt-1.5", density === "icons" ? "left-0" : "right-0"),+ rail ? "left-full top-0 ml-4" : cn("top-full", advanced ? "mt-1" : "mt-1.5", density === "icons" ? "left-0" : "right-0 md:max-w-[calc(var(--sidebar-width)_-_48px)]"),plusMotion.className,)} {...plusMotion.exitProps}>{advanced && <button@@ -1177,7 +1177,7 @@ export const Sidebar = memo(function Sidebar({ open, onClose, collapseToIcons =<MessageSquarePlus size={16} className="text-ink-secondary" />{t("sidebar.newChat.title")}</button>}- {!advanced && plusBot && <><button role="menuitem" className={plusItem} onClick={() => { setPlusOpen(false); dispatch({ type: "newTask", botId: plusBot.id }); }}><SquarePen size={16} className="text-ink-secondary" />{t("sidebar.newConversationWith", { name: plusBot.name })}</button><div role="separator" className={MENU_ITEM_SEPARATOR} /></>}+ {!advanced && plusBot && <><button role="menuitem" className={plusItem} onClick={() => { setPlusOpen(false); dispatch({ type: "newTask", botId: plusBot.id }); }}><SquarePen size={16} className="shrink-0 text-ink-secondary" /><span className="min-w-0 truncate" title={plusBot.name}>{t("sidebar.newConversationWith", { name: plusBot.name })}</span></button><div role="separator" className={MENU_ITEM_SEPARATOR} /></>}{(teamSettingsAllowed !== false || state.config?.team) && <buttononClick={() => { setPlusOpen(false); dispatch({ type: "newBot" }); }}role="menuitem"