MCPcopy Create free account
hub / github.com/coder/coder / Latency

Function Latency

site/src/components/Latency/Latency.tsx:19–70  ·  view source on GitHub ↗
({
	latency,
	isLoading,
	className,
})

Source from the content-addressed store, hash-verified

17}
18
19export const Latency: FC<LatencyProps> = ({
20 latency,
21 isLoading,
22 className,
23}) => {
24 // Always use the no latency color for loading.
25 const latencyColor = getLatencyColor(isLoading ? undefined : latency);
26
27 if (isLoading) {
28 return (
29 <Tooltip>
30 <TooltipTrigger asChild>
31 {/**
32 * Spinning progress icon must be placed inside a fixed-size container,
33 * to ensure tooltip remains stationary when opened
34 */}
35 <div
36 className={cn(
37 "size-4 flex flex-wrap place-content-center",
38 className,
39 )}
40 >
41 <Spinner loading className={cn("!size-icon-xs", latencyColor)} />
42 </div>
43 </TooltipTrigger>
44 <TooltipContent side="bottom">Loading latency...</TooltipContent>
45 </Tooltip>
46 );
47 }
48
49 if (!latency) {
50 return (
51 <Tooltip>
52 <TooltipTrigger asChild>
53 <CircleHelpIcon
54 aria-label="Latency not available"
55 className={cn("!size-icon-sm", latencyColor, className)}
56 />
57 </TooltipTrigger>
58 <TooltipContent side="bottom">Latency not available</TooltipContent>
59 </Tooltip>
60 );
61 }
62
63 return (
64 <div className={cn("text-sm", latencyColor, className)}>
65 <span className="sr-only">Latency: </span>
66 {latency.toFixed(0)}
67 <Abbr title="milliseconds">ms</Abbr>
68 </div>
69 );
70};

Callers

nothing calls this directly

Calls 2

getLatencyColorFunction · 0.90
cnFunction · 0.90

Tested by

no test coverage detected