@pega/angular-sdk-overrides 0.23.7 → 0.23.9

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.
@@ -6,36 +6,37 @@
6
6
  ></component-mapper>
7
7
  </div>
8
8
  <ng-template #noDisplayMode>
9
- <div *ngIf="!bReadonly$ && bHasForm$; else noEdit">
9
+ <div *ngIf="bHasForm$; else noEdit">
10
10
  <div [formGroup]="formGroup$" *ngIf="bVisible$">
11
11
  <div class="mat-form-field-infix" *ngIf="showLabel$">
12
12
  <span>
13
13
  <label class="mat-form-field-label psdk-label-readonly">{{ label$ }}</label>
14
14
  </span>
15
- <mat-checkbox
16
- [labelPosition]="'after'"
17
- [checked]="isChecked$"
18
- [disabled]="bDisabled$"
19
- [attr.data-test-id]="testId"
20
- [formControl]="fieldControl"
21
- (change)="fieldOnChange($event)"
22
- (blur)="fieldOnBlur($event)"
23
- >{{ caption$ }}</mat-checkbox
24
- >
25
15
  </div>
26
- <div class="mat-form-field-infix" *ngIf="!bReadonly$ && !showLabel$">
16
+ <div *ngIf="selectionMode === 'multi'; else single">
17
+ <mat-option *ngFor="let item of listOfCheckboxes" (click)="handleChangeMultiMode($event, item)">
18
+ <mat-checkbox
19
+ [labelPosition]="'after'"
20
+ [checked]="item.selected"
21
+ [attr.data-test-id]="testId + ':' + item.value"
22
+ (change)="handleChangeMultiMode($event, item)"
23
+ (blur)="fieldOnBlur($event)"
24
+ >{{ item.text ?? item.value }}
25
+ </mat-checkbox>
26
+ </mat-option>
27
+ </div>
28
+ <ng-template #single>
27
29
  <mat-checkbox
28
30
  [labelPosition]="'after'"
29
31
  [checked]="isChecked$"
30
- [disabled]="bDisabled$"
31
32
  [attr.data-test-id]="testId"
32
33
  [formControl]="fieldControl"
33
34
  (change)="fieldOnChange($event)"
34
35
  (blur)="fieldOnBlur($event)"
35
36
  >{{ caption$ }}</mat-checkbox
36
37
  >
37
- </div>
38
- <mat-hint *ngIf="helperText">{{ helperText }}</mat-hint>
38
+ <p *ngIf="helperText">{{ helperText }}</p>
39
+ </ng-template>
39
40
  <mat-error *ngIf="fieldControl.invalid">{{ getErrorMessage() }}</mat-error>
40
41
  </div>
41
42
  </div>
@@ -8,10 +8,10 @@
8
8
  top: 0rem;
9
9
  margin-top: 0.625rem;
10
10
  font-size: 0.875rem;
11
- display: block;
12
11
  transform: translateY(-1.28125em) scale(0.75) perspective(100px) translateZ(0.001px);
13
12
  -ms-transform: translateY(-1.28125em) scale(0.75);
14
13
  width: 133.33333%;
14
+ color: rgba(0, 0, 0, 0.6);
15
15
  }
16
16
 
