@@ -51,6 +51,7 @@ export class ResultSetUtils {
51
51
this . historyQuerySource = null ;
52
52
this . hasQueryCommitted = false ;
53
53
this . queryToolCtx = queryToolCtx ;
54
+ this . setLoaderText = null ;
54
55
}
55
56
56
57
static generateURLReconnectionFlag ( baseUrl , transId , shouldReconnect ) {
@@ -445,23 +446,72 @@ export class ResultSetUtils {
445
446
) ;
446
447
}
447
448
448
- saveData ( reqData ) {
449
+ saveData ( reqData , shouldReconnect ) {
450
+ // Generate the URL with the optional `connect=1` parameter.
451
+ const url = ResultSetUtils . generateURLReconnectionFlag ( 'sqleditor.save' , this . transId , shouldReconnect ) ;
452
+
449
453
return this . api . post (
450
- url_for ( 'sqleditor.save' , {
451
- 'trans_id' : this . transId
452
- } ) ,
454
+ url ,
453
455
JSON . stringify ( reqData )
454
- ) . then ( response => {
456
+ ) . then ( ( response ) => {
455
457
if ( response . data ?. data ?. status ) {
456
458
// Set the commit flag to true if the save was successful
457
459
this . hasQueryCommitted = true ;
458
460
}
459
461
return response ;
460
- } ) . catch ( ( error ) => {
461
- // Set the commit flag to false if there was an error
462
- this . hasQueryCommitted = false ;
463
- throw error ;
464
- } ) ;
462
+ } )
463
+ . catch ( async ( error ) => {
464
+ if ( error . response ?. status === 428 ) {
465
+ // Handle 428: Show password dialog.
466
+ return new Promise ( ( resolve , reject ) => {
467
+ this . connectServerModal (
468
+ error . response ?. data ?. result ,
469
+ async ( formData ) => {
470
+ try {
471
+ await this . connectServer (
472
+ this . queryToolCtx . params . sid ,
473
+ this . queryToolCtx . params . user ,
474
+ formData ,
475
+ async ( ) => {
476
+ let retryRespData = await this . saveData ( reqData ) ;
477
+ // Set the commit flag to true if the save was successful
478
+ this . hasQueryCommitted = true ;
479
+ pgAdmin . Browser . notifier . success ( gettext ( 'Server Connected.' ) ) ;
480
+ resolve ( retryRespData ) ;
481
+ }
482
+ ) ;
483
+
484
+ } catch ( retryError ) {
485
+ reject ( retryError ) ;
486
+ }
487
+ } ,
488
+ ( ) => this . setLoaderText ( null )
489
+ ) ;
490
+ } ) ;
491
+ } else if ( error . response ?. status === 503 ) {
492
+ // Handle 503: Fire HANDLE_API_ERROR and wait for connectionLostCallback.
493
+ return new Promise ( ( resolve , reject ) => {
494
+ this . eventBus . fireEvent ( QUERY_TOOL_EVENTS . HANDLE_API_ERROR , error , {
495
+ connectionLostCallback : async ( ) => {
496
+ try {
497
+ // Retry saveData with connect=1
498
+ let retryRespData = await this . saveData ( reqData , true ) ;
499
+ resolve ( retryRespData ) ;
500
+ } catch ( retryError ) {
501
+ reject ( retryError ) ;
502
+ }
503
+ } ,
504
+ checkTransaction : true ,
505
+ cancelCallback : ( ) => this . setLoaderText ( null )
506
+ } ,
507
+ ) ;
508
+ } ) ;
509
+ } else {
510
+ // Set the commit flag to false if there was an error
511
+ this . hasQueryCommitted = false ;
512
+ throw error ;
513
+ }
514
+ } ) ;
465
515
}
466
516
467
517
async saveResultsToFile ( fileName ) {
@@ -861,6 +911,8 @@ export function ResultSet() {
861
911
862
912
rsu . current . setEventBus ( eventBus ) ;
863
913
rsu . current . setQtPref ( queryToolCtx . preferences ?. sqleditor ) ;
914
+ // To use setLoaderText to the ResultSetUtils.
915
+ rsu . current . setLoaderText = setLoaderText ;
864
916
865
917
const isDataChanged = ( ) => {
866
918
return Boolean ( _ . size ( dataChangeStore . updated ) || _ . size ( dataChangeStore . added ) || _ . size ( dataChangeStore . deleted ) ) ;
0 commit comments