@@ -20,6 +20,7 @@ import {
20
20
AddFirewallRuleDialogProps ,
21
21
IConnectionDialogProfile ,
22
22
TrustServerCertDialogProps ,
23
+ ConnectionDialogFormItemSpec ,
23
24
} from "../sharedInterfaces/connectionDialog" ;
24
25
import { ConnectionCompleteParams } from "../models/contracts/connection" ;
25
26
import {
@@ -51,7 +52,6 @@ import { AzureSubscription } from "@microsoft/vscode-azext-azureauth";
51
52
import { IConnectionInfo } from "vscode-mssql" ;
52
53
import MainController from "../controllers/mainController" ;
53
54
import { ObjectExplorerProvider } from "../objectExplorer/objectExplorerProvider" ;
54
- import { ReactWebviewPanelController } from "../controllers/reactWebviewPanelController" ;
55
55
import { UserSurvey } from "../nps/userSurvey" ;
56
56
import VscodeWrapper from "../controllers/vscodeWrapper" ;
57
57
import {
@@ -69,13 +69,14 @@ import {
69
69
import { IAccount } from "../models/contracts/azure" ;
70
70
import {
71
71
generateConnectionComponents ,
72
- getActiveFormComponents ,
73
- getFormComponent ,
74
72
groupAdvancedOptions ,
75
73
} from "./formComponentHelpers" ;
74
+ import { FormWebviewController } from "../forms/formWebviewController" ;
76
75
77
- export class ConnectionDialogWebviewController extends ReactWebviewPanelController <
76
+ export class ConnectionDialogWebviewController extends FormWebviewController <
77
+ IConnectionDialogProfile ,
78
78
ConnectionDialogWebviewState ,
79
+ ConnectionDialogFormItemSpec ,
79
80
ConnectionDialogReducers
80
81
> {
81
82
//#region Properties
@@ -176,12 +177,13 @@ export class ConnectionDialogWebviewController extends ReactWebviewPanelControll
176
177
) ;
177
178
}
178
179
180
+ this . state . formComponents = await generateConnectionComponents (
181
+ this . _mainController . connectionManager ,
182
+ getAccounts ( this . _mainController . azureAccountService ) ,
183
+ this . getAzureActionButtons ( ) ,
184
+ ) ;
185
+
179
186
this . state . connectionComponents = {
180
- components : await generateConnectionComponents (
181
- this . _mainController . connectionManager ,
182
- getAccounts ( this . _mainController . azureAccountService ) ,
183
- this . getAzureActionButtons ( ) ,
184
- ) ,
185
187
mainOptions : [ ...ConnectionDialogWebviewController . mainOptions ] ,
186
188
topAdvancedOptions : [
187
189
"port" ,
@@ -195,7 +197,10 @@ export class ConnectionDialogWebviewController extends ReactWebviewPanelControll
195
197
} ;
196
198
197
199
this . state . connectionComponents . groupedAdvancedOptions =
198
- groupAdvancedOptions ( this . state . connectionComponents ) ;
200
+ groupAdvancedOptions (
201
+ this . state . formComponents as any ,
202
+ this . state . connectionComponents ,
203
+ ) ;
199
204
200
205
await this . updateItemVisibility ( ) ;
201
206
this . updateState ( ) ;
@@ -220,36 +225,6 @@ export class ConnectionDialogWebviewController extends ReactWebviewPanelControll
220
225
} ,
221
226
) ;
222
227
223
- this . registerReducer ( "formAction" , async ( state , payload ) => {
224
- if ( payload . event . isAction ) {
225
- const component = getFormComponent (
226
- this . state ,
227
- payload . event . propertyName ,
228
- ) ;
229
- if ( component && component . actionButtons ) {
230
- const actionButton = component . actionButtons . find (
231
- ( b ) => b . id === payload . event . value ,
232
- ) ;
233
- if ( actionButton ?. callback ) {
234
- await actionButton . callback ( ) ;
235
- }
236
- }
237
- } else {
238
- ( this . state . connectionProfile [
239
- payload . event . propertyName
240
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
241
- ] as any ) = payload . event . value ;
242
- await this . validateConnectionProfile (
243
- this . state . connectionProfile ,
244
- payload . event . propertyName ,
245
- ) ;
246
- await this . handleAzureMFAEdits ( payload . event . propertyName ) ;
247
- }
248
- await this . updateItemVisibility ( ) ;
249
-
250
- return state ;
251
- } ) ;
252
-
253
228
this . registerReducer ( "loadConnection" , async ( state , payload ) => {
254
229
sendActionEvent (
255
230
TelemetryViews . ConnectionDialog ,
@@ -432,7 +407,13 @@ export class ConnectionDialogWebviewController extends ReactWebviewPanelControll
432
407
433
408
//#region Connection helpers
434
409
435
- private async updateItemVisibility ( ) {
410
+ override async afterSetFormProperty (
411
+ propertyName : keyof IConnectionDialogProfile ,
412
+ ) : Promise < void > {
413
+ return await this . handleAzureMFAEdits ( propertyName ) ;
414
+ }
415
+
416
+ async updateItemVisibility ( ) {
436
417
let hiddenProperties : ( keyof IConnectionDialogProfile ) [ ] = [ ] ;
437
418
438
419
if (
@@ -466,56 +447,23 @@ export class ConnectionDialogWebviewController extends ReactWebviewPanelControll
466
447
}
467
448
}
468
449
469
- for ( const component of Object . values (
470
- this . state . connectionComponents . components ,
471
- ) ) {
450
+ for ( const component of Object . values ( this . state . formComponents ) ) {
472
451
component . hidden = hiddenProperties . includes (
473
452
component . propertyName ,
474
453
) ;
475
454
}
476
455
}
477
456
478
- private async validateConnectionProfile (
479
- connectionProfile : IConnectionDialogProfile ,
480
- propertyName ?: keyof IConnectionDialogProfile ,
481
- ) : Promise < string [ ] > {
482
- const erroredInputs = [ ] ;
483
- if ( propertyName ) {
484
- const component = getFormComponent ( this . state , propertyName ) ;
485
- if ( component && component . validate ) {
486
- component . validation = component . validate (
487
- this . state ,
488
- connectionProfile [ propertyName ] ,
489
- ) ;
490
- if ( ! component . validation . isValid ) {
491
- erroredInputs . push ( component . propertyName ) ;
492
- }
493
- }
494
- } else {
495
- getActiveFormComponents ( this . state )
496
- . map ( ( x ) => this . state . connectionComponents . components [ x ] )
497
- . forEach ( ( c ) => {
498
- if ( c . hidden ) {
499
- c . validation = {
500
- isValid : true ,
501
- validationMessage : "" ,
502
- } ;
503
- return ;
504
- } else {
505
- if ( c . validate ) {
506
- c . validation = c . validate (
507
- this . state ,
508
- connectionProfile [ c . propertyName ] ,
509
- ) ;
510
- if ( ! c . validation . isValid ) {
511
- erroredInputs . push ( c . propertyName ) ;
512
- }
513
- }
514
- }
515
- } ) ;
457
+ protected getActiveFormComponents (
458
+ state : ConnectionDialogWebviewState ,
459
+ ) : ( keyof IConnectionDialogProfile ) [ ] {
460
+ if (
461
+ state . selectedInputMode === ConnectionInputMode . Parameters ||
462
+ state . selectedInputMode === ConnectionInputMode . AzureBrowse
463
+ ) {
464
+ return state . connectionComponents . mainOptions ;
516
465
}
517
-
518
- return erroredInputs ;
466
+ return [ "connectionString" , "profileName" ] ;
519
467
}
520
468
521
469
/** Returns a copy of `connection` that's been cleaned up by clearing the properties that aren't being used
@@ -526,9 +474,7 @@ export class ConnectionDialogWebviewController extends ReactWebviewPanelControll
526
474
const cleanedConnection = structuredClone ( connection ) ;
527
475
528
476
// Clear values for inputs that are hidden due to form selections
529
- for ( const option of Object . values (
530
- this . state . connectionComponents . components ,
531
- ) ) {
477
+ for ( const option of Object . values ( this . state . formComponents ) ) {
532
478
if ( option . hidden ) {
533
479
( cleanedConnection [
534
480
option . propertyName as keyof IConnectionDialogProfile
@@ -663,7 +609,7 @@ export class ConnectionDialogWebviewController extends ReactWebviewPanelControll
663
609
// clean the connection by clearing the options that aren't being used
664
610
const cleanedConnection = this . cleanConnection ( connectionProfile ) ;
665
611
666
- return await this . validateConnectionProfile ( cleanedConnection ) ;
612
+ return await this . validateForm ( cleanedConnection ) ;
667
613
}
668
614
669
615
private async connectHelper (
@@ -963,7 +909,7 @@ export class ConnectionDialogWebviewController extends ReactWebviewPanelControll
963
909
callback : async ( ) => {
964
910
const account =
965
911
await this . _mainController . azureAccountService . addAccount ( ) ;
966
- const accountsComponent = getFormComponent (
912
+ const accountsComponent = this . getFormComponent (
967
913
this . state ,
968
914
"accountId" ,
969
915
) ;
@@ -1047,8 +993,14 @@ export class ConnectionDialogWebviewController extends ReactWebviewPanelControll
1047
993
) {
1048
994
return ;
1049
995
}
1050
- const accountComponent = getFormComponent ( this . state , "accountId" ) ;
1051
- const tenantComponent = getFormComponent ( this . state , "tenantId" ) ;
996
+ const accountComponent = this . getFormComponent (
997
+ this . state ,
998
+ "accountId" ,
999
+ ) ;
1000
+ const tenantComponent = this . getFormComponent (
1001
+ this . state ,
1002
+ "tenantId" ,
1003
+ ) ;
1052
1004
let tenants : FormItemOptions [ ] = [ ] ;
1053
1005
switch ( propertyName ) {
1054
1006
case "accountId" :
@@ -1321,8 +1273,8 @@ export class ConnectionDialogWebviewController extends ReactWebviewPanelControll
1321
1273
1322
1274
private clearFormError ( ) {
1323
1275
this . state . formError = "" ;
1324
- for ( const component of getActiveFormComponents ( this . state ) . map (
1325
- ( x ) => this . state . connectionComponents . components [ x ] ,
1276
+ for ( const component of this . getActiveFormComponents ( this . state ) . map (
1277
+ ( x ) => this . state . formComponents [ x ] ,
1326
1278
) ) {
1327
1279
component . validation = undefined ;
1328
1280
}
0 commit comments