Skip to content

πŸ™Œ OpenHands: AI-Driven Development

Fix: Add navigation to conversation page after clicking Launch button on task suggestions (#9760)

Graham Neubigf0a6db936cff
diff --git a/frontend/__tests__/components/features/home/task-card.test.tsx b/frontend/__tests__/components/features/home/task-card.test.tsx
index 4b0b390bc9..a1a43fae34 100644
--- a/frontend/__tests__/components/features/home/task-card.test.tsx
+++ b/frontend/__tests__/components/features/home/task-card.test.tsx
@@ -110,4 +110,29 @@ describe("TaskCard", () => {
expect(launchButton).toHaveTextContent(/Loading/i);
expect(launchButton).toBeDisabled();
});
+
+ it("should navigate to the conversation page after creating a conversation", async () => {
+ const createConversationSpy = vi.spyOn(OpenHands, "createConversation");
+ createConversationSpy.mockResolvedValue({
+ conversation_id: "test-conversation-id",
+ title: "Test Conversation",
+ selected_repository: "repo1",
+ selected_branch: "main",
+ git_provider: "github",
+ last_updated_at: "2023-01-01T00:00:00Z",
+ created_at: "2023-01-01T00:00:00Z",
+ status: "RUNNING",
+ runtime_status: "STATUS$READY",
+ url: null,
+ session_api_key: null
+ });
+
+ renderTaskCard();
+
+ const launchButton = screen.getByTestId("task-launch-button");
+ await userEvent.click(launchButton);
+
+ // Wait for navigation to the conversation page
+ await screen.findByTestId("conversation-screen");
+ });
});
diff --git a/frontend/src/components/features/home/tasks/task-card.tsx b/frontend/src/components/features/home/tasks/task-card.tsx
index 7dfe4a3580..95e7b46592 100644
--- a/frontend/src/components/features/home/tasks/task-card.tsx
+++ b/frontend/src/components/features/home/tasks/task-card.tsx
@@ -1,4 +1,5 @@
import { useTranslation } from "react-i18next";
+import { useNavigate } from "react-router";
import { SuggestedTask } from "./task.types";
import { useIsCreatingConversation } from "#/hooks/use-is-creating-conversation";
import { useCreateConversation } from "#/hooks/mutation/use-create-conversation";
@@ -24,17 +25,25 @@ export function TaskCard({ task }: TaskCardProps) {
const { mutate: createConversation, isPending } = useCreateConversation();
const isCreatingConversation = useIsCreatingConversation();
const { t } = useTranslation();
+ const navigate = useNavigate();
const handleLaunchConversation = () => {
setOptimisticUserMessage(t("TASK$ADDRESSING_TASK"));
- return createConversation({
- repository: {
- name: task.repo,
- gitProvider: task.git_provider,
+ return createConversation(
+ {
+ repository: {
+ name: task.repo,
+ gitProvider: task.git_provider,
+ },
+ suggestedTask: task,
},
- suggestedTask: task,
- });
+ {
+ onSuccess: (data) => {
+ navigate(`/conversations/${data.conversation_id}`);
+ },
+ },
+ );
};
// Determine the correct URL format based on git provider