Skip to content

Conversation

@gabrieltmonkai
Copy link
Contributor

@gabrieltmonkai gabrieltmonkai commented Oct 27, 2025

Overview

Jira Ticket Reference : MN-791

Use are take advantage of the delete image API to clean up the old images of an insight when a new one is taken.

Checklist before requesting a review

  • I have updated the unit tests based on the changes I made
  • I have updated the docs (TSDoc / README / global doc) to reflect my changes
  • I have updated the local app configs if needed
  • I have performed self-QA of my feature by testing the apps and packages and made sure that :
    • No regression or new bug has occurred
    • The acceptance criteria listed in the ticket are met
    • Self-QA was made on both desktop and mobile

Comment on lines 41 to 62
return;
}
const imagesToDelete = state.images.filter(
(image) => image.inspectionId === props.inspectionId && image.sightId === sightId,
);

console.log('Upload succeeded, proceeding to image cleanup.', { imagesToDelete });
if (imagesToDelete.length > 0) {
imagesToDelete.forEach((image) => {
deleteImage({ imageId: image.id, id: props.inspectionId })
.then(() => {
console.log(`Deleted image with id: ${image.id}`);
})
.catch((error) => {
console.error(`Failed to delete image with id: ${image.id}`, error);
});
});
}
}, []);

const onUploadTimeout = useCallback(() => {
console.log('Upload timed out and there has not been any image deletion.');
Copy link
Contributor

Choose a reason for hiding this comment

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

Remove the comments

* @param sightId The sight ID associated with the uploaded picture, if applicable.
*/
onUploadSuccess?: (durationMs: number) => void;
onUploadSuccess?: (durationMs: number, sightId?: string) => void;
Copy link
Contributor

Choose a reason for hiding this comment

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

Create a object as discussed

Copy link
Contributor

Choose a reason for hiding this comment

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

Add imageID aswell

console.log('Uploaded image has no sightId, skipping image cleanup.');
return;
}
const imagesToDelete = state.images.filter(
Copy link
Contributor

Choose a reason for hiding this comment

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

Check the state for other images that need to be deleted

}
}, []);

const onUploadTimeout = useCallback(() => {
Copy link
Contributor

Choose a reason for hiding this comment

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

Remove onUploadTimeout

@gabrieltmonkai gabrieltmonkai force-pushed the feat/MN-791/use-deleteImage-api branch 3 times, most recently from 8635cea to 89f213d Compare October 29, 2025 18:23
Reset state objects containing the deleted image

Updated objects to be deleted in State

Updated API export and added more tests

Added docs

Updated Tests

Added provisory getSortedImagesBySight function

Removed CleanupObserver

Added UploadSuccessPayload
@gabrieltmonkai gabrieltmonkai force-pushed the feat/MN-791/use-deleteImage-api branch from 89f213d to 6891e13 Compare November 3, 2025 09:12
cleanupEventHandlers: UploadEventHandlers;
}

function extractOtherImagesToDelete(imagesBySight: Record<string, Image[]>) {
Copy link
Contributor

Choose a reason for hiding this comment

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

could you specify the return type, as it is a best practice

return imagesToDelete;
}

function groupImagesBySightId(images: Image[], sightIdToSkip: string) {
Copy link
Contributor

Choose a reason for hiding this comment

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

could you specify the return type, as it is a best practice

}

/**
* Custom hook used to cleanup sights' images of the inspection by deleting the old ones
Copy link
Contributor

Choose a reason for hiding this comment

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

typo: remove apostrophe

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants