Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Insufficient file-list validation #442

Open
sylar-zeyangz opened this issue Jan 23, 2025 · 1 comment
Open

Insufficient file-list validation #442

sylar-zeyangz opened this issue Jan 23, 2025 · 1 comment

Comments

@sylar-zeyangz
Copy link
Collaborator

sylar-zeyangz commented Jan 23, 2025

Please refer to: desktop/src/renderer/src/pages/transfers/LanTransfer.tsx

The current logic triggers the toast message if result is falsy or if accession and/or application is undefined or null. However, if result is an object simply missing COVER PAGE sheet, or being an empty file (same to .json if missing admin property), the current code will NOT trigger the toast. Instead, it will attempt to destructure accession and application from result, and they will be undefined.

This leads to unexpected behavior where file being accepted but no error message but also confirmation and Next button is disabled, since the toast condition is tied to the truthiness of result, not its individual properties.

A more robustic logic should be

      #// Xlsx file
      try {
        const result = await api.transfer.parseXlsxFileList(fileList);
      
        if (result && result.accession && result.application) {
          const { accession, application, folders } = result;
          setAccession(accession);
          setApplication(application);
          setFoldersToProcess(folders);
        } else {
          toast.error(Toast, {
            data: {
              title: "Missing accession and/or application number",
              message:
                "Your file list (ARS 662) is missing an accession and/or application number. Please add this information to the ‘Cover Page’ tab in the file list and save it, then try uploading the file again.",
            },
          });
        }
      } catch (error) {
        console.error("Error parsing the file list:", error);
        // error message is subject to change
        toast.error("An error occurred while processing the file. Please ensure file content adheres to the required structure.");
      }
@sylar-zeyangz
Copy link
Collaborator Author

Issue brought up during review #424

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant