fix(FN-4804): sync quick chat session and room selection
- Clear the active chat room when switching Quick Chat to a direct session - Keep the hidden session dropdown value and initial-session state aligned with room selection changes - Add dashboard regression coverage for switching from a room back to a direct chat and include a CLI patch changeset Fusion-Task-Id: FN-4804
This commit is contained in:
committed by
gsxdsm
parent
c3dd34f070
commit
4691cbe199
5
.changeset/fn-4804-quick-chat-session-dropdown.md
Normal file
5
.changeset/fn-4804-quick-chat-session-dropdown.md
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
---
|
||||||
|
"@runfusion/fusion": patch
|
||||||
|
---
|
||||||
|
|
||||||
|
Fix Quick Chat session dropdown so picking a session option actually switches the visible chat (header label, composer placeholder, message list) and mutually excludes active chat-room selection.
|
||||||
@@ -1785,6 +1785,10 @@ export function QuickChatFAB({
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (chatRoomsEnabled && roomsState.activeRoom) {
|
||||||
|
roomsState.selectRoom(null);
|
||||||
|
}
|
||||||
|
|
||||||
markRead("direct", selectedSession.id, selectedSession.lastMessageAt ?? selectedSession.updatedAt);
|
markRead("direct", selectedSession.id, selectedSession.lastMessageAt ?? selectedSession.updatedAt);
|
||||||
hasAppliedInitialSessionRef.current = true;
|
hasAppliedInitialSessionRef.current = true;
|
||||||
|
|
||||||
@@ -1798,12 +1802,13 @@ export function QuickChatFAB({
|
|||||||
|
|
||||||
void selectSession(selectedSession);
|
void selectSession(selectedSession);
|
||||||
setSessionMenuOpen(false);
|
setSessionMenuOpen(false);
|
||||||
}, [markRead, selectSession, sessions]);
|
}, [chatRoomsEnabled, markRead, roomsState, selectSession, sessions]);
|
||||||
|
|
||||||
const handleRoomSwitch = useCallback((roomId: string) => {
|
const handleRoomSwitch = useCallback((roomId: string) => {
|
||||||
const selectedRoom = roomsState.rooms.find((room) => room.id === roomId);
|
const selectedRoom = roomsState.rooms.find((room) => room.id === roomId);
|
||||||
markRead("room", roomId, selectedRoom?.updatedAt);
|
markRead("room", roomId, selectedRoom?.updatedAt);
|
||||||
roomsState.selectRoom(roomId);
|
roomsState.selectRoom(roomId);
|
||||||
|
hasAppliedInitialSessionRef.current = true;
|
||||||
setSessionMenuOpen(false);
|
setSessionMenuOpen(false);
|
||||||
}, [markRead, roomsState]);
|
}, [markRead, roomsState]);
|
||||||
|
|
||||||
@@ -2539,7 +2544,12 @@ export function QuickChatFAB({
|
|||||||
<div className="quick-chat-panel-agent-select" data-testid="quick-chat-session-select">
|
<div className="quick-chat-panel-agent-select" data-testid="quick-chat-session-select">
|
||||||
<div className="quick-chat-session-menu" ref={sessionMenuRef}>
|
<div className="quick-chat-session-menu" ref={sessionMenuRef}>
|
||||||
<label htmlFor="quick-chat-session-dropdown-trigger" className="visually-hidden">Select session</label>
|
<label htmlFor="quick-chat-session-dropdown-trigger" className="visually-hidden">Select session</label>
|
||||||
<input type="hidden" data-testid="quick-chat-session-dropdown" value={activeSession?.id ?? ""} readOnly />
|
<input
|
||||||
|
type="hidden"
|
||||||
|
data-testid="quick-chat-session-dropdown"
|
||||||
|
value={showRoomGroups && roomsState.activeRoom ? "" : activeSession?.id ?? ""}
|
||||||
|
readOnly
|
||||||
|
/>
|
||||||
<button
|
<button
|
||||||
id="quick-chat-session-dropdown-trigger"
|
id="quick-chat-session-dropdown-trigger"
|
||||||
type="button"
|
type="button"
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
import { useState } from "react";
|
||||||
import { beforeEach, describe, expect, it, vi } from "vitest";
|
import { beforeEach, describe, expect, it, vi } from "vitest";
|
||||||
import { fireEvent, render, screen, waitFor } from "@testing-library/react";
|
import { fireEvent, render, screen, waitFor } from "@testing-library/react";
|
||||||
import type { Agent } from "../../api";
|
import type { Agent } from "../../api";
|
||||||
@@ -454,6 +455,53 @@ describe("QuickChatFAB session-first UX", () => {
|
|||||||
expect(screen.getByTestId("quick-chat-input")).toHaveAttribute("placeholder", "Message GPT-4o");
|
expect(screen.getByTestId("quick-chat-input")).toHaveAttribute("placeholder", "Message GPT-4o");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("FN-4804: switching from an active room to a direct session clears room display state", async () => {
|
||||||
|
const room = {
|
||||||
|
id: "room-1",
|
||||||
|
name: "engineering",
|
||||||
|
slug: "engineering",
|
||||||
|
memberCount: 2,
|
||||||
|
createdAt: new Date().toISOString(),
|
||||||
|
updatedAt: new Date().toISOString(),
|
||||||
|
};
|
||||||
|
|
||||||
|
mockUseAppSettings.mockReturnValue({ experimentalFeatures: { chatRooms: true } } as ReturnType<typeof useAppSettings>);
|
||||||
|
mockUseChatRooms.mockImplementation(() => {
|
||||||
|
const [activeRoom, setActiveRoom] = useState(room);
|
||||||
|
return {
|
||||||
|
rooms: [room],
|
||||||
|
roomsLoading: false,
|
||||||
|
roomsError: null,
|
||||||
|
activeRoom,
|
||||||
|
activeRoomMembers: [],
|
||||||
|
messages: [],
|
||||||
|
messagesLoading: false,
|
||||||
|
selectRoom: (roomId: string | null) => {
|
||||||
|
setActiveRoom(roomId ? room : null);
|
||||||
|
},
|
||||||
|
createRoom: vi.fn(),
|
||||||
|
deleteRoom: vi.fn(),
|
||||||
|
sendRoomMessage: vi.fn(),
|
||||||
|
refreshRooms: vi.fn(),
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
|
render(<QuickChatFAB addToast={vi.fn()} projectId="proj-1" />);
|
||||||
|
fireEvent.click(screen.getByTestId("quick-chat-fab"));
|
||||||
|
|
||||||
|
expect(await screen.findByTestId("quick-chat-input")).toHaveAttribute("placeholder", "Message #engineering");
|
||||||
|
expect(screen.getByTestId("quick-chat-session-dropdown")).toHaveValue("");
|
||||||
|
|
||||||
|
fireEvent.click(screen.getByTestId("quick-chat-session-dropdown-trigger"));
|
||||||
|
fireEvent.click(screen.getByTestId("quick-chat-session-option-session-agent"));
|
||||||
|
|
||||||
|
await waitFor(() => {
|
||||||
|
expect(screen.getByTestId("quick-chat-session-dropdown")).toHaveValue("session-agent");
|
||||||
|
expect(screen.getByTestId("quick-chat-input")).toHaveAttribute("placeholder", "Message Agent One");
|
||||||
|
expect(screen.getByTestId("quick-chat-session-dropdown-trigger")).not.toHaveTextContent("#engineering");
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
describe("FN-4708 room reflection", () => {
|
describe("FN-4708 room reflection", () => {
|
||||||
it("shows room placeholder and room tag when an active room exists", async () => {
|
it("shows room placeholder and room tag when an active room exists", async () => {
|
||||||
mockUseAppSettings.mockReturnValue({ experimentalFeatures: { chatRooms: true } } as ReturnType<typeof useAppSettings>);
|
mockUseAppSettings.mockReturnValue({ experimentalFeatures: { chatRooms: true } } as ReturnType<typeof useAppSettings>);
|
||||||
|
|||||||
Reference in New Issue
Block a user