Skip to content

Commit

Permalink
Fix issue #4780: [Bug]: Initial query is not cleared after submission (
Browse files Browse the repository at this point in the history
  • Loading branch information
openhands-agent authored Nov 6, 2024
1 parent 1189572 commit 83ccb74
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 0 deletions.
17 changes: 17 additions & 0 deletions frontend/__tests__/initial-query.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { describe, it, expect } from "vitest";
import store from "../src/store";
import { setInitialQuery, clearInitialQuery } from "../src/state/initial-query-slice";

describe("Initial Query Behavior", () => {
it("should clear initial query when clearInitialQuery is dispatched", () => {
// Set up initial query in the store
store.dispatch(setInitialQuery("test query"));
expect(store.getState().initalQuery.initialQuery).toBe("test query");

// Clear the initial query
store.dispatch(clearInitialQuery());

// Verify initial query is cleared
expect(store.getState().initalQuery.initialQuery).toBeNull();
});
});
2 changes: 2 additions & 0 deletions frontend/src/routes/_oh.app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import ListIcon from "#/assets/list-type-number.svg?react";
import { createChatMessage } from "#/services/chatService";
import {
clearFiles,
clearInitialQuery,
clearSelectedRepository,
setImportedProjectZip,
} from "#/state/initial-query-slice";
Expand Down Expand Up @@ -256,6 +257,7 @@ function App() {
dispatch(clearMessages());
dispatch(clearTerminal());
dispatch(clearJupyter());
dispatch(clearInitialQuery()); // Clear initial query when navigating to /app
startSocketConnection();
});

Expand Down
4 changes: 4 additions & 0 deletions frontend/src/state/initial-query-slice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ export const selectedFilesSlice = createSlice({
setInitialQuery(state, action: PayloadAction<string>) {
state.initialQuery = action.payload;
},
clearInitialQuery(state) {
state.initialQuery = null;
},
setSelectedRepository(state, action: PayloadAction<string | null>) {
state.selectedRepository = action.payload;
},
Expand All @@ -47,6 +50,7 @@ export const {
removeFile,
clearFiles,
setInitialQuery,
clearInitialQuery,
setSelectedRepository,
clearSelectedRepository,
setImportedProjectZip,
Expand Down

0 comments on commit 83ccb74

Please sign in to comment.