Skip to content

πŸ™Œ OpenHands: AI-Driven Development

chore: remove unused shared UI components (#552)

Hiep Lee69217e67e31
diff --git a/__tests__/components/features/sidebar/sidebar.test.tsx b/__tests__/components/features/sidebar/sidebar.test.tsx
index e3cd2f00f5..b3f7b73609 100644
--- a/__tests__/components/features/sidebar/sidebar.test.tsx
+++ b/__tests__/components/features/sidebar/sidebar.test.tsx
@@ -46,20 +46,6 @@ vi.mock("#/components/shared/buttons/openhands-logo-button", () => ({
OpenHandsLogoButton: () => <div data-testid="logo-button" />,
}));
-vi.mock("#/components/shared/buttons/new-project-button", () => ({
- NewProjectButton: () => <div data-testid="new-project-button" />,
-}));
-
-vi.mock("#/components/shared/buttons/conversation-panel-button", () => ({
- ConversationPanelButton: () => (
- <div data-testid="conversation-panel-button" />
- ),
-}));
-
-vi.mock("#/components/shared/buttons/automations-button", () => ({
- AutomationsButton: () => <div data-testid="automations-button" />,
-}));
-
vi.mock("#/components/features/sidebar/user-actions", () => ({
UserActions: () => <div data-testid="user-actions" />,
}));
diff --git a/__tests__/components/shared/buttons/automations-button.test.tsx b/__tests__/components/shared/buttons/automations-button.test.tsx
deleted file mode 100644
index b8d799611c..0000000000
--- a/__tests__/components/shared/buttons/automations-button.test.tsx
+++ /dev/null
@@ -1,73 +0,0 @@
-import { createEvent, fireEvent, render, screen } from "@testing-library/react";
-import { describe, expect, it, vi } from "vitest";
-import { AutomationsButton } from "#/components/shared/buttons/automations-button";
-import {
- NavigationProvider,
- type NavigationContextValue,
-} from "#/context/navigation-context";
-
-vi.mock("#/components/shared/buttons/styled-tooltip", () => ({
- StyledTooltip: ({ children }: { children: unknown }) => children,
-}));
-
-function renderAutomationsButton(
- props: { disabled?: boolean } = {},
- overrides: Partial<NavigationContextValue> = {},
-) {
- const value: NavigationContextValue = {
- currentPath: "/",
- conversationId: null,
- isNavigating: false,
- navigate: vi.fn(),
- ...overrides,
- };
-
- const result = render(
- <NavigationProvider value={value}>
- <AutomationsButton {...props} />
- </NavigationProvider>,
- );
-
- return { ...result, navigate: value.navigate };
-}
-
-describe("AutomationsButton", () => {
- it("should render a link to /automations", () => {
- renderAutomationsButton();
-
- const link = screen.getByTestId("automations-button");
- expect(link).toBeInTheDocument();
- expect(link).toHaveAttribute("href", "/automations");
- });
-
- it("should be focusable and accessible when enabled", () => {
- renderAutomationsButton();
-
- const link = screen.getByTestId("automations-button");
- expect(link).toHaveAttribute("tabIndex", "0");
- expect(link).toHaveAttribute("aria-label", "SIDEBAR$AUTOMATIONS");
- });
-
- it("should navigate via SPA routing without a full page reload when clicked", () => {
- const { navigate } = renderAutomationsButton();
-
- const link = screen.getByTestId("automations-button");
- const clickEvent = createEvent.click(link);
- fireEvent(link, clickEvent);
-
- expect(navigate).toHaveBeenCalledWith("/automations", { replace: false });
- expect(clickEvent.defaultPrevented).toBe(true);
- });
-
- it("should prevent navigation and remove from tab order when disabled", () => {
- const { navigate } = renderAutomationsButton({ disabled: true });
-
- const link = screen.getByTestId("automations-button");
- expect(link).toHaveAttribute("tabIndex", "-1");
-
- const clickEvent = createEvent.click(link);
- fireEvent(link, clickEvent);
- expect(clickEvent.defaultPrevented).toBe(true);
- expect(navigate).not.toHaveBeenCalled();
- });
-});
diff --git a/__tests__/components/shared/inputs/badge-input.test.tsx b/__tests__/components/shared/inputs/badge-input.test.tsx
deleted file mode 100644
index 18fff61ee6..0000000000
--- a/__tests__/components/shared/inputs/badge-input.test.tsx
+++ /dev/null
@@ -1,62 +0,0 @@
-import { render, screen } from "@testing-library/react";
-import userEvent from "@testing-library/user-event";
-import { describe, expect, it, vi } from "vitest";
-import { BadgeInput } from "#/components/shared/inputs/badge-input";
-
-describe("BadgeInput", () => {
- it("should render the values", () => {
- const onChangeMock = vi.fn();
- render(<BadgeInput value={["test", "test2"]} onChange={onChangeMock} />);
-
- expect(screen.getByText("test")).toBeInTheDocument();
- expect(screen.getByText("test2")).toBeInTheDocument();
- });
-
- it("should render the input's as a badge on space", async () => {
- const onChangeMock = vi.fn();
- render(<BadgeInput value={["badge1"]} onChange={onChangeMock} />);
-
- const input = screen.getByTestId("badge-input");
- expect(input).toHaveValue("");
-
- await userEvent.type(input, "test");
- await userEvent.type(input, " ");
-
- expect(onChangeMock).toHaveBeenCalledWith(["badge1", "test"]);
- expect(input).toHaveValue("");
- });
-
- it("should remove the badge on backspace", async () => {
- const onChangeMock = vi.fn();
- render(<BadgeInput value={["badge1", "badge2"]} onChange={onChangeMock} />);
-
- const input = screen.getByTestId("badge-input");
- expect(input).toHaveValue("");
-
- await userEvent.type(input, "{backspace}");
-
- expect(onChangeMock).toHaveBeenCalledWith(["badge1"]);
- expect(input).toHaveValue("");
- });
-
- it("should remove the badge on click", async () => {
- const onChangeMock = vi.fn();
- render(<BadgeInput value={["badge1"]} onChange={onChangeMock} />);
-
- const removeButton = screen.getByTestId("remove-button");
- await userEvent.click(removeButton);
-
- expect(onChangeMock).toHaveBeenCalledWith([]);
- });
-
- it("should not create empty badges", async () => {
- const onChangeMock = vi.fn();
- render(<BadgeInput value={[]} onChange={onChangeMock} />);
-
- const input = screen.getByTestId("badge-input");
- expect(input).toHaveValue("");
-
- await userEvent.type(input, " ");
- expect(onChangeMock).not.toHaveBeenCalled();
- });
-});
diff --git a/__tests__/components/shared/terms-and-privacy-notice.test.tsx b/__tests__/components/shared/terms-and-privacy-notice.test.tsx
deleted file mode 100644
index 559a7f0df6..0000000000
--- a/__tests__/components/shared/terms-and-privacy-notice.test.tsx
+++ /dev/null
@@ -1,48 +0,0 @@
-import { render, screen } from "@testing-library/react";
-import { it, describe, expect } from "vitest";
-import { TermsAndPrivacyNotice } from "#/components/shared/terms-and-privacy-notice";
-
-describe("TermsAndPrivacyNotice", () => {
- it("should render Terms of Service and Privacy Policy links", () => {
- // Arrange & Act
- render(<TermsAndPrivacyNotice />);
-
- // Assert
- const termsSection = screen.getByTestId("terms-and-privacy-notice");
- expect(termsSection).toBeInTheDocument();
-
- const tosLink = screen.getByRole("link", {
- name: "COMMON$TERMS_OF_SERVICE",
- });
- const privacyLink = screen.getByRole("link", {
- name: "COMMON$PRIVACY_POLICY",
- });
-
- expect(tosLink).toBeInTheDocument();
- expect(tosLink).toHaveAttribute("href", "https://www.all-hands.dev/tos");
- expect(tosLink).toHaveAttribute("target", "_blank");
- expect(tosLink).toHaveAttribute("rel", "noopener noreferrer");
-
- expect(privacyLink).toBeInTheDocument();
- expect(privacyLink).toHaveAttribute(
- "href",
- "https://www.all-hands.dev/privacy",
- );
- expect(privacyLink).toHaveAttribute("target", "_blank");
- expect(privacyLink).toHaveAttribute("rel", "noopener noreferrer");
- });
-
- it("should render all required text content", () => {
- // Arrange & Act
- render(<TermsAndPrivacyNotice />);
-
- // Assert
- const termsSection = screen.getByTestId("terms-and-privacy-notice");
- expect(termsSection).toHaveTextContent(
- "AUTH$BY_SIGNING_UP_YOU_AGREE_TO_OUR",
- );
- expect(termsSection).toHaveTextContent("COMMON$TERMS_OF_SERVICE");
- expect(termsSection).toHaveTextContent("COMMON$AND");
- expect(termsSection).toHaveTextContent("COMMON$PRIVACY_POLICY");
- });
-});
diff --git a/src/components/shared/buttons/automations-button.tsx b/src/components/shared/buttons/automations-button.tsx
deleted file mode 100644
index fcea621246..0000000000
--- a/src/components/shared/buttons/automations-button.tsx
+++ /dev/null
@@ -1,39 +0,0 @@
-import { useTranslation } from "react-i18next";
-import { I18nKey } from "#/i18n/declaration";
-import { NavigationLink } from "#/components/shared/navigation-link";
-import { StyledTooltip } from "#/components/shared/buttons/styled-tooltip";
-import AutomationsIcon from "#/icons/automations.svg?react";
-import { cn } from "#/utils/utils";
-
-interface AutomationsButtonProps {
- disabled?: boolean;
-}
-
-export function AutomationsButton({
- disabled = false,
-}: AutomationsButtonProps) {
- const { t } = useTranslation("openhands");
-
- const label = t(I18nKey.SIDEBAR$AUTOMATIONS);
-
- return (
- <StyledTooltip content={label} placement="right">
- <NavigationLink
- to="/automations"
- data-testid="automations-button"
- aria-label={label}
- tabIndex={disabled ? -1 : 0}
- onClick={(e) => {
- if (disabled) {
- e.preventDefault();
- }
- }}
- className={cn("inline-flex items-center justify-center", {
- "pointer-events-none opacity-50": disabled,
- })}
- >
- <AutomationsIcon width={24} height={24} />
- </NavigationLink>
- </StyledTooltip>
- );
-}
diff --git a/src/components/shared/buttons/conversation-panel-button.tsx b/src/components/shared/buttons/conversation-panel-button.tsx
deleted file mode 100644
index 45a27c811d..0000000000
--- a/src/components/shared/buttons/conversation-panel-button.tsx
+++ /dev/null
@@ -1,44 +0,0 @@
-import { useTranslation } from "react-i18next";
-import { I18nKey } from "#/i18n/declaration";
-import ListIcon from "#/icons/list.svg?react";
-import { StyledTooltip } from "#/components/shared/buttons/styled-tooltip";
-import { cn } from "#/utils/utils";
-
-interface ConversationPanelButtonProps {
- isOpen: boolean;
- onClick: () => void;
- disabled?: boolean;
-}
-
-export function ConversationPanelButton({
- isOpen,
- onClick,
- disabled = false,
-}: ConversationPanelButtonProps) {
- const { t } = useTranslation("openhands");
-
- const label = t(I18nKey.SIDEBAR$CONVERSATIONS);
-
- return (
- <StyledTooltip content={label}>
- <button
- type="button"
- data-testid="toggle-conversation-panel"
- aria-label={label}
- onClick={onClick}
- disabled={disabled}
- className="p-0 bg-transparent border-0"
- >
- <ListIcon
- width={24}
- height={24}
- className={cn(
- "cursor-pointer",
- isOpen ? "text-white" : "text-[var(--oh-text-secondary)]",
- disabled && "opacity-50",
- )}
- />
- </button>
- </StyledTooltip>
- );
-}
diff --git a/src/components/shared/buttons/icon-button.tsx b/src/components/shared/buttons/icon-button.tsx
deleted file mode 100644
index 48f58662d1..0000000000
--- a/src/components/shared/buttons/icon-button.tsx
+++ /dev/null
@@ -1,29 +0,0 @@
-import { Button } from "@heroui/react";
-import React, { ReactElement } from "react";
-
-export interface IconButtonProps {
- icon: ReactElement;
- onClick: () => void;
- ariaLabel: string;
- testId?: string;
-}
-
-export function IconButton({
- icon,
- onClick,
- ariaLabel,
- testId = "",
-}: IconButtonProps): React.ReactElement {
- return (
- <Button
- type="button"
- variant="ghost"
- onPress={onClick}
- className="cursor-pointer text-[12px] bg-transparent aspect-square px-0 min-w-[20px] h-[20px]"
- aria-label={ariaLabel}
- data-testid={testId}
- >
- {icon}
- </Button>
- );
-}
diff --git a/src/components/shared/buttons/new-project-button.tsx b/src/components/shared/buttons/new-project-button.tsx
deleted file mode 100644
index 4fba72cdb1..0000000000
--- a/src/components/shared/buttons/new-project-button.tsx
+++ /dev/null
@@ -1,37 +0,0 @@
-import { useTranslation } from "react-i18next";
-import { I18nKey } from "#/i18n/declaration";
-import { NavigationLink } from "#/components/shared/navigation-link";
-import { StyledTooltip } from "#/components/shared/buttons/styled-tooltip";
-import PlusIcon from "#/icons/u-plus.svg?react";
-import { cn } from "#/utils/utils";
-
-interface NewProjectButtonProps {
- disabled?: boolean;
-}
-
-export function NewProjectButton({ disabled = false }: NewProjectButtonProps) {
- const { t } = useTranslation("openhands");
-
- const startNewProject = t(I18nKey.CONVERSATION$START_NEW);
-
- return (
- <StyledTooltip content={startNewProject} placement="right">
- <NavigationLink
- to="/conversations"
- data-testid="new-project-button"
- aria-label={startNewProject}
- tabIndex={disabled ? -1 : 0}
- onClick={(e) => {
- if (disabled) {
- e.preventDefault();
- }
- }}
- className={cn("inline-flex items-center justify-center", {
- "pointer-events-none opacity-50": disabled,
- })}
- >
- <PlusIcon width={24} height={24} />
- </NavigationLink>
- </StyledTooltip>
- );
-}
diff --git a/src/components/shared/buttons/trajectory-action-button.tsx b/src/components/shared/buttons/trajectory-action-button.tsx
deleted file mode 100644
index 1d4507e38d..0000000000
--- a/src/components/shared/buttons/trajectory-action-button.tsx
+++ /dev/null
@@ -1,40 +0,0 @@
-import { StyledTooltip } from "./styled-tooltip";
-
-interface TrajectoryActionButtonProps {
- testId?: string;
- onClick: () => void;
- icon: React.ReactNode;
- tooltip?: string;
-}
-
-export function TrajectoryActionButton({
- testId,
- onClick,
- icon,
- tooltip,
-}: TrajectoryActionButtonProps) {
- const button = (
- <button
- type="button"
- data-testid={testId}
- onClick={onClick}
- className="flex items-center justify-center w-[26px] h-[26px] rounded-lg cursor-pointer bg-[var(--oh-surface)] hover:bg-tertiary"
- >
- {icon}
- </button>
- );
-
- if (tooltip) {
- return (
- <StyledTooltip
- closeDelay={100}
- content={tooltip}
- tooltipClassName="bg-white text-black hover:bg-transparent"
- >
- {button}
- </StyledTooltip>
- );
- }
-
- return button;
-}
diff --git a/src/components/shared/conversation-toast.tsx b/src/components/shared/conversation-toast.tsx
deleted file mode 100644
index ccfdeba698..0000000000
--- a/src/components/shared/conversation-toast.tsx
+++ /dev/null
@@ -1,22 +0,0 @@
-import toast from "react-hot-toast";
-
-export function renderConversationErroredToast(
- _conversationId: string,
- message: string,
-): void {
- toast.error(message);
-}
-
-export function renderConversationCreatedToast(): void {
- toast.success("Runtime started");
-}
-
-export function renderConversationFinishedToast(): void {
- toast.success("Conversation finished");
-}
-
-export function renderConversationStartingToast(conversationId: string): void {
- toast.loading("Starting runtime...", {
- id: `starting-${conversationId}`,
- });
-}
diff --git a/src/components/shared/inputs/badge-input.tsx b/src/components/shared/inputs/badge-input.tsx
deleted file mode 100644
index 6fc285a8d1..0000000000
--- a/src/components/shared/inputs/badge-input.tsx
+++ /dev/null
@@ -1,81 +0,0 @@
-import React from "react";
-import { cn } from "#/utils/utils";
-import { BrandBadge } from "../badge";
-import XIcon from "#/icons/x.svg?react";
-
-interface BadgeInputProps {
- name?: string;
- value: string[];
- placeholder?: string;
- onChange: (value: string[]) => void;
- className?: string;
- inputClassName?: string;
-}
-
-export function BadgeInput({
- name,
- value,
- placeholder,
- onChange,
- className,
- inputClassName,
-}: BadgeInputProps) {
- const [inputValue, setInputValue] = React.useState("");
-
- const handleKeyDown = (e: React.KeyboardEvent<HTMLInputElement>) => {
- // If pressing Backspace with empty input, remove the last badge
- if (e.key === "Backspace" && inputValue === "" && value.length > 0) {
- const newBadges = [...value];
- newBadges.pop();
- onChange(newBadges);
- return;
- }
-
- // If pressing Space or Enter with non-empty input, add a new badge
- if (e.key === " " && inputValue.trim() !== "") {
- e.preventDefault();
- const newBadge = inputValue.trim();
- onChange([...value, newBadge]);
- setInputValue("");
- }
- };
-
- const removeBadge = (indexToRemove: number) => {
- onChange(value.filter((_, index) => index !== indexToRemove));
- };
-
- return (
- <div
- className={cn(
- "bg-tertiary border border-[var(--oh-border-input)] rounded w-full p-2 placeholder:italic placeholder:text-tertiary-alt",
- "flex flex-wrap items-center gap-2",
- className,
- )}
- >
- {value.map((badge, index) => (
- <div key={index}>
- <BrandBadge className="flex items-center gap-0.5 py-1 px-2.5 text-sm text-base font-semibold leading-[16px]">
- {badge}
- <button
- data-testid="remove-button"
- type="button"
- onClick={() => removeBadge(index)}
- className="cursor-pointer"
- >
- <XIcon width={14} height={14} color="#000000" />
- </button>
- </BrandBadge>
- </div>
- ))}
- <input
- data-testid={name || "badge-input"}
- name={name}
- value={inputValue}
- placeholder={value.length === 0 ? placeholder : ""}
- onChange={(e) => setInputValue(e.target.value)}
- onKeyDown={handleKeyDown}
- className={cn("flex-grow outline-none bg-transparent", inputClassName)}
- />
- </div>
- );
-}
diff --git a/src/components/shared/loader.tsx b/src/components/shared/loader.tsx
deleted file mode 100644
index 0bd32ea441..0000000000
--- a/src/components/shared/loader.tsx
+++ /dev/null
@@ -1,25 +0,0 @@
-import { cn } from "#/utils/utils";
-
-interface LoaderProps {
- size?: "small" | "medium" | "large";
- className?: string;
-}
-
-export function Loader({ size = "medium", className }: LoaderProps) {
- const sizeClasses = {
- small: "w-3 h-3",
- medium: "w-4 h-4",
- large: "w-5 h-5",
- };
-
- const dotSize = sizeClasses[size];
-
- return (
- <div
- data-testid="loader"
- className={cn("flex items-center justify-center", className)}
- >
- <div className={cn("loader rounded-full", dotSize)} />
- </div>
- );
-}
diff --git a/src/components/shared/modals/modal-button-group.tsx b/src/components/shared/modals/modal-button-group.tsx
deleted file mode 100644
index d0a1dfec79..0000000000
--- a/src/components/shared/modals/modal-button-group.tsx
+++ /dev/null
@@ -1,70 +0,0 @@
-import React from "react";
-import { useTranslation } from "react-i18next";
-import { BrandButton } from "#/components/features/settings/brand-button";
-import { LoadingSpinner } from "#/components/shared/loading-spinner";
-import { I18nKey } from "#/i18n/declaration";
-import { cn } from "#/utils/utils";
-
-interface ModalButtonGroupProps {
- primaryText: string;
- secondaryText?: string;
- onPrimaryClick?: () => void;
- onSecondaryClick: () => void;
- isLoading?: boolean;
- primaryType?: "button" | "submit";
- primaryTestId?: string;
- secondaryTestId?: string;
- fullWidth?: boolean;
-}
-
-export function ModalButtonGroup({
- primaryText,
- secondaryText,
- onPrimaryClick,
- onSecondaryClick,
- isLoading = false,
- primaryType = "button",
- primaryTestId,
- secondaryTestId,
- fullWidth = false,
-}: ModalButtonGroupProps) {
- const { t } = useTranslation("openhands");
- const closeText = secondaryText ?? t(I18nKey.BUTTON$CLOSE);
-
- return (
- <div className="flex gap-2 w-full">
- <BrandButton
- type={primaryType}
- variant="primary"
- onClick={onPrimaryClick}
- className={cn(
- "flex items-center justify-center",
- fullWidth ? "w-full" : "grow",
- )}
- testId={primaryTestId}
- isDisabled={isLoading}
- >
- {isLoading ? (
- <LoadingSpinner
- size="small"
- className="w-5 h-5"
- innerClassName="hidden"
- outerClassName="w-5 h-5"
- />
- ) : (
- primaryText
- )}
- </BrandButton>
- <BrandButton
- type="button"
- variant="secondary"
- onClick={onSecondaryClick}
- className={cn(fullWidth ? "w-full" : "grow")}
- testId={secondaryTestId}
- isDisabled={isLoading}
- >
- {closeText}
- </BrandButton>
- </div>
- );
-}
diff --git a/src/components/shared/terms-and-privacy-notice.tsx b/src/components/shared/terms-and-privacy-notice.tsx
deleted file mode 100644
index ae6f27f105..0000000000
--- a/src/components/shared/terms-and-privacy-notice.tsx
+++ /dev/null
@@ -1,41 +0,0 @@
-import React from "react";
-import { useTranslation } from "react-i18next";
-import { I18nKey } from "#/i18n/declaration";
-import { cn } from "#/utils/utils";
-
-interface TermsAndPrivacyNoticeProps {
- className?: string;
-}
-
-export function TermsAndPrivacyNotice({
- className,
-}: TermsAndPrivacyNoticeProps) {
- const { t } = useTranslation("openhands");
-
- return (
- <p
- className={cn("text-xs text-center text-muted-foreground", className)}
- data-testid="terms-and-privacy-notice"
- >
- {t(I18nKey.AUTH$BY_SIGNING_UP_YOU_AGREE_TO_OUR)}{" "}
- <a
- href="https://www.all-hands.dev/tos"
- target="_blank"
- className="underline hover:text-primary"
- rel="noopener noreferrer"
- >
- {t(I18nKey.COMMON$TERMS_OF_SERVICE)}
- </a>{" "}
- {t(I18nKey.COMMON$AND)}{" "}
- <a
- href="https://www.all-hands.dev/privacy"
- target="_blank"
- className="underline hover:text-primary"
- rel="noopener noreferrer"
- >
- {t(I18nKey.COMMON$PRIVACY_POLICY)}
- </a>
- .
- </p>
- );
-}