Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 22 additions & 7 deletions client/modules/IDE/actions/assets.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,29 @@ 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)}`
Comment thread
yugalkaushik marked this conversation as resolved.
);
dispatch(deleteAsset(assetKey));
if (asset.sketchId) {
await apiClient.delete(
`/projects/${asset.sketchId}/files/${asset.fileId}`,
{ params: { parentId: asset.parentId } }
);

const { project } = getState();
if (project.id === asset.sketchId) {
dispatch({
type: ActionTypes.DELETE_FILE,
id: asset.fileId,
parentId: asset.parentId
});
}
} else {
await apiClient.delete('/S3/delete', {
params: { objectKey: asset.key }
});
}
Comment on lines +38 to +51

@skyash-dev skyash-dev Jun 11, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we can remove this. unlike deleteFile, there's no need to reactively update local state here since the user is on a different screen, and returning to the sketch will load the latest data anyway.

edit: also getState() returns the currently open project state, which may not even be the project associated with the asset being deleted.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Regarding getState, it's still present solely for the DELETE_FILE dispatch, which is guarded by if (project.id === asset.sketchId). This ensures that when a user deletes a referenced asset from the Assets tab while on the same sketch, the file tree sidebar updates immediately without requiring a page refresh. When the user is viewing a different sketch, the guard prevents any action. So getState is safe and necessary for this reactive UI update.

dispatch(deleteAsset(asset.key));
} catch (error) {
dispatch({
type: ActionTypes.ERROR
Expand Down
11 changes: 8 additions & 3 deletions client/modules/IDE/components/AssetListRow.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
};

Expand All @@ -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,
fileId: PropTypes.string,
parentId: PropTypes.string
}).isRequired
};

Expand Down Expand Up @@ -64,6 +67,8 @@ AssetListRow.propTypes = {
url: PropTypes.string.isRequired,
sketchId: PropTypes.string,
sketchName: PropTypes.string,
fileId: PropTypes.string,
parentId: PropTypes.string,
name: PropTypes.string.isRequired,
size: PropTypes.number.isRequired
}).isRequired,
Expand Down
5 changes: 5 additions & 0 deletions server/controllers/aws.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
Loading