Skip to content

πŸ™Œ OpenHands: AI-Driven Development

hotfix(frontend): Make conversation title clickable (#6609)

sp.wack240d1c972c82
diff --git a/frontend/__tests__/components/features/conversation-panel/conversation-card.test.tsx b/frontend/__tests__/components/features/conversation-panel/conversation-card.test.tsx
index ff073f21f9..b6d3a92eab 100644
--- a/frontend/__tests__/components/features/conversation-panel/conversation-card.test.tsx
+++ b/frontend/__tests__/components/features/conversation-panel/conversation-card.test.tsx
@@ -46,9 +46,8 @@ describe("ConversationCard", () => {
const expectedDate = `${formatTimeDelta(new Date("2021-10-01T12:00:00Z"))} ago`;
const card = screen.getByTestId("conversation-card");
- const title = within(card).getByTestId("conversation-card-title");
- expect(title).toHaveValue("Conversation 1");
+ within(card).getByText("Conversation 1");
within(card).getByText(expectedDate);
});
@@ -165,10 +164,8 @@ describe("ConversationCard", () => {
/>,
);
- const title = screen.getByTestId("conversation-card-title");
- expect(title).toBeDisabled();
-
await clickOnEditButton(user);
+ const title = screen.getByTestId("conversation-card-title");
expect(title).toBeEnabled();
expect(screen.queryByTestId("context-menu")).not.toBeInTheDocument();
@@ -181,7 +178,6 @@ describe("ConversationCard", () => {
expect(onChangeTitle).toHaveBeenCalledWith("New Conversation Name");
expect(title).toHaveValue("New Conversation Name");
- expect(title).toBeDisabled();
});
it("should reset title and not call onChangeTitle when the title is empty", async () => {
@@ -208,7 +204,27 @@ describe("ConversationCard", () => {
expect(title).toHaveValue("Conversation 1");
});
- test("clicking the title should not trigger the onClick handler", async () => {
+ test("clicking the title should trigger the onClick handler", async () => {
+ const user = userEvent.setup();
+ render(
+ <ConversationCard
+ onClick={onClick}
+ onDelete={onDelete}
+ isActive
+ onChangeTitle={onChangeTitle}
+ title="Conversation 1"
+ selectedRepository={null}
+ lastUpdatedAt="2021-10-01T12:00:00Z"
+ />,
+ );
+
+ const title = screen.getByTestId("conversation-card-title");
+ await user.click(title);
+
+ expect(onClick).toHaveBeenCalled();
+ });
+
+ test("clicking the title should not trigger the onClick handler if edit mode", async () => {
const user = userEvent.setup();
render(
<ConversationCard
@@ -221,6 +237,8 @@ describe("ConversationCard", () => {
/>,
);
+ await clickOnEditButton(user);
+
const title = screen.getByTestId("conversation-card-title");
await user.click(title);
diff --git a/frontend/__tests__/components/features/conversation-panel/conversation-panel.test.tsx b/frontend/__tests__/components/features/conversation-panel/conversation-panel.test.tsx
index 702ac35768..6258593925 100644
--- a/frontend/__tests__/components/features/conversation-panel/conversation-panel.test.tsx
+++ b/frontend/__tests__/components/features/conversation-panel/conversation-panel.test.tsx
@@ -179,9 +179,10 @@ describe("ConversationPanel", () => {
const user = userEvent.setup();
renderConversationPanel();
const cards = await screen.findAllByTestId("conversation-card");
- const title = within(cards[0]).getByTestId("conversation-card-title");
- await clickOnEditButton(user);
+ const card = cards[0];
+ await clickOnEditButton(user, card);
+ const title = within(card).getByTestId("conversation-card-title");
await user.clear(title);
await user.type(title, "Conversation 1 Renamed");
@@ -202,7 +203,10 @@ describe("ConversationPanel", () => {
const user = userEvent.setup();
renderConversationPanel();
const cards = await screen.findAllByTestId("conversation-card");
- const title = within(cards[0]).getByTestId("conversation-card-title");
+
+ const card = cards[0];
+ await clickOnEditButton(user, card);
+ const title = within(card).getByTestId("conversation-card-title");
await user.click(title);
await user.tab();
diff --git a/frontend/__tests__/components/features/conversation-panel/utils.ts b/frontend/__tests__/components/features/conversation-panel/utils.ts
index 5963dc0a08..2bf27a9502 100644
--- a/frontend/__tests__/components/features/conversation-panel/utils.ts
+++ b/frontend/__tests__/components/features/conversation-panel/utils.ts
@@ -1,11 +1,16 @@
import { screen, within } from "@testing-library/react";
import { UserEvent } from "@testing-library/user-event";
-export const clickOnEditButton = async (user: UserEvent) => {
- const ellipsisButton = screen.getByTestId("ellipsis-button");
+export const clickOnEditButton = async (
+ user: UserEvent,
+ container?: HTMLElement,
+) => {
+ const wrapper = container ? within(container) : screen;
+
+ const ellipsisButton = wrapper.getByTestId("ellipsis-button");
await user.click(ellipsisButton);
- const menu = screen.getByTestId("context-menu");
+ const menu = wrapper.getByTestId("context-menu");
const editButton = within(menu).getByTestId("edit-button");
await user.click(editButton);
diff --git a/frontend/src/components/features/conversation-panel/conversation-card.tsx b/frontend/src/components/features/conversation-panel/conversation-card.tsx
index 845475c025..e7fb8119b4 100644
--- a/frontend/src/components/features/conversation-panel/conversation-card.tsx
+++ b/frontend/src/components/features/conversation-panel/conversation-card.tsx
@@ -58,8 +58,10 @@ export function ConversationCard({
};
const handleInputClick = (event: React.MouseEvent<HTMLInputElement>) => {
- event.preventDefault();
- event.stopPropagation();
+ if (titleMode === "edit") {
+ event.preventDefault();
+ event.stopPropagation();
+ }
};
const handleDelete = (event: React.MouseEvent<HTMLButtonElement>) => {
@@ -101,17 +103,26 @@ export function ConversationCard({
<div className="flex items-center justify-between">
<div className="flex items-center gap-2 w-full">
{isActive && <span className="w-2 h-2 bg-blue-500 rounded-full" />}
- <input
- ref={inputRef}
- disabled={titleMode === "view"}
- data-testid="conversation-card-title"
- onClick={handleInputClick}
- onBlur={handleBlur}
- onKeyUp={handleKeyUp}
- type="text"
- defaultValue={title}
- className="text-sm leading-6 font-semibold bg-transparent w-full"
- />
+ {titleMode === "edit" && (
+ <input
+ ref={inputRef}
+ data-testid="conversation-card-title"
+ onClick={handleInputClick}
+ onBlur={handleBlur}
+ onKeyUp={handleKeyUp}
+ type="text"
+ defaultValue={title}
+ className="text-sm leading-6 font-semibold bg-transparent w-full"
+ />
+ )}
+ {titleMode === "view" && (
+ <p
+ data-testid="conversation-card-title"
+ className="text-sm leading-6 font-semibold bg-transparent w-full"
+ >
+ {title}
+ </p>
+ )}
</div>
<div className="flex items-center gap-2 relative">