@@ -21,7 +21,7 @@ function createEmptyField() {
2121}
2222
2323// FUNCTION - FIELD ROW COMPONENT
24- function FieldRow ( { field, index, depth, collections, collectionsLoading, onChange, onRemove } ) {
24+ function FieldRow ( { field, index, depth, collections, collectionsLoading, collectionsError , onChange, onRemove } ) {
2525 const [ expanded , setExpanded ] = useState ( true ) ;
2626
2727 const handleChange = ( prop , value ) => {
@@ -283,12 +283,12 @@ function FieldRow({ field, index, depth, collections, collectionsLoading, onChan
283283 </ span >
284284 < select
285285 value = { field . ref || '' }
286- disabled = { collectionsLoading }
286+ disabled = { collectionsLoading || collectionsError }
287287 onChange = { ( e ) => handleChange ( 'ref' , e . target . value ) }
288288 className = "input-field"
289289 style = { { flex : 1 , fontSize : '0.85rem' , padding : '4px 8px' , background : 'rgba(0,0,0,0.2)' , border : '1px solid var(--color-border)' , borderRadius : '4px' } }
290290 >
291- < option value = "" > { collectionsLoading ? 'Loading collections…' : 'Select collection...' } </ option >
291+ < option value = "" > { collectionsLoading ? 'Loading collections…' : collectionsError ? 'Failed to load' : 'Select collection...' } </ option >
292292 { collections . map ( c => (
293293 < option key = { c . name } value = { c . name } > { c . name } </ option >
294294 ) ) }
@@ -322,6 +322,7 @@ function FieldRow({ field, index, depth, collections, collectionsLoading, onChan
322322 depth = { depth + 1 }
323323 collections = { collections }
324324 collectionsLoading = { collectionsLoading }
325+ collectionsError = { collectionsError }
325326 onChange = { handleSubFieldChange }
326327 onRemove = { removeSubField }
327328 />
@@ -373,6 +374,7 @@ function FieldRow({ field, index, depth, collections, collectionsLoading, onChan
373374 depth = { depth + 1 }
374375 collections = { collections }
375376 collectionsLoading = { collectionsLoading }
377+ collectionsError = { collectionsError }
376378 onChange = { handleItemSubFieldChange }
377379 onRemove = { removeItemSubField }
378380 />
@@ -387,12 +389,12 @@ function FieldRow({ field, index, depth, collections, collectionsLoading, onChan
387389 </ span >
388390 < select
389391 value = { field . items ?. ref || '' }
390- disabled = { collectionsLoading }
392+ disabled = { collectionsLoading || collectionsError }
391393 onChange = { ( e ) => handleItemsChange ( 'ref' , e . target . value ) }
392394 className = "input-field"
393395 style = { { flex : 1 , fontSize : '0.85rem' , padding : '4px 8px' , background : 'rgba(0,0,0,0.2)' , border : '1px solid var(--color-border)' , borderRadius : '4px' } }
394396 >
395- < option value = "" > { collectionsLoading ? 'Loading collections…' : 'Select collection...' } </ option >
397+ < option value = "" > { collectionsLoading ? 'Loading collections…' : collectionsError ? 'Failed to load' : 'Select collection...' } </ option >
396398 { collections . map ( c => (
397399 < option key = { c . name } value = { c . name } > { c . name } </ option >
398400 ) ) }
@@ -459,6 +461,7 @@ function CreateCollection() {
459461 const [ loading , setLoading ] = useState ( false ) ;
460462 const [ collections , setCollections ] = useState ( [ ] ) ;
461463 const [ collectionsLoading , setCollectionsLoading ] = useState ( true ) ;
464+ const [ collectionsError , setCollectionsError ] = useState ( null ) ;
462465
463466 // Fetch existing collections for Ref picker — runs immediately on mount
464467 // so it fires in parallel with any other in-flight requests.
@@ -468,11 +471,18 @@ function CreateCollection() {
468471 if ( isMounted ) {
469472 setCollectionsLoading ( true ) ;
470473 setCollections ( [ ] ) ;
474+ setCollectionsError ( null ) ;
471475 }
472476 try {
473477 const res = await api . get ( `/api/projects/${ projectId } ` ) ;
474478 if ( isMounted ) setCollections ( res . data . collections || [ ] ) ;
475- } catch { /* ignore */ } finally {
479+ } catch ( err ) {
480+ console . error ( 'Failed to fetch collections for Ref picker:' , err ) ;
481+ if ( isMounted ) {
482+ setCollectionsError ( 'Failed to load collections' ) ;
483+ toast . error ( 'Failed to load collections for references' ) ;
484+ }
485+ } finally {
476486 if ( isMounted ) setCollectionsLoading ( false ) ;
477487 }
478488 } ;
@@ -611,6 +621,7 @@ function CreateCollection() {
611621 depth = { 1 }
612622 collections = { collections }
613623 collectionsLoading = { collectionsLoading }
624+ collectionsError = { collectionsError }
614625 onChange = { handleFieldChange }
615626 onRemove = { removeField }
616627 />
0 commit comments