π OpenHands: AI-Driven Development
refactor: extract BackNavButtonContent and crossfade helpers (#1404)
Hiep Led4dba6aa5901
diff --git a/__tests__/components/features/conversation/conversation-tab-content-crossfade.test.tsx b/__tests__/components/features/conversation/conversation-tab-content-crossfade.test.tsxnew file mode 100644index 0000000000..38b8fc7e5c--- /dev/null+++ b/__tests__/components/features/conversation/conversation-tab-content-crossfade.test.tsx@@ -0,0 +1,15 @@+import { render, screen } from "@testing-library/react";+import { describe, it, expect } from "vitest";+import { ConversationTabContentCrossfade } from "#/components/features/conversation/conversation-tabs/conversation-tab-content/conversation-tab-content-crossfade";++describe("ConversationTabContentCrossfade", () => {+ it("renders the tab content when not loading", () => {+ render(+ <ConversationTabContentCrossfade showAgentLoading={false} tabKey="files">+ <div data-testid="tab-child" />+ </ConversationTabContentCrossfade>,+ );++ expect(screen.getByTestId("tab-child")).toBeInTheDocument();+ });+});diff --git a/__tests__/components/shared/buttons/back-nav-button.test.tsx b/__tests__/components/shared/buttons/back-nav-button.test.tsxnew file mode 100644index 0000000000..d260979d1e--- /dev/null+++ b/__tests__/components/shared/buttons/back-nav-button.test.tsx@@ -0,0 +1,18 @@+import { render, screen, fireEvent } from "@testing-library/react";+import { describe, it, expect, vi } from "vitest";+import { BackNavButton } from "#/components/shared/buttons/back-nav-button";++describe("BackNavButton", () => {+ it("renders a back button that fires onClick when clicked", () => {+ const onClick = vi.fn();+ render(+ <BackNavButton onClick={onClick} testId="back-button">+ <span />+ </BackNavButton>,+ );++ fireEvent.click(screen.getByTestId("back-button"));++ expect(onClick).toHaveBeenCalledTimes(1);+ });+});diff --git a/src/components/features/conversation/conversation-tabs/conversation-tab-content/conversation-tab-content-crossfade.tsx b/src/components/features/conversation/conversation-tabs/conversation-tab-content/conversation-tab-content-crossfade.tsxindex a68d05a0ab..131588146f 100644--- a/src/components/features/conversation/conversation-tabs/conversation-tab-content/conversation-tab-content-crossfade.tsx+++ b/src/components/features/conversation/conversation-tabs/conversation-tab-content/conversation-tab-content-crossfade.tsx@@ -7,6 +7,8 @@ import {} from "react";import { AnimatePresence, motion, useReducedMotion } from "framer-motion";import { ConversationLoading } from "../../conversation-loading";+import { TabReadyNotifier } from "./tab-ready-notifier";+import { SuspensePendingFallback } from "./suspense-pending-fallback";const CROSSFADE_DURATION_SECONDS = 0.35;@@ -15,28 +17,6 @@ const crossfadeTransition = {ease: "easeInOut" as const,};-function TabReadyNotifier({- children,- onReady,-}: {- children: ReactNode;- onReady: () => void;-}) {- useLayoutEffect(() => {- onReady();- }, [onReady]);-- return children;-}--function SuspensePendingFallback({ onPending }: { onPending: () => void }) {- useLayoutEffect(() => {- onPending();- }, [onPending]);-- return <ConversationLoading />;-}-type ConversationTabContentCrossfadeProps = {showAgentLoading: boolean;tabKey: string;diff --git a/src/components/features/conversation/conversation-tabs/conversation-tab-content/suspense-pending-fallback.tsx b/src/components/features/conversation/conversation-tabs/conversation-tab-content/suspense-pending-fallback.tsxnew file mode 100644index 0000000000..9e54f6c29c--- /dev/null+++ b/src/components/features/conversation/conversation-tabs/conversation-tab-content/suspense-pending-fallback.tsx@@ -0,0 +1,14 @@+import { useLayoutEffect } from "react";+import { ConversationLoading } from "../../conversation-loading";++export function SuspensePendingFallback({+ onPending,+}: {+ onPending: () => void;+}) {+ useLayoutEffect(() => {+ onPending();+ }, [onPending]);++ return <ConversationLoading />;+}diff --git a/src/components/features/conversation/conversation-tabs/conversation-tab-content/tab-ready-notifier.tsx b/src/components/features/conversation/conversation-tabs/conversation-tab-content/tab-ready-notifier.tsxnew file mode 100644index 0000000000..ff3da21632--- /dev/null+++ b/src/components/features/conversation/conversation-tabs/conversation-tab-content/tab-ready-notifier.tsx@@ -0,0 +1,15 @@+import { ReactNode, useLayoutEffect } from "react";++export function TabReadyNotifier({+ children,+ onReady,+}: {+ children: ReactNode;+ onReady: () => void;+}) {+ useLayoutEffect(() => {+ onReady();+ }, [onReady]);++ return children;+}diff --git a/src/components/shared/buttons/back-nav-button-content.tsx b/src/components/shared/buttons/back-nav-button-content.tsxnew file mode 100644index 0000000000..028d853038--- /dev/null+++ b/src/components/shared/buttons/back-nav-button-content.tsx@@ -0,0 +1,11 @@+import type { ReactNode } from "react";+import { ArrowLeft } from "lucide-react";++export function BackNavButtonContent({ children }: { children: ReactNode }) {+ return (+ <>+ <ArrowLeft size={20} aria-hidden />+ {children}+ </>+ );+}diff --git a/src/components/shared/buttons/back-nav-button.tsx b/src/components/shared/buttons/back-nav-button.tsxindex 9cefd4c432..ce1a5c1b91 100644--- a/src/components/shared/buttons/back-nav-button.tsx+++ b/src/components/shared/buttons/back-nav-button.tsx@@ -1,8 +1,8 @@import React from "react";-import { ArrowLeft } from "lucide-react";import { NavigationLink } from "#/components/shared/navigation-link";import { cn } from "#/utils/utils";import { formControlBackNavButtonClassName } from "#/utils/form-control-classes";+import { BackNavButtonContent } from "./back-nav-button-content";type BackNavButtonBaseProps = {children: React.ReactNode;@@ -23,17 +23,6 @@ export type BackNavButtonProps =| BackNavButtonAsButtonProps| BackNavButtonAsLinkProps;-function BackNavButtonContent({- children,-}: Pick<BackNavButtonBaseProps, "children">) {- return (- <>- <ArrowLeft size={20} aria-hidden />- {children}- </>- );-}-export function BackNavButton(props: BackNavButtonAsLinkProps,): React.JSX.Element;