Skip to content

feat: optimize search #530

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

Merged
merged 6 commits into from
Sep 2, 2024
Merged

Conversation

crazyair
Copy link
Contributor

@crazyair crazyair commented Aug 30, 2024

解决设置 showSearch + multiple,搜索结果不支持全选一级的问题

Summary by CodeRabbit

  • 新功能

    • 新增了一个文档页面 multiple-search.md,提供多重搜索功能的演示和代码示例。
    • 引入了 Demo 组件,支持层级选择界面,允许用户进行多选和搜索。
  • 文档

    • 更新了文档以反映新功能和组件的使用示例。
  • 改进

    • 简化了 Cascader 组件的选择逻辑,提升用户体验。
    • 移除了不必要的属性,优化了组件的结构和性能。
    • 精简了搜索选项的处理逻辑,提高了代码的清晰度和效率。
  • 测试

    • 新增了测试用例,验证 Cascader.Search 组件在处理搜索操作时的行为。

Copy link

vercel bot commented Aug 30, 2024

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

Name Status Preview Comments Updated (UTC)
cascader ✅ Ready (Inspect) Visit Preview 💬 Add feedback Sep 2, 2024 4:27am

Copy link

coderabbitai bot commented Aug 30, 2024

Walkthrough

此次更改涉及多个文件,新增了一个名为 multiple-search.md 的文档页面,介绍了多重搜索功能的演示。同时,新增了一个 React 组件 Demo,并对 Cascader 组件的调用进行了简化,移除了 changeOnSelect 属性。useSearchOptions 函数的签名也进行了调整,移除了不再使用的参数,简化了内部逻辑。同时,更新了相关测试以增强覆盖率。

Changes

文件路径 更改摘要
docs/demo/multiple-search.md 新增文档页面,介绍多重搜索功能的演示。
examples/multiple-search.tsx 新增 Demo 组件,使用 Cascader 组件展示层级选择界面。
src/Cascader.tsx, src/hooks/useSearchOptions.ts 移除 changeOnSelect 属性,简化组件调用和 useSearchOptions 函数。
src/OptionList/Column.tsx 修改 onClick 事件处理程序,移除事件参数的类型注解。
src/OptionList/List.tsx 移除 getFullPathKeys 函数,简化选项处理逻辑。
tests/search.spec.tsx 新增测试用例,验证 Cascader.Search 组件的搜索功能。

Sequence Diagram(s)

Loading
sequenceDiagram
    participant User
    participant Demo
    participant Cascader
    participant useSearchOptions

    User->>Demo: 触发搜索
    Demo->>Cascader: 显示选项
    User->>Cascader: 选择选项
    Cascader->>useSearchOptions: 过滤选项
    useSearchOptions-->>Cascader: 返回过滤后的选项
    Cascader-->>User: 更新显示的选项

Poem

🐇
在草地上跳跃,欢声笑语,
多重搜索,真是乐趣无穷。
组件轻盈,逻辑简明,
兔子欢庆,代码如春风。 🌼
让我们一起,探索新天地!


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:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit testing code for this file.
    • 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 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 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 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.

Tip

Early access features: enabled

We are currently testing the following features in early access:

  • Anthropic claude-3-5-sonnet for code reviews: Anthropic claims that the new Claude model has stronger code understanding and code generation capabilities than their previous models. Note: Our default code review model was also updated late last week. Please compare the quality of the reviews between the two models by toggling the early access feature.

Note:

  • You can enable or disable early access features from the CodeRabbit UI or by updating the CodeRabbit configuration file.
  • Please join our Discord Community to provide feedback and report issues on the discussion post.

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

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 8f927bb and 87c0923.

Files selected for processing (5)
  • docs/demo/multiple-search.md (1 hunks)
  • examples/multiple-search.tsx (1 hunks)
  • src/Cascader.tsx (1 hunks)
  • src/OptionList/Column.tsx (1 hunks)
  • src/hooks/useSearchOptions.ts (3 hunks)
Files skipped from review due to trivial changes (2)
  • docs/demo/multiple-search.md
  • src/OptionList/Column.tsx
Additional comments not posted (3)
examples/multiple-search.tsx (1)

1-49: 审查 React 组件 Demo

此文件引入了一个名为 Demo 的新 React 组件,使用了 Cascader 组件并传入了 checkableshowSearch 属性。整体代码结构清晰,适合作为演示使用。没有发现明显的问题或需要改进的地方。

代码更改已获批准。

src/hooks/useSearchOptions.ts (1)

Line range hint 44-80: 优化 useSearchOptions 函数

此函数通过移除 changeOnSelect 参数简化了搜索选项的处理逻辑。更新的依赖数组正确反映了参数的变化。整体上,这些更改提高了代码的清晰度和效率。

代码更改已获批准。

src/Cascader.tsx (1)

Line range hint 1-300: 移除 Cascader 组件的 changeOnSelect 属性

此更改简化了 Cascader 组件的属性,但可能会影响组件的选择行为。建议进行彻底的测试,以确保移除 changeOnSelect 属性后,组件的功能仍然符合预期。

代码更改已获批准。

请运行以下脚本来验证组件的行为是否符合预期:

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

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 87c0923 and c1c9ac5.

Files selected for processing (1)
  • src/hooks/useSearchOptions.ts (3 hunks)
Files skipped from review as they are similar to previous changes (1)
  • src/hooks/useSearchOptions.ts

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

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between c1c9ac5 and 9a28bad.

Files selected for processing (4)
  • examples/multiple-search.tsx (1 hunks)
  • src/OptionList/Column.tsx (4 hunks)
  • src/OptionList/List.tsx (3 hunks)
  • src/hooks/useSearchOptions.ts (3 hunks)