17
17
  .psdk-data-readonly {
@@ -22,3 +22,16 @@
22
22
  ::ng-deep .mat-mdc-form-field-infix {
23
23
  width: auto;
24
24
  }
25
+
26
+ p {
27
+ font-size: 0.75rem;
28
+ color: rgba(0, 0, 0, 0.58);
29
+ }
30
+
31
+ mat-checkbox {
32
+ margin-left: -11px;
33
+ }
34
+
35
+ .mat-mdc-option {
36
+ margin-left: -16px;
37
+ }
@@ -3,10 +3,14 @@ import { CommonModule } from '@angular/common';
3
3
  import { FormControl, FormGroup, ReactiveFormsModule } from '@angular/forms';
4
4
  import { MatCheckboxModule } from '@angular/material/checkbox';
5
5
  import { MatFormFieldModule } from '@angular/material/form-field';
6
+ import { MatOptionModule } from '@angular/material/core';
7
+ import { interval } from 'rxjs';
6
8
  import { AngularPConnectData, AngularPConnectService } from '@pega/angular-sdk-components';
7
9
  import { Utils } from '@pega/angular-sdk-components';
8
10
  import { ComponentMapperComponent } from '@pega/angular-sdk-components';
9
11
  import { PConnFieldProps } from '@pega/angular-sdk-components';
12
+ import { deleteInstruction, insertInstruction, updateNewInstructions } from '@pega/angular-sdk-components';
13
+ import { handleEvent } from '@pega/angular-sdk-components';
10
14
 
11
15
  interface CheckboxProps extends Omit<PConnFieldProps, 'value'> {
12
16
  // If any, enter additional props that only exist on Checkbox here
@@ -15,6 +19,13 @@ interface CheckboxProps extends Omit<PConnFieldProps, 'value'> {
15
19
  caption?: string;
16
20
  trueLabel?: string;
17
21
  falseLabel?: string;
22
+ selectionMode?: string;
23
+ datasource?: any;
24
+ selectionKey?: string;
25
+ selectionList?: any;
26
+ primaryField: string;
27
+ readonlyContextList: any;
28
+ referenceList: string;
18
29
  }
19
30
 
20
31
  @Component({
@@ -22,7 +33,7 @@ interface CheckboxProps extends Omit<PConnFieldProps, 'value'> {
22
33
  templateUrl: './check-box.component.html',
23
34
  styleUrls: ['./check-box.component.scss'],
24
35
  standalone: true,
25
- imports: [CommonModule, ReactiveFormsModule, MatCheckboxModule, MatFormFieldModule, forwardRef(() => ComponentMapperComponent)]
36
+ imports: [CommonModule, ReactiveFormsModule, MatCheckboxModule, MatFormFieldModule, MatOptionModule, forwardRef(() => ComponentMapperComponent)]
26
37
  })
27
38
  export class CheckBoxComponent implements OnInit, OnDestroy {
28
39
  @Input() pConn$: typeof PConnect;
@@ -50,6 +61,17 @@ export class CheckBoxComponent implements OnInit, OnDestroy {
50
61
  trueLabel$?: string;
51
62
  falseLabel$?: string;
52
63
 
64
+ selectionMode?: string;
65
+ datasource?: any;
66
+ selectionKey?: string;
67
+ selectionList?: any;
68
+ primaryField: string;
69
+ selectedvalues: any;
70
+ referenceList: string;
71
+ listOfCheckboxes: any[] = [];
72
+ actionsApi: any;
73
+ propName: any;
74
+
53
75
  fieldControl = new FormControl('', null);
54
76
 
55
77
  constructor(
@@ -69,6 +91,11 @@ export class CheckBoxComponent implements OnInit, OnDestroy {
69
91
  // this.updateSelf();
70
92
  this.checkAndUpdate();
71
93
 
94
+ if (this.selectionMode === 'multi' && this.referenceList?.length > 0) {
95
+ this.pConn$.setReferenceList(this.selectionList);
96
+ updateNewInstructions(this.pConn$, this.selectionList);
97
+ }
98
+
72
99
  if (this.formGroup$) {
73
100
  // add control to formGroup
74
101
  this.formGroup$.addControl(this.controlName$, this.fieldControl);
@@ -111,68 +138,124 @@ export class CheckBoxComponent implements OnInit, OnDestroy {
111
138
  // moved this from ngOnInit() and call this from there instead...
112
139
  this.configProps$ = this.pConn$.resolveConfigProps(this.pConn$.getConfigProps()) as CheckboxProps;
113
140
 
114
- if (this.configProps$.value != undefined) {
115
- this.value$ = this.configProps$.value;
116
- }
117
141
  this.testId = this.configProps$.testId;
118
- this.label$ = this.configProps$.label;
119
142
  this.displayMode$ = this.configProps$.displayMode;
143
+ this.label$ = this.configProps$.label;
144
+ if (this.label$ != '') {
145
+ this.showLabel$ = true;
146
+ }
120
147
 
121
- this.caption$ = this.configProps$.caption;
122
- this.helperText = this.configProps$.helperText;
123
- this.trueLabel$ = this.configProps$.trueLabel;
124
- this.falseLabel$ = this.configProps$.falseLabel;
125
-
126
- // timeout and detectChanges to avoid ExpressionChangedAfterItHasBeenCheckedError
127
- setTimeout(() => {
128
- if (this.configProps$.required != null) {
129
- this.bRequired$ = this.utils.getBooleanValue(this.configProps$.required);
148
+ this.actionsApi = this.pConn$.getActionsApi();
149
+ this.propName = (this.pConn$.getStateProps() as any).value;
150
+
151
+ // multi case
152
+ this.selectionMode = this.configProps$.selectionMode;
153
+ if (this.selectionMode === 'multi') {
154
+ this.referenceList = this.configProps$.referenceList;
155
+ this.selectionList = this.configProps$.selectionList;
156
+ this.selectedvalues = this.configProps$.readonlyContextList;
157
+ this.primaryField = this.configProps$.primaryField;
158
+
159
+ this.datasource = this.configProps$.datasource;
160
+ this.selectionKey = this.configProps$.selectionKey;
161
+ const listSourceItems = this.datasource?.source ?? [];
162
+ const dataField: any = this.selectionKey?.split?.('.')[1];
163
+ const listToDisplay: any[] = [];
164
+ listSourceItems.forEach(element => {
165
+ element.selected = this.selectedvalues?.some?.(data => data[dataField] === element.key);
166
+ listToDisplay.push(element);
167
+ });
168
+ this.listOfCheckboxes = listToDisplay;
169
+ } else {
170
+ if (this.configProps$.value != undefined) {
171
+ this.value$ = this.configProps$.value;
130
172
  }
131
- this.cdRef.detectChanges();
132
- });
133
-
134
- if (this.configProps$.visibility != null) {
135
- this.bVisible$ = this.utils.getBooleanValue(this.configProps$.visibility);
136
- }
137
173
 
138
- // disabled
139
- if (this.configProps$.disabled != undefined) {
140
- this.bDisabled$ = this.utils.getBooleanValue(this.configProps$.disabled);
141
- }
174
+ this.caption$ = this.configProps$.caption;
175
+ this.helperText = this.configProps$.helperText;
176
+ this.trueLabel$ = this.configProps$.trueLabel;
177
+ this.falseLabel$ = this.configProps$.falseLabel;
178
+
179
+ // timeout and detectChanges to avoid ExpressionChangedAfterItHasBeenCheckedError
180
+ setTimeout(() => {
181
+ if (this.configProps$.required != null) {
182
+ this.bRequired$ = this.utils.getBooleanValue(this.configProps$.required);
183
+ }
184
+ this.cdRef.detectChanges();
185
+ });
186
+
187
+ if (this.configProps$.visibility != null) {
188
+ this.bVisible$ = this.utils.getBooleanValue(this.configProps$.visibility);
189
+ }
142
190
 
143
- if (this.bDisabled$) {
144
- this.fieldControl.disable();
145
- } else {
146
- this.fieldControl.enable();
147
- }
191
+ // disabled
192
+ if (this.configProps$.disabled != undefined) {
193
+ this.bDisabled$ = this.utils.getBooleanValue(this.configProps$.disabled);
194
+ }
148
195
 
149
- if (this.configProps$.readOnly != null) {
150
- this.bReadonly$ = this.utils.getBooleanValue(this.configProps$.readOnly);
151
- }
196
+ if (this.bDisabled$) {
197
+ this.fieldControl.disable();
198
+ } else {
199
+ this.fieldControl.enable();
200
+ }
152
201
 
153
- this.componentReference = (this.pConn$.getStateProps() as any).value;
202
+ if (this.configProps$.readOnly != null) {
203
+ this.bReadonly$ = this.utils.getBooleanValue(this.configProps$.readOnly);
204
+ this.fieldControl.disable();
205
+ }
154
206
 
155
- if (this.label$ != '') {
156
- this.showLabel$ = true;
157
- }
207
+ this.componentReference = (this.pConn$.getStateProps() as any).value;
158
208
 
159
- // eslint-disable-next-line sonarjs/no-redundant-boolean
160
- if (this.value$ === 'true' || this.value$ == true) {
161
- this.isChecked$ = true;
162
- } else {
163
- this.isChecked$ = false;
209
+ // eslint-disable-next-line sonarjs/no-redundant-boolean
210
+ if (this.value$ === 'true' || this.value$ == true) {
211
+ this.isChecked$ = true;
212
+ } else {
213
+ this.isChecked$ = false;
214
+ }
215
+ // trigger display of error message with field control
216
+ if (this.angularPConnectData.validateMessage != null && this.angularPConnectData.validateMessage != '') {
217
+ const timer = interval(100).subscribe(() => {
218
+ this.fieldControl.setErrors({ message: true });
219
+ this.fieldControl.markAsTouched();
220
+
221
+ timer.unsubscribe();
222
+ });
223
+ }
164
224
  }
165
225
  }
166
226
 
167
227
  fieldOnChange(event: any) {
168
228
  event.value = event.checked;
169
229
 
170
- this.angularPConnectData.actions?.onChange(this, event);
230
+ handleEvent(this.actionsApi, 'changeNblur', this.propName, event.checked);
171
231
  }
172
232
 
173
233
  fieldOnBlur(event: any) {
174
- event.value = event.checked;
175
- this.angularPConnectData.actions?.onBlur(this, event);
234
+ if (this.selectionMode === 'multi') {
235
+ this.pConn$.getValidationApi().validate(this.selectedvalues, this.selectionList);
236
+ } else {
237
+ event.value = event.checked;
238
+ this.angularPConnectData.actions?.onBlur(this, event);
239
+ }
240
+ }
241
+
242
+ handleChangeMultiMode(event, element) {
243
+ if (!element.selected) {
244
+ insertInstruction(this.pConn$, this.selectionList, this.selectionKey, this.primaryField, {
245
+ id: element.key,
246
+ primary: element.text ?? element.value
247
+ });
248
+ } else {
249
+ deleteInstruction(this.pConn$, this.selectionList, this.selectionKey, {
250
+ id: element.key,
251
+ primary: element.text ?? element.value
252
+ });
253
+ }
254
+ this.pConn$.clearErrorMessages({
255
+ property: this.selectionList,
256
+ category: '',
257
+ context: ''
258
+ });
176
259
  }
177
260
 
178
261
  getErrorMessage() {
@@ -0,0 +1,34 @@
1
+ <div [formGroup]="formGroup$">
2
+ <mat-form-field class="psdk-full-width" subscriptSizing="dynamic">
3
+ <mat-label>{{ label$ }}</mat-label>
4
+ <mat-chip-grid #chipGrid>
5
+ <ng-container *ngFor="let select of selectedItems">
6
+ <mat-chip-row (removed)="removeChip(select)">
7
+ {{ select.primary }}
8
+ <button matChipRemove>
9
+ <mat-icon>cancel</mat-icon>
10
+ </button>
11
+ </mat-chip-row>
12
+ </ng-container>
13
+ </mat-chip-grid>
14
+ <input
15
+ matInput
16
+ [placeholder]="placeholder"
17
+ [formControl]="fieldControl"
18
+ [value]="value$"
19
+ [required]="bRequired$"
20
+ [matAutocomplete]="auto"
21
+ (input)="fieldOnChange($event)"
22
+ [matChipInputFor]="chipGrid"
23
+ #trigger="matAutocompleteTrigger"
24
+ />
25
+ <mat-autocomplete #auto="matAutocomplete">
26
+ <mat-option *ngFor="let item of itemsTree" [value]="item.primary" (click)="optionClicked($event, item, trigger)">
27
+ <mat-checkbox [checked]="item.selected" (click)="optionClicked($event, item, trigger)">
28
+ <span>{{ item.primary }}</span>
29
+ </mat-checkbox>
30
+ </mat-option>
31
+ </mat-autocomplete>
32
+ <mat-error *ngIf="fieldControl.invalid">{{ getErrorMessage() }}</mat-error>
33
+ </mat-form-field>
34
+ </div>
@@ -0,0 +1,7 @@
1
+ .psdk-full-width {
2
+ width: 100%;
3
+ }
4
+
5
+ ::ng-deep .mat-mdc-form-field-infix {
6
+ padding-left: 10px;
7
+ }
@@ -0,0 +1,21 @@
1
+ import { ComponentFixture, TestBed } from '@angular/core/testing';
2
+
3
+ import { MultiselectComponent } from './multiselect.component';
4
+
5
+ describe('MultiselectComponent', () => {
6
+ let component: MultiselectComponent;
7
+ let fixture: ComponentFixture<MultiselectComponent>;
8
+
9
+ beforeEach(() => {
10
+ TestBed.configureTestingModule({
11
+ declarations: [MultiselectComponent]
12
+ });
13
+ fixture = TestBed.createComponent(MultiselectComponent);
14
+ component = fixture.componentInstance;
15
+ fixture.detectChanges();
16
+ });
17
+
18
+ it('should create', () => {
19
+ expect(component).toBeTruthy();
20
+ });
21
+ });