fix: invalidate search results when publishing all changes in library (#1925) (#1927)

(cherry picked from commit cdb8016657)

Co-authored-by: Braden MacDonald <braden@opencraft.com>
This commit is contained in:
Jillian
2025-05-10 01:33:58 +09:30
committed by GitHub
parent 79f865b328
commit 6c4634ebbe

View File

@@ -91,7 +91,11 @@ export const xblockQueryKeys = {
componentMetadata: (usageKey: string) => [...xblockQueryKeys.xblock(usageKey), 'componentMetadata'],
componentDownstreamLinks: (usageKey: string) => [...xblockQueryKeys.xblock(usageKey), 'downstreamLinks'],
/** Predicate used to invalidate all metadata only */
/**
* Predicate used to invalidate all metadata only (not OLX, fields, assets, etc.).
* Affects all libraries; we could do a more complex version that affects only one library, but it would require
* introspecting the usage keys.
*/
allComponentMetadata: (query: Query) => query.queryKey[0] === 'xblock' && query.queryKey[2] === 'componentMetadata',
};
@@ -208,23 +212,32 @@ export const useContentLibraryV2List = (customParams: api.GetLibrariesV2CustomPa
})
);
/** Publish all changes in the library. */
export const useCommitLibraryChanges = () => {
const queryClient = useQueryClient();
return useMutation({
mutationFn: api.commitLibraryChanges,
onSettled: (_data, _error, libraryId) => {
// Invalidate all content-related metadata and search results for the whole library.
queryClient.invalidateQueries({ queryKey: libraryAuthoringQueryKeys.contentLibrary(libraryId) });
queryClient.invalidateQueries({ predicate: (query) => libraryQueryPredicate(query, libraryId) });
// For XBlocks, the only thing we need to invalidate is the metadata which includes "has unpublished changes"
queryClient.invalidateQueries({ predicate: xblockQueryKeys.allComponentMetadata });
},
});
};
/** Discard all un-published changes in the library */
export const useRevertLibraryChanges = () => {
const queryClient = useQueryClient();
return useMutation({
mutationFn: api.revertLibraryChanges,
onSettled: (_data, _error, libraryId) => {
// Invalidate all content-related metadata and search results for the whole library.
queryClient.invalidateQueries({ queryKey: libraryAuthoringQueryKeys.contentLibrary(libraryId) });
queryClient.invalidateQueries({ predicate: (query) => libraryQueryPredicate(query, libraryId) });
// For XBlocks, the only thing we need to invalidate is the metadata which includes "has unpublished changes"
queryClient.invalidateQueries({ predicate: xblockQueryKeys.allComponentMetadata });
},
});
};