Skip to content

Commit

Permalink
review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
jue-henry committed Nov 6, 2024
1 parent 13a1066 commit e667c90
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 20 deletions.
5 changes: 5 additions & 0 deletions src/components/ErrorToast.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ import {
dismissDeploymentsError,
selectCameraSerialNumberErrors,
dismissCameraSerialNumberError,
selectDeleteImagesErrors,
dismissDeleteImagesError,
} from '../features/tasks/tasksSlice';
import {
selectRedriveBatchErrors,
Expand Down Expand Up @@ -74,6 +76,7 @@ const ErrorToast = () => {
const manageLabelsErrors = useSelector(selectManageLabelsErrors);
const uploadErrors = useSelector(selectUploadErrors);
const cameraSerialNumberErrors = useSelector(selectCameraSerialNumberErrors);
const deleteImagesErrors = useSelector(selectDeleteImagesErrors);

const enrichedErrors = [
enrichErrors(labelsErrors, 'Label Error', 'labels'),
Expand All @@ -98,6 +101,7 @@ const ErrorToast = () => {
'Error Updating Camera Serial Number',
'cameraSerialNumber',
),
enrichErrors(deleteImagesErrors, 'Error Deleting Images', 'deleteImages'),
];

const errors = enrichedErrors.reduce(
Expand Down Expand Up @@ -161,6 +165,7 @@ const dismissErrorActions = {
manageLabels: (i) => dismissManageLabelsError(i),
upload: (i) => dismissUploadError(i),
cameraSerialNumber: (i) => dismissCameraSerialNumberError(i),
deleteImagesError: (i) => dismissDeleteImagesError(i),
};

function enrichErrors(errors, title, entity) {
Expand Down
2 changes: 1 addition & 1 deletion src/features/filters/FiltersPanelFooter.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ const FiltersPanelFooter = () => {
</DeleteImagesButton>
</TooltipTrigger>
<TooltipContent side="top" sideOffset={5}>
Delete all images shown
Delete all filtered images
<TooltipArrow />
</TooltipContent>
</Tooltip>
Expand Down
2 changes: 2 additions & 0 deletions src/features/images/imagesSlice.js
Original file line number Diff line number Diff line change
Expand Up @@ -345,9 +345,11 @@ export const deleteImages = (imageIds) => async (dispatch, getState) => {
);
dispatch(setSelectedImageIndices([]));
dispatch(deleteImagesSuccess(imageIds));
dispatch(setDeleteImagesAlertClose())
} catch (err) {
console.log(`error attempting to delete image: `, err);
dispatch(deleteImagesError(err));
dispatch(setDeleteImagesAlertClose())
}
};

Expand Down
5 changes: 2 additions & 3 deletions src/features/loupe/DeleteImagesAlert.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -73,14 +73,13 @@ const DeleteImagesAlert = () => {
return (
<Alert open={alertState.deleteImagesAlertOpen}>
<AlertPortal>
<AlertOverlay>
<AlertOverlay />
<AlertContent>
{isSpinnerActive && (
<SpinnerOverlay>
<SimpleSpinner />
</SpinnerOverlay>
)}
</AlertOverlay>
<AlertContent>
<AlertTitle>
{alertState.deleteImagesAlertByFilter ? filterText : selectionText}
</AlertTitle>
Expand Down
31 changes: 15 additions & 16 deletions src/features/tasks/tasksSlice.js
Original file line number Diff line number Diff line change
Expand Up @@ -413,18 +413,27 @@ export const fetchTask = (taskId) => {
DeleteImages: {
COMPLETE: (res) => {
dispatch(deleteImagesSuccess(res.task.output.imageIds));
dispatch(
setFocus({
index: { image: null, object: null, label: null },
type: 'auto',
}),
);
dispatch(setSelectedImageIndices([]));
dispatch(setDeleteImagesAlertClose());
},
FAIL: (res) => dispatch(deleteImagesFailure(res))
},
DeleteImagesByFilter: {
COMPLETE: (res) => {
dispatch(deleteImagesSuccess());
dispatch(deleteImagesSuccess([]));
dispatch(
setFocus({
index: { image: null, object: null, label: null },
type: 'auto',
}),
);
dispatch(setSelectedImageIndices([]));
dispatch(setDeleteImagesAlertClose());
dispatch(fetchImages(res.task.output.filters));
},
Expand Down Expand Up @@ -586,32 +595,22 @@ export const deleteImagesTask = (imageIds = [], filters = null, useFilters) => {
const token = currentUser.getSignInUserSession().getIdToken().getJwtToken();
const projects = getState().projects.projects;
const selectedProj = projects.find((proj) => proj.selected);
let res = null;
if (token && selectedProj) {
if (useFilters) {
res = await call({
const res = await call({
projId: selectedProj._id,
request: 'deleteImagesByFilterTask',
input: { filters },
});
dispatch(deleteImagesUpdate({ taskId: res.deleteImagesByFilterTask._id }));
} else {
res = await call({
const res = await call({
projId: selectedProj._id,
request: 'deleteImagesTask',
input: { imageIds },
});
dispatch(deleteImagesUpdate({ taskId: res.deleteImagesTask._id }));
}

console.log('deleteImages - res: ', res);
dispatch(deleteImagesUpdate({ taskId: res.deleteImagesTask._id }));
dispatch(
setFocus({
index: { image: null, object: null, label: null },
type: 'auto',
}),
);
dispatch(setSelectedImageIndices([]));
dispatch(setDeleteImagesAlertClose());
}
}
catch (err) {
Expand Down Expand Up @@ -639,6 +638,6 @@ export const selectCameraSerialNumberLoading = (state) =>
export const selectCameraSerialNumberErrors = (state) =>
state.tasks.loadingStates.cameraSerialNumber.errors;
export const selectDeleteImagesLoading = (state) => state.tasks.loadingStates.deleteImages;
export const selectDeleteImagesByFilterLoading = (state) => state.tasks.loadingStates.deleteImagesByFilter;
export const selectDeleteImagesErrors = (state) => state.tasks.loadingStates.deleteImages.errors;

export default tasksSlice.reducer;

0 comments on commit e667c90

Please sign in to comment.