-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add read-only UI for internet gateways (#2488)
* Update OMICRON_VERSION * update msw handlers * Other changes from initial branch * IP Pools tab in place * IP Pool ID is copyable from IP Pools tab * Add content to IP Addresses tab and root page * Update OMICRON_VERSION to sha with internet gateways * small tweaks * remove commented-out code * Use proper truncate component * adjust path-builder spec * Add breadcrumb nav for internet gateways * Update default internet gateway IP pool to reflect actual default values * update unrelated test * Remove n+1 query on IpPools * Add IpPoolCell * Remove code that we'll add separately * Upgrade OMICRON_VERSION * No need to extract UtilizationCell now * Get IP Pool tab for Internet Gateways working * Update snapshot, but there might still be some other issues to work out * Some headway, but screen is still blank * Update snapshots for test * Update routes; fix mock data * update tests with mock data, but this should probably get pulled to a new branch * Simplify mock data; renaming the default IP Pool to default was unnecessary and confusing * convert to new useQueryTable * Add internet gateway combobox to router route target field * Sidebar for Internet Gateway coming together * Bot commit: format with prettier * DOM shuffling * Update mock data * Update routes to handle new sidebar and main tab together * Reorder internet gateway sidebar * Update paths and snapshots * use more common internet-gateway-edit syntax for filename * Internet gateways modal tweak (#2607) Internet gateway modal tweaks * Add IP Address and IP Pool columns to Gateway table * test update * small tweaks to sidebar * reverting back to vertical table for now, to render IP Pool alonside join table info * Update copy when missing pool or ip address * Add a test for internet gateway list and sidemodal * Add routes targeting gateway to table * Better handle multiple route spacing; fix test * Update side modal with routes targeting gateway * Update test for showing route * Tweaks to sidemodal * move example gateway route to custom router, not default router * Update tests to reflect gateway route existing on custom router * use more specific params in queries * use titleCrumb for Edit Internet Gateway * fix RR leaf route without element warning * let's use a valid UUID * clean up InternetGatewayRoutes and call it as a component * update the snapshot! * fix gnarly dependent promises in gateways loader * update read only info box * clean up gateway routes fetch logic by extracting shared hook * extract gateway data logic into a separate file * Use count of routes; link to sidemodal * Use count of 0 instead of EmptyCell for route count * use EmptyCell for zero routes, copy tweaks, sentence case * sentence case idp form heading * minor: remove stub e2e test --------- Co-authored-by: David Crespo <[email protected]> Co-authored-by: github-actions <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: Benjamin Leonard <[email protected]>
- Loading branch information
1 parent
bc3161a
commit ada302c
Showing
23 changed files
with
832 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,151 @@ | ||
/* | ||
* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, you can obtain one at https://mozilla.org/MPL/2.0/. | ||
* | ||
* Copyright Oxide Computer Company | ||
*/ | ||
|
||
import { useQuery } from '@tanstack/react-query' | ||
import { createColumnHelper } from '@tanstack/react-table' | ||
import { useMemo } from 'react' | ||
import { Outlet, type LoaderFunctionArgs } from 'react-router-dom' | ||
|
||
import { apiq, getListQFn, queryClient, type InternetGateway } from '~/api' | ||
import { getVpcSelector, useVpcSelector } from '~/hooks/use-params' | ||
import { EmptyCell } from '~/table/cells/EmptyCell' | ||
import { IpPoolCell } from '~/table/cells/IpPoolCell' | ||
import { LinkCell, makeLinkCell } from '~/table/cells/LinkCell' | ||
import { Columns } from '~/table/columns/common' | ||
import { useQueryTable } from '~/table/QueryTable' | ||
import { CopyableIp } from '~/ui/lib/CopyableIp' | ||
import { EmptyMessage } from '~/ui/lib/EmptyMessage' | ||
import { ALL_ISH } from '~/util/consts' | ||
import { pb } from '~/util/path-builder' | ||
import type * as PP from '~/util/path-params' | ||
|
||
import { | ||
gatewayIpAddressList, | ||
gatewayIpPoolList, | ||
routeList, | ||
routerList, | ||
useGatewayRoutes, | ||
} from '../../gateway-data' | ||
|
||
const gatewayList = ({ project, vpc }: PP.Vpc) => | ||
getListQFn('internetGatewayList', { query: { project, vpc, limit: ALL_ISH } }) | ||
const projectIpPoolList = getListQFn('projectIpPoolList', { query: { limit: ALL_ISH } }) | ||
|
||
const IpAddressCell = (gatewaySelector: PP.VpcInternetGateway) => { | ||
const { data: addresses } = useQuery(gatewayIpAddressList(gatewaySelector).optionsFn()) | ||
if (!addresses || addresses.items.length < 1) return <EmptyCell /> | ||
return <CopyableIp ip={addresses.items[0].address} isLinked={false} /> | ||
} | ||
|
||
const GatewayIpPoolCell = (gatewaySelector: PP.VpcInternetGateway) => { | ||
const { data: gateways } = useQuery(gatewayIpPoolList(gatewaySelector).optionsFn()) | ||
if (!gateways || gateways.items.length < 1) return <EmptyCell /> | ||
return <IpPoolCell ipPoolId={gateways.items[0].ipPoolId} /> | ||
} | ||
|
||
const GatewayRoutes = ({ project, vpc, gateway }: PP.VpcInternetGateway) => { | ||
const matchingRoutes = useGatewayRoutes({ project, vpc, gateway }) | ||
const to = pb.vpcInternetGateway({ project, vpc, gateway }) | ||
if (!matchingRoutes?.length) return <EmptyCell /> | ||
return <LinkCell to={to}>{matchingRoutes.length}</LinkCell> | ||
} | ||
|
||
const colHelper = createColumnHelper<InternetGateway>() | ||
|
||
VpcInternetGatewaysTab.loader = async ({ params }: LoaderFunctionArgs) => { | ||
const { project, vpc } = getVpcSelector(params) | ||
const [gateways, routers] = await Promise.all([ | ||
queryClient.fetchQuery(gatewayList({ project, vpc }).optionsFn()), | ||
queryClient.fetchQuery(routerList({ project, vpc }).optionsFn()), | ||
]) | ||
|
||
await Promise.all([ | ||
...gateways.items.flatMap((gateway: InternetGateway) => [ | ||
queryClient.prefetchQuery( | ||
gatewayIpAddressList({ project, vpc, gateway: gateway.name }).optionsFn() | ||
), | ||
queryClient.prefetchQuery( | ||
gatewayIpPoolList({ project, vpc, gateway: gateway.name }).optionsFn() | ||
), | ||
]), | ||
...routers.items.map((router) => | ||
queryClient.prefetchQuery( | ||
routeList({ project, vpc, router: router.name }).optionsFn() | ||
) | ||
), | ||
queryClient.fetchQuery(projectIpPoolList.optionsFn()).then((pools) => { | ||
for (const pool of pools.items) { | ||
const { queryKey } = apiq('projectIpPoolView', { path: { pool: pool.id } }) | ||
queryClient.setQueryData(queryKey, pool) | ||
} | ||
}), | ||
] satisfies Promise<unknown>[]) | ||
|
||
return null | ||
} | ||
|
||
export function VpcInternetGatewaysTab() { | ||
const { project, vpc } = useVpcSelector() | ||
|
||
const emptyState = ( | ||
<EmptyMessage | ||
title="No internet gateways" | ||
body="Create an internet gateway to see it here" | ||
// buttonText="New internet gateway" | ||
// buttonTo={pb.vpcInternetGatewaysNew(vpcSelector)} | ||
/> | ||
) | ||
|
||
const columns = useMemo( | ||
() => [ | ||
colHelper.accessor('name', { | ||
cell: makeLinkCell((gateway) => pb.vpcInternetGateway({ project, vpc, gateway })), | ||
}), | ||
colHelper.accessor('description', Columns.description), | ||
colHelper.accessor('name', { | ||
// ID needed to avoid key collision with other name column | ||
id: 'ip-address', | ||
header: 'Attached IP Address', | ||
cell: (info) => ( | ||
<IpAddressCell project={project} vpc={vpc} gateway={info.getValue()} /> | ||
), | ||
}), | ||
colHelper.accessor('name', { | ||
// ID needed to avoid key collision with other name column | ||
id: 'ip-pool', | ||
header: 'Attached IP Pool', | ||
cell: (info) => ( | ||
<GatewayIpPoolCell project={project} vpc={vpc} gateway={info.getValue()} /> | ||
), | ||
}), | ||
colHelper.accessor('name', { | ||
// ID needed to avoid key collision with other name column | ||
id: 'routes', | ||
header: 'Routes', | ||
cell: (info) => ( | ||
<GatewayRoutes project={project} vpc={vpc} gateway={info.getValue()} /> | ||
), | ||
}), | ||
colHelper.accessor('timeCreated', Columns.timeCreated), | ||
], | ||
[project, vpc] | ||
) | ||
|
||
const { table } = useQueryTable({ | ||
query: gatewayList({ project, vpc }), | ||
columns, | ||
emptyState, | ||
}) | ||
|
||
return ( | ||
<> | ||
{table} | ||
<Outlet /> | ||
</> | ||
) | ||
} |
Oops, something went wrong.