import { Tooltip } from "@opencode-ai/ui/tooltip" import { createResizeObserver } from "@solid-primitives/resize-observer" import { children, createEffect, createMemo, createSignal, type JSXElement, onMount, type ParentProps, Show, } from "solid-js" import { useLanguage } from "@/context/language" import { type ServerConnection, serverName } from "@/context/server" import type { ServerHealth } from "@/utils/server-health" interface ServerRowProps extends ParentProps { conn: ServerConnection.Any status?: ServerHealth class?: string nameClass?: string versionClass?: string dimmed?: boolean badge?: JSXElement showCredentials?: boolean } export function ServerRow(props: ServerRowProps) { const language = useLanguage() const [truncated, setTruncated] = createSignal(false) let nameRef: HTMLSpanElement | undefined let versionRef: HTMLSpanElement | undefined const name = createMemo(() => serverName(props.conn)) const check = () => { const nameTruncated = nameRef ? nameRef.scrollWidth > nameRef.clientWidth : false const versionTruncated = versionRef ? versionRef.scrollWidth > versionRef.clientWidth : false setTruncated(nameTruncated || versionTruncated) } createEffect(() => { name() props.conn.http.url props.status?.version queueMicrotask(check) }) onMount(() => { if (typeof ResizeObserver !== "function") return createResizeObserver([nameRef, versionRef], check) check() }) const tooltipValue = () => ( {serverName(props.conn, true)} v{props.status?.version} ) const badge = children(() => props.badge) return (
{name()} v{props.status?.version} } > {(badge) => badge()}
{(conn) => (
{conn().http.username ? ( {conn().http.username} ) : ( {language.t("server.row.noUsername")} )} {conn().http.password && ••••••••}
)}
{props.children}
) } export function ServerHealthIndicator(props: { health?: ServerHealth }) { return (
) }