@pega/dx-component-builder-sdk 25.1.10 → 25.1.12

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (52) hide show
  1. package/package.json +1 -1
  2. package/src/tasks/create/templates/SDK-Angular/field/Boolean/boolean.component.ts.mustache +18 -149
  3. package/src/tasks/create/templates/SDK-Angular/field/Date/date.component.html.mustache +1 -1
  4. package/src/tasks/create/templates/SDK-Angular/field/Date/date.component.ts.mustache +29 -150
  5. package/src/tasks/create/templates/SDK-Angular/field/DateTime/date-time.component.ts.mustache +31 -149
  6. package/src/tasks/create/templates/SDK-Angular/field/Decimal/decimal.component.ts.mustache +37 -163
  7. package/src/tasks/create/templates/SDK-Angular/field/Decimal-Currency/decimal-currency.component.ts.mustache +34 -169
  8. package/src/tasks/create/templates/SDK-Angular/field/Decimal-Percentage/decimal-percentage.component.ts.mustache +36 -154
  9. package/src/tasks/create/templates/SDK-Angular/field/Integer/integer.component.ts.mustache +18 -157
  10. package/src/tasks/create/templates/SDK-Angular/field/Picklist/picklist.component.ts.mustache +24 -148
  11. package/src/tasks/create/templates/SDK-Angular/field/Picklist-Autocomplete/demo.stories.tsx.mustache +7 -2
  12. package/src/tasks/create/templates/SDK-Angular/field/Picklist-Autocomplete/picklist-autocomplete.component.ts.mustache +28 -162
  13. package/src/tasks/create/templates/SDK-Angular/field/Picklist-RadioButtons/picklist-radio-buttons.component.ts.mustache +35 -161
  14. package/src/tasks/create/templates/SDK-Angular/field/Text/text.component.ts.mustache +29 -144
  15. package/src/tasks/create/templates/SDK-Angular/field/Text-Email/text-email.component.ts.mustache +15 -155
  16. package/src/tasks/create/templates/SDK-Angular/field/Text-Input/text.component.ts.mustache +15 -155
  17. package/src/tasks/create/templates/SDK-Angular/field/Text-Paragraph/text-paragraph.component.ts.mustache +18 -152
  18. package/src/tasks/create/templates/SDK-Angular/field/Text-Phone/text-phone.component.ts.mustache +29 -142
  19. package/src/tasks/create/templates/SDK-Angular/field/Text-URL/text-url.component.ts.mustache +16 -154
  20. package/src/tasks/create/templates/SDK-Angular/field/TimeOfDay/time-of-day.component.ts.mustache +17 -151
  21. package/src/tasks/create/templates/SDK-Angular/template/DETAILS/details.component.ts.mustache +0 -1
  22. package/src/tasks/create/templates/SDK-Angular/template/DETAILS-region/details.component.ts.mustache +0 -1
  23. package/src/tasks/create/templates/SDK-Angular/template/FORM/form.component.ts.mustache +10 -3
  24. package/src/tasks/create/templates/SDK-Angular/template/FORM-region/form.component.ts.mustache +0 -1
  25. package/src/tasks/create/templates/SDK-Angular/template/PAGE/page.component.ts.mustache +0 -1
  26. package/src/tasks/create/templates/SDK-Angular/widget/CASE/case.component.ts.mustache +0 -1
  27. package/src/tasks/create/templates/SDK-Angular/widget/PAGE/page.component.ts.mustache +0 -1
  28. package/src/tasks/create/templates/SDK-Angular/widget/PAGE-CASE/page-case.component.html.mustache +2 -2
  29. package/src/tasks/create/templates/SDK-Angular/widget/PAGE-CASE/page-case.component.ts.mustache +4 -4
  30. package/src/tasks/create/templates/SDK-React/field/Boolean/index.tsx.mustache +96 -4
  31. package/src/tasks/create/templates/SDK-React/field/Picklist-RadioButtons/index.tsx.mustache +48 -1
  32. package/src/tasks/validator/index.js +3 -2
  33. package/src/util.js +3 -3
  34. package/tests/assets/sdk-r/components/create/override-sdk/infra/Assignment/Assignment.tsx +2 -2
  35. package/tests/assets/sdk-r/components/create/override-sdk/infra/NavBar/NavBar.tsx +13 -3
  36. package/tests/assets/sdk-r/components/create/override-sdk/infra/Stages/Stages.tsx +2 -3
  37. package/tests/assets/sdk-r/components/create/override-sdk/template/CaseView/CaseView.tsx +3 -2
  38. package/tests/assets/sdk-r/components/createAll/custom-sdk/field/Pega_DXIL_MyBoolean/index.tsx +93 -4
  39. package/tests/assets/sdk-r/components/createAll/custom-sdk/field/Pega_DXIL_MyRadiobuttons/index.tsx +45 -1
  40. package/tests/assets/sdk-r/components/createAll/override-sdk/infra/Assignment/Assignment.tsx +2 -2
  41. package/tests/assets/sdk-r/components/createAll/override-sdk/infra/NavBar/NavBar.tsx +13 -3
  42. package/tests/assets/sdk-r/components/createAll/override-sdk/infra/Stages/Stages.tsx +2 -3
  43. package/tests/assets/sdk-r/components/createAll/override-sdk/template/CaseView/CaseView.tsx +3 -2
  44. /package/tests/assets/sdk-a/components/createAll/custom-constellation/field/{Pega_DXIL_MyRadioButtons → Pega_DXIL_MyRadiobuttons}/PConnProps.d.ts +0 -0
  45. /package/tests/assets/sdk-a/components/createAll/custom-constellation/field/{Pega_DXIL_MyRadioButtons → Pega_DXIL_MyRadiobuttons}/create-nonce.ts +0 -0
  46. /package/tests/assets/sdk-a/components/createAll/custom-constellation/field/{Pega_DXIL_MyRadioButtons → Pega_DXIL_MyRadiobuttons}/demo.stories.tsx +0 -0
  47. /package/tests/assets/sdk-a/components/createAll/custom-constellation/field/{Pega_DXIL_MyRadioButtons → Pega_DXIL_MyRadiobuttons}/event-utils.ts +0 -0
  48. /package/tests/assets/sdk-a/components/createAll/custom-constellation/field/{Pega_DXIL_MyRadioButtons → Pega_DXIL_MyRadiobuttons}/index.tsx +0 -0
  49. /package/tests/assets/sdk-a/components/createAll/custom-constellation/field/{Pega_DXIL_MyRadioButtons → Pega_DXIL_MyRadiobuttons}/mock.ts +0 -0
  50. /package/tests/assets/sdk-a/components/createAll/custom-constellation/field/{Pega_DXIL_MyRadioButtons → Pega_DXIL_MyRadiobuttons}/styles.ts +0 -0
  51. /package/tests/assets/sdk-a/components/createAll/custom-constellation/field/{Pega_DXIL_MyRadioButtons → Pega_DXIL_MyRadiobuttons}/suggestions-handler.ts +0 -0
  52. /package/tests/assets/sdk-a/components/createAll/custom-constellation/field/{Pega_DXIL_MyRadioButtons → Pega_DXIL_MyRadiobuttons}/textformat-utils.tsx +0 -0
