Skip to content

Commit e8f8253

Browse files
refactor(site): sort proxies in navbar by latency (coder#8781)
1 parent 91a0c7a commit e8f8253

File tree

1 file changed

+41
-35
lines changed

1 file changed

+41
-35
lines changed

site/src/components/Navbar/NavbarView.tsx

Lines changed: 41 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,7 @@ const ProxyMenu: FC<{ proxyContextValue: ProxyContextValue }> = ({
300300
<Typography
301301
component="p"
302302
sx={{
303-
fontSize: "inherit",
303+
fontSize: 13,
304304
color: (theme) => theme.palette.text.secondary,
305305
lineHeight: "inherit",
306306
marginTop: 0.5,
@@ -311,43 +311,49 @@ const ProxyMenu: FC<{ proxyContextValue: ProxyContextValue }> = ({
311311
</Typography>
312312
</Box>
313313
<Divider sx={{ borderColor: (theme) => theme.palette.divider }} />
314-
{proxyContextValue.proxies?.map((proxy) => (
315-
<MenuItem
316-
onClick={() => {
317-
if (!proxy.healthy) {
318-
displayError("Please select a healthy workspace proxy.")
319-
closeMenu()
320-
return
321-
}
314+
{proxyContextValue.proxies
315+
?.sort((a, b) => {
316+
const latencyA = latencies?.[a.id]?.latencyMS ?? Infinity
317+
const latencyB = latencies?.[b.id]?.latencyMS ?? Infinity
318+
return latencyA - latencyB
319+
})
320+
.map((proxy) => (
321+
<MenuItem
322+
onClick={() => {
323+
if (!proxy.healthy) {
324+
displayError("Please select a healthy workspace proxy.")
325+
closeMenu()
326+
return
327+
}
322328

323-
proxyContextValue.setProxy(proxy)
324-
closeMenu()
325-
}}
326-
key={proxy.id}
327-
selected={proxy.id === selectedProxy?.id}
328-
sx={{
329-
fontSize: 14,
330-
}}
331-
>
332-
<Box display="flex" gap={3} alignItems="center" width="100%">
333-
<Box width={14} height={14} lineHeight={0}>
334-
<Box
335-
component="img"
336-
src={proxy.icon_url}
337-
alt=""
338-
sx={{ objectFit: "contain" }}
339-
width="100%"
340-
height="100%"
329+
proxyContextValue.setProxy(proxy)
330+
closeMenu()
331+
}}
332+
key={proxy.id}
333+
selected={proxy.id === selectedProxy?.id}
334+
sx={{
335+
fontSize: 14,
336+
}}
337+
>
338+
<Box display="flex" gap={3} alignItems="center" width="100%">
339+
<Box width={14} height={14} lineHeight={0}>
340+
<Box
341+
component="img"
342+
src={proxy.icon_url}
343+
alt=""
344+
sx={{ objectFit: "contain" }}
345+
width="100%"
346+
height="100%"
347+
/>
348+
</Box>
349+
{proxy.display_name}
350+
<ProxyStatusLatency
351+
latency={latencies?.[proxy.id]?.latencyMS}
352+
isLoading={proxyLatencyLoading(proxy)}
341353
/>
342354
</Box>
343-
{proxy.display_name}
344-
<ProxyStatusLatency
345-
latency={latencies?.[proxy.id]?.latencyMS}
346-
isLoading={proxyLatencyLoading(proxy)}
347-
/>
348-
</Box>
349-
</MenuItem>
350-
))}
355+
</MenuItem>
356+
))}
351357
<Divider sx={{ borderColor: (theme) => theme.palette.divider }} />
352358
{Boolean(permissions.editWorkspaceProxies) && (
353359
<MenuItem

0 commit comments

Comments
 (0)