@@ -179,6 +179,14 @@ export class BlockEditWithFilters extends ComponentWithSettings {
179179 wordpressSourceType !== prevProps . attributes . wordpressSourceType ||
180180 wordpressSource !== prevProps . attributes . wordpressSource ;
181181 if ( sourceChanged ) {
182+ setAttributes ( {
183+ type : undefined ,
184+ taxonomy : 'none' ,
185+ categories : [ ] ,
186+ sortingTaxonomy : 'none' ,
187+ sortFirstBy : 'none' ,
188+ defaultValues : [ ] ,
189+ } ) ;
182190 this . getTypes ( ) ;
183191 this . getTaxonomies ( ) ;
184192 this . getTaxonomyValues ( ) ;
@@ -538,7 +546,10 @@ export class BlockEditWithAPIMetadata extends ComponentWithSettings {
538546 'Accept' : 'application/json' ,
539547 } ,
540548 } )
541- . then ( response => response . json ( ) )
549+ . then ( response => {
550+ if ( ! response . ok ) throw new Error ( `Eureka apps returned ${ response . status } ` ) ;
551+ return response . json ( ) ;
552+ } )
542553 . then ( data => {
543554 const apps = data . applications ? [ ...data . applications . application
544555 . filter ( a => a . instance [ 0 ] . metadata . type === 'data' )
@@ -570,8 +581,21 @@ export class BlockEditWithAPIMetadata extends ComponentWithSettings {
570581 }
571582 } ) ;
572583 } )
573- . catch ( ( ) => {
574- console . log ( "Error when loading apps" ) ;
584+ . catch ( ( error ) => {
585+ console . error ( "Error when loading apps, falling back to CSV" , error ) ;
586+ this . setState ( {
587+ react_ui_url : settingsData [ "react_ui_url" ] + '/' + window . _page_locale ,
588+ react_api_url : settingsData [ "react_api_url" ] ,
589+ apache_superset_url : settingsData [ "apache_superset_url" ] ,
590+ site_language : settingsData [ "site_language" ] ,
591+ current_language : new URLSearchParams ( document . location . search ) . get ( "edit_lang" ) ,
592+ apps : [ { label : 'CSV' , value : 'csv' } ]
593+ } , ( ) => {
594+ const { app, dvzProxyDatasetId } = this . props . attributes ;
595+ if ( app && app != 'none' ) {
596+ this . loadMetadata ( app , dvzProxyDatasetId ) ;
597+ }
598+ } ) ;
575599 } ) ;
576600 } ) ;
577601 }
0 commit comments