@@ -334,78 +334,91 @@ export default function CDPipeline({
334
334
handlePluginDataStoreUpdate ( getUpdatedPluginStore ( pluginDataStore , parentPluginStore , pluginVersionStore ) )
335
335
}
336
336
337
- const getEnvCDPipelineName = ( form ) => {
338
- Promise . all ( [ getCDPipelineNameSuggestion ( appId , isTemplateView ) , getEnvironmentListMinPublic ( true ) ] )
339
- . then ( ( [ cpPipelineName , envList ] ) => {
340
- form . name = cpPipelineName . result
341
- let list = envList . result || [ ]
342
- list = list . map ( ( env ) => {
343
- return {
344
- id : env . id ,
345
- clusterId : env . cluster_id ,
346
- clusterName : env . cluster_name ,
347
- name : env . environment_name ,
348
- namespace : env . namespace || '' ,
349
- active : false ,
350
- isClusterCdActive : env . isClusterCdActive ,
351
- description : env . description ,
352
- isVirtualEnvironment : env . isVirtualEnvironment ,
353
- allowedDeploymentTypes : env . allowedDeploymentTypes || [ ] ,
354
- isDigestEnforcedForEnv : env . isDigestEnforcedForEnv ,
355
- }
356
- } )
357
- sortObjectArrayAlphabetically ( list , 'name' )
358
- form . environments = list
359
- setFormData ( ( prevState ) => {
360
- return {
361
- ...form ,
362
- // Can retain the release mode since this method is called only when creating a new pipeline
363
- releaseMode : prevState . releaseMode ,
364
- }
365
- } )
366
- setPageState ( ViewType . FORM )
367
- setIsAdvanced ( false )
368
- } )
369
- . catch ( ( error ) => {
370
- showError ( error )
371
- } )
337
+ const getNewPipelineNameAndEnvironments = async ( ) : Promise < Pick < typeof formData , 'name' | 'environments' > > => {
338
+ try {
339
+ const [ cpPipelineName , envList ] = await Promise . all ( [
340
+ getCDPipelineNameSuggestion ( appId , isTemplateView ) ,
341
+ getEnvironmentListMinPublic ( true ) ,
342
+ ] )
343
+ const list = ( envList . result || [ ] ) . map ( ( env ) => ( {
344
+ id : env . id ,
345
+ clusterId : env . cluster_id ,
346
+ clusterName : env . cluster_name ,
347
+ name : env . environment_name ,
348
+ namespace : env . namespace || '' ,
349
+ active : false ,
350
+ isClusterCdActive : env . isClusterCdActive ,
351
+ description : env . description ,
352
+ isVirtualEnvironment : env . isVirtualEnvironment ,
353
+ allowedDeploymentTypes : env . allowedDeploymentTypes || [ ] ,
354
+ isDigestEnforcedForEnv : env . isDigestEnforcedForEnv ,
355
+ } ) )
356
+
357
+ return {
358
+ name : cpPipelineName . result ,
359
+ environments : sortObjectArrayAlphabetically ( list , 'name' ) ,
360
+ }
361
+ } catch ( error ) {
362
+ showError ( error )
363
+ }
364
+
365
+ return {
366
+ name : '' ,
367
+ environments : [ ] ,
368
+ }
372
369
}
373
370
374
371
const getInit = ( ) => {
375
372
Promise . all ( [
376
373
getDeploymentStrategyList ( appId , isTemplateView ) ,
377
374
getGlobalVariables ( { appId : Number ( appId ) , isCD : true } ) ,
378
375
getDockerRegistryMinAuth ( appId , true ) ,
376
+ ! cdPipelineId ? getNewPipelineNameAndEnvironments ( ) : { name : '' , environments : [ ] } ,
379
377
] )
380
- . then ( ( [ pipelineStrategyResponse , globalVariablesOptions , dockerResponse ] ) => {
381
- const strategies = pipelineStrategyResponse . result . pipelineStrategy || [ ]
382
- const dockerRegistries = dockerResponse . result || [ ]
383
- const _allStrategies = { }
384
-
385
- strategies . forEach ( ( strategy ) => {
386
- if ( ! _allStrategies [ strategy . deploymentTemplate ] ) {
387
- _allStrategies [ strategy . deploymentTemplate ] = { }
388
- }
389
- _allStrategies [ strategy . deploymentTemplate ] = strategy . config
390
- } )
391
- allStrategies . current = _allStrategies
392
- noStrategyAvailable . current = strategies . length === 0
378
+ . then (
379
+ ( [
380
+ pipelineStrategyResponse ,
381
+ globalVariablesOptions ,
382
+ dockerResponse ,
383
+ newPipelineNameAndEnvironments ,
384
+ ] ) => {
385
+ const strategies = pipelineStrategyResponse . result . pipelineStrategy || [ ]
386
+ const dockerRegistries = dockerResponse . result || [ ]
387
+ const _allStrategies = { }
388
+
389
+ strategies . forEach ( ( strategy ) => {
390
+ if ( ! _allStrategies [ strategy . deploymentTemplate ] ) {
391
+ _allStrategies [ strategy . deploymentTemplate ] = { }
392
+ }
393
+ _allStrategies [ strategy . deploymentTemplate ] = strategy . config
394
+ } )
395
+ allStrategies . current = _allStrategies
396
+ noStrategyAvailable . current = strategies . length === 0
393
397
394
- const _form = { ...formData }
395
- _form . strategies = strategies
396
- if ( cdPipelineId ) {
397
- getCDPipeline ( _form , dockerRegistries )
398
- } else {
399
- getEnvCDPipelineName ( _form )
400
- if ( strategies . length > 0 ) {
401
- const defaultStrategy = strategies . find ( ( strategy ) => strategy . default )
402
- handleStrategy ( defaultStrategy . deploymentTemplate )
398
+ if ( cdPipelineId ) {
399
+ const _form = { ...formData }
400
+ _form . strategies = strategies
401
+ getCDPipeline ( _form , dockerRegistries )
402
+ } else {
403
+ if ( strategies . length > 0 ) {
404
+ const defaultStrategy = strategies . find ( ( strategy ) => strategy . default )
405
+ handleStrategy ( defaultStrategy . deploymentTemplate )
406
+ }
407
+
408
+ setFormData ( ( prevState ) => ( {
409
+ ...prevState ,
410
+ ...newPipelineNameAndEnvironments ,
411
+ strategies,
412
+ } ) )
413
+
414
+ setPageState ( ViewType . FORM )
415
+ setIsAdvanced ( false )
403
416
}
404
- }
405
417
406
- setGlobalVariables ( globalVariablesOptions )
407
- setDockerRegistries ( dockerRegistries )
408
- } )
418
+ setGlobalVariables ( globalVariablesOptions )
419
+ setDockerRegistries ( dockerRegistries )
420
+ } ,
421
+ )
409
422
. catch ( ( error : ServerErrors ) => {
410
423
showError ( error )
411
424
setErrorCode ( error . code )
0 commit comments