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

fix: Mac upload folder error #2259

Merged
merged 1 commit into from
Feb 12, 2025
Merged

fix: Mac upload folder error #2259

merged 1 commit into from
Feb 12, 2025

Conversation

wangdan-fit2cloud
Copy link
Contributor

What this PR does / why we need it?

Summary of your change

Please indicate you've done the following:

  • Made sure tests are passing and test coverage is added if needed.
  • Made sure commit message follow the rule of Conventional Commits specification.
  • Considered the docs impact and opened a new docs issue or PR with docs changes if needed.

Copy link

f2c-ci-robot bot commented Feb 12, 2025

Adding the "do-not-merge/release-note-label-needed" label because no release-note block was detected, please follow our release note process to remove it.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

Copy link

f2c-ci-robot bot commented Feb 12, 2025

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:

The full list of commands accepted by this bot can be found here.

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@wangdan-fit2cloud wangdan-fit2cloud merged commit c1efc72 into main Feb 12, 2025
4 of 5 checks passed
MsgError(t('views.document.upload.errorMessage2'))
if (file?.name !== '.DS_Store') {
MsgError(t('views.document.upload.errorMessage2'))
}
fileList.splice(-1, 1)
return false
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here are some suggested improvements to the code:

  1. Remove Redundant Line: The line fileList.splice(-1, 1) can be removed since it is only executed when an error occurs and will not change the final state of the fileList.

  2. Use Conditional Statements Consistently: Ensure that all conditions follow a consistent structure.

  3. Move MsgError Call Outside Loop: If there might be multiple errors per upload attempt, consider moving the MsgError call outside the loop to avoid unnecessary processing for valid files.

  4. Check for .DS_Store File Explicitly: The condition if !file?.name !== '.DS_Store' looks redundant because you already check if the file extension is correct. Consider removing this part if appropriate.

Here's refactored version of the code with these improvements applied:

const fileHandleChange = (file: any, fileList: UploadFiles) => {
  // Check file type consistency
  console.log(form.value.fileType); // Debug statement to ensure form value is correct
  if (!isRightType(file?.name, form.value.fileType)) {
    MsgError(t('views.document.upload.errorMessage2'));
    return false;
  }

  // Remove current file if its size exceeds allowed limit
  if (file.size > MAX_SIZE) {
    fileList.splice(-1, 1);
  }

  return true; // Return true to indicate successful handling of the file
}

These changes streamline the function logic and improve readability while addressing potential issues.

@wangdan-fit2cloud wangdan-fit2cloud deleted the pr@main/upload-bug branch February 12, 2025 09:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants