@pega/angular-sdk-overrides 0.23.12 → 0.23.14

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.
@@ -5,12 +5,47 @@ import { MatOptionModule } from '@angular/material/core';
5
5
  import { MatSelectModule } from '@angular/material/select';
6
6
  import { MatFormFieldModule } from '@angular/material/form-field';
7
7
  import { interval } from 'rxjs';
8
+ import isEqual from 'fast-deep-equal';
8
9
  import { AngularPConnectData, AngularPConnectService } from '@pega/angular-sdk-components';
10
+ import { DatapageService } from '@pega/angular-sdk-components';
9
11
  import { Utils } from '@pega/angular-sdk-components';
10
12
  import { ComponentMapperComponent } from '@pega/angular-sdk-components';
11
13
  import { handleEvent } from '@pega/angular-sdk-components';
12
14
  import { PConnFieldProps } from '@pega/angular-sdk-components';
13
15
 
16
+ function flattenParameters(params = {}) {
17
+ const flatParams = {};
18
+ Object.keys(params).forEach(key => {
19
+ const { name, value: theVal } = params[key];
20
+ flatParams[name] = theVal;
21
+ });
22
+
23
+ return flatParams;
24
+ }
25
+
26
+ function preProcessColumns(columnList) {
27
+ return columnList.map(col => {
28
+ const tempColObj = { ...col };
29
+ tempColObj.value = col.value && col.value.startsWith('.') ? col.value.substring(1) : col.value;
30
+ return tempColObj;
31
+ });
32
+ }
33
+
34
+ function getDisplayFieldsMetaData(columnList) {
35
+ const displayColumns = columnList.filter(col => col.display === 'true');
36
+ const metaDataObj: any = { key: '', primary: '', secondary: [] };
37
+ const keyCol = columnList.filter(col => col.key === 'true');
38
+ metaDataObj.key = keyCol.length > 0 ? keyCol[0].value : 'auto';
39
+ for (let index = 0; index < displayColumns.length; index += 1) {
40
+ if (displayColumns[index].primary === 'true') {
41
+ metaDataObj.primary = displayColumns[index].value;
42
+ } else {
43
+ metaDataObj.secondary.push(displayColumns[index].value);
44
+ }
45
+ }
46
+ return metaDataObj;
47
+ }
48
+
14
49
  interface IOption {
15
50
  key: string;
16
51
  value: string;
@@ -22,6 +57,11 @@ interface DropdownProps extends PConnFieldProps {
22
57
  datasource?: any[];
23
58
  onRecordChange?: any;
24
59
  fieldMetadata?: any;
60
+ listType?: string;
61
+ columns?: any[];
62
+ deferDatasource?: boolean;
63
+ datasourceMetadata?: any;
64
+ parameters?: any;
25
65
  }
26
66
 
27
67
  @Component({
@@ -53,7 +93,7 @@ export class DropdownComponent implements OnInit, OnDestroy {
53
93
  testId = '';
54
94
  helperText: string;
55
95
  hideLabel: any;
56
-
96
+ theDatasource: any[] | null;
57
97
  fieldControl = new FormControl('', null);
58
98
  fieldMetadata: any[];
59
99
  localeContext = '';
@@ -65,7 +105,8 @@ export class DropdownComponent implements OnInit, OnDestroy {
65
105
  constructor(
66
106
  private angularPConnect: AngularPConnectService,
67
107
  private cdRef: ChangeDetectorRef,
68
- private utils: Utils
108
+ private utils: Utils,
109
+ private dataPageService: DatapageService
69
110
  ) {}
70
111
 
71
112
  ngOnInit(): void {
@@ -76,8 +117,9 @@ export class DropdownComponent implements OnInit, OnDestroy {
76
117
  // Then, continue on with other initialization
77
118
 
78
119
  // call updateSelf when initializing
79
- // this.updateSelf();
80
120
  this.checkAndUpdate();
121
+ // this should get called afer checkAndUpdate
122
+ this.getDatapageData();
81
123
 
82
124
  if (this.formGroup$) {
83
125
  // add control to formGroup
@@ -120,7 +162,6 @@ export class DropdownComponent implements OnInit, OnDestroy {
120
162
  updateSelf(): void {
121
163
  // moved this from ngOnInit() and call this from there instead...
122
164
  this.configProps$ = this.pConn$.resolveConfigProps(this.pConn$.getConfigProps()) as DropdownProps;
123
-
124
165
  if (this.configProps$.value != undefined) {
125
166
  this.value$ = this.configProps$.value;
126
167
  }
@@ -130,6 +171,7 @@ export class DropdownComponent implements OnInit, OnDestroy {
130
171
  this.label$ = this.configProps$.label;
131
172
  this.helperText = this.configProps$.helperText;
132
173
  this.hideLabel = this.configProps$.hideLabel;
174
+ const datasource = this.configProps$.datasource;
133
175
  // timeout and detectChanges to avoid ExpressionChangedAfterItHasBeenCheckedError
134
176
  setTimeout(() => {
135
177
  if (this.configProps$.required != null) {
@@ -138,6 +180,11 @@ export class DropdownComponent implements OnInit, OnDestroy {
138
180
  this.cdRef.detectChanges();
139
181
  });
140
182
 
183
+ if (!isEqual(datasource, this.theDatasource)) {
184
+ // inbound datasource is different, so update theDatasource
185
+ this.theDatasource = datasource || null;
186
+ }
187
+
141
188
  if (this.configProps$.visibility != null) {
142
189
  this.bVisible$ = this.utils.getBooleanValue(this.configProps$.visibility);
143
190
  }
@@ -159,14 +206,16 @@ export class DropdownComponent implements OnInit, OnDestroy {
159
206
 
160
207
  this.componentReference = (this.pConn$.getStateProps() as any).value;
161
208
 
162
- // @ts-ignore - parameter “contextName” for getDataObject method should be optional
163
- const optionsList = [...this.utils.getOptionList(this.configProps$, this.pConn$.getDataObject())];
164
- optionsList?.unshift({ key: 'Select', value: this.pConn$.getLocalizedValue('Select...', '', '') });
165
- this.options$ = optionsList;
166
209
  if (this.value$ === '' && !this.bReadonly$) {
167
210
  this.value$ = 'Select';
168
211
  }
169
212
 
213
+ if (this.theDatasource) {
214
+ const optionsList = [...this.utils.getOptionList(this.configProps$, this.pConn$.getDataObject())];
215
+ optionsList?.unshift({ key: 'Select', value: this.pConn$.getLocalizedValue('Select...', '', '') });
216
+ this.options$ = optionsList;
217
+ }
218
+
170
219
  const propName = (this.pConn$.getStateProps() as any).value;
171
220
  const className = this.pConn$.getCaseInfo().getClassName();
172
221
  const refName = propName?.slice(propName.lastIndexOf('.') + 1);
@@ -198,6 +247,70 @@ export class DropdownComponent implements OnInit, OnDestroy {
198
247
  }
199
248
  }
200
249
 
250
+ getDatapageData() {
251
+ const configProps = this.pConn$.getConfigProps() as DropdownProps;
252
+ let { listType, parameters, datasource = [], columns = [] } = configProps;
253
+ const { deferDatasource, datasourceMetadata } = configProps;
254
+ const context = this.pConn$.getContextName();
255
+ if (deferDatasource && datasourceMetadata?.datasource?.name) {
256
+ listType = 'datapage';
257
+ datasource = datasourceMetadata.datasource.name;
258
+ const { parameters: dataSourceParameters, propertyForDisplayText, propertyForValue } = datasourceMetadata.datasource;
259
+ parameters = flattenParameters(dataSourceParameters);
260
+ const displayProp = propertyForDisplayText?.startsWith('@P') ? propertyForDisplayText.substring(3) : propertyForDisplayText;
261
+ const valueProp = propertyForValue?.startsWith('@P') ? propertyForValue.substring(3) : propertyForValue;
262
+ columns = [
263
+ {
264
+ key: 'true',
265
+ setProperty: 'Associated property',
266
+ value: valueProp
267
+ },
268
+ {
269
+ display: 'true',
270
+ primary: 'true',
271
+ useForSearch: true,
272
+ value: displayProp
273
+ }
274
+ ];
275
+ }
276
+
277
+ columns = preProcessColumns(columns) || [];
278
+ if (!this.displayMode$ && listType !== 'associated' && typeof datasource === 'string') {
279
+ this.getData(datasource, parameters, columns, context, listType);
280
+ }
281
+ }
282
+
283
+ getData(dataSource, parameters, columns, context, listType) {
284
+ const dataConfig: any = {
285
+ columns,
286
+ dataSource,
287
+ deferDatasource: true,
288
+ listType,
289
+ parameters,
290
+ matchPosition: 'contains',
291
+ maxResultsDisplay: '5000',
292
+ cacheLifeSpan: 'form'
293
+ };
294
+ PCore.getDataApi()
295
+ .init(dataConfig, context)
296
+ .then((dataApiObj: any) => {
297
+ const optionsData: any[] = [];
298
+ const displayColumn = getDisplayFieldsMetaData(columns);
299
+ dataApiObj.fetchData('').then(response => {
300
+ response.data?.forEach(element => {
301
+ const val = element[displayColumn.primary]?.toString();
302
+ const obj = {
303
+ key: element[displayColumn.key] || element.pyGUID,
304
+ value: val
305
+ };
306
+ optionsData.push(obj);
307
+ });
308
+ optionsData?.unshift({ key: 'Select', value: this.pConn$.getLocalizedValue('Select...', '', '') });
309
+ this.options$ = optionsData;
310
+ });
311
+ });
312
+ }
313
+
201
314
  isSelected(buttonValue: string): boolean {
202
315
  return this.value$ === buttonValue;
203
316
  }
@@ -4,6 +4,7 @@
4
4
  width: 100%;
5
5
  margin-top: 0.5rem;
6
6
  margin-bottom: 0.5rem;
7
+ overflow-y: auto;
7
8
  }
8
9
 
9
10
  table {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pega/angular-sdk-overrides",
3
- "version": "0.23.12",
3
+ "version": "0.23.14",
4
4
  "description": "Angular SDK - Code for overriding components",
5
5
  "scripts": {
6
6
  "test": "echo \"Error: no test specified\" && exit 1"