Fix ML feebacks from QA (#11495)

This commit is contained in:
Marvin Frachet 2021-11-08 13:59:36 +01:00 committed by GitHub
parent c603300234
commit ada4fdec18
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 123 additions and 122 deletions

View File

@ -73,11 +73,11 @@ export const PreviewBox = ({
const nextAsset = { ...asset, width, height }; const nextAsset = { ...asset, width, height };
const file = await produceFile(nextAsset.name, nextAsset.mime, nextAsset.updatedAt); const file = await produceFile(nextAsset.name, nextAsset.mime, nextAsset.updatedAt);
await editAsset(nextAsset, file); const updatedAsset = await editAsset(nextAsset, file);
// Making sure that when persisting the new asset, the URL changes with width and height // Making sure that when persisting the new asset, the URL changes with width and height
// So that the browser makes a request and handle the image caching correctly at the good size // So that the browser makes a request and handle the image caching correctly at the good size
const optimizedCachingImage = createAssetUrl(asset); const optimizedCachingImage = createAssetUrl(updatedAsset);
setAssetUrl(optimizedCachingImage); setAssetUrl(optimizedCachingImage);
stopCropping(); stopCropping();

View File

@ -1,4 +1,4 @@
import React, { useState } from 'react'; import React from 'react';
import PropTypes from 'prop-types'; import PropTypes from 'prop-types';
import { CarouselActions } from '@strapi/design-system/Carousel'; import { CarouselActions } from '@strapi/design-system/Carousel';
import { IconButton } from '@strapi/design-system/IconButton'; import { IconButton } from '@strapi/design-system/IconButton';
@ -10,78 +10,47 @@ import PencilIcon from '@strapi/icons/Pencil';
import getTrad from '../../../utils/getTrad'; import getTrad from '../../../utils/getTrad';
import { CopyLinkButton } from '../../CopyLinkButton'; import { CopyLinkButton } from '../../CopyLinkButton';
import { AssetDefinition } from '../../../constants'; import { AssetDefinition } from '../../../constants';
import { EditAssetDialog } from '../../EditAssetDialog';
export const CarouselAssetActions = ({ export const CarouselAssetActions = ({ asset, onDeleteAsset, onAddAsset, onEditAsset }) => {
asset,
onDeleteAsset,
onDeleteAssetFromMediaLibrary,
onAddAsset,
onEditAsset,
}) => {
const { formatMessage } = useIntl(); const { formatMessage } = useIntl();
const [isEditDialogOpened, setEditDialogOpened] = useState(false);
return ( return (
<> <CarouselActions>
<CarouselActions> {onAddAsset && (
{onAddAsset && ( <IconButton
<IconButton label={formatMessage({
label={formatMessage({ id: getTrad('control-card.add'),
id: getTrad('control-card.add'), defaultMessage: 'Add',
defaultMessage: 'Add', })}
})} icon={<PlusIcon />}
icon={<PlusIcon />} onClick={() => onAddAsset(asset)}
onClick={() => onAddAsset(asset)}
/>
)}
<CopyLinkButton url={prefixFileUrlWithBackendUrl(asset.url)} />
{onDeleteAsset && (
<IconButton
label={formatMessage({
id: getTrad('app.utils.delete'),
defaultMessage: 'Delete',
})}
icon={<TrashIcon />}
onClick={() => onDeleteAsset(asset)}
/>
)}
{onEditAsset && (
<IconButton
label={formatMessage({
id: getTrad('app.utils.edit'),
defaultMessage: 'edit',
})}
icon={<PencilIcon />}
onClick={() => setEditDialogOpened(true)}
/>
)}
</CarouselActions>
{isEditDialogOpened && (
<EditAssetDialog
onClose={editedAsset => {
setEditDialogOpened(false);
// The asset has been deleted
if (editedAsset === null) {
onDeleteAssetFromMediaLibrary();
}
if (editedAsset) {
onEditAsset(editedAsset);
}
}}
asset={asset}
canUpdate
canCopyLink
canDownload
/> />
)} )}
</>
<CopyLinkButton url={prefixFileUrlWithBackendUrl(asset.url)} />
{onDeleteAsset && (
<IconButton
label={formatMessage({
id: getTrad('app.utils.delete'),
defaultMessage: 'Delete',
})}
icon={<TrashIcon />}
onClick={() => onDeleteAsset(asset)}
/>
)}
{onEditAsset && (
<IconButton
label={formatMessage({
id: getTrad('app.utils.edit'),
defaultMessage: 'edit',
})}
icon={<PencilIcon />}
onClick={onEditAsset}
/>
)}
</CarouselActions>
); );
}; };
@ -96,5 +65,4 @@ CarouselAssetActions.propTypes = {
onAddAsset: PropTypes.func, onAddAsset: PropTypes.func,
onEditAsset: PropTypes.func, onEditAsset: PropTypes.func,
onDeleteAsset: PropTypes.func, onDeleteAsset: PropTypes.func,
onDeleteAssetFromMediaLibrary: PropTypes.func.isRequired,
}; };

View File

@ -1,4 +1,4 @@
import React from 'react'; import React, { useState } from 'react';
import PropTypes from 'prop-types'; import PropTypes from 'prop-types';
import { useIntl } from 'react-intl'; import { useIntl } from 'react-intl';
import { Carousel, CarouselSlide } from '@strapi/design-system/Carousel'; import { Carousel, CarouselSlide } from '@strapi/design-system/Carousel';
@ -7,6 +7,7 @@ import { AssetDefinition } from '../../../constants';
import { CarouselAssetActions } from './CarouselAssetActions'; import { CarouselAssetActions } from './CarouselAssetActions';
import { CarouselAsset } from './CarouselAsset'; import { CarouselAsset } from './CarouselAsset';
import { EmptyStateAsset } from './EmptyStateAsset'; import { EmptyStateAsset } from './EmptyStateAsset';
import { EditAssetDialog } from '../../EditAssetDialog';
export const CarouselAssets = ({ export const CarouselAssets = ({
assets, assets,
@ -24,65 +25,89 @@ export const CarouselAssets = ({
selectedAssetIndex, selectedAssetIndex,
}) => { }) => {
const { formatMessage } = useIntl(); const { formatMessage } = useIntl();
const [isEditingAsset, setIsEditingAsset] = useState(false);
const currentAsset = assets[selectedAssetIndex]; const currentAsset = assets[selectedAssetIndex];
return ( return (
<Carousel <>
label={label} <Carousel
selectedSlide={selectedAssetIndex} label={label}
previousLabel={formatMessage({ selectedSlide={selectedAssetIndex}
id: getTrad('mediaLibraryInput.actions.previousSlide'), previousLabel={formatMessage({
defaultMessage: 'Previous slide', id: getTrad('mediaLibraryInput.actions.previousSlide'),
})} defaultMessage: 'Previous slide',
nextLabel={formatMessage({ })}
id: getTrad('mediaLibraryInput.actions.nextSlide'), nextLabel={formatMessage({
defaultMessage: 'Next slide', id: getTrad('mediaLibraryInput.actions.nextSlide'),
})} defaultMessage: 'Next slide',
onNext={onNext} })}
onPrevious={onPrevious} onNext={onNext}
hint={hint} onPrevious={onPrevious}
error={error} hint={hint}
actions={ error={error}
currentAsset ? ( actions={
<CarouselAssetActions currentAsset ? (
asset={currentAsset} <CarouselAssetActions
onDeleteAsset={disabled ? undefined : onDeleteAsset} asset={currentAsset}
onDeleteAssetFromMediaLibrary={onDeleteAssetFromMediaLibrary} onDeleteAsset={disabled ? undefined : onDeleteAsset}
onAddAsset={disabled ? undefined : onAddAsset} onDeleteAssetFromMediaLibrary={onDeleteAssetFromMediaLibrary}
onEditAsset={onEditAsset} onAddAsset={disabled ? undefined : onAddAsset}
/> onEditAsset={onEditAsset ? () => setIsEditingAsset(true) : undefined}
) : ( />
undefined ) : (
) undefined
} )
> }
{assets.length === 0 ? ( >
<CarouselSlide {assets.length === 0 ? (
label={formatMessage(
{ id: getTrad('mediaLibraryInput.slideCount'), defaultMessage: '{n} of {m} slides' },
{ n: 1, m: 1 }
)}
>
<EmptyStateAsset disabled={disabled} onClick={onAddAsset} onDropAsset={onDropAsset} />
</CarouselSlide>
) : (
assets.map((asset, index) => (
<CarouselSlide <CarouselSlide
key={asset.id}
label={formatMessage( label={formatMessage(
{ { id: getTrad('mediaLibraryInput.slideCount'), defaultMessage: '{n} of {m} slides' },
id: getTrad('mediaLibraryInput.slideCount'), { n: 1, m: 1 }
defaultMessage: '{n} of {m} slides',
},
{ n: index + 1, m: assets.length }
)} )}
> >
<CarouselAsset asset={asset} /> <EmptyStateAsset disabled={disabled} onClick={onAddAsset} onDropAsset={onDropAsset} />
</CarouselSlide> </CarouselSlide>
)) ) : (
assets.map((asset, index) => (
<CarouselSlide
key={asset.id}
label={formatMessage(
{
id: getTrad('mediaLibraryInput.slideCount'),
defaultMessage: '{n} of {m} slides',
},
{ n: index + 1, m: assets.length }
)}
>
<CarouselAsset asset={asset} />
</CarouselSlide>
))
)}
</Carousel>
{isEditingAsset && (
<EditAssetDialog
onClose={editedAsset => {
setIsEditingAsset(false);
// The asset has been deleted
if (editedAsset === null) {
onDeleteAssetFromMediaLibrary();
}
if (editedAsset) {
onEditAsset(editedAsset);
}
}}
asset={currentAsset}
canUpdate
canCopyLink
canDownload
/>
)} )}
</Carousel> </>
); );
}; };

View File

@ -11,7 +11,15 @@ const uploadAsset = (file, cancelToken, onProgress) => {
const formData = new FormData(); const formData = new FormData();
formData.append('files', file); formData.append('files', file);
formData.append('fileInfo', JSON.stringify(file));
formData.append(
'fileInfo',
JSON.stringify({
alternativeText: file.name,
caption: file.name,
name: file.name,
})
);
return axiosInstance({ return axiosInstance({
method: 'post', method: 'post',

View File

@ -19,7 +19,7 @@ const multiUploadSchema = yup.object({
const validateUploadBody = (data = {}, isMulti = false) => { const validateUploadBody = (data = {}, isMulti = false) => {
const schema = isMulti ? multiUploadSchema : uploadSchema; const schema = isMulti ? multiUploadSchema : uploadSchema;
return validateYupSchema(schema)(data); return validateYupSchema(schema, { strict: false })(data);
}; };
module.exports = validateUploadBody; module.exports = validateUploadBody;