diff --git a/client/modules/IDE/actions/assets.js b/client/modules/IDE/actions/assets.js index 95e51a332a..ed0b9751e4 100644 --- a/client/modules/IDE/actions/assets.js +++ b/client/modules/IDE/actions/assets.js @@ -2,6 +2,7 @@ import { apiClient } from '../../../utils/apiClient'; import * as ActionTypes from '../../../constants'; import { startLoader, stopLoader } from '../reducers/loading'; import { assetsActions } from '../reducers/assets'; +import { setProjectSavedTime } from './project'; const { setAssets, deleteAsset } = assetsActions; @@ -27,14 +28,24 @@ export function getAssets() { }; } -export function deleteAssetRequest(assetKey) { - return async (dispatch) => { +export function deleteAssetRequest(asset) { + return async (dispatch, getState) => { try { - const path = assetKey.split('/').pop(); - await apiClient.delete( - `/S3/delete?objectKey=${encodeURIComponent(path)}` + const response = await apiClient.delete( + `/projects/${asset.sketchId}/files/${asset.fileId}`, + { params: { parentId: asset.parentId } } ); - dispatch(deleteAsset(assetKey)); + dispatch(deleteAsset(asset.key)); + + const { project } = getState(); + if (project.id === asset.sketchId) { + dispatch(setProjectSavedTime(response.data.project.updatedAt)); + dispatch({ + type: ActionTypes.DELETE_FILE, + id: asset.fileId, + parentId: asset.parentId + }); + } } catch (error) { dispatch({ type: ActionTypes.ERROR diff --git a/client/modules/IDE/components/AssetListRow.jsx b/client/modules/IDE/components/AssetListRow.jsx index 97340db0c8..30f86d8257 100644 --- a/client/modules/IDE/components/AssetListRow.jsx +++ b/client/modules/IDE/components/AssetListRow.jsx @@ -13,9 +13,9 @@ const AssetMenu = ({ item: asset }) => { const dispatch = useDispatch(); const handleAssetDelete = () => { - const { key, name } = asset; + const { name } = asset; if (window.confirm(t('Common.DeleteConfirmation', { name }))) { - dispatch(deleteAssetRequest(key)); + dispatch(deleteAssetRequest(asset)); } }; @@ -33,7 +33,10 @@ AssetMenu.propTypes = { item: PropTypes.shape({ key: PropTypes.string.isRequired, url: PropTypes.string.isRequired, - name: PropTypes.string.isRequired + name: PropTypes.string.isRequired, + sketchId: PropTypes.string.isRequired, + fileId: PropTypes.string.isRequired, + parentId: PropTypes.string.isRequired }).isRequired }; @@ -62,8 +65,10 @@ AssetListRow.propTypes = { asset: PropTypes.shape({ key: PropTypes.string.isRequired, url: PropTypes.string.isRequired, - sketchId: PropTypes.string, + sketchId: PropTypes.string.isRequired, sketchName: PropTypes.string, + fileId: PropTypes.string.isRequired, + parentId: PropTypes.string.isRequired, name: PropTypes.string.isRequired, size: PropTypes.number.isRequired }).isRequired, diff --git a/server/controllers/aws.controller.js b/server/controllers/aws.controller.js index b6e03db13c..2c51dd78fb 100644 --- a/server/controllers/aws.controller.js +++ b/server/controllers/aws.controller.js @@ -111,9 +111,14 @@ export async function listObjectsInS3ForUser(userId) { project.files.some((file) => { if (!file.url) return false; if (file.url.includes(asset.key)) { + const parent = project.files.find((f) => + f.children.includes(file.id) + ); foundAsset.name = file.name; foundAsset.sketchName = project.name; foundAsset.sketchId = project.id; + foundAsset.fileId = file.id; + foundAsset.parentId = parent?.id; foundAsset.url = file.url; return true; }