@@ -50,34 +50,25 @@ const InternetGatewayIpPoolCell = ({ gatewayId }: { gatewayId: string }) => {
5050
5151// called by InternetGatewayAttachedRoutesCell to get the routes per router
5252// we need to have this in its own function because useQuery cannot be called inside a loop
53- const InternetGatewayIndividualRoute = ( {
53+ const InternetGatewayRoutes = ( {
5454 project,
5555 vpc,
5656 gateway,
5757 router,
5858} : PP . VpcInternetGateway & { router : string } ) => {
59- const matchingRoutes : JSX . Element [ ] = [ ]
6059 const { data : routes } = useQuery ( routeList ( { project, vpc, router } ) . optionsFn ( ) )
61- if ( ! routes || routes . items . length < 1 ) return
62- routes . items . forEach ( ( route ) => {
63- if ( route . target . type === 'internet_gateway' && route . target . value === gateway ) {
64- matchingRoutes . push (
65- < Link
66- key = { route . name }
67- to = { pb . vpcRouterRouteEdit ( {
68- project,
69- vpc,
70- router,
71- route : route . name ,
72- } ) }
73- className = "link-with-underline text-sans-md"
74- >
75- { route . name }
76- </ Link >
77- )
78- }
79- } )
80- return matchingRoutes
60+ if ( ! routes || routes . items . length < 1 ) return null
61+ return routes . items
62+ . filter ( ( r ) => r . target . type === 'internet_gateway' && r . target . value === gateway )
63+ . map ( ( route ) => (
64+ < Link
65+ key = { route . name }
66+ to = { pb . vpcRouterRouteEdit ( { project, vpc, router, route : route . name } ) }
67+ className = "link-with-underline text-sans-md"
68+ >
69+ { route . name }
70+ </ Link >
71+ ) )
8172}
8273
8374const InternetGatewayAttachedRoutesCell = ( {
@@ -86,14 +77,12 @@ const InternetGatewayAttachedRoutesCell = ({
8677 gateway,
8778} : PP . VpcInternetGateway ) => {
8879 const { data : routers } = useQuery ( routerList ( { project, vpc } ) . optionsFn ( ) )
89- const matchingRoutes = routers ?. items . flatMap ( ( router ) =>
90- InternetGatewayIndividualRoute ( { project, vpc, gateway, router : router . name } )
91- )
92- return matchingRoutes ?. length ? (
93- < div className = "space-x-2" > { matchingRoutes } </ div >
94- ) : (
95- < EmptyCell />
96- )
80+ const matchingRoutes = routers ?. items . map ( ( router ) => {
81+ const props = { project, vpc, gateway, router : router . name }
82+ return < InternetGatewayRoutes key = { router . name } { ...props } />
83+ } )
84+ if ( ! matchingRoutes ?. length ) return < EmptyCell />
85+ return < div className = "space-x-2" > { matchingRoutes } </ div >
9786}
9887
9988const colHelper = createColumnHelper < InternetGateway > ( )
0 commit comments