Skip to content

Commit

Permalink
Add missing JSDoc.
Browse files Browse the repository at this point in the history
Fix project/survey regular attachments error display (shows error in the list, not as a popup).
  • Loading branch information
NickPhura committed Sep 18, 2024
1 parent 259a0bc commit 6150161
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 44 deletions.
5 changes: 5 additions & 0 deletions app/src/components/attachments/FileUploadWithMeta.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ import { FileUploadSingleItem } from 'components/file-upload/FileUploadSingleIte
import { AttachmentTypeFileExtensions } from 'constants/attachments';
import { useFormikContext } from 'formik';

/**
* File upload with meta form. Used to upload a report with accompanying meta data.
*
* @return {*}
*/
export const FileUploadWithMeta = () => {
const { handleSubmit, setFieldValue, setFieldError, values, errors } = useFormikContext<IReportMetaForm>();

Check warning on line 15 in app/src/components/attachments/FileUploadWithMeta.tsx

View check run for this annotation

Codecov / codecov/patch

app/src/components/attachments/FileUploadWithMeta.tsx#L15

Added line #L15 was not covered by tests

Expand Down
2 changes: 2 additions & 0 deletions app/src/components/dialog/attachments/FileUploadDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ interface IFileUploadDialogProps extends IComponentDialogProps {
}

/**
* Wraps the standard `FileUpload` component in a dialog.
*
* The wrapped `FileUpload` component allows for drag-and-drop file uploads of any number of files with any file type.
*
* @param {IFileUploadDialogProps} props
* @return {*}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,7 @@ export interface IReportFileUploadDialogProps {
}

/**
* A dialog to wrap any component(s) that need to be displayed as a modal.
*
* Any component(s) passed in `props.children` will be rendered as the content of the dialog.
* Wraps the `FileUploadWithMeta` component in a dialog.
*
* @param {*} props
* @return {*}
Expand Down
24 changes: 3 additions & 21 deletions app/src/features/projects/view/ProjectAttachments.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { FileUploadDialog } from 'components/dialog/attachments/FileUploadDialog
import { ReportFileUploadDialog } from 'components/dialog/attachments/ReportFileUploadDialog';
import { ProjectRoleGuard } from 'components/security/Guards';
import { H2MenuToolbar } from 'components/toolbar/ActionToolbars';
import { AttachmentsI18N, ReportI18N } from 'constants/i18n';
import { ReportI18N } from 'constants/i18n';
import { PROJECT_PERMISSION, SYSTEM_ROLE } from 'constants/roles';
import { ProjectContext } from 'contexts/projectContext';
import { APIError } from 'hooks/api/useAxios';
Expand All @@ -18,7 +18,7 @@ import { useContext, useEffect, useState } from 'react';
import ProjectAttachmentsList from './ProjectAttachmentsList';

/**
* Project attachments content for a project.
* Project attachments component.
*
* @return {*}
*/
Expand Down Expand Up @@ -53,25 +53,7 @@ const ProjectAttachments = () => {
};

const handleUploadAttachments = async (file: File) => {
try {
await biohubApi.project.uploadProjectAttachments(projectContext.projectId, file);
} catch (error) {
const apiError = error as APIError;

dialogContext.setErrorDialog({
open: true,
dialogTitle: AttachmentsI18N.uploadErrorTitle,
dialogText: AttachmentsI18N.uploadErrorText,
dialogError: apiError.message,
dialogErrorDetails: apiError.errors,
onClose: () => {
dialogContext.setErrorDialog({ open: false });
},
onOk: () => {
dialogContext.setErrorDialog({ open: false });
}
});
}
return biohubApi.project.uploadProjectAttachments(projectContext.projectId, file);

Check warning on line 56 in app/src/features/projects/view/ProjectAttachments.tsx

View check run for this annotation

Codecov / codecov/patch

app/src/features/projects/view/ProjectAttachments.tsx#L56

Added line #L56 was not covered by tests
};

useEffect(() => {
Expand Down
27 changes: 7 additions & 20 deletions app/src/features/surveys/view/SurveyAttachments.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { FileUploadDialog } from 'components/dialog/attachments/FileUploadDialog
import { ReportFileUploadDialog } from 'components/dialog/attachments/ReportFileUploadDialog';
import { ProjectRoleGuard } from 'components/security/Guards';
import { H2MenuToolbar } from 'components/toolbar/ActionToolbars';
import { AttachmentsI18N, ReportI18N } from 'constants/i18n';
import { ReportI18N } from 'constants/i18n';
import { PROJECT_PERMISSION, SYSTEM_ROLE } from 'constants/roles';
import { SurveyContext } from 'contexts/surveyContext';
import { APIError } from 'hooks/api/useAxios';
Expand All @@ -17,6 +17,11 @@ import { useDialogContext } from 'hooks/useContext';
import { useContext, useState } from 'react';
import SurveyAttachmentsList from './SurveyAttachmentsList';

/**
* Survey attachments component.
*
* @return {*}
*/
const SurveyAttachments = () => {
const biohubApi = useBiohubApi();

Expand Down Expand Up @@ -50,25 +55,7 @@ const SurveyAttachments = () => {
};

const handleUploadAttachments = async (file: File) => {
try {
await biohubApi.survey.uploadSurveyAttachments(projectId, surveyId, file);
} catch (error) {
const apiError = error as APIError;

dialogContext.setErrorDialog({
open: true,
dialogTitle: AttachmentsI18N.uploadErrorTitle,
dialogText: AttachmentsI18N.uploadErrorText,
dialogError: apiError.message,
dialogErrorDetails: apiError.errors,
onClose: () => {
dialogContext.setErrorDialog({ open: false });
},
onOk: () => {
dialogContext.setErrorDialog({ open: false });
}
});
}
return biohubApi.survey.uploadSurveyAttachments(projectId, surveyId, file);

Check warning on line 58 in app/src/features/surveys/view/SurveyAttachments.tsx

View check run for this annotation

Codecov / codecov/patch

app/src/features/surveys/view/SurveyAttachments.tsx#L58

Added line #L58 was not covered by tests
};

return (
Expand Down

0 comments on commit 6150161

Please sign in to comment.