@pega/react-sdk-overrides 0.23.17 → 0.23.18

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 (57) 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/date-format-utils.ts +66 -0
  23. package/lib/helpers/formatters/Currency.js +13 -5
  24. package/lib/helpers/formatters/common.js +5 -1
  25. package/lib/helpers/formatters/index.js +5 -0
  26. package/lib/helpers/template-utils.ts +80 -0
  27. package/lib/infra/Containers/FlowContainer/FlowContainer.tsx +66 -70
  28. package/lib/infra/MultiStep/MultiStep.css +4 -18
  29. package/lib/infra/NavBar/NavBar.tsx +129 -219
  30. package/lib/infra/View/View.tsx +27 -20
  31. package/lib/template/CaseView/CaseView.tsx +2 -5
  32. package/lib/template/DefaultForm/DefaultForm.tsx +4 -0
  33. package/lib/template/Details/Details/Details.tsx +52 -21
  34. package/lib/template/Details/DetailsThreeColumn/DetailsThreeColumn.tsx +63 -31
  35. package/lib/template/Details/DetailsTwoColumn/DetailsTwoColumn.tsx +64 -30
  36. package/lib/template/ListView/DefaultViewMeta.js +222 -0
  37. package/lib/template/ListView/ListView.tsx +152 -48
  38. package/lib/template/ListView/hooks.js +97 -0
  39. package/lib/template/ListView/utils.js +636 -0
  40. package/lib/template/NarrowWide/NarrowWideDetails/NarrowWideDetails.tsx +69 -42
  41. package/lib/template/WideNarrow/WideNarrowDetails/WideNarrowDetails.tsx +69 -43
  42. package/lib/widget/Attachment/Attachment.css +7 -0
  43. package/lib/widget/Attachment/Attachment.tsx +37 -3
  44. package/lib/widget/SummaryItem/SummaryItem.tsx +1 -1
  45. package/package.json +1 -1
  46. package/lib/.DS_Store +0 -0
  47. package/lib/field/AutoComplete/.DS_Store +0 -0
  48. package/lib/field/Checkbox/.DS_Store +0 -0
  49. package/lib/field/Currency/.DS_Store +0 -0
  50. package/lib/field/Date/.DS_Store +0 -0
  51. package/lib/field/TextContent/.DS_Store +0 -0
  52. package/lib/infra/.DS_Store +0 -0
  53. package/lib/template/.DS_Store +0 -0
  54. package/lib/template/CaseView/.DS_Store +0 -0
  55. package/lib/template/SimpleTable/.DS_Store +0 -0
  56. package/lib/template/SimpleTable/SimpleTable/.DS_Store +0 -0
  57. package/lib/template/utils.ts +0 -23
@@ -1,6 +1,8 @@
1
1
  /* eslint-disable no-plusplus */
2
2
  /* eslint-disable guard-for-in */
3
3
  /* eslint-disable @typescript-eslint/no-use-before-define */
4
+ /* eslint-disable @typescript-eslint/no-shadow */
5
+ /* eslint-disable no-shadow */
4
6
  import React, { useState, useEffect, useRef } from 'react';
5
7
  import PropTypes from 'prop-types';
6
8
  import { createStyles, makeStyles, Theme } from '@material-ui/core/styles';
@@ -37,6 +39,7 @@ import { Radio } from '@material-ui/core';
37
39
  import Checkbox from '@material-ui/core/Checkbox';
38
40
  import { filterData } from '@pega/react-sdk-components/lib/components/helpers/simpleTableHelpers';
39
41
  import './ListView.css';
42
+ import useInit from './hooks'
40
43
 
41
44
  const SELECTION_MODE = { SINGLE: 'single', MULTI: 'multi' };
42
45
  declare const PCore: any;
@@ -59,7 +62,16 @@ const filterByColumns: Array<any> = [];
59
62
 
