Skip to content

Commit

Permalink
add stackscript event handler
Browse files Browse the repository at this point in the history
  • Loading branch information
bnussman committed Apr 10, 2024
1 parent 94fa5f4 commit e4e71f6
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
5 changes: 5 additions & 0 deletions packages/manager/src/hooks/useEventHandlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { volumeEventsHandler } from 'src/queries/volumes';

import type { Event } from '@linode/api-v4';
import type { QueryClient } from '@tanstack/react-query';
import { stackScriptEventHandler } from 'src/queries/stackscripts';

export interface EventHandlerData {
event: Event;
Expand Down Expand Up @@ -76,6 +77,10 @@ export const eventHandlers: {
filter: (event) => event.action.startsWith('disk'),
handler: diskEventHandler,
},
{
filter: (event) => event.action.startsWith('stackscript'),
handler: stackScriptEventHandler,
},
];

export const useEventHandlers = () => {
Expand Down
16 changes: 16 additions & 0 deletions packages/manager/src/queries/stackscripts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { createQueryKeys } from '@lukemorales/query-key-factory';
import { useInfiniteQuery, useQuery } from '@tanstack/react-query';

import { getOneClickApps } from 'src/features/StackScripts/stackScriptUtils';
import { EventHandlerData } from 'src/hooks/useEventHandlers';
import { getAll } from 'src/utilities/getAll';

import { queryPresets } from './base';
Expand Down Expand Up @@ -66,3 +67,18 @@ export const useStackScriptsInfiniteQuery = (
return page + 1;
},
});

export const stackScriptEventHandler = ({
event,
queryClient,
}: EventHandlerData) => {
// Keep the infinite store up to date
queryClient.invalidateQueries(stackscriptQueries.infinite._def);

// If the event has a StackScript entity attached, invalidate it
if (event.entity?.id) {
queryClient.invalidateQueries(
stackscriptQueries.stackscript(event.entity.id).queryKey
);
}
};

0 comments on commit e4e71f6

Please sign in to comment.