Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(frontend) Refactor and move components #5290

Merged
merged 16 commits into from
Dec 2, 2024
15 changes: 14 additions & 1 deletion frontend/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ This is the frontend of the OpenHands project. It is a React application that pr
- Remix SPA Mode (React + Vite + React Router)
- TypeScript
- Redux
- TanStack Query
- Tailwind CSS
- i18next
- React Testing Library
Expand Down Expand Up @@ -85,7 +86,7 @@ frontend
├── src
│ ├── api # API calls
│ ├── assets
│ ├── components # Reusable components
│ ├── components
│ ├── context # Local state management
│ ├── hooks # Custom hooks
│ ├── i18n # Internationalization
Expand All @@ -99,6 +100,18 @@ frontend
└── .env.sample # Sample environment variables
```

#### Components

Components are organized into folders based on their **domain**, **feature**, or **shared functionality**.

```sh
components
├── features # Domain-specific components
├── layout
├── modals
└── ui # Shared UI components
```

### Features

- Real-time updates with WebSockets
Expand Down
2 changes: 1 addition & 1 deletion frontend/__tests__/components/browser.test.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { screen } from "@testing-library/react";
import { describe, it, expect } from "vitest";
import { renderWithProviders } from "../../test-utils";
import BrowserPanel from "#/components/browser";
import { BrowserPanel } from "#/components/features/browser/browser";

describe("Browser", () => {
it("renders a message if no screenshotSrc is provided", () => {
Expand Down
2 changes: 1 addition & 1 deletion frontend/__tests__/components/chat-message.test.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { render, screen } from "@testing-library/react";
import userEvent from "@testing-library/user-event";
import { describe, it, expect, test } from "vitest";
import { ChatMessage } from "#/components/chat-message";
import { ChatMessage } from "#/components/features/chat/chat-message";

describe("ChatMessage", () => {
it("should render a user message", () => {
Expand Down
2 changes: 1 addition & 1 deletion frontend/__tests__/components/chat/chat-input.test.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import userEvent from "@testing-library/user-event";
import { fireEvent, render, screen } from "@testing-library/react";
import { describe, afterEach, vi, it, expect } from "vitest";
import { ChatInput } from "#/components/chat-input";
import { ChatInput } from "#/components/features/chat/chat-input";

describe("ChatInput", () => {
const onSubmitMock = vi.fn();
Expand Down
2 changes: 1 addition & 1 deletion frontend/__tests__/components/chat/chat-interface.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { addUserMessage } from "#/state/chat-slice";
import { SUGGESTIONS } from "#/utils/suggestions";
import * as ChatSlice from "#/state/chat-slice";
import { WsClientProviderStatus } from "#/context/ws-client-provider";
import { ChatInterface } from "#/routes/_oh.app/chat-interface";
import { ChatInterface } from "#/components/features/chat/chat-interface";

// eslint-disable-next-line @typescript-eslint/no-unused-vars
const renderChatInterface = (messages: (Message | ErrorMessage)[]) =>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { render, screen } from "@testing-library/react";
import userEvent from "@testing-library/user-event";
import { afterEach, describe, expect, it, test, vi } from "vitest";
import { AccountSettingsContextMenu } from "#/components/context-menu/account-settings-context-menu";
import { AccountSettingsContextMenu } from "#/components/features/context-menu/account-settings-context-menu";

describe("AccountSettingsContextMenu", () => {
const user = userEvent.setup();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { describe, it, expect, vi } from "vitest";
import { render, screen } from "@testing-library/react";
import userEvent from "@testing-library/user-event";
import { ContextMenuListItem } from "#/components/context-menu/context-menu-list-item";
import { ContextMenuListItem } from "#/components/features/context-menu/context-menu-list-item";

describe("ContextMenuListItem", () => {
it("should render the component with the children", () => {
Expand Down
2 changes: 1 addition & 1 deletion frontend/__tests__/components/feedback-actions.test.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { render, screen, within } from "@testing-library/react";
import userEvent from "@testing-library/user-event";
import { afterEach, describe, expect, it, vi } from "vitest";
import { FeedbackActions } from "#/components/feedback-actions";
import { FeedbackActions } from "#/components/features/feedback/feedback-actions";

describe("FeedbackActions", () => {
const user = userEvent.setup();
Expand Down
2 changes: 1 addition & 1 deletion frontend/__tests__/components/feedback-form.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { render, screen } from "@testing-library/react";
import userEvent from "@testing-library/user-event";
import { afterEach, describe, expect, it, vi } from "vitest";
import { renderWithProviders } from "test-utils";
import { FeedbackForm } from "#/components/feedback-form";
import { FeedbackForm } from "#/components/features/feedback/feedback-form";

describe("FeedbackForm", () => {
const user = userEvent.setup();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { screen } from "@testing-library/react";
import { renderWithProviders } from "test-utils";
import { describe, afterEach, vi, it, expect } from "vitest";
import ExplorerTree from "#/components/file-explorer/explorer-tree";
import { ExplorerTree } from "#/components/features/file-explorer/explorer-tree";

const FILES = ["file-1-1.ts", "folder-1-2"];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import { renderWithProviders } from "test-utils";
import { describe, it, expect, vi, Mock, afterEach } from "vitest";
import toast from "#/utils/toast";
import AgentState from "#/types/agent-state";
import { FileExplorer } from "#/routes/_oh.app._index/file-explorer/file-explorer";
import OpenHands from "#/api/open-hands";
import { FileExplorer } from "#/components/features/file-explorer/file-explorer";

const toastSpy = vi.spyOn(toast, "error");
const uploadFilesSpy = vi.spyOn(OpenHands, "uploadFiles");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { screen } from "@testing-library/react";
import userEvent from "@testing-library/user-event";
import { renderWithProviders } from "test-utils";
import { vi, describe, afterEach, it, expect } from "vitest";
import TreeNode from "#/components/file-explorer/tree-node";
import TreeNode from "#/components/features/file-explorer/tree-node";
import OpenHands from "#/api/open-hands";

const getFileSpy = vi.spyOn(OpenHands, "getFile");
Expand Down
2 changes: 1 addition & 1 deletion frontend/__tests__/components/image-preview.test.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { ImagePreview } from "#/components/features/images/image-preview";
import { render, screen } from "@testing-library/react";
import userEvent from "@testing-library/user-event";
import { describe, expect, it, vi } from "vitest";
import { ImagePreview } from "#/components/image-preview";

describe("ImagePreview", () => {
it("should render an image", () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { render, screen, within } from "@testing-library/react";
import userEvent from "@testing-library/user-event";
import { afterEach, beforeAll, describe, expect, it, vi } from "vitest";
import { InteractiveChatBox } from "#/components/interactive-chat-box";
import { InteractiveChatBox } from "#/components/features/chat/interactive-chat-box";

describe("InteractiveChatBox", () => {
const onSubmitMock = vi.fn();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { render, screen, act } from "@testing-library/react";
import userEvent from "@testing-library/user-event";
import { describe, it, vi, expect } from "vitest";
import BaseModal from "#/components/modals/base-modal/base-modal";
import { BaseModal } from "#/components/modals/base-modal/base-modal";

describe("BaseModal", () => {
it("should render if the modal is open", () => {
Expand Down
2 changes: 1 addition & 1 deletion frontend/__tests__/components/suggestion-item.test.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { render, screen } from "@testing-library/react";
import userEvent from "@testing-library/user-event";
import { afterEach, describe, expect, it, vi } from "vitest";
import { SuggestionItem } from "#/components/suggestion-item";
import { SuggestionItem } from "#/components/features/suggestions/suggestion-item";

describe("SuggestionItem", () => {
const suggestionItem = { label: "suggestion1", value: "a long text value" };
Expand Down
2 changes: 1 addition & 1 deletion frontend/__tests__/components/suggestions.test.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { render, screen } from "@testing-library/react";
import userEvent from "@testing-library/user-event";
import { afterEach, describe, expect, it, vi } from "vitest";
import { Suggestions } from "#/components/suggestions";
import { Suggestions } from "#/components/features/suggestions/suggestions";

describe("Suggestions", () => {
const firstSuggestion = {
Expand Down
2 changes: 1 addition & 1 deletion frontend/__tests__/components/terminal/terminal.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { act, screen } from "@testing-library/react";
import { renderWithProviders } from "test-utils";
import { vi, describe, afterEach, it, expect } from "vitest";
import { Command, appendInput, appendOutput } from "#/state/command-slice";
import Terminal from "#/components/terminal/terminal";
import Terminal from "#/components/features/terminal/terminal";

global.ResizeObserver = vi.fn().mockImplementation(() => ({
observe: vi.fn(),
Expand Down
2 changes: 1 addition & 1 deletion frontend/__tests__/components/upload-image-input.test.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { render, screen } from "@testing-library/react";
import userEvent from "@testing-library/user-event";
import { afterEach, describe, expect, it, vi } from "vitest";
import { UploadImageInput } from "#/components/upload-image-input";
import { UploadImageInput } from "#/components/features/images/upload-image-input";

describe("UploadImageInput", () => {
const user = userEvent.setup();
Expand Down
2 changes: 1 addition & 1 deletion frontend/__tests__/components/user-actions.test.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { render, screen } from "@testing-library/react";
import { describe, expect, it, test, vi, afterEach } from "vitest";
import userEvent from "@testing-library/user-event";
import { UserActions } from "#/components/user-actions";
import { UserActions } from "#/components/features/sidebar/user-actions";

describe("UserActions", () => {
const user = userEvent.setup();
Expand Down
2 changes: 1 addition & 1 deletion frontend/__tests__/components/user-avatar.test.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { render, screen } from "@testing-library/react";
import userEvent from "@testing-library/user-event";
import { afterEach, describe, expect, it, vi } from "vitest";
import { UserAvatar } from "#/components/user-avatar";
import { UserAvatar } from "#/components/features/sidebar/user-avatar";

describe("UserAvatar", () => {
const onClickMock = vi.fn();
Expand Down
110 changes: 0 additions & 110 deletions frontend/src/components/agent-control-bar.tsx

This file was deleted.

Loading
Loading