Skip to content

Commit

Permalink
Invalidate related linode when removed from PG
Browse files Browse the repository at this point in the history
  • Loading branch information
abailly-akamai committed Feb 16, 2024
1 parent c01bec1 commit cde4ef9
Showing 1 changed file with 19 additions and 2 deletions.
21 changes: 19 additions & 2 deletions packages/manager/src/queries/placementGroups.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import { useMutation, useQuery, useQueryClient } from 'react-query';

import { getAll } from 'src/utilities/getAll';

import { queryKey as LINODES_QUERY_KEY } from './linodes/linodes';
import { queryKey as PROFILE_QUERY_KEY } from './profile';

import type {
Expand Down Expand Up @@ -117,7 +118,7 @@ export const useAssignLinodesToPlacementGroup = (placementGroupId: number) => {
AssignLinodesToPlacementGroupPayload
>({
mutationFn: (data) => assignLinodesToPlacementGroup(placementGroupId, data),
onSuccess: (updatedPlacementGroup) => {
onSuccess: (updatedPlacementGroup, data) => {
// Invalidate paginated placement groups
queryClient.invalidateQueries([queryKey, 'paginated']);

Expand All @@ -129,6 +130,14 @@ export const useAssignLinodesToPlacementGroup = (placementGroupId: number) => {
'linode_ids',
]);

// Invalidate linode placement group data
queryClient.invalidateQueries([
LINODES_QUERY_KEY,
'linode',
data.linodes[0],
'placement_groups',
]);

// Set the updated placement group
queryClient.setQueryData(
[queryKey, 'placement-group', placementGroupId],
Expand All @@ -149,7 +158,7 @@ export const useUnassignLinodesFromPlacementGroup = (
>({
mutationFn: (data) =>
unassignLinodesFromPlacementGroup(placementGroupId, data),
onSuccess: (updatedPlacementGroup) => {
onSuccess: (updatedPlacementGroup, data) => {
// Invalidate paginated placement groups
queryClient.invalidateQueries([queryKey, 'paginated']);

Expand All @@ -160,6 +169,14 @@ export const useUnassignLinodesFromPlacementGroup = (
placementGroupId,
]);

// Invalidate linode placement group data
queryClient.invalidateQueries([
LINODES_QUERY_KEY,
'linode',
data.linodes[0],
'placement_groups',
]);

// Set the updated placement group
queryClient.setQueryData(
[queryKey, 'placement-group', placementGroupId],
Expand Down

0 comments on commit cde4ef9

Please sign in to comment.