1
- import { useRef , useState , FC } from "react" ;
2
- import { makeStyles , useTheme } from "@mui/styles " ;
1
+ import { type FC , useRef , useState } from "react" ;
2
+ import { useTheme } from "@emotion/react " ;
3
3
import { Theme } from "@mui/material/styles" ;
4
+ import type { WorkspaceAgent , DERPRegion } from "api/typesGenerated" ;
4
5
import {
5
6
HelpTooltipText ,
6
7
HelpPopover ,
7
8
HelpTooltipTitle ,
8
9
} from "components/HelpTooltip/HelpTooltip" ;
9
10
import { Stack } from "components/Stack/Stack" ;
10
- import { WorkspaceAgent , DERPRegion } from "api/typesGenerated" ;
11
11
import { getLatencyColor } from "utils/latency" ;
12
12
13
13
const getDisplayLatency = ( theme :Theme , agent :WorkspaceAgent ) => {
@@ -30,12 +30,11 @@ const getDisplayLatency = (theme: Theme, agent: WorkspaceAgent) => {
30
30
} ;
31
31
32
32
export const AgentLatency :FC < { agent :WorkspaceAgent } > = ( { agent} ) => {
33
- const theme : Theme = useTheme ( ) ;
33
+ const theme = useTheme ( ) ;
34
34
const anchorRef = useRef < HTMLButtonElement > ( null ) ;
35
35
const [ isOpen , setIsOpen ] = useState ( false ) ;
36
36
const id = isOpen ?"latency-popover" :undefined ;
37
37
const latency = getDisplayLatency ( theme , agent ) ;
38
- const styles = useStyles ( ) ;
39
38
40
39
if ( ! latency || ! agent . latency ) {
41
40
return null ;
@@ -49,8 +48,7 @@ export const AgentLatency: FC<{ agent: WorkspaceAgent }> = ({ agent }) => {
49
48
ref = { anchorRef }
50
49
onMouseEnter = { ( ) => setIsOpen ( true ) }
51
50
onMouseLeave = { ( ) => setIsOpen ( false ) }
52
- className = { styles . trigger }
53
- style = { { color :latency . color } }
51
+ css = { { cursor :"pointer" , color :latency . color } }
54
52
>
55
53
{ Math . round ( Math . round ( latency . latency_ms ) ) } ms
56
54
</ span >
@@ -67,7 +65,11 @@ export const AgentLatency: FC<{ agent: WorkspaceAgent }> = ({ agent }) => {
67
65
first row is the preferred relay.
68
66
</ HelpTooltipText >
69
67
< HelpTooltipText >
70
- < Stack direction = "column" spacing = { 1 } className = { styles . regions } >
68
+ < Stack
69
+ direction = "column"
70
+ spacing = { 1 }
71
+ css = { { marginTop :theme . spacing ( 2 ) } }
72
+ >
71
73
{ Object . entries ( agent . latency )
72
74
. sort ( ( [ , a ] , [ , b ] ) => a . latency_ms - b . latency_ms )
73
75
. map ( ( [ regionName , region ] ) => (
@@ -76,7 +78,11 @@ export const AgentLatency: FC<{ agent: WorkspaceAgent }> = ({ agent }) => {
76
78
key = { regionName }
77
79
spacing = { 0.5 }
78
80
justifyContent = "space-between"
79
- className = { region . preferred ?styles . preferred :undefined }
81
+ css = {
82
+ region . preferred && {
83
+ color :theme . palette . text . primary ,
84
+ }
85
+ }
80
86
>
81
87
< strong > { regionName } </ strong >
82
88
{ Math . round ( region . latency_ms ) } ms
@@ -88,15 +94,3 @@ export const AgentLatency: FC<{ agent: WorkspaceAgent }> = ({ agent }) => {
88
94
</ >
89
95
) ;
90
96
} ;
91
-
92
- const useStyles = makeStyles ( ( theme ) => ( {
93
- trigger :{
94
- cursor :"pointer" ,
95
- } ,
96
- regions :{
97
- marginTop :theme . spacing ( 2 ) ,
98
- } ,
99
- preferred :{
100
- color :theme . palette . text . primary ,
101
- } ,
102
- } ) ) ;