Skip to content

Commit

Permalink
adding error handling and 200k limit text
Browse files Browse the repository at this point in the history
  • Loading branch information
jue-henry committed Dec 11, 2024
1 parent 811b97d commit 839bdd8
Show file tree
Hide file tree
Showing 6 changed files with 61 additions and 25 deletions.
7 changes: 6 additions & 1 deletion src/components/ErrorToast.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import {
selectManageLabelsErrors,
dismissManageLabelsError,
selectProjectTagErrors,
dismissProjectTagErrors
dismissProjectTagErrors,
} from '../features/projects/projectsSlice';
import {
selectWirelessCamerasErrors,
Expand All @@ -46,6 +46,8 @@ import {
dismissDeploymentsError,
selectCameraSerialNumberErrors,
dismissCameraSerialNumberError,
selectDeleteCameraErrors,
dismissDeleteCameraError,
selectDeleteImagesErrors,
dismissDeleteImagesError,
} from '../features/tasks/tasksSlice';
Expand Down Expand Up @@ -81,6 +83,7 @@ const ErrorToast = () => {
const manageLabelsErrors = useSelector(selectManageLabelsErrors);
const uploadErrors = useSelector(selectUploadErrors);
const cameraSerialNumberErrors = useSelector(selectCameraSerialNumberErrors);
const deleteCameraErrors = useSelector(selectDeleteCameraErrors);
const projectTagErrors = useSelector(selectProjectTagErrors);
const deleteImagesErrors = useSelector(selectDeleteImagesErrors);

Expand Down Expand Up @@ -109,6 +112,7 @@ const ErrorToast = () => {
'Error Updating Camera Serial Number',
'cameraSerialNumber',
),
enrichErrors(deleteCameraErrors, 'Error Deleting Camera', 'deleteCamera'),
enrichErrors(deleteImagesErrors, 'Error Deleting Images', 'deleteImages'),
];

Expand Down Expand Up @@ -175,6 +179,7 @@ const dismissErrorActions = {
manageLabels: (i) => dismissManageLabelsError(i),
upload: (i) => dismissUploadError(i),
cameraSerialNumber: (i) => dismissCameraSerialNumberError(i),
deleteCamera: (i) => dismissDeleteCameraError(i),
deleteImagesError: (i) => dismissDeleteImagesError(i),
};

Expand Down
2 changes: 2 additions & 0 deletions src/components/HydratedModal.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import {
selectCameraSerialNumberLoading,
clearCameraSerialNumberTask,
selectDeleteImagesLoading,
clearDeleteCameraTask,
} from '../features/tasks/tasksSlice.js';
import {
selectModalOpen,
Expand Down Expand Up @@ -130,6 +131,7 @@ const HydratedModal = () => {
content: <DeleteCameraForm />,
callBackOnClose: () => {
dispatch(setSelectedCamera(null));
dispatch(clearDeleteCameraTask());
},
},
'manage-tags-and-labels-form': {
Expand Down
2 changes: 1 addition & 1 deletion src/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export const API_URL = API_URLS[stage];
export const IMAGES_URL = IMAGES_URLS[stage];
export const IMAGE_QUERY_LIMITS = [10, 50, 100];
export const SYNC_IMAGE_DELETE_LIMIT = 300; // when deleting w/o using task handler
export const ASYNC_IMAGE_DELETE_BY_ID_LIMIT = 4000; // when deleting using task handler (by _id). Constrained by POST request size limits
export const ASYNC_IMAGE_DELETE_BY_ID_LIMIT = 3000; // when deleting using task handler (by _id). Constrained by POST request size limits
export const ASYNC_IMAGE_DELETE_BY_FILTER_LIMIT = 200000; // when deleting using task handler (by filter). Constrained by task Lambda timeout

export const SUPPORTED_WIRELESS_CAMS = ['BuckEyeCam', 'RidgeTec', 'CUDDEBACK', 'RECONYX'];
Expand Down
59 changes: 39 additions & 20 deletions src/features/cameras/DeleteCameraForm.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
selectCameraImageCount,
selectCameraImageCountLoading,
} from '../cameras/wirelessCamerasSlice.js';
import { ASYNC_IMAGE_DELETE_BY_FILTER_LIMIT } from '../../config.js';

const BoldText = styled('span', {
fontWeight: '$5',
Expand Down Expand Up @@ -70,26 +71,44 @@ const DeleteCameraForm = ({ handleClose }) => {
handleDeleteCameraSubmit(values);
}}
>
{() => (
<Form>
<HelperText>
Are you sure you&apos;d like to delete Camera <BoldText>{selectedCamera}</BoldText>?
This will remove the camera from the project, remove all deployments associated with
it, and <BoldText>{imagesText}</BoldText> will be deleted.{' '}
<BoldText>This action cannot be undone.</BoldText>
</HelperText>
<Field name="cameraId" type="hidden" />
<Field name="deploymentId" type="hidden" />
<ButtonRow>
<Button type="button" size="large" onClick={handleClose}>
Cancel
</Button>
<Button type="submit" size="large">
Delete Camera
</Button>
</ButtonRow>
</Form>
)}
{() =>
imageCount > ASYNC_IMAGE_DELETE_BY_FILTER_LIMIT ? (
<Form>
<HelperText>
Due to the large number of images associated with this camera, we are unable to
delete Camera <BoldText>{selectedCamera}</BoldText> at this time. Please ensure
that the number of images associated with this camera do not exceed{' '}
{ASYNC_IMAGE_DELETE_BY_FILTER_LIMIT} before trying again. We apologize for the
inconvenience.
</HelperText>
<ButtonRow>
<Button type="button" size="large" onClick={handleClose}>
Cancel
</Button>
</ButtonRow>
</Form>
) : (
<Form>
<HelperText>
Are you sure you&apos;d like to delete Camera{' '}
<BoldText>{selectedCamera}</BoldText>? This will remove the camera from the
project, remove all deployments associated with it, and{' '}
<BoldText>{imagesText}</BoldText> will be deleted.{' '}
<BoldText>This action cannot be undone.</BoldText>
</HelperText>
<Field name="cameraId" type="hidden" />
<Field name="deploymentId" type="hidden" />
<ButtonRow>
<Button type="button" size="large" onClick={handleClose}>
Cancel
</Button>
<Button type="submit" size="large">
Delete Camera
</Button>
</ButtonRow>
</Form>
)
}
</Formik>
</FormWrapper>
</div>
Expand Down
13 changes: 11 additions & 2 deletions src/features/images/DeleteImagesAlert.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,12 @@ import {
} from '../../components/AlertDialog.jsx';
import Button from '../../components/Button.jsx';
import { red, green } from '@radix-ui/colors';
import { deleteImagesTask, fetchTask, selectDeleteImagesLoading } from '../tasks/tasksSlice.js';
import {
clearDeleteImagesTask,
deleteImagesTask,
fetchTask,
selectDeleteImagesLoading,
} from '../tasks/tasksSlice.js';
import {
SYNC_IMAGE_DELETE_LIMIT,
ASYNC_IMAGE_DELETE_BY_ID_LIMIT,
Expand Down Expand Up @@ -91,7 +96,10 @@ const DeleteImagesAlert = () => {
dispatch(deleteImages(selectedImageIds));
}
}
if (selectedImages.length > 3000 || imageCount > 3000) {
if (
selectedImages.length > ASYNC_IMAGE_DELETE_BY_ID_LIMIT ||
imageCount > ASYNC_IMAGE_DELETE_BY_ID_LIMIT
) {
// show progress bar if deleting more than 3000 images (approx wait time will be > 10 seconds)
const count = !alertState.deleteImagesAlertByFilter ? selectedImages.length : imageCount;
setEstimatedTotalTime(count * 0.0055); // estimated deletion time per image in seconds
Expand All @@ -118,6 +126,7 @@ const DeleteImagesAlert = () => {

const handleCancelDelete = () => {
dispatch(setDeleteImagesAlertStatus({ openStatus: false }));
dispatch(clearDeleteImagesTask());
};

const deleteByIdLimitExceeded =
Expand Down
3 changes: 2 additions & 1 deletion src/features/tasks/tasksSlice.js
Original file line number Diff line number Diff line change
Expand Up @@ -659,7 +659,7 @@ export const deleteCamera = (payload) => {
dispatch(updateDeleteCameraUpdate({ taskId: res.deleteCameraConfig._id }));
}
} catch (err) {
console.log('error attempting to delete camera: ', err);
dispatch(updateDeleteCameraFailure(err));
}
};
};
Expand Down Expand Up @@ -719,6 +719,7 @@ export const selectCameraSerialNumberLoading = (state) =>
export const selectCameraSerialNumberErrors = (state) =>
state.tasks.loadingStates.cameraSerialNumber.errors;
export const selectDeleteCameraLoading = (state) => state.tasks.loadingStates.deleteCamera;
export const selectDeleteCameraErrors = (state) => state.tasks.loadingStates.deleteCamera.errors;
export const selectDeleteImagesLoading = (state) => state.tasks.loadingStates.deleteImages;
export const selectDeleteImagesErrors = (state) => state.tasks.loadingStates.deleteImages.errors;

Expand Down

0 comments on commit 839bdd8

Please sign in to comment.