@blaze-cms/plugin-media-ui 0.146.0-node18.1 → 0.146.0-rc-eagle-3.0
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 +13 -12
- package/lib/components/CardMedia/CardMedia.js +235 -244
- 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 +149 -115
- package/lib/components/EditMediaFile/EditMediaFile.js.map +1 -1
- package/lib/components/EditMediaFile/EditMediaFilePage.js +89 -97
- 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 +167 -185
- 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 +93 -133
- 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 +92 -110
- package/lib/components/FileList/useGetFilesList/useGetFilesList.js.map +1 -1
- package/lib/components/FilePreview/Actions/index.js +25 -38
- package/lib/components/FilePreview/Actions/index.js.map +1 -1
- package/lib/components/FilePreview/Image/Image.js +35 -24
- 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 +10 -7
- 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 +9 -0
- package/lib/components/FilePreview/ModalContext.js.map +1 -0
- 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 +3 -3
- 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 +111 -58
- 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 -27
- 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 +3 -3
- 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 -20
- package/lib/components/FilePreviewReadOnly/FilePreviewList.js.map +1 -1
- package/lib/components/FilePreviewReadOnly/FilePreviewReadOnly.js +53 -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 +27 -39
- package/lib/components/FileUploadAdapter/FileList.js.map +1 -1
- package/lib/components/FileUploadAdapter/FilePreviewList.js +14 -20
- 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 +253 -341
- 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 -6
- 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 +6 -5
- 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 +215 -146
- 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 +49 -151
- package/lib/components/FilterPanel/FilterPanel.js.map +1 -1
- package/lib/components/FilterPanel/MediaSearchFilter.js +41 -0
- package/lib/components/FilterPanel/MediaSearchFilter.js.map +1 -0
- package/lib/components/FilterPanel/index.js +2 -3
- package/lib/components/FilterPanel/index.js.map +1 -1
- package/lib/components/ListingContainer/Listing/Listing.js +58 -48
- package/lib/components/ListingContainer/Listing/Listing.js.map +1 -1
- package/lib/components/ListingContainer/Listing/MediaListing/MediaFileList/MediaFileList.js +83 -96
- 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 +23 -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 +74 -93
- 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 +15 -26
- package/lib/components/MediaListing.js.map +1 -1
- package/lib/constants.js +17 -17
- 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 +109 -52
- package/lib-es/components/CardMedia/CardMedia.js.map +1 -1
- package/lib-es/components/EditMediaFile/EditMediaFile.js +109 -53
- package/lib-es/components/EditMediaFile/EditMediaFile.js.map +1 -1
- package/lib-es/components/EditMediaFile/EditMediaFilePage.js +45 -15
- 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 +6 -3
- package/lib-es/components/FileList/useGetFiles/getFiles.js.map +1 -1
- package/lib-es/components/FileList/useGetFiles/useGetFiles.js +7 -2
- package/lib-es/components/FileList/useGetFiles/useGetFiles.js.map +1 -1
- package/lib-es/components/FileList/useGetFilesList/useGetFilesList.js +4 -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/Image/Image.js +16 -3
- package/lib-es/components/FilePreview/Image/Image.js.map +1 -1
- package/lib-es/components/FilePreview/Image/imageSchema.js +9 -5
- package/lib-es/components/FilePreview/Image/imageSchema.js.map +1 -1
- package/lib-es/components/FilePreview/ModalContext.js +3 -0
- package/lib-es/components/FilePreview/ModalContext.js.map +1 -0
- 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/PDF/schema.js +2 -1
- package/lib-es/components/FilePreview/PDF/schema.js.map +1 -1
- package/lib-es/components/FilePreview/index.js +72 -9
- 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/FilePreview/previewDefault/RawPreviewDefault.js +12 -4
- package/lib-es/components/FilePreview/previewDefault/RawPreviewDefault.js.map +1 -1
- package/lib-es/components/FilePreview/previewDefault/previewDefaultSchema.js +2 -1
- package/lib-es/components/FilePreview/previewDefault/previewDefaultSchema.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/FileUploadAdapter.js +78 -43
- package/lib-es/components/FileUploadAdapter/FileUploadAdapter.js.map +1 -1
- package/lib-es/components/FileUploadAdapter/mappers/get-button-text.js +5 -3
- package/lib-es/components/FileUploadAdapter/mappers/get-button-text.js.map +1 -1
- package/lib-es/components/FileUploadAdapter/mappers/get-number-files-pending-to-fetch.js +5 -4
- package/lib-es/components/FileUploadAdapter/mappers/get-number-files-pending-to-fetch.js.map +1 -1
- package/lib-es/components/FileUploadModal/FileUploadModal.js +157 -29
- package/lib-es/components/FileUploadModal/FileUploadModal.js.map +1 -1
- package/lib-es/components/FilterPanel/FilterPanel.js +43 -123
- package/lib-es/components/FilterPanel/FilterPanel.js.map +1 -1
- package/lib-es/components/FilterPanel/MediaSearchFilter.js +34 -0
- package/lib-es/components/FilterPanel/MediaSearchFilter.js.map +1 -0
- package/lib-es/components/ListingContainer/Listing/Listing.js +17 -5
- package/lib-es/components/ListingContainer/Listing/Listing.js.map +1 -1
- package/lib-es/components/ListingContainer/Listing/MediaListing/MediaFileList/MediaFileList.js +21 -10
- package/lib-es/components/ListingContainer/Listing/MediaListing/MediaFileList/MediaFileList.js.map +1 -1
- package/lib-es/components/ListingContainer/Listing/MediaListing/MediaListing.js +12 -3
- package/lib-es/components/ListingContainer/Listing/MediaListing/MediaListing.js.map +1 -1
- package/lib-es/components/ListingContainer/ListingContainer.js +18 -6
- package/lib-es/components/ListingContainer/ListingContainer.js.map +1 -1
- package/lib-es/constants.js +3 -2
- package/lib-es/constants.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 +20 -13
- package/src/components/CardMedia/CardMedia.js +131 -82
- package/src/components/EditMediaFile/EditMediaFile.js +123 -46
- package/src/components/EditMediaFile/EditMediaFilePage.js +41 -10
- package/src/components/EditorAdapter/EditorAdapter.js +31 -4
- package/src/components/FileList/useGetFiles/getFiles.js +12 -4
- package/src/components/FileList/useGetFiles/useGetFiles.js +3 -4
- package/src/components/FileList/useGetFilesList/useGetFilesList.js +2 -1
- package/src/components/FilePreview/Actions/index.js +25 -27
- package/src/components/FilePreview/Image/Image.js +15 -2
- package/src/components/FilePreview/Image/imageSchema.js +9 -5
- package/src/components/FilePreview/ModalContext.js +3 -0
- package/src/components/FilePreview/PDF/PDF.js +17 -4
- package/src/components/FilePreview/PDF/schema.js +2 -1
- package/src/components/FilePreview/index.js +69 -6
- package/src/components/FilePreview/previewDefault/PreviewDefault.js +16 -3
- package/src/components/FilePreview/previewDefault/RawPreviewDefault.js +17 -7
- package/src/components/FilePreview/previewDefault/previewDefaultSchema.js +2 -1
- package/src/components/FilePreviewReadOnly/FileList.js +1 -3
- package/src/components/FilePreviewReadOnly/FilePreviewReadOnly.js +17 -29
- package/src/components/FileUploadAdapter/FileUploadAdapter.js +66 -32
- package/src/components/FileUploadAdapter/mappers/get-button-text.js +4 -3
- package/src/components/FileUploadAdapter/mappers/get-number-files-pending-to-fetch.js +6 -4
- package/src/components/FileUploadModal/FileUploadModal.js +156 -45
- package/src/components/FilterPanel/FilterPanel.js +44 -129
- package/src/components/FilterPanel/MediaSearchFilter.js +32 -0
- package/src/components/ListingContainer/Listing/Listing.js +15 -5
- package/src/components/ListingContainer/Listing/MediaListing/MediaFileList/MediaFileList.js +18 -7
- package/src/components/ListingContainer/Listing/MediaListing/MediaListing.js +10 -2
- package/src/components/ListingContainer/ListingContainer.js +17 -5
- package/src/constants.js +16 -2
- package/src/index.js +17 -14
- package/src/utils/bustUrl.js +6 -0
- package/babel.config.js +0 -3
- package/jest.config.js +0 -5
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import React, { useState, useContext, useEffect } from 'react';
|
|
2
2
|
import FileUpload from '@blaze-react/file-upload';
|
|
3
3
|
import PropTypes from 'prop-types';
|
|
4
|
-
import { useApolloClient } from '@apollo/client';
|
|
4
|
+
import { useApolloClient, useQuery } from '@apollo/client';
|
|
5
5
|
import { getQuery, getMutation, ModalAdapter as Modal } from '@blaze-cms/admin-ui-utils';
|
|
6
|
-
import { parseFormValues } from '@blaze-cms/react-form-builder';
|
|
7
6
|
import { useToasts } from '@blaze-react/toaster';
|
|
7
|
+
import Tooltip from '@blaze-react/tooltip';
|
|
8
8
|
import { MORE } from '../../constants';
|
|
9
9
|
import ListingContainer from '../ListingContainer';
|
|
10
10
|
import { MediaContextProvider } from '../../utils/media-context';
|
|
@@ -30,7 +30,11 @@ const FileUploadAdapter = ({
|
|
|
30
30
|
shouldRenderInPreview,
|
|
31
31
|
canDragAndDrop,
|
|
32
32
|
simpleLayout,
|
|
33
|
-
|
|
33
|
+
tooltip,
|
|
34
|
+
previewAllFiles,
|
|
35
|
+
disableFilePreview,
|
|
36
|
+
fileType,
|
|
37
|
+
storeKey
|
|
34
38
|
}) => {
|
|
35
39
|
const { InjectPreview } = useContext(FileUploadAdapter.FormContext);
|
|
36
40
|
const [currentLimit] = useLimit(maxItems);
|
|
@@ -38,12 +42,19 @@ const FileUploadAdapter = ({
|
|
|
38
42
|
const [displayFileUploadModal, setDisplayFileUploadModal] = useState(false);
|
|
39
43
|
const initialValue = formatInitialValue({ value, type });
|
|
40
44
|
const [currentValue, setCurrentValue] = useState(initialValue);
|
|
41
|
-
const [currentOffset, setCurrentOffset] = useState(0);
|
|
42
45
|
const [selectedFiles, setSelectedFiles] = useState([]);
|
|
43
46
|
const [editFile, setEditFile] = useState(null);
|
|
47
|
+
const [allFilesLoaded, setAllFilesLoaded] = useState(false);
|
|
44
48
|
const client = useApolloClient();
|
|
45
49
|
const { addToast } = useToasts();
|
|
46
50
|
|
|
51
|
+
const { data: { getEntitySchemas: [schemaData] = [] } = {} } = useQuery(
|
|
52
|
+
getQuery('GET_ENTITY_SCHEMA'),
|
|
53
|
+
{
|
|
54
|
+
variables: { identifier: 'file' }
|
|
55
|
+
}
|
|
56
|
+
);
|
|
57
|
+
|
|
47
58
|
const getFiles = async (offset, ids, fetchAll = previewAllFiles) => {
|
|
48
59
|
const {
|
|
49
60
|
data: { files: newFiles }
|
|
@@ -67,6 +78,13 @@ const FileUploadAdapter = ({
|
|
|
67
78
|
useEffect(
|
|
68
79
|
() => {
|
|
69
80
|
(async () => {
|
|
81
|
+
if (allFilesLoaded) {
|
|
82
|
+
const loadedFiles = await getFiles(0, currentValue, true);
|
|
83
|
+
const loadedOrderedFiles = orderFiles(loadedFiles, currentValue);
|
|
84
|
+
setSelectedFiles(loadedOrderedFiles);
|
|
85
|
+
return;
|
|
86
|
+
}
|
|
87
|
+
|
|
70
88
|
const initialFiles =
|
|
71
89
|
!selectedFiles.length && !previewAllFiles
|
|
72
90
|
? currentValue.filter((_, i) => i <= 3)
|
|
@@ -74,8 +92,8 @@ const FileUploadAdapter = ({
|
|
|
74
92
|
|
|
75
93
|
const files = await getFiles(0, initialFiles);
|
|
76
94
|
const orderedFiles = orderFiles(files, currentValue);
|
|
77
|
-
setCurrentOffset(0);
|
|
78
95
|
setSelectedFiles(orderedFiles);
|
|
96
|
+
setAllFilesLoaded(false);
|
|
79
97
|
})();
|
|
80
98
|
},
|
|
81
99
|
[currentValue] //eslint-disable-line
|
|
@@ -83,14 +101,10 @@ const FileUploadAdapter = ({
|
|
|
83
101
|
|
|
84
102
|
const fetchMore = async shouldFetchAll => {
|
|
85
103
|
if (selectedFiles.length === currentValue.length) return;
|
|
86
|
-
const
|
|
87
|
-
const
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
const newFiles = [...selectedFiles, ...files];
|
|
91
|
-
const orderedFiles = orderFiles(newFiles, currentValue);
|
|
92
|
-
setSelectedFiles(orderedFiles);
|
|
93
|
-
setCurrentOffset(newOffset);
|
|
104
|
+
const newFiles = await getFiles(0, currentValue, true);
|
|
105
|
+
const newOrderedFiles = orderFiles(newFiles, currentValue);
|
|
106
|
+
setSelectedFiles(newOrderedFiles);
|
|
107
|
+
setAllFilesLoaded(true);
|
|
94
108
|
};
|
|
95
109
|
|
|
96
110
|
const handleSelectedFiles = (files, checkIsUnselecting = true) => {
|
|
@@ -155,11 +169,11 @@ const FileUploadAdapter = ({
|
|
|
155
169
|
setDisplayModal(false);
|
|
156
170
|
};
|
|
157
171
|
|
|
158
|
-
const fileUploadButtonText = getButtonText({ maxItems, value: initialValue });
|
|
172
|
+
const fileUploadButtonText = getButtonText({ maxItems, value: initialValue, fileType });
|
|
159
173
|
|
|
160
174
|
const filesPending = previewAllFiles
|
|
161
175
|
? 0
|
|
162
|
-
: getNumberFilesPendingToFetch(
|
|
176
|
+
: getNumberFilesPendingToFetch(selectedFiles.length, currentValue);
|
|
163
177
|
const onOpenLibrary = () => setDisplayModal(true);
|
|
164
178
|
const handleEditModal = file => {
|
|
165
179
|
const selectedEditFile = selectedFiles.find(({ id: _id }) => _id === file.id);
|
|
@@ -167,18 +181,22 @@ const FileUploadAdapter = ({
|
|
|
167
181
|
};
|
|
168
182
|
|
|
169
183
|
const handleEditFileForm = editedFile => {
|
|
170
|
-
const
|
|
184
|
+
const dataValues = editedFile.valuesChecked.reduce(
|
|
185
|
+
(acc, { id: formValueId, value: formValue, isDataPropery }) => {
|
|
186
|
+
if (isDataPropery) {
|
|
187
|
+
acc.data[formValueId] = formValue;
|
|
188
|
+
} else {
|
|
189
|
+
acc[formValueId] = formValue;
|
|
190
|
+
}
|
|
191
|
+
return acc;
|
|
192
|
+
},
|
|
193
|
+
{ id: editFile.id, data: { ...editFile.data } }
|
|
194
|
+
);
|
|
195
|
+
delete dataValues.data.__typename; // Remove __typename if it exists in data to avoid issues with Apollo cache.
|
|
171
196
|
|
|
172
|
-
const { altText, caption, credits, hrefUrl, name } = values;
|
|
173
197
|
setEditFile({
|
|
174
198
|
...editFile,
|
|
175
|
-
|
|
176
|
-
data: {
|
|
177
|
-
altText,
|
|
178
|
-
caption,
|
|
179
|
-
credits,
|
|
180
|
-
hrefUrl
|
|
181
|
-
}
|
|
199
|
+
formData: dataValues
|
|
182
200
|
});
|
|
183
201
|
};
|
|
184
202
|
|
|
@@ -194,7 +212,7 @@ const FileUploadAdapter = ({
|
|
|
194
212
|
modifiers: ['cancel']
|
|
195
213
|
},
|
|
196
214
|
{
|
|
197
|
-
textButton: '
|
|
215
|
+
textButton: 'Apply',
|
|
198
216
|
callback: () => {
|
|
199
217
|
closeModalAndSetValue(true);
|
|
200
218
|
},
|
|
@@ -211,9 +229,9 @@ const FileUploadAdapter = ({
|
|
|
211
229
|
modifiers: ['cancel']
|
|
212
230
|
},
|
|
213
231
|
{
|
|
214
|
-
textButton: '
|
|
232
|
+
textButton: 'Apply',
|
|
215
233
|
callback: async () => {
|
|
216
|
-
const { name, id: editedFileId, data } = editFile;
|
|
234
|
+
const { name, id: editedFileId, data, formData } = editFile;
|
|
217
235
|
const updatedSelectedFiles = selectedFiles.map(selectedFile => {
|
|
218
236
|
if (selectedFile.id === editedFileId) {
|
|
219
237
|
return { ...selectedFile, name, data };
|
|
@@ -227,8 +245,7 @@ const FileUploadAdapter = ({
|
|
|
227
245
|
mutation: getMutation('UPDATE_FILE'),
|
|
228
246
|
variables: {
|
|
229
247
|
input: {
|
|
230
|
-
|
|
231
|
-
data,
|
|
248
|
+
...formData,
|
|
232
249
|
id: editedFileId
|
|
233
250
|
}
|
|
234
251
|
},
|
|
@@ -269,7 +286,9 @@ const FileUploadAdapter = ({
|
|
|
269
286
|
return (
|
|
270
287
|
<>
|
|
271
288
|
<div className="form-field form-field--button">
|
|
272
|
-
<label>
|
|
289
|
+
<label>
|
|
290
|
+
{label} <Tooltip tooltipContent={tooltip} />
|
|
291
|
+
</label>
|
|
273
292
|
{selectedFiles && (
|
|
274
293
|
<MediaContextProvider value={{ handleEditModal, onUnselectFile: handleSelectedFiles }}>
|
|
275
294
|
{shouldRenderInPreview ? (
|
|
@@ -294,6 +313,7 @@ const FileUploadAdapter = ({
|
|
|
294
313
|
)}
|
|
295
314
|
<FileUpload
|
|
296
315
|
actionText={fileUploadButtonText}
|
|
316
|
+
storeKey={storeKey}
|
|
297
317
|
handleLibraryClick={() => {
|
|
298
318
|
if (simpleLayout) {
|
|
299
319
|
setDisplayFileUploadModal(true);
|
|
@@ -312,6 +332,8 @@ const FileUploadAdapter = ({
|
|
|
312
332
|
handleFormChange={handleEditFileForm}
|
|
313
333
|
displayForm
|
|
314
334
|
previewType="card"
|
|
335
|
+
disableFilePreview={disableFilePreview}
|
|
336
|
+
schemaData={schemaData}
|
|
315
337
|
/>
|
|
316
338
|
</Modal>
|
|
317
339
|
)}
|
|
@@ -326,6 +348,8 @@ const FileUploadAdapter = ({
|
|
|
326
348
|
maxItems={currentLimit}
|
|
327
349
|
simpleLayout={simpleLayout}
|
|
328
350
|
filesSelected={currentValue.length > 1 ? currentValue : []}
|
|
351
|
+
openEditInModal
|
|
352
|
+
storeKey={storeKey}
|
|
329
353
|
/>
|
|
330
354
|
</div>
|
|
331
355
|
)}
|
|
@@ -344,6 +368,8 @@ const FileUploadAdapter = ({
|
|
|
344
368
|
handleSelectedFiles={handleSelectedFiles}
|
|
345
369
|
maxItems={currentLimit}
|
|
346
370
|
filesSelected={currentValue.length > 1 ? currentValue : []}
|
|
371
|
+
openEditInModal
|
|
372
|
+
storeKey={storeKey}
|
|
347
373
|
/>
|
|
348
374
|
</Modal>
|
|
349
375
|
</div>
|
|
@@ -362,7 +388,11 @@ FileUploadAdapter.propTypes = {
|
|
|
362
388
|
shouldRenderInPreview: PropTypes.bool,
|
|
363
389
|
canDragAndDrop: PropTypes.bool,
|
|
364
390
|
simpleLayout: PropTypes.bool,
|
|
365
|
-
previewAllFiles: PropTypes.bool
|
|
391
|
+
previewAllFiles: PropTypes.bool,
|
|
392
|
+
tooltip: PropTypes.string,
|
|
393
|
+
fileType: PropTypes.string,
|
|
394
|
+
disableFilePreview: PropTypes.bool,
|
|
395
|
+
storeKey: PropTypes.string
|
|
366
396
|
};
|
|
367
397
|
|
|
368
398
|
FileUploadAdapter.defaultProps = {
|
|
@@ -371,7 +401,11 @@ FileUploadAdapter.defaultProps = {
|
|
|
371
401
|
shouldRenderInPreview: false,
|
|
372
402
|
canDragAndDrop: false,
|
|
373
403
|
simpleLayout: false,
|
|
374
|
-
previewAllFiles: false
|
|
404
|
+
previewAllFiles: false,
|
|
405
|
+
tooltip: '',
|
|
406
|
+
fileType: 'file',
|
|
407
|
+
disableFilePreview: true,
|
|
408
|
+
storeKey: null
|
|
375
409
|
};
|
|
376
410
|
|
|
377
411
|
export default FileUploadAdapter;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
const getButtonText = ({ maxItems, value }) => {
|
|
2
|
-
const
|
|
3
|
-
|
|
1
|
+
const getButtonText = ({ maxItems, value, fileType = 'file' }) => {
|
|
2
|
+
const pluralSuffix = maxItems > 1 ? 's' : '';
|
|
3
|
+
const fileLabel = `Add ${fileType}${pluralSuffix}`;
|
|
4
|
+
return value && value.length > 0 ? `Change ${fileType}${pluralSuffix}` : fileLabel;
|
|
4
5
|
};
|
|
5
6
|
|
|
6
7
|
export { getButtonText };
|
|
@@ -1,5 +1,7 @@
|
|
|
1
|
-
export const getNumberFilesPendingToFetch = (
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
export const getNumberFilesPendingToFetch = (loadedFilesCount, currentValue) => {
|
|
2
|
+
if (loadedFilesCount >= currentValue.length) {
|
|
3
|
+
return 0;
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
return currentValue.length - loadedFilesCount;
|
|
5
7
|
};
|
|
@@ -1,62 +1,163 @@
|
|
|
1
|
-
import React, { useState } from 'react';
|
|
1
|
+
import React, { useState, useMemo } from 'react';
|
|
2
2
|
import { ModalAdapter as Modal, getMutation, getQuery } from '@blaze-cms/admin-ui-utils';
|
|
3
3
|
import FileUpload from '@blaze-react/file-upload';
|
|
4
|
+
import { getFormBuilderLookup } from '@blaze-cms/react-form-builder';
|
|
4
5
|
import PropTypes from 'prop-types';
|
|
5
6
|
import { useToasts } from '@blaze-react/toaster';
|
|
6
7
|
import { useApolloClient, useQuery } from '@apollo/client';
|
|
7
8
|
import useFileList from '../FileList/useFileList';
|
|
8
9
|
|
|
9
|
-
const FileUploadModal = ({
|
|
10
|
+
const FileUploadModal = ({
|
|
11
|
+
onClose,
|
|
12
|
+
getSelectedFiles,
|
|
13
|
+
closeModalAndSetValue,
|
|
14
|
+
simpleLayout,
|
|
15
|
+
fileId,
|
|
16
|
+
storeKey,
|
|
17
|
+
selectedStoreKey
|
|
18
|
+
}) => {
|
|
10
19
|
const [files, setFiles] = useState([]);
|
|
11
20
|
const { addToast } = useToasts();
|
|
12
21
|
const client = useApolloClient();
|
|
13
22
|
const { addNewFile } = useFileList();
|
|
14
23
|
|
|
24
|
+
const { data: { getEntitySchemas: [schemaData] = [] } = {}, loading: schemaLoading } = useQuery(
|
|
25
|
+
getQuery('GET_ENTITY_SCHEMA'),
|
|
26
|
+
{
|
|
27
|
+
variables: { identifier: 'file' }
|
|
28
|
+
}
|
|
29
|
+
);
|
|
30
|
+
|
|
31
|
+
const customFields = useMemo(() => {
|
|
32
|
+
if (schemaData && schemaData.properties) {
|
|
33
|
+
const { name: _name, storeKey: _storeKey, ...restProperties } = schemaData.properties;
|
|
34
|
+
return Object.entries(restProperties)
|
|
35
|
+
.filter(([, field]) => field && field.showInForm === true)
|
|
36
|
+
.map(([key, field]) => {
|
|
37
|
+
const Component = getFormBuilderLookup.getFormField(field.formFieldType);
|
|
38
|
+
return {
|
|
39
|
+
name: key,
|
|
40
|
+
label: field.label || key,
|
|
41
|
+
component: props => (
|
|
42
|
+
<Component
|
|
43
|
+
{...field}
|
|
44
|
+
{...props}
|
|
45
|
+
onChange={(...args) => {
|
|
46
|
+
const [event] = args;
|
|
47
|
+
if (!event.value) {
|
|
48
|
+
event.value = event.event.target ? event.event.target.value : event.value;
|
|
49
|
+
}
|
|
50
|
+
if (event.event.target && !event.event.target.id) {
|
|
51
|
+
event.event.target.id = props.id || key;
|
|
52
|
+
}
|
|
53
|
+
if (event.event.target) {
|
|
54
|
+
event.event.target.name = key;
|
|
55
|
+
}
|
|
56
|
+
return props.onChange(...args);
|
|
57
|
+
}}
|
|
58
|
+
/>
|
|
59
|
+
)
|
|
60
|
+
};
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
return [];
|
|
64
|
+
}, [schemaData]);
|
|
65
|
+
|
|
15
66
|
const fileStoresType = getQuery('GET_FILE_STORES');
|
|
67
|
+
const { data: { getFileStores: storeType = [] } = {}, loading: storeLoading } = useQuery(
|
|
68
|
+
fileStoresType,
|
|
69
|
+
{
|
|
70
|
+
variables: { visibleInAdmin: true }
|
|
71
|
+
}
|
|
72
|
+
);
|
|
16
73
|
|
|
17
|
-
|
|
18
|
-
variables: { visibleInAdmin: true }
|
|
19
|
-
});
|
|
74
|
+
if (schemaLoading || storeLoading) return null;
|
|
20
75
|
|
|
21
76
|
const handleFiles = filesToUpload => {
|
|
77
|
+
if (fileId && filesToUpload && filesToUpload.length) {
|
|
78
|
+
setFiles([filesToUpload[0]]);
|
|
79
|
+
return;
|
|
80
|
+
}
|
|
22
81
|
setFiles(filesToUpload);
|
|
23
82
|
};
|
|
24
83
|
|
|
25
84
|
const uploadFiles = async () => {
|
|
85
|
+
const filesToProcess = fileId && files.length ? [files[0]] : files;
|
|
86
|
+
|
|
26
87
|
const response = await Promise.all(
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
88
|
+
filesToProcess.map(fileData => {
|
|
89
|
+
const { file, name, data: dataProperties = {}, storeKey: fileStoreKey } = fileData;
|
|
90
|
+
const customProperties = customFields.map(
|
|
91
|
+
({ name: customPropertyName }) => customPropertyName
|
|
92
|
+
);
|
|
93
|
+
const otherProperties = Object.entries(dataProperties).reduce(
|
|
94
|
+
(acc, [key, value]) => {
|
|
95
|
+
if (customProperties.includes(key)) {
|
|
96
|
+
acc.fileProperties[key] = value;
|
|
97
|
+
} else {
|
|
98
|
+
acc.data[key] = value;
|
|
36
99
|
}
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
100
|
+
return acc;
|
|
101
|
+
},
|
|
102
|
+
{ data: {}, fileProperties: {} }
|
|
103
|
+
);
|
|
104
|
+
const payload = {
|
|
105
|
+
name,
|
|
106
|
+
storeKey: fileStoreKey || selectedStoreKey || storeKey,
|
|
107
|
+
...otherProperties
|
|
108
|
+
};
|
|
109
|
+
|
|
110
|
+
if (fileId) {
|
|
111
|
+
payload.id = fileId;
|
|
112
|
+
} else if (!name) {
|
|
113
|
+
payload.name = file.filename;
|
|
114
|
+
}
|
|
115
|
+
return client.mutate({
|
|
116
|
+
mutation: getMutation('UPLOAD_FILE'),
|
|
117
|
+
variables: { input: { file, ...payload } }
|
|
118
|
+
});
|
|
119
|
+
})
|
|
40
120
|
).catch(error => {
|
|
41
121
|
addToast(error.message, {
|
|
42
122
|
appearance: 'error',
|
|
43
123
|
autoDismiss: true
|
|
44
124
|
});
|
|
125
|
+
return [];
|
|
45
126
|
});
|
|
46
127
|
|
|
47
|
-
const parsedResponse = response.map(({ data: { file } }) =>
|
|
128
|
+
const parsedResponse = response.map(({ data: { file } }) => {
|
|
129
|
+
const { message, ...rest } = file.result || {};
|
|
130
|
+
return rest;
|
|
131
|
+
});
|
|
48
132
|
|
|
49
133
|
const fileNames = files.map(({ file }) => file.name);
|
|
50
|
-
addNewFile(parsedResponse);
|
|
51
|
-
const toastMessage = `Uploaded: ${fileNames.join(', ')}`;
|
|
52
134
|
|
|
53
135
|
if (simpleLayout) {
|
|
54
|
-
|
|
136
|
+
if (fileId && parsedResponse && parsedResponse.length) {
|
|
137
|
+
const { message, ...updatedFile } = parsedResponse[0];
|
|
138
|
+
try {
|
|
139
|
+
client.writeQuery({
|
|
140
|
+
query: getQuery('GET_FILE_BY_ID'),
|
|
141
|
+
variables: { id: fileId },
|
|
142
|
+
data: { file: updatedFile }
|
|
143
|
+
});
|
|
144
|
+
} catch (e) {
|
|
145
|
+
console.error(e); //eslint-disable-line
|
|
146
|
+
}
|
|
147
|
+
const updateMessage = `Updated: ${updatedFile.filename || fileNames[0]}`;
|
|
148
|
+
closeModalAndSetValue(simpleLayout, updatedFile, updateMessage);
|
|
149
|
+
return;
|
|
150
|
+
}
|
|
151
|
+
const filesToSelect = parsedResponse.map(({ id }) => id);
|
|
152
|
+
const uploadMessage = `Uploaded: ${fileNames.join(', ')}`;
|
|
55
153
|
getSelectedFiles(null, filesToSelect);
|
|
56
|
-
closeModalAndSetValue(simpleLayout, filesToSelect,
|
|
154
|
+
closeModalAndSetValue(simpleLayout, filesToSelect, uploadMessage);
|
|
57
155
|
return;
|
|
58
156
|
}
|
|
59
157
|
|
|
158
|
+
addNewFile && addNewFile(parsedResponse);
|
|
159
|
+
const toastMessage = fileId ? `Updated: ${fileNames[0]}` : `Uploaded: ${fileNames.join(', ')}`;
|
|
160
|
+
|
|
60
161
|
addToast(toastMessage, {
|
|
61
162
|
appearance: 'success',
|
|
62
163
|
autoDismiss: true
|
|
@@ -68,43 +169,53 @@ const FileUploadModal = ({ onClose, getSelectedFiles, closeModalAndSetValue, sim
|
|
|
68
169
|
onClose();
|
|
69
170
|
};
|
|
70
171
|
|
|
71
|
-
|
|
172
|
+
let storeOptions = storeType.map(type => [type.key, type.name]);
|
|
173
|
+
storeOptions = storeKey ? storeOptions.filter(([key]) => key === storeKey) : storeOptions;
|
|
72
174
|
|
|
73
175
|
return (
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
176
|
+
<Modal
|
|
177
|
+
onClose={onClose}
|
|
178
|
+
title="Add media"
|
|
179
|
+
actions={[
|
|
180
|
+
{
|
|
181
|
+
textButton: 'Cancel',
|
|
182
|
+
callback: onClose,
|
|
183
|
+
modifiers: ['cancel']
|
|
184
|
+
},
|
|
185
|
+
{
|
|
186
|
+
textButton: 'Upload',
|
|
187
|
+
callback: handleOnSave,
|
|
188
|
+
modifiers: []
|
|
189
|
+
}
|
|
190
|
+
]}
|
|
191
|
+
upload>
|
|
192
|
+
<FileUpload
|
|
193
|
+
storeKey={selectedStoreKey || storeKey}
|
|
194
|
+
onChange={handleFiles}
|
|
195
|
+
selectOptions={storeOptions}
|
|
196
|
+
customFields={customFields}
|
|
197
|
+
/>
|
|
198
|
+
</Modal>
|
|
94
199
|
);
|
|
95
200
|
};
|
|
96
201
|
|
|
97
202
|
FileUploadModal.propTypes = {
|
|
203
|
+
fileId: PropTypes.string,
|
|
98
204
|
getSelectedFiles: PropTypes.func.isRequired,
|
|
99
205
|
onClose: PropTypes.func,
|
|
100
206
|
simpleLayout: PropTypes.bool,
|
|
101
|
-
closeModalAndSetValue: PropTypes.func
|
|
207
|
+
closeModalAndSetValue: PropTypes.func,
|
|
208
|
+
storeKey: PropTypes.string,
|
|
209
|
+
selectedStoreKey: PropTypes.string
|
|
102
210
|
};
|
|
103
211
|
|
|
104
212
|
FileUploadModal.defaultProps = {
|
|
105
213
|
onClose: () => {},
|
|
106
214
|
closeModalAndSetValue: () => {},
|
|
107
|
-
simpleLayout: false
|
|
215
|
+
simpleLayout: false,
|
|
216
|
+
fileId: null,
|
|
217
|
+
storeKey: null,
|
|
218
|
+
selectedStoreKey: null
|
|
108
219
|
};
|
|
109
220
|
|
|
110
221
|
export default FileUploadModal;
|