Skip to content

Commit

Permalink
fix(module: tree): fix default keys bug with setTimeOut
Browse files Browse the repository at this point in the history
close #3001

fix(module: tree): remove unused code

fix(module: tree): fix spec test

fix(module: tree): fix tree-select spec test

fix(module: tree): fix tree spec test
  • Loading branch information
simplejason committed Mar 2, 2019
1 parent 623a9ff commit 21bfa3c
Show file tree
Hide file tree
Showing 14 changed files with 447 additions and 263 deletions.
9 changes: 6 additions & 3 deletions components/tree-select/nz-tree-select.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ export class NzTreeSelectComponent implements ControlValueAccessor, OnInit, OnDe
if (this.selectedNodes.length) {
const removeNode = this.selectedNodes[ this.selectedNodes.length - 1 ];
this.removeSelected(removeNode);
this.nzTreeService.$statusChange.next({
this.nzTreeService.triggerEventChange$.next({
'eventName': 'removeSelect',
'node' : removeNode
});
Expand All @@ -274,7 +274,7 @@ export class NzTreeSelectComponent implements ControlValueAccessor, OnInit, OnDe
node.isChecked = false;
if (this.nzCheckable) {
this.nzTreeService.conduct(node);
this.nzTreeService.setCheckedNodeList(node);
// this.nzTreeService.setCheckedNodeList(node);
} else {
this.nzTreeService.setSelectedNodeList(node, this.nzMultiple);
}
Expand Down Expand Up @@ -305,7 +305,7 @@ export class NzTreeSelectComponent implements ControlValueAccessor, OnInit, OnDe
if (this.nzCheckable && !node.isDisabled && !node.isDisableCheckbox) {
node.isChecked = !node.isChecked;
this.nzTreeService.conduct(node);
this.nzTreeService.setCheckedNodeList(node);
// this.nzTreeService.setCheckedNodeList(node);
}
if (this.nzCheckable) {
node.isSelected = false;
Expand Down Expand Up @@ -341,6 +341,7 @@ export class NzTreeSelectComponent implements ControlValueAccessor, OnInit, OnDe
updateSelectedNodes(init: boolean = false): void {
if (init) {
let nodes;
this.nzTreeService.isMultiple = this.isMultiple;
if (!this.nzTreeService.isArrayOfNzTreeNode(this.nzNodes)) {
// has not been new NzTreeNode
nodes = this.nzNodes.map(item => (new NzTreeNode(item, null, this.nzTreeService)));
Expand All @@ -355,6 +356,8 @@ export class NzTreeSelectComponent implements ControlValueAccessor, OnInit, OnDe
}
}
this.selectedNodes = [ ...(this.nzCheckable ? this.nzTreeService.getCheckedNodeList() : this.nzTreeService.getSelectedNodeList()) ];
// console.log(this.nzCheckable, this.selectedNodes.length, this.selectedNodes, this.value, this.value.length, '===');

}

updatePosition(): void {
Expand Down
2 changes: 2 additions & 0 deletions components/tree-select/nz-tree-select.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,9 @@ describe('tree-select component', () => {
expect(selectedValueEl.style.opacity).toBe('1');
}));
it('should max tag count work', fakeAsync(() => {
fixture.detectChanges();
testComponent.multiple = true;
fixture.detectChanges();
testComponent.value = [ '1001', '10001', '100011', '100012' ];
fixture.detectChanges();
tick(200);
Expand Down
14 changes: 7 additions & 7 deletions components/tree/demo/basic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,20 @@ import { NzFormatEmitEvent, NzTreeNodeOptions } from 'ng-zorro-antd';
<nz-tree
#treeCom
[nzData]="nodes"
[nzDraggable]="true"
nzCheckable
[nzCheckedKeys]="defaultCheckedKeys"
[nzExpandedKeys]="defaultExpandedKeys"
[nzSelectedKeys]="defaultSelectedKeys"
(nzClick)="nzClick($event)"
(nzCheckBoxChange)="nzCheck($event)">
(nzCheckBoxChange)="nzCheck($event)"
(nzExpandChange)="nzCheck($event)">
</nz-tree>
`
})

export class NzDemoTreeBasicComponent implements OnInit {
@ViewChild('treeCom') treeCom;
defaultCheckedKeys = [ '1001', '1002' ];
defaultSelectedKeys = [ '10010', '10020' ];
defaultCheckedKeys = [ '10020' ];
defaultSelectedKeys = [ '10010' ];
defaultExpandedKeys = [ '100', '1001' ];

nodes: NzTreeNodeOptions[] = [ {
Expand All @@ -33,11 +32,12 @@ export class NzDemoTreeBasicComponent implements OnInit {
disabled: true,
children: [
{ title: 'leaf 1-0-0', key: '10010', disableCheckbox: true, isLeaf: true },
{ title: 'leaf 1-0-1', key: '10011', isLeaf: true, checked: true }
{ title: 'leaf 1-0-1', key: '10011', isLeaf: true }
]
}, {
title : 'parent 1-1',
key : '1002',
selected: true,
children: [
{ title: 'leaf 1-1-0', key: '10020', isLeaf: true },
{ title: 'leaf 1-1-1', key: '10021', isLeaf: true }
Expand All @@ -50,7 +50,7 @@ export class NzDemoTreeBasicComponent implements OnInit {
}

nzCheck(event: NzFormatEmitEvent): void {
console.log(event, event.checkedKeys, event.keys, event.nodes);
console.log(event);
}

// nzSelectedKeys change
Expand Down
5 changes: 2 additions & 3 deletions components/tree/demo/directory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,14 +102,13 @@ export class NzDemoTreeDirectoryComponent {
openFolder(data: NzTreeNode | NzFormatEmitEvent): void {
// do something if u want
if (data instanceof NzTreeNode) {
data.setExpanded(!data.isExpanded);
data.isExpanded = !data.isExpanded;
} else {
data.node.setExpanded(!data.node.isExpanded);
data.node.isExpanded = !data.node.isExpanded;
}
}

activeNode(data: NzFormatEmitEvent): void {
data.node.setExpanded(true);
this.activedNode = data.node;
}

Expand Down
8 changes: 7 additions & 1 deletion components/tree/demo/draggable.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import { Component, OnInit } from '@angular/core';
import { NzFormatEmitEvent } from 'ng-zorro-antd';

@Component({
selector: 'nz-demo-tree-draggable',
template: `
<nz-tree
[nzData]="nodes"
nzDraggable="true">
nzDraggable="true"
(nzOnDrop)="afterDrop($event)">
</nz-tree>
`,
styles : [ `
Expand Down Expand Up @@ -67,6 +69,10 @@ export class NzDemoTreeDraggableComponent implements OnInit {
isLeaf: true
} ];

afterDrop(event: NzFormatEmitEvent): void {
console.log(event);
}

ngOnInit(): void {
}
}
5 changes: 0 additions & 5 deletions components/tree/doc/index.en-US.md
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,6 @@ Almost anything can be represented in a tree structure. Examples include directo
| isDisableCheckbox | Whether treeNode's checkbox can not be clicked | `boolean` | `true` / `false` |
| isSelectable | Set whether the treeNode can be selected | `boolean` | `true``false` |
| isChecked | Whether treeNode is checked | `boolean` | `true` / `false` |
| isAllChecked | Whether all treeNode's children are checked | `boolean` | `true` / `false` |
| isHalfChecked | Part of treeNode's children are checked | `boolean` | `true` / `false` |
| isSelected | Whether treeNode is selected | `boolean` | `true` / `false` |
| isLoading | Whether treeNode is loading(when nzAsyncData is true) | `boolean` | `true` / `false` |
Expand All @@ -119,10 +118,6 @@ Almost anything can be represented in a tree structure. Examples include directo
| addChildren | Add child nodes, receive NzTreeNode or NzTreeNodeOptions array, the second parameter is the inserted index position | (children: array, index?: number )=>{} | void |
| clearChildren | Clear the treeNode's children | function | void |
| remove | Clear current node(not root node) | function | void |
| setSyncChecked | set isChecked & isHalfChecked state,params: checked , halfChecked.(will affect other nodes checked state) | (checked: boolean, halfChecked: boolean=false)=>{} | void |
| setChecked | set isChecked & isHalfChecked state,params: checked , halfChecked | (checked: boolean, halfChecked: boolean=false)=>{} | void |
| setExpanded | set isExpanded state | (value: boolean)=>{} | void |
| setSelected | set isSelected state | (value: boolean)=>{} | void |

## Note
`NzTreeNodeOptions` accepts your customized properties,use NzTreeNode.origin to get them.
5 changes: 0 additions & 5 deletions components/tree/doc/index.zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,6 @@ subtitle: 树形控件
| isDisableCheckbox | 是否禁用 checkBox | `boolean` | `true``false` |
| isSelectable | 是否可选中 | `boolean` | `true``false` |
| isChecked | 是否选中 checkBox | `boolean` | `true``false` |
| isAllChecked | 子节点是否全选 | `boolean` | `true``false` |
| isHalfChecked | 子节点有选中但未全选 | `boolean` | `true``false` |
| isSelected | 是否已选中 | `boolean` | `true``false` |
| isLoading | 是否异步加载状态(影响展开图标展示) | `boolean` | `true``false` |
Expand All @@ -123,10 +122,6 @@ subtitle: 树形控件
| addChildren | 添加子节点,接收NzTreeNode或NzTreeNodeOptions数组,第二个参数为插入的索引位置,默认插入末尾 | (children: array, index?: number )=>{} | void |
| clearChildren | 清除子节点 | function | void |
| remove | 清除当前节点(非根节点) | function | void |
| setSyncChecked | 设置checked状态(同步树组件节点 checked 状态) | (checked: boolean, halfChecked: boolean=false)=>{} | void |
| setChecked | 设置checked状态,参数为checked和halfChecked | (checked: boolean, halfChecked: boolean=false)=>{} | void |
| setExpanded | 设置expanded状态 | (value: boolean)=>{} | void |
| setSelected | 设置selected状态 | (value: boolean)=>{} | void |


## 注意
Expand Down
Loading

0 comments on commit 21bfa3c

Please sign in to comment.