@blaze-cms/plugin-media-ui 0.147.0-rc-eagle.4 → 0.147.0-rc-eagle.6
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.map +1 -1
- package/lib/components/EditMediaFile/EditMediaFile.js.map +1 -1
- package/lib/components/FileUploadModal/FileUploadModal.js +80 -17
- package/lib/components/FileUploadModal/FileUploadModal.js.map +1 -1
- package/lib/components/ListingContainer/Listing/MediaListing/MediaFileList/MediaFileList.js +2 -0
- package/lib/components/ListingContainer/Listing/MediaListing/MediaFileList/MediaFileList.js.map +1 -1
- package/lib/constants.js +1 -1
- package/lib/constants.js.map +1 -1
- package/lib-es/components/CardMedia/CardMedia.js.map +1 -1
- package/lib-es/components/EditMediaFile/EditMediaFile.js.map +1 -1
- package/lib-es/components/FileUploadModal/FileUploadModal.js +81 -18
- package/lib-es/components/FileUploadModal/FileUploadModal.js.map +1 -1
- package/lib-es/components/ListingContainer/Listing/MediaListing/MediaFileList/MediaFileList.js +2 -0
- package/lib-es/components/ListingContainer/Listing/MediaListing/MediaFileList/MediaFileList.js.map +1 -1
- package/lib-es/constants.js +1 -1
- package/lib-es/constants.js.map +1 -1
- package/package.json +8 -6
- package/src/components/CardMedia/CardMedia.js +1 -1
- package/src/components/EditMediaFile/EditMediaFile.js +5 -5
- package/src/components/FileUploadModal/FileUploadModal.js +71 -6
- package/src/components/ListingContainer/Listing/MediaListing/MediaFileList/MediaFileList.js +2 -0
- package/src/constants.js +1 -1
|
@@ -1,6 +1,7 @@
|
|
|
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';
|
|
@@ -20,10 +21,57 @@ const FileUploadModal = ({
|
|
|
20
21
|
const client = useApolloClient();
|
|
21
22
|
const { addNewFile } = useFileList();
|
|
22
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
|
+
|
|
23
66
|
const fileStoresType = getQuery('GET_FILE_STORES');
|
|
24
|
-
const { data: { getFileStores: storeType = [] } = {} } = useQuery(
|
|
25
|
-
|
|
26
|
-
|
|
67
|
+
const { data: { getFileStores: storeType = [] } = {}, loading: storeLoading } = useQuery(
|
|
68
|
+
fileStoresType,
|
|
69
|
+
{
|
|
70
|
+
variables: { visibleInAdmin: true }
|
|
71
|
+
}
|
|
72
|
+
);
|
|
73
|
+
|
|
74
|
+
if (schemaLoading || storeLoading) return null;
|
|
27
75
|
|
|
28
76
|
const handleFiles = filesToUpload => {
|
|
29
77
|
if (fileId && filesToUpload && filesToUpload.length) {
|
|
@@ -37,12 +85,28 @@ const FileUploadModal = ({
|
|
|
37
85
|
const filesToProcess = fileId && files.length ? [files[0]] : files;
|
|
38
86
|
|
|
39
87
|
const response = await Promise.all(
|
|
40
|
-
filesToProcess.map(
|
|
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;
|
|
99
|
+
}
|
|
100
|
+
return acc;
|
|
101
|
+
},
|
|
102
|
+
{ data: {}, fileProperties: {} }
|
|
103
|
+
);
|
|
41
104
|
const payload = {
|
|
42
105
|
name,
|
|
43
106
|
storeKey: fileStoreKey || selectedStoreKey || storeKey,
|
|
44
|
-
|
|
107
|
+
...otherProperties
|
|
45
108
|
};
|
|
109
|
+
|
|
46
110
|
if (fileId) {
|
|
47
111
|
payload.id = fileId;
|
|
48
112
|
} else if (!name) {
|
|
@@ -129,6 +193,7 @@ const FileUploadModal = ({
|
|
|
129
193
|
storeKey={selectedStoreKey || storeKey}
|
|
130
194
|
onChange={handleFiles}
|
|
131
195
|
selectOptions={storeOptions}
|
|
196
|
+
customFields={customFields}
|
|
132
197
|
/>
|
|
133
198
|
</Modal>
|
|
134
199
|
);
|
|
@@ -34,6 +34,8 @@ const MediaFileList = ({
|
|
|
34
34
|
|
|
35
35
|
useEffect(() => {
|
|
36
36
|
if (!loading && !hasFiles) setDisplayCardPrompt(true);
|
|
37
|
+
if (!loading) setDisplayCardPrompt(false);
|
|
38
|
+
if (hasFiles) setDisplayCardPrompt(false);
|
|
37
39
|
}, [loading, hasFiles, setDisplayCardPrompt]);
|
|
38
40
|
|
|
39
41
|
useEffect(
|