-
Notifications
You must be signed in to change notification settings - Fork 280
feat(uploader): support beforeupload props in taro #2567
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
Conversation
Walkthrough此次更改在上传组件中引入了一个新的异步函数 Changes
Sequence Diagram(s)sequenceDiagram
participant User
participant Uploader
participant beforeUpload
participant FileHandler
User->>Uploader: 选择文件
Uploader->>beforeUpload: 调用 beforeUpload(files)
beforeUpload-->>Uploader: 返回处理后的文件或布尔值
alt 处理成功
Uploader->>FileHandler: 处理文件
else 处理失败
Uploader-->>User: 显示错误信息
end
Possibly related issues
Poem
Recent review detailsConfiguration used: CodeRabbit UI Files selected for processing (3)
Additional context usedLearnings (2)
Additional comments not posted (4)
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? TipsChatThere are 3 ways to chat with CodeRabbit:
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)
Other keywords and placeholders
CodeRabbit Configuration File (
|
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## next #2567 +/- ##
=======================================
Coverage 83.20% 83.20%
=======================================
Files 217 217
Lines 17801 17801
Branches 2573 2573
=======================================
Hits 14812 14812
Misses 2984 2984
Partials 5 5 ☔ View full report in Codecov by Sentry. |
There was a problem hiding this 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
Outside diff range, codebase verification and nitpick comments (2)
src/packages/uploader/demos/taro/demo1.tsx (1)
10-17
: 考虑将允许的文件类型提取到一个常量中。为了提高可读性和可维护性,建议将允许的文件类型提取到一个常量中。
可以应用以下更改:
+const ALLOWED_TYPES = ['image/png'] + const beforeUpload = async (files: File[]) => { console.log('beforeUpload') - const allowedTypes = ['image/png'] const filteredFiles = Array.from(files).filter((file) => - allowedTypes.includes(file.type) + ALLOWED_TYPES.includes(file.type) ) return filteredFiles }src/packages/uploader/uploader.taro.tsx (1)
Line range hint
1-1
: 根据之前的学习,建议为涉及fileList
状态变化的改动添加单元测试。当前的改动引入了
beforeUpload
功能,可能会影响fileList
状态。为涵盖beforeUpload
函数的不同场景编写单元测试,有助于维护上传组件的稳定性和正确性。
return ( | ||
<Cell style={{ flexWrap: 'wrap' }}> | ||
<Uploader | ||
url={uploadUrl} | ||
onStart={onStart} | ||
beforeUpload={beforeUpload} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
考虑为 src/packages/uploader/uploader.taro.tsx
文件中的 fileList
状态变更生成单元测试。
根据之前的学习,建议为 src/packages/uploader/uploader.taro.tsx
文件中的 fileList
状态变更生成单元测试,以确保功能的正确性。
如果需要帮助生成单元测试代码或创建 GitHub issue 来跟踪此任务,请告诉我。
Summary by CodeRabbit
新功能
beforeUpload
异步函数,允许在文件上传前进行自定义验证和过滤,仅处理PNG图像。Uploader
组件,支持beforeUpload
属性,增强了文件上传的灵活性和控制能力。文档
beforeUpload
属性的使用及其返回值。