Skip to content

πŸ™Œ OpenHands: AI-Driven Development

1.3 KB
Raw Blame
import React from "react";
import { cn } from "#/utils/utils";

interface BackendStatusDotProps {
  /** `null` while the first probe is in flight. */
  isConnected: boolean | null | "unavailable";
  className?: string;
}

/**
 * Small colored dot that reflects backend reachability:
 *   - green when connected
 *   - red when disconnected
 *   - dim gray while the first probe is in flight
 */
export function BackendStatusDot({
  isConnected,
  className,
}: BackendStatusDotProps) {
  let color: string;
  let label: string;
  let status: string;
  if (isConnected === "unavailable") {
    color = "bg-text-tertiary";
    label = "No Backend Available";
    status = "unavailable";
  } else if (isConnected === true) {
    color = "bg-status-success";
    label = "Connected";
    status = "connected";
  } else if (isConnected === false) {
    color = "bg-status-error";
    label = "Disconnected";
    status = "disconnected";
  } else {
    color = "bg-interactive-selected";
    label = "Checking connection";
    status = "checking";
  }

  return (
    <span
      data-testid="backend-status-dot"
      data-status={status}
      aria-label={label}
      title={label}
      role="status"
      className={cn(
        "inline-block w-2 h-2 rounded-full shrink-0",
        color,
        className,
      )}
    />
  );
}