Skip to content

feat: add retryUpload method for upload - #723

Open
EmilyyyLiu wants to merge 2 commits into
react-component:masterfrom
EmilyyyLiu:feat/retry-upload
Open

feat: add retryUpload method for upload#723
EmilyyyLiu wants to merge 2 commits into
react-component:masterfrom
EmilyyyLiu:feat/retry-upload

Conversation

@EmilyyyLiu

@EmilyyyLiu EmilyyyLiu commented Jul 27, 2026

Copy link
Copy Markdown
Contributor

背景

新增 retryUpload 方法,允许用户重试上传失败的文件。

关联issue: ant-design/ant-design#27021

修改内容

  • AjaxUploader 组件中添加 retryUpload 方法
  • Upload 组件中暴露 retryUpload 方法
  • 添加单元测试验证功能
  • 更新中英文文档

使用示例

const uploadRef = useRef();

<Upload ref={uploadRef} action="/upload">
  <button>Upload</button>
</Upload>

// 调用重试
uploadRef.current.retryUpload(file);

测试覆盖

  • retryUpload 方法已覆盖 ✅

Summary by CodeRabbit

Summary by CodeRabbit

  • 新功能

    • 支持按指定文件进行上传重试:重新生成文件信息后,解析成功即继续发起上传请求。
    • 上传组件新增 retryUpload 方法,可在组件实例上触发重试。
  • 文档

    • 更新中英文 API 文档 “Methods/方法”:新增 retryUpload(file),并调整方法表格排版。
  • 测试

    • 新增重试用例:验证重试会产生新请求;当 action/data 异步抛错时不发起新增请求。

- Add retryUpload method to AjaxUploader
- Add retryUpload method to Upload component
- Add unit test for retryUpload
- Update README docs

Co-Authored-By: Claude <noreply@anthropic.com>
@gemini-code-assist

Copy link
Copy Markdown

Caution

The consumer version of Gemini Code Assist on GitHub has been sunset. All code review activity has officially ceased.

@vercel

vercel Bot commented Jul 27, 2026

Copy link
Copy Markdown

Someone is attempting to deploy a commit to the React Component Team on Vercel.

A member of the Team first needs to authorize it.

@coderabbitai

coderabbitai Bot commented Jul 27, 2026

Copy link
Copy Markdown

Review Change Stack

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review

Walkthrough

新增 retryUpload(file) 实例方法,由 Upload 转发至 AjaxUploader,重新处理文件并提交上传;processFile 增加异常回退逻辑,测试验证成功及拒绝场景,中英文文档同步更新 API 列表。

Changes

文件重试上传

Layer / File(s) Summary
文件重新处理与异常回退
src/AjaxUploader.tsx
processFile 捕获 actiondata 函数异常,并返回结构化的拒绝结果。
重试上传调用链
src/Upload.tsx, src/AjaxUploader.tsx, tests/uploader.spec.tsx
Upload 新增并转发 retryUploadAjaxUploader 重新解析文件并在解析成功后提交,测试验证成功请求及拒绝场景不会创建新请求。
API 文档更新
README.md, README.zh-CN.md
中英文方法表格新增 retryUpload(file: RcFile) => void,并调整表格布局及头部空行排版。

Estimated code review effort: 3 (Moderate) | ~20 minutes

Sequence Diagram(s)

sequenceDiagram
  participant Test
  participant Upload
  participant AjaxUploader
  participant processFile
  participant post
  Test->>Upload: 调用 retryUpload(file)
  Upload->>AjaxUploader: 转发 retryUpload(file)
  AjaxUploader->>processFile: 重新解析 originFile
  processFile-->>AjaxUploader: 返回 fileInfo
  AjaxUploader->>post: parsedFile 存在时提交 fileInfo
  post-->>Test: 创建新的上传请求
Loading

Poem

小兔挥爪重试传,
文件重新上云端。
解析成功再出发,
新请求咚咚响。
文档也把新法藏。

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed 标题准确概括了本次变更的核心:为上传组件新增 retryUpload 方法。
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@codecov

codecov Bot commented Jul 27, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 92.59259% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 89.55%. Comparing base (c2f2fef) to head (9c18602).
⚠️ Report is 1 commits behind head on master.

Files with missing lines Patch % Lines
src/AjaxUploader.tsx 92.00% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #723      +/-   ##
==========================================
- Coverage   89.58%   89.55%   -0.04%     
==========================================
  Files           6        6              
  Lines         317      335      +18     
  Branches       94       97       +3     
==========================================
+ Hits          284      300      +16     
- Misses         33       35       +2     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Comment thread src/AjaxUploader.tsx

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/AjaxUploader.tsx`:
- Around line 304-310: Update retryUpload to handle rejected promises from
processFile, reusing the existing upload flow’s preprocessing-error strategy and
adding an explicit catch to the promise chain. Return the resulting promise so
callers can observe or handle failures, while preserving the current parsedFile
check and post behavior.

In `@tests/uploader.spec.tsx`:
- Around line 260-271: 更新 tests/uploader.spec.tsx 中 retryUpload 的测试夹具,使 file 符合
RcFile 合约:使用带稳定 uid 的 File 夹具,并移除对 file 的 as any 绕过。保留 files.item
的必要模拟,同时在请求断言中验证重试请求收到该正确文件,确保 post 使用 origin.uid 作为正确索引。
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: b182eb6a-62f6-4bce-869e-c0546118dfe8

📥 Commits

Reviewing files that changed from the base of the PR and between c2f2fef and 33a1d04.

📒 Files selected for processing (5)
  • README.md
  • README.zh-CN.md
  • src/AjaxUploader.tsx
  • src/Upload.tsx
  • tests/uploader.spec.tsx

Comment thread src/AjaxUploader.tsx
Comment thread tests/uploader.spec.tsx Outdated
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants