Skip to content

Commit

Permalink
refactor: invalidate library related content queries
Browse files Browse the repository at this point in the history
  • Loading branch information
navinkarkera committed Aug 14, 2024
1 parent bb36424 commit 9a3fc04
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions src/library-authoring/data/apiHooks.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import { useQuery, useMutation, useQueryClient } from '@tanstack/react-query';
import {
useQuery, useMutation, useQueryClient, Query,
} from '@tanstack/react-query';

import {
type GetLibrariesV2CustomParams,
Expand Down Expand Up @@ -121,7 +123,17 @@ export const useRevertLibraryChanges = () => {
mutationFn: revertLibraryChanges,
onSettled: (_data, _error, libraryId) => {
queryClient.invalidateQueries({ queryKey: libraryAuthoringQueryKeys.contentLibrary(libraryId) });
queryClient.invalidateQueries({ queryKey: ['content_search'] });
queryClient.invalidateQueries({
// Invalidate all content queries related to this library
predicate: (query: Query): boolean => {

Check warning on line 128 in src/library-authoring/data/apiHooks.ts

View check run for this annotation

Codecov / codecov/patch

src/library-authoring/data/apiHooks.ts#L128

Added line #L128 was not covered by tests
// extraFilter contains library id
const extraFilter = query.queryKey[5];

Check warning on line 130 in src/library-authoring/data/apiHooks.ts

View check run for this annotation

Codecov / codecov/patch

src/library-authoring/data/apiHooks.ts#L130

Added line #L130 was not covered by tests
if (!(Array.isArray(extraFilter) || typeof extraFilter === 'string')) {
return false;

Check warning on line 132 in src/library-authoring/data/apiHooks.ts

View check run for this annotation

Codecov / codecov/patch

src/library-authoring/data/apiHooks.ts#L132

Added line #L132 was not covered by tests
}
return query.queryKey[0] === 'content_search' && extraFilter?.includes(`context_key = "${libraryId}"`);
},
});
},
});
};

0 comments on commit 9a3fc04

Please sign in to comment.