@@ -91,7 +91,11 @@ export const xblockQueryKeys = {
9191 componentMetadata : ( usageKey : string ) => [ ...xblockQueryKeys . xblock ( usageKey ) , 'componentMetadata' ] ,
9292 componentDownstreamLinks : ( usageKey : string ) => [ ...xblockQueryKeys . xblock ( usageKey ) , 'downstreamLinks' ] ,
9393
94- /** Predicate used to invalidate all metadata only */
94+ /**
95+ * Predicate used to invalidate all metadata only (not OLX, fields, assets, etc.).
96+ * Affects all libraries; we could do a more complex version that affects only one library, but it would require
97+ * introspecting the usage keys.
98+ */
9599 allComponentMetadata : ( query : Query ) => query . queryKey [ 0 ] === 'xblock' && query . queryKey [ 2 ] === 'componentMetadata' ,
96100} ;
97101
@@ -208,23 +212,32 @@ export const useContentLibraryV2List = (customParams: api.GetLibrariesV2CustomPa
208212 } )
209213) ;
210214
215+ /** Publish all changes in the library. */
211216export const useCommitLibraryChanges = ( ) => {
212217 const queryClient = useQueryClient ( ) ;
213218 return useMutation ( {
214219 mutationFn : api . commitLibraryChanges ,
215220 onSettled : ( _data , _error , libraryId ) => {
221+ // Invalidate all content-related metadata and search results for the whole library.
216222 queryClient . invalidateQueries ( { queryKey : libraryAuthoringQueryKeys . contentLibrary ( libraryId ) } ) ;
223+ queryClient . invalidateQueries ( { predicate : ( query ) => libraryQueryPredicate ( query , libraryId ) } ) ;
224+ // For XBlocks, the only thing we need to invalidate is the metadata which includes "has unpublished changes"
225+ queryClient . invalidateQueries ( { predicate : xblockQueryKeys . allComponentMetadata } ) ;
217226 } ,
218227 } ) ;
219228} ;
220229
230+ /** Discard all un-published changes in the library */
221231export const useRevertLibraryChanges = ( ) => {
222232 const queryClient = useQueryClient ( ) ;
223233 return useMutation ( {
224234 mutationFn : api . revertLibraryChanges ,
225235 onSettled : ( _data , _error , libraryId ) => {
236+ // Invalidate all content-related metadata and search results for the whole library.
226237 queryClient . invalidateQueries ( { queryKey : libraryAuthoringQueryKeys . contentLibrary ( libraryId ) } ) ;
227238 queryClient . invalidateQueries ( { predicate : ( query ) => libraryQueryPredicate ( query , libraryId ) } ) ;
239+ // For XBlocks, the only thing we need to invalidate is the metadata which includes "has unpublished changes"
240+ queryClient . invalidateQueries ( { predicate : xblockQueryKeys . allComponentMetadata } ) ;
228241 } ,
229242 } ) ;
230243} ;
0 commit comments