Skip to content

Commit

Permalink
fix: invalidate some queries
Browse files Browse the repository at this point in the history
  • Loading branch information
niekcandaele committed May 28, 2024
1 parent e779ae6 commit 3315c94
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions packages/web-main/src/queries/modules/queries.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ export const useModuleRemove = () => {
onSuccess: async (removedModule: IdUuidDTO) => {
await queryClient.invalidateQueries({ queryKey: moduleKeys.list() });
await queryClient.invalidateQueries({ queryKey: moduleKeys.detail(removedModule.id) });
await queryClient.invalidateQueries({ queryKey: moduleKeys.export(removedModule.id) });
},
}),
{}
Expand Down Expand Up @@ -166,6 +167,7 @@ export const useModuleUpdate = () => {
(await apiClient.module.moduleControllerUpdate(id, moduleUpdate)).data.data,
onSuccess: async (updatedModule: ModuleOutputDTO) => {
await queryClient.invalidateQueries({ queryKey: moduleKeys.list() });
await queryClient.invalidateQueries({ queryKey: moduleKeys.export(updatedModule.id) });
return queryClient.setQueryData(moduleKeys.detail(updatedModule.id), updatedModule);
},
}),
Expand All @@ -191,6 +193,7 @@ export const useHookCreate = () => {
mutationFn: async (hook) => (await apiClient.hook.hookControllerCreate(hook)).data.data,
onSuccess: async (newHook: HookOutputDTO) => {
await queryClient.invalidateQueries({ queryKey: moduleKeys.hooks.list() });
await queryClient.invalidateQueries({ queryKey: moduleKeys.export(newHook.moduleId) });
queryClient.setQueryData<ModuleOutputDTO>(moduleKeys.detail(newHook.moduleId), (prev) => {
if (!prev) {
// we are updating a module that does not have a cache entry
Expand Down Expand Up @@ -221,6 +224,7 @@ export const useHookRemove = ({ moduleId }) => {
mutationFn: async ({ hookId }) => (await apiClient.hook.hookControllerRemove(hookId)).data.data,
onSuccess: async (removedHook: IdUuidDTO) => {
await queryClient.invalidateQueries({ queryKey: moduleKeys.hooks.list() });
await queryClient.invalidateQueries({ queryKey: moduleKeys.export(moduleId) });
queryClient.setQueryData<ModuleOutputDTO>(moduleKeys.detail(moduleId), (prev) => {
if (!prev) {
return prev;
Expand Down Expand Up @@ -250,6 +254,7 @@ export const useHookUpdate = () => {
mutationFn: async ({ hookId, hook }) => (await apiClient.hook.hookControllerUpdate(hookId, hook)).data.data,
onSuccess: async (updatedHook: HookOutputDTO) => {
await queryClient.invalidateQueries({ queryKey: moduleKeys.hooks.list() });
await queryClient.invalidateQueries({ queryKey: moduleKeys.export(updatedHook.moduleId) });
queryClient.setQueryData<ModuleOutputDTO>(moduleKeys.detail(updatedHook.moduleId), (prev) => {
if (!prev) {
return prev;
Expand Down Expand Up @@ -285,6 +290,7 @@ export const useCommandCreate = () => {
mutationFn: async (command) => (await apiClient.command.commandControllerCreate(command)).data.data,
onSuccess: async (newCommand: CommandOutputDTO) => {
await queryClient.invalidateQueries({ queryKey: moduleKeys.commands.list() });
await queryClient.invalidateQueries({ queryKey: moduleKeys.export(newCommand.moduleId) });
queryClient.setQueryData<ModuleOutputDTO>(moduleKeys.detail(newCommand.moduleId), (prev) => {
if (!prev) {
return prev;
Expand Down Expand Up @@ -315,6 +321,7 @@ export const useCommandUpdate = () => {
(await apiClient.command.commandControllerUpdate(commandId, command)).data.data,
onSuccess: async (updatedCommand: CommandOutputDTO) => {
await queryClient.invalidateQueries({ queryKey: moduleKeys.commands.list() });
await queryClient.invalidateQueries({ queryKey: moduleKeys.export(updatedCommand.moduleId) });
queryClient.setQueryData<ModuleOutputDTO>(moduleKeys.detail(updatedCommand.id), (prev) => {
if (!prev) {
return prev;
Expand Down Expand Up @@ -348,6 +355,7 @@ export const useCommandRemove = ({ moduleId }) => {
onSuccess: async (removedCommand: IdUuidDTO) => {
// invalidate list of commands
await queryClient.invalidateQueries({ queryKey: moduleKeys.commands.list() });
await queryClient.invalidateQueries({ queryKey: moduleKeys.export(moduleId) });
queryClient.setQueryData<ModuleOutputDTO>(moduleKeys.detail(moduleId), (prev) => {
if (!prev) {
return prev;
Expand Down Expand Up @@ -384,6 +392,7 @@ export const useCronJobCreate = () => {
onSuccess: async (newCronJob: CronJobOutputDTO) => {
// invalidate list of cronjobs
await queryClient.invalidateQueries({ queryKey: moduleKeys.cronJobs.list() });
await queryClient.invalidateQueries({ queryKey: moduleKeys.export(newCronJob.moduleId) });
queryClient.setQueryData<ModuleOutputDTO>(moduleKeys.detail(newCronJob.moduleId), (prev) => {
if (!prev) {
return prev;
Expand Down Expand Up @@ -416,6 +425,7 @@ export const useCronJobUpdate = () => {
onSuccess: async (updatedCronJob: CronJobOutputDTO) => {
// invalidate list of cronjob
await queryClient.invalidateQueries({ queryKey: moduleKeys.cronJobs.list() });
await queryClient.invalidateQueries({ queryKey: moduleKeys.export(updatedCronJob.moduleId) });
queryClient.setQueryData<ModuleOutputDTO>(moduleKeys.detail(updatedCronJob.moduleId), (prev) => {
if (!prev) {
return prev;
Expand Down Expand Up @@ -449,6 +459,7 @@ export const useCronJobRemove = ({ moduleId }: { moduleId: string }) => {
(await apiClient.cronjob.cronJobControllerRemove(cronJobId)).data.data,
onSuccess: async (removedCronJob: IdUuidDTO) => {
await queryClient.invalidateQueries({ queryKey: moduleKeys.cronJobs.list() });
await queryClient.invalidateQueries({ queryKey: moduleKeys.export(moduleId) });

queryClient.setQueryData<ModuleOutputDTO>(moduleKeys.detail(moduleId), (prev) => {
if (!prev) {
Expand Down

0 comments on commit 3315c94

Please sign in to comment.