5
5
6
6
import * as vscode from 'vscode' ;
7
7
import { ReactWebViewPanelController } from "../controllers/reactWebviewController" ;
8
- import { AuthenticationType , ConnectionDialogReducers , ConnectionDialogWebviewState , FormComponent , FormComponentActionButton , FormComponentOptions , FormComponentType , FormTabType , IConnectionDialogProfile } from '../sharedInterfaces/connectionDialog' ;
8
+ import { AuthenticationType , ConnectionDialogReducers , ConnectionDialogWebviewState , FormTabType , 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' ;
@@ -17,6 +17,7 @@ import { ConnectionOption } from 'azdata';
17
17
import { Logger } from '../models/logger' ;
18
18
import VscodeWrapper from '../controllers/vscodeWrapper' ;
19
19
import * as LocalizedConstants from '../constants/localizedConstants' ;
20
+ import { FormItemSpec , FormItemActionButton , FormItemOptions , FormItemType } from '../reactviews/common/forms/form' ;
20
21
import { ApiStatus } from '../sharedInterfaces/webview' ;
21
22
22
23
export class ConnectionDialogWebViewController extends ReactWebViewPanelController < ConnectionDialogWebviewState , ConnectionDialogReducers > {
@@ -34,7 +35,7 @@ export class ConnectionDialogWebViewController extends ReactWebViewPanelControll
34
35
context ,
35
36
LocalizedConstants . connectionDialog ,
36
37
WebviewRoute . connectionDialog ,
37
- {
38
+ new ConnectionDialogWebviewState ( {
38
39
connectionProfile : { } as IConnectionDialogProfile ,
39
40
recentConnections : [ ] ,
40
41
selectedFormTab : FormTabType . Parameters ,
@@ -45,7 +46,7 @@ export class ConnectionDialogWebViewController extends ReactWebViewPanelControll
45
46
connectionStringComponents : [ ] ,
46
47
connectionStatus : ApiStatus . NotStarted ,
47
48
formError : ''
48
- } ,
49
+ } ) ,
49
50
vscode . ViewColumn . Active ,
50
51
{
51
52
dark : vscode . Uri . joinPath ( context . extensionUri , 'media' , 'connectionDialogEditor_inverse.svg' ) ,
@@ -154,19 +155,19 @@ export class ConnectionDialogWebViewController extends ReactWebViewPanelControll
154
155
}
155
156
}
156
157
157
- private getActiveFormComponents ( ) : FormComponent [ ] {
158
+ private getActiveFormComponents ( ) : FormItemSpec < IConnectionDialogProfile > [ ] {
158
159
if ( this . state . selectedFormTab === FormTabType . Parameters ) {
159
160
return this . state . connectionFormComponents . mainComponents ;
160
161
}
161
162
return this . state . connectionStringComponents ;
162
163
}
163
164
164
- private getFormComponent ( propertyName : keyof IConnectionDialogProfile ) : FormComponent | undefined {
165
+ private getFormComponent ( propertyName : keyof IConnectionDialogProfile ) : FormItemSpec < IConnectionDialogProfile > | undefined {
165
166
166
167
return this . getActiveFormComponents ( ) . find ( c => c . propertyName === propertyName ) ;
167
168
}
168
169
169
- private async getAccounts ( ) : Promise < FormComponentOptions [ ] > {
170
+ private async getAccounts ( ) : Promise < FormItemOptions [ ] > {
170
171
const accounts = await this . _mainController . azureAccountService . getAccounts ( ) ;
171
172
return accounts . map ( account => {
172
173
return {
@@ -177,7 +178,7 @@ export class ConnectionDialogWebViewController extends ReactWebViewPanelControll
177
178
178
179
}
179
180
180
- private async getTenants ( accountId : string ) : Promise < FormComponentOptions [ ] > {
181
+ private async getTenants ( accountId : string ) : Promise < FormItemOptions [ ] > {
181
182
const account = ( await this . _mainController . azureAccountService . getAccounts ( ) ) . find ( account => account . displayInfo . userId === accountId ) ;
182
183
if ( ! account ) {
183
184
return [ ] ;
@@ -194,30 +195,30 @@ export class ConnectionDialogWebViewController extends ReactWebViewPanelControll
194
195
} ) ;
195
196
}
196
197
197
- private convertToFormComponent ( connOption : ConnectionOption ) : FormComponent {
198
+ private convertToFormComponent ( connOption : ConnectionOption ) : FormItemSpec < IConnectionDialogProfile > {
198
199
switch ( connOption . valueType ) {
199
200
case 'boolean' :
200
201
return {
201
202
propertyName : connOption . name as keyof IConnectionDialogProfile ,
202
203
label : connOption . displayName ,
203
204
required : connOption . isRequired ,
204
- type : FormComponentType . Checkbox ,
205
+ type : FormItemType . Checkbox ,
205
206
tooltip : connOption . description ,
206
207
} ;
207
208
case 'string' :
208
209
return {
209
210
propertyName : connOption . name as keyof IConnectionDialogProfile ,
210
211
label : connOption . displayName ,
211
212
required : connOption . isRequired ,
212
- type : FormComponentType . Input ,
213
+ type : FormItemType . Input ,
213
214
tooltip : connOption . description ,
214
215
} ;
215
216
case 'password' :
216
217
return {
217
218
propertyName : connOption . name as keyof IConnectionDialogProfile ,
218
219
label : connOption . displayName ,
219
220
required : connOption . isRequired ,
220
- type : FormComponentType . Password ,
221
+ type : FormItemType . Password ,
221
222
tooltip : connOption . description ,
222
223
} ;
223
224
@@ -226,15 +227,15 @@ export class ConnectionDialogWebViewController extends ReactWebViewPanelControll
226
227
propertyName : connOption . name as keyof IConnectionDialogProfile ,
227
228
label : connOption . displayName ,
228
229
required : connOption . isRequired ,
229
- type : FormComponentType . Input ,
230
+ type : FormItemType . Input ,
230
231
tooltip : connOption . description ,
231
232
} ;
232
233
case 'category' :
233
234
return {
234
235
propertyName : connOption . name as keyof IConnectionDialogProfile ,
235
236
label : connOption . displayName ,
236
237
required : connOption . isRequired ,
237
- type : FormComponentType . Dropdown ,
238
+ type : FormItemType . Dropdown ,
238
239
tooltip : connOption . description ,
239
240
options : connOption . categoryValues . map ( v => {
240
241
return {
@@ -248,15 +249,15 @@ export class ConnectionDialogWebViewController extends ReactWebViewPanelControll
248
249
}
249
250
}
250
251
251
- private async completeFormComponents ( components : Map < string , { option : ConnectionOption , component : FormComponent } > ) {
252
+ private async completeFormComponents ( components : Map < string , { option : ConnectionOption , component : FormItemSpec < IConnectionDialogProfile > } > ) {
252
253
// Add additional components that are not part of the connection options
253
254
components . set ( 'savePassword' , {
254
255
option : undefined ,
255
256
component : {
256
257
propertyName : 'savePassword' ,
257
258
label : LocalizedConstants . savePassword ,
258
259
required : false ,
259
- type : FormComponentType . Checkbox ,
260
+ type : FormItemType . Checkbox ,
260
261
}
261
262
} ) ;
262
263
@@ -266,7 +267,7 @@ export class ConnectionDialogWebViewController extends ReactWebViewPanelControll
266
267
propertyName : 'accountId' ,
267
268
label : LocalizedConstants . azureAccount ,
268
269
required : true ,
269
- type : FormComponentType . Dropdown ,
270
+ type : FormItemType . Dropdown ,
270
271
options : await this . getAccounts ( ) ,
271
272
placeholder : LocalizedConstants . selectAnAccount ,
272
273
actionButtons : await this . getAzureActionButtons ( ) ,
@@ -291,7 +292,7 @@ export class ConnectionDialogWebViewController extends ReactWebViewPanelControll
291
292
propertyName : 'tenantId' ,
292
293
label : LocalizedConstants . tenantId ,
293
294
required : true ,
294
- type : FormComponentType . Dropdown ,
295
+ type : FormItemType . Dropdown ,
295
296
options : [ ] ,
296
297
hidden : true ,
297
298
placeholder : LocalizedConstants . selectATenant ,
@@ -316,7 +317,7 @@ export class ConnectionDialogWebViewController extends ReactWebViewPanelControll
316
317
propertyName : 'profileName' ,
317
318
label : LocalizedConstants . profileName ,
318
319
required : false ,
319
- type : FormComponentType . Input ,
320
+ type : FormItemType . Input ,
320
321
}
321
322
} ) ;
322
323
@@ -363,15 +364,15 @@ export class ConnectionDialogWebViewController extends ReactWebViewPanelControll
363
364
] ) ;
364
365
365
366
private async generateConnectionFormComponents ( ) : Promise < {
366
- mainComponents : FormComponent [ ] ,
367
- advancedComponents : { [ category : string ] : FormComponent [ ] }
367
+ mainComponents : FormItemSpec < IConnectionDialogProfile > [ ] ,
368
+ advancedComponents : { [ category : string ] : FormItemSpec < IConnectionDialogProfile > [ ] }
368
369
} > {
369
370
// get list of connection options from Tools Service
370
371
const result : CapabilitiesResult = await this . _mainController . connectionManager . client . sendRequest ( GetCapabilitiesRequest . type , { } ) ;
371
372
const connectionOptions : ConnectionOption [ ] = result . capabilities . connectionProvider . options ;
372
373
373
374
// convert connection options to form components
374
- const allConnectionFormComponents = new Map < string , { option : ConnectionOption , component : FormComponent } > ( ) ;
375
+ const allConnectionFormComponents = new Map < string , { option : ConnectionOption , component : FormItemSpec < IConnectionDialogProfile > } > ( ) ;
375
376
376
377
for ( const option of connectionOptions ) {
377
378
allConnectionFormComponents . set ( option . name , { option, component : this . convertToFormComponent ( option ) } ) ;
@@ -381,8 +382,8 @@ export class ConnectionDialogWebViewController extends ReactWebViewPanelControll
381
382
382
383
// organize the main components and advanced components
383
384
// main components are few-enough that there's no grouping, but advanced components get grouped by category
384
- const mainComponents : FormComponent [ ] = [ ] ;
385
- const advancedComponents : { [ category : string ] : FormComponent [ ] } = { } ;
385
+ const mainComponents : FormItemSpec < IConnectionDialogProfile > [ ] = [ ] ;
386
+ const advancedComponents : { [ category : string ] : FormItemSpec < IConnectionDialogProfile > [ ] } = { } ;
386
387
387
388
for ( const [ optionName , { option, component} ] of allConnectionFormComponents ) {
388
389
if ( this . _mainOptionNames . has ( optionName ) ) {
@@ -399,10 +400,10 @@ export class ConnectionDialogWebViewController extends ReactWebViewPanelControll
399
400
return { mainComponents, advancedComponents} ;
400
401
}
401
402
402
- private async generateConnectionStringComponents ( ) : Promise < FormComponent [ ] > {
403
+ private async generateConnectionStringComponents ( ) : Promise < FormItemSpec < IConnectionDialogProfile > [ ] > {
403
404
return [
404
405
{
405
- type : FormComponentType . TextArea ,
406
+ type : FormItemType . TextArea ,
406
407
propertyName : 'connectionString' ,
407
408
label : LocalizedConstants . connectionString ,
408
409
required : true ,
@@ -423,7 +424,7 @@ export class ConnectionDialogWebViewController extends ReactWebViewPanelControll
423
424
propertyName : 'profileName' ,
424
425
label : LocalizedConstants . profileName ,
425
426
required : false ,
426
- type : FormComponentType . Input ,
427
+ type : FormItemType . Input ,
427
428
}
428
429
] ;
429
430
}
@@ -460,8 +461,8 @@ export class ConnectionDialogWebViewController extends ReactWebViewPanelControll
460
461
return errorCount ;
461
462
}
462
463
463
- private async getAzureActionButtons ( ) : Promise < FormComponentActionButton [ ] > {
464
- const actionButtons : FormComponentActionButton [ ] = [ ] ;
464
+ private async getAzureActionButtons ( ) : Promise < FormItemActionButton [ ] > {
465
+ const actionButtons : FormItemActionButton [ ] = [ ] ;
465
466
actionButtons . push ( {
466
467
label : LocalizedConstants . signIn ,
467
468
id : 'azureSignIn' ,
@@ -507,7 +508,7 @@ export class ConnectionDialogWebViewController extends ReactWebViewPanelControll
507
508
}
508
509
const accountComponent = this . getFormComponent ( 'accountId' ) ;
509
510
const tenantComponent = this . getFormComponent ( 'tenantId' ) ;
510
- let tenants : FormComponentOptions [ ] = [ ] ;
511
+ let tenants : FormItemOptions [ ] = [ ] ;
511
512
switch ( propertyName ) {
512
513
case 'accountId' :
513
514
tenants = await this . getTenants ( this . state . connectionProfile . accountId ) ;
0 commit comments