@pareto-engineering/design-system 4.2.3 → 4.3.2

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 (38) hide show
  1. package/dist/cjs/f/fields/FileUpload/FileUpload.js +32 -29
  2. package/dist/cjs/f/fields/FileUpload/common/{FilePreview/FilePreview.js → Preview/Preview.js} +64 -25
  3. package/dist/cjs/f/fields/FileUpload/common/{FilePreview → Preview}/index.js +3 -3
  4. package/{src/ui/f/fields/FileUpload/common/FilePreview → dist/cjs/f/fields/FileUpload/common/Preview}/styles.scss +9 -6
  5. package/dist/cjs/f/fields/FileUpload/common/index.js +3 -3
  6. package/dist/cjs/f/fields/FileUpload/index.js +14 -2
  7. package/dist/cjs/f/fields/FileUpload/{fileUploadOptions.js → utils.js} +19 -2
  8. package/dist/cjs/f/fields/index.js +12 -0
  9. package/dist/cjs/g/FormBuilder/FormBuilder.js +11 -3
  10. package/dist/cjs/g/FormBuilder/common/Renderer/Renderer.js +6 -2
  11. package/dist/cjs/g/FormBuilder/common/Renderer/common/Section/Section.js +6 -2
  12. package/dist/es/f/fields/FileUpload/FileUpload.js +32 -30
  13. package/dist/es/f/fields/FileUpload/common/Preview/Preview.js +119 -0
  14. package/dist/es/f/fields/FileUpload/common/{FilePreview → Preview}/index.js +1 -1
  15. package/dist/{cjs/f/fields/FileUpload/common/FilePreview → es/f/fields/FileUpload/common/Preview}/styles.scss +9 -6
  16. package/dist/es/f/fields/FileUpload/common/index.js +1 -1
  17. package/dist/es/f/fields/FileUpload/index.js +1 -1
  18. package/dist/es/f/fields/FileUpload/{fileUploadOptions.js → utils.js} +16 -1
  19. package/dist/es/f/fields/index.js +1 -1
  20. package/dist/es/g/FormBuilder/FormBuilder.js +11 -3
  21. package/dist/es/g/FormBuilder/common/Renderer/Renderer.js +6 -2
  22. package/dist/es/g/FormBuilder/common/Renderer/common/Section/Section.js +6 -2
  23. package/package.json +2 -2
  24. package/src/stories/f/FileUpload.stories.jsx +13 -0
  25. package/src/ui/f/fields/FileUpload/FileUpload.jsx +25 -26
  26. package/src/ui/f/fields/FileUpload/common/Preview/Preview.jsx +185 -0
  27. package/src/ui/f/fields/FileUpload/common/{FilePreview → Preview}/index.js +1 -1
  28. package/{dist/es/f/fields/FileUpload/common/FilePreview → src/ui/f/fields/FileUpload/common/Preview}/styles.scss +9 -6
  29. package/src/ui/f/fields/FileUpload/common/index.js +1 -1
  30. package/src/ui/f/fields/FileUpload/index.js +1 -1
  31. package/src/ui/f/fields/FileUpload/{fileUploadOptions.js → utils.js} +20 -0
  32. package/src/ui/f/fields/index.js +6 -1
  33. package/src/ui/g/FormBuilder/FormBuilder.jsx +9 -0
  34. package/src/ui/g/FormBuilder/common/Renderer/Renderer.jsx +4 -0
  35. package/src/ui/g/FormBuilder/common/Renderer/common/Section/Section.jsx +4 -0
  36. package/tests/__snapshots__/Storyshots.test.js.snap +65 -0
  37. package/dist/es/f/fields/FileUpload/common/FilePreview/FilePreview.js +0 -80
  38. package/src/ui/f/fields/FileUpload/common/FilePreview/FilePreview.jsx +0 -115
@@ -40,16 +40,13 @@ const FileUpload = _ref => {
40
40
  maxSize,
41
41
  maxSizeError,
42
42
  onChange,
43
- onDelete,
44
- // TODO: TBD when connecting with BE
45
- // onPreview,
46
- // progress,
47
- // percent,
48
- // uploadStatus,
43
+ uploadStatus,
49
44
  filePreviewAlignment,
50
45
  optional,
51
46
  labelColor,
52
- color
47
+ color,
48
+ viewOnly,
49
+ handleFileDelete
53
50
  // ...otherProps
54
51
  } = _ref;
