From 644f882aa7263eab8c265f9c6d6465ed30f8da66 Mon Sep 17 00:00:00 2001 From: Banks Nussman Date: Tue, 2 Jan 2024 15:33:28 -0500 Subject: [PATCH] use `useVPCQuery` to get all subnets insted of extra query --- .../features/VPCs/VPCDetail/SubnetCreateDrawer.tsx | 6 +++--- packages/manager/src/queries/vpcs.ts | 14 -------------- 2 files changed, 3 insertions(+), 17 deletions(-) diff --git a/packages/manager/src/features/VPCs/VPCDetail/SubnetCreateDrawer.tsx b/packages/manager/src/features/VPCs/VPCDetail/SubnetCreateDrawer.tsx index c0e24fb81b5..d7e613b0157 100644 --- a/packages/manager/src/features/VPCs/VPCDetail/SubnetCreateDrawer.tsx +++ b/packages/manager/src/features/VPCs/VPCDetail/SubnetCreateDrawer.tsx @@ -6,7 +6,7 @@ import { ActionsPanel } from 'src/components/ActionsPanel/ActionsPanel'; import { Drawer } from 'src/components/Drawer'; import { Notice } from 'src/components/Notice/Notice'; import { useGrants, useProfile } from 'src/queries/profile'; -import { useAllSubnetsQuery, useCreateSubnetMutation } from 'src/queries/vpcs'; +import { useCreateSubnetMutation, useVPCQuery } from 'src/queries/vpcs'; import { getErrorMap } from 'src/utilities/errorUtils'; import { DEFAULT_SUBNET_IPV4_VALUE, @@ -27,13 +27,13 @@ export const SubnetCreateDrawer = (props: Props) => { const { data: profile } = useProfile(); const { data: grants } = useGrants(); - const { data: allSubnets } = useAllSubnetsQuery(vpcId); + const { data: vpc } = useVPCQuery(vpcId, open); const userCannotAddSubnet = profile?.restricted && !grants?.global.add_vpcs; const recommendedIPv4 = getRecommendedSubnetIPv4( DEFAULT_SUBNET_IPV4_VALUE, - allSubnets?.map((subnet) => subnet.ipv4 ?? '') ?? [] + vpc?.subnets?.map((subnet) => subnet.ipv4 ?? '') ?? [] ); const [errorMap, setErrorMap] = React.useState< diff --git a/packages/manager/src/queries/vpcs.ts b/packages/manager/src/queries/vpcs.ts index 3693b9bd9a1..10175e32a41 100644 --- a/packages/manager/src/queries/vpcs.ts +++ b/packages/manager/src/queries/vpcs.ts @@ -24,8 +24,6 @@ import { } from '@linode/api-v4/lib/types'; import { useMutation, useQuery, useQueryClient } from 'react-query'; -import { getAll } from 'src/utilities/getAll'; - export const vpcQueryKey = 'vpcs'; export const subnetQueryKey = 'subnets'; @@ -98,18 +96,6 @@ export const useSubnetsQuery = ( ); }; -export const useAllSubnetsQuery = (vpcID: number, enabled: boolean = true) => - useQuery( - [vpcQueryKey, 'vpc', vpcID, subnetQueryKey, 'unpaginated'], - () => getAllSubnetsRequest(vpcID), - { enabled, keepPreviousData: true } - ); - -const getAllSubnetsRequest = (vpcID: number) => - getAll((params, filters) => - getSubnets(vpcID, params, filters) - )().then((data) => data.data); - export const useSubnetQuery = (vpcID: number, subnetID: number) => { return useQuery( [vpcQueryKey, 'vpc', vpcID, subnetQueryKey, 'subnet', subnetID],