-
Notifications
You must be signed in to change notification settings - Fork 332
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
refactor: [M3-7920, M3-7930] β Refactor VPC queries #10322
refactor: [M3-7920, M3-7930] β Refactor VPC queries #10322
Conversation
β¦ConfigInterface.ts; include 'VPCs' as capability for mock regions
β¦sts.ts + update imports across multiple files
contextQueries: { | ||
subnet: (subnetId: number) => ({ | ||
queryFn: () => getSubnet(vpcId, subnetId), | ||
queryKey: null, | ||
}), | ||
subnets: { | ||
paginated: (params: Params = {}, filter: Filter = {}) => ({ | ||
queryFn: () => getSubnets(vpcId, params, filter), | ||
queryKey: [params, filter], | ||
}), | ||
}, | ||
}, | ||
queryFn: () => getVPC(vpcId), | ||
queryKey: [vpcId], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@bnussman-akamai Does this look correct to you? For some reason, when I go into useSubnetsQuery
and begin refactoring it, I type ...vpcQueries.vpc(vpcID).
but _ctx
doesn't get picked up on as something that exists on the object.
I pulled an example from the docs,
export const users = createQueryKeys('users', {
detail: (userId: string) => ({
contextQueries: {
likes: {
queryFn: () => api.getUserLikes(userId),
queryKey: null,
},
},
queryFn: () => api.getUser(userId),
queryKey: [userId],
}),
});
just to test the autocomplete and see if there's a syntax issue, but it successfully picked up on users.detail(userId)._ctx
as expected.
Am I overlooking something here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Give this a try
export const vpcQueries = createQueryKeys('vpcs', {
vpc: (vpcId: number) => ({
contextQueries: {
subnets: {
contextQueries: {
paginated: (params: Params = {}, filter: Filter = {}) => ({
queryFn: () => getSubnets(vpcId, params, filter),
queryKey: [params, filter],
}),
subnet: (subnetId: number) => ({
queryFn: () => getSubnet(vpcId, subnetId),
queryKey: [subnetId],
}),
},
queryKey: null,
},
},
queryFn: () => getVPC(vpcId),
queryKey: [vpcId],
}),
vpcs: {
contextQueries: {
all: {
queryFn: getAllVPCsRequest,
queryKey: null,
},
paginated: (params: Params = {}, filter: Filter = {}) => ({
queryFn: () => getVPCs(params, filter),
queryKey: [params, filter],
}),
},
queryKey: null,
},
});
- I added
queryKey: [subnetId]
to the subnet definition - I added more nesting to the subnets queries
β¦ should invalidate all VPC queries still)
β¦since LinodeEntityDetail.tsx pulls in from that one
β¦dual VPC, and VPC subnets queries should be invalidated upon Linode deletion
β¦tUnassignLinodesDrawer.tsx, and SubnetAssignLinodesDrawer.tsx (assigning and unassigning Linodes via the drawer should invalidate the paginated VPC, individual VPC, and VPC subnets queries)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This query previously existed:
export const useSubnetQuery = (vpcID: number, subnetID: number) => {
return useQuery<Subnet, APIError[]>(
[vpcQueryKey, 'vpc', vpcID, subnetQueryKey, 'subnet', subnetID],
() => getSubnet(vpcID, subnetID)
);
};
Most of the original queries were written before actual dev work on the UI began last summer, and it turns out this was never used (there's nothing approximating a Subnet Details page) so I removed it.
|
||
import type { | ||
APIError, | ||
DeleteLinodeConfigInterfacePayload, | ||
} from '@linode/api-v4'; | ||
|
||
type IdsForUnassignLinode = DeleteLinodeConfigInterfacePayload & { | ||
subnetId: number; | ||
interface IdsForUnassignLinode extends DeleteLinodeConfigInterfacePayload { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
match the new convention (see #10309 for more)
|
||
import type { | ||
APIError, | ||
DeleteLinodeConfigInterfacePayload, | ||
} from '@linode/api-v4'; | ||
|
||
type IdsForUnassignLinode = DeleteLinodeConfigInterfacePayload & { | ||
subnetId: number; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nothing at the level of [vpcQueryKey, 'vpc', vpcId, subnetQueryKey, 'subnet', subnetId]
was ever used in the actual code so this was superfluous
queryFn: () => getVPC(vpcId), | ||
queryKey: [vpcId], | ||
}), | ||
vpcs: { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we "un-nest" the all
and paginated
queries?
Like this:
export const vpcQueries = createQueryKeys('vpcs', {
all: {
queryFn: getAllVPCsRequest,
queryKey: null,
},
paginated: (params: Params = {}, filter: Filter = {}) => ({
queryFn: () => getVPCs(params, filter),
queryKey: [params, filter],
}),
vpc: (vpcId: number) => ({
contextQueries: {
subnets: {
contextQueries: {
paginated: (params: Params = {}, filter: Filter = {}) => ({
queryFn: () => getSubnets(vpcId, params, filter),
queryKey: [params, filter],
}),
subnet: (subnetId: number) => ({
queryFn: () => getSubnet(vpcId, subnetId),
queryKey: [subnetId],
}),
},
queryKey: null,
},
},
queryFn: () => getVPC(vpcId),
queryKey: [vpcId],
}),
})
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@bnussman-akamai Yes, that works and allows us to clean things up a bit ππΎ Going to push that change
β¦ng need for contextQueries/_ctx and to clean up the end result of the query key
Coverage Report: β
|
packages/manager/src/features/Linodes/LinodesCreate/LinodeCreateContainer.tsx
Outdated
Show resolved
Hide resolved
packages/manager/src/features/Linodes/LinodesDetail/LinodeConfigs/LinodeConfigDialog.tsx
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we refactor this hook to use useVPCQuery
instead of useAllVPCsQuery
? This should be a solid optimization over fetching every single VPC
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We previously used useVPCsQuery
here, but I think that would pose an issue for some data on the Linode Detail page (see LinodeEntityDetail.tsx
and LinodeIPAddress.tsx
) for customers with lots of VPCs if the VPC wasn't on the first page of results?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm proposing we just fetch the singular VPC. I agree useVPCsQuery
isn't a reliable way to do this
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Whoops, I misread your original comment. Yes, that worked fine from my testing so I pushed the refactor in the most recent commit.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking great, just a few more things
@@ -35,6 +22,10 @@ export const useVPCConfigInterface = (linodeId: number) => { | |||
return interfaceWithVPC; | |||
}); | |||
|
|||
const { data: vpcLinodeIsAssignedTo } = useVPCQuery( | |||
configInterfaceWithVPC?.vpc_id ?? -1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We might want to disable this query so we don't fetch when there is no VPC interface on a Linode.
configInterfaceWithVPC?.vpc_id ?? -1 | |
configInterfaceWithVPC?.vpc_id ?? -1, | |
Boolean(configInterfaceWithVPC) |
@cliu-akamai There's an E2E failure for |
Sure thing! |
Looks like deleting lines I'm happy to push that change if you want me to! |
Initially it was a bit confusing because Another point is looking into removing the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great π₯ Thanks for doing this!
packages/manager/src/features/Linodes/LinodesCreate/LinodeCreateContainer.tsx
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice work @dwiley-akamai!
confirming on the VPC flow and no regressions found.
@bnussman-akamai Good catches, those were appropriate invalidations to include. Added in the latest commit |
Description π
Refactor the VPC queries to use
createQueryKeys
fromquery-key-factory
.The main objective was to achieve parity with existing functionality, although some small enhancements at the margins were done as well.
Changes π
createQueryKeys
to generate VPC & subnet query keysuseAllVPCsQuery
and use it inVPCPanel.tsx
&useVPCConfigInterface.tsx
vpcQueryKey
andsubnetQueryKey
throughout codebase, notably for various query invalidationsuseSubnetQuery
Target release date ποΈ
4/15/24
How to test π§ͺ
Verification steps
Essentially the entire VPC offering in Cloud needs to be tested to ensure nothing has broken with these changes.
As an Author I have considered π€