@pega/react-sdk-overrides 0.23.17 → 0.23.19

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 (65) hide show
  1. package/lib/designSystemExtension/CaseSummaryFields/CaseSummaryFields.tsx +37 -3
  2. package/lib/designSystemExtension/FieldGroup/FieldGroup.tsx +1 -2
  3. package/lib/designSystemExtension/FieldValueList/FieldValueList.tsx +38 -56
  4. package/lib/field/AutoComplete/AutoComplete.tsx +6 -4
  5. package/lib/field/Checkbox/Checkbox.tsx +7 -5
  6. package/lib/field/Currency/Currency.tsx +31 -6
  7. package/lib/field/Currency/currency-utils.ts +76 -0
  8. package/lib/field/Date/Date.tsx +25 -9
  9. package/lib/field/DateTime/DateTime.tsx +24 -10
  10. package/lib/field/Decimal/Decimal.tsx +8 -6
  11. package/lib/field/Dropdown/Dropdown.tsx +6 -4
  12. package/lib/field/Email/Email.tsx +8 -8
  13. package/lib/field/Integer/Integer.tsx +8 -6
  14. package/lib/field/Percentage/Percentage.tsx +8 -6
  15. package/lib/field/Phone/Phone.tsx +8 -7
  16. package/lib/field/RadioButtons/RadioButtons.tsx +7 -5
  17. package/lib/field/SemanticLink/SemanticLink.tsx +6 -0
  18. package/lib/field/TextArea/TextArea.tsx +8 -6
  19. package/lib/field/TextInput/TextInput.tsx +8 -6
  20. package/lib/field/Time/Time.tsx +7 -5
  21. package/lib/field/URL/URL.tsx +8 -6
  22. package/lib/helpers/authManager.js +1 -0
  23. package/lib/helpers/date-format-utils.ts +66 -0
  24. package/lib/helpers/event-utils.js +1 -1
  25. package/lib/helpers/formatters/Currency.js +13 -5
  26. package/lib/helpers/formatters/common.js +5 -1
  27. package/lib/helpers/formatters/index.js +5 -0
  28. package/lib/helpers/template-utils.ts +80 -0
  29. package/lib/infra/Containers/FlowContainer/FlowContainer.tsx +67 -72
  30. package/lib/infra/ErrorBoundary/ErrorBoundary.tsx +0 -44
  31. package/lib/infra/MultiStep/MultiStep.css +4 -18
  32. package/lib/infra/NavBar/NavBar.tsx +129 -219
  33. package/lib/infra/RootContainer/RootContainer.tsx +2 -54
  34. package/lib/infra/Stages/Stages.tsx +1 -2
  35. package/lib/infra/View/View.tsx +28 -21
  36. package/lib/template/AppShell/AppShell.tsx +2 -343
  37. package/lib/template/CaseSummary/CaseSummary.tsx +1 -1
  38. package/lib/template/CaseView/CaseView.tsx +2 -5
  39. package/lib/template/DefaultForm/DefaultForm.tsx +4 -0
  40. package/lib/template/Details/Details/Details.tsx +52 -21
  41. package/lib/template/Details/DetailsThreeColumn/DetailsThreeColumn.tsx +63 -31
  42. package/lib/template/Details/DetailsTwoColumn/DetailsTwoColumn.tsx +64 -30
  43. package/lib/template/ListView/DefaultViewMeta.js +222 -0
  44. package/lib/template/ListView/ListView.tsx +155 -94
  45. package/lib/template/ListView/hooks.js +97 -0
  46. package/lib/template/ListView/utils.js +636 -0
  47. package/lib/template/NarrowWide/NarrowWideDetails/NarrowWideDetails.tsx +69 -42
  48. package/lib/template/SimpleTable/SimpleTableManual/SimpleTableManual.tsx +3 -24
  49. package/lib/template/WideNarrow/WideNarrowDetails/WideNarrowDetails.tsx +69 -43
  50. package/lib/widget/Attachment/Attachment.css +7 -0
  51. package/lib/widget/Attachment/Attachment.tsx +37 -3
  52. package/lib/widget/SummaryItem/SummaryItem.tsx +1 -1
  53. package/package.json +1 -1
  54. package/lib/.DS_Store +0 -0
  55. package/lib/field/AutoComplete/.DS_Store +0 -0
  56. package/lib/field/Checkbox/.DS_Store +0 -0
  57. package/lib/field/Currency/.DS_Store +0 -0
  58. package/lib/field/Date/.DS_Store +0 -0
  59. package/lib/field/TextContent/.DS_Store +0 -0
  60. package/lib/infra/.DS_Store +0 -0
  61. package/lib/template/.DS_Store +0 -0
  62. package/lib/template/CaseView/.DS_Store +0 -0
  63. package/lib/template/SimpleTable/.DS_Store +0 -0
  64. package/lib/template/SimpleTable/SimpleTable/.DS_Store +0 -0
  65. package/lib/template/utils.ts +0 -23
