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

feat(tree-select): add check strategy in tree-select #758

Merged
merged 15 commits into from
Sep 2, 2021

Conversation

LYErin
Copy link
Contributor

@LYErin LYErin commented Aug 2, 2021

close #624

@vercel
Copy link

vercel bot commented Aug 2, 2021

This pull request is being automatically deployed with Vercel (learn more).
To see the status of your deployment, click below or on the icon next to each commit.

🔍 Inspect: https://vercel.com/tusimple/naive-ui/DpXwX8TajNy3v2mXqCWPck8By2sZ
✅ Preview: https://naive-ui-git-fork-lyerin-feat-tree-select-strategy-tusimple.vercel.app

@codecov
Copy link

codecov bot commented Aug 2, 2021

Codecov Report

Merging #758 (39d8e7f) into main (a715dfd) will decrease coverage by 5.97%.
The diff coverage is 14.28%.

❗ Current head 39d8e7f differs from pull request most recent head 2644384. Consider uploading reports for the commit 2644384 to get more accurate results
Impacted file tree graph

@@            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     
Impacted Files Coverage Δ
src/tree-select/src/TreeSelect.tsx 22.51% <0.00%> (-1.65%) ⬇️
src/tree-select/src/interface.ts 100.00% <ø> (ø)
src/tree/src/Tree.tsx 16.62% <50.00%> (-6.53%) ⬇️
src/preset.ts 0.00% <0.00%> (-100.00%) ⬇️
src/themes/dark.ts 0.00% <0.00%> (-100.00%) ⬇️
src/themes/light.ts 0.00% <0.00%> (-100.00%) ⬇️
src/_internal/icons/Search.tsx 0.00% <0.00%> (-100.00%) ⬇️
src/page-header/styles/dark.ts 0.00% <0.00%> (-100.00%) ⬇️
src/tree/src/MotionWrapper.tsx 0.00% <0.00%> (-100.00%) ⬇️
src/_utils/vue/create-data-key.ts 0.00% <0.00%> (-100.00%) ⬇️
... and 106 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 29577a2...2644384. Read the comment docs.

@@ -38,3 +38,5 @@ export interface TreeSelectInjection {

export const treeSelectInjectionKey: InjectionKey<TreeSelectInjection> =
Symbol('tree-select')

export type CheckStrategy = 'SHOW_ALL' | 'SHOW_PARENT' | 'SHOW_CHILD'
Copy link
Collaborator

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: 只显示子节点 |
Copy link
Collaborator

Choose a reason for hiding this comment

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

  1. API 的 value 取名不好(其他地方有解释)
  2. 类型可以用 'all' | 'parent' | 'child'
  3. 描述内容太多太啰嗦太口语化,不用解释每个 value 的含义

Copy link
Collaborator

@07akioni 07akioni left a 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 的测试比较完善

@LYErin
Copy link
Contributor Author

LYErin commented Aug 3, 2021

这个 Strategy 具体的运算应该在 treemate 那个仓库实现。

比如

const res = dataTreeMateRef.value![checked ? 'check' : 'uncheck'](
        node.key,
        displayedCheckedKeysRef.value,
        {
          cascade: props.cascade,
          leafOnly: props.leafOnly,
          strategy: xxx
        }
      )

可以把相关的逻辑转移一下,treemate 的测试比较完善

treemate 仓库已实现 等你这边合并发布

@07akioni
Copy link
Collaborator

07akioni commented Aug 3, 2021

这个 Strategy 具体的运算应该在 treemate 那个仓库实现。
比如

const res = dataTreeMateRef.value![checked ? 'check' : 'uncheck'](
        node.key,
        displayedCheckedKeysRef.value,
        {
          cascade: props.cascade,
          leafOnly: props.leafOnly,
          strategy: xxx
        }
      )

可以把相关的逻辑转移一下,treemate 的测试比较完善

treemate 仓库已实现 等你这边合并发布

那边 Review 了,可能需要麻烦你想想有没有更好的方法。

@LYErin
Copy link
Contributor Author

LYErin commented Aug 4, 2021

这个 Strategy 具体的运算应该在 treemate 那个仓库实现。
比如

const res = dataTreeMateRef.value![checked ? 'check' : 'uncheck'](
        node.key,
        displayedCheckedKeysRef.value,
        {
          cascade: props.cascade,
          leafOnly: props.leafOnly,
          strategy: xxx
        }
      )

可以把相关的逻辑转移一下,treemate 的测试比较完善

treemate 仓库已实现 等你这边合并发布

那边 Review 了,可能需要麻烦你想想有没有更好的方法。

已进一步优化,测试已添加

@07akioni
Copy link
Collaborator

07akioni commented Aug 4, 2021

这个 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 了,感觉总体比昨天好很多,还有一点小的疑问需要处理。

07akioni/treemate#34 (review)

Copy link
Collaborator

@07akioni 07akioni left a 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
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
# set checkedStrategy
# Set Check Strategy

Comment on lines 4 to 11
<n-tree-select
multiple
cascade
checkable
checkStrategy="SHOW_PARENT"
:options="options"
:default-value="['Norwegian Wood']"
/>
Copy link
Collaborator

Choose a reason for hiding this comment

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

把三种都写上

Copy link
Collaborator

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

Copy link
Collaborator

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 |
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
| 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 @@
# 勾选指定策略
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
# 勾选指定策略
# 指定勾选策略

@@ -20,6 +21,7 @@ debug
| --- | --- | --- | --- |
| cascade | `boolean` | `false` | 使用 checkbox 进行多选时是否级联 |
| checkable | `boolean` | `false` | 是否使用 checkbox 进行选择 |
| check-strategy | `string` | `'all'` | 设置勾选策略来指定显示勾选的子节点还是父节点,all: 默认显示全部选中节点;parent: 只显示父节点(当父节点下所有子节点都选中时);child: 只显示子节点 |
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
| check-strategy | `string` | `'all'` | 设置勾选策略来指定显示勾选的子节点还是父节点,all: 默认显示全部选中节点;parent: 只显示父节点(当父节点下所有子节点都选中时);child: 只显示子节点 |
| check-strategy | `string` | `'all'` | 设置勾选策略来指定显示的勾选节点,`all`:显示全部选中节点;`parent`只显示父节点当父节点下所有子节点都选中时);`child`只显示子节点 |

