Skip to content
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

upcoming: [M3-7972] - Invalidate PG queries on Linode create/delete #10366

Merged
merged 2 commits into from
Apr 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@linode/manager": Upcoming Features
---

Invalidate Placement Group queries on Linode create & delete mutations ([#10366](https://github.com/linode/manager/pull/10366))
30 changes: 30 additions & 0 deletions packages/manager/src/queries/linodes/linodes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import {
useQueryClient,
} from '@tanstack/react-query';

import { placementGroupQueries } from 'src/queries/placementGroups';
import { manuallySetVPCConfigInterfacesToActive } from 'src/utilities/configs';

import { accountQueries } from '../account/queries';
Expand Down Expand Up @@ -138,12 +139,30 @@ export const useLinodeLishTokenQuery = (id: number) => {

export const useDeleteLinodeMutation = (id: number) => {
const queryClient = useQueryClient();
const linode = queryClient.getQueryData<Linode>([
queryKey,
'linode',
id,
'details',
]);
const placementGroupId = linode?.placement_group?.id;

return useMutation<{}, APIError[]>(() => deleteLinode(id), {
onSuccess() {
queryClient.removeQueries([queryKey, 'linode', id]);
queryClient.invalidateQueries([queryKey, 'paginated']);
queryClient.invalidateQueries([queryKey, 'all']);
queryClient.invalidateQueries([queryKey, 'infinite']);

// If the linode is assigned to a placement group,
// we need to invalidate the placement group queries
if (placementGroupId) {
queryClient.invalidateQueries(
placementGroupQueries.placementGroup(placementGroupId).queryKey
);
queryClient.invalidateQueries(placementGroupQueries.all.queryKey);
queryClient.invalidateQueries(placementGroupQueries.paginated._def);
}
},
});
};
Expand All @@ -167,6 +186,17 @@ export const useCreateLinodeMutation = () => {
// they are derived from Linode configs.
queryClient.invalidateQueries(vlanQueries._def);
}

// If the Linode is assigned to a placement group on creation,
// we need to invalidate the placement group queries
if (variables.placement_group?.id) {
queryClient.invalidateQueries(
placementGroupQueries.placementGroup(variables.placement_group.id)
.queryKey
);
queryClient.invalidateQueries(placementGroupQueries.all.queryKey);
queryClient.invalidateQueries(placementGroupQueries.paginated._def);
}
},
});
};
Expand Down
Loading