@blaze-cms/plugin-media-ui 0.146.0-translations.8 → 0.147.0-rc-eagle.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.
- package/lib/components/CardMedia/CardMedia.js +160 -223
- package/lib/components/CardMedia/CardMedia.js.map +1 -1
- package/lib/components/CardMedia/index.js +2 -3
- package/lib/components/CardMedia/index.js.map +1 -1
- package/lib/components/EditMediaFile/EditMediaFile.js +153 -164
- package/lib/components/EditMediaFile/EditMediaFile.js.map +1 -1
- package/lib/components/EditMediaFile/EditMediaFilePage.js +79 -96
- package/lib/components/EditMediaFile/EditMediaFilePage.js.map +1 -1
- package/lib/components/EditMediaFile/index.js +2 -3
- package/lib/components/EditMediaFile/index.js.map +1 -1
- package/lib/components/EditorAdapter/EditorAdapter.js +43 -22
- package/lib/components/EditorAdapter/EditorAdapter.js.map +1 -1
- package/lib/components/EditorAdapter/index.js +2 -3
- package/lib/components/EditorAdapter/index.js.map +1 -1
- package/lib/components/FileList/FilesListContext/index.js +3 -4
- package/lib/components/FileList/FilesListContext/index.js.map +1 -1
- package/lib/components/FileList/FilesListProvider/index.js +27 -29
- package/lib/components/FileList/FilesListProvider/index.js.map +1 -1
- package/lib/components/FileList/useFileList/index.js +3 -6
- package/lib/components/FileList/useFileList/index.js.map +1 -1
- package/lib/components/FileList/useGetFiles/getFiles.js +164 -184
- package/lib/components/FileList/useGetFiles/getFiles.js.map +1 -1
- package/lib/components/FileList/useGetFiles/index.js +2 -3
- package/lib/components/FileList/useGetFiles/index.js.map +1 -1
- package/lib/components/FileList/useGetFiles/useGetFiles.js +88 -132
- package/lib/components/FileList/useGetFiles/useGetFiles.js.map +1 -1
- package/lib/components/FileList/useGetFilesList/getCounters.js +10 -30
- package/lib/components/FileList/useGetFilesList/getCounters.js.map +1 -1
- package/lib/components/FileList/useGetFilesList/index.js +2 -3
- package/lib/components/FileList/useGetFilesList/index.js.map +1 -1
- package/lib/components/FileList/useGetFilesList/useGetFilesList.js +89 -109
- package/lib/components/FileList/useGetFilesList/useGetFilesList.js.map +1 -1
- package/lib/components/FilePreview/Actions/index.js +24 -38
- package/lib/components/FilePreview/Actions/index.js.map +1 -1
- package/lib/components/FilePreview/Image/Image.js +31 -33
- package/lib/components/FilePreview/Image/Image.js.map +1 -1
- package/lib/components/FilePreview/Image/RawImage.js +25 -27
- package/lib/components/FilePreview/Image/RawImage.js.map +1 -1
- package/lib/components/FilePreview/Image/imageSchema.js +1 -2
- package/lib/components/FilePreview/Image/imageSchema.js.map +1 -1
- package/lib/components/FilePreview/Image/index.js +1 -2
- package/lib/components/FilePreview/Image/index.js.map +1 -1
- package/lib/components/FilePreview/ModalContext.js +1 -2
- package/lib/components/FilePreview/ModalContext.js.map +1 -1
- package/lib/components/FilePreview/PDF/PDF.js +44 -31
- package/lib/components/FilePreview/PDF/PDF.js.map +1 -1
- package/lib/components/FilePreview/PDF/RawPDF.js +27 -29
- package/lib/components/FilePreview/PDF/RawPDF.js.map +1 -1
- package/lib/components/FilePreview/PDF/index.js +1 -2
- package/lib/components/FilePreview/PDF/index.js.map +1 -1
- package/lib/components/FilePreview/PDF/schema.js +1 -2
- package/lib/components/FilePreview/PDF/schema.js.map +1 -1
- package/lib/components/FilePreview/get-preview.js +12 -10
- package/lib/components/FilePreview/get-preview.js.map +1 -1
- package/lib/components/FilePreview/index.js +59 -62
- package/lib/components/FilePreview/index.js.map +1 -1
- package/lib/components/FilePreview/previewDefault/PreviewDefault.js +35 -23
- package/lib/components/FilePreview/previewDefault/PreviewDefault.js.map +1 -1
- package/lib/components/FilePreview/previewDefault/RawPreviewDefault.js +33 -35
- package/lib/components/FilePreview/previewDefault/RawPreviewDefault.js.map +1 -1
- package/lib/components/FilePreview/previewDefault/icons/DefaultIcon.js +120 -123
- package/lib/components/FilePreview/previewDefault/icons/DefaultIcon.js.map +1 -1
- package/lib/components/FilePreview/previewDefault/icons/index.js +2 -3
- package/lib/components/FilePreview/previewDefault/icons/index.js.map +1 -1
- package/lib/components/FilePreview/previewDefault/index.js +1 -2
- package/lib/components/FilePreview/previewDefault/index.js.map +1 -1
- package/lib/components/FilePreview/previewDefault/previewDefaultSchema.js +1 -2
- package/lib/components/FilePreview/previewDefault/previewDefaultSchema.js.map +1 -1
- package/lib/components/FilePreviewReadOnly/FileList.js +10 -12
- package/lib/components/FilePreviewReadOnly/FileList.js.map +1 -1
- package/lib/components/FilePreviewReadOnly/FilePreviewList.js +14 -19
- package/lib/components/FilePreviewReadOnly/FilePreviewList.js.map +1 -1
- package/lib/components/FilePreviewReadOnly/FilePreviewReadOnly.js +52 -98
- package/lib/components/FilePreviewReadOnly/FilePreviewReadOnly.js.map +1 -1
- package/lib/components/FilePreviewReadOnly/index.js +2 -3
- package/lib/components/FilePreviewReadOnly/index.js.map +1 -1
- package/lib/components/FilePreviewReadOnly/mappers/format-initial-value.js +7 -8
- package/lib/components/FilePreviewReadOnly/mappers/format-initial-value.js.map +1 -1
- package/lib/components/FilePreviewReadOnly/mappers/index.js +1 -2
- package/lib/components/FilePreviewReadOnly/mappers/index.js.map +1 -1
- package/lib/components/FileUploadAdapter/FileList.js +26 -39
- package/lib/components/FileUploadAdapter/FileList.js.map +1 -1
- package/lib/components/FileUploadAdapter/FilePreviewList.js +14 -19
- package/lib/components/FileUploadAdapter/FilePreviewList.js.map +1 -1
- package/lib/components/FileUploadAdapter/FileReorderList.js +18 -21
- package/lib/components/FileUploadAdapter/FileReorderList.js.map +1 -1
- package/lib/components/FileUploadAdapter/FileReorderListItem.js +20 -23
- package/lib/components/FileUploadAdapter/FileReorderListItem.js.map +1 -1
- package/lib/components/FileUploadAdapter/FileUploadAdapter.js +219 -342
- package/lib/components/FileUploadAdapter/FileUploadAdapter.js.map +1 -1
- package/lib/components/FileUploadAdapter/index.js +2 -3
- package/lib/components/FileUploadAdapter/index.js.map +1 -1
- package/lib/components/FileUploadAdapter/mappers/format-initial-value.js +7 -8
- package/lib/components/FileUploadAdapter/mappers/format-initial-value.js.map +1 -1
- package/lib/components/FileUploadAdapter/mappers/get-button-text.js +9 -10
- package/lib/components/FileUploadAdapter/mappers/get-button-text.js.map +1 -1
- package/lib/components/FileUploadAdapter/mappers/get-format.js +7 -13
- package/lib/components/FileUploadAdapter/mappers/get-format.js.map +1 -1
- package/lib/components/FileUploadAdapter/mappers/get-number-files-pending-to-fetch.js +2 -2
- package/lib/components/FileUploadAdapter/mappers/get-number-files-pending-to-fetch.js.map +1 -1
- package/lib/components/FileUploadAdapter/mappers/index.js +6 -7
- package/lib/components/FileUploadAdapter/mappers/index.js.map +1 -1
- package/lib/components/FileUploadAdapter/mappers/is-unselecting.js +2 -10
- package/lib/components/FileUploadAdapter/mappers/is-unselecting.js.map +1 -1
- package/lib/components/FileUploadAdapter/mappers/transform-to-array.js +2 -5
- package/lib/components/FileUploadAdapter/mappers/transform-to-array.js.map +1 -1
- package/lib/components/FileUploadAdapter/useLimit.js +4 -10
- package/lib/components/FileUploadAdapter/useLimit.js.map +1 -1
- package/lib/components/FileUploadModal/FileUploadModal.js +142 -169
- package/lib/components/FileUploadModal/FileUploadModal.js.map +1 -1
- package/lib/components/FileUploadModal/index.js +2 -3
- package/lib/components/FileUploadModal/index.js.map +1 -1
- package/lib/components/FilterPanel/FilterPanel.js +68 -88
- package/lib/components/FilterPanel/FilterPanel.js.map +1 -1
- package/lib/components/FilterPanel/index.js +2 -3
- package/lib/components/FilterPanel/index.js.map +1 -1
- package/lib/components/ListingContainer/Listing/Listing.js +55 -57
- package/lib/components/ListingContainer/Listing/Listing.js.map +1 -1
- package/lib/components/ListingContainer/Listing/MediaListing/MediaFileList/MediaFileList.js +71 -92
- package/lib/components/ListingContainer/Listing/MediaListing/MediaFileList/MediaFileList.js.map +1 -1
- package/lib/components/ListingContainer/Listing/MediaListing/MediaFileList/index.js +2 -3
- package/lib/components/ListingContainer/Listing/MediaListing/MediaFileList/index.js.map +1 -1
- package/lib/components/ListingContainer/Listing/MediaListing/MediaListing.js +14 -26
- package/lib/components/ListingContainer/Listing/MediaListing/MediaListing.js.map +1 -1
- package/lib/components/ListingContainer/Listing/MediaListing/index.js +2 -3
- package/lib/components/ListingContainer/Listing/MediaListing/index.js.map +1 -1
- package/lib/components/ListingContainer/Listing/index.js +2 -3
- package/lib/components/ListingContainer/Listing/index.js.map +1 -1
- package/lib/components/ListingContainer/ListingContainer.js +62 -94
- package/lib/components/ListingContainer/ListingContainer.js.map +1 -1
- package/lib/components/ListingContainer/index.js +2 -3
- package/lib/components/ListingContainer/index.js.map +1 -1
- package/lib/components/ListingContainer/mappers/exist-previous.js +3 -10
- package/lib/components/ListingContainer/mappers/exist-previous.js.map +1 -1
- package/lib/components/ListingContainer/mappers/index.js +2 -3
- package/lib/components/ListingContainer/mappers/index.js.map +1 -1
- package/lib/components/MediaListing.js +14 -26
- package/lib/components/MediaListing.js.map +1 -1
- package/lib/constants.js +15 -16
- package/lib/constants.js.map +1 -1
- package/lib/icons/MediaLibraryIcon.js +17 -20
- package/lib/icons/MediaLibraryIcon.js.map +1 -1
- package/lib/icons/index.js +2 -3
- package/lib/icons/index.js.map +1 -1
- package/lib/index.js +67 -92
- package/lib/index.js.map +1 -1
- package/lib/utils/available-filters/available-filters.js +1 -2
- package/lib/utils/available-filters/available-filters.js.map +1 -1
- package/lib/utils/bustUrl.js +13 -0
- package/lib/utils/bustUrl.js.map +1 -0
- package/lib/utils/media-context/index.js +4 -5
- package/lib/utils/media-context/index.js.map +1 -1
- package/lib/utils/media-context/media-context.js +3 -4
- package/lib/utils/media-context/media-context.js.map +1 -1
- package/lib/utils/media-context/useMediaContext.js +2 -4
- package/lib/utils/media-context/useMediaContext.js.map +1 -1
- package/lib-es/components/CardMedia/CardMedia.js +7 -3
- package/lib-es/components/CardMedia/CardMedia.js.map +1 -1
- package/lib-es/components/EditMediaFile/EditMediaFile.js +74 -39
- 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/EditorAdapter/EditorAdapter.js +26 -6
- package/lib-es/components/EditorAdapter/EditorAdapter.js.map +1 -1
- package/lib-es/components/FileList/useGetFiles/getFiles.js.map +1 -1
- package/lib-es/components/FileList/useGetFilesList/useGetFilesList.js.map +1 -1
- package/lib-es/components/FilePreview/Actions/index.js +2 -2
- package/lib-es/components/FilePreview/Actions/index.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/FilePreviewReadOnly/FileList.js +2 -2
- package/lib-es/components/FilePreviewReadOnly/FileList.js.map +1 -1
- package/lib-es/components/FilePreviewReadOnly/FilePreviewReadOnly.js +14 -12
- package/lib-es/components/FilePreviewReadOnly/FilePreviewReadOnly.js.map +1 -1
- package/lib-es/components/FileUploadAdapter/FileList.js.map +1 -1
- package/lib-es/components/FileUploadAdapter/FileUploadAdapter.js +8 -2
- package/lib-es/components/FileUploadAdapter/FileUploadAdapter.js.map +1 -1
- package/lib-es/components/FileUploadAdapter/mappers/get-button-text.js.map +1 -1
- package/lib-es/components/FileUploadAdapter/useLimit.js.map +1 -1
- package/lib-es/components/FileUploadModal/FileUploadModal.js +51 -9
- package/lib-es/components/FileUploadModal/FileUploadModal.js.map +1 -1
- package/lib-es/components/FilterPanel/FilterPanel.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/index.js +20 -4
- package/lib-es/index.js.map +1 -1
- package/lib-es/utils/bustUrl.js +7 -0
- package/lib-es/utils/bustUrl.js.map +1 -0
- package/package.json +25 -17
- package/src/components/CardMedia/CardMedia.js +6 -7
- package/src/components/EditMediaFile/EditMediaFile.js +75 -46
- package/src/components/EditMediaFile/EditMediaFilePage.js +33 -13
- package/src/components/EditorAdapter/EditorAdapter.js +31 -4
- package/src/components/FileList/useGetFilesList/useGetFilesList.js +15 -14
- package/src/components/FilePreview/Actions/index.js +25 -27
- 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/FilePreviewReadOnly/FileList.js +1 -3
- package/src/components/FilePreviewReadOnly/FilePreviewReadOnly.js +17 -29
- package/src/components/FileUploadAdapter/FileUploadAdapter.js +52 -55
- package/src/components/FileUploadAdapter/useLimit.js +5 -8
- package/src/components/FileUploadModal/FileUploadModal.js +57 -38
- package/src/components/FilterPanel/FilterPanel.js +18 -23
- package/src/components/ListingContainer/Listing/MediaListing/MediaFileList/MediaFileList.js +22 -34
- package/src/index.js +17 -10
- package/src/utils/bustUrl.js +6 -0
- package/CHANGELOG.md +0 -1243
- package/babel.config.js +0 -3
- package/jest.config.js +0 -5
|
@@ -10,18 +10,22 @@ 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);
|
|
19
19
|
const { addToast } = useToasts();
|
|
20
20
|
|
|
21
21
|
const fileQuery = getQuery('GET_FILE_BY_ID');
|
|
22
|
-
const {
|
|
22
|
+
const {
|
|
23
|
+
loading,
|
|
24
|
+
data: { file } = {},
|
|
25
|
+
refetch: refetchFile
|
|
26
|
+
} = useQuery(fileQuery, {
|
|
23
27
|
variables: { id: fileId },
|
|
24
|
-
fetchPolicy: 'network
|
|
28
|
+
fetchPolicy: 'cache-and-network'
|
|
25
29
|
});
|
|
26
30
|
|
|
27
31
|
const fileStoresType = getQuery('GET_FILE_STORES');
|
|
@@ -29,16 +33,25 @@ const EditMediaFile = ({
|
|
|
29
33
|
variables: { visibleInAdmin: true }
|
|
30
34
|
});
|
|
31
35
|
|
|
32
|
-
useEffect(
|
|
33
|
-
()
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
36
|
+
useEffect(() => {
|
|
37
|
+
if (file) {
|
|
38
|
+
setFormValues(prevFormValues => {
|
|
39
|
+
if (!prevFormValues || prevFormValues.updated !== file.updated) {
|
|
40
|
+
return file;
|
|
41
|
+
}
|
|
42
|
+
return prevFormValues;
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
}, [file]);
|
|
46
|
+
|
|
47
|
+
useEffect(() => {
|
|
48
|
+
if (fileUpdated && fileUpdated.updated) {
|
|
49
|
+
setFormValues(fileUpdated);
|
|
50
|
+
}
|
|
51
|
+
}, [fileUpdated]);
|
|
40
52
|
|
|
41
53
|
const handleFormChange = ({ isValid, isNewValueSet, valuesChecked }) => {
|
|
54
|
+
const baseFile = formValues || file;
|
|
42
55
|
const valuesCheckedWithoutName = valuesChecked.filter(
|
|
43
56
|
({ id }) => id !== NAME && id !== STORE_KEY
|
|
44
57
|
);
|
|
@@ -52,60 +65,75 @@ const EditMediaFile = ({
|
|
|
52
65
|
const { value: storeKey } = valuesChecked.find(({ id }) => id === STORE_KEY) || {};
|
|
53
66
|
|
|
54
67
|
const shouldEnableSaveButton = isNewValueSet && isValid;
|
|
55
|
-
handleSaveButtonStatus(
|
|
56
|
-
if (shouldEnableSaveButton && shouldEnableSaveButton !== enableSaveButton) {
|
|
57
|
-
handleSaveButtonStatus(shouldEnableSaveButton);
|
|
58
|
-
}
|
|
68
|
+
handleSaveButtonStatus(shouldEnableSaveButton);
|
|
59
69
|
|
|
60
70
|
const updatedFile = {
|
|
61
|
-
|
|
62
|
-
name: newFileName,
|
|
63
|
-
storeKey,
|
|
64
|
-
data: dataValues
|
|
71
|
+
...baseFile,
|
|
72
|
+
name: newFileName || baseFile.name,
|
|
73
|
+
storeKey: storeKey || baseFile.storeKey,
|
|
74
|
+
data: { ...(baseFile.data || {}), ...dataValues }
|
|
65
75
|
};
|
|
66
76
|
|
|
67
77
|
setFormValues(updatedFile);
|
|
68
|
-
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 });
|
|
69
81
|
};
|
|
70
82
|
|
|
71
|
-
const getFileWithStoreType =
|
|
72
|
-
|
|
83
|
+
const getFileWithStoreType = sourceFile => {
|
|
84
|
+
const base = sourceFile || file;
|
|
85
|
+
if (storeType && base) {
|
|
73
86
|
const storeOptions = storeType.map(type => [type.key, type.name]);
|
|
74
87
|
const defaultStore = storeType.find(type => type.isDefault) || null;
|
|
75
|
-
return { ...
|
|
88
|
+
return { ...base, store: { defaultStore, storeOptions } };
|
|
76
89
|
}
|
|
77
|
-
return
|
|
90
|
+
return base;
|
|
78
91
|
};
|
|
79
92
|
|
|
80
93
|
const closeModalAndSetValue = async (isSaving, values, toastMessage) => {
|
|
81
94
|
if (toastMessage) {
|
|
82
|
-
addToast(toastMessage, {
|
|
83
|
-
|
|
84
|
-
|
|
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()
|
|
85
114
|
});
|
|
115
|
+
if (refreshedFile) {
|
|
116
|
+
setFormValues(refreshedFile);
|
|
117
|
+
onChange(refreshedFile);
|
|
118
|
+
handleSaveButtonStatus(true);
|
|
119
|
+
}
|
|
86
120
|
}
|
|
87
|
-
await refetchFile({
|
|
88
|
-
id: fileId,
|
|
89
|
-
timestamp: Date.now()
|
|
90
|
-
});
|
|
91
|
-
setDisplayFileUploadModal(false);
|
|
92
|
-
};
|
|
93
121
|
|
|
94
|
-
|
|
95
|
-
setDisplayFileUploadModal(true);
|
|
122
|
+
setDisplayFileUploadModal(false);
|
|
96
123
|
};
|
|
97
124
|
|
|
98
125
|
if (loading) return <div>loading...</div>;
|
|
99
126
|
|
|
100
|
-
const
|
|
127
|
+
const fileToRender = formValues || file;
|
|
128
|
+
const fileWithStoreType = getFileWithStoreType(fileToRender);
|
|
101
129
|
|
|
102
|
-
return (
|
|
130
|
+
return !loading ? (
|
|
103
131
|
<>
|
|
104
132
|
{!!file && (
|
|
105
133
|
<FilePreview
|
|
106
134
|
file={fileWithStoreType}
|
|
107
135
|
handleFormChange={handleFormChange}
|
|
108
|
-
handleChangeFile={
|
|
136
|
+
handleChangeFile={() => setDisplayFileUploadModal(true)}
|
|
109
137
|
displayForm
|
|
110
138
|
showChangeButton={showChangeButton}
|
|
111
139
|
/>
|
|
@@ -113,17 +141,18 @@ const EditMediaFile = ({
|
|
|
113
141
|
{displayFileUploadModal && (
|
|
114
142
|
<div className="file-upload-modal-wrapper">
|
|
115
143
|
<FileUploadModal
|
|
116
|
-
onClose={() =>
|
|
117
|
-
setDisplayFileUploadModal(false);
|
|
118
|
-
}}
|
|
144
|
+
onClose={() => setDisplayFileUploadModal(false)}
|
|
119
145
|
closeModalAndSetValue={closeModalAndSetValue}
|
|
120
146
|
simpleLayout
|
|
121
147
|
fileId={fileId}
|
|
148
|
+
storeKey={file && file.storeKey}
|
|
122
149
|
getSelectedFiles={() => {}}
|
|
123
150
|
/>
|
|
124
151
|
</div>
|
|
125
152
|
)}
|
|
126
153
|
</>
|
|
154
|
+
) : (
|
|
155
|
+
<div>loading...</div>
|
|
127
156
|
);
|
|
128
157
|
};
|
|
129
158
|
|
|
@@ -131,13 +160,13 @@ EditMediaFile.propTypes = {
|
|
|
131
160
|
fileId: PropTypes.string.isRequired,
|
|
132
161
|
onChange: PropTypes.func.isRequired,
|
|
133
162
|
handleSaveButtonStatus: PropTypes.func.isRequired,
|
|
134
|
-
|
|
135
|
-
|
|
163
|
+
showChangeButton: PropTypes.bool,
|
|
164
|
+
fileUpdated: PropTypes.object
|
|
136
165
|
};
|
|
137
166
|
|
|
138
167
|
EditMediaFile.defaultProps = {
|
|
139
|
-
|
|
140
|
-
|
|
168
|
+
showChangeButton: false,
|
|
169
|
+
fileUpdated: null
|
|
141
170
|
};
|
|
142
171
|
|
|
143
172
|
export default EditMediaFile;
|
|
@@ -20,24 +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: {
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
43
|
+
variables: {
|
|
44
|
+
input: inputData
|
|
45
|
+
},
|
|
46
|
+
update(cache, { data: { updateFile: fileUpdated } }) {
|
|
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
|
|
31
55
|
}
|
|
32
|
-
) {
|
|
33
|
-
cache.writeQuery({
|
|
34
|
-
query: getQuery('GET_FILE_BY_ID'),
|
|
35
|
-
variables: { id: match.params.fileId },
|
|
36
|
-
data: { file: fileUpdated.result }
|
|
37
|
-
});
|
|
38
56
|
}
|
|
39
57
|
});
|
|
40
58
|
|
|
59
|
+
setFile(updatedFile.result);
|
|
60
|
+
|
|
41
61
|
addToast(`File: ${file.name} has been updated`, {
|
|
42
62
|
appearance: 'success',
|
|
43
63
|
autoDismiss: true
|
|
@@ -47,7 +67,6 @@ const EditMediaFilePage = ({ match, history }) => {
|
|
|
47
67
|
appearance: 'error',
|
|
48
68
|
autoDismiss: true
|
|
49
69
|
});
|
|
50
|
-
console.error(e); //eslint-disable-line
|
|
51
70
|
}
|
|
52
71
|
setShouldEnableSaveButton(false);
|
|
53
72
|
};
|
|
@@ -66,6 +85,7 @@ const EditMediaFilePage = ({ match, history }) => {
|
|
|
66
85
|
handleSaveButtonStatus={handleSaveButtonStatus}
|
|
67
86
|
handleFormSave={handleFormSave}
|
|
68
87
|
showChangeButton
|
|
88
|
+
fileUpdated={file}
|
|
69
89
|
/>
|
|
70
90
|
<div className="page__content__mediaWrapperActions">
|
|
71
91
|
<Button onClick={pushBack}>Cancel</Button>
|
|
@@ -1,16 +1,41 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import DraftEditor from '@blaze-react/drafteditor';
|
|
3
3
|
import PropTypes from 'prop-types';
|
|
4
|
+
import Tooltip from '@blaze-react/tooltip';
|
|
4
5
|
|
|
5
|
-
const
|
|
6
|
+
const customStyleMap = {
|
|
7
|
+
SUPERSCRIPT: {
|
|
8
|
+
fontSize: '0.75em',
|
|
9
|
+
verticalAlign: 'super'
|
|
10
|
+
},
|
|
11
|
+
SUBSCRIPT: {
|
|
12
|
+
fontSize: '0.75em',
|
|
13
|
+
verticalAlign: 'sub'
|
|
14
|
+
}
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
const DraftEditorAdapter = ({
|
|
18
|
+
id,
|
|
19
|
+
value,
|
|
20
|
+
onChange,
|
|
21
|
+
error,
|
|
22
|
+
validationMessage,
|
|
23
|
+
label,
|
|
24
|
+
tooltip,
|
|
25
|
+
...props
|
|
26
|
+
}) => (
|
|
6
27
|
<div className="form-field form-field--full-width">
|
|
7
|
-
<label>
|
|
28
|
+
<label>
|
|
29
|
+
<Tooltip tooltipContent={tooltip} />
|
|
30
|
+
</label>
|
|
8
31
|
<DraftEditor
|
|
9
32
|
name={id}
|
|
10
33
|
value={value}
|
|
11
34
|
onChange={onChange}
|
|
12
35
|
error={error}
|
|
13
36
|
validationMessage={validationMessage}
|
|
37
|
+
tooltip={{ tooltipContent: tooltip }}
|
|
38
|
+
customStyleMap={customStyleMap}
|
|
14
39
|
/>
|
|
15
40
|
</div>
|
|
16
41
|
);
|
|
@@ -21,12 +46,14 @@ DraftEditorAdapter.propTypes = {
|
|
|
21
46
|
onChange: PropTypes.func.isRequired,
|
|
22
47
|
error: PropTypes.bool,
|
|
23
48
|
validationMessage: PropTypes.string,
|
|
24
|
-
label: PropTypes.string.isRequired
|
|
49
|
+
label: PropTypes.string.isRequired,
|
|
50
|
+
tooltip: PropTypes.string
|
|
25
51
|
};
|
|
26
52
|
|
|
27
53
|
DraftEditorAdapter.defaultProps = {
|
|
28
54
|
error: false,
|
|
29
|
-
validationMessage: undefined
|
|
55
|
+
validationMessage: undefined,
|
|
56
|
+
tooltip: ''
|
|
30
57
|
};
|
|
31
58
|
|
|
32
59
|
export default DraftEditorAdapter;
|
|
@@ -20,19 +20,16 @@ function useGetFilesList() {
|
|
|
20
20
|
const [allFilesCounter, setAllFilesCounter] = useState({ all: 0, text: 0, image: 0, video: 0 });
|
|
21
21
|
const [counters, setCounters] = useState(null);
|
|
22
22
|
|
|
23
|
-
useEffect(
|
|
24
|
-
()
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
},
|
|
34
|
-
[all, image, video, text]
|
|
35
|
-
);
|
|
23
|
+
useEffect(() => {
|
|
24
|
+
if (all && image && video && text) {
|
|
25
|
+
setCounters({
|
|
26
|
+
all: all.total,
|
|
27
|
+
image: image.total,
|
|
28
|
+
video: video.total,
|
|
29
|
+
text: text.total
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
}, [all, image, video, text]);
|
|
36
33
|
|
|
37
34
|
useEffect(
|
|
38
35
|
() => {
|
|
@@ -102,7 +99,11 @@ function useGetFilesList() {
|
|
|
102
99
|
};
|
|
103
100
|
|
|
104
101
|
const addNewFile = newFiles => {
|
|
105
|
-
const {
|
|
102
|
+
const {
|
|
103
|
+
image: _image,
|
|
104
|
+
video: _video,
|
|
105
|
+
text: _text
|
|
106
|
+
} = newFiles.reduce(
|
|
106
107
|
(acc, { type }) => {
|
|
107
108
|
acc[type] += 1;
|
|
108
109
|
return acc;
|
|
@@ -7,34 +7,32 @@ const Actions = ({ file }) => {
|
|
|
7
7
|
const [, extension] = file.mimetype.split('/');
|
|
8
8
|
|
|
9
9
|
return (
|
|
10
|
-
|
|
11
|
-
<div className="FilePreviewItem__info__actions">
|
|
12
|
-
<
|
|
13
|
-
|
|
14
|
-
<span>{extension}</span>
|
|
15
|
-
</div>
|
|
16
|
-
<div>
|
|
17
|
-
{handleEditModal && (
|
|
18
|
-
<div
|
|
19
|
-
data-testid={`open-media-library-${file.id}`}
|
|
20
|
-
className="FilePreviewItem__info__actionsIcon material-icons edit"
|
|
21
|
-
aria-hidden="true"
|
|
22
|
-
onClick={() => handleEditModal(file)}>
|
|
23
|
-
<i className="fas fa-pen fa-xs" />
|
|
24
|
-
</div>
|
|
25
|
-
)}
|
|
26
|
-
{onUnselectFile && (
|
|
27
|
-
<div
|
|
28
|
-
data-testid={`unselect-${file.id}`}
|
|
29
|
-
className="FilePreviewItem__info__actionsIcon material-icons delete"
|
|
30
|
-
aria-hidden="true"
|
|
31
|
-
onClick={() => onUnselectFile([file.id])}>
|
|
32
|
-
<i className="fas fa-trash fa-xs" />
|
|
33
|
-
</div>
|
|
34
|
-
)}
|
|
35
|
-
</div>
|
|
10
|
+
<div className="FilePreviewItem__info__actions">
|
|
11
|
+
<div className="FilePreviewItem__info__actions FilePreviewItem__info__actions--media-type">
|
|
12
|
+
<i className="FilePreviewItem__info__actionsIcon material-icons">insert_photo</i>{' '}
|
|
13
|
+
<span>{extension}</span>
|
|
36
14
|
</div>
|
|
37
|
-
|
|
15
|
+
<div>
|
|
16
|
+
{handleEditModal && (
|
|
17
|
+
<div
|
|
18
|
+
data-testid={`open-media-library-${file.id}`}
|
|
19
|
+
className="FilePreviewItem__info__actionsIcon material-icons edit"
|
|
20
|
+
aria-hidden="true"
|
|
21
|
+
onClick={() => handleEditModal(file)}>
|
|
22
|
+
<i className="fas fa-pen fa-xs" />
|
|
23
|
+
</div>
|
|
24
|
+
)}
|
|
25
|
+
{onUnselectFile && (
|
|
26
|
+
<div
|
|
27
|
+
data-testid={`unselect-${file.id}`}
|
|
28
|
+
className="FilePreviewItem__info__actionsIcon material-icons delete"
|
|
29
|
+
aria-hidden="true"
|
|
30
|
+
onClick={() => onUnselectFile([file.id])}>
|
|
31
|
+
<i className="fas fa-trash fa-xs" />
|
|
32
|
+
</div>
|
|
33
|
+
)}
|
|
34
|
+
</div>
|
|
35
|
+
</div>
|
|
38
36
|
);
|
|
39
37
|
};
|
|
40
38
|
|
|
@@ -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 };
|
|
@@ -3,9 +3,7 @@ import PropTypes from 'prop-types';
|
|
|
3
3
|
import FilePreviewList from './FilePreviewList';
|
|
4
4
|
|
|
5
5
|
const FileList = ({ selectedFiles, children }) => (
|
|
6
|
-
|
|
7
|
-
<FilePreviewList selectedFiles={selectedFiles}>{children}</FilePreviewList>
|
|
8
|
-
</>
|
|
6
|
+
<FilePreviewList selectedFiles={selectedFiles}>{children}</FilePreviewList>
|
|
9
7
|
);
|
|
10
8
|
|
|
11
9
|
FileList.propTypes = {
|
|
@@ -11,49 +11,37 @@ const FilePreviewReadOnly = ({ label, id, type, value }) => {
|
|
|
11
11
|
const client = useApolloClient();
|
|
12
12
|
|
|
13
13
|
const getFiles = async (offset, ids) => {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
} = await client.query({
|
|
14
|
+
if (!ids.length) return [];
|
|
15
|
+
const { data: { files = [] } = {} } = await client.query({
|
|
17
16
|
query: getQuery('GET_FILES'),
|
|
18
17
|
variables: {
|
|
19
18
|
offset,
|
|
20
19
|
where: {
|
|
21
|
-
id: {
|
|
22
|
-
_in: ids
|
|
23
|
-
}
|
|
20
|
+
id: { _in: ids }
|
|
24
21
|
}
|
|
25
22
|
},
|
|
26
|
-
skip: !initialValue.length,
|
|
27
23
|
fetchPolicy: 'network-only'
|
|
28
24
|
});
|
|
29
|
-
return
|
|
25
|
+
return files;
|
|
30
26
|
};
|
|
31
27
|
|
|
32
|
-
useEffect(
|
|
33
|
-
() => {
|
|
34
|
-
(async () => {
|
|
35
|
-
const files = await getFiles(0, initialValue);
|
|
36
|
-
const orderedFiles = orderFiles(files, initialValue);
|
|
37
|
-
setSelectedFiles(orderedFiles);
|
|
38
|
-
})();
|
|
39
|
-
},
|
|
40
|
-
[] //eslint-disable-line
|
|
41
|
-
);
|
|
42
|
-
|
|
43
28
|
const orderFiles = (files, ids) =>
|
|
44
29
|
ids.map(currentId => files.find(({ id: fileId }) => fileId === currentId)).filter(Boolean);
|
|
45
30
|
|
|
31
|
+
useEffect(() => {
|
|
32
|
+
(async () => {
|
|
33
|
+
const files = await getFiles(0, initialValue);
|
|
34
|
+
const orderedFiles = orderFiles(files, initialValue);
|
|
35
|
+
setSelectedFiles(orderedFiles);
|
|
36
|
+
})();
|
|
37
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
38
|
+
}, []);
|
|
39
|
+
|
|
46
40
|
return (
|
|
47
|
-
|
|
48
|
-
<
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
<>
|
|
52
|
-
<FileList selectedFiles={selectedFiles} />
|
|
53
|
-
</>
|
|
54
|
-
)}
|
|
55
|
-
</div>
|
|
56
|
-
</>
|
|
41
|
+
<div className="form-field form-field--button">
|
|
42
|
+
<label htmlFor={id}>{label}</label>
|
|
43
|
+
{selectedFiles.length > 0 && <FileList selectedFiles={selectedFiles} />}
|
|
44
|
+
</div>
|
|
57
45
|
);
|
|
58
46
|
};
|
|
59
47
|
|