Skip to content

fix(uploader): openFileDialogOnClick支持传入函数 #637

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

Open
wants to merge 7 commits into
base: master
Choose a base branch
from

Conversation

Frank17008
Copy link

@Frank17008 Frank17008 commented Jun 24, 2025

Summary by CodeRabbit

  • 新功能

    • openFileDialogOnClick 属性现支持传入布尔值或返回布尔值的函数,提升了文件对话框打开行为的灵活性。
  • 文档

    • 更新了 API 文档,反映 openFileDialogOnClick 属性类型的变化。
  • 测试

    • 新增针对 openFileDialogOnClick 属性不同用法的测试用例,确保其行为符合预期。

Copy link

vercel bot commented Jun 24, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
upload ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jun 24, 2025 2:51am

Copy link

coderabbitai bot commented Jun 24, 2025

Walkthrough

此次变更将 openFileDialogOnClick 属性从单一布尔值扩展为可接受布尔值或返回布尔值的函数,并相应更新了类型声明、文档说明和上传组件的事件处理逻辑。同时,增加了针对该属性行为的单元测试。

Changes

文件/分组 变更摘要
README.md 更新 openFileDialogOnClick 属性文档,类型由 boolean 改为 boolean 或函数
src/interface.tsx UploadProps 接口中 openFileDialogOnClick 类型由 boolean 改为 boolean | (() => boolean)
src/AjaxUploader.tsx 新增 eventHandler 方法,统一处理事件回调逻辑,render 方法相应调整
tests/uploader.spec.tsx 新增 openFileDialogOnClick 相关测试用例,覆盖多种类型与动态切换场景

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant UploadComponent
    participant AjaxUploader

    User->>UploadComponent: 点击上传区域
    UploadComponent->>AjaxUploader: 触发 onClick/onKeyDown 事件
    AjaxUploader->>AjaxUploader: 调用 eventHandler(fn, originFn, event)
    alt fn 为 boolean 或函数
        AjaxUploader->>AjaxUploader: 判断 fn 或 fn()
        alt 返回 true
            AjaxUploader->>AjaxUploader: 执行 originFn(event)
        else 返回 false
            AjaxUploader-->>AjaxUploader: 不执行 originFn
        end
    end
Loading

Suggested reviewers

  • zombieJ

Poem

小兔子写代码,
属性类型变灵活。
布尔或函数皆可用,
点击上传随心走。
测试覆盖全场景,
代码如春风拂柳。
🐇✨

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

src/AjaxUploader.tsx

Oops! Something went wrong! :(

ESLint: 8.57.1

ESLint couldn't find the config "prettier" to extend from. Please check that the name of the config is correct.

The config "prettier" was referenced from the config file in "/.eslintrc.js".

If you still have problems, please stop by https://eslint.org/chat/help to chat with the team.


📜 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 198ea49 and 9e4ac01.

📒 Files selected for processing (1)
  • src/AjaxUploader.tsx (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/AjaxUploader.tsx
✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate Unit Tests
  • Create PR with Unit Tests
  • Post Copyable Unit Tests in Comment

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
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai auto-generate unit tests to generate unit tests for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

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: 1

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between c892be5 and 198ea49.

📒 Files selected for processing (4)
  • README.md (1 hunks)
  • src/AjaxUploader.tsx (2 hunks)
  • src/interface.tsx (1 hunks)
  • tests/uploader.spec.tsx (1 hunks)
🧰 Additional context used
🪛 Biome (1.9.4)
src/AjaxUploader.tsx

[error] 308-308: Don't use 'Function' as a type.

Prefer explicitly define the function shape. This type accepts any function-like value, which can be a common source of bugs.

(lint/complexity/noBannedTypes)

🔇 Additional comments (4)
README.md (1)

86-86: 文档更新正确反映了新功能

API文档正确地反映了 openFileDialogOnClick 属性类型的增强,支持布尔值或返回布尔值的函数。

src/interface.tsx (1)

34-34: 类型定义增强实现得当

联合类型 boolean | (() => boolean) 正确地扩展了功能,同时保持了向后兼容性。

tests/uploader.spec.tsx (1)

1190-1235: 测试覆盖全面且实现正确

新增的测试套件全面覆盖了 openFileDialogOnClick 的各种使用场景:

  • 布尔值 true/false 的行为验证
  • 函数返回 true/false 的行为验证
  • 动态函数返回值的行为验证

测试实现使用了正确的模拟和断言方式,为新功能提供了可靠的质量保障。

src/AjaxUploader.tsx (1)

347-348: 事件处理逻辑实现正确

使用新的 eventHandler 方法正确地实现了条件事件处理,支持了 openFileDialogOnClick 的布尔值和函数两种类型。逻辑清晰且向后兼容。

Copy link

codecov bot commented Jun 24, 2025

Codecov Report

Attention: Patch coverage is 80.00000% with 1 line in your changes missing coverage. Please review.

Project coverage is 91.83%. Comparing base (c892be5) to head (9e4ac01).

Files with missing lines Patch % Lines
src/AjaxUploader.tsx 80.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #637      +/-   ##
==========================================
+ Coverage   89.10%   91.83%   +2.72%     
==========================================
  Files           6        6              
  Lines         303      306       +3     
  Branches       84       81       -3     
==========================================
+ Hits          270      281      +11     
+ Misses         33       25       -8     

☔ 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.

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.

1 participant