Skip to content
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

修改picker组件issue #2360

Open
wants to merge 3 commits into
base: next
Choose a base branch
from

Conversation

dragonfly-captain
Copy link

@dragonfly-captain dragonfly-captain commented Jun 18, 2024

🤔 这个变动的性质是?

  • 新特性提交
  • [√ ] 日常 bug 修复
  • 站点、文档改进
  • 演示代码改进
  • 组件样式/交互改进
  • TypeScript 定义更新
  • 包体积优化
  • 性能优化
  • 功能增强
  • 国际化改进
  • 重构
  • 代码风格优化
  • 测试用例
  • 分支合并
  • 其他改动(是关于什么的改动?)

🔗 相关 Issue

  1. form下的picker在第一次不选择选项,直接取消选择后再次点击picker,出现第一项被选中的问题form下的picker在第一次不选择选项,直接取消选择后再次点击picker,出现第一项被选中的问题 #2290
  2. Picker 和 FormItem 搭配使用时,ref.open() 会触发 Picker 的 onClose
    Picker 和 FormItem 搭配使用时,ref.open() 会触发 Picker 的 onClose  #2312

💡 需求背景和解决方案

背景:线上issue
解决方案:通过修改源代码的方式对issue进行修改,不破坏原逻辑,对性能没有影响

☑️ 请求合并前的自查清单

⚠️ 请自检并全部勾选全部选项⚠️

  • [√ ] 文档已补充或无须补充
  • [ √ ] 代码演示已提供或无须提供
  • [ √ ] TypeScript 定义已补充或无须补充
  • [ √ ] fork仓库代码是否为最新避免文件冲突
  • [√ ] Files changed 没有 package.json lock 等无关文件

Summary by CodeRabbit

  • 错误修复
    • 更新了选择器组件的onChange事件处理逻辑,以确保在确认选择时行为正确。

Copy link

coderabbitai bot commented Jun 18, 2024

Walkthrough

这些更改涉及InternalPicker组件内逻辑和控制流的修改。具体来说,调整了基于所选值的onChange事件处理,以解决特定问题并在确认选择时确保正确行为。此外,还重构了useEffect钩内的setInnerValue逻辑以处理选择的值并防止不必要的修改。

Changes

文件 更改摘要
src/packages/picker/picker.tsx 更新onChange方法以条件性地调用props.onConfirm、重构useEffect内的setInnerValue逻辑、移除内联useEffect的onChange方法。

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant Picker as InternalPicker
    participant ConfirmHandler

    User ->> Picker: Selects Value
    Picker ->> Picker: setInnerValue(newValue)
    alt if val is present
        Picker ->> ConfirmHandler: props.onConfirm(val)
    end
    Picker ->> User: onChange Callback
Loading

Poem

内部挑选更新忙,
onChange逻辑细思量。
确认选择无误差,
修改流畅前景亮。
代码如诗般绽放,
程序健壮无限畅。


Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between cfc5be3 and 76a5e85.

Files selected for processing (1)
  • src/packages/picker/picker.tsx (5 hunks)
Additional context used
Biome
src/packages/picker/picker.tsx

[error] 143-144: Change to an optional chain. (lint/complexity/useOptionalChain)

Unsafe fix: Change to an optional chain.


[error] 262-264: Change to an optional chain. (lint/complexity/useOptionalChain)

Unsafe fix: Change to an optional chain.


[error] 280-282: Change to an optional chain. (lint/complexity/useOptionalChain)

Unsafe fix: Change to an optional chain.


[error] 305-317: Enforce to have the onClick mouse event with the onKeyUp, the onKeyDown, or the onKeyPress keyboard event. (lint/a11y/useKeyWithClickEvents)

Actions triggered using mouse events should have corresponding keyboard events to account for keyboard-only navigation.


[error] 322-327: Enforce to have the onClick mouse event with the onKeyUp, the onKeyDown, or the onKeyPress keyboard event. (lint/a11y/useKeyWithClickEvents)

Actions triggered using mouse events should have corresponding keyboard events to account for keyboard-only navigation.

Additional comments not posted (1)
src/packages/picker/picker.tsx (1)

