@@ -12,6 +12,7 @@ import type {
1212 Dataset ,
1313 DatasetAvatarRelation ,
1414 DatasetField ,
15+ DatasetOptions ,
1516 DatasetSource ,
1617 DatasetSourceAvatar ,
1718 WorkbookId ,
@@ -491,13 +492,16 @@ export function deleteConnection({
491492 } ,
492493 } = getState ( ) ;
493494
495+ getSdk ( ) . cancelRequest ( 'getSourceListingOptions' ) ;
496+ getSdk ( ) . cancelRequest ( 'getDbNames' ) ;
494497 getSdk ( ) . cancelRequest ( 'getSources' ) ;
495498
496499 if (
497500 ( sourceLoadingError && sourceLoadingError . connectionId === connectionId ) ||
498501 ! selectedConnections . length
499502 ) {
500503 dispatch ( setSourcesLoadingError ( null ) ) ;
504+ dispatch ( setSourcesListingOptionsError ( null ) ) ;
501505 }
502506 } ;
503507}
@@ -804,6 +808,16 @@ export function toggleSourcesLoader(isSourcesLoading: boolean) {
804808 } ) ;
805809 } ;
806810}
811+
812+ export function toggleSourcesListingOptionsLoader ( isLoading : boolean ) {
813+ return ( dispatch : DatasetDispatch ) => {
814+ dispatch ( {
815+ type : DATASET_ACTION_TYPES . TOGGLE_SOURCES_LISTING_OPTIONS_LOADER ,
816+ payload : { isLoading} ,
817+ } ) ;
818+ } ;
819+ }
820+
807821export function setSourcesLoadingError ( error : DatasetError ) {
808822 return ( dispatch : DatasetDispatch ) => {
809823 dispatch ( {
@@ -813,6 +827,15 @@ export function setSourcesLoadingError(error: DatasetError) {
813827 } ;
814828}
815829
830+ export function setSourcesListingOptionsError ( error : DatasetError ) {
831+ return ( dispatch : DatasetDispatch ) => {
832+ dispatch ( {
833+ type : DATASET_ACTION_TYPES . SET_SOURCES_LISTING_OPTIONS_ERROR ,
834+ payload : { error} ,
835+ } ) ;
836+ } ;
837+ }
838+
816839export function setDatasetRevisionMismatch ( ) {
817840 return ( dispatch : DatasetDispatch ) => {
818841 dispatch ( { type : DATASET_ACTION_TYPES . SET_DATASET_REVISION_MISMATCH } ) ;
@@ -1375,10 +1398,19 @@ export function getSources({
13751398 isSideEffect = false ,
13761399} : GetSourcesProps ) {
13771400 return async ( dispatch : DatasetDispatch , getState : GetState ) => {
1401+ const {
1402+ sourcesPagination,
1403+ errors : { sourceListingOptionsError} ,
1404+ } = getState ( ) . dataset ;
1405+
1406+ if ( sourceListingOptionsError ) {
1407+ dispatch ( setSourcesLoadingError ( sourceListingOptionsError ) ) ;
1408+ dispatch ( setSourcesListingOptionsError ( null ) ) ;
1409+ return [ ] ;
1410+ }
13781411 if ( ! isSideEffect ) {
13791412 dispatch ( toggleSourcesLoader ( true ) ) ;
13801413 }
1381- const { sourcesPagination} = getState ( ) . dataset ;
13821414 let sources : GetSourceResponse [ 'sources' ] = [ ] ;
13831415 const currentLimit = limit ? limit + 1 : 10000 ;
13841416 try {
@@ -1447,27 +1479,28 @@ export function getSources({
14471479
14481480export function getDbNames ( connectionIds : string [ ] ) {
14491481 return async ( dispatch : DatasetDispatch , getState : GetState ) => {
1450- dispatch ( toggleSourcesLoader ( true ) ) ;
1482+ dispatch ( toggleSourcesListingOptionsLoader ( true ) ) ;
14511483 try {
14521484 if ( connectionIds . length ) {
14531485 const state = getState ( ) ;
14541486 const {
14551487 options : { source_listing} ,
14561488 } = state . dataset ;
14571489 const currentEntryId = selectedConnectionSelector ( state ) ?. entryId ;
1458- const result = await Promise . allSettled (
1490+ const result = await Promise . all (
14591491 connectionIds . map ( ( id ) =>
14601492 getSdk ( )
1461- . sdk . bi . getDbNames ( { connectionId : id } )
1493+ . sdk . bi . getDbNames (
1494+ { connectionId : id } ,
1495+ { concurrentId : 'getDbNames' , retries : 2 } ,
1496+ )
14621497 . then ( ( res ) => ( { id, ...res } ) ) ,
14631498 ) ,
14641499 ) ;
1465- const existingDbNames = result
1466- . filter ( ( item ) => item . status === 'fulfilled' )
1467- . reduce < Record < string , string [ ] > > ( ( acc , item ) => {
1468- acc [ item . value . id ] = item . value . db_names ;
1469- return acc ;
1470- } , { } ) ;
1500+ const existingDbNames = result . reduce < Record < string , string [ ] > > ( ( acc , item ) => {
1501+ acc [ item . id ] = item . db_names ;
1502+ return acc ;
1503+ } , { } ) ;
14711504
14721505 batch ( ( ) => {
14731506 dispatch ( {
@@ -1481,8 +1514,9 @@ export function getDbNames(connectionIds: string[]) {
14811514 }
14821515 } catch ( e ) {
14831516 logger . logError ( 'dataset: getDbNames failed' , e ) ;
1517+ dispatch ( setSourcesListingOptionsError ( e ) ) ;
14841518 } finally {
1485- dispatch ( toggleSourcesLoader ( false ) ) ;
1519+ dispatch ( toggleSourcesListingOptionsLoader ( false ) ) ;
14861520 }
14871521 } ;
14881522}
@@ -1806,6 +1840,7 @@ export function initializeDataset({connectionId}: {connectionId: string}) {
18061840 return async ( dispatch : DatasetDispatch ) => {
18071841 if ( connectionId ) {
18081842 await dispatch ( setInitialSources ( [ connectionId ] ) ) ;
1843+ await dispatch ( getSourcesListingOptions ( connectionId ) ) ;
18091844 }
18101845
18111846 dispatch ( _getSources ( ) ) ;
@@ -1963,29 +1998,39 @@ function _getSources() {
19631998
19641999export function getSourcesListingOptions ( connectionId : string ) {
19652000 return async ( dispatch : DatasetDispatch , getState : GetState ) => {
1966- dispatch ( toggleSourcesLoader ( true ) ) ;
1967-
1968- const result = await ( DatasetUtils . isEnabledFeature ( Feature . EnableDatasetSourcesPagination )
1969- ? getSdk ( ) . sdk . bi . getSourceListingOptions ( { connectionId} )
1970- : undefined ) ;
1971-
1972- dispatch ( {
1973- type : DATASET_ACTION_TYPES . SET_SOURCES_LISTING_OPTIONS ,
1974- payload : result ?. source_listing ,
1975- } ) ;
2001+ dispatch ( toggleSourcesListingOptionsLoader ( true ) ) ;
2002+ let sourceListing : DatasetOptions [ 'source_listing' ] | undefined ;
2003+ try {
2004+ const result = await ( DatasetUtils . isEnabledFeature (
2005+ Feature . EnableDatasetSourcesPagination ,
2006+ )
2007+ ? getSdk ( ) . sdk . bi . getSourceListingOptions (
2008+ { connectionId} ,
2009+ { concurrentId : 'getSourceListingOptions' , retries : 2 } ,
2010+ )
2011+ : undefined ) ;
2012+ sourceListing = result ?. source_listing ;
19762013
1977- const { dbNameRequiredForSearch, supportsDbNameListing} = getSourceListingValues (
1978- result ?. source_listing ,
1979- ) ;
2014+ dispatch ( {
2015+ type : DATASET_ACTION_TYPES . SET_SOURCES_LISTING_OPTIONS ,
2016+ payload : sourceListing ,
2017+ } ) ;
19802018
1981- dispatch ( toggleSourcesLoader ( false ) ) ;
2019+ const { dbNameRequiredForSearch, supportsDbNameListing} =
2020+ getSourceListingValues ( sourceListing ) ;
19822021
1983- if ( dbNameRequiredForSearch || supportsDbNameListing ) {
1984- await dispatch ( getDbNames ( [ connectionId ] ) ) ;
2022+ if ( dbNameRequiredForSearch || supportsDbNameListing ) {
2023+ await dispatch ( getDbNames ( [ connectionId ] ) ) ;
2024+ }
2025+ } catch ( error ) {
2026+ logger . logError ( 'dataset: getSourcesListingOptions failed' , error ) ;
2027+ dispatch ( setSourcesListingOptionsError ( error ) ) ;
2028+ } finally {
2029+ dispatch ( toggleSourcesListingOptionsLoader ( false ) ) ;
19852030 }
19862031
19872032 const currentDbName = getState ( ) . dataset . currentDbName ;
19882033
1989- return { sourceListing : result ?. source_listing , currentDbName} ;
2034+ return { sourceListing, currentDbName} ;
19902035 } ;
19912036}
0 commit comments