Skip to content

Commit

Permalink
Wire up error alerts for redriveBatch and exportErrors
Browse files Browse the repository at this point in the history
  • Loading branch information
nathanielrindlaub committed Dec 22, 2023
1 parent fc03e02 commit 11b2beb
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 10 deletions.
18 changes: 15 additions & 3 deletions src/components/ErrorAlerts.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,15 @@ import {
dismissImageContextError,
selectStatsErrors,
dismissStatsError,
selectExportErrors,
selectExportDataErrors,
dismissExportError,
} from '../features/images/imagesSlice';
import {
selectExportImageErrorsErrors,
dismissExportErrorsError,
selectRedriveBatchErrors,
dismissRedriveBatchError
} from '../features/upload/uploadSlice';
import getErrorContent from '../content/Errors';
import { selectManageUserErrors, dismissManageUsersError } from '../features/projects/usersSlice';

Expand All @@ -58,7 +64,9 @@ const ErrorAlerts = () => {
const imagesErrors = useSelector(selectImagesErrors);
const imageContextErrors = useSelector(selectImageContextErrors);
const statsErrors = useSelector(selectStatsErrors);
const exportErrors = useSelector(selectExportErrors);
const exportDataErrors = useSelector(selectExportDataErrors);
const exportImageErrorsErrors = useSelector(selectExportImageErrorsErrors);
const redriveBatchErrors = useSelector(selectRedriveBatchErrors);
const manageUserErrors = useSelector(selectManageUserErrors);
const createProjectErrors = useSelector(selectCreateProjectsErrors);

Expand All @@ -73,7 +81,9 @@ const ErrorAlerts = () => {
enrichErrors(imagesErrors, 'Image Error', 'images'),
enrichErrors(imageContextErrors, 'Image Error', 'imageContext'),
enrichErrors(statsErrors, 'Error Getting Stats', 'stats'),
enrichErrors(exportErrors, 'Error Exporting Data', 'data'),
enrichErrors(exportDataErrors, 'Error Exporting Data', 'data'),
enrichErrors(exportImageErrorsErrors, 'Error downloading errors CSV', 'uploadImageErrors'),
enrichErrors(redriveBatchErrors, 'Error retrying failed images in batch', 'redriveBatch'),
enrichErrors(manageUserErrors, 'Manage user error', 'manageUsers'),
enrichErrors(createProjectErrors, 'Error Creating Project', 'createProject'),
];
Expand Down Expand Up @@ -134,6 +144,8 @@ const dismissErrorActions = {
'imageContext': (i) => dismissImageContextError(i),
'stats': (i) => dismissStatsError(i),
'data': (i) => dismissExportError(i),
'uploadImageErrors': (i) => dismissExportErrorsError(i),
'redriveBatch': (i) => dismissRedriveBatchError(i),
'manageUsers': (i) => dismissManageUsersError(i),
};

Expand Down
2 changes: 1 addition & 1 deletion src/features/images/imagesSlice.js
Original file line number Diff line number Diff line change
Expand Up @@ -514,7 +514,7 @@ export const selectStatsLoading = state => state.images.loadingStates.stats;
export const selectStatsErrors = state => state.images.loadingStates.stats.errors;
export const selectExport = state => state.images.export;
export const selectExportLoading = state => state.images.loadingStates.export;
export const selectExportErrors = state => state.images.loadingStates.export.errors;
export const selectExportDataErrors = state => state.images.loadingStates.export.errors;
export const selectDeleteImagesAlertOpen = state => state.images.deleteImagesAlertOpen;

// TODO: find a different place for this?
Expand Down
12 changes: 10 additions & 2 deletions src/features/upload/BulkUploadTable.jsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React, { useState, useEffect } from 'react';
import { useDispatch, useSelector } from 'react-redux';
import { fetchBatches, stopBatch, exportErrors, getErrorsExportStatus, filterBatches, selectStopBatchLoading, selectRedriveBatchLoading, redriveBatch } from './uploadSlice';
import { fetchBatches, stopBatch, exportErrors, getErrorsExportStatus, filterBatches, selectStopBatchLoading, selectRedriveBatchLoading, redriveBatch, selectBatchStatesLoading } from './uploadSlice';
import { selectBatchStates, selectBatchPageInfo, selectErrorsExport, selectErrorsExportLoading, selectBatchFilter } from './uploadSlice';
import { styled, keyframes } from '@stitches/react';
import * as ToggleGroup from '@radix-ui/react-toggle-group';
Expand All @@ -9,6 +9,7 @@ import Button from '../../components/Button';
import IconButton from '../../components/IconButton.jsx';
import { ChevronLeftIcon, ChevronRightIcon, Cross2Icon, ExclamationTriangleIcon, ReloadIcon } from '@radix-ui/react-icons';
import { Tooltip, TooltipContent, TooltipArrow, TooltipTrigger } from '../../components/Tooltip.jsx';
import { SimpleSpinner, SpinnerOverlay } from '../../components/Spinner';


const Table = styled('table', {
Expand Down Expand Up @@ -91,6 +92,7 @@ const Error = styled('span', {
const BulkUploadTable = ({ percentUploaded }) => {
const { hasNext, hasPrevious } = useSelector(selectBatchPageInfo);
const batchStates = useSelector(selectBatchStates);
const batchStatesLoading = useSelector(selectBatchStatesLoading);
const errorsExport = useSelector(selectErrorsExport);
const errorsExportLoading = useSelector(selectErrorsExportLoading);
const stopBatchLoading = useSelector(selectStopBatchLoading);
Expand Down Expand Up @@ -148,7 +150,12 @@ const BulkUploadTable = ({ percentUploaded }) => {
}, [errorsExportReady, errorsExport, dispatch]);

return (
<div>
<div style={{ position: 'relative' }}>
{batchStatesLoading.isLoading &&
<SpinnerOverlay>
<SimpleSpinner/>
</SpinnerOverlay>
}
<CurrentCompletedToggle />
<Table>
<thead>
Expand Down Expand Up @@ -225,6 +232,7 @@ const BulkUploadTable = ({ percentUploaded }) => {
variant='ghost'
state={isRedrivingImages && 'loading'}
size='large'
css={{ color: '$errorText' }}
disabled={!(status['processing-complete'] && status['has-failed-images'])}
onClick={() => dispatch(redriveBatch(_id))}
>
Expand Down
16 changes: 12 additions & 4 deletions src/features/upload/uploadSlice.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ export const uploadSlice = createSlice({
fetchBatchesSuccess: (state, { payload }) => {
const { batches, pageInfo } = payload.batches.batches;
const ls = {
isLoading: true,
isLoading: false,
operation: null,
errors: null,
}
Expand Down Expand Up @@ -213,7 +213,6 @@ export const uploadSlice = createSlice({
};
},

// TODO: don't forget to wire up redriveBatch errors
redriveBatchFailure: (state, { payload }) => {
const ls = {
isLoading: false,
Expand All @@ -226,6 +225,11 @@ export const uploadSlice = createSlice({
};
},

dismissRedriveBatchError: (state, { payload }) => {
const index = payload;
state.loadingStates.redriveBatch.errors.splice(index, 1);
},

// export image errors

exportErrorsStart: (state, { payload }) => {
Expand Down Expand Up @@ -270,7 +274,6 @@ export const uploadSlice = createSlice({
}
},

// TODO: remember to wire up exportErrors errors
dismissExportErrorsError: (state, { payload }) => {
const index = payload;
state.loadingStates.errorsExport.errors.splice(index, 1);
Expand Down Expand Up @@ -308,6 +311,7 @@ export const {
redriveBatchStart,
redriveBatchSuccess,
redriveBatchFailure,
dismissRedriveBatchError,
exportErrorsStart,
exportErrorsSuccess,
exportErrorsUpdate,
Expand Down Expand Up @@ -480,6 +484,7 @@ export const fetchBatches = (page = 'current') => async (dispatch, getState) =>
const currentUser = await Auth.currentAuthenticatedUser();
const token = currentUser.getSignInUserSession().getIdToken().getJwtToken();
if (token) {
dispatch(fetchBatchesStart());
const projects = getState().projects.projects;
const selectedProj = projects.find((proj) => proj.selected);
const pageInfo = getState().uploads.pageInfo;
Expand Down Expand Up @@ -604,10 +609,13 @@ export const selectBatchStates = state => state.uploads.batchStates;
export const selectBatchFilter = state => state.uploads.filter;
export const selectBatchPageInfo = state => state.uploads.pageInfo;
export const selectUploadsLoading = state => state.uploads.loadingStates.upload;
export const selectBatchStatesLoading = state => state.uploads.loadingStates.batchStates;
export const selectErrorsExport = state => state.uploads.errorsExport;
export const selectErrorsExportLoading = state => state.uploads.loadingStates.errorsExport;
export const selectErrorsExportErrors = state => state.uploads.loadingStates.errorsExport.errors;
export const selectExportImageErrorsErrors = state => state.uploads.loadingStates.errorsExport.errors;
export const selectStopBatchLoading = state => state.uploads.loadingStates.stopBatch;
export const selectRedriveBatchLoading = state => state.uploads.loadingStates.redriveBatch;
export const selectRedriveBatchErrors = state => state.uploads.loadingStates.redriveBatch.errors;


export default uploadSlice.reducer;

0 comments on commit 11b2beb

Please sign in to comment.