@@ -0,0 +1,636 @@
1
+ /* eslint-disable no-undef */
2
+ import getDefaultViewMeta from './DefaultViewMeta';
3
+
4
+ const USER_REFERENCE = 'UserReference';
5
+ const PAGE = '!P!';
6
+ const PAGELIST = '!PL!';
7
+
8
+ export const formatConstants = {
9
+ WorkStatus: 'WorkStatus',
10
+ Integer: 'Integer',
11
+ WorkLink: 'WorkLink',
12
+ };
13
+
14
+ export async function getContext(componentConfig) {
15
+ const {
16
+ promisesArray = [], // array of promises which can be invoked paralelly,
17
+ } = componentConfig;
18
+ const promisesResponseArray = await Promise.all(promisesArray);
19
+ return {
20
+ promisesResponseArray,
21
+ };
22
+ }
23
+
24
+ /**
25
+ * [getFieldNameFromEmbeddedFieldName]
26
+ * Description - converting embeddedField name starting with !P! or !PL! to normal field
27
+ * @ignore
28
+ * @param {string} propertyName EmbeddedField name starting with !P! or !PL!
29
+ * @returns {string} returns converted string without !P! or !PL! and :
30
+ *
31
+ * @example <caption>Example for getFieldNameFromEmbeddedFieldName </caption>
32
+ * getFieldNameFromEmbeddedFieldName('!P!Organisation:Name') return 'Organisation.Name'
33
+ * getFieldNameFromEmbeddedFieldName('!PL!Employees:Name') return 'Employees.Name'
34
+ */
35
+ export function getFieldNameFromEmbeddedFieldName(propertyName) {
36
+ let value = propertyName;
37
+ if (value.startsWith(PAGE) || value.startsWith(PAGELIST)) {
38
+ value = value.substring(value.lastIndexOf('!') + 1);
39
+ value = value.replace(/:/g, '.');
40
+ }
41
+ return value;
42
+ }
43
+
44
+ /**
45
+ * [updateMetaEmbeddedFieldID]
46
+ * Description - If the fieldID in meta starts with '!P!' or '!PL!' and contains ':' then replace them with .(dot)
47
+ * @ignore
48
+ * @param {Array} metaFields Fields metadata Array. Contains metadata of all the fields.
49
+ */
50
+ export function updateMetaEmbeddedFieldID(metaFields) {
51
+ return metaFields.forEach((metaField) => {
52
+ if (metaField.fieldID?.startsWith(PAGE) || metaField.fieldID?.startsWith(PAGELIST)) {
53
+ metaField.fieldID = getFieldNameFromEmbeddedFieldName(metaField.fieldID);
54
+ }
55
+ });
56
+ }
57
+
58
+ export const isEmbeddedField = (field) => {
59
+ if (field?.startsWith('@')) {
60
+ field = field.substring(field.indexOf(' ') + 1);
61
+ if (field[0] === '.') field = field.substring(1);
62
+ }
63
+ return field?.indexOf('.') > 0;
64
+ };
65
+
66
+ /**
67
+ * [getConfigEmbeddedFieldsMeta]
68
+ * Description - Get the metadata for configured embedded fields
69
+ * @ignore
70
+ * @param {Set} configFields Set of config fields
71
+ * @param {string} classID clasID of datapage
72
+ * @returns {Array} Metadata of configured embedded fields
73
+ */
74
+ export function getConfigEmbeddedFieldsMeta(configFields, classID) {
75
+ const configEmbeddedFieldsMeta = [];
76
+ configFields.forEach((field) => {
77
+ let value = field;
78
+ if (isEmbeddedField(value)) {
79
+ // conversion Page.PageList[].property => Page.PageList.property
80
+ if (value.includes('[')) {
81
+ value = value.substring(0, value.indexOf('[')) + value.substring(value.indexOf(']') + 1);
82
+ }
83
+ const meta = PCore.getMetadataUtils().getEmbeddedPropertyMetadata(value, classID);
84
+ meta.fieldID = field;
85
+ configEmbeddedFieldsMeta.push(meta);
86
+ }
87
+ });
88
+ return configEmbeddedFieldsMeta;
89
+ }
90
+
91
+ /**
92
+ * [mergeConfigEmbeddedFieldsMeta]
93
+ * Description - Get the metadata for configured embedded fields
94
+ * @ignore
95
+ * @param {Array} configEmbeddedFieldsMeta config fields metadata.
96
+ * @param {Array} metaFields Fields metadata Array. Contains metadata of all the fields
97
+ */
98
+ export function mergeConfigEmbeddedFieldsMeta(configEmbeddedFieldsMeta, metaFields) {
99
+ const mergedMetaFields = [...metaFields];
100
+ configEmbeddedFieldsMeta.forEach((configFieldMeta) => {
101
+ const fieldMeta = metaFields.find((metaField) => metaField.fieldID === configFieldMeta.fieldID);
102
+ if (!fieldMeta) mergedMetaFields.push(configFieldMeta);
103
+ });
104
+ return mergedMetaFields;
105
+ }
106
+
107
+ const oldToNewFieldTypeMapping = {
108
+ 'Date Time': 'Date & time',
109
+ Date: 'Date only'
110
+ };
111
+
112
+ /**
113
+ * [updateFieldType]
114
+ * Description - Updates the field type if its changed in the new implementation. Such mapping is maintained in oldToNewFieldTypeMapping.
115
+ * @ignore
116
+ * @param {Array} metaFields Fields metadata Array. Contains metadata of all the fields.
117
+ */
118
+ function updateFieldType(metaFields) {
119
+ metaFields.forEach((metaField) => {
120
+ if (metaField.type) metaField.type = oldToNewFieldTypeMapping[metaField.type] || metaField.type;
121
+ });
122
+ }
123
+
124
+ function getPresetMetaAttribute(attribute) {
125
+ const {
126
+ type,
127
+ config: { label, value }
128
+ } = attribute;
129
+ return {
130
+ type,
131
+ name: value.startsWith('@') ? value.substring(4) : value,
132
+ label: label.startsWith('@') ? label.substring(3) : label
133
+ };
134
+ }
135
+
136
+ /**
137
+ * [generateViewMetaData]
138
+ * Description - Returns a list of metaobjects of the fields provided.
139
+ * @ignore
140
+ * @param {Array} rawFields List of fields to update meta for
141
+ * @param {string} classID Class ID from the response
142
+ * @returns {Array} List of fields with updated meta objects.
143
+ */
144
+ function generateViewMetaData(rawFields, classID, showField) {
145
+ return rawFields.map((item) => getDefaultViewMeta(item, classID, showField));
146
+ }
147
+
148
+ /**
149
+ * [getConfigFields]
150
+ * Description - Returns list of config fields with primary fields meta updated.
151
+ * @ignore
152
+ * @param {Array} configFields List of Authored fields
153
+ * @param {Array} primaryFields List of Primary Fields
154
+ * @param {Array} metaFields Metadata of all fields
155
+ * @param {string} classID Class ID from the response
156
+ * @returns {Array} List of all fields with their meta updated.
157
+ */
158
+ function getConfigFields(configFields, primaryFields, metaFields, classID) {
159
+ const presetConfigFields = configFields;
160
+ const primaryFieldsViewIndex = presetConfigFields.findIndex((field) => field.config.value === 'pyPrimaryFields');
161
+ if (!primaryFields || !primaryFields.length) {
162
+ if (primaryFieldsViewIndex < 0) return presetConfigFields;
163
+
164
+ presetConfigFields.splice(primaryFieldsViewIndex, 1);
165
+
166
+ return presetConfigFields;
167
+ }
168
+
169
+ if (primaryFieldsViewIndex > -1) {
170
+ // list of uncommon fields - non overlap of primary fields grouped view and independent entity columns of primary type
171
+ const uncommonFieldsList = primaryFields.filter(
172
+ (primaryField) =>
173
+ !presetConfigFields.some((presetConfigField) => presetConfigField.config.value.split('.')[1] === primaryField)
174
+ );
175
+ const uncommonFieldsRawMeta = [];
176
+ uncommonFieldsList.forEach((uncommonField) => {
177
+ const uncommonFieldMeta = metaFields.find((metaField) => metaField.fieldID === uncommonField);
178
+ if (uncommonFieldMeta) uncommonFieldsRawMeta.push(uncommonFieldMeta);
179
+ });
180
+ const uncommonFieldsConfigMeta = generateViewMetaData(uncommonFieldsRawMeta, classID, true);
181
+
182
+ presetConfigFields.splice(primaryFieldsViewIndex, 1, ...uncommonFieldsConfigMeta);
183
+ }
184
+ return presetConfigFields;
185
+ }
186
+
187
+ /**
188
+ * [getTableConfigFromPresetMeta]
189
+ * Description - Get the table config from the presets meta.
190
+ * @ignore
191
+ * @param {object} presetMeta Presets meta
192
+ * @param {boolean} isMetaWithPresets true if meta has presets else false
193
+ * @param {Function} getPConnect Callback to get the PConnect object
194
+ * @param {string} classID Class ID from the response
195
+ * @param {Array} primaryFields List of Primary Fields
196
+ * @param {Array} metaFields List of all metafields
197
+ * @returns {object} Table config object
198
+ */
199
+ export function getTableConfigFromPresetMeta(
200
+ presetMeta,
201
+ isMetaWithPresets,
202
+ getPConnect,
203
+ classID,
204
+ primaryFields,
205
+ metaFields
206
+ ) {
207
+ let presetId;
208
+ let presetName;
209
+ let cardHeader;
210
+ let secondaryText;
211
+ let timelineDate;
212
+ let timelineTitle;
213
+ let timelineStatus;
214
+ let timelineIcon;
215
+ let { filterExpression } = getPConnect().getRawMetadata().config;
216
+ let fieldsMeta;
217
+ let configFields;
218
+ if (isMetaWithPresets) {
219
+ presetId = presetMeta.id;
220
+ presetName = presetMeta.label;
221
+ cardHeader = presetMeta.cardHeader && getPresetMetaAttribute(presetMeta.cardHeader);
222
+ secondaryText = presetMeta.secondaryText && getPresetMetaAttribute(presetMeta.secondaryText);
223
+ timelineDate = presetMeta.timelineDate && getPresetMetaAttribute(presetMeta.timelineDate);
224
+ timelineTitle = presetMeta.timelineTitle && getPresetMetaAttribute(presetMeta.timelineTitle);
225
+ timelineStatus = presetMeta.timelineStatus && getPresetMetaAttribute(presetMeta.timelineStatus);
226
+ timelineIcon = presetMeta.timelineIcon && getPresetMetaAttribute(presetMeta.timelineIcon);
227
+ filterExpression = presetMeta.config.filterExpression;
228
+ [fieldsMeta] = presetMeta.children;
229
+ if (
230
+ presetMeta.timelineTitle &&
231
+ !fieldsMeta.children.find((fieldMeta) => {
232
+ return fieldMeta?.config?.value === presetMeta.timelineTitle?.config?.value;
233
+ })
234
+ ) {
235
+ const { type, config } = presetMeta.timelineTitle;
236
+ fieldsMeta.children.push({ type, config: { ...config, show: false } });
237
+ }
238
+ if (
239
+ presetMeta.timelineDate &&
240
+ !fieldsMeta.children.find((fieldMeta) => {
241
+ return fieldMeta?.config?.value === presetMeta.timelineDate?.config?.value;
242
+ })
243
+ ) {
244
+ const { type, config } = presetMeta.timelineDate;
245
+ fieldsMeta.children.push({ type, config: { ...config, show: false } });
246
+ }
247
+ configFields = getConfigFields(fieldsMeta.children, primaryFields, metaFields, classID);
248
+ } else {
249
+ fieldsMeta = presetMeta.props;
250
+ configFields = getConfigFields(
251
+ fieldsMeta
252
+ .getPConnect()
253
+ .getChildren()
254
+ ?.map((child) => {
255
+ return child.getPConnect().getRawMetadata();
256
+ }),
257
+ primaryFields,
258
+ metaFields,
259
+ classID
260
+ );
261
+ }
262
+ return {
263
+ presetId,
264
+ presetName,
265
+ cardHeader,
266
+ secondaryText,
267
+ timelineDate,
268
+ timelineTitle,
269
+ timelineStatus,
270
+ timelineIcon,
271
+ filterExpression,
272
+ fieldsMeta,
273
+ configFields
274
+ };
275
+ }
276
+
277
+ /**
278
+ * [getReportColumns]
279
+ * Description - Returns a set of columns from the report response.
280
+ * @ignore
281
+ * @param {object} response -
282
+ * @returns {Set} Set of columns from the report response
283
+ */
284
+ function getReportColumns(response) {
285
+ const {
286
+ data: { data: reportColumns }
287
+ } = response;
288
+ const reportColumnsSet = new Set();
289
+ reportColumns?.forEach((item) => {
290
+ let val = item.pyFieldName;
291
+ // Remove '.' from index 0 only, if '.' is present
292
+ if (val[0] === '.') {
293
+ val = val.substring(1);
294
+ }
295
+ reportColumnsSet.add(val);
296
+ });
297
+ return reportColumnsSet;
298
+ }
299
+
300
+ /**
301
+ * [getConfigFieldValue]
302
+ * Descritpion - Returns a valid value for a configuration field. Remove any annotations and also "."
303
+ * @ignore
304
+ * @param {object} config
305
+ * config.value - Raw value
306
+ * @returns {string} value - Value with out any annotations or "."
307
+ */
308
+ function getConfigFieldValue(config) {
309
+ let { value } = config;
310
+ if (value.startsWith('@')) {
311
+ value = value.substring(value.indexOf(' ') + 1);
312
+ if (value[0] === '.') value = value.substring(1);
313
+ }
314
+ return value;
315
+ }
316
+
317
+ /**
318
+ * [prepareConfigFields]
319
+ * Description - Prepares a set of configuration fields and pushes each config type to a set using the callback parameter.
320
+ * @ignore
321
+ * @param {object} configFields List of Authored fields
322
+ * @param {Function} pushToComponentsList Callback to push the field type to a set.
323
+ * @returns {Set} configFieldSet
324
+ */
325
+ function prepareConfigFields(configFields, pushToComponentsList) {
326
+ const configFieldSet = new Set();
327
+ configFields.forEach((item) => {
328
+ pushToComponentsList(item.type);
329
+ const val = getConfigFieldValue(item.config);
330
+ configFieldSet.add(val);
331
+ });
332
+ return configFieldSet;
333
+ }
334
+
335
+ /**
336
+ * [findAuthoredField]
337
+ * Description - Finds an authored field from yhe list of config fields.
338
+ * @ignore
339
+ * @param {Array} configFields List of Authored fields
340
+ * @param {string} fieldID Filter
341
+ * @returns {object} config with its field value equal to fieldID, which means an authored field
342
+ */
343
+ function findAuthoredField(configFields, fieldID) {
344
+ return configFields.find((configField) => {
345
+ const val = getConfigFieldValue(configField.config);
346
+ return val === fieldID;
347
+ });
348
+ }
349
+
350
+ /**
351
+ * [findAndUpdateAuthoredFieldConfig]
352
+ * Description - Find the authored field, and update its config.
353
+ * @ignore
354
+ * @param {Array} configFields List of Authored fields
355
+ * @param {object} item Field item to copy displayAs and category information
356
+ * @param {string} classId classID from the response
357
+ */
358
+ function findAndUpdateAuthoredFieldConfig(configFields, item, classId) {
359
+ const authoredField = findAuthoredField(configFields, item.fieldID);
360
+ if (authoredField?.config) {
361
+ if (item.displayAs) {
362
+ authoredField.config.displayAs = item.displayAs;
363
+ }
364
+ authoredField.config.classID = item.classID ?? classId;
365
+
366
+ if (authoredField.type === USER_REFERENCE) {
367
+ authoredField.config.associationID = item.associationID || item.fieldID;
368
+ }
369
+ authoredField.config.category = item.category;
370
+ // FieldType identifies whether the field is configured as pickList
371
+ authoredField.config.fieldType = item.fieldType;
372
+ // type defined on the property rule,
373
+ // used for the picklist field to assign the appropriate type
374
+ authoredField.config.propertyType = item.dataType || item.type;
375
+ }
376
+ }
377
+
378
+ /**
379
+ * [isAnExtraField]
380
+ * Description - Returns true if the field is an extra field. Extra field is the one which is not authored but part of the report.
381
+ * @ignore
382
+ * @param {Array} configFields List of Authored fields
383
+ * @param {Set} configFieldSet Set if Authored filed values
384
+ * @param {Set} reportColumnsSet Set of columns from the report
385
+ * @param {object} item Config field item
386
+ * @param {string} classId Class ID from the response
387
+ * @param {boolean} showDynamicFields Flag indicating whether fields are fetched dynamically at runtime
388
+ * @returns {boolean} true If the field is an extra field else false.
389
+ */
390
+ function isAnExtraField(configFields, configFieldSet, reportColumnsSet, item, classId, showDynamicFields) {
391
+ // Is the field already present in authoring metadata?
392
+ // Mutates config fields to copy displayAs and category information
393
+ if (configFieldSet.has(item.fieldID)) {
394
+ findAndUpdateAuthoredFieldConfig(configFields, item, classId);
395
+ return false;
396
+ }
397
+
398
+ // If field is not authored and not part of report columns then discard it
399
+ return showDynamicFields || !!reportColumnsSet.has(item.fieldID);
400
+ }
401
+
402
+ /**
403
+ * [prepareExtraFields]
404
+ * Description - Returns a list of extra fields with their meta updated.
405
+ * @ignore
406
+ * @param {Array} metaFields List of fields
407
+ * @param {Array} configFields List of Authored fields
408
+ * @param {Set} configFieldSet Set if Authored filed values
409
+ * @param {Set} reportColumnsSet Set of columns from the report
410
+ * @param {string} classID Class ID from the response
411
+ * @param {boolean} showDynamicFields Flag indicating whether fields are fetched dynamically at runtime
412
+ * @returns {Array} List of extra fields with their meta updated.
413
+ */
414
+ function prepareExtraFields(
415
+ metaFields,
416
+ configFields,
417
+ configFieldSet,
418
+ reportColumnsSet,
419
+ classID,
420
+ showDynamicFields
421
+ ) {
422
+ // Filter all the extra fields
423
+ const extraFileds = metaFields.filter((item) => {
424
+ return isAnExtraField(configFields, configFieldSet, reportColumnsSet, item, classID, showDynamicFields);
425
+ });
426
+ return generateViewMetaData(extraFileds, classID, false);
427
+ // Update the meta object of each of the extra fields.
428
+ }
429
+
430
+ const AssignDashObjects = ['Assign-Worklist', 'Assign-WorkBasket'];
431
+
432
+ function populateRenderingOptions(name, config, field) {
433
+ const shouldDisplayAsSemanticLink = 'displayAsLink' in field.config && field.config.displayAsLink;
434
+ if (shouldDisplayAsSemanticLink) {
435
+ config.customObject.isAssignmentLink = AssignDashObjects.includes(field.config.classID);
436
+ if (field.config.value.startsWith('@CA')) {
437
+ config.customObject.isAssociation = true;
438
+ }
439
+ config.cellRenderer = formatConstants.WorkLink;
440
+ } else if (name === 'pyStatusWork' || name === 'pyAssignmentStatus') {
441
+ config.cellRenderer = formatConstants.WorkStatus;
442
+ } else if (name === 'pxUrgencyWork') {
443
+ config.cellRenderer = formatConstants.Integer;
444
+ }
445
+ }
446
+ export function initializeColumns(
447
+ fields = [],
448
+ getMappedProperty
449
+ ) {
450
+ return fields.map((field, originalColIndex) => {
451
+ let name = field.config.value;
452
+
453
+ if (name.startsWith('@')) {
454
+ name = name.substring(name.indexOf(' ') + 1);
455
+ if (name[0] === '.') name = name.substring(1);
456
+ }
457
+ name = getMappedProperty?.(name) ?? name;
458
+
459
+ let label = field.config.label || field.config.caption;
460
+ const { show = true, displayAs } = field.config;
461
+ if (label.startsWith('@')) {
462
+ label = label.substring(3);
463
+ }
464
+
465
+ const config = {
466
+ name,
467
+ label,
468
+ show,
469
+ classID: field.config.classID,
470
+ id: field.id || name || originalColIndex,
471
+ displayAs,
472
+ associationID: field.config.associationID,
473
+ ...(field.config.classID && { category: field.config.category }),
474
+ customObject: {},
475
+ fieldType: field.config.fieldType,
476
+ meta: {
477
+ ...field
478
+ },
479
+ };
480
+
481
+ populateRenderingOptions(name, config, field);
482
+
483
+ return config;
484
+ });
485
+ }
486
+
487
+ export const getItemKey = (fields) => {
488
+ let itemKey;
489
+ if (fields.findIndex((field) => field.id === 'pyGUID') > -1) {
490
+ itemKey = 'pyGUID';
491
+ } else {
492
+ itemKey = 'pzInsKey';
493
+ }
494
+ return itemKey;
495
+ };
496
+
497
+ export function preparePatchQueryFields(fields, isDataObject = false, classID = '') {
498
+ const queryFields = [];
499
+ fields.forEach((field) => {
500
+ const patchFields = [];
501
+ if (field.cellRenderer === 'WorkLink') {
502
+ if (field.customObject && field.customObject.isAssignmentLink) {
503
+ const associationName = field.name.includes(':') ? `${field.name.split(':')[0]}:` : '';
504
+ patchFields.push(`${associationName}pzInsKey`);
505
+ patchFields.push(`${associationName}pxRefObjectClass`);
506
+ } else if (field.customObject && field.customObject.isAssociation) {
507
+ const associationCategory = field.name.split(':')[0];
508
+ patchFields.push(`${associationCategory}:pyID`);
509
+ patchFields.push(`${associationCategory}:pzInsKey`);
510
+ patchFields.push(`${associationCategory}:pxObjClass`);
511
+ } else if (isDataObject) {
512
+ const dataViewName = PCore.getDataTypeUtils().getSavableDataPage(classID);
513
+ const dataPageKeys = PCore.getDataTypeUtils().getDataPageKeys(dataViewName);
514
+ dataPageKeys?.forEach((item) =>
515
+ item.isAlternateKeyStorage ? patchFields.push(item.linkedField) : patchFields.push(item.keyName)
516
+ );
517
+ } else {
518
+ patchFields.push('pyID');
519
+ patchFields.push('pzInsKey');
520
+ patchFields.push('pxObjClass');
521
+ }
522
+ }
523
+ patchFields.forEach((k) => {
524
+ if (!queryFields.find((q) => q === k)) {
525
+ queryFields.push(k);
526
+ }
527
+ });
528
+ });
529
+
530
+ return queryFields;
531
+ }
532
+
533
+ export const readContextResponse = async (context, params) => {
534
+ const {
535
+ getPConnect,
536
+ apiContext,
537
+ setListContext,
538
+ children,
539
+ showDynamicFields,
540
+ referenceList,
541
+ isDataObject
542
+ } = params;
543
+ const { promisesResponseArray, apiContext: otherContext } = context;
544
+ // eslint-disable-next-line sonarjs/no-unused-collection
545
+ const listOfComponents = [];
546
+ const {
547
+ data: { fields: metaFields, classID, isQueryable }
548
+ } = promisesResponseArray[0];
549
+ let {
550
+ data: { primaryFields }
551
+ } = promisesResponseArray[0];
552
+ // When list is configured with Include all class fields configuration, provide support for Primary fields column
553
+ if (showDynamicFields) {
554
+ const sourceMetadata = PCore.getMetadataUtils().getDataPageMetadata(referenceList);
555
+ if (sourceMetadata?.primaryFields) {
556
+ primaryFields = sourceMetadata.primaryFields;
557
+ }
558
+ // updating metaData fieldID to normal property if it has fieldID starts with !P! or !PL!
559
+ updateMetaEmbeddedFieldID(metaFields);
560
+ }
561
+ updateFieldType(metaFields);
562
+
563
+
564
+ if (isDataObject) {
565
+ const compositeKeys = [];
566
+ const dataViewName = PCore.getDataTypeUtils().getSavableDataPage(classID);
567
+ const dataPageKeys = PCore.getDataTypeUtils().getDataPageKeys(dataViewName);
568
+ dataPageKeys?.forEach((item) =>
569
+ item.isAlternateKeyStorage ? compositeKeys.push(item.linkedField) : compositeKeys.push(item.keyName)
570
+ );
571
+ if (compositeKeys.length) {
572
+ otherContext.setCompositeKeys(compositeKeys);
573
+ }
574
+ otherContext.fetchRowActionDetails = null;
575
+ }
576
+
577
+ const presetArray = [];
578
+ const rawMetadata = getPConnect().getRawMetadata().config;
579
+ const rawPresets = rawMetadata.presets;
580
+ const isMetaWithPresets = rawPresets && rawPresets.length !== 0;
581
+ const childrenIterator = isMetaWithPresets ? rawPresets : children;
582
+ const resolvedPresets = getPConnect().getConfigProps().presets;
583
+ let fields;
584
+ let tableConfig;
585
+ childrenIterator?.forEach((presetMeta, index) => {
586
+ const {
587
+ configFields
588
+ } = getTableConfigFromPresetMeta(
589
+ { ...presetMeta, label: resolvedPresets[index].label },
590
+ isMetaWithPresets,
591
+ getPConnect,
592
+ classID,
593
+ primaryFields,
594
+ metaFields
595
+ );
596
+ const pushToComponentsList = (fieldType) => {
597
+ listOfComponents.push(fieldType);
598
+ };
599
+ // read report columns response - in case of nonqueryable ignore the response and rely only on the fields configured at authoing time in presets
600
+ const reportColumnsSet = isQueryable ? getReportColumns(promisesResponseArray[1]) : new Set();
601
+
602
+ const configFieldSet = prepareConfigFields(configFields, pushToComponentsList);
603
+
604
+ // FIXME #EmbeddedPropertyPatch
605
+ // TODO: Remove this merge logic when the metadata response includes all optimized embedded page and pagelists
606
+ // merging configured embedded properties with metadata so that while preparing extra fields, config fields can get other properties from meta(eg: category, displayAsLink)
607
+ // get configured embedded properties metadata and get new mergedMetaFields
608
+ const configEmbeddedFieldsMeta = getConfigEmbeddedFieldsMeta(configFieldSet, classID);
609
+ const mergedMetaFields = mergeConfigEmbeddedFieldsMeta(configEmbeddedFieldsMeta, metaFields);
610
+
611
+ const extraFields = prepareExtraFields(
612
+ mergedMetaFields, // passing new merged meta fields which has meta of configured embedded fields of current preset
613
+ configFields,
614
+ configFieldSet,
615
+ reportColumnsSet,
616
+ classID,
617
+ showDynamicFields
618
+ );
619
+
620
+
621
+ fields = initializeColumns(
622
+ [...configFields, ...extraFields],
623
+ );
624
+ const patchQueryFields = preparePatchQueryFields(fields, isDataObject, classID);
625
+ const itemKey = getItemKey(fields);
626
+ tableConfig = { fieldDefs: fields, patchQueryFields, itemKey, isQueryable}
627
+ });
628
+ const meta = tableConfig;
629
+ setListContext({
630
+ meta,
631
+ presets: presetArray,
632
+ apiContext: {
633
+ ...apiContext,
634
+ }
635
+ });
636
+ };