File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -88,6 +88,12 @@ const UnitInfo = () => {
8888 ) ? sidebarTab : defaultTab . unit ;
8989
9090 const unitId = sidebarComponentInfo ?. id ;
91+
92+ // istanbul ignore if: this should never happen
93+ if ( ! unitId ) {
94+ throw new Error ( 'unitId is required' ) ;
95+ }
96+
9197 const { data : container } = useContainer ( unitId ) ;
9298
9399 const handleOpenUnit = useCallback ( ( ) => {
Original file line number Diff line number Diff line change @@ -609,13 +609,14 @@ export const useCreateLibraryContainer = (libraryId: string) => {
609609/**
610610 * Get the metadata for a container in a library
611611 */
612- export const useContainer = ( containerId ?: string ) => (
613- useQuery ( {
612+ export const useContainer = ( containerId : string ) => {
613+ const libraryId = getLibraryId ( containerId ) ;
614+ return useQuery ( {
614615 enabled : ! ! containerId ,
615- queryKey : containerQueryKeys . container ( containerId ) ,
616+ queryKey : libraryAuthoringQueryKeys . container ( libraryId , containerId ) ,
616617 queryFn : ( ) => getContainerMetadata ( containerId ! ) ,
617- } )
618- ) ;
618+ } ) ;
619+ } ;
619620
620621/**
621622 * Use this mutation to update the fields of a container in a library
@@ -673,7 +674,7 @@ export const useContainerChildren = (containerId: string) => {
673674 queryKey : libraryAuthoringQueryKeys . containerChildren ( libraryId , containerId ) ,
674675 queryFn : ( ) => getLibraryContainerChildren ( containerId ! ) ,
675676 } ) ;
676- ) ;
677+ } ;
677678
678679/**
679680 * Use this mutation to add components to a container
Original file line number Diff line number Diff line change @@ -18,7 +18,7 @@ import TagCount from '../../generic/tag-count';
1818import { useLibraryContext } from '../common/context/LibraryContext' ;
1919import ComponentMenu from '../components' ;
2020import { LibraryBlockMetadata } from '../data/api' ;
21- import { containerQueryKeys , useContainerChildren } from '../data/apiHooks' ;
21+ import { libraryAuthoringQueryKeys , useContainerChildren } from '../data/apiHooks' ;
2222import { LibraryBlock } from '../LibraryBlock' ;
2323import { useLibraryRoutes } from '../routes' ;
2424import messages from './messages' ;
@@ -31,6 +31,7 @@ export const LibraryUnitBlocks = () => {
3131 const { navigateTo } = useLibraryRoutes ( ) ;
3232
3333 const {
34+ libraryId,
3435 unitId,
3536 showOnlyPublished,
3637 componentId,
@@ -55,7 +56,6 @@ export const LibraryUnitBlocks = () => {
5556 error,
5657 } = useContainerChildren ( unitId ) ;
5758
58-
5959 useEffect ( ( ) => setOrderedBlocks ( blocks || [ ] ) , [ blocks ] ) ;
6060
6161 if ( isLoading ) {
@@ -75,7 +75,7 @@ export const LibraryUnitBlocks = () => {
7575 } ;
7676
7777 const onTagSidebarClose = ( ) => {
78- queryClient . invalidateQueries ( containerQueryKeys . children ( unitId ) ) ;
78+ queryClient . invalidateQueries ( libraryAuthoringQueryKeys . containerChildren ( libraryId , unitId ) ) ;
7979 closeManageTagsDrawer ( ) ;
8080 } ;
8181
You can’t perform that action at this time.
0 commit comments