-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
feat(tree-select): add check strategy in tree-select #758
Conversation
This pull request is being automatically deployed with Vercel (learn more). 🔍 Inspect: https://vercel.com/tusimple/naive-ui/DpXwX8TajNy3v2mXqCWPck8By2sZ |
Codecov Report
@@ Coverage Diff @@
## main #758 +/- ##
==========================================
- Coverage 47.24% 41.27% -5.98%
==========================================
Files 511 507 -4
Lines 12612 12418 -194
Branches 3550 3491 -59
==========================================
- Hits 5959 5125 -834
- Misses 5636 6367 +731
+ Partials 1017 926 -91
Continue to review full report at Codecov.
|
src/tree-select/src/interface.ts
Outdated
@@ -38,3 +38,5 @@ export interface TreeSelectInjection { | |||
|
|||
export const treeSelectInjectionKey: InjectionKey<TreeSelectInjection> = | |||
Symbol('tree-select') | |||
|
|||
export type CheckStrategy = 'SHOW_ALL' | 'SHOW_PARENT' | 'SHOW_CHILD' |
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.
命名不要全字母大写,也不用这么啰嗦,'all'、'parent'、'child' 即可
@@ -20,6 +21,7 @@ debug | |||
| --- | --- | --- | --- | | |||
| cascade | `boolean` | `false` | 使用 checkbox 进行多选时是否级联 | | |||
| checkable | `boolean` | `false` | 是否使用 checkbox 进行选择 | | |||
| check-strategy | `string` | `'SHOW_ALL'` | 设置勾选策略来指定显示勾选的子节点还是父节点,SHOW_ALL: 默认显示所有选中节点(包括父节点);SHOW_PARENT: 只显示父节点(当父节点下所有子节点都选中时);SHOW_CHILD: 只显示子节点 | |
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.
- API 的 value 取名不好(其他地方有解释)
- 类型可以用 'all' | 'parent' | 'child'
- 描述内容太多太啰嗦太口语化,不用解释每个 value 的含义
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.
这个 Strategy 具体的运算应该在 treemate 那个仓库实现。
比如
const res = dataTreeMateRef.value![checked ? 'check' : 'uncheck'](
node.key,
displayedCheckedKeysRef.value,
{
cascade: props.cascade,
leafOnly: props.leafOnly,
strategy: xxx
}
)
可以把相关的逻辑转移一下,treemate 的测试比较完善
treemate 仓库已实现 等你这边合并发布 |
那边 Review 了,可能需要麻烦你想想有没有更好的方法。 |
已进一步优化,测试已添加 |
Review 了,感觉总体比昨天好很多,还有一点小的疑问需要处理。 |
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.
要注意的是 mergedCheckedKeys 也需要使用 treeMate.getCheckedKeys 过滤一波。
例如在 strategy = parent,value = [0-0] 的时候
- 0
- 0-0
我们应该在选择框中显示 0
而不是 0-0
。所以这就要求我们不能直接把选中的值交给选择框,而是通过 treeMate.getCheckedKeys 滤一遍。
@@ -0,0 +1,141 @@ | |||
# set checkedStrategy |
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.
# set checkedStrategy | |
# Set Check Strategy |
<n-tree-select | ||
multiple | ||
cascade | ||
checkable | ||
checkStrategy="SHOW_PARENT" | ||
:options="options" | ||
:default-value="['Norwegian Wood']" | ||
/> |
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.
把三种都写上
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.
注意 SHOW_PARENT 变成 parent 了
@@ -0,0 +1,141 @@ | |||
# set checkedStrategy | |||
|
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.
把三种的用途写一下
@@ -20,6 +21,7 @@ debug | |||
| --- | --- | --- | --- | | |||
| cascade | `boolean` | `false` | Whether to do cascade check when use checkboxes. | | |||
| checkable | `boolean` | `false` | Whether to use checkbox to select value. | | |||
| check-strategy | `string` | `'all'` | set Check Strategy to show parent node or children. all: show all checked node; parent: show all checked parent node when all child node are checked; child: show all child node | |
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.
| check-strategy | `string` | `'all'` | set Check Strategy to show parent node or children. all: show all checked node; parent: show all checked parent node when all child node are checked; child: show all child node | | |
| check-strategy | `string` | `'all'` | The way to show checked options. `all`: Show all checked node. `parent`: Show all checked parent node when all child node are checked. `child`: show all child node. | |
中文也顺带改一下
@@ -0,0 +1,119 @@ | |||
# 勾选指定策略 |
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.
# 勾选指定策略 | |
# 指定勾选策略 |
@@ -20,6 +21,7 @@ debug | |||
| --- | --- | --- | --- | | |||
| cascade | `boolean` | `false` | 使用 checkbox 进行多选时是否级联 | | |||
| checkable | `boolean` | `false` | 是否使用 checkbox 进行选择 | | |||
| check-strategy | `string` | `'all'` | 设置勾选策略来指定显示勾选的子节点还是父节点,all: 默认显示全部选中节点;parent: 只显示父节点(当父节点下所有子节点都选中时);child: 只显示子节点 | |
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.
| check-strategy | `string` | `'all'` | 设置勾选策略来指定显示勾选的子节点还是父节点,all: 默认显示全部选中节点;parent: 只显示父节点(当父节点下所有子节点都选中时);child: 只显示子节点 | | |
| check-strategy | `string` | `'all'` | 设置勾选策略来指定显示的勾选节点,`all`:显示全部选中节点;`parent`:只显示父节点(当父节点下所有子节点都选中时);`child`:只显示子节点 | |
src/tree/src/Tree.tsx
Outdated
leafOnly: props.leafOnly | ||
}) | ||
doUpdateCheckedKeys(checkedKeys) | ||
const res = dataTreeMateRef.value![checked ? 'check' : 'uncheck']( |
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.
用原来的解构写法
代码没有细看,只是回显做了merge还是emit出去的值也merge了?应该是值也merge了才是正解的。 |
期望的处理方式是 emit 和回显的都要处理 |
这个时候点了 0-0,emit 的值应该是 0 |
了解你的意思 |
可以 rebase 一下,tree-select 有一点更新 |
|
CI 挂了 |
@@ -265,10 +266,16 @@ export default defineComponent({ | |||
if (Array.isArray(mergedValue)) { | |||
const res: SelectBaseOption[] = [] | |||
const { value: treeMate } = dataTreeMateRef | |||
mergedValue.forEach((value) => { | |||
const { checkedKeys } = treeMate.getCheckedKeys(mergedValue) |
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.
不是下面那样处理,那样干的话 treemate 白改了😂。是通过 getCheckedKeys 的第二个 options。
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.
拿到 checkedKeys
<n-tree-select | ||
multiple | ||
cascade | ||
checkable | ||
checkStrategy="parent" | ||
:options="options" | ||
:default-value="['Dig It', 'go']" | ||
@update:value="updateValue" | ||
/> |
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.
把三种策略都写进 demo
close #624