Skip to content

Commit

Permalink
fix: csv page now closes on success
Browse files Browse the repository at this point in the history
  • Loading branch information
MacQSL committed Sep 9, 2024
1 parent 527ec77 commit 0ee218e
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 11 deletions.
2 changes: 1 addition & 1 deletion api/src/utils/logger.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ describe('logger', () => {
});
});

describe.only('setLogLevel', () => {
describe('setLogLevel', () => {
let currentLogLevel: string | undefined;

beforeEach(() => {
Expand Down
8 changes: 5 additions & 3 deletions app/src/components/file-upload/FileUploadItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -278,13 +278,15 @@ const FileUploadItem = (props: IFileUploadItemProps) => {
return (
<FileUploadItemContent
file={file}
status={status}
progress={progress}
error={error}
errorDetails={errorDetails}
enableErrorDetails={props.enableErrorDetails}
onCancel={() => setInitiateCancel(true)}
SubtextComponent={() => <Subtext file={file} status={status} progress={progress} error={error} />}
ActionButtonComponent={() => <MemoizedActionButton status={status} onCancel={() => setInitiateCancel(true)} />}
ProgressBarComponent={() => <MemoizedProgressBar status={status} progress={progress} />}
SubtextComponent={Subtext}
ActionButtonComponent={MemoizedActionButton as any}
ProgressBarComponent={MemoizedProgressBar as any}
/>
);
};
Expand Down
15 changes: 10 additions & 5 deletions app/src/components/file-upload/FileUploadItemContent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,13 @@ import FileUploadItemProgressBar from './FileUploadItemProgressBar';
import FileUploadItemSubtext from './FileUploadItemSubtext';

type FileUploadItemContentProps = Omit<IFileUploadItemProps, 'uploadHandler' | 'onSuccess' | 'fileHandler'> & {
/**
* The file upload status.
*
* @type {UploadFileStatus}
* @memberof FileUploadItemContentProps
*/
status: UploadFileStatus;
/**
* The progress of the file upload.
*
Expand All @@ -35,8 +42,6 @@ type FileUploadItemContentProps = Omit<IFileUploadItemProps, 'uploadHandler' | '
* @returns {*}
*/
export const FileUploadItemContent = (props: FileUploadItemContentProps) => {
const status = props.status ?? UploadFileStatus.PENDING;

/**
* Sensible defaults for the subtext, action button, and progress bar components.
*
Expand All @@ -48,7 +53,7 @@ export const FileUploadItemContent = (props: FileUploadItemContentProps) => {
return (
<ListItem
key={props.file.name}
secondaryAction={<ActionButton status={status} onCancel={props.onCancel} />}
secondaryAction={<ActionButton status={props.status} onCancel={props.onCancel} />}
sx={{
flexWrap: 'wrap',
borderStyle: 'solid',
Expand Down Expand Up @@ -77,7 +82,7 @@ export const FileUploadItemContent = (props: FileUploadItemContentProps) => {
</ListItemIcon>
<ListItemText
primary={props.file.name}
secondary={<Subtext file={props.file} status={status} progress={props.progress} error={props.error} />}
secondary={<Subtext file={props.file} status={props.status} progress={props.progress} error={props.error} />}
sx={{
'& .MuiListItemText-primary': {
fontWeight: 700
Expand All @@ -93,7 +98,7 @@ export const FileUploadItemContent = (props: FileUploadItemContentProps) => {
mb: 1
}
}}>
<ProgressBar status={status} progress={props.progress} />
<ProgressBar status={props.status} progress={props.progress} />
</Box>
{props.enableErrorDetails && (
<Box sx={{ mt: 1, ml: 5, width: '100%' }}>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { FileUploadSingleItem } from 'components/file-upload/FileUploadSingleIte
import PageHeader from 'components/layout/PageHeader';
import { useBiohubApi } from 'hooks/useBioHubApi';
import { useProjectContext, useSurveyContext } from 'hooks/useContext';
import { useUnsavedChangesDialog } from 'hooks/useUnsavedChangesDialog';
import { SKIP_CONFIRMATION_DIALOG, useUnsavedChangesDialog } from 'hooks/useUnsavedChangesDialog';
import { useCallback, useMemo, useState } from 'react';
import { Prompt, useHistory } from 'react-router';
import { Link as RouterLink } from 'react-router-dom';
Expand Down Expand Up @@ -136,14 +136,18 @@ export const CreateCSVCapturesPage = () => {
// If the Captures CSV upload failed, don't attempt to upload Measurements or Markings
if (captureUploadStatus !== UploadFileStatus.FAILED) {
// Measurements / Markings can be uploaded in parallel
await Promise.all([
const [measurementUploadStatus, markingUploadStatus] = await Promise.all([

Check warning on line 139 in app/src/features/surveys/animals/profile/captures/import-captures/CreateCSVCapturesPage.tsx

View check run for this annotation

Codecov / codecov/patch

app/src/features/surveys/animals/profile/captures/import-captures/CreateCSVCapturesPage.tsx#L139

Added line #L139 was not covered by tests
handleFileUpload('measurements', (file, onProgress) =>
biohubApi.survey.importMeasurementsFromCsv(file, projectId, surveyId, cancelToken, onProgress)

Check warning on line 141 in app/src/features/surveys/animals/profile/captures/import-captures/CreateCSVCapturesPage.tsx

View check run for this annotation

Codecov / codecov/patch

app/src/features/surveys/animals/profile/captures/import-captures/CreateCSVCapturesPage.tsx#L141

Added line #L141 was not covered by tests
),
handleFileUpload('markings', (file, onProgress) =>
biohubApi.survey.importMarkingsFromCsv(file, projectId, surveyId, cancelToken, onProgress)

Check warning on line 144 in app/src/features/surveys/animals/profile/captures/import-captures/CreateCSVCapturesPage.tsx

View check run for this annotation

Codecov / codecov/patch

app/src/features/surveys/animals/profile/captures/import-captures/CreateCSVCapturesPage.tsx#L144

Added line #L144 was not covered by tests
)
]);

if (measurementUploadStatus !== UploadFileStatus.FAILED || markingUploadStatus !== UploadFileStatus.FAILED) {
history.push(`/admin/projects/${projectId}/surveys/${surveyId}/animals`, SKIP_CONFIRMATION_DIALOG);

Check warning on line 149 in app/src/features/surveys/animals/profile/captures/import-captures/CreateCSVCapturesPage.tsx

View check run for this annotation

Codecov / codecov/patch

app/src/features/surveys/animals/profile/captures/import-captures/CreateCSVCapturesPage.tsx#L149

Added line #L149 was not covered by tests
}
}
};

Expand Down

0 comments on commit 0ee218e

Please sign in to comment.