55
52
  const [field,, helpers] = (0, _formik.useField)({
@@ -91,10 +88,17 @@ const FileUpload = _ref => {
91
88
  // eslint-disable-next-line no-param-reassign
92
89
  event.target.value = null;
93
90
  };
94
- const handleDelete = fileIndex => {
95
- const updatedFiles = value.filter((_, i) => i !== fileIndex);
91
+ const handleDelete = _ref2 => {
92
+ let {
93
+ fileIndex,
94
+ identifier
95
+ } = _ref2;
96
+ const updatedFiles = value?.filter((_, i) => i !== fileIndex);
96
97
  setValue(updatedFiles);
97
- onDelete?.(fileIndex);
98
+ handleFileDelete?.({
99
+ fileIndex,
100
+ identifier
101
+ });
98
102
  };
99
103
  const acceptOptions = Array.isArray(accept) ? accept?.join(',') : accept;
100
104
  return /*#__PURE__*/React.createElement("div", {
@@ -105,7 +109,7 @@ const FileUpload = _ref => {
105
109
  className: "s-1",
106
110
  description: description,
107
111
  name: name
108
- }), !disabled && /*#__PURE__*/React.createElement(_common2.FormLabel, {
112
+ }), !viewOnly && /*#__PURE__*/React.createElement(_common2.FormLabel, {
109
113
  name: name,
110
114
  color: labelColor,
111
115
  optional: optional
@@ -123,11 +127,15 @@ const FileUpload = _ref => {
123
127
  className: "attached-files"
124
128
  }, /*#__PURE__*/React.createElement("p", null, "Attached files:"), /*#__PURE__*/React.createElement("div", {
125
129
  className: "files"
126
- }, value.map((file, indx) => /*#__PURE__*/React.createElement(_common.FilePreview, {
130
+ }, value.map((file, indx) => /*#__PURE__*/React.createElement(_common.Preview, {
127
131
  file: file,
128
132
  key: file.name,
129
- disabled: disabled,
130
- handleDelete: () => handleDelete(indx)
133
+ writeOnly: !disabled,
134
+ handleDelete: () => handleDelete({
135
+ fileIndex: indx,
136
+ identifier: file?.id || file.name
137
+ }),
138
+ uploadStatus: uploadStatus?.[file?.name]
131
139
  })))));
132
140
  };
133
141
  FileUpload.propTypes = {
@@ -199,30 +207,25 @@ FileUpload.propTypes = {
199
207
  /**
200
208
  * The function to handle file delete events
201
209
  */
202
- onDelete: _propTypes.default.func,
203
- /**
204
- * The function to handle file download events
205
- */
206
- // onDownload:PropTypes.func,
207
-
210
+ handleFileDelete: _propTypes.default.func,
208
211
  /**
209
- * The function to handle file preview events
212
+ * The upload status of the file with the file name as the key
210
213
  */
211
- // onPreview:PropTypes.func,
212
-
214
+ uploadStatus: _propTypes.default.objectOf(_propTypes.default.string),
213
215
  /**
214
- * The upload status of the file if being sent to an external service (e.g., 'uploading', 'done')
216
+ * The alignment for file previews WRT the upload input
215
217
  */
216
- // uploadStatus:PropTypes.oneOf(['uploading', 'done', 'failed']),
217
-
218
+ filePreviewAlignment: _propTypes.default.oneOf(['left', 'right', 'top', 'bottom']),
218
219
  /**
219
- * The alignment for file previews WRT the upload input
220
+ * Whether the file upload is in view only mode
220
221
  */
221
- filePreviewAlignment: _propTypes.default.oneOf(['left', 'right', 'top', 'bottom'])
222
+ viewOnly: _propTypes.default.bool
222
223
  };
223
224
  FileUpload.defaultProps = {
224
225
  disabled: false,
225
226
  color: 'paragraph',
226
- filePreviewAlignment: 'bottom'
227
+ filePreviewAlignment: 'bottom',
228
+ viewOnly: false
227
229
  };
230
+ FileUpload.Preview = _common.Preview;
228
231
  var _default = exports.default = FileUpload;
@@ -7,10 +7,10 @@ exports.default = void 0;
7
7
  var React = _interopRequireWildcard(require("react"));
8
8
  var _propTypes = _interopRequireDefault(require("prop-types"));
9
9
  var _exports = _interopRequireDefault(require("@pareto-engineering/bem/exports"));
10
- require("./styles.scss");
11
10
  var _a = require("../../../../../a");
11
+ require("./styles.scss");
12
12
  var _b = require("../../../../../b");
13
- var _fileUploadOptions = require("../../fileUploadOptions");
13
+ var _utils = require("../../utils");
14
14
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
15
15
  function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
16
16
  function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
@@ -20,27 +20,43 @@ function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e;
20
20
 
21
21
  const baseClassName = _exports.default.base;
22
22
  const componentClassName = 'file-preview';
23
- const getFileType = file => {
24
- const mimeType = file.type;
25
- const extension = file.name.split('.').pop().toLowerCase();
26
- const fileType = _fileUploadOptions.fileUploadOptions.find(option => option.value.includes(mimeType) || option.value.includes(extension));
27
- return fileType ? fileType.key : 'unknown';
23
+ const statusColorMap = {
24
+ pending: 'yellow',
25
+ error: 'red',
26
+ success: 'green'
28
27
  };
28
+ const FILE_UPLOAD_COMPLETE_PROGRESS = 100;
29
29
 
30
30
  /**
31
31
  * This is the component description.
32
32
  */
33
- const FilePreview = _ref => {
33
+ const Preview = _ref => {
34
34
  let {
35
35
  id,
36
36
  className: userClassName,
37
37
  style,
38
38
  file,
39
- disabled,
40
- handleDelete
39
+ handleDelete,
40
+ uploadStatus,
41
+ color,
42
+ uploadProgress,
43
+ writeOnly
41
44
  // ...otherProps
42
45
  } = _ref;
43
- const type = getFileType(file);
46
+ const isFileObject = file instanceof File;
47
+ const type = isFileObject ? (0, _utils.getFileType)(file) : (0, _utils.getFileTypeFromUrl)(file?.url);
48
+ const status = uploadStatus?.status;
49
+ const statusColor = statusColorMap[status] ?? color;
50
+ const isPending = status === 'pending';
51
+ // isPreview means the file is uploaded and previewed while other files can still be uploaded
52
+ const isSuccess = status === 'success' || file?.isPreview;
53
+ const handlePreview = () => {
54
+ if (!isFileObject) {
55
+ window.open(file.url, '_blank');
56
+ }
57
+ };
58
+ const canDelete = file?.isPreview || isFileObject;
59
+ const isFileBroken = !writeOnly && !file?.url;
44
60
  return /*#__PURE__*/React.createElement("div", {
45
61
  id: id,
46
62
  className: [baseClassName, componentClassName, userClassName].filter(e => e).join(' '),
@@ -52,25 +68,35 @@ const FilePreview = _ref => {
52
68
  }, type), /*#__PURE__*/React.createElement("span", {
53
69
  title: file.name,
54
70
  className: "name"
55
- }, file.name), /*#__PURE__*/React.createElement(_b.Button, {
71
+ }, file.name), isFileBroken ? /*#__PURE__*/React.createElement(_a.Tooltip, {
72
+ description: "bulk-updates-text",
73
+ content: /*#__PURE__*/React.createElement("p", null, "This file doesn't have a link or the link is invalid.")
74
+ }, /*#__PURE__*/React.createElement("span", {
75
+ className: "icon x-ui-icons c-x"
76
+ }, "h")) : /*#__PURE__*/React.createElement(_b.Button, {
77
+ color: "ui-icons",
56
78
  isCompact: true,
57
79
  isSimple: true,
58
- onClick: handleDelete
80
+ onClick: () => canDelete ? handleDelete() : handlePreview()
59
81
  }, /*#__PURE__*/React.createElement("span", {
60
- className: "icon x-ui-icons c-x"
61
- }, "Y"))), !disabled && /*#__PURE__*/React.createElement("div", {
62
- className: "progress-status"
82
+ className: "icon"
83
+ }, canDelete ? 'Y' : '9'))), writeOnly && /*#__PURE__*/React.createElement("div", {
84
+ className: `progress-status x-${statusColor}`
63
85
  }, /*#__PURE__*/React.createElement("div", {
64
86
  className: "status"
65
- }, /*#__PURE__*/React.createElement("span", {
87
+ }, isPending ? /*#__PURE__*/React.createElement(_a.LoadingCircle, {
88
+ className: `x-${statusColor}`,
89
+ heightWidth: "1rem",
90
+ color: statusColor
91
+ }) : /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement("span", {
66
92
  className: "icon"
67
- }, "I"), /*#__PURE__*/React.createElement("span", null, "Uploaded")), /*#__PURE__*/React.createElement(_a.ProgressBar, {
68
- color: "green",
69
- progress: 100,
93
+ }, isSuccess ? 'I' : 'Y'), /*#__PURE__*/React.createElement("span", null, isSuccess ? 'Uploaded' : 'Error'))), /*#__PURE__*/React.createElement(_a.ProgressBar, {
94
+ color: statusColor,
95
+ progress: isPending ? uploadProgress : FILE_UPLOAD_COMPLETE_PROGRESS,
70
96
  height: "3px"
71
97
  })));
72
98
  };
73
- FilePreview.propTypes = {
99
+ Preview.propTypes = {
74
100
  /**
75
101
  * The HTML id for this element
76
102
  */
@@ -82,9 +108,22 @@ FilePreview.propTypes = {
82
108
  /**
83
109
  * The React-written, css properties for this element.
84
110
  */
85
- style: _propTypes.default.objectOf(_propTypes.default.string)
111
+ style: _propTypes.default.objectOf(_propTypes.default.string),
112
+ /**
113
+ * The base color of the file preview
114
+ */
115
+ color: _propTypes.default.string,
116
+ /**
117
+ * The upload progress of the file
118
+ */
119
+ uploadProgress: _propTypes.default.number,
120
+ /**
121
+ * Whether the preview is used in a context where the user can upload new files
122
+ */
123
+ writeOnly: _propTypes.default.bool
86
124
  };
87
- FilePreview.defaultProps = {
88
- // someProp:false
125
+ Preview.defaultProps = {
126
+ color: 'green',
127
+ uploadProgress: 45
89
128
  };
90
- var _default = exports.default = FilePreview;
129
+ var _default = exports.default = Preview;
@@ -3,11 +3,11 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- Object.defineProperty(exports, "FilePreview", {
6
+ Object.defineProperty(exports, "Preview", {
7
7
  enumerable: true,
8
8
  get: function () {
9
- return _FilePreview.default;
9
+ return _Preview.default;
10
10
  }
11
11
  });
12
- var _FilePreview = _interopRequireDefault(require("./FilePreview"));
12
+ var _Preview = _interopRequireDefault(require("./Preview"));
13
13
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
@@ -3,6 +3,7 @@
3
3
  @use "@pareto-engineering/bem";
4
4
 
5
5
  $default-padding: 1rem;
6
+ $default-margin: 1rem;
6
7
  $files-per-row: 3;
7
8
  $total-gaps: $files-per-row - 1;
8
9
  $combined-gap: calc(var(--gap) * $total-gaps);
@@ -22,13 +23,16 @@ $default-file-width: calc($width-without-gaps / $files-per-row);
22
23
  align-items: center;
23
24
  display: flex;
24
25
  gap: calc(var(--gap) / 2);
26
+ justify-content: space-between;
25
27
 
26
28
  > .type {
27
29
  padding-block: calc($default-padding / 4);
28
30
  padding-inline: calc($default-padding / 2);
29
31
 
30
32
  // TODO: update the colors to use variables. These are colors from the new DS
31
- &.pdf {
33
+ &.pdf,
34
+ &.broken,
35
+ &.unknown {
32
36
  background-color: #fdead7;
33
37
  color: #b93814;
34
38
  }
@@ -67,7 +71,6 @@ $default-file-width: calc($width-without-gaps / $files-per-row);
67
71
  }
68
72
 
69
73
  > .#{bem.$base}.button {
70
- cursor: pointer;
71
74
  margin-left: auto;
72
75
  }
73
76
  }
@@ -75,15 +78,15 @@ $default-file-width: calc($width-without-gaps / $files-per-row);
75
78
  > .progress-status {
76
79
  > .status {
77
80
  align-items: center;
78
- // TODO handle as a prop
79
- color: var(--green);
81
+ color: var(--x);
80
82
  display: flex;
81
83
  gap: calc(var(--gap) / 2);
84
+ margin-bottom: calc($default-margin / 4);
82
85
 
83
86
  > .icon {
84
- background-color: var(--green);
87
+ background-color: var(--x);
85
88
  border-radius: 50%;
86
- color: var(--on-green);
89
+ color: var(--on-x);
87
90
  font-size: calc(var(--s-2) * 1rem);
88
91
  padding: calc($default-padding / 4);
89
92
  }
@@ -3,10 +3,10 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- Object.defineProperty(exports, "FilePreview", {
6
+ Object.defineProperty(exports, "Preview", {
7
7
  enumerable: true,
8
8
  get: function () {
9
- return _FilePreview.FilePreview;
9
+ return _Preview.Preview;
10
10
  }
11
11
  });
12
- var _FilePreview = require("./FilePreview");
12
+ var _Preview = require("./Preview");
@@ -12,9 +12,21 @@ Object.defineProperty(exports, "FileUpload", {
12
12
  Object.defineProperty(exports, "fileUploadOptions", {
13
13
  enumerable: true,
14
14
  get: function () {
15
- return _fileUploadOptions.fileUploadOptions;
15
+ return _utils.fileUploadOptions;
16
+ }
17
+ });
18
+ Object.defineProperty(exports, "getFileType", {
19
+ enumerable: true,
20
+ get: function () {
21
+ return _utils.getFileType;
22
+ }
23
+ });
24
+ Object.defineProperty(exports, "getFileTypeFromUrl", {
25
+ enumerable: true,
26
+ get: function () {
27
+ return _utils.getFileTypeFromUrl;
16
28
  }
17
29
  });
18
30
  var _FileUpload = _interopRequireDefault(require("./FileUpload"));
19
- var _fileUploadOptions = require("./fileUploadOptions");
31
+ var _utils = require("./utils");
20
32
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
@@ -3,7 +3,7 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.fileUploadOptions = void 0;
6
+ exports.getFileTypeFromUrl = exports.getFileType = exports.fileUploadOptions = void 0;
7
7
  const fileUploadOptions = exports.fileUploadOptions = [{
8
8
  key: 'FILE',
9
9
  value: '.doc,.docx,.odt,application/msword,application/vnd.openxmlformats-officedocument.wordprocessingml.document,application/vnd.oasis.opendocument.text',
@@ -28,4 +28,21 @@ const fileUploadOptions = exports.fileUploadOptions = [{
28
28
  key: 'AUD',
29
29
  value: '.mp3,.ogg,.wav,audio/mpeg,audio/ogg,audio/wav',
30
30
  label: 'Audio'
31
- }];
31
+ }];
32
+ const getFileType = file => {
33
+ const mimeType = file?.type;
34
+ const extension = file?.name?.split('.').pop().toLowerCase();
35
+ const fileType = fileUploadOptions.find(option => option.value.includes(mimeType) || option.value.includes(extension));
36
+ return fileType ? fileType.key : 'unknown';
37
+ };
38
+ exports.getFileType = getFileType;
39
+ const getFileTypeFromUrl = url => {
40
+ if (!url) {
41
+ return 'BROKEN';
42
+ }
43
+ const urlWithoutParams = url.split('?')[0];
44
+ const extension = urlWithoutParams.split('.').pop().toLowerCase();
45
+ const fileType = fileUploadOptions.find(option => option.value.includes(extension));
46
+ return fileType ? fileType.key : 'UNKNOWN';
47
+ };
48
+ exports.getFileTypeFromUrl = getFileTypeFromUrl;
@@ -81,6 +81,18 @@ Object.defineProperty(exports, "fileUploadOptions", {
81
81
  return _FileUpload.fileUploadOptions;
82
82
  }
83
83
  });
84
+ Object.defineProperty(exports, "getFileType", {
85
+ enumerable: true,
86
+ get: function () {
87
+ return _FileUpload.getFileType;
88
+ }
89
+ });
90
+ Object.defineProperty(exports, "getFileTypeFromUrl", {
91
+ enumerable: true,
92
+ get: function () {
93
+ return _FileUpload.getFileTypeFromUrl;
94
+ }
95
+ });
84
96
  var _TextInput = require("./TextInput");
85
97
  var _SelectInput = require("./SelectInput");
86
98
  var _ChoicesInput = require("./ChoicesInput");
@@ -37,7 +37,9 @@ const FormBuilder = _ref => {
37
37
  onRendererError,
38
38
  onRendererFormSave,
39
39
  onBuilderValidate,
40
- initialBuilderValues
40
+ initialBuilderValues,
41
+ fileUploadStatus,
42
+ handleFileDelete
41
43
  // ...otherProps
42
44
  } = _ref;
43
45
  return /*#__PURE__*/React.createElement("div", {
@@ -56,7 +58,9 @@ const FormBuilder = _ref => {
56
58
  onSave: onRendererFormSave,
57
59
  readOnly: readOnly,
58
60
  shouldSubmit: shouldSubmit,
59
- onError: onRendererError
61
+ onError: onRendererError,
62
+ fileUploadStatus: fileUploadStatus,
63
+ handleFileDelete: handleFileDelete
60
64
  }));
61
65
  };
62
66
  FormBuilder.propTypes = {
@@ -99,7 +103,11 @@ FormBuilder.propTypes = {
99
103
  /**
100
104
  * Whether the form builder in renderer mode should submit the form values itself
101
105
  */
102
- shouldSubmit: _propTypes.default.bool
106
+ shouldSubmit: _propTypes.default.bool,
107
+ /**
108
+ * The upload status of files if any
109
+ */
110
+ fileUploadStatus: _propTypes.default.objectOf(_propTypes.default.string)
103
111
  };
104
112
  FormBuilder.defaultProps = {
105
113
  mode: 'build',
@@ -57,7 +57,9 @@ const Renderer = _ref => {
57
57
  readOnly,
58
58
  onSave,
59
59
  onError,
60
- shouldSubmit
60
+ shouldSubmit,
61
+ fileUploadStatus,
62
+ handleFileDelete
61
63
  // ...otherProps
62
64
  } = _ref;
63
65
  const [currentSectionIndex, setCurrentSectionIndex] = (0, _react.useState)(0);
@@ -131,7 +133,9 @@ const Renderer = _ref => {
131
133
  key: `${section.title}`
132
134
  }, section, {
133
135
  readOnly: readOnly,
134
- setUpdatedFormData: setUpdatedFormData
136
+ setUpdatedFormData: setUpdatedFormData,
137
+ fileUploadStatus: fileUploadStatus,
138
+ handleFileDelete: handleFileDelete
135
139
  }))), /*#__PURE__*/React.createElement("div", {
136
140
  className: "navigator-container"
137
141
  }, /*#__PURE__*/React.createElement(_b.Button, {
@@ -27,7 +27,9 @@ const Section = _ref => {
27
27
  title,
28
28
  description,
29
29
  inputs,
30
- readOnly
30
+ readOnly,
31
+ fileUploadStatus,
32
+ handleFileDelete
31
33
  // ...otherProps
32
34
  } = _ref;
33
35
  return /*#__PURE__*/React.createElement("div", {
@@ -42,7 +44,9 @@ const Section = _ref => {
42
44
  }), inputs?.map(input => /*#__PURE__*/React.createElement(_f.FormInput, _extends({
43
45
  key: input.name
44
46
  }, input, {
45
- disabled: readOnly
47
+ disabled: readOnly,
48
+ uploadStatus: fileUploadStatus,
49
+ handleFileDelete: handleFileDelete
46
50
  }))));
47
51
  };
48
52
  Section.propTypes = {
@@ -4,7 +4,7 @@ import PropTypes from 'prop-types';
4
4
  import { useField } from 'formik';
5
5
  import styleNames from '@pareto-engineering/bem/exports';
6
6
  import "./styles.scss";
7
- import { FilePreview } from "./common";
7
+ import { Preview } from "./common";
8
8
  import { FormLabel, FormDescription } from "../../common";
9
9
 
10
10
  // Local Definitions
@@ -30,16 +30,13 @@ const FileUpload = ({
30
30
  maxSize,
31
31
  maxSizeError,
32
32
  onChange,
33
- onDelete,
34
- // TODO: TBD when connecting with BE
35
- // onPreview,
36
- // progress,
37
- // percent,
38
- // uploadStatus,
33
+ uploadStatus,
39
34
  filePreviewAlignment,
40
35
  optional,
41
36
  labelColor,
42
- color
37
+ color,
38
+ viewOnly,
39
+ handleFileDelete
43
40
  // ...otherProps
44
41
  }) => {
45
42
  const [field,, helpers] = useField({
@@ -81,10 +78,16 @@ const FileUpload = ({
81
78
  // eslint-disable-next-line no-param-reassign
82
79
  event.target.value = null;
83
80
  };
84
- const handleDelete = fileIndex => {
85
- const updatedFiles = value.filter((_, i) => i !== fileIndex);
81
+ const handleDelete = ({
82
+ fileIndex,
83
+ identifier
84
+ }) => {
85
+ const updatedFiles = value?.filter((_, i) => i !== fileIndex);
86
86
  setValue(updatedFiles);
87
- onDelete?.(fileIndex);
87
+ handleFileDelete?.({
88
+ fileIndex,
89
+ identifier
90
+ });
88
91
  };
89
92
  const acceptOptions = Array.isArray(accept) ? accept?.join(',') : accept;
90
93
  return /*#__PURE__*/React.createElement("div", {
@@ -95,7 +98,7 @@ const FileUpload = ({
95
98
  className: "s-1",
96
99
  description: description,
97
100
  name: name
98
- }), !disabled && /*#__PURE__*/React.createElement(FormLabel, {
101
+ }), !viewOnly && /*#__PURE__*/React.createElement(FormLabel, {
99
102
  name: name,
100
103
  color: labelColor,
101
104
  optional: optional
@@ -113,11 +116,15 @@ const FileUpload = ({
113
116
  className: "attached-files"
114
117
  }, /*#__PURE__*/React.createElement("p", null, "Attached files:"), /*#__PURE__*/React.createElement("div", {
115
118
  className: "files"
116
- }, value.map((file, indx) => /*#__PURE__*/React.createElement(FilePreview, {
119
+ }, value.map((file, indx) => /*#__PURE__*/React.createElement(Preview, {
117
120
  file: file,
118
121
  key: file.name,
119
- disabled: disabled,
120
- handleDelete: () => handleDelete(indx)
122
+ writeOnly: !disabled,
123
+ handleDelete: () => handleDelete({
124
+ fileIndex: indx,
125
+ identifier: file?.id || file.name
126
+ }),
127
+ uploadStatus: uploadStatus?.[file?.name]
121
128
  })))));
122
129
  };
123
130
  FileUpload.propTypes = {
@@ -189,30 +196,25 @@ FileUpload.propTypes = {
189
196
  /**
190
197
  * The function to handle file delete events
191
198
  */
192
- onDelete: PropTypes.func,
193
- /**
194
- * The function to handle file download events
195
- */
196
- // onDownload:PropTypes.func,
197
-
199
+ handleFileDelete: PropTypes.func,
198
200
  /**
199
- * The function to handle file preview events
201
+ * The upload status of the file with the file name as the key
200
202
  */
201
- // onPreview:PropTypes.func,
202
-
203
+ uploadStatus: PropTypes.objectOf(PropTypes.string),
203
204
  /**
204
- * The upload status of the file if being sent to an external service (e.g., 'uploading', 'done')
205
+ * The alignment for file previews WRT the upload input
205
206
  */
206
- // uploadStatus:PropTypes.oneOf(['uploading', 'done', 'failed']),
207
-
207
+ filePreviewAlignment: PropTypes.oneOf(['left', 'right', 'top', 'bottom']),
208
208
  /**
209
- * The alignment for file previews WRT the upload input
209
+ * Whether the file upload is in view only mode
210
210
  */
211
- filePreviewAlignment: PropTypes.oneOf(['left', 'right', 'top', 'bottom'])
211
+ viewOnly: PropTypes.bool
212
212
  };
213
213
  FileUpload.defaultProps = {
214
214
  disabled: false,
215
215
  color: 'paragraph',
216
- filePreviewAlignment: 'bottom'
216
+ filePreviewAlignment: 'bottom',
217
+ viewOnly: false
217
218
  };
219
+ FileUpload.Preview = Preview;
218
220
  export default FileUpload;