@pega/react-sdk-overrides 0.23.6

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 (220) hide show
  1. package/lib/designSystemExtensions/CaseSummaryFields/CaseSummaryFields.css +19 -0
  2. package/lib/designSystemExtensions/CaseSummaryFields/CaseSummaryFields.tsx +156 -0
  3. package/lib/designSystemExtensions/CaseSummaryFields/index.tsx +1 -0
  4. package/lib/designSystemExtensions/DetailsFields/DetailsFields.tsx +154 -0
  5. package/lib/designSystemExtensions/DetailsFields/index.tsx +1 -0
  6. package/lib/designSystemExtensions/FieldGroup/FieldGroup.tsx +113 -0
  7. package/lib/designSystemExtensions/FieldGroup/index.tsx +1 -0
  8. package/lib/designSystemExtensions/FieldGroupList/FieldGroupList.tsx +53 -0
  9. package/lib/designSystemExtensions/FieldGroupList/index.tsx +1 -0
  10. package/lib/designSystemExtensions/FieldValueList/FieldValueList.tsx +106 -0
  11. package/lib/designSystemExtensions/FieldValueList/index.tsx +1 -0
  12. package/lib/designSystemExtensions/Operator/Operator.tsx +195 -0
  13. package/lib/designSystemExtensions/Operator/index.tsx +1 -0
  14. package/lib/designSystemExtensions/Pulse/Pulse.tsx +31 -0
  15. package/lib/designSystemExtensions/Pulse/index.tsx +1 -0
  16. package/lib/forms/AutoComplete/AutoComplete.tsx +183 -0
  17. package/lib/forms/AutoComplete/index.tsx +1 -0
  18. package/lib/forms/CancelAlert/CancelAlert.css +24 -0
  19. package/lib/forms/CancelAlert/CancelAlert.tsx +126 -0
  20. package/lib/forms/CancelAlert/index.tsx +1 -0
  21. package/lib/forms/Checkbox/Checkbox.tsx +68 -0
  22. package/lib/forms/Checkbox/index.tsx +1 -0
  23. package/lib/forms/Currency/Currency.tsx +89 -0
  24. package/lib/forms/Currency/index.tsx +1 -0
  25. package/lib/forms/Date/Date.tsx +79 -0
  26. package/lib/forms/Date/index.tsx +1 -0
  27. package/lib/forms/DateTime/DateTime.tsx +75 -0
  28. package/lib/forms/DateTime/index.tsx +1 -0
  29. package/lib/forms/Decimal/Decimal.tsx +51 -0
  30. package/lib/forms/Decimal/index.tsx +1 -0
  31. package/lib/forms/Dropdown/Dropdown.tsx +82 -0
  32. package/lib/forms/Dropdown/index.tsx +1 -0
  33. package/lib/forms/Email/Email.tsx +68 -0
  34. package/lib/forms/Email/index.tsx +1 -0
  35. package/lib/forms/Integer/Integer.tsx +77 -0
  36. package/lib/forms/Integer/index.tsx +1 -0
  37. package/lib/forms/Percentage/Percentage.tsx +82 -0
  38. package/lib/forms/Percentage/index.tsx +1 -0
  39. package/lib/forms/Phone/Phone.tsx +90 -0
  40. package/lib/forms/Phone/index.tsx +1 -0
  41. package/lib/forms/RadioButtons/RadioButtons.tsx +73 -0
  42. package/lib/forms/RadioButtons/index.tsx +1 -0
  43. package/lib/forms/SemanticLink/SemanticLink.tsx +69 -0
  44. package/lib/forms/SemanticLink/index.tsx +1 -0
  45. package/lib/forms/SemanticLink/utils.ts +51 -0
  46. package/lib/forms/TextArea/TextArea.tsx +66 -0
  47. package/lib/forms/TextArea/index.tsx +1 -0
  48. package/lib/forms/TextContent/TextContent.tsx +40 -0
  49. package/lib/forms/TextContent/index.tsx +1 -0
  50. package/lib/forms/TextInput/TextInput.tsx +61 -0
  51. package/lib/forms/TextInput/index.tsx +1 -0
  52. package/lib/forms/Time/Time.tsx +71 -0
  53. package/lib/forms/Time/index.tsx +1 -0
  54. package/lib/forms/URL/URL.tsx +53 -0
  55. package/lib/forms/URL/index.tsx +1 -0
  56. package/lib/forms/UserReference/UserReference.tsx +197 -0
  57. package/lib/forms/UserReference/UserReferenceUtils.ts +13 -0
  58. package/lib/forms/UserReference/index.tsx +1 -0
  59. package/lib/helpers/auth.js +483 -0
  60. package/lib/helpers/authManager.js +630 -0
  61. package/lib/helpers/config_access.js +268 -0
  62. package/lib/helpers/data_page.ts +24 -0
  63. package/lib/helpers/event-utils.js +20 -0
  64. package/lib/helpers/field-group-utils.js +61 -0
  65. package/lib/helpers/formatters/Boolean.js +38 -0
  66. package/lib/helpers/formatters/Currency.js +74 -0
  67. package/lib/helpers/formatters/CurrencyMap.js +908 -0
  68. package/lib/helpers/formatters/Date.js +77 -0
  69. package/lib/helpers/formatters/common.js +10 -0
  70. package/lib/helpers/formatters/index.js +120 -0
  71. package/lib/helpers/utils.ts +334 -0
  72. package/lib/helpers/versionHelpers.ts +50 -0
  73. package/lib/infra/ActionButtons/ActionButtons.tsx +70 -0
  74. package/lib/infra/ActionButtons/index.tsx +1 -0
  75. package/lib/infra/Assignment/Assignment.tsx +301 -0
  76. package/lib/infra/Assignment/index.tsx +1 -0
  77. package/lib/infra/AssignmentCard/AssignmentCard.tsx +47 -0
  78. package/lib/infra/AssignmentCard/index.tsx +1 -0
  79. package/lib/infra/Attachment/Attachment.css +18 -0
  80. package/lib/infra/Attachment/Attachment.tsx +404 -0
  81. package/lib/infra/Attachment/AttachmentUtils.js +71 -0
  82. package/lib/infra/Attachment/index.tsx +1 -0
  83. package/lib/infra/Containers/FlowContainer/FlowContainer.tsx +511 -0
  84. package/lib/infra/Containers/FlowContainer/helpers.js +147 -0
  85. package/lib/infra/Containers/FlowContainer/index.tsx +1 -0
  86. package/lib/infra/Containers/ModalViewContainer/ModalViewContainer.tsx +320 -0
  87. package/lib/infra/Containers/ModalViewContainer/index.tsx +1 -0
  88. package/lib/infra/Containers/ViewContainer/ViewContainer.tsx +216 -0
  89. package/lib/infra/Containers/ViewContainer/index.tsx +1 -0
  90. package/lib/infra/DashboardFilter/DashboardFilter.tsx +180 -0
  91. package/lib/infra/DashboardFilter/filterUtils.tsx +188 -0
  92. package/lib/infra/DashboardFilter/index.tsx +1 -0
  93. package/lib/infra/DeferLoad/DeferLoad.tsx +175 -0
  94. package/lib/infra/DeferLoad/index.tsx +1 -0
  95. package/lib/infra/ErrorBoundary/ErrorBoundary.tsx +103 -0
  96. package/lib/infra/ErrorBoundary/index.tsx +1 -0
  97. package/lib/infra/MultiStep/MultiStep.css +261 -0
  98. package/lib/infra/MultiStep/MultiStep.tsx +225 -0
  99. package/lib/infra/MultiStep/index.tsx +1 -0
  100. package/lib/infra/NavBar/NavBar.css +170 -0
  101. package/lib/infra/NavBar/NavBar.tsx +393 -0
  102. package/lib/infra/NavBar/index.tsx +1 -0
  103. package/lib/infra/Reference/Reference.tsx +58 -0
  104. package/lib/infra/Reference/index.tsx +1 -0
  105. package/lib/infra/Region/Region.tsx +17 -0
  106. package/lib/infra/Region/index.tsx +1 -0
  107. package/lib/infra/RootContainer/RootContainer.tsx +336 -0
  108. package/lib/infra/RootContainer/index.tsx +1 -0
  109. package/lib/infra/Stages/Stages.tsx +120 -0
  110. package/lib/infra/Stages/index.tsx +1 -0
  111. package/lib/infra/ToDo/ToDo.css +87 -0
  112. package/lib/infra/ToDo/ToDo.tsx +285 -0
  113. package/lib/infra/ToDo/index.tsx +1 -0
  114. package/lib/infra/VerticalTabs/LeftAlignVerticalTab.tsx +27 -0
  115. package/lib/infra/VerticalTabs/VerticalTabs.tsx +75 -0
  116. package/lib/infra/VerticalTabs/index.tsx +1 -0
  117. package/lib/infra/View/View.css +8 -0
  118. package/lib/infra/View/View.tsx +175 -0
  119. package/lib/infra/View/index.tsx +1 -0
  120. package/lib/templates/AppShell/AppShell.css +40 -0
  121. package/lib/templates/AppShell/AppShell.tsx +439 -0
  122. package/lib/templates/AppShell/index.tsx +1 -0
  123. package/lib/templates/CaseSummary/CaseSummary.tsx +50 -0
  124. package/lib/templates/CaseSummary/index.tsx +1 -0
  125. package/lib/templates/CaseView/CaseView.tsx +261 -0
  126. package/lib/templates/CaseView/CaseViewActionsMenu.tsx +73 -0
  127. package/lib/templates/CaseView/index.tsx +1 -0
  128. package/lib/templates/DataReference/DataReference.tsx +290 -0
  129. package/lib/templates/DataReference/index.tsx +1 -0
  130. package/lib/templates/DefaultForm/DefaultForm.css +25 -0
  131. package/lib/templates/DefaultForm/DefaultForm.tsx +52 -0
  132. package/lib/templates/DefaultForm/index.tsx +1 -0
  133. package/lib/templates/Details/Details/Details.tsx +35 -0
  134. package/lib/templates/Details/Details/index.tsx +1 -0
  135. package/lib/templates/Details/DetailsSubTabs/DetailsSubTabs.tsx +65 -0
  136. package/lib/templates/Details/DetailsSubTabs/index.tsx +1 -0
  137. package/lib/templates/Details/DetailsThreeColumn/DetailsThreeColumn.tsx +45 -0
  138. package/lib/templates/Details/DetailsThreeColumn/index.tsx +1 -0
  139. package/lib/templates/Details/DetailsTwoColumn/DetailsTwoColumn.tsx +43 -0
  140. package/lib/templates/Details/DetailsTwoColumn/index.tsx +1 -0
  141. package/lib/templates/FieldGroupTemplate/FieldGroupTemplate.tsx +94 -0
  142. package/lib/templates/FieldGroupTemplate/index.tsx +1 -0
  143. package/lib/templates/InlineDashboard/InlineDashboard.tsx +72 -0
  144. package/lib/templates/InlineDashboard/index.tsx +1 -0
  145. package/lib/templates/InlineDashboardPage/InlineDashboardPage.tsx +41 -0
  146. package/lib/templates/InlineDashboardPage/index.tsx +1 -0
  147. package/lib/templates/ListPage/ListPage.tsx +20 -0
  148. package/lib/templates/ListPage/index.tsx +1 -0
  149. package/lib/templates/ListView/ListView.css +10 -0
  150. package/lib/templates/ListView/ListView.tsx +1230 -0
  151. package/lib/templates/ListView/index.tsx +1 -0
  152. package/lib/templates/MultiReferenceReadOnly/MultiReferenceReadOnly.tsx +42 -0
  153. package/lib/templates/MultiReferenceReadOnly/index.tsx +1 -0
  154. package/lib/templates/NarrowWide/NarrowWide/NarrowWide.css +21 -0
  155. package/lib/templates/NarrowWide/NarrowWide/NarrowWide.tsx +35 -0
  156. package/lib/templates/NarrowWide/NarrowWide/index.tsx +1 -0
  157. package/lib/templates/NarrowWide/NarrowWideDetails/NarrowWideDetails.tsx +53 -0
  158. package/lib/templates/NarrowWide/NarrowWideDetails/index.tsx +1 -0
  159. package/lib/templates/NarrowWide/NarrowWideForm/NarrowWideForm.css +21 -0
  160. package/lib/templates/NarrowWide/NarrowWideForm/NarrowWideForm.tsx +24 -0
  161. package/lib/templates/NarrowWide/NarrowWideForm/index.tsx +1 -0
  162. package/lib/templates/NarrowWide/NarrowWidePage/NarrowWidePage.tsx +38 -0
  163. package/lib/templates/NarrowWide/NarrowWidePage/index.tsx +1 -0
  164. package/lib/templates/OneColumn/OneColumn/OneColumn.tsx +32 -0
  165. package/lib/templates/OneColumn/OneColumn/index.tsx +1 -0
  166. package/lib/templates/OneColumn/OneColumnPage/OneColumnPage.tsx +24 -0
  167. package/lib/templates/OneColumn/OneColumnPage/index.tsx +1 -0
  168. package/lib/templates/OneColumn/OneColumnTab/OneColumnTab.tsx +17 -0
  169. package/lib/templates/OneColumn/OneColumnTab/index.tsx +1 -0
  170. package/lib/templates/PromotedFilters/PromotedFilters.css +7 -0
  171. package/lib/templates/PromotedFilters/PromotedFilters.tsx +160 -0
  172. package/lib/templates/PromotedFilters/index.tsx +1 -0
  173. package/lib/templates/SimpleTable/SimpleTable/SimpleTable.tsx +28 -0
  174. package/lib/templates/SimpleTable/SimpleTable/index.tsx +1 -0
  175. package/lib/templates/SimpleTable/SimpleTableManual/SimpleTableManual.tsx +719 -0
  176. package/lib/templates/SimpleTable/SimpleTableManual/index.tsx +1 -0
  177. package/lib/templates/SimpleTable/SimpleTableSelect/SimpleTableSelect.tsx +129 -0
  178. package/lib/templates/SimpleTable/SimpleTableSelect/index.tsx +1 -0
  179. package/lib/templates/SimpleTable/helpers.ts +360 -0
  180. package/lib/templates/SingleReferenceReadOnly/SingleReferenceReadOnly.tsx +66 -0
  181. package/lib/templates/SingleReferenceReadOnly/index.tsx +1 -0
  182. package/lib/templates/SubTabs/SubTabs.tsx +65 -0
  183. package/lib/templates/SubTabs/index.tsx +1 -0
  184. package/lib/templates/SubTabs/tabUtils.ts +73 -0
  185. package/lib/templates/TwoColumn/TwoColumn/TwoColumn.css +13 -0
  186. package/lib/templates/TwoColumn/TwoColumn/TwoColumn.tsx +58 -0
  187. package/lib/templates/TwoColumn/TwoColumn/index.tsx +1 -0
  188. package/lib/templates/TwoColumn/TwoColumnPage/TwoColumnPage.tsx +25 -0
  189. package/lib/templates/TwoColumn/TwoColumnPage/index.tsx +1 -0
  190. package/lib/templates/TwoColumn/TwoColumnTab/TwoColumnTab.css +12 -0
  191. package/lib/templates/TwoColumn/TwoColumnTab/TwoColumnTab.tsx +55 -0
  192. package/lib/templates/TwoColumn/TwoColumnTab/index.tsx +1 -0
  193. package/lib/templates/WideNarrow/WideNarrow/WideNarrow.css +21 -0
  194. package/lib/templates/WideNarrow/WideNarrow/WideNarrow.tsx +35 -0
  195. package/lib/templates/WideNarrow/WideNarrow/index.tsx +1 -0
  196. package/lib/templates/WideNarrow/WideNarrowDetails/WideNarrowDetails.tsx +54 -0
  197. package/lib/templates/WideNarrow/WideNarrowDetails/index.tsx +1 -0
  198. package/lib/templates/WideNarrow/WideNarrowForm/WideNarrowForm.css +21 -0
  199. package/lib/templates/WideNarrow/WideNarrowForm/WideNarrowForm.tsx +24 -0
  200. package/lib/templates/WideNarrow/WideNarrowForm/index.tsx +1 -0
  201. package/lib/templates/WideNarrow/WideNarrowPage/WideNarrowPage.tsx +38 -0
  202. package/lib/templates/WideNarrow/WideNarrowPage/index.tsx +1 -0
  203. package/lib/templates/utils.ts +23 -0
  204. package/lib/widgets/AppAnnouncement/AppAnnouncement.tsx +67 -0
  205. package/lib/widgets/AppAnnouncement/index.tsx +1 -0
  206. package/lib/widgets/CaseHistory/CaseHistory.tsx +169 -0
  207. package/lib/widgets/CaseHistory/index.tsx +1 -0
  208. package/lib/widgets/FileUtility/ActionButtonsForFileUtil.css +27 -0
  209. package/lib/widgets/FileUtility/ActionButtonsForFileUtil.tsx +22 -0
  210. package/lib/widgets/FileUtility/FileUtility.css +117 -0
  211. package/lib/widgets/FileUtility/FileUtility.tsx +567 -0
  212. package/lib/widgets/FileUtility/index.tsx +0 -0
  213. package/lib/widgets/Followers/Followers.tsx +43 -0
  214. package/lib/widgets/Followers/index.tsx +1 -0
  215. package/lib/widgets/SummaryItem/SummaryItem.css +78 -0
  216. package/lib/widgets/SummaryItem/SummaryItem.tsx +80 -0
  217. package/lib/widgets/SummaryItem/index.tsx +1 -0
  218. package/lib/widgets/SummaryList/SummaryList.tsx +12 -0
  219. package/lib/widgets/SummaryList/index.tsx +1 -0
  220. package/package.json +14 -0
