@blaze-cms/plugin-media-ui 0.146.0-node18-tooltips.32 → 0.146.0-node18-core-styles-tooltips.41
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/CHANGELOG.md +71 -15
- package/lib/components/CardMedia/CardMedia.js +5 -1
- package/lib/components/CardMedia/CardMedia.js.map +1 -1
- package/lib/components/EditMediaFile/EditMediaFile.js +80 -37
- package/lib/components/EditMediaFile/EditMediaFile.js.map +1 -1
- package/lib/components/EditMediaFile/EditMediaFilePage.js +46 -22
- package/lib/components/EditMediaFile/EditMediaFilePage.js.map +1 -1
- package/lib/components/FilePreview/PDF/PDF.js +19 -4
- package/lib/components/FilePreview/PDF/PDF.js.map +1 -1
- package/lib/components/FilePreview/index.js +14 -3
- package/lib/components/FilePreview/index.js.map +1 -1
- package/lib/components/FilePreview/previewDefault/PreviewDefault.js +18 -4
- package/lib/components/FilePreview/previewDefault/PreviewDefault.js.map +1 -1
- package/lib/components/FileUploadModal/FileUploadModal.js +57 -21
- package/lib/components/FileUploadModal/FileUploadModal.js.map +1 -1
- package/lib/components/ListingContainer/Listing/MediaListing/MediaFileList/MediaFileList.js +6 -2
- package/lib/components/ListingContainer/Listing/MediaListing/MediaFileList/MediaFileList.js.map +1 -1
- package/lib/utils/bustUrl.js +18 -0
- package/lib/utils/bustUrl.js.map +1 -0
- package/lib-es/components/CardMedia/CardMedia.js +5 -1
- package/lib-es/components/CardMedia/CardMedia.js.map +1 -1
- package/lib-es/components/EditMediaFile/EditMediaFile.js +72 -37
- package/lib-es/components/EditMediaFile/EditMediaFile.js.map +1 -1
- package/lib-es/components/EditMediaFile/EditMediaFilePage.js +35 -13
- package/lib-es/components/EditMediaFile/EditMediaFilePage.js.map +1 -1
- package/lib-es/components/FilePreview/PDF/PDF.js +19 -4
- package/lib-es/components/FilePreview/PDF/PDF.js.map +1 -1
- package/lib-es/components/FilePreview/index.js +10 -3
- package/lib-es/components/FilePreview/index.js.map +1 -1
- package/lib-es/components/FilePreview/previewDefault/PreviewDefault.js +18 -4
- package/lib-es/components/FilePreview/previewDefault/PreviewDefault.js.map +1 -1
- package/lib-es/components/FileUploadModal/FileUploadModal.js +49 -7
- package/lib-es/components/FileUploadModal/FileUploadModal.js.map +1 -1
- package/lib-es/components/ListingContainer/Listing/MediaListing/MediaFileList/MediaFileList.js +6 -2
- package/lib-es/components/ListingContainer/Listing/MediaListing/MediaFileList/MediaFileList.js.map +1 -1
- package/lib-es/utils/bustUrl.js +7 -0
- package/lib-es/utils/bustUrl.js.map +1 -0
- package/package.json +8 -8
- package/src/components/CardMedia/CardMedia.js +5 -1
- package/src/components/EditMediaFile/EditMediaFile.js +66 -40
- package/src/components/EditMediaFile/EditMediaFilePage.js +33 -8
- package/src/components/FilePreview/PDF/PDF.js +17 -4
- package/src/components/FilePreview/index.js +9 -3
- package/src/components/FilePreview/previewDefault/PreviewDefault.js +16 -3
- package/src/components/FileUploadModal/FileUploadModal.js +35 -14
- package/src/components/ListingContainer/Listing/MediaListing/MediaFileList/MediaFileList.js +3 -1
- package/src/utils/bustUrl.js +6 -0
|
@@ -10,9 +10,9 @@ import { STORE_KEY, NAME } from '../../constants';
|
|
|
10
10
|
const EditMediaFile = ({
|
|
11
11
|
onChange,
|
|
12
12
|
handleSaveButtonStatus,
|
|
13
|
-
enableSaveButton,
|
|
14
13
|
fileId,
|
|
15
|
-
showChangeButton
|
|
14
|
+
showChangeButton,
|
|
15
|
+
fileUpdated
|
|
16
16
|
}) => {
|
|
17
17
|
const [formValues, setFormValues] = useState(null);
|
|
18
18
|
const [displayFileUploadModal, setDisplayFileUploadModal] = useState(false);
|
|
@@ -25,7 +25,7 @@ const EditMediaFile = ({
|
|
|
25
25
|
refetch: refetchFile
|
|
26
26
|
} = useQuery(fileQuery, {
|
|
27
27
|
variables: { id: fileId },
|
|
28
|
-
fetchPolicy: 'network
|
|
28
|
+
fetchPolicy: 'cache-and-network'
|
|
29
29
|
});
|
|
30
30
|
|
|
31
31
|
const fileStoresType = getQuery('GET_FILE_STORES');
|
|
@@ -34,12 +34,24 @@ const EditMediaFile = ({
|
|
|
34
34
|
});
|
|
35
35
|
|
|
36
36
|
useEffect(() => {
|
|
37
|
-
if (
|
|
38
|
-
setFormValues(
|
|
37
|
+
if (file) {
|
|
38
|
+
setFormValues(prevFormValues => {
|
|
39
|
+
if (!prevFormValues || prevFormValues.updated !== file.updated) {
|
|
40
|
+
return file;
|
|
41
|
+
}
|
|
42
|
+
return prevFormValues;
|
|
43
|
+
});
|
|
39
44
|
}
|
|
40
|
-
}, [file
|
|
45
|
+
}, [file]);
|
|
46
|
+
|
|
47
|
+
useEffect(() => {
|
|
48
|
+
if (fileUpdated && fileUpdated.updated) {
|
|
49
|
+
setFormValues(fileUpdated);
|
|
50
|
+
}
|
|
51
|
+
}, [fileUpdated]);
|
|
41
52
|
|
|
42
53
|
const handleFormChange = ({ isValid, isNewValueSet, valuesChecked }) => {
|
|
54
|
+
const baseFile = formValues || file;
|
|
43
55
|
const valuesCheckedWithoutName = valuesChecked.filter(
|
|
44
56
|
({ id }) => id !== NAME && id !== STORE_KEY
|
|
45
57
|
);
|
|
@@ -53,52 +65,67 @@ const EditMediaFile = ({
|
|
|
53
65
|
const { value: storeKey } = valuesChecked.find(({ id }) => id === STORE_KEY) || {};
|
|
54
66
|
|
|
55
67
|
const shouldEnableSaveButton = isNewValueSet && isValid;
|
|
56
|
-
handleSaveButtonStatus(
|
|
57
|
-
if (shouldEnableSaveButton && shouldEnableSaveButton !== enableSaveButton) {
|
|
58
|
-
handleSaveButtonStatus(shouldEnableSaveButton);
|
|
59
|
-
}
|
|
68
|
+
handleSaveButtonStatus(shouldEnableSaveButton);
|
|
60
69
|
|
|
61
70
|
const updatedFile = {
|
|
62
|
-
|
|
63
|
-
name: newFileName,
|
|
64
|
-
storeKey,
|
|
65
|
-
data: dataValues
|
|
71
|
+
...baseFile,
|
|
72
|
+
name: newFileName || baseFile.name,
|
|
73
|
+
storeKey: storeKey || baseFile.storeKey,
|
|
74
|
+
data: { ...(baseFile.data || {}), ...dataValues }
|
|
66
75
|
};
|
|
67
76
|
|
|
68
77
|
setFormValues(updatedFile);
|
|
69
|
-
onChange
|
|
78
|
+
// Strip GraphQL metadata field __typename before passing data to onChange.
|
|
79
|
+
const { __typename, ...cleanData } = updatedFile.data || {};
|
|
80
|
+
onChange({ id: updatedFile.id, name: updatedFile.name, data: cleanData });
|
|
70
81
|
};
|
|
71
82
|
|
|
72
|
-
const getFileWithStoreType =
|
|
73
|
-
|
|
83
|
+
const getFileWithStoreType = sourceFile => {
|
|
84
|
+
const base = sourceFile || file;
|
|
85
|
+
if (storeType && base) {
|
|
74
86
|
const storeOptions = storeType.map(type => [type.key, type.name]);
|
|
75
87
|
const defaultStore = storeType.find(type => type.isDefault) || null;
|
|
76
|
-
return { ...
|
|
88
|
+
return { ...base, store: { defaultStore, storeOptions } };
|
|
77
89
|
}
|
|
78
|
-
return
|
|
90
|
+
return base;
|
|
79
91
|
};
|
|
80
92
|
|
|
81
93
|
const closeModalAndSetValue = async (isSaving, values, toastMessage) => {
|
|
82
94
|
if (toastMessage) {
|
|
83
|
-
addToast(toastMessage, {
|
|
84
|
-
|
|
85
|
-
|
|
95
|
+
addToast(toastMessage, { appearance: 'success', autoDismiss: true });
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
if (values) {
|
|
99
|
+
const updated =
|
|
100
|
+
values.id === fileId
|
|
101
|
+
? values
|
|
102
|
+
: {
|
|
103
|
+
...(formValues || file),
|
|
104
|
+
...values,
|
|
105
|
+
url: values.url || (formValues || file).url
|
|
106
|
+
};
|
|
107
|
+
setFormValues(updated);
|
|
108
|
+
onChange(updated);
|
|
109
|
+
handleSaveButtonStatus(true);
|
|
110
|
+
} else {
|
|
111
|
+
const { data: { file: refreshedFile } = {} } = await refetchFile({
|
|
112
|
+
id: fileId,
|
|
113
|
+
timestamp: Date.now()
|
|
86
114
|
});
|
|
115
|
+
if (refreshedFile) {
|
|
116
|
+
setFormValues(refreshedFile);
|
|
117
|
+
onChange(refreshedFile);
|
|
118
|
+
handleSaveButtonStatus(true);
|
|
119
|
+
}
|
|
87
120
|
}
|
|
88
|
-
await refetchFile({
|
|
89
|
-
id: fileId,
|
|
90
|
-
timestamp: Date.now()
|
|
91
|
-
});
|
|
92
|
-
setDisplayFileUploadModal(false);
|
|
93
|
-
};
|
|
94
121
|
|
|
95
|
-
|
|
96
|
-
setDisplayFileUploadModal(true);
|
|
122
|
+
setDisplayFileUploadModal(false);
|
|
97
123
|
};
|
|
98
124
|
|
|
99
125
|
if (loading) return <div>loading...</div>;
|
|
100
126
|
|
|
101
|
-
const
|
|
127
|
+
const fileToRender = formValues || file;
|
|
128
|
+
const fileWithStoreType = getFileWithStoreType(fileToRender);
|
|
102
129
|
|
|
103
130
|
return !loading ? (
|
|
104
131
|
<>
|
|
@@ -106,7 +133,7 @@ const EditMediaFile = ({
|
|
|
106
133
|
<FilePreview
|
|
107
134
|
file={fileWithStoreType}
|
|
108
135
|
handleFormChange={handleFormChange}
|
|
109
|
-
handleChangeFile={
|
|
136
|
+
handleChangeFile={() => setDisplayFileUploadModal(true)}
|
|
110
137
|
displayForm
|
|
111
138
|
showChangeButton={showChangeButton}
|
|
112
139
|
/>
|
|
@@ -114,13 +141,12 @@ const EditMediaFile = ({
|
|
|
114
141
|
{displayFileUploadModal && (
|
|
115
142
|
<div className="file-upload-modal-wrapper">
|
|
116
143
|
<FileUploadModal
|
|
117
|
-
onClose={() =>
|
|
118
|
-
setDisplayFileUploadModal(false);
|
|
119
|
-
}}
|
|
144
|
+
onClose={() => setDisplayFileUploadModal(false)}
|
|
120
145
|
closeModalAndSetValue={closeModalAndSetValue}
|
|
121
146
|
simpleLayout
|
|
122
147
|
fileId={fileId}
|
|
123
|
-
|
|
148
|
+
storeKey={file && file.storeKey}
|
|
149
|
+
getSelectedFiles={() => { }}
|
|
124
150
|
/>
|
|
125
151
|
</div>
|
|
126
152
|
)}
|
|
@@ -134,13 +160,13 @@ EditMediaFile.propTypes = {
|
|
|
134
160
|
fileId: PropTypes.string.isRequired,
|
|
135
161
|
onChange: PropTypes.func.isRequired,
|
|
136
162
|
handleSaveButtonStatus: PropTypes.func.isRequired,
|
|
137
|
-
|
|
138
|
-
|
|
163
|
+
showChangeButton: PropTypes.bool,
|
|
164
|
+
fileUpdated: PropTypes.object
|
|
139
165
|
};
|
|
140
166
|
|
|
141
167
|
EditMediaFile.defaultProps = {
|
|
142
|
-
|
|
143
|
-
|
|
168
|
+
showChangeButton: false,
|
|
169
|
+
fileUpdated: null
|
|
144
170
|
};
|
|
145
171
|
|
|
146
172
|
export default EditMediaFile;
|
|
@@ -20,19 +20,44 @@ const EditMediaFilePage = ({ match, history }) => {
|
|
|
20
20
|
};
|
|
21
21
|
|
|
22
22
|
const handleFormSave = async () => {
|
|
23
|
+
if (!file) {
|
|
24
|
+
addToast('No file data to update', {
|
|
25
|
+
appearance: 'error',
|
|
26
|
+
autoDismiss: true
|
|
27
|
+
});
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
|
|
23
31
|
try {
|
|
24
|
-
|
|
32
|
+
const inputData = {
|
|
33
|
+
id: file.id,
|
|
34
|
+
name: file.name,
|
|
35
|
+
data: file.data,
|
|
36
|
+
storeKey: file.storeKey
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
const {
|
|
40
|
+
data: { updateFile: updatedFile }
|
|
41
|
+
} = await client.mutate({
|
|
25
42
|
mutation: getMutation('UPDATE_FILE'),
|
|
26
|
-
variables: {
|
|
43
|
+
variables: {
|
|
44
|
+
input: inputData
|
|
45
|
+
},
|
|
27
46
|
update(cache, { data: { updateFile: fileUpdated } }) {
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
47
|
+
try {
|
|
48
|
+
cache.writeQuery({
|
|
49
|
+
query: getQuery('GET_FILE_BY_ID'),
|
|
50
|
+
variables: { id: match.params.fileId },
|
|
51
|
+
data: { file: fileUpdated.result }
|
|
52
|
+
});
|
|
53
|
+
} catch (e) {
|
|
54
|
+
console.error(e); //eslint-disable-line
|
|
55
|
+
}
|
|
33
56
|
}
|
|
34
57
|
});
|
|
35
58
|
|
|
59
|
+
setFile(updatedFile.result);
|
|
60
|
+
|
|
36
61
|
addToast(`File: ${file.name} has been updated`, {
|
|
37
62
|
appearance: 'success',
|
|
38
63
|
autoDismiss: true
|
|
@@ -42,7 +67,6 @@ const EditMediaFilePage = ({ match, history }) => {
|
|
|
42
67
|
appearance: 'error',
|
|
43
68
|
autoDismiss: true
|
|
44
69
|
});
|
|
45
|
-
console.error(e); //eslint-disable-line
|
|
46
70
|
}
|
|
47
71
|
setShouldEnableSaveButton(false);
|
|
48
72
|
};
|
|
@@ -61,6 +85,7 @@ const EditMediaFilePage = ({ match, history }) => {
|
|
|
61
85
|
handleSaveButtonStatus={handleSaveButtonStatus}
|
|
62
86
|
handleFormSave={handleFormSave}
|
|
63
87
|
showChangeButton
|
|
88
|
+
fileUpdated={file}
|
|
64
89
|
/>
|
|
65
90
|
<div className="page__content__mediaWrapperActions">
|
|
66
91
|
<Button onClick={pushBack}>Cancel</Button>
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import PropTypes from 'prop-types';
|
|
3
|
+
import Button from '@blaze-react/button';
|
|
3
4
|
|
|
4
|
-
const PDF = ({ mimetype, url, name, children }) => (
|
|
5
|
-
<div className="preview">
|
|
5
|
+
const PDF = ({ mimetype, url, name, children, handleChangeFile, showChangeButton }) => (
|
|
6
|
+
<div className="preview" key={`pdf-${url}`}>
|
|
6
7
|
<div className="preview__file preview__file--pdf">
|
|
7
|
-
<object data={url} type={mimetype} className="preview__file--pdf">
|
|
8
|
+
<object key={url} data={url} type={mimetype} className="preview__file--pdf">
|
|
8
9
|
<p>
|
|
9
10
|
<a href={url} rel="noopener noreferrer" target="_blank">
|
|
10
11
|
Download {name}
|
|
@@ -18,6 +19,11 @@ const PDF = ({ mimetype, url, name, children }) => (
|
|
|
18
19
|
Original
|
|
19
20
|
</a>
|
|
20
21
|
</p>
|
|
22
|
+
{showChangeButton && (
|
|
23
|
+
<div className="preview__change-button">
|
|
24
|
+
<Button onClick={handleChangeFile}>Change file</Button>
|
|
25
|
+
</div>
|
|
26
|
+
)}
|
|
21
27
|
</div>
|
|
22
28
|
</div>
|
|
23
29
|
{children}
|
|
@@ -28,7 +34,14 @@ PDF.propTypes = {
|
|
|
28
34
|
mimetype: PropTypes.string.isRequired,
|
|
29
35
|
url: PropTypes.string.isRequired,
|
|
30
36
|
name: PropTypes.string.isRequired,
|
|
31
|
-
children: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.node), PropTypes.node]).isRequired
|
|
37
|
+
children: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.node), PropTypes.node]).isRequired,
|
|
38
|
+
handleChangeFile: PropTypes.func,
|
|
39
|
+
showChangeButton: PropTypes.bool
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
PDF.defaultProps = {
|
|
43
|
+
handleChangeFile: () => {},
|
|
44
|
+
showChangeButton: false
|
|
32
45
|
};
|
|
33
46
|
|
|
34
47
|
export { PDF };
|
|
@@ -13,7 +13,13 @@ const FilePreview = ({
|
|
|
13
13
|
showChangeButton,
|
|
14
14
|
disableFilePreview
|
|
15
15
|
}) => {
|
|
16
|
-
const { name, url, mimetype, data, store } = file;
|
|
16
|
+
const { name, url, mimetype, data, store, updated } = file;
|
|
17
|
+
const bustUrl = (srcUrl, version) => {
|
|
18
|
+
if (!srcUrl) return srcUrl;
|
|
19
|
+
const sep = srcUrl.includes('?') ? '&' : '?';
|
|
20
|
+
return `${srcUrl}${sep}v=${version || Date.now()}`;
|
|
21
|
+
};
|
|
22
|
+
const displayUrl = bustUrl(url, updated);
|
|
17
23
|
const [Preview, schema] = getPreview({ mimetype, previewType });
|
|
18
24
|
const shouldRenderForm = schema && displayForm;
|
|
19
25
|
|
|
@@ -28,13 +34,13 @@ const FilePreview = ({
|
|
|
28
34
|
}
|
|
29
35
|
}
|
|
30
36
|
|
|
31
|
-
const formBuilderData = { values: { ...
|
|
37
|
+
const formBuilderData = { values: { ...data, ...file } };
|
|
32
38
|
|
|
33
39
|
return (
|
|
34
40
|
<>
|
|
35
41
|
<Preview
|
|
36
42
|
mimetype={mimetype}
|
|
37
|
-
url={
|
|
43
|
+
url={displayUrl}
|
|
38
44
|
name={name}
|
|
39
45
|
{...data}
|
|
40
46
|
file={file}
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import PropTypes from 'prop-types';
|
|
3
|
+
import Button from '@blaze-react/button';
|
|
3
4
|
import { DefaultIcon } from './icons';
|
|
4
5
|
|
|
5
|
-
const PreviewDefault = ({ url, name, children }) => (
|
|
6
|
-
<div className="preview">
|
|
6
|
+
const PreviewDefault = ({ url, name, children, handleChangeFile, showChangeButton }) => (
|
|
7
|
+
<div className="preview" key={`default-${url}`}>
|
|
7
8
|
<div className="preview__file preview__file--default">
|
|
8
9
|
<div className="preview__file--icon">
|
|
9
10
|
<DefaultIcon />
|
|
@@ -16,6 +17,11 @@ const PreviewDefault = ({ url, name, children }) => (
|
|
|
16
17
|
Original
|
|
17
18
|
</a>
|
|
18
19
|
</p>
|
|
20
|
+
{showChangeButton && (
|
|
21
|
+
<div className="preview__change-button">
|
|
22
|
+
<Button onClick={handleChangeFile}>Change file</Button>
|
|
23
|
+
</div>
|
|
24
|
+
)}
|
|
19
25
|
</div>
|
|
20
26
|
</div>
|
|
21
27
|
{children}
|
|
@@ -25,7 +31,14 @@ const PreviewDefault = ({ url, name, children }) => (
|
|
|
25
31
|
PreviewDefault.propTypes = {
|
|
26
32
|
url: PropTypes.string.isRequired,
|
|
27
33
|
name: PropTypes.string.isRequired,
|
|
28
|
-
children: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.node), PropTypes.node]).isRequired
|
|
34
|
+
children: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.node), PropTypes.node]).isRequired,
|
|
35
|
+
handleChangeFile: PropTypes.func,
|
|
36
|
+
showChangeButton: PropTypes.bool
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
PreviewDefault.defaultProps = {
|
|
40
|
+
handleChangeFile: () => {},
|
|
41
|
+
showChangeButton: false
|
|
29
42
|
};
|
|
30
43
|
|
|
31
44
|
export { PreviewDefault };
|
|
@@ -21,21 +21,26 @@ const FileUploadModal = ({
|
|
|
21
21
|
const { addNewFile } = useFileList();
|
|
22
22
|
|
|
23
23
|
const fileStoresType = getQuery('GET_FILE_STORES');
|
|
24
|
-
|
|
25
24
|
const { data: { getFileStores: storeType = [] } = {} } = useQuery(fileStoresType, {
|
|
26
25
|
variables: { visibleInAdmin: true }
|
|
27
26
|
});
|
|
28
27
|
|
|
29
28
|
const handleFiles = filesToUpload => {
|
|
29
|
+
if (fileId && filesToUpload && filesToUpload.length) {
|
|
30
|
+
setFiles([filesToUpload[0]]);
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
30
33
|
setFiles(filesToUpload);
|
|
31
34
|
};
|
|
32
35
|
|
|
33
36
|
const uploadFiles = async () => {
|
|
37
|
+
const filesToProcess = fileId && files.length ? [files[0]] : files;
|
|
38
|
+
|
|
34
39
|
const response = await Promise.all(
|
|
35
|
-
|
|
40
|
+
filesToProcess.map(({ file, name, data, storeKey: fileStoreKey }) => {
|
|
36
41
|
const payload = {
|
|
37
42
|
name,
|
|
38
|
-
storeKey: fileStoreKey,
|
|
43
|
+
storeKey: fileStoreKey || selectedStoreKey || storeKey,
|
|
39
44
|
data
|
|
40
45
|
};
|
|
41
46
|
if (fileId) {
|
|
@@ -45,12 +50,7 @@ const FileUploadModal = ({
|
|
|
45
50
|
}
|
|
46
51
|
return client.mutate({
|
|
47
52
|
mutation: getMutation('UPLOAD_FILE'),
|
|
48
|
-
variables: {
|
|
49
|
-
input: {
|
|
50
|
-
file,
|
|
51
|
-
...payload
|
|
52
|
-
}
|
|
53
|
-
}
|
|
53
|
+
variables: { input: { file, ...payload } }
|
|
54
54
|
});
|
|
55
55
|
})
|
|
56
56
|
).catch(error => {
|
|
@@ -58,21 +58,42 @@ const FileUploadModal = ({
|
|
|
58
58
|
appearance: 'error',
|
|
59
59
|
autoDismiss: true
|
|
60
60
|
});
|
|
61
|
+
return [];
|
|
61
62
|
});
|
|
62
63
|
|
|
63
|
-
const parsedResponse = response.map(({ data: { file } }) =>
|
|
64
|
+
const parsedResponse = response.map(({ data: { file } }) => {
|
|
65
|
+
const { message, ...rest } = file.result || {};
|
|
66
|
+
return rest;
|
|
67
|
+
});
|
|
64
68
|
|
|
65
69
|
const fileNames = files.map(({ file }) => file.name);
|
|
66
|
-
addNewFile && addNewFile(parsedResponse);
|
|
67
|
-
const toastMessage = `Uploaded: ${fileNames.join(', ')}`;
|
|
68
70
|
|
|
69
71
|
if (simpleLayout) {
|
|
70
|
-
|
|
72
|
+
if (fileId && parsedResponse && parsedResponse.length) {
|
|
73
|
+
const { message, ...updatedFile } = parsedResponse[0];
|
|
74
|
+
try {
|
|
75
|
+
client.writeQuery({
|
|
76
|
+
query: getQuery('GET_FILE_BY_ID'),
|
|
77
|
+
variables: { id: fileId },
|
|
78
|
+
data: { file: updatedFile }
|
|
79
|
+
});
|
|
80
|
+
} catch (e) {
|
|
81
|
+
console.error(e); //eslint-disable-line
|
|
82
|
+
}
|
|
83
|
+
const updateMessage = `Updated: ${updatedFile.filename || fileNames[0]}`;
|
|
84
|
+
closeModalAndSetValue(simpleLayout, updatedFile, updateMessage);
|
|
85
|
+
return;
|
|
86
|
+
}
|
|
87
|
+
const filesToSelect = parsedResponse.map(({ id }) => id);
|
|
88
|
+
const uploadMessage = `Uploaded: ${fileNames.join(', ')}`;
|
|
71
89
|
getSelectedFiles(null, filesToSelect);
|
|
72
|
-
closeModalAndSetValue(simpleLayout, filesToSelect,
|
|
90
|
+
closeModalAndSetValue(simpleLayout, filesToSelect, uploadMessage);
|
|
73
91
|
return;
|
|
74
92
|
}
|
|
75
93
|
|
|
94
|
+
addNewFile && addNewFile(parsedResponse);
|
|
95
|
+
const toastMessage = fileId ? `Updated: ${fileNames[0]}` : `Uploaded: ${fileNames.join(', ')}`;
|
|
96
|
+
|
|
76
97
|
addToast(toastMessage, {
|
|
77
98
|
appearance: 'success',
|
|
78
99
|
autoDismiss: true
|
|
@@ -109,7 +109,7 @@ const MediaFileList = ({
|
|
|
109
109
|
scrollToIndex={currentListIndex}
|
|
110
110
|
onItemsRendered={handleRenderedItems}
|
|
111
111
|
renderItem={({ index, style }) => {
|
|
112
|
-
const { name, url, mimetype, id } = data.files[index];
|
|
112
|
+
const { name, url, mimetype, id, data: fileData, updated } = data.files[index];
|
|
113
113
|
const isSelected = existPrevious(selectedFiles, id);
|
|
114
114
|
return (
|
|
115
115
|
<div key={index} style={style} className="list__item--resultWrapper">
|
|
@@ -129,6 +129,8 @@ const MediaFileList = ({
|
|
|
129
129
|
index={index}
|
|
130
130
|
removeFile={removeFile}
|
|
131
131
|
openEditInModal={openEditInModal}
|
|
132
|
+
data={fileData}
|
|
133
|
+
updated={updated}
|
|
132
134
|
/>
|
|
133
135
|
</div>
|
|
134
136
|
);
|