diff --git a/examples/getstarted/api/address/models/Address.settings.json b/examples/getstarted/api/address/models/Address.settings.json index 703b834fdb..bb9658080c 100755 --- a/examples/getstarted/api/address/models/Address.settings.json +++ b/examples/getstarted/api/address/models/Address.settings.json @@ -1,4 +1,5 @@ { + "kind": "collectionType", "connection": "default", "collectionName": "addresses", "info": { @@ -7,14 +8,13 @@ }, "options": { "increments": true, - "timestamps": ["created_at", "updated_at"], + "timestamps": [ + "created_at", + "updated_at" + ], "comment": "" }, "attributes": { - "geolocation": { - "type": "json", - "required": true - }, "city": { "type": "string", "required": true @@ -30,16 +30,22 @@ "cover": { "model": "file", "via": "related", + "allowedTypes": [ + "files", + "images", + "videos" + ], "plugin": "upload", - "required": false, - "allowedTypes": ["images", "cover"] + "required": false }, "images": { "collection": "file", "via": "related", + "allowedTypes": [ + "images" + ], "plugin": "upload", - "required": false, - "allowedTypes": [] + "required": false }, "full_name": { "type": "string", diff --git a/examples/getstarted/api/category/models/Category.settings.json b/examples/getstarted/api/category/models/Category.settings.json index 59b0c45f28..5a599b8046 100755 --- a/examples/getstarted/api/category/models/Category.settings.json +++ b/examples/getstarted/api/category/models/Category.settings.json @@ -1,4 +1,5 @@ { + "kind": "collectionType", "connection": "default", "collectionName": "categories", "info": { diff --git a/examples/getstarted/extensions/upload/config/settings.js b/examples/getstarted/extensions/upload/config/settings.js index 1d80f74142..621dcbf782 100644 --- a/examples/getstarted/extensions/upload/config/settings.js +++ b/examples/getstarted/extensions/upload/config/settings.js @@ -1,8 +1,8 @@ module.exports = { - // provider: 'aws-s3', + // provider: 'cloudinary', // providerOptions: { - // cloud_name: '', - // api_key: '', - // api_secret: '', + // cloud_name: 'cloud-name', + // api_key: 'api-key', + // api_secret: 'api-secret', // }, }; diff --git a/examples/getstarted/package.json b/examples/getstarted/package.json index 5c0b9d45ab..d4d21c8862 100644 --- a/examples/getstarted/package.json +++ b/examples/getstarted/package.json @@ -29,6 +29,7 @@ "strapi-plugin-users-permissions": "3.0.0-beta.19.3", "strapi-provider-email-mailgun": "3.0.0-beta.19.3", "strapi-provider-upload-aws-s3": "3.0.0-beta.19.3", + "strapi-provider-upload-cloudinary": "3.0.0-beta.19.3", "strapi-utils": "3.0.0-beta.19.3" }, "strapi": { diff --git a/packages/strapi-admin/admin/src/translations/en.json b/packages/strapi-admin/admin/src/translations/en.json index 6641fe4514..5a3e5366b6 100644 --- a/packages/strapi-admin/admin/src/translations/en.json +++ b/packages/strapi-admin/admin/src/translations/en.json @@ -273,5 +273,6 @@ "notification.contentType.relations.conflict": "Content type has conflicting relations", "notification.form.error.fields": "The form contains some errors", "notification.form.success.fields": "Changes saved", + "notification.success.delete": "The item has been deleted", "global.prompt.unsaved": "Are you sure you want to leave this page? All your modifications will be lost" } diff --git a/packages/strapi-helper-plugin/lib/src/components/OverlayBlocker/Overlay.js b/packages/strapi-helper-plugin/lib/src/components/OverlayBlocker/Overlay.js index d4c3099fb0..099bec2ae9 100644 --- a/packages/strapi-helper-plugin/lib/src/components/OverlayBlocker/Overlay.js +++ b/packages/strapi-helper-plugin/lib/src/components/OverlayBlocker/Overlay.js @@ -14,7 +14,14 @@ const Overlay = styled.div` right: 0; bottom: 0; left: 0; - background: linear-gradient(rgba(0, 0, 0, 15) 0%, rgba(0, 0, 0, 0) 100%); + ${({ noGradient }) => { + if (noGradient) { + return ''; + } + + return `background: linear-gradient(rgba(0, 0, 0, 15) 0%, rgba(0, 0, 0, 0) 100%)`; + }}; + opacity: 0.5; } @@ -25,7 +32,13 @@ const Overlay = styled.div` right: 0; bottom: 0; left: 24rem; - background: linear-gradient(#fbfbfb 20%, rgba(0, 0, 100, 0) 100%); + ${({ noGradient }) => { + if (noGradient) { + return ''; + } + + return `background: linear-gradient(#fbfbfb 20%, rgba(0, 0, 100, 0) 100%)`; + }}; box-shadow: inset 0px 2px 4px rgba(0, 0, 0, 0.1); box-shadow: inset 0 1px 2px 0 rgba(40, 42, 49, 0.16); } @@ -38,4 +51,9 @@ const Overlay = styled.div` z-index: 1100; } `; + +Overlay.defaultProps = { + noGradient: false, +}; + export default Overlay; diff --git a/packages/strapi-helper-plugin/lib/src/components/OverlayBlocker/index.js b/packages/strapi-helper-plugin/lib/src/components/OverlayBlocker/index.js index 39cd3e0f09..7a02ff9a62 100644 --- a/packages/strapi-helper-plugin/lib/src/components/OverlayBlocker/index.js +++ b/packages/strapi-helper-plugin/lib/src/components/OverlayBlocker/index.js @@ -110,7 +110,7 @@ class OverlayBlocker extends React.Component { if (this.props.isOpen) { return ReactDOM.createPortal( - +
{content}
, this.overlayContainer @@ -126,6 +126,7 @@ OverlayBlocker.defaultProps = { description: 'components.OverlayBlocker.description', icon: 'sync-alt', isOpen: false, + noGradient: false, title: 'components.OverlayBlocker.title', }; @@ -134,6 +135,7 @@ OverlayBlocker.propTypes = { description: PropTypes.string, icon: PropTypes.string, isOpen: PropTypes.bool, + noGradient: PropTypes.bool, title: PropTypes.string, }; diff --git a/packages/strapi-plugin-content-type-builder/admin/src/components/AllowedTypesSelect/MenuList.js b/packages/strapi-plugin-content-type-builder/admin/src/components/AllowedTypesSelect/MenuList.js index 99fe573e62..6bc6b937a7 100644 --- a/packages/strapi-plugin-content-type-builder/admin/src/components/AllowedTypesSelect/MenuList.js +++ b/packages/strapi-plugin-content-type-builder/admin/src/components/AllowedTypesSelect/MenuList.js @@ -13,8 +13,8 @@ import Text from './Text'; const MenuList = ({ selectProps: { changeMediaAllowedTypes, value }, ...rest }) => { const { formatMessage } = useGlobalContext(); const Component = components.MenuList; - const areAllAllowedTypesSelected = value.value.length === 3; - const someChecked = !areAllAllowedTypesSelected && value.value.length > 0; + const areAllAllowedTypesSelected = value.value && value.value.length === 3; + const someChecked = value.value && !areAllAllowedTypesSelected && value.value.length > 0; const options = [ { name: 'images', @@ -58,7 +58,7 @@ const MenuList = ({ selectProps: { changeMediaAllowedTypes, value }, ...rest }) {options.map(({ name, infos }) => { - const isChecked = value.value.includes(name); + const isChecked = value.value && value.value.includes(name); const target = { name, value: !isChecked }; return ( diff --git a/packages/strapi-plugin-content-type-builder/admin/src/components/AllowedTypesSelect/index.js b/packages/strapi-plugin-content-type-builder/admin/src/components/AllowedTypesSelect/index.js index 3155c093af..946cf2af9b 100644 --- a/packages/strapi-plugin-content-type-builder/admin/src/components/AllowedTypesSelect/index.js +++ b/packages/strapi-plugin-content-type-builder/admin/src/components/AllowedTypesSelect/index.js @@ -15,8 +15,9 @@ const AllowedTypesSelect = ({ name, changeMediaAllowedTypes, styles, value }) => const ref = useRef(); /* eslint-disable indent */ + const displayedValue = - value.length === 0 + value === null || value.length === 0 ? formatMessage({ id: getTrad('form.attribute.media.allowed-types.none') }) : value .sort() @@ -35,16 +36,20 @@ const AllowedTypesSelect = ({ name, changeMediaAllowedTypes, styles, value }) => ref={ref} refState={ref} styles={styles} - value={{ label: displayedValue, value }} + value={{ label: displayedValue, value: value || '' }} /> ); }; +AllowedTypesSelect.defaultProps = { + value: null, +}; + AllowedTypesSelect.propTypes = { changeMediaAllowedTypes: PropTypes.func.isRequired, name: PropTypes.string.isRequired, styles: PropTypes.object.isRequired, - value: PropTypes.array.isRequired, + value: PropTypes.oneOfType([PropTypes.object, PropTypes.array]), }; export default AllowedTypesSelect; diff --git a/packages/strapi-plugin-content-type-builder/admin/src/containers/DataManagerProvider/index.js b/packages/strapi-plugin-content-type-builder/admin/src/containers/DataManagerProvider/index.js index 95c87224e1..7f30001faf 100644 --- a/packages/strapi-plugin-content-type-builder/admin/src/containers/DataManagerProvider/index.js +++ b/packages/strapi-plugin-content-type-builder/admin/src/containers/DataManagerProvider/index.js @@ -419,8 +419,8 @@ const DataManagerProvider = ({ allIcons, children }) => { if (!isInContentTypeView) { emitEvent('didNotSaveComponent'); } - console.error({ err }); - strapi.notification.error(err.response.payload.error || 'notification.error'); + console.error({ err: err.response }); + strapi.notification.error('notification.error'); } }; diff --git a/packages/strapi-plugin-content-type-builder/admin/src/containers/FormModal/index.js b/packages/strapi-plugin-content-type-builder/admin/src/containers/FormModal/index.js index 21672c5ce7..11ffd80f86 100644 --- a/packages/strapi-plugin-content-type-builder/admin/src/containers/FormModal/index.js +++ b/packages/strapi-plugin-content-type-builder/admin/src/containers/FormModal/index.js @@ -53,6 +53,7 @@ const FormModal = () => { const { emitEvent, formatMessage } = useGlobalContext(); const query = useQuery(); const attributeOptionRef = useRef(); + const { addAttribute, addCreatedComponentToDynamicZone, @@ -1197,6 +1198,8 @@ const FormModal = () => { value = retrievedValue.join('\n'); } else if (input.name === 'uid') { value = input.value; + } else if (input.name === 'allowedTypes' && retrievedValue === '') { + value = null; } else { value = retrievedValue; } diff --git a/packages/strapi-plugin-content-type-builder/admin/src/containers/FormModal/reducer.js b/packages/strapi-plugin-content-type-builder/admin/src/containers/FormModal/reducer.js index bbdf62c17c..1cb4c9fdab 100644 --- a/packages/strapi-plugin-content-type-builder/admin/src/containers/FormModal/reducer.js +++ b/packages/strapi-plugin-content-type-builder/admin/src/containers/FormModal/reducer.js @@ -103,13 +103,21 @@ const reducer = (state, action) => { return fromJS(['images', 'videos', 'files']); } - return fromJS([]); + return null; }); } - return state.updateIn(['modifiedData', 'allowedTypes'], list => { + return state.updateIn(['modifiedData', 'allowedTypes'], currentList => { + let list = currentList || fromJS([]); + if (list.includes(action.name)) { - return list.filter(v => v !== action.name); + list = list.filter(v => v !== action.name); + + if (list.size === 0) { + return null; + } + + return list; } return list.push(action.name); diff --git a/packages/strapi-plugin-content-type-builder/admin/src/containers/FormModal/tests/reducer.test.js b/packages/strapi-plugin-content-type-builder/admin/src/containers/FormModal/tests/reducer.test.js index 7693b142eb..1e9d69ddda 100644 --- a/packages/strapi-plugin-content-type-builder/admin/src/containers/FormModal/tests/reducer.test.js +++ b/packages/strapi-plugin-content-type-builder/admin/src/containers/FormModal/tests/reducer.test.js @@ -248,7 +248,7 @@ describe('CTB | containers | FormModal | reducer | actions', () => { value: false, type: 'ON_CHANGE_ALLOWED_TYPE', }; - const expected = state.setIn(['modifiedData', 'allowedTypes'], fromJS([])); + const expected = state.setIn(['modifiedData', 'allowedTypes'], null); expect(reducer(state, action)).toEqual(expected); }); @@ -271,7 +271,7 @@ describe('CTB | containers | FormModal | reducer | actions', () => { expect(reducer(state, action)).toEqual(expected); }); - it('Shoul remove the type', () => { + it('Should remove the type', () => { const state = initialState.setIn( ['modifiedData', 'allowedTypes'], fromJS(['videos', 'images', 'files']) @@ -285,6 +285,18 @@ describe('CTB | containers | FormModal | reducer | actions', () => { expect(reducer(state, action)).toEqual(expected); }); + + it('Should remove set the allowedTypes to null if removing the last type', () => { + const state = initialState.setIn(['modifiedData', 'allowedTypes'], fromJS(['videos'])); + const action = { + name: 'videos', + value: null, + type: 'ON_CHANGE_ALLOWED_TYPE', + }; + const expected = state.setIn(['modifiedData', 'allowedTypes'], null); + + expect(reducer(state, action)).toEqual(expected); + }); }); describe('RESET_PROPS', () => { diff --git a/packages/strapi-plugin-upload/admin/src/components/EditForm/index.js b/packages/strapi-plugin-upload/admin/src/components/EditForm/index.js index 4ba98d88ea..1e44b3d422 100644 --- a/packages/strapi-plugin-upload/admin/src/components/EditForm/index.js +++ b/packages/strapi-plugin-upload/admin/src/components/EditForm/index.js @@ -16,12 +16,7 @@ import { Inputs } from '@buffetjs/custom'; import { useGlobalContext } from 'strapi-helper-plugin'; import Cropper from 'cropperjs'; import 'cropperjs/dist/cropper.css'; -import { - canDownloadFile, - createFileToDownloadName, - getTrad, - prefixFileUrlWithBackendUrl, -} from '../../utils'; +import { createFileToDownloadName, getTrad, prefixFileUrlWithBackendUrl } from '../../utils'; import CardControl from '../CardControl'; import CardControlsWrapper from '../CardControlsWrapper'; import CardPreview from '../CardPreview'; @@ -60,9 +55,9 @@ const EditForm = forwardRef( const [src, setSrc] = useState(null); const fileURL = get(fileToEdit, ['file', 'url'], null); - const isFileDownloadable = canDownloadFile(fileURL); + const prefixedFileURL = fileURL ? prefixFileUrlWithBackendUrl(fileURL) : null; - const downloadFileName = isFileDownloadable ? createFileToDownloadName(fileToEdit) : null; + const downloadFileName = createFileToDownloadName(fileToEdit); const mimeType = get(fileToEdit, ['file', 'type'], null) || get(fileToEdit, ['file', 'mime'], ''); const isImg = isImageType(mimeType); diff --git a/packages/strapi-plugin-upload/admin/src/components/List/index.js b/packages/strapi-plugin-upload/admin/src/components/List/index.js index 2b14a882ca..157c91b5b0 100644 --- a/packages/strapi-plugin-upload/admin/src/components/List/index.js +++ b/packages/strapi-plugin-upload/admin/src/components/List/index.js @@ -1,6 +1,7 @@ import React from 'react'; import PropTypes from 'prop-types'; import { Checkbox } from '@buffetjs/core'; +import { get } from 'lodash'; import { createMatrix } from '../../utils'; import Card from '../Card'; import CardControlsWrapper from '../CardControlsWrapper'; @@ -19,7 +20,8 @@ const List = ({ data, onChange, onClickEditFile, selectedItems, canSelect }) => return (
{rowContent.map(item => { - const { id, url } = item; + const { id } = item; + const url = get(item, ['formats', 'thumbnail', 'url'], ''); const checked = selectedItems.findIndex(file => file.id === id) !== -1; const fileUrl = url.startsWith('/') ? `${strapi.backendURL}${url}` : url; diff --git a/packages/strapi-plugin-upload/admin/src/components/SelectedAssets/SortableList.js b/packages/strapi-plugin-upload/admin/src/components/SelectedAssets/SortableList.js index e9f8be367e..f294107e69 100644 --- a/packages/strapi-plugin-upload/admin/src/components/SelectedAssets/SortableList.js +++ b/packages/strapi-plugin-upload/admin/src/components/SelectedAssets/SortableList.js @@ -1,6 +1,7 @@ import React from 'react'; import PropTypes from 'prop-types'; import { Checkbox } from '@buffetjs/core'; +import { get } from 'lodash'; import DraggableCard from './DraggableCard'; import CardControlsWrapper from '../CardControlsWrapper'; import ListWrapper from '../ListWrapper'; @@ -14,7 +15,8 @@ const SortableList = ({ data, moveAsset, onChange, onClickEditFile, selectedItem
{data.map((item, index) => { - const { id, url } = item; + const { id } = item; + const url = get(item, ['formats', 'thumbnail', 'url'], ''); const checked = selectedItems.findIndex(file => file.id === id) !== -1; const fileUrl = url.startsWith('/') ? `${strapi.backendURL}${url}` : url; diff --git a/packages/strapi-plugin-upload/admin/src/containers/HomePage/index.js b/packages/strapi-plugin-upload/admin/src/containers/HomePage/index.js index ec7ddc0d4d..23be6fedbb 100644 --- a/packages/strapi-plugin-upload/admin/src/containers/HomePage/index.js +++ b/packages/strapi-plugin-upload/admin/src/containers/HomePage/index.js @@ -71,6 +71,7 @@ const HomePage = () => { await request(requestURL, { method: 'DELETE', }); + strapi.notification.success('notification.success.delete'); } catch (err) { if (isMounted) { strapi.notification.error('notification.error'); @@ -79,6 +80,8 @@ const HomePage = () => { }; const fetchListData = async () => { + dispatch({ type: 'GET_DATA' }); + const [data, count] = await Promise.all([fetchData(), fetchDataCount()]); if (isMounted) { @@ -101,7 +104,10 @@ const HomePage = () => { return Promise.resolve(data); } catch (err) { - strapi.notification.error('notification.error'); + if (isMounted) { + dispatch({ type: 'GET_DATA_ERROR' }); + strapi.notification.error('notification.error'); + } } return []; @@ -118,6 +124,7 @@ const HomePage = () => { return Promise.resolve(count); } catch (err) { if (isMounted) { + dispatch({ type: 'GET_DATA_ERROR' }); strapi.notification.error('notification.error'); } } @@ -204,6 +211,28 @@ const HomePage = () => { }); }; + const handleDeleteMediaFromModal = async id => { + handleClickToggleModal(); + const overlayblockerParams = { + children:
, + noGradient: true, + }; + strapi.lockApp(overlayblockerParams); + + try { + await deleteMedia(id); + + dispatch({ + type: 'ON_DELETE_MEDIA_SUCCEEDED', + mediaId: id, + }); + } catch (err) { + // Silent + } finally { + strapi.unlockApp(); + } + }; + const handleDeleteMedias = async () => { await Promise.all(dataToDelete.map(item => deleteMedia(item.id))); @@ -333,7 +362,9 @@ const HomePage = () => { initialStep={modalInitialStep} isOpen={isModalOpen} onClosed={handleModalClose} + onDeleteMedia={handleDeleteMediaFromModal} onToggle={handleClickToggleModal} + refetchData={fetchListData} /> { switch (action.type) { case 'CLEAR_DATA_TO_DELETE': return state.update('dataToDelete', () => fromJS([])); + case 'GET_DATA': + return state.update('isLoading', () => true); + case 'GET_DATA_ERROR': + return state.update('isLoading', () => false); case 'GET_DATA_SUCCEEDED': return state .update('data', () => fromJS(action.data)) @@ -48,6 +52,10 @@ const reducer = (state, action) => { return dataToDelete.concat(newItems); }); } + case 'ON_DELETE_MEDIA_SUCCEEDED': + return state + .update('data', list => list.filter(item => item.get('id') !== action.mediaId)) + .update('dataCount', count => count - 1); default: return state; } diff --git a/packages/strapi-plugin-upload/admin/src/containers/HomePage/tests/reducer.test.js b/packages/strapi-plugin-upload/admin/src/containers/HomePage/tests/reducer.test.js index 72ee0c65b7..47bb708c9f 100644 --- a/packages/strapi-plugin-upload/admin/src/containers/HomePage/tests/reducer.test.js +++ b/packages/strapi-plugin-upload/admin/src/containers/HomePage/tests/reducer.test.js @@ -2,6 +2,44 @@ import { fromJS } from 'immutable'; import reducer, { initialState } from '../reducer'; describe('Upload | containers | HomePage | reducer', () => { + describe('GET_DATA', () => { + it('should set isLoading to true', () => { + const state = fromJS({ + isLoading: false, + test: true, + }); + const action = { + type: 'GET_DATA', + }; + + const expected = fromJS({ + isLoading: true, + test: true, + }); + + expect(reducer(state, action)).toEqual(expected); + }); + }); + + describe('GET_DATA_ERROR', () => { + it('should set isLoading to false', () => { + const state = fromJS({ + isLoading: true, + test: true, + }); + const action = { + type: 'GET_DATA_ERROR', + }; + + const expected = fromJS({ + isLoading: false, + test: true, + }); + + expect(reducer(state, action)).toEqual(expected); + }); + }); + it('should update data with received data', () => { const state = initialState; diff --git a/packages/strapi-plugin-upload/admin/src/containers/ModalStepper/index.js b/packages/strapi-plugin-upload/admin/src/containers/ModalStepper/index.js index f8eb8edde0..89e129ffa6 100644 --- a/packages/strapi-plugin-upload/admin/src/containers/ModalStepper/index.js +++ b/packages/strapi-plugin-upload/admin/src/containers/ModalStepper/index.js @@ -4,13 +4,20 @@ import { get } from 'lodash'; import { Modal, ModalFooter, PopUpWarning, useGlobalContext, request } from 'strapi-helper-plugin'; import { Button } from '@buffetjs/core'; import pluginId from '../../pluginId'; -import { getRequestUrl, getTrad } from '../../utils'; +import { getTrad } from '../../utils'; import ModalHeader from '../../components/ModalHeader'; import stepper from './stepper'; import init from './init'; import reducer, { initialState } from './reducer'; -const ModalStepper = ({ initialFileToEdit, initialStep, isOpen, onClosed, onToggle }) => { +const ModalStepper = ({ + initialFileToEdit, + initialStep, + isOpen, + onClosed, + onDeleteMedia, + onToggle, +}) => { const { formatMessage } = useGlobalContext(); const [isWarningDeleteOpen, setIsWarningDeleteOpen] = useState(false); const [shouldDeleteFile, setShouldDeleteFile] = useState(false); @@ -66,15 +73,15 @@ const ModalStepper = ({ initialFileToEdit, initialStep, isOpen, onClosed, onTogg }); }; - const handleCancelFileToUpload = fileIndex => { - const fileToCancel = get(filesToUpload, fileIndex, {}); + const handleCancelFileToUpload = fileOriginalIndex => { + const fileToCancel = filesToUpload.find(file => file.originalIndex === fileOriginalIndex); // Cancel upload fileToCancel.abortController.abort(); dispatch({ type: 'REMOVE_FILE_TO_UPLOAD', - fileIndex, + fileIndex: fileOriginalIndex, }); }; @@ -123,16 +130,7 @@ const ModalStepper = ({ initialFileToEdit, initialStep, isOpen, onClosed, onTogg if (shouldDeleteFile) { const { id } = fileToEdit; - try { - const requestURL = getRequestUrl(`files/${id}`); - - await request(requestURL, { method: 'DELETE' }); - - setShouldDeleteFile(false); - toggleRef.current(true); - } catch (err) { - console.log(err); - } + onDeleteMedia(id); } }; @@ -268,11 +266,13 @@ const ModalStepper = ({ initialFileToEdit, initialStep, isOpen, onClosed, onTogg null ); - dispatch({ - type: 'SET_FILE_ERROR', - fileIndex: originalIndex, - errorMessage, - }); + if (errorMessage) { + dispatch({ + type: 'SET_FILE_ERROR', + fileIndex: originalIndex, + errorMessage, + }); + } } } ); @@ -330,12 +330,12 @@ const ModalStepper = ({ initialFileToEdit, initialStep, isOpen, onClosed, onTogg onChange={handleChange} onClickCancelUpload={handleCancelFileToUpload} onClickDeleteFileToUpload={ - currentStep === 'edit-new' ? handleClickDeleteFileToUpload : handleClickDeleteFile + currentStep === 'edit' ? handleClickDeleteFile : handleClickDeleteFileToUpload } onClickEditNewFile={handleGoToEditNewFile} onGoToAddBrowseFiles={handleGoToAddBrowseFiles} onSubmitEdit={ - currentStep === 'edit-new' ? handleSubmitEditNewFile : handleSubmitEditExistingFile + currentStep === 'edit' ? handleSubmitEditExistingFile : handleSubmitEditNewFile } onToggle={handleToggle} toggleDisableForm={setIsFormDisabled} @@ -408,6 +408,7 @@ ModalStepper.defaultProps = { initialFileToEdit: null, initialStep: 'browse', onClosed: () => {}, + onDeleteMedia: () => {}, onToggle: () => {}, }; @@ -416,6 +417,7 @@ ModalStepper.propTypes = { initialStep: PropTypes.string, isOpen: PropTypes.bool.isRequired, onClosed: PropTypes.func, + onDeleteMedia: PropTypes.func, onToggle: PropTypes.func, }; diff --git a/packages/strapi-plugin-upload/admin/src/utils/formatFileForEditing.js b/packages/strapi-plugin-upload/admin/src/utils/formatFileForEditing.js index 6d905cbf00..d316c4ed7d 100644 --- a/packages/strapi-plugin-upload/admin/src/utils/formatFileForEditing.js +++ b/packages/strapi-plugin-upload/admin/src/utils/formatFileForEditing.js @@ -7,7 +7,7 @@ const formatFileForEditing = file => { abortController, id: file.id, file: { - ...pick(file, ['size', 'ext', 'width', 'height', 'url', 'mime', 'name']), + ...pick(file, ['size', 'ext', 'width', 'height', 'mime', 'name', 'url']), created_at: file.created_at || file.createdAt, }, fileInfo: pick(file, ['alternativeText', 'caption', 'name']), diff --git a/packages/strapi-plugin-upload/admin/src/utils/tests/formatFileForEditing.test.js b/packages/strapi-plugin-upload/admin/src/utils/tests/formatFileForEditing.test.js index 4a474117c3..a6d71b8ed8 100644 --- a/packages/strapi-plugin-upload/admin/src/utils/tests/formatFileForEditing.test.js +++ b/packages/strapi-plugin-upload/admin/src/utils/tests/formatFileForEditing.test.js @@ -19,8 +19,18 @@ describe('UPLOAD | utils | formatFileForEditing', () => { updated_at: '2020-03-23T11:43:46.729Z', alternativeText: 'test', id: 12, - formats: null, provider_metadata: null, + formats: { + thumbnail: { + hash: 'thumbnail_Screenshot_2020-03-26_at_13.09.24.png_df7f56f901', + ext: '.png', + mime: 'image/png', + width: 245, + height: 23, + size: 4.09, + url: '/uploads/thumbnail_Screenshot_2020-03-26_at_13.09.24.png_df7f56f901.png', + }, + }, }; const abortController = new AbortController(); @@ -68,7 +78,17 @@ describe('UPLOAD | utils | formatFileForEditing', () => { updated_at: '2020-03-23T11:43:46.729Z', alternativeText: 'test', id: 12, - formats: null, + formats: { + thumbnail: { + hash: 'thumbnail_Screenshot_2020-03-26_at_13.09.24.png_df7f56f901', + ext: '.png', + mime: 'image/png', + width: 245, + height: 23, + size: 4.09, + url: '/uploads/thumbnail_Screenshot_2020-03-26_at_13.09.24.png_df7f56f901.png', + }, + }, provider_metadata: null, }; const abortController = new AbortController();