Skip to content

Commit

Permalink
use useVPCQuery to get all subnets insted of extra query
Browse files Browse the repository at this point in the history
  • Loading branch information
bnussman committed Jan 2, 2024
1 parent f8d7aa2 commit 644f882
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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<
Expand Down
14 changes: 0 additions & 14 deletions packages/manager/src/queries/vpcs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down Expand Up @@ -98,18 +96,6 @@ export const useSubnetsQuery = (
);
};

export const useAllSubnetsQuery = (vpcID: number, enabled: boolean = true) =>
useQuery<Subnet[], APIError[]>(
[vpcQueryKey, 'vpc', vpcID, subnetQueryKey, 'unpaginated'],
() => getAllSubnetsRequest(vpcID),
{ enabled, keepPreviousData: true }
);

const getAllSubnetsRequest = (vpcID: number) =>
getAll<Subnet>((params, filters) =>
getSubnets(vpcID, params, filters)
)().then((data) => data.data);

export const useSubnetQuery = (vpcID: number, subnetID: number) => {
return useQuery<Subnet, APIError[]>(
[vpcQueryKey, 'vpc', vpcID, subnetQueryKey, 'subnet', subnetID],
Expand Down

0 comments on commit 644f882

Please sign in to comment.