Skip to content

docs(attachments): add high-quality preview example for image file #960

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 1 commit into
base: main
Choose a base branch
from

Conversation

wzc520pyfm
Copy link
Contributor

@wzc520pyfm wzc520pyfm commented Jun 21, 2025

中文版模板 / Chinese template

🤔 This is a ...

  • 🆕 New feature
  • 🐞 Bug fix
  • 📝 Site / documentation improvement
  • 📽️ Demo improvement
  • 💄 Component style improvement
  • 🤖 TypeScript definition improvement
  • 📦 Bundle size optimization
  • ⚡️ Performance optimization
  • ⭐️ Feature enhancement
  • 🌐 Internationalization
  • 🛠 Refactoring
  • 🎨 Code style optimization
  • ✅ Test Case
  • 🔀 Branch merge
  • ⏩ Workflow
  • ⌨️ Accessibility improvement
  • ❓ Other (about what?)

🔗 Related Issues

  • Describe the source of related requirements, such as links to relevant issue discussions.
  • For example: close #xxxx, fix #xxxx

💡 Background and Solution

  • The specific problem to be addressed.
  • List the final API implementation and usage if needed.
  • If there are UI/interaction changes, consider providing screenshots or GIFs.

Before:

image

After:

image

📝 Change Log

Language Changelog
🇺🇸 English add high-quality preview example for image attachments
🇨🇳 Chinese 为Attachments组件添加高清预览上次图片的示例

Summary by CodeRabbit

  • 新功能
    • 优化了附件组件的文件处理,支持在添加或更改文件时动态生成文件的预览链接,并更精确地处理文件移除操作,提升内存管理效率。

Copy link
Contributor

github-actions bot commented Jun 21, 2025

Preview is ready

Copy link
Contributor

coderabbitai bot commented Jun 21, 2025

📝 Walkthrough

Walkthrough

本次更改在 Demo 组件中新增了 React effect 钩子,用于组件卸载时撤销所有文件的 blob URL,防止内存泄漏。Attachments 组件的 onChange 处理逻辑被细化,针对变更的文件动态撤销旧 URL 并生成新 URL,更新文件列表状态。

Changes

文件/分组 变更摘要
components/attachments/demo/with-sender.tsx 新增卸载时撤销 blob URL 的 effect;优化 onChange,动态管理文件 blob URL,防止内存泄漏

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant Attachments
    participant DemoComponent
    participant State

    User->>Attachments: 上传/移除文件
    Attachments->>Attachments: 判断文件状态
    alt 文件被移除
        Attachments->>State: 移除文件并更新状态
    else 文件添加或更改
        Attachments->>Attachments: 撤销旧 URL,生成新 URL
        Attachments->>State: 替换并更新文件列表
    end
    DemoComponent->>DemoComponent: 组件卸载时撤销所有 blob URL
Loading

Suggested reviewers

  • afc163

Poem

小兔挥爪忙清理,
URL旧影去无痕。
文件变更细心护,
组件轻盈无内存。
上传移除皆顺畅,
代码更健壮欢欣。
🐇💻✨


📜 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 49faf6f and 427de1a.

📒 Files selected for processing (1)
  • components/attachments/demo/with-sender.tsx (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • components/attachments/demo/with-sender.tsx
⏰ Context from checks skipped due to timeout of 90000ms (3)
  • GitHub Check: test / react component workflow
  • GitHub Check: build preview
  • GitHub Check: size
✨ 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.

@dosubot dosubot bot added the documentation Improvements or additions to documentation label Jun 21, 2025
Copy link

codecov bot commented Jun 21, 2025

Bundle Report

Bundle size has no change ✅

Copy link
Contributor

@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

🧹 Nitpick comments (1)
components/attachments/demo/with-sender.tsx (1)

6-6: 考虑使用更直接的类型定义

当前的类型提取方式功能正确,但可以考虑使用更直接的方法来提高可读性。

可以考虑直接使用 antd 的内置类型:

-type FileType = Parameters<GetProp<UploadProps, 'beforeUpload'>>[0];
+type FileType = File;

或者如果需要兼容 antd 的 UploadFile 类型:

-type FileType = Parameters<GetProp<UploadProps, 'beforeUpload'>>[0];
+import type { UploadFile } from 'antd';
+type FileType = UploadFile;
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between c175f7d and 49faf6f.

📒 Files selected for processing (1)
  • components/attachments/demo/with-sender.tsx (2 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (3)
  • GitHub Check: test / react component workflow
  • GitHub Check: size
  • GitHub Check: build preview
🔇 Additional comments (1)
components/attachments/demo/with-sender.tsx (1)

3-3: 导入语句更新合理

新增的类型导入支撑了后续的类型定义,变更合理。

@wzc520pyfm wzc520pyfm changed the title docs(attachments): add high-quality preview example for image attachments docs(attachments): add high-quality preview example for image file Jun 21, 2025
@wzc520pyfm wzc520pyfm force-pushed the docs/update-attachment-img-preview-demo branch from 49faf6f to 427de1a Compare June 22, 2025 06:48
@wzc520pyfm wzc520pyfm requested a review from afc163 June 23, 2025 04:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants