Skip to content

Shared task board where people and AI coding agents work as teammates. Source-available, self-hostable.

Go

MUL-9067: feat(chat): close the quick-chat window from its header (#10388)

Jiayuan Zhange8d7fde3a7ed
diff --git a/packages/views/chat/components/chat-window.test.tsx b/packages/views/chat/components/chat-window.test.tsx
index a473d5592f..d92f0ae698 100644
--- a/packages/views/chat/components/chat-window.test.tsx
+++ b/packages/views/chat/components/chat-window.test.tsx
@@ -1,7 +1,7 @@
// @vitest-environment jsdom
import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
-import { act, render, screen } from "@testing-library/react";
+import { act, fireEvent, render, screen } from "@testing-library/react";
import { beforeEach, describe, expect, it, vi } from "vitest";
import { createChatStore, registerChatStore, useChatStore } from "@multica/core/chat";
import { chatSessionsOptions } from "@multica/core/chat/queries";
@@ -108,12 +108,13 @@ beforeEach(() => {
});
describe("ChatWindow header buttons", () => {
- it("names the new chat, expand and minimize buttons after their tooltips", () => {
+ it("names the new chat, expand, minimize and close buttons after their tooltips", () => {
renderWindow();
expect(screen.getByRole("button", { name: enChat.window.new_chat_tooltip })).toBeInTheDocument();
expect(screen.getByRole("button", { name: enChat.window.expand_tooltip })).toBeInTheDocument();
expect(screen.getByRole("button", { name: enChat.window.minimize_tooltip })).toBeInTheDocument();
+ expect(screen.getByRole("button", { name: enChat.window.close_tooltip })).toBeInTheDocument();
expect(
screen.queryByRole("button", { name: enChat.window.restore_tooltip }),
).not.toBeInTheDocument();
@@ -138,3 +139,31 @@ describe("ChatWindow header buttons", () => {
expect(screen.getByRole("button", { name: enChat.window.restore_tooltip })).toBeInTheDocument();
});
});
+
+describe("ChatWindow minimize and close", () => {
+ beforeEach(() => {
+ act(() => {
+ useChatStore.setState({ chatBarKept: [session.id], chatBarDismissed: {} });
+ });
+ });
+
+ it("minimize hides the window and keeps the chat's chip", () => {
+ renderWindow();
+
+ fireEvent.click(screen.getByRole("button", { name: enChat.window.minimize_tooltip }));
+
+ expect(useChatStore.getState().isOpen).toBe(false);
+ expect(useChatStore.getState().chatBarKept).toEqual([session.id]);
+ });
+
+ it("close hides the window and closes the chat's chip", () => {
+ renderWindow();
+
+ fireEvent.click(screen.getByRole("button", { name: enChat.window.close_tooltip }));
+
+ const state = useChatStore.getState();
+ expect(state.isOpen).toBe(false);
+ expect(state.chatBarKept).toEqual([]);
+ expect(state.chatBarDismissed).toEqual({ [session.id]: session.updated_at });
+ });
+});
diff --git a/packages/views/chat/components/chat-window.tsx b/packages/views/chat/components/chat-window.tsx
index 2bac0728b5..7461d58bda 100644
--- a/packages/views/chat/components/chat-window.tsx
+++ b/packages/views/chat/components/chat-window.tsx
@@ -3,7 +3,7 @@
import React, { useCallback, useEffect, useMemo, useRef, useState } from "react";
import { useQuery, useQueryClient } from "@tanstack/react-query";
import { AnimatePresence, motion } from "motion/react";
-import { Minus, Maximize2, Minimize2, ChevronDown, Plus, Check, Archive, Pencil, Loader2, Square } from "@multica/ui/icons";
+import { Minus, Maximize2, Minimize2, ChevronDown, Plus, Check, Archive, Pencil, Loader2, Square, X } from "@multica/ui/icons";
import { Button } from "@multica/ui/components/ui/button";
import { cn } from "@multica/ui/lib/utils";
import { Tooltip, TooltipTrigger, TooltipContent } from "@multica/ui/components/ui/tooltip";
@@ -78,6 +78,7 @@ import { ChatAppRequests } from "../../common/app-requests";
import { EmptyState } from "./chat-empty-state";
import { SessionRenameInput } from "./session-rename-input";
import { SessionHistoryList } from "./session-history-list";
+import { chatActivity } from "./chat-bar-sessions";
import { ChatResizeHandles } from "./chat-resize-handles";
import { useChatContextItems } from "./use-chat-context-items";
import { useChatResize } from "./use-chat-resize";
@@ -116,6 +117,7 @@ export function ChatWindow() {
const selectedAgentId = useChatStore((s) => s.selectedAgentId);
const selectedProjectId = useChatStore((s) => s.selectedProjectId);
const setOpen = useChatStore((s) => s.setOpen);
+ const dismissChatFromBar = useChatStore((s) => s.dismissChatFromBar);
const setActiveSession = useChatStore((s) => s.setActiveSession);
const setSelectedAgentId = useChatStore((s) => s.setSelectedAgentId);
const setSelectedProjectId = useChatStore((s) => s.setSelectedProjectId);
@@ -732,6 +734,17 @@ export function ChatWindow() {
setOpen(false);
}, [activeSessionId, pendingTaskId, setOpen]);
+ // Minimize leaves the chat's chip in the bottom bar; close also takes the
+ // chip away, the same as closing it from the bar.
+ const handleClose = useCallback(() => {
+ uiLogger.info("close", {
+ activeSessionId,
+ pendingTaskId,
+ });
+ setOpen(false);
+ if (currentSession) dismissChatFromBar(currentSession.id, chatActivity(currentSession));
+ }, [activeSessionId, pendingTaskId, currentSession, setOpen, dismissChatFromBar]);
+
const isExpanded = useChatStore((s) => s.isExpanded);
const { renderWidth, renderHeight, isAtMax, boundsReady, isDragging, toggleExpand, startDrag } = useChatResize(windowRef);
@@ -813,6 +826,7 @@ export function ChatWindow() {
? t(($) => $.window.restore_tooltip)
: t(($) => $.window.expand_tooltip);
const minimizeLabel = t(($) => $.window.minimize_tooltip);
+ const closeLabel = t(($) => $.window.close_tooltip);
const sizeTransition =
isDragging || reduceMotion ? { duration: 0 } : { type: "spring" as const, duration: 0.3, bounce: 0 };
@@ -902,6 +916,24 @@ export function ChatWindow() {
<ActionShortcutKeycaps action="toggleChat" />
</TooltipContent>
</Tooltip>
+ {!isMobile && (
+ <Tooltip>
+ <TooltipTrigger
+ render={
+ <Button
+ variant="ghost"
+ size="icon-sm"
+ className="text-muted-foreground"
+ aria-label={closeLabel}
+ onClick={handleClose}
+ />
+ }
+ >
+ <X />
+ </TooltipTrigger>
+ <TooltipContent side="top">{closeLabel}</TooltipContent>
+ </Tooltip>
+ )}
</div>
</div>
diff --git a/packages/views/locales/en/chat.json b/packages/views/locales/en/chat.json
index 23cc0d6f07..2fa8258c67 100644
--- a/packages/views/locales/en/chat.json
+++ b/packages/views/locales/en/chat.json
@@ -149,6 +149,7 @@
"restore_tooltip": "Restore",
"expand_tooltip": "Expand",
"minimize_tooltip": "Minimize",
+ "close_tooltip": "Close",
"another_running": "Another chat is running",
"another_unread": "Another chat has unread replies",
"running": "Running",
diff --git a/packages/views/locales/es/chat.json b/packages/views/locales/es/chat.json
index 46a138bb49..dabfec9fca 100644
--- a/packages/views/locales/es/chat.json
+++ b/packages/views/locales/es/chat.json
@@ -149,6 +149,7 @@
"restore_tooltip": "Restaurar",
"expand_tooltip": "Expandir",
"minimize_tooltip": "Minimizar",
+ "close_tooltip": "Cerrar",
"another_running": "Otro chat está en ejecución",
"another_unread": "Otro chat tiene respuestas sin leer",
"running": "En ejecución",
diff --git a/packages/views/locales/fr/chat.json b/packages/views/locales/fr/chat.json
index 0a8fbab96a..b7f79e1563 100644
--- a/packages/views/locales/fr/chat.json
+++ b/packages/views/locales/fr/chat.json
@@ -149,6 +149,7 @@
"restore_tooltip": "Restaurer",
"expand_tooltip": "Développer",
"minimize_tooltip": "Réduire",
+ "close_tooltip": "Fermer",
"another_running": "Une autre discussion est en cours",
"another_unread": "Une autre discussion a des réponses non lues",
"running": "En cours",
diff --git a/packages/views/locales/ja/chat.json b/packages/views/locales/ja/chat.json
index f59517a44e..442feb605f 100644
--- a/packages/views/locales/ja/chat.json
+++ b/packages/views/locales/ja/chat.json
@@ -144,6 +144,7 @@
"restore_tooltip": "復元",
"expand_tooltip": "展開",
"minimize_tooltip": "最小化",
+ "close_tooltip": "閉じる",
"another_running": "別のチャットが実行中です",
"another_unread": "別のチャットに未読の返信があります",
"running": "実行中",
diff --git a/packages/views/locales/ko/chat.json b/packages/views/locales/ko/chat.json
index c2482eaad3..ab173202e9 100644
--- a/packages/views/locales/ko/chat.json
+++ b/packages/views/locales/ko/chat.json
@@ -144,6 +144,7 @@
"restore_tooltip": "복원",
"expand_tooltip": "펼치기",
"minimize_tooltip": "최소화",
+ "close_tooltip": "닫기",
"another_running": "다른 채팅이 실행 중입니다",
"another_unread": "다른 채팅에 읽지 않은 답변이 있습니다",
"running": "실행 중",
diff --git a/packages/views/locales/ru/chat.json b/packages/views/locales/ru/chat.json
index 5c4cb1784b..22ad9f8f1a 100644
--- a/packages/views/locales/ru/chat.json
+++ b/packages/views/locales/ru/chat.json
@@ -159,6 +159,7 @@
"restore_tooltip": "Восстановить",
"expand_tooltip": "Развернуть",
"minimize_tooltip": "Свернуть",
+ "close_tooltip": "Закрыть",
"another_running": "Выполняется другой чат",
"another_unread": "В другом чате есть непрочитанные ответы",
"running": "Выполняется",
diff --git a/packages/views/locales/zh-Hans/chat.json b/packages/views/locales/zh-Hans/chat.json
index f7f8c383d1..f7dc5536f3 100644
--- a/packages/views/locales/zh-Hans/chat.json
+++ b/packages/views/locales/zh-Hans/chat.json
@@ -144,6 +144,7 @@
"restore_tooltip": "还原",
"expand_tooltip": "展开",
"minimize_tooltip": "最小化",
+ "close_tooltip": "关闭",
"another_running": "另一个对话正在运行",
"another_unread": "另一个对话有未读回复",
"running": "运行中",
diff --git a/packages/views/locales/zh-Hant/chat.json b/packages/views/locales/zh-Hant/chat.json
index 2c7425ece8..5a85e46c46 100644
--- a/packages/views/locales/zh-Hant/chat.json
+++ b/packages/views/locales/zh-Hant/chat.json
@@ -144,6 +144,7 @@
"restore_tooltip": "還原",
"expand_tooltip": "展開",
"minimize_tooltip": "最小化",
+ "close_tooltip": "關閉",
"another_running": "另一個對話正在執行",
"another_unread": "另一個對話有未讀回覆",
"running": "執行中",