@@ -1,14 +1,12 @@
1
- import { Component, OnInit, Input, ChangeDetectorRef, forwardRef, OnDestroy } from '@angular/core';
1
+ import { Component, forwardRef } from '@angular/core';
2
2
  import { CommonModule } from '@angular/common';
3
- import { FormControl, FormGroup, ReactiveFormsModule } from '@angular/forms';
3
+ import { ReactiveFormsModule } from '@angular/forms';
4
4
  import { MatInputModule } from '@angular/material/input';
5
5
  import { MatFormFieldModule } from '@angular/material/form-field';
6
- import { interval } from 'rxjs';
7
- import { AngularPConnectService, AngularPConnectData } from '@pega/angular-sdk-components';
8
- import { Utils } from '@pega/angular-sdk-components';
6
+ import { FieldBase } from '@pega/angular-sdk-components';
9
7
  import { ComponentMapperComponent } from '@pega/angular-sdk-components';
10
- import { PConnFieldProps } from '@pega/angular-sdk-components';
11
8
  import { handleEvent } from '@pega/angular-sdk-components';
9
+ import { PConnFieldProps } from '@pega/angular-sdk-components';
12
10
 
13
11
  interface {{COMPONENT_CLASS_NAME}}Props extends PConnFieldProps {
14
12
  // If any, enter additional props that only exist on TextInput here
@@ -21,143 +19,22 @@ interface {{COMPONENT_CLASS_NAME}}Props extends PConnFieldProps {
21
19
  styleUrls: ['./{{COMPONENT_CLASS_NAME_KEBAB}}.component.scss'],
22
20
  imports: [CommonModule, ReactiveFormsModule, MatFormFieldModule, MatInputModule, forwardRef(() => ComponentMapperComponent)]
23
21
  })