Files skipped from review as they are similar to previous changes (3)
  • examples/multiple-search.tsx
  • src/OptionList/Column.tsx
  • src/hooks/useSearchOptions.ts
Additional comments not posted (2)
src/OptionList/List.tsx (2)

133-133: 简化了查找当前选项的逻辑。

通过直接比较 option[fieldNames.value]activeValueCell,简化了查找当前选项的逻辑。请确保这一变更没有影响到相关功能的正确性。

代码更改已批准。

运行以下脚本以验证相关功能的影响:


133-133: 移除 Column 组件中的 searchValue 属性。

此更改可能简化了组件,但需要验证搜索功能是否仍然正确实现。

请确认在移除 searchValue 属性后,搜索功能是否有在其他地方正确处理。

运行以下脚本以验证搜索功能的处理:

Verification successful

确认 searchValue 属性已被移除。

在代码库中未找到 searchValue 的使用,表明该属性已被彻底移除。建议检查 OptionList 或相关组件中搜索功能的当前实现,以确保其仍然正常工作。

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# 描述:验证搜索功能在移除 `searchValue` 属性后的处理。

# 测试:搜索 `searchValue` 的使用。预期:不应再使用此属性。
rg --type python -A 5 $'searchValue'

Length of output: 66


Script:

#!/bin/bash
# 描述:验证搜索功能在移除 `searchValue` 属性后的处理。

# 测试:搜索 `searchValue` 的使用。预期:不应再使用此属性。
rg --type js -A 5 'searchValue'

Length of output: 31

Copy link

codecov bot commented Aug 30, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 99.67%. Comparing base (989b3b9) to head (2b1754f).
Report is 2 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master     #530   +/-   ##
=======================================
  Coverage   99.67%   99.67%           
=======================================
  Files          23       23           
  Lines         607      609    +2     
  Branches      183      184    +1     
=======================================
+ Hits          605      607    +2     
  Misses          2        2           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

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

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 9a28bad and 15de04b.

Files selected for processing (2)
  • src/Cascader.tsx (1 hunks)
  • src/hooks/useSearchOptions.ts (3 hunks)
Files skipped from review as they are similar to previous changes (2)
  • src/Cascader.tsx
  • src/hooks/useSearchOptions.ts

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

Outside diff range, codebase verification and nitpick comments (1)
src/hooks/useSearchOptions.ts (1)

Line range hint 18-90: 引入 enableHalfPath 参数

新增了 enableHalfPath 可选参数,似乎是为了替代之前 changeOnSelect 参数的部分功能。建议详细说明此参数的具体用途和影响,以便开发者更好地理解其在函数中的角色。

建议在文档中添加对 enableHalfPath 参数的详细描述,以便开发者能够理解其用途和影响。

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 15de04b and e8cff02.

Files selected for processing (1)
  • src/hooks/useSearchOptions.ts (3 hunks)
Additional comments not posted (2)
src/hooks/useSearchOptions.ts (2)

90-90: 更新依赖数组

更新了 useMemo 的依赖数组,以反映 changeOnSelect 的移除和 enableHalfPath 的添加。这是一个好的实践,确保了函数的响应性和正确性。

依赖数组的更新是正确的。


12-18: 简化函数签名

移除了 changeOnSelect 参数,使函数签名更加简洁。请确认这一变更不会影响项目中其他依赖此函数的部分。

代码更改已批准。

运行以下脚本以验证函数在代码库中的使用情况:

Verification successful

函数签名更新验证成功

useSearchOptions 函数的调用在代码库中已更新为匹配新的签名,特别是在 src/Cascader.tsx 文件中。没有发现与新签名冲突的其他直接使用情况。

  • src/Cascader.tsx: 确认使用了新的函数签名。
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# 描述:验证所有对 `useSearchOptions` 函数的调用都匹配新的签名。

# 测试:搜索函数使用情况。预期:只有新签名的出现。
rg --type typescript -A 5 $'useSearchOptions'

Length of output: 79


Script:

#!/bin/bash
# 描述:验证所有对 `useSearchOptions` 函数的调用都匹配新的签名。

# 测试:搜索函数使用情况。预期:只有新签名的出现。
rg --type ts -A 5 $'useSearchOptions'

Length of output: 2125

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

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between e8cff02 and 2b1754f.

Files selected for processing (1)
  • tests/search.spec.tsx (1 hunks)
Additional comments not posted (2)
tests/search.spec.tsx (2)

205-212: 新增测试用例验证多重选择功能

这个新增的测试用例扩展了现有的功能测试,验证了在进行搜索后选择多个选项的行为。

主要观察点:

  1. 测试首先选择了 "toy" 搜索结果中的一个选项。
  2. 然后进行了 "light" 的搜索,并选择了结果。
  3. 验证 onChange 回调被调用,且参数包含了两个选中的选项路径。

这个测试用例有效地覆盖了多重选择的场景,增强了组件的测试覆盖率。


Line range hint 1-359: 文件总结

本次更改为 Cascader.Search 组件添加了一个新的测试用例,有效地增强了测试覆盖率。新增的测试验证了多重选择的功能,特别是在进行搜索操作后的选择行为。这个添加是有价值的,因为它确保了组件在处理多个选择时的正确性。

整体而言,这个更改是积极的,提高了测试的全面性。

@zombieJ zombieJ merged commit 62bbe3c into react-component:master Sep 2, 2024
10 checks passed
lihongxiangfrontend pushed a commit to lihongxiangfrontend/cascader that referenced this pull request Oct 25, 2024
* feat: optimize search

* feat: test

* feat: test

* feat: test

* feat: test

* feat: add test
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.

None yet

2 participants