Skip to content

Conversation

@EmilyyyLiu
Copy link
Contributor

@EmilyyyLiu EmilyyyLiu commented Sep 23, 2025

关联issue: ant-design/ant-design#54457
在customRequest 参数中增加 defaultRequest

Summary by CodeRabbit

  • 新功能
    • 上传组件的 customRequest 在被调用时额外收到 info.defaultRequest,允许在自定义逻辑中回退或委托到内置上传流程,提升可定制性与可控性。
  • 类型
    • 新增并导出用于 customRequest 的公共类型,改善 TypeScript 提示与开发体验。
  • 测试
    • 新增测试,验证在 customRequest 中调用 defaultRequest 能触发并完成上传回调流程。

@vercel
Copy link

vercel bot commented Sep 23, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Preview Comments Updated (UTC)
upload Ready Ready Preview Comment Sep 23, 2025 7:39am

@coderabbitai
Copy link

coderabbitai bot commented Sep 23, 2025

Note

Other AI code review bot(s) detected

CodeRabbit has detected other AI code review bot(s) in this pull request and will avoid duplicating their findings in the review comments. This may lead to a less comprehensive review.

Walkthrough

将上传请求的调用签名扩展为向自定义请求传入额外信息对象 { defaultRequest },新增并导出 CustomUploadRequestOption 类型并将其用于 UploadProps.customRequest,并新增测试以验证在 customRequest 中调用 info.defaultRequest 的场景。

Changes

