@@ -9,18 +9,11 @@ import { createCommonButtons, createRefreshButton, QuickInputToggleButton } from
9
9
import { Remote } from '../../../types/git.d'
10
10
import { GitExtension } from '../../shared/extensions/git'
11
11
import * as vscode from 'vscode'
12
- import { CachedFunction , CachedPrompter } from '../../shared/ui/prompter'
13
12
import { WizardForm } from '../../shared/wizards/wizardForm'
14
13
import { createVariablesPrompter } from '../../shared/ui/common/variablesPrompter'
15
14
import { AppRunnerClient } from '../../shared/clients/apprunnerClient'
16
15
import { makeDeploymentButton } from './deploymentButton'
17
- import { ConnectionSummary } from 'aws-sdk/clients/apprunner'
18
- import {
19
- createLabelQuickPick ,
20
- createQuickPick ,
21
- DataQuickPickItem ,
22
- QuickPickPrompter ,
23
- } from '../../shared/ui/pickerPrompter'
16
+ import { createLabelQuickPick , createQuickPick , QuickPickPrompter } from '../../shared/ui/pickerPrompter'
24
17
import { createInputBox , InputBoxPrompter } from '../../shared/ui/inputPrompter'
25
18
import {
26
19
apprunnerConnectionHelpUrl ,
@@ -29,7 +22,6 @@ import {
29
22
apprunnerCreateServiceDocsUrl ,
30
23
} from '../../shared/constants'
31
24
import { Wizard , WIZARD_BACK } from '../../shared/wizards/wizard'
32
- import { getLogger } from '../../shared/logger/logger'
33
25
34
26
const localize = nls . loadMessageBundle ( )
35
27
@@ -151,71 +143,41 @@ function createPortPrompter(): InputBoxPrompter {
151
143
} )
152
144
}
153
145
154
- export class ConnectionPrompter extends CachedPrompter < ConnectionSummary > {
155
- public constructor ( private readonly client : AppRunnerClient ) {
156
- super ( )
146
+ export function createConnectionPrompter ( client : AppRunnerClient ) {
147
+ const noItemsFoundItem = {
148
+ label : 'No connections found' ,
149
+ detail : 'Click for documentation on creating a new GitHub connection for App Runner' ,
150
+ data : { } as any ,
151
+ invalidSelection : true ,
152
+ onClick : ( ) => vscode . env . openExternal ( vscode . Uri . parse ( apprunnerConnectionHelpUrl ) ) ,
157
153
}
158
154
159
- protected load ( ) : Promise < DataQuickPickItem < ConnectionSummary > [ ] > {
160
- return this . client
161
- . listConnections ( { } )
162
- . then ( resp => {
163
- const connections = resp . ConnectionSummaryList . filter ( conn => conn . Status === 'AVAILABLE' ) . map (
164
- conn => ( {
165
- label : conn . ConnectionName ! ,
166
- data : conn ,
167
- } )
168
- )
169
-
170
- if ( connections . length === 0 ) {
171
- return [
172
- {
173
- label : 'No connections found' ,
174
- detail : 'Click for documentation on creating a new GitHub connection for App Runner' ,
175
- data : { } as any ,
176
- invalidSelection : true ,
177
- onClick : vscode . env . openExternal . bind (
178
- vscode . env ,
179
- vscode . Uri . parse ( apprunnerConnectionHelpUrl )
180
- ) ,
181
- } ,
182
- ]
183
- } else {
184
- return connections
185
- }
186
- } )
187
- . catch ( err => {
188
- getLogger ( ) . error ( `Failed to list GitHub connections: %O` , err )
189
- return [
190
- {
191
- label : localize (
192
- 'AWS.apprunner.createService.selectConnection.failed' ,
193
- 'Failed to list GitHub connections'
194
- ) ,
195
- description : localize ( 'AWS.generic.goBack' , 'Click to go back' ) ,
196
- data : WIZARD_BACK ,
197
- } ,
198
- ]
199
- } )
155
+ const errorItem = {
156
+ label : localize ( 'AWS.apprunner.createService.selectConnection.failed' , 'Failed to list GitHub connections' ) ,
157
+ description : localize ( 'AWS.generic.goBack' , 'Click to go back' ) ,
158
+ data : WIZARD_BACK ,
200
159
}
201
160
202
- protected createPrompter ( loader : CachedFunction < ConnectionPrompter [ 'load' ] > ) : QuickPickPrompter < ConnectionSummary > {
203
- const connections = loader ( )
204
- const refreshButton = createRefreshButton ( )
205
- const prompter = createQuickPick ( connections , {
206
- title : localize ( 'AWS.apprunner.createService.selectConnection.title' , 'Select a connection' ) ,
207
- buttons : [ refreshButton , ...createCommonButtons ( apprunnerConnectionHelpUrl ) ] ,
208
- } )
161
+ const getItems = async ( ) => {
162
+ const resp = await client . listConnections ( )
209
163
210
- const refresh = ( ) => {
211
- loader . clearCache ( )
212
- prompter . clearAndLoadItems ( loader ( ) )
213
- }
164
+ return resp . ConnectionSummaryList . filter ( conn => conn . Status === 'AVAILABLE' ) . map ( conn => ( {
165
+ label : conn . ConnectionName ! ,
166
+ data : conn ,
167
+ } ) )
168
+ }
214
169
215
- refreshButton . onClick = refresh
170
+ const refreshButton = createRefreshButton ( )
171
+ refreshButton . onClick = ( ) => void prompter . clearAndLoadItems ( getItems ( ) )
216
172
217
- return prompter
218
- }
173
+ const prompter = createQuickPick ( getItems ( ) , {
174
+ errorItem,
175
+ noItemsFoundItem,
176
+ buttons : [ refreshButton , ...createCommonButtons ( apprunnerConnectionHelpUrl ) ] ,
177
+ title : localize ( 'AWS.apprunner.createService.selectConnection.title' , 'Select a connection' ) ,
178
+ } )
179
+
180
+ return prompter
219
181
}
220
182
221
183
function createSourcePrompter ( ) : QuickPickPrompter < AppRunner . ConfigurationSource > {
@@ -276,10 +238,9 @@ export class AppRunnerCodeRepositoryWizard extends Wizard<AppRunner.SourceConfig
276
238
) {
277
239
super ( )
278
240
const form = this . form
279
- const connectionPrompter = new ConnectionPrompter ( client )
280
241
281
- form . AuthenticationConfiguration . ConnectionArn . bindPrompter (
282
- connectionPrompter . transform ( conn => conn . ConnectionArn ! )
242
+ form . AuthenticationConfiguration . ConnectionArn . bindPrompter ( ( ) =>
243
+ createConnectionPrompter ( client ) . transform ( conn => conn . ConnectionArn ! )
283
244
)
284
245
form . CodeRepository . applyBoundForm ( createCodeRepositorySubForm ( git ) )
285
246
form . AutoDeploymentsEnabled . setDefault ( ( ) => autoDeployButton . state === 'on' )
0 commit comments