@@ -58,13 +58,16 @@ const shouldIncludeCollection = ({
5858 collectionSlugs,
5959} ) => ( enableRichTextRelationship && ( ( uploads && Boolean ( upload ) ) || collectionSlugs ?. includes ( slug ) ) ) ;
6060
61- export const ListDrawerContent : React . FC < ListDrawerProps > = ( {
61+ const DrawerContent : React . FC < ListDrawerProps & {
62+ enabledCollectionConfigs : SanitizedCollectionConfig [ ]
63+ } > = ( {
6264 drawerSlug,
6365 onSelect,
6466 customHeader,
6567 collectionSlugs,
6668 uploads,
6769 selectedCollection,
70+ enabledCollectionConfigs
6871} ) => {
6972 const { t, i18n } = useTranslation ( [ 'upload' , 'general' ] ) ;
7073 const { permissions } = useAuth ( ) ;
@@ -75,7 +78,7 @@ export const ListDrawerContent: React.FC<ListDrawerProps> = ({
7578 const [ page , setPage ] = useState ( 1 ) ;
7679 const [ where , setWhere ] = useState ( null ) ;
7780 const { serverURL, routes : { api } , collections } = useConfig ( ) ;
78- const [ enabledCollectionConfigs ] = useState ( ( ) => collections . filter ( ( coll ) => shouldIncludeCollection ( { coll , uploads , collectionSlugs } ) ) ) ;
81+
7982 const [ selectedCollectionConfig , setSelectedCollectionConfig ] = useState < SanitizedCollectionConfig > ( ( ) => {
8083 let initialSelection : SanitizedCollectionConfig ;
8184 if ( selectedCollection ) {
@@ -92,7 +95,9 @@ export const ListDrawerContent: React.FC<ListDrawerProps> = ({
9295 } ) ;
9396
9497 const [ selectedOption , setSelectedOption ] = useState < { label : string , value : string } > ( ( ) => ( selectedCollectionConfig ? { label : getTranslation ( selectedCollectionConfig . labels . singular , i18n ) , value : selectedCollectionConfig . slug } : undefined ) ) ;
98+
9599 const [ fields , setFields ] = useState < Field [ ] > ( ( ) => formatFields ( selectedCollectionConfig , t ) ) ;
100+
96101 const [ tableColumns , setTableColumns ] = useState < Column [ ] > ( ( ) => {
97102 const initialColumns = getInitialColumnState ( fields , selectedCollectionConfig . admin . useAsTitle , selectedCollectionConfig . admin . defaultColumns ) ;
98103 return buildColumns ( {
@@ -308,3 +313,25 @@ export const ListDrawerContent: React.FC<ListDrawerProps> = ({
308313 </ Fragment >
309314 ) ;
310315} ;
316+
317+ export const ListDrawerContent : React . FC < ListDrawerProps > = ( props ) => {
318+ const {
319+ collectionSlugs,
320+ uploads,
321+ } = props ;
322+
323+ const { collections } = useConfig ( ) ;
324+
325+ const [ enabledCollectionConfigs ] = useState ( ( ) => collections . filter ( ( coll ) => shouldIncludeCollection ( { coll, uploads, collectionSlugs } ) ) ) ;
326+
327+ if ( enabledCollectionConfigs . length === 0 ) {
328+ return null ;
329+ }
330+
331+ return (
332+ < DrawerContent
333+ { ...props }
334+ enabledCollectionConfigs = { enabledCollectionConfigs }
335+ />
336+ )
337+ }
0 commit comments