@@ -0,0 +1,719 @@
1
+ /* eslint-disable no-nested-ternary */
2
+ import React, { useEffect, useState } from 'react';
3
+ import Table from '@material-ui/core/Table';
4
+ import TableBody from '@material-ui/core/TableBody';
5
+ import TableCell from '@material-ui/core/TableCell';
6
+ import TableContainer from '@material-ui/core/TableContainer';
7
+ import TableHead from '@material-ui/core/TableHead';
8
+ import TableRow from '@material-ui/core/TableRow';
9
+ import Paper from '@material-ui/core/Paper';
10
+ import { makeStyles } from '@material-ui/core/styles';
11
+ import { buildFieldsForTable, filterData } from '@pega/react-sdk-components/lib/components/helpers';
12
+ import { getDataPage } from '@pega/react-sdk-components/lib/components/helpers/data_page';
13
+ import Link from '@material-ui/core/Link';
14
+ import { getReferenceList } from '@pega/react-sdk-components/lib/components/helpers/field-group-utils';
15
+ import { Utils } from '@pega/react-sdk-components/lib/components/helpers/utils';
16
+ import { createElement } from 'react';
17
+
18
+ import createPConnectComponent from '@pega/react-sdk-components/lib/bridge/react_pconnect';
19
+
20
+ import TableSortLabel from '@material-ui/core/TableSortLabel';
21
+ import MoreIcon from '@material-ui/icons/MoreVert';
22
+ import Menu from '@material-ui/core/Menu';
23
+ import MenuItem from '@material-ui/core/MenuItem';
24
+ import FilterListIcon from '@material-ui/icons/FilterList';
25
+ import SubjectIcon from '@material-ui/icons/Subject';
26
+ import Dialog from '@material-ui/core/Dialog';
27
+ import DialogActions from '@material-ui/core/DialogActions';
28
+ import DialogContent from '@material-ui/core/DialogContent';
29
+ import DialogTitle from '@material-ui/core/DialogTitle';
30
+ import Select from '@material-ui/core/Select';
31
+ import Button from '@material-ui/core/Button';
32
+ import TextField from '@material-ui/core/TextField';
33
+
34
+ const useStyles = makeStyles((/* theme */) => ({
35
+ label: {
36
+ margin: '8px'
37
+ },
38
+ header: {
39
+ background: '#f5f5f5'
40
+ },
41
+ tableCell: {
42
+ borderRight: '1px solid lightgray',
43
+ padding: '8px'
44
+ },
45
+ visuallyHidden: {
46
+ border: 0,
47
+ clip: 'rect(0 0 0 0)',
48
+ height: 1,
49
+ margin: -1,
50
+ overflow: 'hidden',
51
+ padding: 0,
52
+ position: 'absolute',
53
+ top: 20,
54
+ width: 1
55
+ },
56
+ moreIcon: {
57
+ verticalAlign: 'bottom'
58
+ }
59
+ }));
60
+
61
+ declare const PCore: any;
62
+
63
+ let menuColumnId = '';
64
+ let menuColumnType = '';
65
+ let menuColumnLabel = '';
66
+
67
+ const filterByColumns: Array<any> = [];
68
+ let myRows: Array<any>;
69
+ export default function SimpleTableManual(props) {
70
+ const classes = useStyles();
71
+ const {
72
+ getPConnect,
73
+ referenceList = [], // if referenceList not in configProps$, default to empy list
74
+ children,
75
+ renderMode,
76
+ presets,
77
+ label: labelProp,
78
+ showLabel,
79
+ dataPageName,
80
+ contextClass,
81
+ hideAddRow,
82
+ hideDeleteRow,
83
+ propertyLabel,
84
+ fieldMetadata
85
+ } = props;
86
+ const pConn = getPConnect();
87
+ const [rowData, setRowData] = useState([]);
88
+ const [elements, setElementsData] = useState([]);
89
+ const [order, setOrder] = useState<Order>('asc');
90
+ const [orderBy, setOrderBy] = useState<keyof any>('');
91
+ const [anchorEl, setAnchorEl] = useState<null | HTMLElement>(null);
92
+ const [open, setOpen] = useState(false);
93
+ const [filterBy, setFilterBy] = useState<string>();
94
+ const [containsDateOrTime, setContainsDateOrTime] = useState<boolean>(false);
95
+ const [filterType, setFilterType] = useState<string>('string');
96
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars, no-unused-vars
97
+ const [displayDialogFilterName, setDisplayDialogFilterName] = useState<string>('');
98
+ const [displayDialogContainsFilter, setDisplayDialogContainsFilter] =
99
+ useState<string>('contains');
100
+ const [displayDialogContainsValue, setDisplayDialogContainsValue] = useState<string>('');
101
+ const [displayDialogDateFilter, setDisplayDialogDateFilter] = useState<string>('notequal');
102
+ const [displayDialogDateValue, setDisplayDialogDateValue] = useState<string>('');
103
+
104
+ const parameters = fieldMetadata?.datasource?.parameters;
105
+
106
+ const label = labelProp || propertyLabel;
107
+ const propsToUse = { label, showLabel, ...getPConnect().getInheritedProps() };
108
+ if (propsToUse.showLabel === false) {
109
+ propsToUse.label = '';
110
+ }
111
+ // Getting current context
112
+ const context = getPConnect().getContextName();
113
+ const resolvedList = getReferenceList(pConn);
114
+ const pageReference = `${pConn.getPageReference()}${resolvedList}`;
115
+ pConn.setReferenceList(resolvedList);
116
+ const menuIconOverride$ = Utils.getImageSrc('trash', PCore.getAssetLoader().getStaticServerUrl());
117
+
118
+ const resolvedFields = children?.[0]?.children || presets?.[0].children?.[0].children;
119
+ // NOTE: props has each child.config with datasource and value undefined
120
+ // but getRawMetadata() has each child.config with datasource and value showing their unresolved values (ex: "@P thePropName")
121
+ // We need to use the prop name as the "glue" to tie the table dataSource, displayColumns and data together.
122
+ // So, in the code below, we'll use the unresolved config.value (but replacing the space with an underscore to keep things happy)
123
+ const rawMetadata = getPConnect().getRawMetadata();
124
+
125
+ // get raw config since @P and other annotations are processed and don't appear in the resolved config.
126
+ // Destructure "raw" children into array var: "rawFields"
127
+ // NOTE: when config.listType == "associated", the property can be found in either
128
+ // config.value (ex: "@P .DeclarantChoice") or
129
+ // config.datasource (ex: "@ASSOCIATED .DeclarantChoice")
130
+ // Neither of these appear in the resolved props
131
+
132
+ const rawConfig = rawMetadata?.config;
133
+ const rawFields =
134
+ rawConfig?.children?.[0]?.children || rawConfig?.presets?.[0].children?.[0]?.children;
135
+
136
+ const readOnlyMode = renderMode === 'ReadOnly';
137
+ const editableMode = renderMode === 'Editable';
138
+ const showAddRowButton = !readOnlyMode && !hideAddRow;
139
+ const showDeleteButton = !readOnlyMode && !hideDeleteRow;
140
+ useEffect(() => {
141
+ if (editableMode) {
142
+ // eslint-disable-next-line @typescript-eslint/no-use-before-define
143
+ buildElementsForTable();
144
+ } else {
145
+ // eslint-disable-next-line @typescript-eslint/no-use-before-define
146
+ generateRowsData();
147
+ }
148
+ }, [referenceList.length]);
149
+
150
+ // Nebula has other handling for isReadOnlyMode but has Cosmos-specific code
151
+ // so ignoring that for now...
152
+ // fieldDefs will be an array where each entry will have a "name" which will be the
153
+ // "resolved" property name (that we can use as the colId) though it's not really
154
+ // resolved. The buildFieldsForTable helper just removes the "@P " (which is what
155
+ // Nebula does). It will also have the "label", and "meta" contains the original,
156
+ // unchanged config info. For now, much of the info here is carried over from
157
+ // Nebula and we may not end up using it all.
158
+ const fieldDefs = buildFieldsForTable(rawFields, resolvedFields, showDeleteButton);
159
+
160
+ const displayedColumns = fieldDefs.map(field => {
161
+ return field.name ? field.name : field.cellRenderer;
162
+ });
163
+
164
+ // console.log(`SimpleTable displayedColumns:`);
165
+ // console.log(displayedColumns);
166
+
167
+ // And now we can process the resolvedFields to add in the "name"
168
+ // from from the fieldDefs. This "name" is the value that
169
+ // we'll share to connect things together in the table.
170
+
171
+ // const processedFields = resolvedFields.map((field, i) => {
172
+ // field.config['name'] = displayedColumns[i]; // .config["value"].replace(/ ./g,"_"); // replace space dot with underscore
173
+ // return field;
174
+ // });
175
+
176
+ // console.log("SimpleTable processedFields:");
177
+ // console.log(processedFields);
178
+
179
+ // return the value that should be shown as the contents for the given row data
180
+ // of the given row field
181
+ function getRowValue(inRowData: Object, inColKey: string): any {
182
+ // See what data (if any) we have to display
183
+ const refKeys: Array<string> = inColKey.split('.');
184
+ let valBuilder = inRowData;
185
+ for (const key of refKeys) {
186
+ valBuilder = valBuilder[key];
187
+ }
188
+ return valBuilder;
189
+ }
190
+
191
+ const formatRowsData = data => {
192
+ return data.map(item => {
193
+ return displayedColumns.reduce((dataForRow, colKey) => {
194
+ dataForRow[colKey] = getRowValue(item, colKey);
195
+ return dataForRow;
196
+ }, {});
197
+ });
198
+ };
199
+
200
+ function generateRowsData() {
201
+ // if dataPageName property value exists then make a datapage fetch call and get the list of data.
202
+ if (dataPageName) {
203
+ getDataPage(dataPageName, parameters, context).then(listData => {
204
+ const data = formatRowsData(listData);
205
+ myRows = data;
206
+ setRowData(data);
207
+ });
208
+ } else {
209
+ // The referenceList prop has the JSON data for each row to be displayed
210
+ // in the table. So, iterate over referenceList to create the dataRows that
211
+ // we're using as the table's dataSource
212
+ const data: any = [];
213
+ for (const row of referenceList) {
214
+ const dataForRow: Object = {};
215
+ for (const col of displayedColumns) {
216
+ const colKey: string = col;
217
+ const theVal = getRowValue(row, colKey);
218
+ dataForRow[colKey] = theVal || '';
219
+ }
220
+ data.push(dataForRow);
221
+ myRows = data;
222
+ }
223
+ setRowData(data);
224
+ }
225
+ }
226
+
227
+ // These are the data structures referred to in the html file.
228
+ // These are the relationships that make the table work
229
+ // displayedColumns: key/value pairs where key is order of column and
230
+ // value is the property shown in that column. Ex: 1: "FirstName"
231
+ // processedFields: key/value pairs where each key is order of column
232
+ // and each value is an object of more detailed information about that
233
+ // column.
234
+ // rowData: array of each row's key/value pairs. Inside each row,
235
+ // each key is an entry in displayedColumns: ex: "FirstName": "Charles"
236
+ // Ex: { 1: {config: {label: "First Name", readOnly: true: name: "FirstName"}}, type: "TextInput" }
237
+ // The "type" indicates the type of component that should be used for editing (when editing is enabled)
238
+ //
239
+ // Note that the "property" shown in the column ("FirstName" in the above examples) is what
240
+ // ties the 3 data structures together.
241
+
242
+ // console.log("SimpleTable displayedColumns:");
243
+ // console.log(displayedColumns);
244
+ // console.log("SimpleTable processedFields:");
245
+ // console.log(processedFields);
246
+ // console.log(`SimpleTable rowData (${rowData.length} row(s)):`);
247
+ // console.log(JSON.stringify(rowData));
248
+
249
+ const addRecord = () => {
250
+ if (PCore.getPCoreVersion()?.includes('8.7')) {
251
+ pConn.getListActions().insert({ classID: contextClass }, referenceList.length, pageReference);
252
+ } else {
253
+ pConn.getListActions().insert({ classID: contextClass }, referenceList.length);
254
+ }
255
+ };
256
+
257
+ const deleteRecord = index => {
258
+ if (PCore.getPCoreVersion()?.includes('8.7')) {
259
+ pConn.getListActions().deleteEntry(index, pageReference);
260
+ } else {
261
+ pConn.getListActions().deleteEntry(index);
262
+ }
263
+ };
264
+
265
+ function buildElementsForTable() {
266
+ const eleData: any = [];
267
+ referenceList.forEach((element, index) => {
268
+ const data: any = [];
269
+ rawFields.forEach(item => {
270
+ // removing label field from config to hide title in the table cell
271
+ item = {...item, config: {...item.config, label: ''}};
272
+ const referenceListData = getReferenceList(pConn);
273
+ const isDatapage = referenceListData.startsWith('D_');
274
+ const pageReferenceValue = isDatapage
275
+ ? `${referenceListData}[${index}]`
276
+ : `${pConn.getPageReference()}${referenceListData.substring(
277
+ referenceListData.lastIndexOf('.')
278
+ )}[${index}]`;
279
+ const config = {
280
+ meta: item,
281
+ options: {
282
+ context,
283
+ pageReference: pageReferenceValue,
284
+ referenceList: referenceListData,
285
+ hasForm: true
286
+ }
287
+ };
288
+ const view = PCore.createPConnect(config);
289
+ data.push(createElement(createPConnectComponent(), view));
290
+ });
291
+ eleData.push(data);
292
+ });
293
+ setElementsData(eleData);
294
+ }
295
+
296
+ const handleRequestSort = (event: React.MouseEvent<unknown>, property: keyof any) => {
297
+ const isAsc = orderBy === property && order === 'asc';
298
+ setOrder(isAsc ? 'desc' : 'asc');
299
+ setOrderBy(property);
300
+ };
301
+
302
+ const createSortHandler = (property: keyof any) => (event: React.MouseEvent<unknown>) => {
303
+ handleRequestSort(event, property);
304
+ };
305
+
306
+ function descendingComparator<T>(a: T, b: T, orderedBy: keyof T) {
307
+ if (b[orderedBy] < a[orderedBy]) {
308
+ return -1;
309
+ }
310
+ if (b[orderedBy] > a[orderedBy]) {
311
+ return 1;
312
+ }
313
+ return 0;
314
+ }
315
+
316
+ type Order = 'asc' | 'desc';
317
+
318
+ function getComparator<Key extends keyof any>(
319
+ theOrder: Order,
320
+ orderedBy: Key
321
+ // eslint-disable-next-line no-unused-vars
322
+ ): (a: { [key in Key]: number | string }, b: { [key in Key]: number | string }) => number {
323
+ return theOrder === 'desc'
324
+ ? (a, b) => descendingComparator(a, b, orderedBy)
325
+ : (a, b) => -descendingComparator(a, b, orderedBy);
326
+ }
327
+
328
+ // eslint-disable-next-line no-unused-vars
329
+ function stableSort<T>(array: Array<T>, comparator: (a: T, b: T) => number) {
330
+ const stabilizedThis = array.map((el, index) => [el, index] as [T, number]);
331
+ stabilizedThis.sort((a, b) => {
332
+ // eslint-disable-next-line @typescript-eslint/no-shadow, no-shadow
333
+ const order = comparator(a[0], b[0]);
334
+ if (order !== 0) return order;
335
+ return a[1] - b[1];
336
+ });
337
+
338
+ return stabilizedThis.map(el => el[0]);
339
+ }
340
+
341
+ function _menuClick(event, columnId: string, columnType: string, labelValue: string) {
342
+ menuColumnId = columnId;
343
+ menuColumnType = columnType;
344
+ menuColumnLabel = labelValue;
345
+
346
+ setAnchorEl(event.currentTarget);
347
+ }
348
+
349
+ function _menuClose() {
350
+ setAnchorEl(null);
351
+ }
352
+
353
+ function _filterMenu() {
354
+ setAnchorEl(null);
355
+
356
+ let bFound = false;
357
+
358
+ for (const filterObj of filterByColumns) {
359
+ if (filterObj.ref === menuColumnId) {
360
+ setFilterBy(menuColumnLabel);
361
+ if (
362
+ filterObj.type === 'Date' ||
363
+ filterObj.type === 'DateTime' ||
364
+ filterObj.type === 'Time'
365
+ ) {
366
+ setContainsDateOrTime(true);
367
+ setFilterType(filterObj.type);
368
+ setDisplayDialogDateFilter(filterObj.containsFilter);
369
+ setDisplayDialogDateValue(filterObj.containsFilterValue);
370
+ } else {
371
+ setContainsDateOrTime(false);
372
+ setFilterType('string');
373
+ setDisplayDialogContainsFilter(filterObj.containsFilter);
374
+ setDisplayDialogContainsValue(filterObj.containsFilterValue);
375
+ }
376
+ bFound = true;
377
+ break;
378
+ }
379
+ }
380
+
381
+ if (!bFound) {
382
+ setFilterBy(menuColumnLabel);
383
+ setDisplayDialogFilterName(menuColumnId);
384
+ setDisplayDialogContainsValue('');
385
+
386
+ switch (menuColumnType) {
387
+ case 'Date':
388
+ case 'DateTime':
389
+ case 'Time':
390
+ setContainsDateOrTime(true);
391
+ setFilterType(menuColumnType);
392
+ break;
393
+ default:
394
+ setContainsDateOrTime(false);
395
+ setFilterType('string');
396
+ break;
397
+ }
398
+ }
399
+
400
+ // open dialog
401
+ setOpen(true);
402
+ }
403
+
404
+ function _groupMenu() {}
405
+
406
+ function _closeDialog() {
407
+ setOpen(false);
408
+ }
409
+
410
+ function _dialogContainsFilter(event) {
411
+ setDisplayDialogContainsFilter(event.target.value);
412
+ }
413
+
414
+ function _dialogContainsValue(event) {
415
+ setDisplayDialogContainsValue(event.target.value);
416
+ }
417
+
418
+ function _dialogDateFilter(event) {
419
+ setDisplayDialogDateFilter(event.target.value);
420
+ }
421
+
422
+ function _dialogDateValue(event) {
423
+ setDisplayDialogDateValue(event.target.value);
424
+ }
425
+
426
+ function filterSortGroupBy() {
427
+ // get original data set
428
+ let theData: any = myRows.slice();
429
+
430
+ // last filter config data is global
431
+ theData = theData.filter(filterData(filterByColumns));
432
+
433
+ // move data to array and then sort
434
+ setRowData(theData);
435
+ }
436
+
437
+ function updateFilterWithInfo() {
438
+ let bFound = false;
439
+ for (const filterObj of filterByColumns) {
440
+ if (filterObj['ref'] === menuColumnId) {
441
+ filterObj['type'] = filterType;
442
+ if (containsDateOrTime) {
443
+ filterObj['containsFilter'] = displayDialogDateFilter;
444
+ filterObj['containsFilterValue'] = displayDialogDateValue;
445
+ } else {
446
+ filterObj['containsFilter'] = displayDialogContainsFilter;
447
+ filterObj['containsFilterValue'] = displayDialogContainsValue;
448
+ }
449
+ bFound = true;
450
+ break;
451
+ }
452
+ }
453
+
454
+ if (!bFound) {
455
+ // add in
456
+ const filterObj: any = {};
457
+ filterObj.ref = menuColumnId;
458
+ filterObj['type'] = filterType;
459
+ if (containsDateOrTime) {
460
+ filterObj['containsFilter'] = displayDialogDateFilter;
461
+ filterObj['containsFilterValue'] = displayDialogDateValue;
462
+ } else {
463
+ filterObj['containsFilter'] = displayDialogContainsFilter;
464
+ filterObj['containsFilterValue'] = displayDialogContainsValue;
465
+ }
466
+
467
+ filterByColumns.push(filterObj);
468
+ }
469
+ }
470
+
471
+ function _submitFilter() {
472
+ updateFilterWithInfo();
473
+ filterSortGroupBy();
474
+
475
+ setOpen(false);
476
+ }
477
+
478
+ function _showFilteredIcon(columnId) {
479
+ for (const filterObj of filterByColumns) {
480
+ if (filterObj['ref'] === columnId) {
481
+ // eslint-disable-next-line sonarjs/prefer-single-boolean-return
482
+ if (filterObj['containsFilterValue'] !== '') {
483
+ return true;
484
+ }
485
+ return false;
486
+ }
487
+ }
488
+
489
+ return false;
490
+ }
491
+
492
+ function results() {
493
+ const len = editableMode ? elements.length : rowData.length;
494
+
495
+ return len ? (
496
+ <span style={{ fontSize: '0.9em', opacity: '0.7' }}>
497
+ {len} result{len > 1 ? 's' : ''}
498
+ </span>
499
+ ) : null;
500
+ }
501
+
502
+ return (
503
+ <React.Fragment>
504
+ <TableContainer component={Paper} style={{ margin: '4px 0px' }} id="simple-table-manual">
505
+ {propsToUse.label && (
506
+ <h3 className={classes.label}>
507
+ {propsToUse.label} {results()}
508
+ </h3>
509
+ )}
510
+ <Table>
511
+ <TableHead className={classes.header}>
512
+ <TableRow>
513
+ {fieldDefs.map((field: any, index) => {
514
+ return (
515
+ <TableCell key={`head-${displayedColumns[index]}`} className={classes.tableCell}>
516
+ {readOnlyMode ? (
517
+ <div>
518
+ <TableSortLabel
519
+ active={orderBy === displayedColumns[index]}
520
+ direction={orderBy === displayedColumns[index] ? order : 'asc'}
521
+ onClick={createSortHandler(displayedColumns[index])}
522
+ >
523
+ {field.label}
524
+ {_showFilteredIcon(field.name) && (
525
+ <FilterListIcon className={classes.moreIcon} />
526
+ )}
527
+ {orderBy === displayedColumns[index] ? (
528
+ <span className={classes.visuallyHidden}>
529
+ {order === 'desc' ? 'sorted descending' : 'sorted ascending'}
530
+ </span>
531
+ ) : null}
532
+ </TableSortLabel>
533
+ <MoreIcon
534
+ id='menu-icon'
535
+ className={classes.moreIcon}
536
+ onClick={event => {
537
+ _menuClick(event, field.name, field.meta.type, field.label);
538
+ }}
539
+ />
540
+ </div>
541
+ ) : (
542
+ field.label
543
+ )}
544
+ </TableCell>
545
+ );
546
+ })}
547
+ </TableRow>
548
+ </TableHead>
549
+ <TableBody>
550
+ {editableMode &&
551
+ elements.map((row: any, index) => {
552
+ const theKey = `row-${index}`;
553
+ return (
554
+ <TableRow key={theKey}>
555
+ {row.map((item, childIndex) => {
556
+ const theColKey = `data-${index}-${childIndex}`;
557
+ return (
558
+ <TableCell key={theColKey} className={classes.tableCell}>
559
+ {item}
560
+ </TableCell>
561
+ );
562
+ })}
563
+ {showDeleteButton && (
564
+ <TableCell>
565
+ <button
566
+ type='button'
567
+ className='psdk-utility-button'
568
+ id='delete-button'
569
+ onClick={() => deleteRecord(index)}
570
+ >
571
+ <img
572
+ className='psdk-utility-card-action-svg-icon'
573
+ src={menuIconOverride$}
574
+ ></img>
575
+ </button>
576
+ </TableCell>
577
+ )}
578
+ </TableRow>
579
+ );
580
+ })}
581
+ {readOnlyMode &&
582
+ rowData &&
583
+ rowData.length > 0 &&
584
+ stableSort(rowData, getComparator(order, orderBy))
585
+ .slice(0)
586
+ .map(row => {
587
+ return (
588
+ <TableRow key={row[1]}>
589
+ {displayedColumns.map(colKey => {
590
+ return (
591
+ <TableCell key={colKey} className={classes.tableCell}>
592
+ {typeof row[colKey] === 'boolean' && !row[colKey]
593
+ ? 'False'
594
+ : typeof row[colKey] === 'boolean' && row[colKey]
595
+ ? 'True'
596
+ : row[colKey]}
597
+ </TableCell>
598
+ );
599
+ })}
600
+ </TableRow>
601
+ );
602
+ })}
603
+ </TableBody>
604
+ </Table>
605
+ {readOnlyMode && rowData && rowData.length === 0 && (
606
+ <div className='no-records' id='no-records'>
607
+ No records found.
608
+ </div>
609
+ )}
610
+ {editableMode && referenceList && referenceList.length === 0 && (
611
+ <div className='no-records' id='no-records'>
612
+ No records found.
613
+ </div>
614
+ )}
615
+ </TableContainer>
616
+ {showAddRowButton && (
617
+ <div style={{ fontSize: '1rem' }}>
618
+ <Link style={{ cursor: 'pointer' }} onClick={addRecord}>
619
+ + Add
620
+ </Link>
621
+ </div>
622
+ )}
623
+ <Menu
624
+ id='simple-menu'
625
+ anchorEl={anchorEl}
626
+ keepMounted
627
+ open={Boolean(anchorEl)}
628
+ onClose={_menuClose}
629
+ >
630
+ <MenuItem onClick={_filterMenu}>
631
+ <FilterListIcon /> Filter
632
+ </MenuItem>
633
+ <MenuItem onClick={_groupMenu}>
634
+ <SubjectIcon /> Group
635
+ </MenuItem>
636
+ </Menu>
637
+ <Dialog open={open} onClose={_closeDialog} aria-labelledby='form-dialog-title'>
638
+ <DialogTitle id='form-dialog-title'>Filter: {filterBy}</DialogTitle>
639
+ <DialogContent>
640
+ {containsDateOrTime ? (
641
+ <>
642
+ <Select value={displayDialogDateFilter} onChange={_dialogDateFilter} fullWidth>
643
+ <MenuItem value='notequal'>is not equal to</MenuItem>
644
+ <MenuItem value='equal'>is equal to</MenuItem>
645
+ <MenuItem value='after'>after</MenuItem>
646
+ <MenuItem value='before'>before</MenuItem>
647
+ <MenuItem value='null'>is null</MenuItem>
648
+ <MenuItem value='notnull'>is not null</MenuItem>
649
+ </Select>
650
+ {filterType === 'Date' && (
651
+ <TextField
652
+ autoFocus
653
+ margin='dense'
654
+ id='containsFilter'
655
+ type='date'
656
+ fullWidth
657
+ value={displayDialogDateValue}
658
+ onChange={_dialogDateValue}
659
+ />
660
+ )}
661
+ {filterType === 'DateTime' && (
662
+ <TextField
663
+ autoFocus
664
+ margin='dense'
665
+ id='containsFilter'
666
+ type='datetime-local'
667
+ fullWidth
668
+ value={displayDialogDateValue}
669
+ onChange={_dialogDateValue}
670
+ />
671
+ )}
672
+ {filterType === 'Time' && (
673
+ <TextField
674
+ autoFocus
675
+ margin='dense'
676
+ id='containsFilter'
677
+ type='time'
678
+ fullWidth
679
+ value={displayDialogDateValue}
680
+ onChange={_dialogDateValue}
681
+ />
682
+ )}
683
+ </>
684
+ ) : (
685
+ <>
686
+ <Select
687
+ id='filter'
688
+ fullWidth
689
+ onChange={_dialogContainsFilter}
690
+ value={displayDialogContainsFilter}
691
+ >
692
+ <MenuItem value='contains'>Contains</MenuItem>
693
+ <MenuItem value='equals'>Equals</MenuItem>
694
+ <MenuItem value='startswith'>Starts with</MenuItem>
695
+ </Select>
696
+ <TextField
697
+ autoFocus
698
+ margin='dense'
699
+ id='containsFilter'
700
+ type='text'
701
+ fullWidth
702
+ value={displayDialogContainsValue}
703
+ onChange={_dialogContainsValue}
704
+ />
705
+ </>
706
+ )}
707
+ </DialogContent>
708
+ <DialogActions>
709
+ <Button onClick={_closeDialog} color='secondary'>
710
+ Cancel
711
+ </Button>
712
+ <Button onClick={_submitFilter} color='primary'>
713
+ Submit
714
+ </Button>
715
+ </DialogActions>
716
+ </Dialog>
717
+ </React.Fragment>
718
+ );
719
+ }