leafOnly: props.leafOnly
})
doUpdateCheckedKeys(checkedKeys)
const res = dataTreeMateRef.value![checked ? 'check' : 'uncheck'](
Copy link
Collaborator

Choose a reason for hiding this comment

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

用原来的解构写法

@pipinet
Copy link

pipinet commented Aug 7, 2021

代码没有细看,只是回显做了merge还是emit出去的值也merge了?应该是值也merge了才是正解的。

@07akioni
Copy link
Collaborator

07akioni commented Aug 7, 2021

了merge还是emit出去的值也merge了?应该

期望的处理方式是 emit 和回显的都要处理

@07akioni
Copy link
Collaborator

07akioni commented Aug 7, 2021

了merge还是emit出去的值也merge了?应该

期望的处理方式是 emit 和回显的都要处理

  1. 例如在 strategy = parent,value = [0-0] 的时候
  • 0
    • 0-0
      我们应该在选择框中显示 0 而不是 0-0。所以这就要求我们不能直接把选中的值交给选择框,而是通过 treeMate.getCheckedKeys 滤一遍。
  1. 例如在 strategy = parent,value = [] 的时候
  • 0
    • 0-0

这个时候点了 0-0,emit 的值应该是 0

@07akioni
Copy link
Collaborator

07akioni commented Aug 7, 2021

@LYErin @pipinet treemate 0.3 已经可以用了

@pipinet
Copy link

pipinet commented Aug 8, 2021

@LYErin @pipinet treemate 0.3 已经可以用了

太棒了!

@LYErin LYErin closed this Aug 8, 2021
@LYErin
Copy link
Contributor Author

LYErin commented Aug 8, 2021

了merge还是emit出去的值也merge了?应该

期望的处理方式是 emit 和回显的都要处理

  1. 例如在 strategy = parent,value = [0-0] 的时候
  • 0

    • 0-0
      我们应该在选择框中显示 0 而不是 0-0。所以这就要求我们不能直接把选中的值交给选择框,而是通过 treeMate.getCheckedKeys 滤一遍。
  1. 例如在 strategy = parent,value = [] 的时候
  • 0

    • 0-0

这个时候点了 0-0,emit 的值应该是 0

了解你的意思

@07akioni
Copy link
Collaborator

07akioni commented Aug 8, 2021

可以 rebase 一下,tree-select 有一点更新

@LYErin
Copy link
Contributor Author

LYErin commented Aug 8, 2021

可以 rebase 一下,tree-select 有一点更新
解决冲突啦,你看看,回显那边也兼容策略了

@07akioni
Copy link
Collaborator

07akioni commented Aug 8, 2021

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)
Copy link
Collaborator

Choose a reason for hiding this comment

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

不是下面那样处理,那样干的话 treemate 白改了😂。是通过 getCheckedKeys 的第二个 options。

Copy link
Collaborator

Choose a reason for hiding this comment

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

拿到 checkedKeys

Comment on lines 4 to 12
<n-tree-select
multiple
cascade
checkable
checkStrategy="parent"
:options="options"
:default-value="['Dig It', 'go']"
@update:value="updateValue"
/>
Copy link
Collaborator

Choose a reason for hiding this comment

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

把三种策略都写进 demo

src/tree-select/demos/zhCN/check-strategy.demo.md Outdated Show resolved Hide resolved
@07akioni 07akioni merged commit 6ccbe86 into tusen-ai:main Sep 2, 2021
@LYErin LYErin deleted the feat-tree-select-strategy branch September 20, 2021 01:46
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.

Tree Select支持指定选中策略
4 participants