1
1
// Angular imports
2
- import { Directive , ElementRef , OnInit , Type , ViewChild } from '@angular/core' ;
3
- import { FormBuilder , FormGroup } from '@angular/forms' ;
4
- import { Router } from '@angular/router' ;
5
- import { Title } from '@angular/platform-browser' ;
2
+ import { Directive , ElementRef , OnInit , Type , ViewChild } from '@angular/core' ;
3
+ import { FormBuilder , FormGroup } from '@angular/forms' ;
4
+ import { Router } from '@angular/router' ;
5
+ import { Title } from '@angular/platform-browser' ;
6
6
// Third party imports
7
- import { takeUntil } from 'rxjs/operators' ;
8
- import { Observable } from 'rxjs' ;
7
+ import { takeUntil } from 'rxjs/operators' ;
8
+ import { Observable } from 'rxjs' ;
9
9
// App imports
10
- import { APP_ROUTES , Routes } from 'src/app/shared/constants/routes.constants' ;
10
+ import { APP_ROUTES , Routes } from 'src/app/shared/constants/routes.constants' ;
11
11
import AppServices from '../../../../../shared/service/appServices' ;
12
- import { BasicSubscriber } from 'src/app/shared/abstracts/basic-subscriber' ;
13
- import { CeipField } from '../components/steps/ceip-step/ceip-step.fieldmapping' ;
14
- import { ClusterType , IdentityManagementType , WizardForm } from "../constants/wizard.constants" ;
15
- import { ConfigFileInfo } from '../../../../../swagger/models/config-file-info.model' ;
16
- import { EditionData } from '../../../../../shared/service/branding.service' ;
17
- import { FieldMapping } from '../field-mapping/FieldMapping' ;
18
- import { FormDataForHTML , FormUtility } from '../components/steps/form-utility' ;
19
- import { IdentityField } from '../components/steps/identity-step/identity-step.fieldmapping' ;
12
+ import { BasicSubscriber } from 'src/app/shared/abstracts/basic-subscriber' ;
13
+ import { CeipField } from '../components/steps/ceip-step/ceip-step.fieldmapping' ;
14
+ import { ClusterType , IdentityManagementType , WizardForm } from "../constants/wizard.constants" ;
15
+ import { ConfigFileInfo } from '../../../../../swagger/models/config-file-info.model' ;
16
+ import { EditionData } from '../../../../../shared/service/branding.service' ;
17
+ import { FieldMapping } from '../field-mapping/FieldMapping' ;
18
+ import { FormDataForHTML , FormUtility } from '../components/steps/form-utility' ;
19
+ import { IdentityField } from '../components/steps/identity-step/identity-step.fieldmapping' ;
20
20
import {
21
21
LoadBalancerField ,
22
22
LoadBalancerStepMapping
23
23
} from '../components/steps/load-balancer/load-balancer-step.fieldmapping' ;
24
- import { MetadataField , MetadataStepMapping } from '../components/steps/metadata-step/metadata-step.fieldmapping' ;
25
- import { MetadataStepComponent } from '../components/steps/metadata-step/metadata-step.component' ;
26
- import { NetworkField } from '../components/steps/network-step/network-step.fieldmapping' ;
27
- import { OsImageField } from '../components/steps/os-image-step/os-image-step.fieldmapping' ;
28
- import { Providers , PROVIDERS } from 'src/app/shared/constants/app.constants' ;
29
- import { SharedCeipStepComponent } from '../components/steps/ceip-step/ceip-step.component' ;
30
- import { SharedIdentityStepComponent } from '../components/steps/identity-step/identity-step.component' ;
31
- import { SharedNetworkStepComponent } from '../components/steps/network-step/network-step.component' ;
32
- import { StepFormDirective } from '../step-form/step-form' ;
24
+ import { MetadataField , MetadataStepMapping } from '../components/steps/metadata-step/metadata-step.fieldmapping' ;
25
+ import { MetadataStepComponent } from '../components/steps/metadata-step/metadata-step.component' ;
26
+ import { NetworkField } from '../components/steps/network-step/network-step.fieldmapping' ;
27
+ import { OsImageField } from '../components/steps/os-image-step/os-image-step.fieldmapping' ;
28
+ import { Providers , PROVIDERS } from 'src/app/shared/constants/app.constants' ;
29
+ import { SharedCeipStepComponent } from '../components/steps/ceip-step/ceip-step.component' ;
30
+ import { SharedIdentityStepComponent } from '../components/steps/identity-step/identity-step.component' ;
31
+ import { SharedNetworkStepComponent } from '../components/steps/network-step/network-step.component' ;
32
+ import { StepFormDirective } from '../step-form/step-form' ;
33
33
import {
34
34
StepCompletedPayload ,
35
35
StepDescriptionChangePayload ,
36
36
StepStartedPayload ,
37
37
TanzuEventType
38
38
} from './../../../../../shared/service/Messenger' ;
39
- import { StepWrapperSetComponent } from '../step-wrapper/step-wrapper-set.component' ;
40
- import { NodeSettingField } from '../components/steps/node-setting-step/node-setting-step.fieldmapping' ;
39
+ import { StepWrapperSetComponent } from '../step-wrapper/step-wrapper-set.component' ;
40
+ import { NodeSettingField } from '../components/steps/node-setting-step/node-setting-step.fieldmapping' ;
41
41
42
42
// This interface describes a wizard that can register a step component
43
43
export interface WizardStepRegistrar {
@@ -64,6 +64,10 @@ export interface Label {
64
64
value : string
65
65
}
66
66
67
+ export interface KeyValueObject {
68
+ [ key : string ] : string
69
+ }
70
+
67
71
@Directive ( )
68
72
export abstract class WizardBaseDirective extends BasicSubscriber implements WizardStepRegistrar , OnInit {
69
73
APP_ROUTES : Routes = APP_ROUTES ;
@@ -343,14 +347,23 @@ export abstract class WizardBaseDirective extends BasicSubscriber implements Wiz
343
347
344
348
/**
345
349
* @param arrObj of type [ {key: 'a', value: '1}, {key : 'b, value:'2}]
346
- * @param key To Identify the ObjectKey
347
- * @param value To Identify the ObjectValue
348
- * @return Object {'a': 1 , 'b': '1'}
350
+ * @param params. key<Function> To Identify the ObjectKey
351
+ * @param params. value<Function> To Identify the ObjectValue
352
+ * @return Object {'a': 1 , 'b': '1'} and drops values with empty string on key
349
353
*/
350
- arrayOfObjectsToObject < T > ( arrObj : T [ ] , params : Params < T > ) : { [ key : string ] : string ; } {
351
- return arrObj && arrObj instanceof Array
352
- ? arrObj . reduce ( ( obj , item ) => ( ( obj [ params . key ( item ) ] = params . value ( item ) ) , obj ) , { } )
353
- : { } ;
354
+ arrayOfObjectsToObject < T > ( arrObj : T [ ] , params : Params < T > ) : KeyValueObject {
355
+ if ( ! arrObj || ! ( arrObj instanceof Array ) ) {
356
+ return { } ;
357
+ }
358
+
359
+ return arrObj . reduce < KeyValueObject > (
360
+ ( accum , item ) => {
361
+ const itemKey = params . key ( item ) ;
362
+ if ( itemKey ) {
363
+ accum [ itemKey ] = params . value ( item ) ;
364
+ }
365
+ return accum ;
366
+ } , { } ) ;
354
367
}
355
368
356
369
/**
@@ -537,6 +550,7 @@ export abstract class WizardBaseDirective extends BasicSubscriber implements Wiz
537
550
'name' : this . getFieldValue ( WizardForm . LOADBALANCER , LoadBalancerField . WORKLOAD_CLUSTER_CONTROL_PLANE_VIP_NETWORK_NAME ) ,
538
551
'cidr' : this . getFieldValue ( WizardForm . LOADBALANCER , LoadBalancerField . WORKLOAD_CLUSTER_CONTROL_PLANE_VIP_NETWORK_CIDR )
539
552
} ,
553
+ // thinking should cleanse formarray data in payload here, maybe an additional utility or add to arrayOfObjectsToObject
540
554
'labels' : this . arrayOfObjectsToObject < { key : string , value : string } > (
541
555
loadBalancerLabels ,
542
556
{
0 commit comments