@@ -131,14 +131,6 @@ export const xblockQueryKeys = {
131131 componentDownstreamLinks : ( usageKey : string ) => [ ...xblockQueryKeys . xblock ( usageKey ) , 'downstreamLinks' ] ,
132132} ;
133133
134- export const containerQueryKeys = {
135- all : [ 'container' , 'children' ] ,
136- /**
137- * Base key for data specific to a container
138- */
139- container : ( containerId ?: string ) => [ ...containerQueryKeys . all , containerId ] ,
140- } ;
141-
142134/**
143135 * Tell react-query to refresh its cache of any data related to the given
144136 * component (XBlock).
@@ -609,13 +601,14 @@ export const useCreateLibraryContainer = (libraryId: string) => {
609601/**
610602 * Get the metadata for a container in a library
611603 */
612- export const useContainer = ( containerId ?: string ) => (
613- useQuery ( {
604+ export const useContainer = ( containerId ?: string ) => {
605+ const libraryId = getLibraryId ( containerId ) ;
606+ return useQuery ( {
614607 enabled : ! ! containerId ,
615- queryKey : containerQueryKeys . container ( containerId ) ,
608+ queryKey : libraryAuthoringQueryKeys . container ( libraryId , containerId ! ) ,
616609 queryFn : ( ) => getContainerMetadata ( containerId ! ) ,
617- } )
618- ) ;
610+ } ) ;
611+ } ;
619612
620613/**
621614 * Use this mutation to update the fields of a container in a library
@@ -629,7 +622,7 @@ export const useUpdateContainer = (containerId: string) => {
629622 // NOTE: We invalidate the library query here because we need to update the library's
630623 // container list.
631624 queryClient . invalidateQueries ( { predicate : ( query ) => libraryQueryPredicate ( query , libraryId ) } ) ;
632- queryClient . invalidateQueries ( { queryKey : libraryAuthoringQueryKeys . containerChildren ( libraryId , containerId ) } ) ;
625+ queryClient . invalidateQueries ( { queryKey : libraryAuthoringQueryKeys . container ( libraryId , containerId ) } ) ;
633626 } ,
634627 } ) ;
635628} ;
@@ -666,19 +659,19 @@ export const useRestoreContainer = (containerId: string) => {
666659/**
667660 * Get the metadata and children for a container in a library
668661 */
669- export const useContainerChildren = ( containerId : string ) => {
670- const libraryId = getLibraryId ( containerId ) ;
662+ export const useContainerChildren = ( containerId ? : string ) => {
663+ const libraryId = containerId ? getLibraryId ( containerId ) : undefined ;
671664 return useQuery ( {
672665 enabled : ! ! containerId ,
673666 queryKey : libraryAuthoringQueryKeys . containerChildren ( libraryId , containerId ) ,
674667 queryFn : ( ) => getLibraryContainerChildren ( containerId ! ) ,
675668 } ) ;
676- ) ;
669+ } ;
677670
678671/**
679672 * Use this mutation to add components to a container
680673 */
681- export const useAddComponentsToContainer = ( libraryId ? : string , containerId ?: string ) => {
674+ export const useAddComponentsToContainer = ( libraryId : string , containerId ?: string ) => {
682675 const queryClient = useQueryClient ( ) ;
683676 return useMutation ( {
684677 mutationFn : async ( componentIds : string [ ] ) => {
@@ -688,7 +681,7 @@ export const useAddComponentsToContainer = (libraryId?: string, containerId?: st
688681 return undefined ;
689682 } ,
690683 onSettled : ( ) => {
691- queryClient . invalidateQueries ( { queryKey : libraryAuthoringQueryKeys . containerChildren ( libraryId , containerId ) } ) ;
684+ queryClient . invalidateQueries ( { queryKey : libraryAuthoringQueryKeys . containerChildren ( libraryId , containerId ! ) } ) ;
692685 } ,
693686 } ) ;
694687} ;
@@ -702,7 +695,7 @@ export const useUpdateContainerCollections = (containerId: string) => {
702695 return useMutation ( {
703696 mutationFn : async ( collectionKeys : string [ ] ) => updateContainerCollections ( containerId , collectionKeys ) ,
704697 onSettled : ( ) => {
705- queryClient . invalidateQueries ( { queryKey : libraryAuthoringQueryKeys . container ( containerId ) } ) ;
698+ queryClient . invalidateQueries ( { queryKey : libraryAuthoringQueryKeys . container ( libraryId , containerId ) } ) ;
706699 queryClient . invalidateQueries ( { predicate : ( query ) => libraryQueryPredicate ( query , libraryId ) } ) ;
707700 } ,
708701 } ) ;
0 commit comments