@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,404 @@
1
+ /* eslint-disable react/jsx-boolean-value */
2
+
3
+ import { Button } from '@material-ui/core';
4
+ import React, { useState, useEffect } from 'react';
5
+ import { buildFilePropsFromResponse, getIconFromFileType, validateMaxSize, getIconForAttachment } from './AttachmentUtils';
6
+ import './Attachment.css';
7
+ import SummaryList from '@pega/react-sdk-components/lib/components/widgets/SummaryList'
8
+ import { CircularProgress } from "@material-ui/core";
9
+ import download from "downloadjs";
10
+
11
+ declare const PCore: any;
12
+
13
+ function getCurrentAttachmentsList(context) {
14
+ return PCore.getStoreValue('.attachmentsList', 'context_data', context) || [];
15
+ }
16
+
17
+ export default function Attachment(props) {
18
+ const {value, getPConnect, label} = props;
19
+ /* this is a temporary fix because required is supposed to be passed as a boolean and NOT as a string */
20
+ let { required, disabled } = props;
21
+ [required, disabled] = [required, disabled].map(
22
+ prop => prop === true || (typeof prop === 'string' && prop === 'true')
23
+ );
24
+ let arFileList$: Array<any> = [];
25
+ const pConn = getPConnect();
26
+
27
+ let fileTemp: any = {};
28
+
29
+ let categoryName = '';
30
+ if (value && value.pyCategoryName) {
31
+ categoryName = value.pyCategoryName;
32
+ }
33
+
34
+ let valueRef = pConn.getStateProps().value;
35
+ valueRef = valueRef.indexOf('.') === 0 ? valueRef.substring(1) : valueRef;
36
+ const [file, setFile] = useState(fileTemp);
37
+
38
+ const fileDownload = (data, fileName, ext) => {
39
+ const fileData = ext ? `${fileName}.${ext}` : fileName;
40
+ download(atob(data), fileData);
41
+ };
42
+
43
+ function _downloadFileFromList(fileObj: any) {
44
+ PCore.getAttachmentUtils()
45
+ .downloadAttachment(fileObj.pzInsKey, pConn.getContextName())
46
+ .then((content) => {
47
+ const extension = fileObj.pyAttachName.split(".").pop();
48
+ fileDownload(content.data, fileObj.pyFileName, extension);
49
+ })
50
+ .catch(() => {});
51
+ }
52
+
53
+ function setNewFiles(arFiles) {
54
+ let index = 0;
55
+ for (const item of arFiles) {
56
+ if (!validateMaxSize(item, 5)) {
57
+ item.error = true;
58
+ item.meta = "File is too big. Max allowed size is 5MB.";
59
+ }
60
+ item.mimeType = item.type;
61
+ item.icon = getIconFromFileType(item.type);
62
+ item.ID = `${new Date().getTime()}I${index}`;
63
+ index+=1;
64
+ }
65
+ return arFiles;
66
+ }
67
+
68
+ function getFiles(arFiles: Array<any>) {
69
+ return setNewFiles(arFiles);
70
+ }
71
+
72
+ function getNewListUtilityItemProps({
73
+ att,
74
+ cancelFile,
75
+ downloadFile,
76
+ deleteFile,
77
+ removeFile
78
+ }) {
79
+ let actions;
80
+ if (att.progress && att.progress !== 100) {
81
+ actions = [
82
+ {
83
+ id: `Cancel-${att.ID}`,
84
+ text: "Cancel",
85
+ icon: "times",
86
+ onClick: cancelFile
87
+ }
88
+ ];
89
+ } else if (att.links) {
90
+ const isFile = att.type === "FILE";
91
+ const ID = att.ID.replace(/\s/gi, "");
92
+ const actionsMap = new Map([
93
+ [
94
+ "download",
95
+ {
96
+ id: `download-${ID}`,
97
+ text: isFile ? "Download" : "Open",
98
+ icon: isFile ? "download" : "open",
99
+ onClick: downloadFile
100
+ }
101
+ ],
102
+ [
103
+ "delete",
104
+ {
105
+ id: `Delete-${ID}`,
106
+ text: "Delete",
107
+ icon: "trash",
108
+ onClick: deleteFile
109
+ }
110
+ ]
111
+ ]);
112
+ actions = [];
113
+ actionsMap.forEach((action, actionKey) => {
114
+ if (att.links[actionKey]) {
115
+ actions.push(action);
116
+ }
117
+ });
118
+ } else if (att.error) {
119
+ actions = [
120
+ {
121
+ id: `Remove-${att.ID}`,
122
+ text: "Remove",
123
+ icon: "trash",
124
+ onClick: removeFile
125
+ }
126
+ ];
127
+ }
128
+ return {
129
+ id: att.ID,
130
+ visual: {
131
+ icon: getIconForAttachment(att),
132
+ progress: att.progress === 100 ? undefined: att.progress,
133
+ },
134
+ primary: {
135
+ type: att.type,
136
+ name: att.name,
137
+ icon: "trash",
138
+ click: removeFile,
139
+ },
140
+ secondary: {
141
+ text: att.meta
142
+ },
143
+ actions
144
+ };
145
+ };
146
+
147
+ const onFileAdded = (event) => {
148
+ const addedFile = event.target.files[0];
149
+ setFile({
150
+ props: {
151
+ name: addedFile.name,
152
+ icon: getIconFromFileType(addedFile.type),
153
+ },
154
+ inProgress: true
155
+ });
156
+ const arFiles$ = getFiles(event.target.files);
157
+ const myFiles: any = Array.from(arFiles$);
158
+
159
+ const onUploadProgress = () => {};
160
+
161
+ const errorHandler = () => {};
162
+
163
+ PCore.getAttachmentUtils()
164
+ .uploadAttachment(
165
+ myFiles[0],
166
+ onUploadProgress,
167
+ errorHandler,
168
+ pConn.getContextName()
169
+ )
170
+ .then((fileRes) => {
171
+ let reqObj;
172
+ if (PCore.getPCoreVersion()?.includes('8.7')) {
173
+ reqObj = {
174
+ type: "File",
175
+ attachmentFieldName: valueRef,
176
+ category: categoryName,
177
+ ID: fileRes.ID
178
+ };
179
+ pConn.attachmentsInfo = reqObj;
180
+ } else {
181
+ reqObj = {
182
+ type: "File",
183
+ label: valueRef,
184
+ category: categoryName,
185
+ handle: fileRes.ID,
186
+ ID: fileRes.clientFileID
187
+ };
188
+ const currentAttachmentList = getCurrentAttachmentsList(pConn.getContextName()).filter(
189
+ (f) => f.label !== valueRef
190
+ );
191
+ PCore.getStateUtils().updateState(
192
+ pConn.getContextName(),
193
+ 'attachmentsList',
194
+ [...currentAttachmentList, reqObj],
195
+ {
196
+ pageReference: 'context_data',
197
+ isArrayDeepMerge: false
198
+ }
199
+ );
200
+ }
201
+ const fieldName = pConn.getStateProps().value;
202
+ const context = pConn.getContextName();
203
+
204
+ PCore.getMessageManager().clearMessages({
205
+ type: PCore.getConstants().MESSAGES.MESSAGES_TYPE_ERROR,
206
+ property: fieldName,
207
+ pageReference: pConn.getPageReference(),
208
+ context
209
+ });
210
+ myFiles[0].meta = "Uploaded Successfully";
211
+
212
+ arFileList$ = myFiles.map((att) => {
213
+ return getNewListUtilityItemProps({
214
+ att,
215
+ downloadFile: null,
216
+ cancelFile: null,
217
+ deleteFile: null,
218
+ removeFile: null
219
+ });
220
+ });
221
+ setFile((current) => {
222
+ return {
223
+ ...current,
224
+ props: {
225
+ ...current.props,
226
+ arFileList$
227
+ },
228
+ inProgress: false,
229
+ attachmentUploaded: true,
230
+ showMenuIcon: false
231
+ };
232
+ });
233
+ })
234
+
235
+ .catch(() => {
236
+ // just catching the rethrown error at uploadAttachment
237
+ // to handle Unhandled rejections
238
+ });
239
+ };
240
+
241
+ function _removeFileFromList(item: any, list) {
242
+ const arFileList = file.props ? file.props.arFileList$ : list;
243
+ const fileIndex = arFileList.findIndex(element => element?.id === item?.id);
244
+ if (PCore.getPCoreVersion()?.includes('8.7')) {
245
+ if (value) {
246
+ pConn.attachmentsInfo = {
247
+ type: "File",
248
+ attachmentFieldName: valueRef,
249
+ delete: true
250
+ };
251
+ }
252
+ if (fileIndex > -1) { arFileList.splice(parseInt(fileIndex, 10), 1) };
253
+ setFile((current) => {
254
+ return {
255
+ ...current,
256
+ props: {
257
+ ...current.props,
258
+ arFileList
259
+ },
260
+ };
261
+ });
262
+ } else {
263
+ const attachmentsList = [];
264
+ const currentAttachmentList = getCurrentAttachmentsList(pConn.getContextName()).filter(
265
+ (f) => f.label !== valueRef
266
+ );
267
+ if (value && value.pxResults && +value.pyCount > 0) {
268
+ const deletedFile = {
269
+ type: "File",
270
+ label: valueRef,
271
+ delete: true,
272
+ responseProps: {
273
+ pzInsKey: arFileList[fileIndex].id
274
+ },
275
+ };
276
+ // updating the redux store to help form-handler in passing the data to delete the file from server
277
+ PCore.getStateUtils().updateState(
278
+ pConn.getContextName(),
279
+ 'attachmentsList',
280
+ [...currentAttachmentList, deletedFile],
281
+ {
282
+ pageReference: 'context_data',
283
+ isArrayDeepMerge: false
284
+ }
285
+ );
286
+ } else {
287
+ PCore.getStateUtils().updateState(
288
+ pConn.getContextName(),
289
+ 'attachmentsList',
290
+ [...currentAttachmentList, ...attachmentsList],
291
+ {
292
+ pageReference: 'context_data',
293
+ isArrayDeepMerge: false
294
+ }
295
+ );
296
+ }
297
+ if (fileIndex > -1) { arFileList.splice(parseInt(fileIndex, 10), 1) };
298
+ setFile((current) => {
299
+ return {
300
+ ...current,
301
+ props: {
302
+ ...current.props,
303
+ arFileList
304
+ },
305
+ };
306
+ });
307
+ }
308
+ }
309
+
310
+ useEffect(() => {
311
+ if (value && value.pxResults && +value.pyCount > 0) {
312
+ fileTemp = buildFilePropsFromResponse(value.pxResults[0]);
313
+
314
+ if (fileTemp.responseProps) {
315
+ if (!pConn.attachmentsInfo) {
316
+ pConn.attachmentsInfo = {
317
+ type: "File",
318
+ attachmentFieldName: valueRef,
319
+ category: categoryName
320
+ };
321
+ }
322
+
323
+ if (fileTemp.responseProps.pzInsKey && !fileTemp.responseProps.pzInsKey.includes("temp")) {
324
+
325
+ fileTemp.props.type = fileTemp.responseProps.pyMimeFileExtension;
326
+ fileTemp.props.mimeType = fileTemp.responseProps.pyMimeFileExtension;
327
+ fileTemp.props.ID = fileTemp.responseProps.pzInsKey;
328
+ // create the actions for the "more" menu on the attachment
329
+ const arMenuList: Array<any> = [];
330
+ let oMenu: any = {};
331
+
332
+ oMenu.icon = "download";
333
+ oMenu.text = "Download";
334
+ oMenu.onClick = () => { _downloadFileFromList(value.pxResults[0])}
335
+ arMenuList.push(oMenu);
336
+ oMenu = {};
337
+ oMenu.icon = "trash";
338
+ oMenu.text = "Delete";
339
+ oMenu.onClick = () => { _removeFileFromList(arFileList$[0], arFileList$)}
340
+ arMenuList.push(oMenu);
341
+
342
+ arFileList$.push(getNewListUtilityItemProps({
343
+ att: fileTemp.props,
344
+ downloadFile: null,
345
+ cancelFile: null,
346
+ deleteFile: null,
347
+ removeFile: null
348
+ }));
349
+ arFileList$[0].actions = arMenuList;
350
+
351
+ setFile((current) => {
352
+ return {
353
+ ...current,
354
+ props: {
355
+ ...current.props,
356
+ arFileList$
357
+ },
358
+ inProgress: false,
359
+ attachmentUploaded: true,
360
+ showMenuIcon: true
361
+ };
362
+ });
363
+ }
364
+ }
365
+ }
366
+ }, [""]);
367
+
368
+ let content = (
369
+ <div className='file-div'>
370
+ {file.inProgress && (<div className="progress-div"><CircularProgress /></div>)}
371
+ <div hidden={true} id="attachment-ID">{valueRef}</div>
372
+ <label htmlFor={valueRef}>
373
+ <input
374
+ style={{ display: 'none' }}
375
+ id={valueRef}
376
+ name='upload-photo'
377
+ type='file'
378
+ required={required}
379
+ onChange={onFileAdded}
380
+ />
381
+ <Button variant='outlined' color='primary' component="span">
382
+ Upload file
383
+ </Button>
384
+ </label>
385
+ </div>
386
+ );
387
+
388
+ if (file && file.attachmentUploaded && file.props.arFileList$ && file.props.arFileList$.length > 0) {
389
+ content = (
390
+ <div>
391
+ {file.showMenuIcon && (<SummaryList arItems$={file.props.arFileList$} menuIconOverrideAction$={_removeFileFromList}></SummaryList>)}
392
+ {!file.showMenuIcon && (<SummaryList menuIconOverride$='trash' arItems$={file.props.arFileList$} menuIconOverrideAction$={_removeFileFromList}></SummaryList>)}
393
+ </div>
394
+
395
+ );
396
+ }
397
+
398
+ return (
399
+ <div className='file-upload-container'>
400
+ <span className='label'>{label}</span>
401
+ <section>{content}</section>
402
+ </div>
403
+ );
404
+ }
@@ -0,0 +1,71 @@
1
+ import download from 'downloadjs';
2
+
3
+ export const validateMaxSize = (fileObj, maxSizeInMB) => {
4
+ const fileSize = (fileObj.size / 1048576).toFixed(2);
5
+ return parseFloat(fileSize) < parseFloat(maxSizeInMB);
6
+ };
7
+
8
+ export const fileDownload = (data, fileName, ext) => {
9
+ const name = ext ? `${fileName}.${ext}` : fileName;
10
+ // Temp fix: downloading EMAIl type attachment as html file
11
+ if (ext === 'html') {
12
+ download(data, name, 'text/html');
13
+ } else {
14
+ download(atob(data), name);
15
+ }
16
+ };
17
+
18
+ export const getIconFromFileType = (fileType) => {
19
+ let icon = 'document-doc';
20
+ if (!fileType) return icon;
21
+ if (fileType.startsWith('audio')) {
22
+ icon = 'audio';
23
+ } else if (fileType.startsWith('video')) {
24
+ icon = 'video';
25
+ } else if (fileType.startsWith('image')) {
26
+ icon = 'picture';
27
+ } else if (fileType.includes('pdf')) {
28
+ icon = 'document-pdf';
29
+ } else {
30
+ const [, subtype] = fileType.split('/');
31
+ const foundMatch = (sources) => {
32
+ return sources.some((key) => subtype.includes(key));
33
+ };
34
+
35
+ if (foundMatch(['excel', 'spreadsheet'])) {
36
+ icon = 'document-xls';
37
+ } else if (foundMatch(['zip', 'compressed', 'gzip', 'rar', 'tar'])) {
38
+ icon = 'document-compress';
39
+ }
40
+ }
41
+
42
+ return icon;
43
+ };
44
+
45
+ export const getIconForAttachment = (attachment) => {
46
+ let icon;
47
+ switch (attachment.type) {
48
+ case "FILE":
49
+ icon = this.getIconFromFileType(attachment.mimeType);
50
+ break;
51
+ case "URL":
52
+ icon = "chain";
53
+ break;
54
+ default:
55
+ icon = "document-doc";
56
+ }
57
+ return icon;
58
+ };
59
+
60
+ export const buildFilePropsFromResponse = (respObj) => {
61
+ return {
62
+ props: {
63
+ meta: `${respObj.pyCategoryName}, ${respObj.pxCreateOperator}`,
64
+ name: respObj.pyAttachName,
65
+ icon: getIconFromFileType(respObj.pyMimeFileExtension)
66
+ },
67
+ responseProps: {
68
+ ...respObj
69
+ }
70
+ };
71
+ };
@@ -0,0 +1 @@
1
+ export { default } from './Attachment';