5
5
6
6
import * as vscode from 'vscode' ;
7
7
import { ReactWebViewPanelController } from "../controllers/reactWebviewController" ;
8
- import { ApiStatus , AuthenticationType , ConnectionDialogWebviewState , FormComponent , FormComponentActionButton , FormComponentOptions , FormComponentType , FormEvent , FormTabs , IConnectionDialogProfile } from '../sharedInterfaces/connectionDialog' ;
8
+ import { ApiStatus , AuthenticationType , ConnectionDialogReducers , ConnectionDialogWebviewState , FormComponent , FormComponentActionButton , FormComponentOptions , FormComponentType , FormTabs , IConnectionDialogProfile } from '../sharedInterfaces/connectionDialog' ;
9
9
import { IConnectionInfo } from 'vscode-mssql' ;
10
10
import MainController from '../controllers/mainController' ;
11
11
import { getConnectionDisplayName } from '../models/connectionInfo' ;
12
12
import { AzureController } from '../azure/azureController' ;
13
13
import { ObjectExplorerProvider } from '../objectExplorer/objectExplorerProvider' ;
14
14
15
- export class ConnectionDialogWebViewController extends ReactWebViewPanelController < ConnectionDialogWebviewState > {
15
+ export class ConnectionDialogWebViewController extends ReactWebViewPanelController < ConnectionDialogWebviewState , ConnectionDialogReducers > {
16
16
private _connectionToEditCopy : IConnectionDialogProfile | undefined ;
17
17
constructor (
18
18
context : vscode . ExtensionContext ,
@@ -476,88 +476,83 @@ export class ConnectionDialogWebViewController extends ReactWebViewPanelControll
476
476
}
477
477
478
478
private registerRpcHandlers ( ) {
479
- this . registerReducers ( {
480
- 'setFormTab' : async ( state , payload : {
481
- tab : FormTabs
482
- } ) => {
483
- this . state . selectedFormTab = payload . tab ;
484
- await this . updateItemVisibility ( ) ;
485
- return state ;
486
- } ,
487
- 'formAction' : async ( state , payload : {
488
- event : FormEvent
489
- } ) => {
490
- if ( payload . event . isAction ) {
491
- const component = this . getFormComponent ( payload . event . propertyName ) ;
492
- if ( component && component . actionButtons ) {
493
- const actionButton = component . actionButtons . find ( b => b . id === payload . event . value ) ;
494
- if ( actionButton ?. callback ) {
495
- await actionButton . callback ( ) ;
496
- }
479
+ this . registerReducer ( 'setFormTab' , async ( state , payload ) => {
480
+ this . state . selectedFormTab = payload . tab ;
481
+ await this . updateItemVisibility ( ) ;
482
+ return state ;
483
+ } ) ;
484
+
485
+ this . registerReducer ( 'formAction' , async ( state , payload ) => {
486
+ if ( payload . event . isAction ) {
487
+ const component = this . getFormComponent ( payload . event . propertyName ) ;
488
+ if ( component && component . actionButtons ) {
489
+ const actionButton = component . actionButtons . find ( b => b . id === payload . event . value ) ;
490
+ if ( actionButton ?. callback ) {
491
+ await actionButton . callback ( ) ;
497
492
}
498
- } else {
499
- ( this . state . connectionProfile [ payload . event . propertyName ] as any ) = payload . event . value ;
500
- await this . validateFormComponents ( payload . event . propertyName ) ;
501
- await this . handleAzureMFAEdits ( payload . event . propertyName ) ;
502
493
}
503
- await this . updateItemVisibility ( ) ;
504
- return state ;
505
- } ,
506
- 'loadConnection' : async ( state , payload : {
507
- connection : IConnectionDialogProfile
508
- } ) => {
509
- this . _connectionToEditCopy = structuredClone ( payload . connection ) ;
510
- this . clearFormError ( ) ;
511
- this . state . connectionProfile = payload . connection ;
512
- await this . updateItemVisibility ( ) ;
513
- await this . handleAzureMFAEdits ( 'azureAuthType' ) ;
514
- await this . handleAzureMFAEdits ( 'accountId' ) ;
494
+ } else {
495
+ ( this . state . connectionProfile [ payload . event . propertyName ] as any ) = payload . event . value ;
496
+ await this . validateFormComponents ( payload . event . propertyName ) ;
497
+ await this . handleAzureMFAEdits ( payload . event . propertyName ) ;
498
+ }
499
+ await this . updateItemVisibility ( ) ;
500
+ return state ;
501
+ } ) ;
502
+
503
+ this . registerReducer ( 'loadConnection' , async ( state , payload ) => {
504
+ this . _connectionToEditCopy = structuredClone ( payload . connection ) ;
505
+ this . clearFormError ( ) ;
506
+ this . state . connectionProfile = payload . connection ;
507
+ await this . updateItemVisibility ( ) ;
508
+ await this . handleAzureMFAEdits ( 'azureAuthType' ) ;
509
+ await this . handleAzureMFAEdits ( 'accountId' ) ;
510
+ return state ;
511
+ } ) ;
512
+
513
+ this . registerReducer ( 'connect' , async ( state ) => {
514
+ this . clearFormError ( ) ;
515
+ this . state . connectionStatus = ApiStatus . Loading ;
516
+ this . state . formError = '' ;
517
+ this . state = this . state ;
518
+ const notHiddenComponents = this . state . formComponents . filter ( c => ! c . hidden ) . map ( c => c . propertyName ) ;
519
+ // Set all other fields to undefined
520
+ Object . keys ( this . state . connectionProfile ) . forEach ( key => {
521
+ if ( ! notHiddenComponents . includes ( key as keyof IConnectionDialogProfile ) ) {
522
+ ( this . state . connectionProfile [ key as keyof IConnectionDialogProfile ] as any ) = undefined ;
523
+ }
524
+ } ) ;
525
+ const errorCount = await this . validateFormComponents ( ) ;
526
+ if ( errorCount > 0 ) {
527
+ this . state . connectionStatus = ApiStatus . Error ;
515
528
return state ;
516
- } ,
517
- 'connect' : async ( state ) => {
518
- this . clearFormError ( ) ;
519
- this . state . connectionStatus = ApiStatus . Loading ;
520
- this . state . formError = '' ;
521
- this . state = this . state ;
522
- const notHiddenComponents = this . state . formComponents . filter ( c => ! c . hidden ) . map ( c => c . propertyName ) ;
523
- // Set all other fields to undefined
524
- Object . keys ( this . state . connectionProfile ) . forEach ( key => {
525
- if ( ! notHiddenComponents . includes ( key as keyof IConnectionDialogProfile ) ) {
526
- ( this . state . connectionProfile [ key as keyof IConnectionDialogProfile ] as any ) = undefined ;
527
- }
528
- } ) ;
529
- const errorCount = await this . validateFormComponents ( ) ;
530
- if ( errorCount > 0 ) {
529
+ }
530
+
531
+ try {
532
+ const result = await this . _mainController . connectionManager . connectionUI . validateAndSaveProfileFromDialog ( this . state . connectionProfile as any ) ;
533
+ if ( result ?. errorMessage ) {
534
+ this . state . formError = result . errorMessage ;
531
535
this . state . connectionStatus = ApiStatus . Error ;
532
536
return state ;
533
537
}
534
-
535
- try {
536
- const result = await this . _mainController . connectionManager . connectionUI . validateAndSaveProfileFromDialog ( this . state . connectionProfile as any ) ;
537
- if ( result ?. errorMessage ) {
538
- this . state . formError = result . errorMessage ;
539
- this . state . connectionStatus = ApiStatus . Error ;
540
- return state ;
541
- }
542
- if ( this . _connectionToEditCopy ) {
543
- await this . _mainController . connectionManager . getUriForConnection ( this . _connectionToEditCopy ) ;
544
- await this . _objectExplorerProvider . removeConnectionNodes ( [ this . _connectionToEditCopy ] ) ;
545
- await this . _mainController . connectionManager . connectionStore . removeProfile ( this . _connectionToEditCopy as any ) ;
546
- await this . _objectExplorerProvider . refresh ( undefined ) ;
547
- }
548
- await this . _mainController . connectionManager . connectionUI . saveProfile ( this . state . connectionProfile as any ) ;
549
- const node = await this . _mainController . createObjectExplorerSessionFromDialog ( this . state . connectionProfile ) ;
538
+ if ( this . _connectionToEditCopy ) {
539
+ await this . _mainController . connectionManager . getUriForConnection ( this . _connectionToEditCopy ) ;
540
+ await this . _objectExplorerProvider . removeConnectionNodes ( [ this . _connectionToEditCopy ] ) ;
541
+ await this . _mainController . connectionManager . connectionStore . removeProfile ( this . _connectionToEditCopy as any ) ;
550
542
await this . _objectExplorerProvider . refresh ( undefined ) ;
551
- await this . loadRecentConnections ( ) ;
552
- this . state . connectionStatus = ApiStatus . Loaded ;
553
- await this . _mainController . objectExplorerTree . reveal ( node , { focus : true , select : true , expand : true } ) ;
554
- await this . panel . dispose ( ) ;
555
- } catch ( error ) {
556
- this . state . connectionStatus = ApiStatus . Error ;
557
- return state ;
558
543
}
544
+ await this . _mainController . connectionManager . connectionUI . saveProfile ( this . state . connectionProfile as any ) ;
545
+ const node = await this . _mainController . createObjectExplorerSessionFromDialog ( this . state . connectionProfile ) ;
546
+ await this . _objectExplorerProvider . refresh ( undefined ) ;
547
+ await this . loadRecentConnections ( ) ;
548
+ this . state . connectionStatus = ApiStatus . Loaded ;
549
+ await this . _mainController . objectExplorerTree . reveal ( node , { focus : true , select : true , expand : true } ) ;
550
+ await this . panel . dispose ( ) ;
551
+ } catch ( error ) {
552
+ this . state . connectionStatus = ApiStatus . Error ;
559
553
return state ;
560
554
}
555
+ return state ;
561
556
} ) ;
562
557
}
563
558
}
0 commit comments