60
63
  export default function ListView(props) {
61
64
  const { getPConnect, bInForm } = props;
62
- const { globalSearch, presets, referenceList, rowClickAction, selectionMode, referenceType, payload, parameters, compositeKeys } = props;
65
+ const { globalSearch, referenceList, rowClickAction, selectionMode, referenceType, payload, parameters, compositeKeys, showDynamicFields, presets } = props;
66
+ const ref = useRef({}).current;
67
+ const cosmosTableRef = useRef();
68
+ // List component context
69
+ const [listContext, setListContext] = useState<any>({});
70
+ const { meta } = listContext;
71
+ const xRayApis = PCore.getDebugger().getXRayRuntime();
72
+ const xRayUid = xRayApis.startXRay();
73
+
74
+ useInit({ ...props, setListContext, ref, showDynamicFields, xRayUid, cosmosTableRef });
63
75
 
64
76
  const thePConn = getPConnect();
65
77
  const componentConfig = thePConn.getComponentConfig();
@@ -74,6 +86,7 @@ export default function ListView(props) {
74
86
  const [arRows, setRows] = useState<Array<any>>([]);
75
87
  const [arColumns, setColumns] = useState<Array<any>>([]);
76
88
  const [response, setResponse] = useState<Array<any>>([]);
89
+
77
90
  const [order, setOrder] = useState<Order>('asc');
78
91
  const [orderBy, setOrderBy] = useState<keyof any>('');
79
92
 
@@ -185,7 +198,6 @@ export default function ListView(props) {
185
198
  function stableSort<T>(array: Array<T>, comparator: (a: T, b: T) => number) {
186
199
  const stabilizedThis = array.map((el, index) => [el, index] as [T, number]);
187
200
  stabilizedThis.sort((a, b) => {
188
- // eslint-disable-next-line @typescript-eslint/no-shadow, no-shadow
189
201
  const order = comparator(a[0], b[0]);
190
202
  if (order !== 0) return order;
191
203
  return a[1] - b[1];
@@ -218,16 +230,19 @@ export default function ListView(props) {
218
230
 
219
231
  // }
220
232
 
221
- function getHeaderCells(colFields, fields) {
222
- const arReturn = colFields.map((field: any, colIndex) => {
233
+ const AssignDashObjects = ['Assign-Worklist', 'Assign-WorkBasket'];
234
+ function getHeaderCells(colFields, fields, presetFields) {
235
+ const arReturn = colFields.map((field: any, index) => {
223
236
  let theField = field.config.value.substring(field.config.value.indexOf(' ') + 1);
224
237
  if (theField.indexOf('.') === 0) {
225
238
  theField = theField.substring(1);
226
239
  }
227
-
240
+ const colIndex = fields.findIndex(ele => ele.name === theField);
241
+ const displayAsLink = field.config.displayAsLink;
228
242
  const headerRow: any = {};
229
243
  headerRow.id = theField;
230
244
  headerRow.type = field.type;
245
+ headerRow.displayAsLink = displayAsLink;
231
246
  headerRow.numeric =
232
247
  field.type === 'Decimal' ||
233
248
  field.type === 'Integer' ||
@@ -235,23 +250,31 @@ export default function ListView(props) {
235
250
  field.type === 'Currency' ||
236
251
  false;
237
252
  headerRow.disablePadding = false;
238
- headerRow.label = fields[colIndex].config.label;
239
-
253
+ headerRow.label = presetFields[index].config.label;
254
+ if (colIndex > -1) {
255
+ headerRow.classID = fields[colIndex].classID;
256
+ }
257
+ if (displayAsLink) {
258
+ headerRow.isAssignmentLink = AssignDashObjects.includes(headerRow.classID);
259
+ if (field.config.value?.startsWith('@CA')) {
260
+ headerRow.isAssociation = true;
261
+ }
262
+ }
240
263
  return headerRow;
241
264
  });
242
265
  return arReturn;
243
266
  }
244
267
 
245
268
  function updateFields(arFields, theColumns): Array<any> {
246
- const arReturn = arFields;
247
- arFields.forEach((field, index) => {
269
+ const arReturn = arFields.filter(ele => ele.type !== 'reference');
270
+ arReturn.forEach((field, index) => {
248
271
  arReturn[index].config.name = theColumns[index].id;
249
272
  });
250
273
 
251
274
  return arReturn;
252
275
  }
253
276
 
254
- function getUsingData(arTableData, theColumns): Array<any> {
277
+ function getUsingData(arTableData): Array<any> {
255
278
  if (selectionMode === SELECTION_MODE.SINGLE || selectionMode === SELECTION_MODE.MULTI) {
256
279
  const record = arTableData?.length > 0 ? arTableData[0] : '';
257
280
  if (typeof record === 'object' && !('pyGUID' in record) && !('pyID' in record)) {
@@ -260,24 +283,8 @@ export default function ListView(props) {
260
283
  }
261
284
  }
262
285
  const arReturn = arTableData?.map((data: any) => {
263
- const row: any = {};
264
286
 
265
- theColumns.forEach(col => {
266
- row[col.id] = data[col.id];
267
- });
268
- row[rowID] = data[rowID];
269
- // for (const field of theColumns) {
270
- // row[field.id] = data[field.id];
271
- // }
272
-
273
- // add in pxRefObjectClass and pzInsKey
274
- if (data['pxRefObjectClass']) {
275
- row['pxRefObjectClass'] = data['pxRefObjectClass'];
276
- }
277
-
278
- if (data['pzInsKey']) {
279
- row['pzInsKey'] = data['pzInsKey'];
280
- }
287
+ const row = data;
281
288
 
282
289
  return row;
283
290
  });
@@ -484,20 +491,96 @@ export default function ListView(props) {
484
491
  }, 0);
485
492
  }, []);
486
493
 
487
- function fetchAllData() {
494
+ function fetchAllData(fields) {
495
+ let query: any = null;
496
+ if (payload) {
497
+ query = payload.query;
498
+ } else if (fields?.length && meta.isQueryable) {
499
+ query = {select: fields};
500
+ } else if (dashboardFilterPayload) {
501
+ query = dashboardFilterPayload.query;
502
+ }
488
503
  const context = getPConnect().getContextName();
489
504
  return PCore.getDataPageUtils().getDataAsync(
490
505
  referenceList,
491
506
  context,
492
507
  payload ? payload.dataViewParameters : dataViewParameters,
493
508
  null,
494
- payload ? payload.query : dashboardFilterPayload && dashboardFilterPayload.query
509
+ query
495
510
  );
496
511
  }
497
512
 
513
+ const buildSelect = (fieldDefs, colId, patchQueryFields = [], compositeKeys = []) => {
514
+ const listFields: any = [];
515
+ if (colId) {
516
+ const field = getField(fieldDefs, colId);
517
+ listFields.push({
518
+ field: field.name
519
+ });
520
+ } else {
521
+ // NOTE: If we ever decide to not set up all the `fieldDefs` on select, ensure that the fields corresponding to `state.groups` are set up. Needed in Client-mode grouping/pagination.
522
+ fieldDefs.forEach(field => {
523
+ if (!listFields.find(f => f.field === field.name)) {
524
+ listFields.push({
525
+ field: field.name
526
+ });
527
+ }
528
+ });
529
+ patchQueryFields.forEach(k => {
530
+ if (!listFields.find(f => f.field === k)) {
531
+ listFields.push({
532
+ field: k
533
+ });
534
+ }
535
+ });
536
+ }
537
+
538
+ compositeKeys.forEach(k => {
539
+ if (!listFields.find(f => f.field === k)) {
540
+ listFields.push({
541
+ field: k
542
+ });
543
+ }
544
+ });
545
+ return listFields;
546
+ };
547
+
548
+ const addItemKeyInSelect = (
549
+ fieldDefs,
550
+ itemKey,
551
+ select,
552
+ compositeKeys
553
+ ) => {
554
+ const elementFound = getField(fieldDefs, itemKey);
555
+
556
+ if (itemKey && !elementFound && Array.isArray(select) && !(compositeKeys !== null && compositeKeys?.length) && !select.find(sel => sel.field === itemKey)) {
557
+ return [...select, {
558
+ field: itemKey
559
+ }];
560
+ }
561
+
562
+ return select;
563
+ };
564
+
565
+ const getField = (fieldDefs, columnId) => {
566
+ const fieldsMap = getFieldsMap(fieldDefs);
567
+ return fieldsMap.get(columnId);
568
+ };
569
+
570
+ const getFieldsMap = fieldDefs => {
571
+ const fieldsMap = new Map();
572
+ fieldDefs.forEach(element => {
573
+ fieldsMap.set(element.id, element);
574
+ });
575
+ return fieldsMap;
576
+ };
577
+
498
578
  async function fetchDataFromServer() {
499
579
  let bCallSetRowsColumns = true;
500
- const workListJSON = await fetchAllData();
580
+ const { fieldDefs, itemKey, patchQueryFields } = meta;
581
+ let listFields = fieldDefs ? buildSelect(fieldDefs, undefined, patchQueryFields, compositeKeys) : [];
582
+ listFields = addItemKeyInSelect(fieldDefs, itemKey, listFields, compositeKeys);
583
+ const workListJSON = await fetchAllData(listFields);
501
584
 
502
585
  // don't update these fields until we return from promise
503
586
  let fields = presets[0].children[0].children;
@@ -507,7 +590,7 @@ export default function ListView(props) {
507
590
 
508
591
  const tableDataResults = workListJSON['data'];
509
592
 
510
- const myColumns = getHeaderCells(columnFields, fields);
593
+ const myColumns = getHeaderCells(columnFields, fieldDefs, fields);
511
594
 
512
595
  const selectParams: any = [];
513
596
 
@@ -529,7 +612,7 @@ export default function ListView(props) {
529
612
 
530
613
  setResponse(tableDataResults);
531
614
 
532
- const usingDataResults = getUsingData(tableDataResults, myColumns);
615
+ const usingDataResults = getUsingData(tableDataResults);
533
616
 
534
617
  // store globally, so can be searched, filtered, etc.
535
618
  myRows = updateData(usingDataResults, fields);
@@ -554,8 +637,10 @@ export default function ListView(props) {
554
637
  }
555
638
 
556
639
  useEffect(() => {
557
- fetchDataFromServer();
558
- }, []);
640
+ if (listContext.meta) {
641
+ fetchDataFromServer();
642
+ }
643
+ }, [listContext]);
559
644
 
560
645
  function searchFilter(value: string, rows: Array<any>) {
561
646
  function filterArray(el: any): boolean {
@@ -629,8 +714,8 @@ export default function ListView(props) {
629
714
  }
630
715
 
631
716
  function openWork(row) {
632
- const { pxRefObjectClass, pxRefObjectKey } = row;
633
-
717
+ const { pxRefObjectKey } = row;
718
+ const pxRefObjectClass = row.pxRefObjectClass || row.pxObjClass;
634
719
  if (pxRefObjectClass !== '' && pxRefObjectKey !== '') {
635
720
  thePConn.getActionsApi().openWorkByHandle(pxRefObjectKey, pxRefObjectClass);
636
721
  }
@@ -854,19 +939,37 @@ export default function ListView(props) {
854
939
  return bReturn;
855
940
  }
856
941
 
857
- function _listViewClick(name, row) {
858
- switch (name) {
859
- case 'pxTaskLabel':
860
- openAssignment(row);
861
- break;
942
+ function _listViewClick(row, column) {
943
+ const name = column.id
944
+ if (column.displayAsLink) {
945
+ const { pxObjClass } = row;
946
+ let { pzInsKey } = row;
947
+ if (column.isAssociation) {
948
+ const associationCategory = name.split(':')[0];
949
+ pzInsKey = row[`${associationCategory}:pzInsKey`];
950
+ }
951
+ if (column.isAssignmentLink) {
952
+ thePConn.getActionsApi().openAssignment(pzInsKey, pxObjClass, {
953
+ containerName: 'primary'
954
+ });
955
+ } else {
956
+ thePConn.getActionsApi().openWorkByHandle(pzInsKey, pxObjClass);
957
+ }
958
+ } else {
959
+ switch (name) {
960
+ case 'pxTaskLabel':
961
+ openAssignment(row);
962
+ break;
862
963
 
863
- case 'pxRefObjectInsName':
864
- openWork(row);
865
- break;
964
+ case 'pxRefObjectInsName':
965
+ openWork(row);
966
+ break;
866
967
 
867
- default:
868
- break;
968
+ default:
969
+ break;
970
+ }
869
971
  }
972
+
870
973
  }
871
974
 
872
975
  function _listTitle() {
@@ -945,6 +1048,7 @@ export default function ListView(props) {
945
1048
  variant='outlined'
946
1049
  placeholder=''
947
1050
  size='small'
1051
+ id="search"
948
1052
  onChange={_onSearch}
949
1053
  />
950
1054
  </Grid>
@@ -1008,11 +1112,11 @@ export default function ListView(props) {
1008
1112
  align={column.align}
1009
1113
  className={classes.cell}
1010
1114
  >
1011
- {_showButton(column.id, row) ? (
1115
+ {_showButton(column.id, row) || column.displayAsLink ? (
1012
1116
  <Link
1013
1117
  component='button'
1014
1118
  onClick={() => {
1015
- _listViewClick(column.id, row);
1119
+ _listViewClick(row, column);
1016
1120
  }}
1017
1121
  >
1018
1122
  {column.format && typeof value === 'number'
@@ -0,0 +1,97 @@
1
+ import { useEffect } from 'react';
2
+ import { getContext, readContextResponse } from './utils';
3
+
4
+ export default function useInit(props) {
5
+ const PCore = window.PCore;
6
+ const {
7
+ referenceList,
8
+ getPConnect,
9
+ personalizationId,
10
+ parameters,
11
+ compositeKeys,
12
+ isSearchable,
13
+ allowBulkActions,
14
+ ref,
15
+ showDynamicFields,
16
+ isDataObject,
17
+ xRayUid,
18
+ cosmosTableRef
19
+ } = props;
20
+ let { editing, selectionMode } = props;
21
+
22
+ const runtimeParams = PCore.getRuntimeParamsAPI().getRuntimeParams();
23
+
24
+ let selectionCountThreshold;
25
+ useEffect(() => {
26
+ let isCompStillMounted = true; // react hooks cleanup function will toggle this flag and use it before setting a state variable
27
+
28
+ (async function init() {
29
+ // promise to fetch metadata
30
+ const metaDataPromise = PCore.getAnalyticsUtils().getDataViewMetadata(referenceList, showDynamicFields);
31
+
32
+ const promisesArray = [metaDataPromise];
33
+
34
+ // promise to fetch report configured columns
35
+ const reportColumnsPromise = PCore.getAnalyticsUtils()
36
+ .getFieldsForDataSource(referenceList, false, getPConnect().getContextName())
37
+ .catch(() => {
38
+ return Promise.resolve({
39
+ data: { data: [] }
40
+ });
41
+ });
42
+ promisesArray.push(reportColumnsPromise);
43
+
44
+ const fetchEditDetails = async (metadata) => {
45
+ const {
46
+ data: { isQueryable }
47
+ } = metadata;
48
+ if (!isDataObject) {
49
+ if (!isQueryable) {
50
+ editing = false; /* Force editing to false if DP is non queryable */
51
+ }
52
+
53
+ const { MULTI_ON_HOVER, MULTI } = PCore.getConstants().LIST_SELECTION_MODE;
54
+ if (allowBulkActions && isQueryable) {
55
+ /** enable bulk actions only if DP is queryable */
56
+ selectionMode = MULTI_ON_HOVER;
57
+ }
58
+ if ([MULTI_ON_HOVER, MULTI].includes(selectionMode)) {
59
+ selectionCountThreshold = 250; // Results count should not be greater than threshold to display SelectAll checkbox.
60
+ }
61
+ }
62
+ return Promise.resolve();
63
+ };
64
+
65
+ const editPromise = metaDataPromise.then((metadata) => fetchEditDetails(metadata));
66
+ promisesArray.push(editPromise);
67
+ getContext({
68
+ tableSource: referenceList,
69
+ ListId: personalizationId,
70
+ runtimeParams: parameters ?? runtimeParams,
71
+ promisesArray,
72
+ getPConnect,
73
+ compositeKeys,
74
+ isSearchable,
75
+ isCacheable: true,
76
+ xRayUid
77
+ })
78
+ .then(async (context) => {
79
+ if (isCompStillMounted) {
80
+ return readContextResponse(context, {
81
+ ...props,
82
+ editing,
83
+ selectionCountThreshold,
84
+ ref,
85
+ selectionMode,
86
+ xRayUid,
87
+ cosmosTableRef
88
+ });
89
+ }
90
+ });
91
+ })();
92
+
93
+ return () => {
94
+ isCompStillMounted = false;
95
+ };
96
+ }, []);
97
+ }