Conversation
useTableMultipleSelect 勾选「全选」时只把当前 list 追加进已选,取消时却 直接 setSelectedItems([])。分页或搜索让 list 变化后,取消全选会把不在当前 list 里的选中项一起清掉。 对话日志页复现:第 1 页勾几条 → 翻到第 2 页 → 全选 → 再取消全选,第 1 页 选中的记录也没了,「已选 N 条」直接归零。 取消时改成只过滤掉当前 list 的 id,与勾选保持对称;单页场景行为不变。
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
Collaborator
|
反选 全选,移除全部应该是符合预期的,需要产品确认。 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
现象
在「应用 → 对话日志」里:
第 1 页勾选的记录也一起没了,计数直接归零,只能重新翻回去勾一遍。
同一个 hook 还用在知识库集合列表、模型表格、工具批量更新抽屉上,凡是
list会因为翻页或搜索变化的地方都会遇到;搜索场景更容易踩到:勾了几行 → 输入关键词让列表变短 → 全选 → 取消全选,之前勾的行被清掉。原因
packages/web/hooks/useTableMultipleSelect.tsx里勾选和取消不对称:isSelecteAll的语义是list.length > 0 && list.every(isSelected),也就是「当前 list 全选中」,勾选也只作用于当前list;取消却是全局清空。selectedItems本身会跨list变化累积(toggleSelect不会重置),所以差异就暴露出来了。修改
取消时只过滤掉当前
list的 id,和勾选保持对称:list就是全部数据的单页场景下,两种写法结果一致,行为不变。验证
新增
packages/web/test/hooks/useTableMultipleSelect.test.ts,用 jsdom 渲染一个只调用该 hook 的壳组件,模拟翻页(切换list):修改前(只加测试、不改实现):
Tests 1 failed | 1 passed (2)修改后,跑完整
test/hooks目录:Test Files 7 passed (7),Tests 21 passed (21)两个用例分别钉住了跨页取消只影响当前页、以及单页取消仍然清空,避免以后改回去。
prettier --check与git diff --check均通过。