mirror of
https://github.com/strapi/strapi.git
synced 2025-11-03 11:25:17 +00:00
Cancelling assets
This commit is contained in:
parent
2213d36f9c
commit
d7a2affe48
@ -53,7 +53,7 @@ const CancelButton = styled.button`
|
|||||||
}
|
}
|
||||||
`;
|
`;
|
||||||
|
|
||||||
export const UploadingAssetCard = ({ name, extension, assetType, file }) => {
|
export const UploadingAssetCard = ({ name, extension, assetType, file, onCancel }) => {
|
||||||
const { upload, cancel, error, progress } = useUpload();
|
const { upload, cancel, error, progress } = useUpload();
|
||||||
const { formatMessage } = useIntl();
|
const { formatMessage } = useIntl();
|
||||||
|
|
||||||
@ -78,9 +78,17 @@ export const UploadingAssetCard = ({ name, extension, assetType, file }) => {
|
|||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
upload(file);
|
upload(file);
|
||||||
|
|
||||||
|
return () => {
|
||||||
|
cancel();
|
||||||
|
};
|
||||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
|
const handleCancel = () => {
|
||||||
|
onCancel(file);
|
||||||
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Stack size={1}>
|
<Stack size={1}>
|
||||||
<Card borderColor={error ? 'danger600' : undefined}>
|
<Card borderColor={error ? 'danger600' : undefined}>
|
||||||
@ -97,11 +105,11 @@ export const UploadingAssetCard = ({ name, extension, assetType, file }) => {
|
|||||||
<>
|
<>
|
||||||
<Box paddingBottom={2}>
|
<Box paddingBottom={2}>
|
||||||
<ProgressBar value={progress} size="S">
|
<ProgressBar value={progress} size="S">
|
||||||
{progress}/100%
|
{`${progress}/100%`}
|
||||||
</ProgressBar>
|
</ProgressBar>
|
||||||
</Box>
|
</Box>
|
||||||
|
|
||||||
<CancelButton type="button" onClick={cancel}>
|
<CancelButton type="button" onClick={handleCancel}>
|
||||||
<Text small as="span" textColor="neutral200">
|
<Text small as="span" textColor="neutral200">
|
||||||
{formatMessage({
|
{formatMessage({
|
||||||
id: 'app.components.Button.cancel',
|
id: 'app.components.Button.cancel',
|
||||||
@ -142,4 +150,5 @@ UploadingAssetCard.propTypes = {
|
|||||||
extension: PropTypes.string.isRequired,
|
extension: PropTypes.string.isRequired,
|
||||||
name: PropTypes.string.isRequired,
|
name: PropTypes.string.isRequired,
|
||||||
file: PropTypes.instanceOf(File).isRequired,
|
file: PropTypes.instanceOf(File).isRequired,
|
||||||
|
onCancel: PropTypes.func.isRequired,
|
||||||
};
|
};
|
||||||
|
|||||||
@ -16,7 +16,7 @@ import { UploadingAssetCard } from '../../AssetCard/UploadingAssetCard';
|
|||||||
import { getTrad } from '../../../utils';
|
import { getTrad } from '../../../utils';
|
||||||
import { AssetType, AssetSource } from '../../../constants';
|
import { AssetType, AssetSource } from '../../../constants';
|
||||||
|
|
||||||
export const PendingAssetStep = ({ onClose, assets, onClickAddAsset }) => {
|
export const PendingAssetStep = ({ onClose, assets, onClickAddAsset, onCancelUpload }) => {
|
||||||
const { formatMessage } = useIntl();
|
const { formatMessage } = useIntl();
|
||||||
const [isUploading, setIsUploading] = useState(false);
|
const [isUploading, setIsUploading] = useState(false);
|
||||||
|
|
||||||
@ -79,6 +79,7 @@ export const PendingAssetStep = ({ onClose, assets, onClickAddAsset }) => {
|
|||||||
assetType={asset.type}
|
assetType={asset.type}
|
||||||
file={asset.rawFile}
|
file={asset.rawFile}
|
||||||
size="S"
|
size="S"
|
||||||
|
onCancel={onCancelUpload}
|
||||||
/>
|
/>
|
||||||
</GridItem>
|
</GridItem>
|
||||||
);
|
);
|
||||||
@ -173,4 +174,5 @@ PendingAssetStep.propTypes = {
|
|||||||
).isRequired,
|
).isRequired,
|
||||||
onClose: PropTypes.func.isRequired,
|
onClose: PropTypes.func.isRequired,
|
||||||
onClickAddAsset: PropTypes.func.isRequired,
|
onClickAddAsset: PropTypes.func.isRequired,
|
||||||
|
onCancelUpload: PropTypes.func.isRequired,
|
||||||
};
|
};
|
||||||
|
|||||||
@ -62,6 +62,7 @@ describe('PendingAssetStep', () => {
|
|||||||
onClose={jest.fn()}
|
onClose={jest.fn()}
|
||||||
onAddAsset={jest.fn()}
|
onAddAsset={jest.fn()}
|
||||||
onClickAddAsset={jest.fn()}
|
onClickAddAsset={jest.fn()}
|
||||||
|
onCancelUpload={jest.fn()}
|
||||||
/>
|
/>
|
||||||
</ThemeProvider>
|
</ThemeProvider>
|
||||||
</QueryClientProvider>
|
</QueryClientProvider>
|
||||||
|
|||||||
@ -23,13 +23,28 @@ export const UploadAssetDialog = ({ onSuccess, onClose }) => {
|
|||||||
setStep(Steps.AddAsset);
|
setStep(Steps.AddAsset);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const handleCancelUpload = file => {
|
||||||
|
const nextAssets = assets.filter(asset => asset.rawFile !== file);
|
||||||
|
setAssets(nextAssets);
|
||||||
|
|
||||||
|
// When there's no asset, transition to the AddAsset step
|
||||||
|
if (nextAssets.length === 0) {
|
||||||
|
moveToAddAsset();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<ModalLayout onClose={onClose} labelledBy="title">
|
<ModalLayout onClose={onClose} labelledBy="title">
|
||||||
{step === Steps.AddAsset && (
|
{step === Steps.AddAsset && (
|
||||||
<AddAssetStep onClose={onClose} onAddAsset={handleAddToPendingAssets} />
|
<AddAssetStep onClose={onClose} onAddAsset={handleAddToPendingAssets} />
|
||||||
)}
|
)}
|
||||||
{step === Steps.PendingAsset && (
|
{step === Steps.PendingAsset && (
|
||||||
<PendingAssetStep onClose={onClose} assets={assets} onClickAddAsset={moveToAddAsset} />
|
<PendingAssetStep
|
||||||
|
onClose={onClose}
|
||||||
|
assets={assets}
|
||||||
|
onClickAddAsset={moveToAddAsset}
|
||||||
|
onCancelUpload={handleCancelUpload}
|
||||||
|
/>
|
||||||
)}
|
)}
|
||||||
</ModalLayout>
|
</ModalLayout>
|
||||||
);
|
);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user