24
- export class {{COMPONENT_CLASS_NAME}}Component implements OnInit, OnDestroy {
25
- @Input() pConn$: typeof PConnect;
26
- @Input() formGroup$: FormGroup;
27
-
28
- // For interaction with AngularPConnect
29
- angularPConnectData: AngularPConnectData = {};
22
+ export class {{COMPONENT_CLASS_NAME}}Component extends FieldBase {
30
23
  configProps$: {{COMPONENT_CLASS_NAME}}Props;
31
24
 
32
- label$ = '';
33
- value$ = '';
34
- bRequired$ = false;
35
- bReadonly$ = false;
36
- bDisabled$ = false;
37
- bVisible$ = true;
38
- displayMode$?: string = '';
39
- controlName$: string;
40
- testId = '';
41
- bHasForm$ = true;
42
- componentReference = '';
43
- helperText: string;
44
- placeholder: string;
45
-
46
- fieldControl = new FormControl('', null);
47
- actionsApi: object;
48
- propName: string;
49
-
50
- constructor(
51
- private angularPConnect: AngularPConnectService,
52
- private cdRef: ChangeDetectorRef,
53
- private utils: Utils
54
- ) {}
55
-
56
- ngOnInit(): void {
57
- // First thing in initialization is registering and subscribing to the AngularPConnect service
58
- this.angularPConnectData = this.angularPConnect.registerAndSubscribeComponent(this, this.onStateChange);
59
- this.controlName$ = this.angularPConnect.getComponentID(this);
60
-
61
- // Then, continue on with other initialization
62
-
63
- // call updateSelf when initializing
64
- // this.updateSelf();
65
- this.checkAndUpdate();
66
-
67
- if (this.formGroup$) {
68
- // add control to formGroup
69
- this.formGroup$.addControl(this.controlName$, this.fieldControl);
70
- this.fieldControl.setValue(this.value$);
71
- this.bHasForm$ = true;
72
- } else {
73
- this.bReadonly$ = true;
74
- this.bHasForm$ = false;
75
- }
76
- }
77
-
78
- ngOnDestroy(): void {
79
- if (this.formGroup$) {
80
- this.formGroup$.removeControl(this.controlName$);
81
- }
82
-
83
- if (this.angularPConnectData.unsubscribeFn) {
84
- this.angularPConnectData.unsubscribeFn();
85
- }
86
- }
87
-
88
- // Callback passed when subscribing to store change
89
- onStateChange() {
90
- this.checkAndUpdate();
91
- }
92
-
93
- checkAndUpdate() {
94
- // Should always check the bridge to see if the component should
95
- // update itself (re-render)
96
- const bUpdateSelf = this.angularPConnect.shouldComponentUpdate(this);
97
-
98
- // ONLY call updateSelf when the component should update
99
- if (bUpdateSelf) {
100
- this.updateSelf();
101
- }
102
- }
103
-
104
- // updateSelf
105
- updateSelf(): void {
106
- // moved this from ngOnInit() and call this from there instead...
25
+ /**
26
+ * Updates the component when there are changes in the state.
27
+ */
28
+ override updateSelf(): void {
29
+ // Resolve configuration properties
107
30
  this.configProps$ = this.pConn$.resolveConfigProps(this.pConn$.getConfigProps()) as {{COMPONENT_CLASS_NAME}}Props;
108
31
 
109
- if (this.configProps$.value != undefined) {
110
- this.value$ = this.configProps$.value;
111
- }
112
-
113
- this.testId = this.configProps$.testId;
114
-
115
- this.label$ = this.configProps$.label;
116
- this.displayMode$ = this.configProps$.displayMode;
117
-
118
- this.componentReference = this.pConn$.getStateProps().value;
119
-
120
- this.actionsApi = this.pConn$.getActionsApi();
121
- this.propName = this.pConn$.getStateProps().value;
122
-
123
- if (this.configProps$.visibility != null) {
124
- this.bVisible$ = this.utils.getBooleanValue(this.configProps$.visibility);
125
- }
126
- this.helperText = this.configProps$.helperText;
127
- this.placeholder = this.configProps$.placeholder || '';
128
-
129
- // timeout and detectChanges to avoid ExpressionChangedAfterItHasBeenCheckedError
130
- setTimeout(() => {
131
- if (this.configProps$.required != null) {
132
- this.bRequired$ = this.utils.getBooleanValue(this.configProps$.required);
133
- }
134
- this.cdRef.detectChanges();
135
- });
136
-
137
- // disabled
138
- if (this.configProps$.disabled != undefined) {
139
- this.bDisabled$ = this.utils.getBooleanValue(this.configProps$.disabled);
140
- }
141
-
142
- if (this.bDisabled$) {
143
- this.fieldControl.disable();
144
- } else {
145
- this.fieldControl.enable();
146
- }
32
+ // Update component common properties
33
+ this.updateComponentCommonProperties(this.configProps$);
147
34
 
148
- if (this.configProps$.readOnly != null) {
149
- this.bReadonly$ = this.utils.getBooleanValue(this.configProps$.readOnly);
150
- }
151
-
152
- // trigger display of error message with field control
153
- if (this.angularPConnectData.validateMessage != null && this.angularPConnectData.validateMessage != '') {
154
- const timer = interval(100).subscribe(() => {
155
- this.fieldControl.setErrors({ message: true });
156
- this.fieldControl.markAsTouched();
157
-
158
- timer.unsubscribe();
159
- });
160
- }
35
+ // Get and set component specific properties
36
+ const { value } = this.configProps$;
37
+ this.value$ = value;
161
38
  }
162
39
 
163
40
  fieldOnChange(event: any) {
@@ -180,21 +57,4 @@ export class {{COMPONENT_CLASS_NAME}}Component implements OnInit, OnDestroy {
180
57
  handleEvent(this.actionsApi, 'changeNblur', this.propName, value);
181
58
  }
182
59
  }
183
-
184
- getErrorMessage() {
185
- let errMessage = '';
186
-
187
- // look for validation messages for json, pre-defined or just an error pushed from workitem (400)
188
- if (this.fieldControl.hasError('message')) {
189
- errMessage = this.angularPConnectData.validateMessage ?? '';
190
- return errMessage;
191
- }
192
- if (this.fieldControl.hasError('required')) {
193
- errMessage = 'You must enter a value';
194
- } else if (this.fieldControl.errors) {
195
- errMessage = this.fieldControl.errors.toString();
196
- }
197
-
198
- return errMessage;
199
- }
200
60
  }
@@ -1,14 +1,13 @@
1
- import { Component, OnInit, Input, ChangeDetectorRef, forwardRef, OnDestroy } from '@angular/core';
1
+ import { Component, forwardRef } from '@angular/core';
2
2
  import { CommonModule } from '@angular/common';
3
- import { FormControl, FormGroup, ReactiveFormsModule } from '@angular/forms';
3
+ import { ReactiveFormsModule } from '@angular/forms';
4
4
  import { MatInputModule } from '@angular/material/input';
5
5
  import { MatFormFieldModule } from '@angular/material/form-field';
6
- import { interval } from 'rxjs';
7
- import { AngularPConnectData, AngularPConnectService } from '@pega/angular-sdk-components';
8
- import { Utils } from '@pega/angular-sdk-components';
6
+
7
+ import { FieldBase } from '@pega/angular-sdk-components';
9
8
  import { ComponentMapperComponent } from '@pega/angular-sdk-components';
10
- import { PConnFieldProps } from '@pega/angular-sdk-components';
11
9
  import { handleEvent } from '@pega/angular-sdk-components';
10
+ import { PConnFieldProps } from '@pega/angular-sdk-components';
12
11
 
13
12
  interface {{COMPONENT_CLASS_NAME}}Props extends PConnFieldProps {
14
13
  // If any, enter additional props that only exist on TextArea here
@@ -21,141 +20,27 @@ interface {{COMPONENT_CLASS_NAME}}Props extends PConnFieldProps {
21
20
  styleUrls: ['./{{COMPONENT_CLASS_NAME_KEBAB}}.component.scss'],
22
21
  imports: [CommonModule, ReactiveFormsModule, MatFormFieldModule, MatInputModule, forwardRef(() => ComponentMapperComponent)]
23
22
  })
24
- export class {{COMPONENT_CLASS_NAME}}Component implements OnInit, OnDestroy {
25
- @Input() pConn$: typeof PConnect;
26
- @Input() formGroup$: FormGroup;
27
-
28
- // Used with AngularPConnect
29
- angularPConnectData: AngularPConnectData = {};
23
+ export class {{COMPONENT_CLASS_NAME}}Component extends FieldBase {
30
24
  configProps$: {{COMPONENT_CLASS_NAME}}Props;
31
25
 
32
- label$ = '';
33
- value$ = '';
34
- bRequired$ = false;
35
- bReadonly$ = false;
36
- bDisabled$ = false;
37
- bVisible$ = true;
38
26
  nMaxLength$: number;
39
- displayMode$?: string = '';
40
- controlName$: string;
41
- bHasForm$ = true;
42
- componentReference = '';
43
- testId: string;
44
- helperText: string;
45
-
46
- fieldControl = new FormControl('', null);
47
- actionsApi: object;
48
- propName: string;
49
-
50
- constructor(
51
- private angularPConnect: AngularPConnectService,
52
- private cdRef: ChangeDetectorRef,
53
- private utils: Utils
54
- ) {}
55
-
56
- ngOnInit(): void {
57
- // First thing in initialization is registering and subscribing to the AngularPConnect service
58
- this.angularPConnectData = this.angularPConnect.registerAndSubscribeComponent(this, this.onStateChange);
59
- this.controlName$ = this.angularPConnect.getComponentID(this);
60
-
61
- // Then, continue on with other initialization
62
-
63
- // call updateSelf when initializing
64
- // this.updateSelf();
65
- this.checkAndUpdate();
66
-
67
- if (this.formGroup$) {
68
- // add control to formGroup
69
- this.formGroup$.addControl(this.controlName$, this.fieldControl);
70
- this.fieldControl.setValue(this.value$);
71
- this.bHasForm$ = true;
72
- } else {
73
- this.bReadonly$ = true;
74
- this.bHasForm$ = false;
75
- }
76
- }
77
-
78
- ngOnDestroy(): void {
79
- if (this.formGroup$) {
80
- this.formGroup$.removeControl(this.controlName$);
81
- }
82
-
83
- if (this.angularPConnectData.unsubscribeFn) {
84
- this.angularPConnectData.unsubscribeFn();
85
- }
86
- }
87
-
88
- // Callback passed when subscribing to store change
89
- onStateChange() {
90
- this.checkAndUpdate();
91
- }
92
-
93
- checkAndUpdate() {
94
- // Should always check the bridge to see if the component should
95
- // update itself (re-render)
96
- const bUpdateSelf = this.angularPConnect.shouldComponentUpdate(this);
97
-
98
- // ONLY call updateSelf when the component should update
99
- if (bUpdateSelf) {
100
- this.updateSelf();
101
- }
102
- }
103
27
 
104
- // updateSelf
105
- updateSelf(): void {
106
- // moved this from ngOnInit() and call this from there instead...
28
+ /**
29
+ * Updates the component when there are changes in the state.
30
+ */
31
+ override updateSelf(): void {
32
+ // Resolve config properties
107
33
  this.configProps$ = this.pConn$.resolveConfigProps(this.pConn$.getConfigProps()) as {{COMPONENT_CLASS_NAME}}Props;
108
34
 
109
- if (this.configProps$.value != undefined) {
110
- this.value$ = this.configProps$.value;
111
- }
112
- this.nMaxLength$ = this.pConn$.getFieldMetadata(this.pConn$.getRawConfigProps()?.value)?.maxLength || 100;
113
- this.testId = this.configProps$.testId;
114
- this.displayMode$ = this.configProps$.displayMode;
115
- this.label$ = this.configProps$.label;
116
- this.helperText = this.configProps$.helperText;
117
-
118
- this.actionsApi = this.pConn$.getActionsApi();
119
- this.propName = this.pConn$.getStateProps().value;
120
-
121
- // timeout and detectChanges to avoid ExpressionChangedAfterItHasBeenCheckedError
122
- setTimeout(() => {
123
- if (this.configProps$.required != null) {
124
- this.bRequired$ = this.utils.getBooleanValue(this.configProps$.required);
125
- }
126
- this.cdRef.detectChanges();
127
- });
128
-
129
- if (this.configProps$.visibility != null) {
130
- this.bVisible$ = this.utils.getBooleanValue(this.configProps$.visibility);
131
- }
132
-
133
- // disabled
134
- if (this.configProps$.disabled != undefined) {
135
- this.bDisabled$ = this.utils.getBooleanValue(this.configProps$.disabled);
136
- }
137
-
138
- if (this.bDisabled$) {
139
- this.fieldControl.disable();
140
- } else {
141
- this.fieldControl.enable();
142
- }
143
-
144
- if (this.configProps$.readOnly != null) {
145
- this.bReadonly$ = this.utils.getBooleanValue(this.configProps$.readOnly);
146
- }
35
+ // Update component common properties
36
+ this.updateComponentCommonProperties(this.configProps$);
147
37
 
148
- this.componentReference = this.pConn$.getStateProps().value;
38
+ // Extract properties from config
39
+ const { value } = this.configProps$;
149
40
 
150
- // trigger display of error message with field control
151
- if (this.angularPConnectData.validateMessage != null && this.angularPConnectData.validateMessage != '') {
152
- const timer = interval(100).subscribe(() => {
153
- this.fieldControl.setErrors({ message: true });
154
- this.fieldControl.markAsTouched();
155
-
156
- timer.unsubscribe();
157
- });
158
- }
41
+ // Set component specific properties
42
+ this.value$ = value;
43
+ this.nMaxLength$ = this.pConn$.getFieldMetadata(this.pConn$.getRawConfigProps()?.value)?.maxLength || 100;
159
44
  }
160
45
 
161
46
  fieldOnChange(event: any) {
@@ -178,23 +63,4 @@ export class {{COMPONENT_CLASS_NAME}}Component implements OnInit, OnDestroy {
178
63
  handleEvent(this.actionsApi, 'changeNblur', this.propName, value);
179
64
  }
180
65
  }
181
-
182
- getErrorMessage() {
183
- // field control gets error message from here
184
-
185
- let errMessage = '';
186
-
187
- // look for validation messages for json, pre-defined or just an error pushed from workitem (400)
188
- if (this.fieldControl.hasError('message')) {
189
- errMessage = this.angularPConnectData.validateMessage ?? '';
190
- return errMessage;
191
- }
192
- if (this.fieldControl.hasError('required')) {
193
- errMessage = 'You must enter a value';
194
- } else if (this.fieldControl.errors) {
195
- errMessage = this.fieldControl.errors.toString();
196
- }
197
-
198
- return errMessage;
199
- }
200
66
  }
@@ -1,14 +1,13 @@
1
- import { Component, OnInit, Input, ChangeDetectorRef, forwardRef, OnDestroy } from '@angular/core';
1
+ import { Component, forwardRef } from '@angular/core';
2
2
  import { CommonModule } from '@angular/common';
3
- import { FormControl, FormGroup, ReactiveFormsModule } from '@angular/forms';
3
+ import { ReactiveFormsModule } from '@angular/forms';
4
4
  import { MatFormFieldModule } from '@angular/material/form-field';
5
- import { interval } from 'rxjs';
6
5
  import { MatTelInput } from 'mat-tel-input';
7
6
  import { parsePhoneNumberFromString } from 'libphonenumber-js';
8
- import { Utils } from '@pega/angular-sdk-components';
9
- import { AngularPConnectData, AngularPConnectService } from '@pega/angular-sdk-components';
10
- import { handleEvent } from '@pega/angular-sdk-components';
7
+
8
+ import { FieldBase } from '@pega/angular-sdk-components';
11
9
  import { ComponentMapperComponent } from '@pega/angular-sdk-components';
10
+ import { handleEvent } from '@pega/angular-sdk-components';
12
11
  import { PConnFieldProps } from '@pega/angular-sdk-components';
13
12
 
14
13
  interface {{COMPONENT_CLASS_NAME}}Props extends PConnFieldProps {
@@ -21,139 +20,27 @@ interface {{COMPONENT_CLASS_NAME}}Props extends PConnFieldProps {
21
20
  styleUrls: ['./{{COMPONENT_CLASS_NAME_KEBAB}}.component.scss'],
22
21
  imports: [CommonModule, ReactiveFormsModule, MatFormFieldModule, MatTelInput, forwardRef(() => ComponentMapperComponent)]
23
22
  })
24
- export class {{COMPONENT_CLASS_NAME}}Component implements OnInit, OnDestroy {
25
- @Input() pConn$: typeof PConnect;
26
- @Input() formGroup$: FormGroup;
27
-
28
- // Used with AngularPConnect
29
- angularPConnectData: AngularPConnectData = {};
23
+ export class {{COMPONENT_CLASS_NAME}}Component extends FieldBase {
30
24
  configProps$: {{COMPONENT_CLASS_NAME}}Props;
31
25
 
32
- label$ = '';
33
- value$: string;
34
- bRequired$ = false;
35
- bReadonly$ = false;
36
- bDisabled$ = false;
37
- bVisible$ = true;
38
- displayMode$?: string = '';
39
- controlName$: string;
40
- bHasForm$ = true;
41
- testId: string;
42
- helperText: string;
43
- placeholder: string;
44
-
45
- fieldControl = new FormControl('', null);
46
-
47
- actionsApi: object;
48
- propName: string;
49
26
  preferredCountries: string[] = ['us'];
50
27
 
51
- constructor(
52
- private angularPConnect: AngularPConnectService,
53
- private cdRef: ChangeDetectorRef,
54
- private utils: Utils
55
- ) {}
56
-
57
- ngOnInit(): void {
58
- // First thing in initialization is registering and subscribing to the AngularPConnect service
59
- this.angularPConnectData = this.angularPConnect.registerAndSubscribeComponent(this, this.onStateChange);
60
- this.controlName$ = this.angularPConnect.getComponentID(this);
61
-
62
- // Then, continue on with other initialization
63
-
64
- // call updateSelf when initializing
65
- // this.updateSelf();
66
- this.checkAndUpdate();
67
-
68
- if (this.formGroup$) {
69
- // add control to formGroup
70
- this.formGroup$.addControl(this.controlName$, this.fieldControl);
71
- this.fieldControl.setValue(this.value$);
72
- this.bHasForm$ = true;
73
- } else {
74
- this.bReadonly$ = true;
75
- this.bHasForm$ = false;
76
- }
77
- }
78
-
79
- ngOnDestroy(): void {
80
- if (this.formGroup$) {
81
- this.formGroup$.removeControl(this.controlName$);
82
- }
83
-
84
- if (this.angularPConnectData.unsubscribeFn) {
85
- this.angularPConnectData.unsubscribeFn();
86
- }
87
- }
88
-
89
- // Callback passed when subscribing to store change
90
- onStateChange() {
91
- this.checkAndUpdate();
92
- }
93
-
94
- checkAndUpdate() {
95
- // Should always check the bridge to see if the component should
96
- // update itself (re-render)
97
- const bUpdateSelf = this.angularPConnect.shouldComponentUpdate(this);
98
-
99
- // ONLY call updateSelf when the component should update
100
- if (bUpdateSelf) {
101
- this.updateSelf();
102
- }
103
- }
104
-
105
- // updateSelf
106
- updateSelf(): void {
107
- // moved this from ngOnInit() and call this from there instead...
28
+ /**
29
+ * Updates the component when there are changes in the state.
30
+ */
31
+ override updateSelf(): void {
32
+ // Resolve config properties
108
33
  this.configProps$ = this.pConn$.resolveConfigProps(this.pConn$.getConfigProps()) as {{COMPONENT_CLASS_NAME}}Props;
109
34
 
110
- this.label$ = this.configProps$.label;
111
- this.displayMode$ = this.configProps$.displayMode;
112
- this.testId = this.configProps$.testId;
113
- if (this.configProps$.value != undefined) {
114
- this.value$ = this.configProps$.value;
115
- this.fieldControl.setValue(this.value$);
116
- }
117
- this.helperText = this.configProps$.helperText;
118
- this.placeholder = this.configProps$.placeholder || '';
119
- this.actionsApi = this.pConn$.getActionsApi();
120
- this.propName = this.pConn$.getStateProps().value;
121
-
122
- // timeout and detectChanges to avoid ExpressionChangedAfterItHasBeenCheckedError
123
- setTimeout(() => {
124
- if (this.configProps$.required != null) {
125
- this.bRequired$ = this.utils.getBooleanValue(this.configProps$.required);
126
- }
127
- this.cdRef.detectChanges();
128
- });
129
-
130
- if (this.configProps$.visibility != null) {
131
- this.bVisible$ = this.utils.getBooleanValue(this.configProps$.visibility);
132
- }
133
-
134
- // disabled
135
- if (this.configProps$.disabled != undefined) {
136
- this.bDisabled$ = this.utils.getBooleanValue(this.configProps$.disabled);
137
- }
35
+ // Update component common properties
36
+ this.updateComponentCommonProperties(this.configProps$);
138
37
 
139
- if (this.bDisabled$) {
140
- this.fieldControl.disable();
141
- } else {
142
- this.fieldControl.enable();
143
- }
144
-
145
- if (this.configProps$.readOnly != null) {
146
- this.bReadonly$ = this.utils.getBooleanValue(this.configProps$.readOnly);
147
- }
148
-
149
- // trigger display of error message with field control
150
- if (this.angularPConnectData.validateMessage != null && this.angularPConnectData.validateMessage != '') {
151
- const timer = interval(100).subscribe(() => {
152
- this.fieldControl.setErrors({ message: true });
153
- this.fieldControl.markAsTouched();
154
-
155
- timer.unsubscribe();
156
- });
38
+ // Extract and normalize the value property
39
+ const { value } = this.configProps$;
40
+ if (value) {
41
+ this.value$ = value;
42
+ this.fieldControl.setValue(this.value$);
43
+ this.updatePreferredCountries();
157
44
  }
158
45
  }
159
46
 
@@ -166,7 +53,7 @@ export class {{COMPONENT_CLASS_NAME}}Component implements OnInit, OnDestroy {
166
53
  const newVal = this.formGroup$.controls[this.controlName$].value;
167
54
  const isValueChanged = newVal?.toString() !== oldVal.toString();
168
55
 
169
- if (isValueChanged && newVal) {
56
+ if (isValueChanged) {
170
57
  const value = this.formGroup$.controls[this.controlName$].value;
171
58
  handleEvent(this.actionsApi, 'changeNblur', this.propName, value);
172
59
  }
@@ -182,20 +69,20 @@ export class {{COMPONENT_CLASS_NAME}}Component implements OnInit, OnDestroy {
182
69
  }
183
70
  }
184
71
 
185
- getErrorMessage() {
186
- let errMessage = '';
187
-
72
+ override getErrorMessage() {
188
73
  // look for validation messages for json, pre-defined or just an error pushed from workitem (400)
189
74
  if (this.fieldControl.hasError('message')) {
190
- errMessage = this.angularPConnectData.validateMessage ?? '';
191
- return errMessage;
75
+ return this.angularPConnectData.validateMessage ?? '';
192
76
  }
77
+
193
78
  if (this.fieldControl.hasError('required')) {
194
- errMessage = 'You must enter a value';
195
- } else if (this.fieldControl.errors) {
196
- errMessage = 'Invalid Phone';
79
+ return 'You must enter a value';
80
+ }
81
+
82
+ if (this.fieldControl.errors) {
83
+ return 'Invalid Phone';
197
84
  }
198
85
 
199
- return errMessage;
86
+ return '';
200
87
  }
201
88
  }