@pareto-engineering/design-system 4.3.0 → 4.3.4
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.
- package/dist/cjs/f/fields/FileUpload/FileUpload.js +11 -14
- package/dist/cjs/f/fields/FileUpload/common/{FilePreview/FilePreview.js → Preview/Preview.js} +21 -10
- package/dist/cjs/f/fields/FileUpload/common/{FilePreview → Preview}/index.js +3 -3
- package/dist/{es/f/fields/FileUpload/common/FilePreview → cjs/f/fields/FileUpload/common/Preview}/styles.scss +4 -2
- package/dist/cjs/f/fields/FileUpload/common/index.js +3 -3
- package/dist/cjs/f/fields/FileUpload/utils.js +4 -1
- package/dist/cjs/g/FormBuilder/common/Builder/common/InputBuilder/InputBuilder.js +3 -0
- package/dist/es/f/fields/FileUpload/FileUpload.js +12 -15
- package/dist/es/f/fields/FileUpload/common/{FilePreview/FilePreview.js → Preview/Preview.js} +22 -11
- package/dist/es/f/fields/FileUpload/common/{FilePreview → Preview}/index.js +1 -1
- package/dist/{cjs/f/fields/FileUpload/common/FilePreview → es/f/fields/FileUpload/common/Preview}/styles.scss +4 -2
- package/dist/es/f/fields/FileUpload/common/index.js +1 -1
- package/dist/es/f/fields/FileUpload/utils.js +4 -1
- package/dist/es/g/FormBuilder/common/Builder/common/InputBuilder/InputBuilder.js +3 -0
- package/package.json +2 -2
- package/src/stories/f/FileUpload.stories.jsx +13 -0
- package/src/ui/f/fields/FileUpload/FileUpload.jsx +15 -18
- package/src/ui/f/fields/FileUpload/common/{FilePreview/FilePreview.jsx → Preview/Preview.jsx} +39 -14
- package/src/ui/f/fields/FileUpload/common/{FilePreview → Preview}/index.js +1 -1
- package/src/ui/f/fields/FileUpload/common/{FilePreview → Preview}/styles.scss +4 -2
- package/src/ui/f/fields/FileUpload/common/index.js +1 -1
- package/src/ui/f/fields/FileUpload/utils.js +4 -1
- package/src/ui/g/FormBuilder/common/Builder/common/InputBuilder/InputBuilder.jsx +4 -0
- package/tests/__snapshots__/Storyshots.test.js.snap +43 -0
|
@@ -127,20 +127,16 @@ const FileUpload = _ref => {
|
|
|
127
127
|
className: "attached-files"
|
|
128
128
|
}, /*#__PURE__*/React.createElement("p", null, "Attached files:"), /*#__PURE__*/React.createElement("div", {
|
|
129
129
|
className: "files"
|
|
130
|
-
}, value.map((file, indx) => {
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
uploadStatus: uploadStatus?.[file?.name],
|
|
141
|
-
viewOnly: viewOnly
|
|
142
|
-
});
|
|
143
|
-
}))));
|
|
130
|
+
}, value.map((file, indx) => /*#__PURE__*/React.createElement(_common.Preview, {
|
|
131
|
+
file: file,
|
|
132
|
+
key: file.name,
|
|
133
|
+
writeOnly: !disabled,
|
|
134
|
+
handleDelete: () => handleDelete({
|
|
135
|
+
fileIndex: indx,
|
|
136
|
+
identifier: file?.id || file.name
|
|
137
|
+
}),
|
|
138
|
+
uploadStatus: uploadStatus?.[file?.name]
|
|
139
|
+
})))));
|
|
144
140
|
};
|
|
145
141
|
FileUpload.propTypes = {
|
|
146
142
|
/**
|
|
@@ -231,4 +227,5 @@ FileUpload.defaultProps = {
|
|
|
231
227
|
filePreviewAlignment: 'bottom',
|
|
232
228
|
viewOnly: false
|
|
233
229
|
};
|
|
230
|
+
FileUpload.Preview = _common.Preview;
|
|
234
231
|
var _default = exports.default = FileUpload;
|
package/dist/cjs/f/fields/FileUpload/common/{FilePreview/FilePreview.js → Preview/Preview.js}
RENAMED
|
@@ -30,17 +30,17 @@ const FILE_UPLOAD_COMPLETE_PROGRESS = 100;
|
|
|
30
30
|
/**
|
|
31
31
|
* This is the component description.
|
|
32
32
|
*/
|
|
33
|
-
const
|
|
33
|
+
const Preview = _ref => {
|
|
34
34
|
let {
|
|
35
35
|
id,
|
|
36
36
|
className: userClassName,
|
|
37
37
|
style,
|
|
38
38
|
file,
|
|
39
|
-
disabled,
|
|
40
39
|
handleDelete,
|
|
41
40
|
uploadStatus,
|
|
42
41
|
color,
|
|
43
|
-
uploadProgress
|
|
42
|
+
uploadProgress,
|
|
43
|
+
writeOnly
|
|
44
44
|
// ...otherProps
|
|
45
45
|
} = _ref;
|
|
46
46
|
const isFileObject = file instanceof File;
|
|
@@ -56,6 +56,7 @@ const FilePreview = _ref => {
|
|
|
56
56
|
}
|
|
57
57
|
};
|
|
58
58
|
const canDelete = file?.isPreview || isFileObject;
|
|
59
|
+
const isFileBroken = !writeOnly && !file?.url;
|
|
59
60
|
return /*#__PURE__*/React.createElement("div", {
|
|
60
61
|
id: id,
|
|
61
62
|
className: [baseClassName, componentClassName, userClassName].filter(e => e).join(' '),
|
|
@@ -67,13 +68,19 @@ const FilePreview = _ref => {
|
|
|
67
68
|
}, type), /*#__PURE__*/React.createElement("span", {
|
|
68
69
|
title: file.name,
|
|
69
70
|
className: "name"
|
|
70
|
-
}, file.name), /*#__PURE__*/React.createElement(
|
|
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",
|
|
71
78
|
isCompact: true,
|
|
72
79
|
isSimple: true,
|
|
73
80
|
onClick: () => canDelete ? handleDelete() : handlePreview()
|
|
74
81
|
}, /*#__PURE__*/React.createElement("span", {
|
|
75
|
-
className: "icon
|
|
76
|
-
}, canDelete ? 'Y' : '9'))),
|
|
82
|
+
className: "icon"
|
|
83
|
+
}, canDelete ? 'Y' : '9'))), writeOnly && /*#__PURE__*/React.createElement("div", {
|
|
77
84
|
className: `progress-status x-${statusColor}`
|
|
78
85
|
}, /*#__PURE__*/React.createElement("div", {
|
|
79
86
|
className: "status"
|
|
@@ -89,7 +96,7 @@ const FilePreview = _ref => {
|
|
|
89
96
|
height: "3px"
|
|
90
97
|
})));
|
|
91
98
|
};
|
|
92
|
-
|
|
99
|
+
Preview.propTypes = {
|
|
93
100
|
/**
|
|
94
101
|
* The HTML id for this element
|
|
95
102
|
*/
|
|
@@ -109,10 +116,14 @@ FilePreview.propTypes = {
|
|
|
109
116
|
/**
|
|
110
117
|
* The upload progress of the file
|
|
111
118
|
*/
|
|
112
|
-
uploadProgress: _propTypes.default.number
|
|
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
|
|
113
124
|
};
|
|
114
|
-
|
|
125
|
+
Preview.defaultProps = {
|
|
115
126
|
color: 'green',
|
|
116
127
|
uploadProgress: 45
|
|
117
128
|
};
|
|
118
|
-
var _default = exports.default =
|
|
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, "
|
|
6
|
+
Object.defineProperty(exports, "Preview", {
|
|
7
7
|
enumerable: true,
|
|
8
8
|
get: function () {
|
|
9
|
-
return
|
|
9
|
+
return _Preview.default;
|
|
10
10
|
}
|
|
11
11
|
});
|
|
12
|
-
var
|
|
12
|
+
var _Preview = _interopRequireDefault(require("./Preview"));
|
|
13
13
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
@@ -23,13 +23,16 @@ $default-file-width: calc($width-without-gaps / $files-per-row);
|
|
|
23
23
|
align-items: center;
|
|
24
24
|
display: flex;
|
|
25
25
|
gap: calc(var(--gap) / 2);
|
|
26
|
+
justify-content: space-between;
|
|
26
27
|
|
|
27
28
|
> .type {
|
|
28
29
|
padding-block: calc($default-padding / 4);
|
|
29
30
|
padding-inline: calc($default-padding / 2);
|
|
30
31
|
|
|
31
32
|
// TODO: update the colors to use variables. These are colors from the new DS
|
|
32
|
-
&.pdf
|
|
33
|
+
&.pdf,
|
|
34
|
+
&.broken,
|
|
35
|
+
&.unknown {
|
|
33
36
|
background-color: #fdead7;
|
|
34
37
|
color: #b93814;
|
|
35
38
|
}
|
|
@@ -68,7 +71,6 @@ $default-file-width: calc($width-without-gaps / $files-per-row);
|
|
|
68
71
|
}
|
|
69
72
|
|
|
70
73
|
> .#{bem.$base}.button {
|
|
71
|
-
cursor: pointer;
|
|
72
74
|
margin-left: auto;
|
|
73
75
|
}
|
|
74
76
|
}
|
|
@@ -3,10 +3,10 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
Object.defineProperty(exports, "
|
|
6
|
+
Object.defineProperty(exports, "Preview", {
|
|
7
7
|
enumerable: true,
|
|
8
8
|
get: function () {
|
|
9
|
-
return
|
|
9
|
+
return _Preview.Preview;
|
|
10
10
|
}
|
|
11
11
|
});
|
|
12
|
-
var
|
|
12
|
+
var _Preview = require("./Preview");
|
|
@@ -37,9 +37,12 @@ const getFileType = file => {
|
|
|
37
37
|
};
|
|
38
38
|
exports.getFileType = getFileType;
|
|
39
39
|
const getFileTypeFromUrl = url => {
|
|
40
|
+
if (!url) {
|
|
41
|
+
return 'BROKEN';
|
|
42
|
+
}
|
|
40
43
|
const urlWithoutParams = url.split('?')[0];
|
|
41
44
|
const extension = urlWithoutParams.split('.').pop().toLowerCase();
|
|
42
45
|
const fileType = fileUploadOptions.find(option => option.value.includes(extension));
|
|
43
|
-
return fileType ? fileType.key : '
|
|
46
|
+
return fileType ? fileType.key : 'UNKNOWN';
|
|
44
47
|
};
|
|
45
48
|
exports.getFileTypeFromUrl = getFileTypeFromUrl;
|
|
@@ -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 {
|
|
7
|
+
import { Preview } from "./common";
|
|
8
8
|
import { FormLabel, FormDescription } from "../../common";
|
|
9
9
|
|
|
10
10
|
// Local Definitions
|
|
@@ -116,20 +116,16 @@ const FileUpload = ({
|
|
|
116
116
|
className: "attached-files"
|
|
117
117
|
}, /*#__PURE__*/React.createElement("p", null, "Attached files:"), /*#__PURE__*/React.createElement("div", {
|
|
118
118
|
className: "files"
|
|
119
|
-
}, value.map((file, indx) => {
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
uploadStatus: uploadStatus?.[file?.name],
|
|
130
|
-
viewOnly: viewOnly
|
|
131
|
-
});
|
|
132
|
-
}))));
|
|
119
|
+
}, value.map((file, indx) => /*#__PURE__*/React.createElement(Preview, {
|
|
120
|
+
file: file,
|
|
121
|
+
key: file.name,
|
|
122
|
+
writeOnly: !disabled,
|
|
123
|
+
handleDelete: () => handleDelete({
|
|
124
|
+
fileIndex: indx,
|
|
125
|
+
identifier: file?.id || file.name
|
|
126
|
+
}),
|
|
127
|
+
uploadStatus: uploadStatus?.[file?.name]
|
|
128
|
+
})))));
|
|
133
129
|
};
|
|
134
130
|
FileUpload.propTypes = {
|
|
135
131
|
/**
|
|
@@ -220,4 +216,5 @@ FileUpload.defaultProps = {
|
|
|
220
216
|
filePreviewAlignment: 'bottom',
|
|
221
217
|
viewOnly: false
|
|
222
218
|
};
|
|
219
|
+
FileUpload.Preview = Preview;
|
|
223
220
|
export default FileUpload;
|
package/dist/es/f/fields/FileUpload/common/{FilePreview/FilePreview.js → Preview/Preview.js}
RENAMED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
import * as React from 'react';
|
|
3
3
|
import PropTypes from 'prop-types';
|
|
4
4
|
import styleNames from '@pareto-engineering/bem/exports';
|
|
5
|
-
import { LoadingCircle, ProgressBar } from "../../../../../a";
|
|
5
|
+
import { LoadingCircle, ProgressBar, Tooltip } from "../../../../../a";
|
|
6
6
|
|
|
7
7
|
// Local Definitions
|
|
8
8
|
|
|
@@ -21,16 +21,16 @@ const FILE_UPLOAD_COMPLETE_PROGRESS = 100;
|
|
|
21
21
|
/**
|
|
22
22
|
* This is the component description.
|
|
23
23
|
*/
|
|
24
|
-
const
|
|
24
|
+
const Preview = ({
|
|
25
25
|
id,
|
|
26
26
|
className: userClassName,
|
|
27
27
|
style,
|
|
28
28
|
file,
|
|
29
|
-
disabled,
|
|
30
29
|
handleDelete,
|
|
31
30
|
uploadStatus,
|
|
32
31
|
color,
|
|
33
|
-
uploadProgress
|
|
32
|
+
uploadProgress,
|
|
33
|
+
writeOnly
|
|
34
34
|
// ...otherProps
|
|
35
35
|
}) => {
|
|
36
36
|
const isFileObject = file instanceof File;
|
|
@@ -46,6 +46,7 @@ const FilePreview = ({
|
|
|
46
46
|
}
|
|
47
47
|
};
|
|
48
48
|
const canDelete = file?.isPreview || isFileObject;
|
|
49
|
+
const isFileBroken = !writeOnly && !file?.url;
|
|
49
50
|
return /*#__PURE__*/React.createElement("div", {
|
|
50
51
|
id: id,
|
|
51
52
|
className: [baseClassName, componentClassName, userClassName].filter(e => e).join(' '),
|
|
@@ -57,13 +58,19 @@ const FilePreview = ({
|
|
|
57
58
|
}, type), /*#__PURE__*/React.createElement("span", {
|
|
58
59
|
title: file.name,
|
|
59
60
|
className: "name"
|
|
60
|
-
}, file.name), /*#__PURE__*/React.createElement(
|
|
61
|
+
}, file.name), isFileBroken ? /*#__PURE__*/React.createElement(Tooltip, {
|
|
62
|
+
description: "bulk-updates-text",
|
|
63
|
+
content: /*#__PURE__*/React.createElement("p", null, "This file doesn't have a link or the link is invalid.")
|
|
64
|
+
}, /*#__PURE__*/React.createElement("span", {
|
|
65
|
+
className: "icon x-ui-icons c-x"
|
|
66
|
+
}, "h")) : /*#__PURE__*/React.createElement(Button, {
|
|
67
|
+
color: "ui-icons",
|
|
61
68
|
isCompact: true,
|
|
62
69
|
isSimple: true,
|
|
63
70
|
onClick: () => canDelete ? handleDelete() : handlePreview()
|
|
64
71
|
}, /*#__PURE__*/React.createElement("span", {
|
|
65
|
-
className: "icon
|
|
66
|
-
}, canDelete ? 'Y' : '9'))),
|
|
72
|
+
className: "icon"
|
|
73
|
+
}, canDelete ? 'Y' : '9'))), writeOnly && /*#__PURE__*/React.createElement("div", {
|
|
67
74
|
className: `progress-status x-${statusColor}`
|
|
68
75
|
}, /*#__PURE__*/React.createElement("div", {
|
|
69
76
|
className: "status"
|
|
@@ -79,7 +86,7 @@ const FilePreview = ({
|
|
|
79
86
|
height: "3px"
|
|
80
87
|
})));
|
|
81
88
|
};
|
|
82
|
-
|
|
89
|
+
Preview.propTypes = {
|
|
83
90
|
/**
|
|
84
91
|
* The HTML id for this element
|
|
85
92
|
*/
|
|
@@ -99,10 +106,14 @@ FilePreview.propTypes = {
|
|
|
99
106
|
/**
|
|
100
107
|
* The upload progress of the file
|
|
101
108
|
*/
|
|
102
|
-
uploadProgress: PropTypes.number
|
|
109
|
+
uploadProgress: PropTypes.number,
|
|
110
|
+
/**
|
|
111
|
+
* Whether the preview is used in a context where the user can upload new files
|
|
112
|
+
*/
|
|
113
|
+
writeOnly: PropTypes.bool
|
|
103
114
|
};
|
|
104
|
-
|
|
115
|
+
Preview.defaultProps = {
|
|
105
116
|
color: 'green',
|
|
106
117
|
uploadProgress: 45
|
|
107
118
|
};
|
|
108
|
-
export default
|
|
119
|
+
export default Preview;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
/* @pareto-engineering/generator-front 1.1.1-alpha.2 */
|
|
2
|
-
export { default as
|
|
2
|
+
export { default as Preview } from "./Preview";
|
|
@@ -23,13 +23,16 @@ $default-file-width: calc($width-without-gaps / $files-per-row);
|
|
|
23
23
|
align-items: center;
|
|
24
24
|
display: flex;
|
|
25
25
|
gap: calc(var(--gap) / 2);
|
|
26
|
+
justify-content: space-between;
|
|
26
27
|
|
|
27
28
|
> .type {
|
|
28
29
|
padding-block: calc($default-padding / 4);
|
|
29
30
|
padding-inline: calc($default-padding / 2);
|
|
30
31
|
|
|
31
32
|
// TODO: update the colors to use variables. These are colors from the new DS
|
|
32
|
-
&.pdf
|
|
33
|
+
&.pdf,
|
|
34
|
+
&.broken,
|
|
35
|
+
&.unknown {
|
|
33
36
|
background-color: #fdead7;
|
|
34
37
|
color: #b93814;
|
|
35
38
|
}
|
|
@@ -68,7 +71,6 @@ $default-file-width: calc($width-without-gaps / $files-per-row);
|
|
|
68
71
|
}
|
|
69
72
|
|
|
70
73
|
> .#{bem.$base}.button {
|
|
71
|
-
cursor: pointer;
|
|
72
74
|
margin-left: auto;
|
|
73
75
|
}
|
|
74
76
|
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
/* @pareto-engineering/generator-front 1.1.1-alpha.2 */
|
|
2
|
-
export {
|
|
2
|
+
export { Preview } from "./Preview";
|
|
@@ -30,8 +30,11 @@ export const getFileType = file => {
|
|
|
30
30
|
return fileType ? fileType.key : 'unknown';
|
|
31
31
|
};
|
|
32
32
|
export const getFileTypeFromUrl = url => {
|
|
33
|
+
if (!url) {
|
|
34
|
+
return 'BROKEN';
|
|
35
|
+
}
|
|
33
36
|
const urlWithoutParams = url.split('?')[0];
|
|
34
37
|
const extension = urlWithoutParams.split('.').pop().toLowerCase();
|
|
35
38
|
const fileType = fileUploadOptions.find(option => option.value.includes(extension));
|
|
36
|
-
return fileType ? fileType.key : '
|
|
39
|
+
return fileType ? fileType.key : 'UNKNOWN';
|
|
37
40
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pareto-engineering/design-system",
|
|
3
|
-
"version": "4.3.
|
|
3
|
+
"version": "4.3.4",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "dist/cjs/index.js",
|
|
6
6
|
"module": "dist/es/index.js",
|
|
@@ -82,5 +82,5 @@
|
|
|
82
82
|
"relay-test-utils": "^15.0.0"
|
|
83
83
|
},
|
|
84
84
|
"browserslist": "> 2%",
|
|
85
|
-
"gitHead": "
|
|
85
|
+
"gitHead": "8586c03f9cb3bb9fd9704813cf8a2b5f4bbb73cb"
|
|
86
86
|
}
|
|
@@ -53,3 +53,16 @@ export const WithLimitedCount = {
|
|
|
53
53
|
maxCount:2,
|
|
54
54
|
},
|
|
55
55
|
}
|
|
56
|
+
|
|
57
|
+
const file = {
|
|
58
|
+
id :'101568dad8544564901830661183e281',
|
|
59
|
+
name :'test.tar',
|
|
60
|
+
url :'https://forte-development-assets.pareto.ai/task/73/101568dad8544564901830661183e281.tar?Expires=1725387927&Signature=D8wIYnCQKyS6kkZbumgHHJ8fXnciwz1f31YGpKUH47InfPFDqGTDpEDub4xsjDPlxlDWomNj05xJs~uiaef49ZuRnPKRgcUFzw86Pn9A81Rw5gawfmuIpJPaUIkhG6VpsmH5pKnnEX2jWb0t5OqD~jMiL1aQU8f7HS241E9qdLy1kG9BHAHYR8IxSz9mHeZD3k~cjVW3I4QtB1PuN3nOgLH1ebBHI0Y1bk6kyVT1Bihz0bpbdg6o5KkoV6DKqLUGbsxvYliWOX8XCjkoDujtl8hDnTFS6Hix75a9idf3qVbTA7IDhoGodzVRw8MbyIHashxQ5-5XRF0mAblJr~2QTQ__&Key-Pair-Id=K3IY7IU3GPUR0N',
|
|
61
|
+
writeOnly:false,
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
export const Preview = {
|
|
65
|
+
render:() => (
|
|
66
|
+
<FileUpload.Preview file={file} />
|
|
67
|
+
),
|
|
68
|
+
}
|
|
@@ -9,7 +9,7 @@ import styleNames from '@pareto-engineering/bem/exports'
|
|
|
9
9
|
|
|
10
10
|
import './styles.scss'
|
|
11
11
|
|
|
12
|
-
import {
|
|
12
|
+
import { Preview } from './common'
|
|
13
13
|
|
|
14
14
|
import { FormLabel, FormDescription } from '../../common'
|
|
15
15
|
|
|
@@ -143,23 +143,18 @@ const FileUpload = ({
|
|
|
143
143
|
<div className="attached-files">
|
|
144
144
|
<p>Attached files:</p>
|
|
145
145
|
<div className="files">
|
|
146
|
-
{value.map((file, indx) =>
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
uploadStatus={uploadStatus?.[file?.name]}
|
|
159
|
-
viewOnly={viewOnly}
|
|
160
|
-
/>
|
|
161
|
-
)
|
|
162
|
-
})}
|
|
146
|
+
{value.map((file, indx) => (
|
|
147
|
+
<Preview
|
|
148
|
+
file={file}
|
|
149
|
+
key={file.name}
|
|
150
|
+
writeOnly={!disabled}
|
|
151
|
+
handleDelete={() => handleDelete({
|
|
152
|
+
fileIndex :indx,
|
|
153
|
+
identifier:file?.id || file.name,
|
|
154
|
+
})}
|
|
155
|
+
uploadStatus={uploadStatus?.[file?.name]}
|
|
156
|
+
/>
|
|
157
|
+
))}
|
|
163
158
|
</div>
|
|
164
159
|
</div>
|
|
165
160
|
)}
|
|
@@ -276,4 +271,6 @@ FileUpload.defaultProps = {
|
|
|
276
271
|
viewOnly :false,
|
|
277
272
|
}
|
|
278
273
|
|
|
274
|
+
FileUpload.Preview = Preview
|
|
275
|
+
|
|
279
276
|
export default FileUpload
|
package/src/ui/f/fields/FileUpload/common/{FilePreview/FilePreview.jsx → Preview/Preview.jsx}
RENAMED
|
@@ -5,7 +5,7 @@ import PropTypes from 'prop-types'
|
|
|
5
5
|
|
|
6
6
|
import styleNames from '@pareto-engineering/bem/exports'
|
|
7
7
|
|
|
8
|
-
import { LoadingCircle, ProgressBar } from 'ui/a'
|
|
8
|
+
import { LoadingCircle, ProgressBar, Tooltip } from 'ui/a'
|
|
9
9
|
|
|
10
10
|
// Local Definitions
|
|
11
11
|
|
|
@@ -30,16 +30,16 @@ const FILE_UPLOAD_COMPLETE_PROGRESS = 100
|
|
|
30
30
|
/**
|
|
31
31
|
* This is the component description.
|
|
32
32
|
*/
|
|
33
|
-
const
|
|
33
|
+
const Preview = ({
|
|
34
34
|
id,
|
|
35
35
|
className:userClassName,
|
|
36
36
|
style,
|
|
37
37
|
file,
|
|
38
|
-
disabled,
|
|
39
38
|
handleDelete,
|
|
40
39
|
uploadStatus,
|
|
41
40
|
color,
|
|
42
41
|
uploadProgress,
|
|
42
|
+
writeOnly,
|
|
43
43
|
// ...otherProps
|
|
44
44
|
}) => {
|
|
45
45
|
const isFileObject = file instanceof File
|
|
@@ -60,6 +60,8 @@ const FilePreview = ({
|
|
|
60
60
|
|
|
61
61
|
const canDelete = file?.isPreview || isFileObject
|
|
62
62
|
|
|
63
|
+
const isFileBroken = !writeOnly && !file?.url
|
|
64
|
+
|
|
63
65
|
return (
|
|
64
66
|
<div
|
|
65
67
|
id={id}
|
|
@@ -88,15 +90,33 @@ const FilePreview = ({
|
|
|
88
90
|
{type}
|
|
89
91
|
</span>
|
|
90
92
|
<span title={file.name} className="name">{file.name}</span>
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
93
|
+
{isFileBroken
|
|
94
|
+
? (
|
|
95
|
+
<Tooltip
|
|
96
|
+
description="bulk-updates-text"
|
|
97
|
+
content={(
|
|
98
|
+
<p>
|
|
99
|
+
This file doesn't have a link or the link is invalid.
|
|
100
|
+
</p>
|
|
101
|
+
)}
|
|
102
|
+
>
|
|
103
|
+
<span className="icon x-ui-icons c-x">
|
|
104
|
+
h
|
|
105
|
+
</span>
|
|
106
|
+
</Tooltip>
|
|
107
|
+
)
|
|
108
|
+
: (
|
|
109
|
+
<Button
|
|
110
|
+
color="ui-icons"
|
|
111
|
+
isCompact
|
|
112
|
+
isSimple
|
|
113
|
+
onClick={() => (canDelete ? handleDelete() : handlePreview())}
|
|
114
|
+
>
|
|
115
|
+
<span className="icon">{canDelete ? 'Y' : '9'}</span>
|
|
116
|
+
</Button>
|
|
117
|
+
)}
|
|
98
118
|
</div>
|
|
99
|
-
{
|
|
119
|
+
{writeOnly && (
|
|
100
120
|
<div className={`progress-status x-${statusColor}`}>
|
|
101
121
|
<div className="status">
|
|
102
122
|
{isPending ? (
|
|
@@ -125,7 +145,7 @@ const FilePreview = ({
|
|
|
125
145
|
)
|
|
126
146
|
}
|
|
127
147
|
|
|
128
|
-
|
|
148
|
+
Preview.propTypes = {
|
|
129
149
|
/**
|
|
130
150
|
* The HTML id for this element
|
|
131
151
|
*/
|
|
@@ -150,11 +170,16 @@ FilePreview.propTypes = {
|
|
|
150
170
|
* The upload progress of the file
|
|
151
171
|
*/
|
|
152
172
|
uploadProgress:PropTypes.number,
|
|
173
|
+
|
|
174
|
+
/**
|
|
175
|
+
* Whether the preview is used in a context where the user can upload new files
|
|
176
|
+
*/
|
|
177
|
+
writeOnly:PropTypes.bool,
|
|
153
178
|
}
|
|
154
179
|
|
|
155
|
-
|
|
180
|
+
Preview.defaultProps = {
|
|
156
181
|
color :'green',
|
|
157
182
|
uploadProgress:45,
|
|
158
183
|
}
|
|
159
184
|
|
|
160
|
-
export default
|
|
185
|
+
export default Preview
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
/* @pareto-engineering/generator-front 1.1.1-alpha.2 */
|
|
2
|
-
export { default as
|
|
2
|
+
export { default as Preview } from './Preview'
|
|
@@ -23,13 +23,16 @@ $default-file-width: calc($width-without-gaps / $files-per-row);
|
|
|
23
23
|
align-items: center;
|
|
24
24
|
display: flex;
|
|
25
25
|
gap: calc(var(--gap) / 2);
|
|
26
|
+
justify-content: space-between;
|
|
26
27
|
|
|
27
28
|
> .type {
|
|
28
29
|
padding-block: calc($default-padding / 4);
|
|
29
30
|
padding-inline: calc($default-padding / 2);
|
|
30
31
|
|
|
31
32
|
// TODO: update the colors to use variables. These are colors from the new DS
|
|
32
|
-
&.pdf
|
|
33
|
+
&.pdf,
|
|
34
|
+
&.broken,
|
|
35
|
+
&.unknown {
|
|
33
36
|
background-color: #fdead7;
|
|
34
37
|
color: #b93814;
|
|
35
38
|
}
|
|
@@ -68,7 +71,6 @@ $default-file-width: calc($width-without-gaps / $files-per-row);
|
|
|
68
71
|
}
|
|
69
72
|
|
|
70
73
|
> .#{bem.$base}.button {
|
|
71
|
-
cursor: pointer;
|
|
72
74
|
margin-left: auto;
|
|
73
75
|
}
|
|
74
76
|
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
/* @pareto-engineering/generator-front 1.1.1-alpha.2 */
|
|
2
|
-
export {
|
|
2
|
+
export { Preview } from './Preview'
|
|
@@ -41,9 +41,12 @@ export const getFileType = (file) => {
|
|
|
41
41
|
}
|
|
42
42
|
|
|
43
43
|
export const getFileTypeFromUrl = (url) => {
|
|
44
|
+
if (!url) {
|
|
45
|
+
return 'BROKEN'
|
|
46
|
+
}
|
|
44
47
|
const urlWithoutParams = url.split('?')[0]
|
|
45
48
|
const extension = urlWithoutParams.split('.').pop().toLowerCase()
|
|
46
49
|
const fileType = fileUploadOptions.find((option) => option.value.includes(extension))
|
|
47
50
|
|
|
48
|
-
return fileType ? fileType.key : '
|
|
51
|
+
return fileType ? fileType.key : 'UNKNOWN'
|
|
49
52
|
}
|
|
@@ -27553,6 +27553,49 @@ exports[`Storyshots f/fields/FileUpload Multiple 1`] = `
|
|
|
27553
27553
|
</form>
|
|
27554
27554
|
`;
|
|
27555
27555
|
|
|
27556
|
+
exports[`Storyshots f/fields/FileUpload Preview 1`] = `
|
|
27557
|
+
<form
|
|
27558
|
+
action="#"
|
|
27559
|
+
onReset={[Function]}
|
|
27560
|
+
onSubmit={[Function]}
|
|
27561
|
+
>
|
|
27562
|
+
<div
|
|
27563
|
+
className="base file-preview"
|
|
27564
|
+
>
|
|
27565
|
+
<div
|
|
27566
|
+
className="identity"
|
|
27567
|
+
>
|
|
27568
|
+
<span
|
|
27569
|
+
className="type unknown"
|
|
27570
|
+
>
|
|
27571
|
+
UNKNOWN
|
|
27572
|
+
</span>
|
|
27573
|
+
<span
|
|
27574
|
+
className="name"
|
|
27575
|
+
title="test.tar"
|
|
27576
|
+
>
|
|
27577
|
+
test.tar
|
|
27578
|
+
</span>
|
|
27579
|
+
<button
|
|
27580
|
+
className="base button x-ui-icons modifierCompact modifierSimple"
|
|
27581
|
+
onClick={[Function]}
|
|
27582
|
+
type="button"
|
|
27583
|
+
>
|
|
27584
|
+
<span
|
|
27585
|
+
className="modifierUnderlined"
|
|
27586
|
+
>
|
|
27587
|
+
<span
|
|
27588
|
+
className="icon"
|
|
27589
|
+
>
|
|
27590
|
+
9
|
|
27591
|
+
</span>
|
|
27592
|
+
</span>
|
|
27593
|
+
</button>
|
|
27594
|
+
</div>
|
|
27595
|
+
</div>
|
|
27596
|
+
</form>
|
|
27597
|
+
`;
|
|
27598
|
+
|
|
27556
27599
|
exports[`Storyshots f/fields/FileUpload With Limited Count 1`] = `
|
|
27557
27600
|
<form
|
|
27558
27601
|
action="#"
|