feat(TALE-36): redesign machines page to account for exit nodes

This commit is contained in:
Aarnav Tale 2024-11-07 13:04:53 -05:00
parent 1490406784
commit a2e659f36c
No known key found for this signature in database
4 changed files with 287 additions and 102 deletions

View file

@ -36,6 +36,35 @@ export default function MachineRow({ machine, routes, magic, users }: Props) {
? magic.replace('[user]', machine.user.name)
: magic
// This is much easier with Object.groupBy but it's too new for us
const { exit, subnet, subnetApproved } = routes.reduce((acc, route) => {
if (route.prefix === '::/0' || route.prefix === '0.0.0.0/0') {
acc.exit.push(route)
return acc
}
if (route.enabled) {
acc.subnetApproved.push(route)
return acc
}
acc.subnet.push(route)
return acc
}, { exit: [], subnetApproved: [], subnet: [] })
const exitEnabled = useMemo(() => {
if (exit.length !== 2) return false
return exit[0].enabled && exit[1].enabled
}, [exit])
if (exitEnabled) {
tags.unshift('Exit Node')
}
if (subnetApproved.length > 0) {
tags.unshift('Subnets')
}
return (
<tr
key={machine.id}