Skip to content

Commit 5c1412f

Browse files
committed
Share colors from the agent row
1 parent ce7ad2b commit 5c1412f

File tree

4 files changed

+27
-10
lines changed

4 files changed

+27
-10
lines changed

site/src/components/Resources/AgentLatency.tsx

+2-9
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import {
77
} from "components/Tooltips/HelpTooltip"
88
import { Stack } from "components/Stack/Stack"
99
import { WorkspaceAgent, DERPRegion } from "api/typesGenerated"
10+
import { getLatencyColor } from "utils/colors"
1011

1112
const getDisplayLatency = (theme: Theme, agent: WorkspaceAgent) => {
1213
// Find the right latency to display
@@ -21,17 +22,9 @@ const getDisplayLatency = (theme: Theme, agent: WorkspaceAgent) => {
2122
return undefined
2223
}
2324

24-
// Get the color
25-
let color = theme.palette.success.light
26-
if (latency.latency_ms >= 150 && latency.latency_ms < 300) {
27-
color = theme.palette.warning.light
28-
} else if (latency.latency_ms >= 300) {
29-
color = theme.palette.error.light
30-
}
31-
3225
return {
3326
...latency,
34-
color,
27+
color: getLatencyColor(theme, latency.latency_ms),
3528
}
3629
}
3730

site/src/pages/UserSettingsPage/WorkspaceProxyPage/WorkspaceProxyRow.tsx

+10-1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ import {
1212
import { makeStyles } from "@material-ui/core/styles"
1313
import { combineClasses } from "utils/combineClasses"
1414
import { ProxyLatencyReport } from "contexts/useProxyLatency"
15+
import { useTheme } from "@material-ui/core/styles"
16+
import { getLatencyColor } from "utils/colors"
1517

1618
export const ProxyRow: FC<{
1719
latency?: ProxyLatencyReport
@@ -20,6 +22,7 @@ export const ProxyRow: FC<{
2022
preferred: boolean
2123
}> = ({ proxy, onSelectRegion, preferred, latency }) => {
2224
const styles = useStyles()
25+
const theme = useTheme()
2326

2427
const clickable = useClickableTableRow(() => {
2528
onSelectRegion(proxy)
@@ -56,7 +59,13 @@ export const ProxyRow: FC<{
5659
<ProxyStatus proxy={proxy} />
5760
</TableCell>
5861
<TableCell>
59-
{latency ? `${latency.latencyMS.toFixed(1)} ms` : "?"}
62+
<span
63+
style={{
64+
color: latency ? getLatencyColor(theme, latency.latencyMS) : "",
65+
}}
66+
>
67+
{latency ? `${latency.latencyMS.toFixed(1)} ms` : "?"}
68+
</span>
6069
</TableCell>
6170
</TableRow>
6271
)

site/src/pages/UserSettingsPage/WorkspaceProxyPage/WorkspaceProxyView.tsx

+1
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ export const WorkspaceProxyView: FC<
5252
<TableCell width="40%">Proxy</TableCell>
5353
<TableCell width="30%">URL</TableCell>
5454
<TableCell width="10%">Status</TableCell>
55+
<TableCell width="20%">Latency</TableCell>
5556
</TableRow>
5657
</TableHead>
5758
<TableBody>

site/src/utils/colors.ts

+14
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { Theme } from "@material-ui/core/styles"
2+
13
// Used to convert our theme colors to Hex since monaco theme only support hex colors
24
// From https://www.jameslmilner.com/posts/converting-rgb-hex-hsl-colors/
35
export function hslToHex(hsl: string): string {
@@ -21,3 +23,15 @@ export function hslToHex(hsl: string): string {
2123
}
2224
return `#${f(0)}${f(8)}${f(4)}`
2325
}
26+
27+
// getLatencyColor is the text color to use for a given latency
28+
// in milliseconds.
29+
export const getLatencyColor = (theme: Theme, latency: number) => {
30+
let color = theme.palette.success.light
31+
if (latency >= 150 && latency < 300) {
32+
color = theme.palette.warning.light
33+
} else if (latency >= 300) {
34+
color = theme.palette.error.light
35+
}
36+
return color
37+
}

0 commit comments

Comments
 (0)