Line range hint 143-144: 应使用可选链 (Optional Chaining) 操作符来简化代码。
[REFACTOR_SUGGESTIOn]

- columnOptions && columnOptions.children
+ columnOptions?.children

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?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

‼️ IMPORTANT
Auto-reply has been disabled for this repository in the CodeRabbit settings. The CodeRabbit bot will not respond to your replies unless it is explicitly tagged.

  • 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 generate unit testing code for this file.
    • @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 generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @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.

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 as 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 resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration 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: 3

Outside diff range and nitpick comments (3)
src/packages/picker/picker.tsx (3)

Line range hint 280-282: 建议使用可选链操作符来简化代码。

- columnOptions && Object.keys(columnOptions).length
+ columnOptions?.length

Line range hint 305-317: 鼠标事件应与键盘事件一起提供,以支持键盘导航。

建议添加键盘事件处理函数,如 onKeyPress,以改善无障碍性。


Line range hint 322-327: 鼠标事件应与键盘事件一起提供,以支持键盘导航。

建议添加键盘事件处理函数,如 onKeyPress,以改善无障碍性。

Comment on lines +253 to +254

onChange && onChange(setSelectedOptions(), combineResult, columnIndex)
Copy link

Choose a reason for hiding this comment

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

建议使用可选链操作符来简化代码。

- onChange && onChange(setSelectedOptions(), combineResult, columnIndex)
+ onChange?.(setSelectedOptions(), combineResult, columnIndex)

Also applies to: 262-264

@@ -98,7 +98,7 @@ const InternalPicker: ForwardRefRenderFunction<
defaultValue: [...defaultValue],
finalValue: [...defaultValue],
onChange: (val: (string | number)[]) => {
props.onConfirm?.(setSelectedOptions(), val)
!val && props.onConfirm?.(setSelectedOptions(), val)
Copy link

Choose a reason for hiding this comment

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

代码逻辑存在潜在问题。当 valundefinednull 时,onConfirm 事件仍会被调用,这可能不是预期行为。

- !val && props.onConfirm?.(setSelectedOptions(), val)
+ val && props.onConfirm?.(setSelectedOptions(), val)
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
!val && props.onConfirm?.(setSelectedOptions(), val)
val && props.onConfirm?.(setSelectedOptions(), val)

Comment on lines +200 to +204
// 此hook的作用是‘如果内部选中值与用户选中值不同则把内部值置用户选中值’保证用户打开选项时选中的是选择的值。
// 但是当用户并没有进行确认选择,则不需要进行修改innerValue,否则会出现 issue#2290的问题
if (innerValue !== selectedValue && selectedValue.length > 0) {
setInnerValue(selectedValue)
}
Copy link

Choose a reason for hiding this comment

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

此处的逻辑处理可能会导致不必要的状态更新,建议仅在 selectedValue 有实质性变化时更新 innerValue

- if (innerValue !== selectedValue && selectedValue.length > 0) {
+ if (!isEqual(innerValue, selectedValue) && selectedValue.length > 0) {
    setInnerValue(selectedValue)
  }
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
// 此hook的作用是‘如果内部选中值与用户选中值不同则把内部值置用户选中值’保证用户打开选项时选中的是选择的值。
// 但是当用户并没有进行确认选择,则不需要进行修改innerValue,否则会出现 issue#2290的问题
if (innerValue !== selectedValue && selectedValue.length > 0) {
setInnerValue(selectedValue)
}
// 此hook的作用是‘如果内部选中值与用户选中值不同则把内部值置用户选中值’保证用户打开选项时选中的是选择的值。
// 但是当用户并没有进行确认选择,则不需要进行修改innerValue,否则会出现 issue#2290的问题
if (!isEqual(innerValue, selectedValue) && selectedValue.length > 0) {
setInnerValue(selectedValue)
}

Copy link
Collaborator

@xiaoyatong xiaoyatong left a comment

Choose a reason for hiding this comment

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

需要关注一下,点击确认后数据获取的情况~

@Lin-Min
Copy link

Lin-Min commented Sep 19, 2024

请问这个问题啥时候解决呢 今天就遇到了

@oasis-cloud oasis-cloud added the 2.x label Nov 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants