@blaze-cms/plugin-media-ui 0.146.0-node18-core-styles-tooltips.58 → 0.146.0-node18-tooltips.44
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 +25 -92
- package/lib/components/CardMedia/CardMedia.js +107 -50
- package/lib/components/CardMedia/CardMedia.js.map +1 -1
- package/lib/components/EditMediaFile/EditMediaFile.js +31 -45
- package/lib/components/EditMediaFile/EditMediaFile.js.map +1 -1
- package/lib/components/EditMediaFile/EditMediaFilePage.js +18 -9
- package/lib/components/EditMediaFile/EditMediaFilePage.js.map +1 -1
- package/lib/components/FileList/useGetFiles/getFiles.js +13 -12
- package/lib/components/FileList/useGetFiles/getFiles.js.map +1 -1
- package/lib/components/FileList/useGetFiles/useGetFiles.js +8 -4
- package/lib/components/FileList/useGetFiles/useGetFiles.js.map +1 -1
- package/lib/components/FileList/useGetFilesList/getCounters.js +1 -1
- package/lib/components/FileList/useGetFilesList/getCounters.js.map +1 -1
- package/lib/components/FileList/useGetFilesList/useGetFilesList.js +4 -2
- package/lib/components/FileList/useGetFilesList/useGetFilesList.js.map +1 -1
- package/lib/components/FilePreview/Actions/index.js +1 -1
- package/lib/components/FilePreview/Actions/index.js.map +1 -1
- package/lib/components/FilePreview/Image/Image.js.map +1 -1
- package/lib/components/FilePreview/Image/imageSchema.js +8 -4
- package/lib/components/FilePreview/Image/imageSchema.js.map +1 -1
- package/lib/components/FilePreview/PDF/PDF.js.map +1 -1
- package/lib/components/FilePreview/PDF/schema.js +2 -1
- package/lib/components/FilePreview/PDF/schema.js.map +1 -1
- package/lib/components/FilePreview/index.js +52 -9
- package/lib/components/FilePreview/index.js.map +1 -1
- package/lib/components/FilePreview/previewDefault/PreviewDefault.js.map +1 -1
- package/lib/components/FilePreview/previewDefault/previewDefaultSchema.js +2 -1
- package/lib/components/FilePreview/previewDefault/previewDefaultSchema.js.map +1 -1
- package/lib/components/FilePreviewReadOnly/FilePreviewList.js +0 -1
- package/lib/components/FilePreviewReadOnly/FilePreviewList.js.map +1 -1
- package/lib/components/FilePreviewReadOnly/FilePreviewReadOnly.js +3 -3
- package/lib/components/FilePreviewReadOnly/FilePreviewReadOnly.js.map +1 -1
- package/lib/components/FileUploadAdapter/FileList.js +1 -1
- package/lib/components/FileUploadAdapter/FileList.js.map +1 -1
- package/lib/components/FileUploadAdapter/FilePreviewList.js +0 -1
- package/lib/components/FileUploadAdapter/FilePreviewList.js.map +1 -1
- package/lib/components/FileUploadAdapter/FileReorderList.js.map +1 -1
- package/lib/components/FileUploadAdapter/FileUploadAdapter.js +50 -36
- package/lib/components/FileUploadAdapter/FileUploadAdapter.js.map +1 -1
- package/lib/components/FileUploadModal/FileUploadModal.js +3 -3
- package/lib/components/FileUploadModal/FileUploadModal.js.map +1 -1
- package/lib/components/FilterPanel/FilterPanel.js +42 -141
- package/lib/components/FilterPanel/FilterPanel.js.map +1 -1
- package/lib/components/FilterPanel/MediaSearchFilter.js +40 -0
- package/lib/components/FilterPanel/MediaSearchFilter.js.map +1 -0
- package/lib/components/ListingContainer/Listing/Listing.js.map +1 -1
- package/lib/components/ListingContainer/Listing/MediaListing/MediaFileList/MediaFileList.js +6 -5
- package/lib/components/ListingContainer/Listing/MediaListing/MediaFileList/MediaFileList.js.map +1 -1
- package/lib/components/ListingContainer/Listing/MediaListing/MediaListing.js +1 -1
- package/lib/components/ListingContainer/Listing/MediaListing/MediaListing.js.map +1 -1
- package/lib/components/ListingContainer/ListingContainer.js +5 -2
- package/lib/components/ListingContainer/ListingContainer.js.map +1 -1
- package/lib/components/MediaListing.js +1 -1
- package/lib/components/MediaListing.js.map +1 -1
- package/lib/constants.js +2 -1
- package/lib/constants.js.map +1 -1
- package/lib/index.js +5 -5
- package/lib/index.js.map +1 -1
- package/lib/utils/bustUrl.js +1 -0
- package/lib/utils/bustUrl.js.map +1 -1
- package/lib-es/components/CardMedia/CardMedia.js +97 -54
- package/lib-es/components/CardMedia/CardMedia.js.map +1 -1
- package/lib-es/components/EditMediaFile/EditMediaFile.js +26 -42
- package/lib-es/components/EditMediaFile/EditMediaFile.js.map +1 -1
- package/lib-es/components/EditMediaFile/EditMediaFilePage.js +15 -8
- package/lib-es/components/EditMediaFile/EditMediaFilePage.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.map +1 -1
- package/lib-es/components/FilePreview/Image/imageSchema.js +8 -4
- package/lib-es/components/FilePreview/Image/imageSchema.js.map +1 -1
- 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 +48 -3
- package/lib-es/components/FilePreview/index.js.map +1 -1
- package/lib-es/components/FilePreview/previewDefault/PreviewDefault.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/FileUploadAdapter/FileList.js.map +1 -1
- package/lib-es/components/FileUploadAdapter/FileUploadAdapter.js +34 -23
- 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/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/MediaListing/MediaFileList/MediaFileList.js +5 -4
- package/lib-es/components/ListingContainer/Listing/MediaListing/MediaFileList/MediaFileList.js.map +1 -1
- package/lib-es/components/ListingContainer/ListingContainer.js +4 -1
- package/lib-es/components/ListingContainer/ListingContainer.js.map +1 -1
- package/lib-es/constants.js +2 -1
- package/lib-es/constants.js.map +1 -1
- package/lib-es/index.js +3 -3
- package/lib-es/index.js.map +1 -1
- package/lib-es/utils/bustUrl.js.map +1 -1
- package/package.json +8 -8
- package/src/components/CardMedia/CardMedia.js +119 -90
- package/src/components/EditMediaFile/EditMediaFile.js +28 -27
- package/src/components/EditMediaFile/EditMediaFilePage.js +12 -7
- 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/Image/imageSchema.js +8 -4
- package/src/components/FilePreview/PDF/schema.js +2 -1
- package/src/components/FilePreview/index.js +37 -2
- package/src/components/FilePreview/previewDefault/previewDefaultSchema.js +2 -1
- package/src/components/FileUploadAdapter/FileUploadAdapter.js +24 -14
- package/src/components/FilterPanel/FilterPanel.js +44 -129
- package/src/components/FilterPanel/MediaSearchFilter.js +32 -0
- package/src/components/ListingContainer/Listing/MediaListing/MediaFileList/MediaFileList.js +5 -2
- package/src/components/ListingContainer/ListingContainer.js +4 -1
- package/src/constants.js +15 -1
|
@@ -1,15 +1,14 @@
|
|
|
1
|
-
import React, { useState } from 'react';
|
|
2
|
-
import More from '@blaze-react/more';
|
|
3
|
-
import Button from '@blaze-react/button';
|
|
1
|
+
import React, { useState, useCallback } from 'react';
|
|
4
2
|
import { DeleteAction } from '@blaze-cms/admin';
|
|
5
3
|
import PropTypes from 'prop-types';
|
|
6
4
|
import { getQuery, getMutation } from '@blaze-cms/admin-ui-utils';
|
|
7
|
-
import { useMutation, useApolloClient } from '@apollo/client';
|
|
5
|
+
import { useMutation, useApolloClient, useQuery } from '@apollo/client';
|
|
8
6
|
import classnames from 'classnames';
|
|
9
7
|
import { useToasts } from '@blaze-react/toaster';
|
|
10
8
|
import Modal from '@blaze-react/modal';
|
|
11
9
|
import { createPortal } from 'react-dom';
|
|
12
10
|
import { Link } from 'react-router-dom';
|
|
11
|
+
import { DeleteIcon, EditIcon } from '@blaze-cms/plugin-page-builder-ui';
|
|
13
12
|
import EditMediaFile from '../EditMediaFile';
|
|
14
13
|
import bustUrl from '../../utils/bustUrl';
|
|
15
14
|
|
|
@@ -38,52 +37,53 @@ const CardMedia = ({
|
|
|
38
37
|
const [type, extension] = mimetype.split('/');
|
|
39
38
|
const client = useApolloClient();
|
|
40
39
|
|
|
40
|
+
const { data: { getEntitySchemas: [schemaData] = [] } = {}, loading: schemaLoading } = useQuery(
|
|
41
|
+
getQuery('GET_ENTITY_SCHEMA'),
|
|
42
|
+
{
|
|
43
|
+
variables: { identifier: 'file' }
|
|
44
|
+
}
|
|
45
|
+
);
|
|
46
|
+
|
|
41
47
|
const deleteFileById = async () => {
|
|
42
48
|
setDisplayDeleteModal(false);
|
|
43
49
|
try {
|
|
44
|
-
await deleteFile({
|
|
45
|
-
|
|
46
|
-
});
|
|
47
|
-
|
|
48
|
-
removeFile({
|
|
49
|
-
index
|
|
50
|
-
});
|
|
51
|
-
|
|
52
|
-
addToast(`File: ${name} has been deleted`, {
|
|
53
|
-
appearance: 'success',
|
|
54
|
-
autoDismiss: true
|
|
55
|
-
});
|
|
50
|
+
await deleteFile({ variables: { input: { id } } });
|
|
51
|
+
removeFile({ index });
|
|
52
|
+
addToast(`File: ${name} has been deleted`, { appearance: 'success', autoDismiss: true });
|
|
56
53
|
} catch (error) {
|
|
57
|
-
addToast(error.message, {
|
|
58
|
-
appearance: 'error',
|
|
59
|
-
autoDismiss: true
|
|
60
|
-
});
|
|
54
|
+
addToast(error.message, { appearance: 'error', autoDismiss: true });
|
|
61
55
|
}
|
|
62
56
|
};
|
|
63
57
|
|
|
64
|
-
const
|
|
65
|
-
onSelected({ id, url, name, data });
|
|
66
|
-
};
|
|
58
|
+
const handleRowClick = () => onSelected({ id, url, name, data });
|
|
67
59
|
|
|
68
|
-
const
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
60
|
+
const handleCheckboxToggle = useCallback(
|
|
61
|
+
e => {
|
|
62
|
+
e.preventDefault();
|
|
63
|
+
e.stopPropagation();
|
|
64
|
+
onSelected({ id, url, name, data });
|
|
65
|
+
},
|
|
66
|
+
[id, url, name, data, onSelected]
|
|
67
|
+
);
|
|
72
68
|
|
|
73
|
-
const
|
|
74
|
-
|
|
69
|
+
const handleKeyDown = e => {
|
|
70
|
+
if (e.key === ' ' || e.key === 'Enter') {
|
|
71
|
+
e.preventDefault();
|
|
72
|
+
handleRowClick();
|
|
73
|
+
}
|
|
75
74
|
};
|
|
76
75
|
|
|
77
|
-
const
|
|
78
|
-
|
|
79
|
-
|
|
76
|
+
const cardMediaClassNames = classnames(
|
|
77
|
+
'card card--media-list card--media-list-row',
|
|
78
|
+
`card--media-${displayLayout}`,
|
|
79
|
+
{ 'card--media-list--selected': selected }
|
|
80
|
+
);
|
|
81
|
+
|
|
82
|
+
const handleCloseModal = () => setDisplayEditModal(false);
|
|
83
|
+
const handleSaveButtonStatus = state => setEnableSaveButton(state);
|
|
80
84
|
|
|
81
85
|
const modalActions = [
|
|
82
|
-
{
|
|
83
|
-
textButton: 'Cancel',
|
|
84
|
-
callback: handleCloseModal,
|
|
85
|
-
modifiers: ['cancel']
|
|
86
|
-
},
|
|
86
|
+
{ textButton: 'Cancel', callback: handleCloseModal, modifiers: ['cancel'] },
|
|
87
87
|
{
|
|
88
88
|
textButton: 'Apply',
|
|
89
89
|
callback: () => handleFormSave(),
|
|
@@ -91,9 +91,9 @@ const CardMedia = ({
|
|
|
91
91
|
}
|
|
92
92
|
];
|
|
93
93
|
|
|
94
|
-
const handleFileChange = file =>
|
|
95
|
-
|
|
96
|
-
|
|
94
|
+
const handleFileChange = file => setFileData(file);
|
|
95
|
+
|
|
96
|
+
const handleStopPropagation = e => e.stopPropagation();
|
|
97
97
|
|
|
98
98
|
const handleFormSave = async () => {
|
|
99
99
|
try {
|
|
@@ -101,7 +101,7 @@ const CardMedia = ({
|
|
|
101
101
|
data: { updateFile: updatedFile }
|
|
102
102
|
} = await client.mutate({
|
|
103
103
|
mutation: getMutation('UPDATE_FILE'),
|
|
104
|
-
variables: { input: fileData },
|
|
104
|
+
variables: { input: fileData.formData },
|
|
105
105
|
update(cache, { data: { updateFile: fileUpdated } }) {
|
|
106
106
|
cache.writeQuery({
|
|
107
107
|
query: getQuery('GET_FILE_BY_ID'),
|
|
@@ -127,6 +127,8 @@ const CardMedia = ({
|
|
|
127
127
|
setEnableSaveButton(false);
|
|
128
128
|
};
|
|
129
129
|
|
|
130
|
+
if (schemaLoading) return null;
|
|
131
|
+
|
|
130
132
|
return (
|
|
131
133
|
<>
|
|
132
134
|
{displayEditModal &&
|
|
@@ -138,20 +140,38 @@ const CardMedia = ({
|
|
|
138
140
|
handleSaveButtonStatus={handleSaveButtonStatus}
|
|
139
141
|
handleFormSave={handleFormSave}
|
|
140
142
|
enableSaveButton={enableSaveButton}
|
|
143
|
+
schemaData={schemaData}
|
|
141
144
|
/>
|
|
142
145
|
</Modal>,
|
|
143
146
|
modalTargetRef.current
|
|
144
147
|
)}
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
148
|
+
|
|
149
|
+
{displayDeleteModal &&
|
|
150
|
+
createPortal(
|
|
151
|
+
<DeleteAction
|
|
152
|
+
onClose={() => setDisplayDeleteModal(false)}
|
|
153
|
+
deleteAction={() => deleteFileById()}
|
|
154
|
+
itemName={name}
|
|
155
|
+
/>,
|
|
156
|
+
modalTargetRef.current
|
|
157
|
+
)}
|
|
158
|
+
|
|
159
|
+
<div
|
|
160
|
+
className={cardMediaClassNames}
|
|
161
|
+
role="option"
|
|
162
|
+
aria-selected={selected}
|
|
163
|
+
tabIndex={0}
|
|
164
|
+
onClick={handleRowClick}
|
|
165
|
+
onKeyDown={handleKeyDown}>
|
|
166
|
+
<div className="card__select">
|
|
167
|
+
<input
|
|
168
|
+
type="checkbox"
|
|
169
|
+
aria-label={`Select ${name}`}
|
|
170
|
+
checked={!!selected}
|
|
171
|
+
onChange={handleCheckboxToggle}
|
|
172
|
+
onClick={handleStopPropagation}
|
|
173
|
+
/>
|
|
174
|
+
</div>
|
|
155
175
|
|
|
156
176
|
{type === 'image' ? (
|
|
157
177
|
<div className={`card__image card__image--media-${displayLayout}`}>
|
|
@@ -159,7 +179,12 @@ const CardMedia = ({
|
|
|
159
179
|
</div>
|
|
160
180
|
) : (
|
|
161
181
|
<div className="card__image card__image--media-list-document">
|
|
162
|
-
<svg
|
|
182
|
+
<svg
|
|
183
|
+
xmlns="http://www.w3.org/2000/svg"
|
|
184
|
+
width="100"
|
|
185
|
+
height="100"
|
|
186
|
+
viewBox="0 0 8 8"
|
|
187
|
+
aria-hidden="true">
|
|
163
188
|
<path d="M0 0v8h7v-4h-4v-4h-3zm4 0v3h3l-3-3zm-3 2h1v1h-1v-1zm0 2h1v1h-1v-1zm0 2h4v1h-4v-1z" />
|
|
164
189
|
</svg>
|
|
165
190
|
</div>
|
|
@@ -168,46 +193,50 @@ const CardMedia = ({
|
|
|
168
193
|
<footer className={`card__footer card__footer--media-${displayLayout}`}>
|
|
169
194
|
<div className={`card__details card__details--media-${displayLayout}`}>
|
|
170
195
|
<div className={`card__title card__title--media-${displayLayout}`}>
|
|
171
|
-
<h2>{name}</h2>
|
|
196
|
+
<h2 className="card__file-name">{name}</h2>
|
|
172
197
|
</div>
|
|
173
|
-
<p>
|
|
174
|
-
<span>
|
|
198
|
+
<p className="card__meta">
|
|
199
|
+
<span>Format: {extension}</span>
|
|
175
200
|
</p>
|
|
176
201
|
</div>
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
202
|
+
|
|
203
|
+
<div className={`card__menu card__menu--icons card__menu--${displayLayout}`}>
|
|
204
|
+
{openEditInModal ? (
|
|
205
|
+
<button
|
|
206
|
+
type="button"
|
|
207
|
+
className="card__icon-btn"
|
|
208
|
+
title="Edit"
|
|
209
|
+
aria-label="Edit"
|
|
210
|
+
onClick={e => {
|
|
211
|
+
e.preventDefault();
|
|
212
|
+
e.stopPropagation();
|
|
213
|
+
setDisplayEditModal(true);
|
|
214
|
+
}}>
|
|
215
|
+
<EditIcon width="20px" height="20px" />
|
|
216
|
+
</button>
|
|
217
|
+
) : (
|
|
218
|
+
<Link
|
|
219
|
+
to={`/media/edit/${id}`}
|
|
220
|
+
className="card__icon-btn"
|
|
221
|
+
title="Edit"
|
|
222
|
+
aria-label="Edit"
|
|
223
|
+
onClick={e => e.stopPropagation()}>
|
|
224
|
+
<EditIcon width="20px" height="20px" />
|
|
225
|
+
</Link>
|
|
226
|
+
)}
|
|
227
|
+
|
|
228
|
+
<button
|
|
229
|
+
type="button"
|
|
230
|
+
className="card__icon-btn"
|
|
231
|
+
title="Delete"
|
|
232
|
+
aria-label="Delete"
|
|
233
|
+
onClick={e => {
|
|
234
|
+
e.preventDefault();
|
|
235
|
+
e.stopPropagation();
|
|
236
|
+
setDisplayDeleteModal(true);
|
|
237
|
+
}}>
|
|
238
|
+
<DeleteIcon width="18px" height="18px" />
|
|
239
|
+
</button>
|
|
211
240
|
</div>
|
|
212
241
|
</footer>
|
|
213
242
|
</div>
|
|
@@ -233,7 +262,7 @@ CardMedia.propTypes = {
|
|
|
233
262
|
};
|
|
234
263
|
|
|
235
264
|
CardMedia.defaultProps = {
|
|
236
|
-
onSelected: () => {},
|
|
265
|
+
onSelected: () => { },
|
|
237
266
|
selected: false,
|
|
238
267
|
data: {},
|
|
239
268
|
updated: null,
|
|
@@ -1,27 +1,28 @@
|
|
|
1
1
|
import React, { useState, useEffect } from 'react';
|
|
2
2
|
import PropTypes from 'prop-types';
|
|
3
|
-
import { getQuery } from '@blaze-cms/admin-ui-utils';
|
|
3
|
+
import { getQuery, getDynamicQuery } from '@blaze-cms/admin-ui-utils';
|
|
4
4
|
import { useQuery } from '@apollo/client';
|
|
5
5
|
import { useToasts } from '@blaze-react/toaster';
|
|
6
6
|
import FilePreview from '../FilePreview';
|
|
7
7
|
import FileUploadModal from '../FileUploadModal';
|
|
8
|
-
import {
|
|
8
|
+
import { FILE_DEFAULT_PROPS } from '../../constants';
|
|
9
9
|
|
|
10
10
|
const EditMediaFile = ({
|
|
11
11
|
onChange,
|
|
12
12
|
handleSaveButtonStatus,
|
|
13
13
|
fileId,
|
|
14
14
|
showChangeButton,
|
|
15
|
-
fileUpdated
|
|
15
|
+
fileUpdated,
|
|
16
|
+
schemaData
|
|
16
17
|
}) => {
|
|
17
18
|
const [formValues, setFormValues] = useState(null);
|
|
18
19
|
const [displayFileUploadModal, setDisplayFileUploadModal] = useState(false);
|
|
19
20
|
const { addToast } = useToasts();
|
|
20
21
|
|
|
21
|
-
const fileQuery =
|
|
22
|
+
const fileQuery = getDynamicQuery('DATA_QUERY')(schemaData, fileId, null, FILE_DEFAULT_PROPS);
|
|
22
23
|
const {
|
|
23
24
|
loading,
|
|
24
|
-
data: { file } = {},
|
|
25
|
+
data: { entityData: file } = {},
|
|
25
26
|
refetch: refetchFile
|
|
26
27
|
} = useQuery(fileQuery, {
|
|
27
28
|
variables: { id: fileId },
|
|
@@ -52,32 +53,30 @@ const EditMediaFile = ({
|
|
|
52
53
|
|
|
53
54
|
const handleFormChange = ({ isValid, isNewValueSet, valuesChecked }) => {
|
|
54
55
|
const baseFile = formValues || file;
|
|
55
|
-
const valuesCheckedWithoutName = valuesChecked.filter(
|
|
56
|
-
({ id }) => id !== NAME && id !== STORE_KEY
|
|
57
|
-
);
|
|
58
|
-
|
|
59
|
-
const dataValues = valuesCheckedWithoutName.reduce((acc, { id, value }) => {
|
|
60
|
-
acc[id] = value;
|
|
61
|
-
return acc;
|
|
62
|
-
}, {});
|
|
63
56
|
|
|
64
|
-
const
|
|
65
|
-
|
|
57
|
+
const dataValues = valuesChecked.reduce(
|
|
58
|
+
(acc, { id, value, isDataPropery }) => {
|
|
59
|
+
if (isDataPropery) {
|
|
60
|
+
acc.data[id] = value;
|
|
61
|
+
} else {
|
|
62
|
+
acc[id] = value;
|
|
63
|
+
}
|
|
64
|
+
return acc;
|
|
65
|
+
},
|
|
66
|
+
{ id: baseFile.id, data: { ...baseFile.data } }
|
|
67
|
+
);
|
|
68
|
+
delete dataValues.data.__typename; // Remove __typename if it exists in data to avoid issues with Apollo cache.
|
|
66
69
|
|
|
67
70
|
const shouldEnableSaveButton = isNewValueSet && isValid;
|
|
68
71
|
handleSaveButtonStatus(shouldEnableSaveButton);
|
|
69
72
|
|
|
70
73
|
const updatedFile = {
|
|
71
74
|
...baseFile,
|
|
72
|
-
|
|
73
|
-
storeKey: storeKey || baseFile.storeKey,
|
|
74
|
-
data: { ...(baseFile.data || {}), ...dataValues }
|
|
75
|
+
...dataValues
|
|
75
76
|
};
|
|
76
77
|
|
|
77
78
|
setFormValues(updatedFile);
|
|
78
|
-
|
|
79
|
-
const { __typename, ...cleanData } = updatedFile.data || {};
|
|
80
|
-
onChange({ id: updatedFile.id, name: updatedFile.name, data: cleanData });
|
|
79
|
+
onChange({ ...updatedFile, formData: dataValues });
|
|
81
80
|
};
|
|
82
81
|
|
|
83
82
|
const getFileWithStoreType = sourceFile => {
|
|
@@ -100,10 +99,10 @@ const EditMediaFile = ({
|
|
|
100
99
|
values.id === fileId
|
|
101
100
|
? values
|
|
102
101
|
: {
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
102
|
+
...(formValues || file),
|
|
103
|
+
...values,
|
|
104
|
+
url: values.url || (formValues || file).url
|
|
105
|
+
};
|
|
107
106
|
setFormValues(updated);
|
|
108
107
|
onChange(updated);
|
|
109
108
|
handleSaveButtonStatus(true);
|
|
@@ -127,7 +126,7 @@ const EditMediaFile = ({
|
|
|
127
126
|
const fileToRender = formValues || file;
|
|
128
127
|
const fileWithStoreType = getFileWithStoreType(fileToRender);
|
|
129
128
|
|
|
130
|
-
return (
|
|
129
|
+
return !loading ? (
|
|
131
130
|
<>
|
|
132
131
|
{!!file && (
|
|
133
132
|
<FilePreview
|
|
@@ -146,11 +145,13 @@ const EditMediaFile = ({
|
|
|
146
145
|
simpleLayout
|
|
147
146
|
fileId={fileId}
|
|
148
147
|
storeKey={file && file.storeKey}
|
|
149
|
-
getSelectedFiles={() => {}}
|
|
148
|
+
getSelectedFiles={() => { }}
|
|
150
149
|
/>
|
|
151
150
|
</div>
|
|
152
151
|
)}
|
|
153
152
|
</>
|
|
153
|
+
) : (
|
|
154
|
+
<div>loading...</div>
|
|
154
155
|
);
|
|
155
156
|
};
|
|
156
157
|
|
|
@@ -2,7 +2,7 @@ import React, { useState } from 'react';
|
|
|
2
2
|
import { withRouter } from 'react-router-dom';
|
|
3
3
|
import PropTypes from 'prop-types';
|
|
4
4
|
import Button from '@blaze-react/button';
|
|
5
|
-
import { useApolloClient } from '@apollo/client';
|
|
5
|
+
import { useApolloClient, useQuery } from '@apollo/client';
|
|
6
6
|
import { getQuery, getMutation } from '@blaze-cms/admin-ui-utils';
|
|
7
7
|
import { useToasts } from '@blaze-react/toaster';
|
|
8
8
|
import EditMediaFile from './EditMediaFile';
|
|
@@ -13,6 +13,13 @@ const EditMediaFilePage = ({ match, history }) => {
|
|
|
13
13
|
const client = useApolloClient();
|
|
14
14
|
const { addToast } = useToasts();
|
|
15
15
|
|
|
16
|
+
const { data: { getEntitySchemas: [schemaData] = [] } = {}, loading: schemaLoading } = useQuery(
|
|
17
|
+
getQuery('GET_ENTITY_SCHEMA'),
|
|
18
|
+
{
|
|
19
|
+
variables: { identifier: 'file' }
|
|
20
|
+
}
|
|
21
|
+
);
|
|
22
|
+
|
|
16
23
|
const handleFileChange = values => setFile(values);
|
|
17
24
|
|
|
18
25
|
const handleSaveButtonStatus = value => {
|
|
@@ -29,12 +36,7 @@ const EditMediaFilePage = ({ match, history }) => {
|
|
|
29
36
|
}
|
|
30
37
|
|
|
31
38
|
try {
|
|
32
|
-
const inputData =
|
|
33
|
-
id: file.id,
|
|
34
|
-
name: file.name,
|
|
35
|
-
data: file.data,
|
|
36
|
-
storeKey: file.storeKey
|
|
37
|
-
};
|
|
39
|
+
const inputData = file.formData;
|
|
38
40
|
|
|
39
41
|
const {
|
|
40
42
|
data: { updateFile: updatedFile }
|
|
@@ -75,6 +77,8 @@ const EditMediaFilePage = ({ match, history }) => {
|
|
|
75
77
|
|
|
76
78
|
const buttonModifiers = shouldEnableSaveButton ? [] : ['disabled'];
|
|
77
79
|
|
|
80
|
+
if (schemaLoading) return null;
|
|
81
|
+
|
|
78
82
|
return (
|
|
79
83
|
<div className="page">
|
|
80
84
|
<div className="page__content">
|
|
@@ -86,6 +90,7 @@ const EditMediaFilePage = ({ match, history }) => {
|
|
|
86
90
|
handleFormSave={handleFormSave}
|
|
87
91
|
showChangeButton
|
|
88
92
|
fileUpdated={file}
|
|
93
|
+
schemaData={schemaData}
|
|
89
94
|
/>
|
|
90
95
|
<div className="page__content__mediaWrapperActions">
|
|
91
96
|
<Button onClick={pushBack}>Cancel</Button>
|
|
@@ -1,7 +1,15 @@
|
|
|
1
1
|
import { getQuery } from '@blaze-cms/admin-ui-utils';
|
|
2
2
|
import { ALL, INVALID_STORE_KEY_VALUES } from '../../../constants';
|
|
3
3
|
|
|
4
|
-
const getFromSearch = async ({
|
|
4
|
+
const getFromSearch = async ({
|
|
5
|
+
searchTerm,
|
|
6
|
+
offset,
|
|
7
|
+
limit,
|
|
8
|
+
where,
|
|
9
|
+
client,
|
|
10
|
+
fileStores = [],
|
|
11
|
+
esFilters = []
|
|
12
|
+
}) => {
|
|
5
13
|
const allTypesMatches = [
|
|
6
14
|
{
|
|
7
15
|
match: { type: 'image' }
|
|
@@ -19,7 +27,7 @@ const getFromSearch = async ({ searchTerm, offset, limit, where, client, fileSto
|
|
|
19
27
|
}
|
|
20
28
|
];
|
|
21
29
|
const match = !where.type || where.type === ALL ? allTypesMatches : matchSpecificType;
|
|
22
|
-
const mustMatch = [];
|
|
30
|
+
const mustMatch = [...esFilters];
|
|
23
31
|
|
|
24
32
|
if (searchTerm) {
|
|
25
33
|
mustMatch.push({
|
|
@@ -160,7 +168,7 @@ const getFromSearch = async ({ searchTerm, offset, limit, where, client, fileSto
|
|
|
160
168
|
return { files, all, image, video, text };
|
|
161
169
|
};
|
|
162
170
|
|
|
163
|
-
const getFiles = ({ offset, limit, where,
|
|
164
|
-
getFromSearch({ searchTerm, offset, limit, where, client, fileStores });
|
|
171
|
+
const getFiles = ({ searchTerm, offset, limit, where, esFilters, fileStores }, client) =>
|
|
172
|
+
getFromSearch({ searchTerm, offset, limit, where, esFilters, client, fileStores });
|
|
165
173
|
|
|
166
174
|
export default getFiles;
|
|
@@ -29,8 +29,8 @@ function useGetFiles() {
|
|
|
29
29
|
|
|
30
30
|
useEffect(
|
|
31
31
|
() => {
|
|
32
|
-
const { offset, limit, where, sort, searchTerm, isSearch } = queryParams;
|
|
33
|
-
const newFilter = JSON.stringify(where);
|
|
32
|
+
const { offset, limit, where, sort, searchTerm, isSearch, esFilters } = queryParams;
|
|
33
|
+
const newFilter = JSON.stringify({ where, esFilters });
|
|
34
34
|
const isNewFilterSet = newFilter !== previousFilter;
|
|
35
35
|
const isNewOffsetSet = previousOffset !== null && offset !== previousOffset;
|
|
36
36
|
const isNewSearchTermSet = searchTerm && previousSearchTerm !== searchTerm;
|
|
@@ -41,9 +41,8 @@ function useGetFiles() {
|
|
|
41
41
|
if (data.files.length) {
|
|
42
42
|
setData({ files: [] });
|
|
43
43
|
}
|
|
44
|
-
|
|
45
44
|
const { files, total, all, image, video, text } = await getFiles(
|
|
46
|
-
{ offset, limit, where, sort, searchTerm, isSearch, fileStores },
|
|
45
|
+
{ offset, limit, where, sort, searchTerm, isSearch, esFilters, fileStores },
|
|
47
46
|
client
|
|
48
47
|
);
|
|
49
48
|
setData({ files, total, all, image, video, text });
|
|
@@ -137,8 +137,9 @@ function useGetFilesList() {
|
|
|
137
137
|
const setQueryParams = params => {
|
|
138
138
|
const isNewSearchTerm = params.isSearch && previousSearchTerm !== params.searchTerm;
|
|
139
139
|
const hasDeletedSearchTerm = previousSearchTerm && params.searchTerm === null;
|
|
140
|
-
const newFilter = JSON.stringify(params.where);
|
|
140
|
+
const newFilter = JSON.stringify({ where: params.where, esFilters: params.esFilters });
|
|
141
141
|
const isNewFilter = newFilter !== previousFilter;
|
|
142
|
+
|
|
142
143
|
const shouldClearList = hasDeletedSearchTerm || isNewFilter || isNewSearchTerm;
|
|
143
144
|
shouldClearList ? clearList(params) : setParams(params);
|
|
144
145
|
setCurrentFilter(newFilter);
|
|
@@ -23,19 +23,22 @@ const imageSchema = {
|
|
|
23
23
|
showInForm: true,
|
|
24
24
|
label: 'Alt text',
|
|
25
25
|
formFieldType: 'text',
|
|
26
|
-
formPriority: 3.0
|
|
26
|
+
formPriority: 3.0,
|
|
27
|
+
isDataPropery: true
|
|
27
28
|
},
|
|
28
29
|
caption: {
|
|
29
30
|
type: 'string',
|
|
30
31
|
showInForm: true,
|
|
31
32
|
formFieldType: 'text',
|
|
32
|
-
formPriority: 4.0
|
|
33
|
+
formPriority: 4.0,
|
|
34
|
+
isDataPropery: true
|
|
33
35
|
},
|
|
34
36
|
credits: {
|
|
35
37
|
type: 'string',
|
|
36
38
|
showInForm: true,
|
|
37
39
|
formFieldType: 'text',
|
|
38
|
-
formPriority: 5.0
|
|
40
|
+
formPriority: 5.0,
|
|
41
|
+
isDataPropery: true
|
|
39
42
|
},
|
|
40
43
|
hrefUrl: {
|
|
41
44
|
type: 'string',
|
|
@@ -43,7 +46,8 @@ const imageSchema = {
|
|
|
43
46
|
label: 'Image hyperlink',
|
|
44
47
|
showInForm: true,
|
|
45
48
|
formFieldType: 'text',
|
|
46
|
-
description: 'Url format is not valid'
|
|
49
|
+
description: 'Url format is not valid',
|
|
50
|
+
isDataPropery: true
|
|
47
51
|
}
|
|
48
52
|
},
|
|
49
53
|
required: ['name']
|
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import { FormBuilder } from '@blaze-cms/react-form-builder';
|
|
3
3
|
import PropTypes from 'prop-types';
|
|
4
|
+
import { useQuery } from '@apollo/client';
|
|
5
|
+
import { getQuery, getDynamicQuery } from '@blaze-cms/admin-ui-utils';
|
|
4
6
|
import { getPreview } from './get-preview';
|
|
7
|
+
import { FILE_DEFAULT_PROPS } from '../../constants';
|
|
5
8
|
|
|
6
9
|
const FilePreview = ({
|
|
7
10
|
file,
|
|
@@ -13,7 +16,35 @@ const FilePreview = ({
|
|
|
13
16
|
showChangeButton,
|
|
14
17
|
disableFilePreview
|
|
15
18
|
}) => {
|
|
16
|
-
const {
|
|
19
|
+
const {
|
|
20
|
+
data: schemaData = {
|
|
21
|
+
getEntitySchemas: [
|
|
22
|
+
{
|
|
23
|
+
properties: {},
|
|
24
|
+
actions: {
|
|
25
|
+
get: 'getFile'
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
]
|
|
29
|
+
},
|
|
30
|
+
loading: schemaLoading
|
|
31
|
+
} = useQuery(getQuery('GET_ENTITY_SCHEMA'), {
|
|
32
|
+
variables: { identifier: 'file' },
|
|
33
|
+
skip: schemaData
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
const [fileSchema] = schemaData && schemaData.getEntitySchemas ? schemaData.getEntitySchemas : [];
|
|
37
|
+
|
|
38
|
+
const fileQuery = getDynamicQuery('DATA_QUERY')(fileSchema, file.id, null, FILE_DEFAULT_PROPS);
|
|
39
|
+
const { loading, data: { entityData: fileData } = {} } = useQuery(fileQuery, {
|
|
40
|
+
variables: { id: file.id },
|
|
41
|
+
fetchPolicy: 'cache-and-network',
|
|
42
|
+
skip: !fileSchema || !fileSchema.id
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
if (!fileSchema || schemaLoading || loading) return null;
|
|
46
|
+
|
|
47
|
+
const { name, url, mimetype, data, store, updated } = fileData;
|
|
17
48
|
const bustUrl = (srcUrl, version) => {
|
|
18
49
|
if (!srcUrl) return srcUrl;
|
|
19
50
|
const sep = srcUrl.includes('?') ? '&' : '?';
|
|
@@ -23,6 +54,10 @@ const FilePreview = ({
|
|
|
23
54
|
const [Preview, schema] = getPreview({ mimetype, previewType });
|
|
24
55
|
const shouldRenderForm = schema && displayForm;
|
|
25
56
|
|
|
57
|
+
const { properties } = fileSchema;
|
|
58
|
+
const { name: nameProp, storeKey: storeKeyProp, ...restProperties } = properties;
|
|
59
|
+
Object.assign(schema.formSchema.properties, restProperties);
|
|
60
|
+
|
|
26
61
|
if (shouldRenderForm && store) {
|
|
27
62
|
const { defaultStore = {}, storeOptions = [] } = store;
|
|
28
63
|
if (schema.formSchema.properties.storeKey) {
|
|
@@ -34,7 +69,7 @@ const FilePreview = ({
|
|
|
34
69
|
}
|
|
35
70
|
}
|
|
36
71
|
|
|
37
|
-
const formBuilderData = { values: { ...data, ...
|
|
72
|
+
const formBuilderData = { values: { ...data, ...fileData } };
|
|
38
73
|
|
|
39
74
|
return (
|
|
40
75
|
<>
|