import { BranchEnvironmentIconSmall, DeployedEnvironmentIconSmall, DevEnvironmentIconSmall, ProdEnvironmentIconSmall, } from "~/assets/icons/EnvironmentIcons"; import type { RuntimeEnvironment } from "~/models/runtimeEnvironment.server"; import { cn } from "~/utils/cn"; import { SimpleTooltip } from "~/components/primitives/Tooltip"; import { useEffect, useRef, useState } from "react"; type Environment = Pick & { branchName?: string | null }; export function EnvironmentIcon({ environment, className, }: { environment: Environment; className?: string; }) { if (environment.branchName) { return ( ); } switch (environment.type) { case "DEVELOPMENT": return ( ); case "PRODUCTION": return ( ); case "STAGING": case "PREVIEW": return ( ); } } export function EnvironmentCombo({ environment, className, iconClassName, tooltipSideOffset, tooltipSide, }: { environment: Environment; className?: string; iconClassName?: string; tooltipSideOffset?: number; tooltipSide?: "top" | "right" | "bottom" | "left"; }) { return ( ); } export function EnvironmentLabel({ environment, className, tooltipSideOffset = 34, tooltipSide = "right", disableTooltip = false, }: { environment: Environment; className?: string; tooltipSideOffset?: number; tooltipSide?: "top" | "right" | "bottom" | "left"; disableTooltip?: boolean; }) { const spanRef = useRef(null); const [isTruncated, setIsTruncated] = useState(false); const text = environment.branchName ? environment.branchName : environmentFullTitle(environment); useEffect(() => { const checkTruncation = () => { if (spanRef.current) { const isTruncated = spanRef.current.scrollWidth > spanRef.current.clientWidth; setIsTruncated(isTruncated); } }; checkTruncation(); // Add resize observer to recheck on window resize const resizeObserver = new ResizeObserver(checkTruncation); if (spanRef.current) { resizeObserver.observe(spanRef.current); } return () => resizeObserver.disconnect(); }, [text]); const content = ( {text} ); if (isTruncated && !disableTooltip) { return ( {text} } side={tooltipSide} variant="dark" sideOffset={tooltipSideOffset} disableHoverableContent /> ); } return content; } export function EnvironmentSlug({ environment }: { environment: Environment & { slug: string } }) { return {environment.slug}; } export function environmentTitle(environment: Environment, username?: string) { if (environment.branchName) { return environment.branchName; } switch (environment.type) { case "PRODUCTION": return "Prod"; case "STAGING": return "Staging"; case "DEVELOPMENT": return username ? `Dev: ${username}` : "Dev: You"; case "PREVIEW": return "Preview"; } } export function environmentFullTitle(environment: Environment) { if (environment.branchName) { return environment.branchName; } switch (environment.type) { case "PRODUCTION": return "Production"; case "STAGING": return "Staging"; case "DEVELOPMENT": return "Development"; case "PREVIEW": return "Preview"; } } export function environmentTextClassName(environment: { type: Environment["type"] }) { switch (environment.type) { case "PRODUCTION": return "text-prod"; case "STAGING": return "text-staging"; case "DEVELOPMENT": return "text-dev"; case "PREVIEW": return "text-preview"; } }