diff --git a/packages/manager/.changeset/pr-10366-upcoming-features-1712781737734.md b/packages/manager/.changeset/pr-10366-upcoming-features-1712781737734.md new file mode 100644 index 00000000000..cc324ed2626 --- /dev/null +++ b/packages/manager/.changeset/pr-10366-upcoming-features-1712781737734.md @@ -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)) diff --git a/packages/manager/src/queries/linodes/linodes.ts b/packages/manager/src/queries/linodes/linodes.ts index 391c4870271..9f376fbbe6f 100644 --- a/packages/manager/src/queries/linodes/linodes.ts +++ b/packages/manager/src/queries/linodes/linodes.ts @@ -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'; @@ -138,12 +139,30 @@ export const useLinodeLishTokenQuery = (id: number) => { export const useDeleteLinodeMutation = (id: number) => { const queryClient = useQueryClient(); + const linode = queryClient.getQueryData([ + 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); + } }, }); }; @@ -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); + } }, }); };