Skip to content

πŸ™Œ OpenHands: AI-Driven Development

fix: hide Suggested Tasks section for local backends (#219)

Hiep Le3487cfda0481
diff --git a/__tests__/components/features/home/task-suggestions.test.tsx b/__tests__/components/features/home/task-suggestions.test.tsx
index 96ee054bff..198475e0db 100644
--- a/__tests__/components/features/home/task-suggestions.test.tsx
+++ b/__tests__/components/features/home/task-suggestions.test.tsx
@@ -1,10 +1,17 @@
import { render, screen, waitFor } from "@testing-library/react";
-import { afterEach, describe, expect, it, vi } from "vitest";
+import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
import { createRoutesStub } from "react-router";
import { TaskSuggestions } from "#/components/features/home/tasks/task-suggestions";
import { SuggestionsService } from "#/api/suggestions-service/suggestions-service.api";
import { MOCK_TASKS } from "#/mocks/task-suggestions-handlers";
+import { ActiveBackendProvider } from "#/contexts/active-backend-context";
+import {
+ __resetActiveStoreForTests,
+ setActiveSelection,
+ setRegisteredBackends,
+} from "#/api/backend-registry/active-store";
+import type { Backend } from "#/api/backend-registry/types";
// Mock the translation function
vi.mock("react-i18next", async () => {
@@ -46,6 +53,14 @@ vi.mock("#/hooks/use-user-providers", () => ({
useUserProviders: () => useUserProvidersMock(),
}));
+const cloudBackend: Backend = {
+ id: "prod",
+ name: "Production",
+ host: "https://app.all-hands.dev",
+ apiKey: "k",
+ kind: "cloud",
+};
+
const renderTaskSuggestions = () => {
const RouterStub = createRoutesStub([
{
@@ -65,7 +80,7 @@ const renderTaskSuggestions = () => {
return render(<RouterStub />, {
wrapper: ({ children }) => (
<QueryClientProvider client={new QueryClient()}>
- {children}
+ <ActiveBackendProvider>{children}</ActiveBackendProvider>
</QueryClientProvider>
),
});
@@ -77,8 +92,17 @@ describe("TaskSuggestions", () => {
"getSuggestedTasks",
);
+ beforeEach(() => {
+ window.localStorage.clear();
+ __resetActiveStoreForTests();
+ setRegisteredBackends([cloudBackend]);
+ setActiveSelection({ backendId: cloudBackend.id });
+ });
+
afterEach(() => {
vi.clearAllMocks();
+ window.localStorage.clear();
+ __resetActiveStoreForTests();
});
it("should render the task suggestions section", () => {
@@ -86,6 +110,15 @@ describe("TaskSuggestions", () => {
screen.getByTestId("task-suggestions");
});
+ it("renders nothing when the active backend is local", () => {
+ setRegisteredBackends([]);
+ setActiveSelection(null);
+
+ renderTaskSuggestions();
+
+ expect(screen.queryByTestId("task-suggestions")).not.toBeInTheDocument();
+ });
+
it("should render an empty message if there are no tasks", async () => {
getSuggestedTasksSpy.mockResolvedValue([]);
renderTaskSuggestions();
diff --git a/src/components/features/home/tasks/task-suggestions.tsx b/src/components/features/home/tasks/task-suggestions.tsx
index c067821d4b..3e27a4b913 100644
--- a/src/components/features/home/tasks/task-suggestions.tsx
+++ b/src/components/features/home/tasks/task-suggestions.tsx
@@ -7,6 +7,7 @@ import { cn, getDisplayedTaskGroups, getTotalTaskCount } from "#/utils/utils";
import { I18nKey } from "#/i18n/declaration";
import { GitRepository } from "#/types/git";
import { Typography } from "#/ui/typography";
+import { useActiveBackend } from "#/contexts/active-backend-context";
interface TaskSuggestionsProps {
filterFor?: GitRepository | null;
@@ -15,9 +16,12 @@ interface TaskSuggestionsProps {
export function TaskSuggestions({ filterFor }: TaskSuggestionsProps) {
const { t } = useTranslation("openhands");
const [isExpanded, setIsExpanded] = useState(false);
+ const isCloud = useActiveBackend().backend.kind === "cloud";
const { data: tasks, isLoading } = useSuggestedTasks();
+ if (!isCloud) return null;
+
const suggestedTasks = filterFor
? tasks?.filter(
(element) =>