-
Notifications
You must be signed in to change notification settings - Fork 13
Use Delete Image API to clean up previous images #950
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
packages/inspection-capture-web/src/PhotoCapture/PhotoCapture.tsx
Outdated
Show resolved
Hide resolved
| 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.'); |
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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( |
There was a problem hiding this comment.
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(() => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove onUploadTimeout
8635cea to
89f213d
Compare
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
89f213d to
6891e13
Compare
| cleanupEventHandlers: UploadEventHandlers; | ||
| } | ||
|
|
||
| function extractOtherImagesToDelete(imagesBySight: Record<string, Image[]>) { |
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
typo: remove apostrophe
Overview
Jira Ticket Reference : MN-791
Use are take advantage of the
delete imageAPI to clean up the old images of an insight when a new one is taken.Checklist before requesting a review