Cohort / File(s) Summary
上传请求调用签名变化
src/AjaxUploader.tsx
在启动上传时以两个参数调用请求函数:(option, { defaultRequest });保留请求选择逻辑 `customRequest
类型与公开接口新增
src/interface.tsx
新增并导出类型 CustomUploadRequestOption:`(option: UploadRequestOption, info: { defaultRequest: (option: UploadRequestOption) => { abort: () => void }
测试新增
tests/uploader.spec.tsx
新增测试用例验证在 customRequest 内接收并调用 info.defaultRequest:模拟文件输入(如 test.png),触发上传并断言 customRequest 被调用且从 info.defaultRequest 得到与 src 请求相同的 defaultRequest 行为。

Sequence Diagram(s)

sequenceDiagram
  participant UI as Upload 组件
  participant AU as AjaxUploader
  participant CR as customRequest(fn)
  participant DR as defaultRequest
  participant S as 服务器

  UI->>AU: 选择文件并触发上传
  AU->>CR: 调用 customRequest(option, { defaultRequest })
  alt customRequest 调用 info.defaultRequest
    CR->>DR: info.defaultRequest(option)
    DR->>S: 发送上传请求
    S-->>DR: 返回响应
    DR-->>AU: 通知上传结果(onSuccess/onError)
  else customRequest 自行处理上传
    CR-->>AU: 直接回调 onSuccess/onError 或 返回含 abort 的对象
  end
  AU-->>UI: 触发 onStart/onSuccess/onError
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

我是代码兔,耳朵竖又轻 🐇
把默认请求藏进 info 的心庭
若你愿自定义,我递上回落绳
上传轻快跳舞,测试唱着并行
胡萝卜小庆祝,代码齐声鸣 🎉

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed 标题“feat: Add defaultRequest to customRequest”准确反映了本次变更的核心:为 customRequest 增加 defaultRequest 参数,表述简洁具体并符合常见的 commit/PR 风格,能够让审阅者快速理解主要改动。
Docstring Coverage ✅ Passed No functions found in the changes. Docstring coverage check skipped.
✨ Finishing touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 7485284 and 466f2fc.

📒 Files selected for processing (1)
  • tests/uploader.spec.tsx (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • tests/uploader.spec.tsx

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 and usage tips.

@gemini-code-assist
Copy link

Summary of Changes

Hello @EmilyyyLiu, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

此PR旨在增强 Upload 组件的 customRequest 功能,允许开发者在自定义上传逻辑中灵活地调用组件的默认上传行为。通过在 customRequest 的选项中暴露 defaultRequest,它解决了在某些场景下需要混合自定义逻辑和默认逻辑的需求,例如在特定条件下使用默认上传,而在其他条件下执行完全自定义的操作,从而提高了组件的灵活性和可扩展性。

Highlights

  • 增强 customRequest 参数: 现在 customRequest 参数中包含 defaultRequest 函数,允许开发者在自定义上传逻辑中选择性地调用默认上传行为。
  • 更新类型定义: 引入了 CustomUploadRequestOption 接口,扩展了 UploadRequestOption,并为 customRequest 提供了更具体的类型定义,以支持新的 defaultRequest 属性。
  • 新增测试用例: 增加了新的单元测试,确保 customRequest 能够正确地接收并使用 defaultRequest
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

这个 PR 的目标是在 customRequest 中提供 defaultRequest,让用户可以在自定义上传逻辑中回退到默认实现,这是一个很好的功能增强。代码实现基本正确,但在 AjaxUploader.tsx 中,确定最终 request 函数的逻辑可以更简洁一些。此外,新添加的测试用例 tests/uploader.spec.tsx 存在一些问题:它采用了一种不寻常的测试模式,即修改传入的 info 对象来注入 mock,并且没有正确地测试功能。测试用例应该被修正以确保功能的正确性和促进正确的 API 用法。我对这两点都提出了具体的修改建议。

@codecov
Copy link

codecov bot commented Sep 23, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 89.03%. Comparing base (4958954) to head (466f2fc).
⚠️ Report is 1 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master     #660   +/-   ##
=======================================
  Coverage   89.03%   89.03%           
=======================================
  Files           6        6           
  Lines         301      301           
  Branches       82       82           
=======================================
  Hits          268      268           
  Misses         33       33           

☔ View full report in Codecov by Sentry.
📢 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.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (1)
src/interface.tsx (1)

34-34: 补充 JSDoc 说明新参数约定与兼容性

为公共 API 增强可发现性,建议在属性上补充注释,说明“第二个参数 info 自本次发版起可用,旧实现可忽略该参数”。

应用示例 diff:

-  customRequest?: CustomUploadRequestOption;
+  /** 第二参数 `info` 提供 `defaultRequest`(新能力);旧实现可忽略该参数以保持兼容 */
+  customRequest?: CustomUploadRequestOption;
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 983bcb7 and e80da55.

📒 Files selected for processing (3)
  • src/AjaxUploader.tsx (1 hunks)
  • src/interface.tsx (2 hunks)
  • tests/uploader.spec.tsx (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • tests/uploader.spec.tsx
  • src/AjaxUploader.tsx
🔇 Additional comments (2)
src/interface.tsx (2)

81-84: 已对齐既往评审意见:info 放在第二参数

与过往评论“info 放第二个参数,不要和 option 放一起”一致,形参顺序正确。👍


81-84: 结论:将 info 设为必填以“避免破坏性变更”的担忧不成立

仓库检索:src/AjaxUploader.tsx 在调用处会以两个参数传入 customRequest(tests 中有两参实现,docs 示例有一参用法)。TypeScript(含 --strictFunctionTypes)允许参数更少的函数赋值给期望更多参数的函数签名,因此一参实现不会被判为不兼容。建议性改进:可选地按原 diff 添加泛型并将 info 设为可选以提高类型精确度(不会破坏兼容性)。

-export type CustomUploadRequestOption = (
-  option: UploadRequestOption,
-  info: { defaultRequest: (option: UploadRequestOption) => { abort: () => void } | void },
-) => void | { abort: () => void };
+export type CustomUploadRequestOption<T = any> = (
+  option: UploadRequestOption<T>,
+  info?: { defaultRequest: (option: UploadRequestOption<T>) => { abort: () => void } | void },
+) => void | { abort: () => void };

位置:src/interface.tsx(类型定义);调用处:src/AjaxUploader.tsx;示例/测试:docs/examples/customRequest.tsx、tests/uploader.spec.tsx。

Likely an incorrect or invalid review comment.

@zombieJ
Copy link
Member

zombieJ commented Sep 23, 2025

@gemini-code-assist CR

const { uid } = origin;
const request = customRequest || defaultRequest;

const request =
Copy link
Member

Choose a reason for hiding this comment

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

为啥不直接去 request 调用的地方改?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

request = customRequest || defaultRequest;
如果在调用时候改,有可能 defaultRequest 的参数也加上了{defaultRequest}

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

这个 PR 为 Upload 组件的 customRequest 属性增加了一个新功能,允许在自定义上传逻辑中通过第二个参数 info.defaultRequest 回退使用内置的上传请求。这是一个很好的功能增强,提高了 customRequest 的灵活性。

代码实现方面,逻辑是正确的,并且做了向后兼容。类型定义也已相应更新。

我提出了一些建议:

  1. tests/uploader.spec.tsx 中,修复测试用例里对 defaultRequest 不正确的调用方式,以确保测试的健壮性和正确性。
  2. src/AjaxUploader.tsx 中,对 request 变量的赋值逻辑进行少量重构,以提高代码的清晰度。

总体来说,这是一个高质量的 PR,在采纳了建议的修改后即可合并。

Comment on lines 256 to 259
const request =
typeof propsCustomRequest === 'function'
? args => propsCustomRequest(args, { defaultRequest })
: propsCustomRequest || defaultRequest;

Choose a reason for hiding this comment

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

medium

为了提高代码的简洁性和可读性,这里的 request 变量赋值逻辑可以进行简化。

考虑到 propsCustomRequest 的类型是函数或 undefined,我们可以使用更直接的三元运算符。这与现有逻辑在功能上是等价的,但结构更清晰。

    const request = propsCustomRequest
      ? args => propsCustomRequest(args, { defaultRequest })
      : defaultRequest;

@zombieJ zombieJ merged commit c639080 into react-component:master Sep 25, 2025
9 checks passed
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