Skip to content
This repository was archived by the owner on Nov 20, 2018. It is now read-only.

Commit dbde13b

Browse files
committed
Update E2E test, fix last smal problems with anim.
1 parent 82bfa21 commit dbde13b

12 files changed

+58
-35
lines changed

.travis.yml

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,17 @@ dist: trusty
33
addons:
44
apt:
55
sources:
6-
- google-chrome
6+
- google-chrome
77
packages:
8-
- google-chrome-stable
8+
- google-chrome-stable
99
language: node_js
1010
node_js:
11-
- 6
11+
- 6
1212
before_script:
13-
- export DISPLAY=:99.0
14-
- sh -e /etc/init.d/xvfb start
13+
- export DISPLAY=:99.0
14+
- sh -e /etc/init.d/xvfb start
1515
install:
16-
- npm install
16+
- npm install
1717
script:
18-
- ./node_modules/.bin/webdriver-manager update
19-
- npm run ci
18+
- ./node_modules/.bin/webdriver-manager update
19+
- npm run ci

README.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -159,22 +159,22 @@ and _newItem.component.html_
159159
</div>
160160
</div>
161161
<div class="tree" *ngIf="isExpanded" [@expand]>
162-
<ri-tree-item *ngFor="let child of children$ | async" [node]="child"
162+
<ri-tree-item *ngFor="let child of children$ | async" [node]="child; trackBy: trackByFn"
163163
[treeModel]="treeModel"
164-
[isExpanded]="treeModel.isExpanded(child.id)"
165-
[isSelected]="treeModel.isSelected(child.id)"
164+
[isExpanded]="treeModel.isExpanded(child)"
165+
[isSelected]="treeModel.isSelected(child)"
166166
[contextMenu]="contextMenu"></ri-tree-item>
167167
</div>
168168

169169

170170
Then when you create tree component in your application use such construction
171171

172172
<rign-tree [treeModel]="treeModel">
173-
<new-tree-item *ngFor="let node of treeModel.getRootNodes() | async"
173+
<new-tree-item *ngFor="let node of treeModel.getRootNodes() | async; trackBy: trackByFn"
174174
[node]="node"
175175
[treeModel]="treeModel"
176-
[isSelected]="treeModel.isSelected(node.id)"
177-
[isExpanded]="treeModel.isExpanded(node.id)"
176+
[isSelected]="treeModel.isSelected(node)"
177+
[isExpanded]="treeModel.isExpanded(node)"
178178
[contextMenu]="contextMenu"></new-tree-item>
179179
</rign-tree>
180180

demo/src/app/treeTwo/newItem.component.html

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,10 @@
2828
</div>
2929
</div>
3030
<div class="tree" *ngIf="isExpanded">
31-
<new-tree-item *ngFor="let child of children$ | async"
31+
<new-tree-item *ngFor="let child of children$ | async; trackBy: trackByFn"
3232
[node]="child"
3333
[treeModel]="treeModel"
34-
[isExpanded]="treeModel.isExpanded(child.id)"
35-
[isSelected]="treeModel.isSelected(child.id)"
34+
[isExpanded]="treeModel.isExpanded(child)"
35+
[isSelected]="treeModel.isSelected(child)"
3636
[contextMenu]="contextMenu"></new-tree-item>
3737
</div>
Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
<ri-tree [treeModel]="treeModel">
22
<new-tree-item class="root-node"
3-
*ngFor="let node of treeModel.rootNodes$ | async" [node]="node"
3+
*ngFor="let node of treeModel.rootNodes$ | async; trackBy: trackByFn"
4+
[node]="node"
45
[treeModel]="treeModel"
5-
[isExpanded]="treeModel.isExpanded(node.id)"
6-
[isSelected]="treeModel.isSelected(node.id)"
6+
[isExpanded]="treeModel.isExpanded(node)"
7+
[isSelected]="treeModel.isSelected(node)"
78
[contextMenu]="contextMenu"></new-tree-item>
89
</ri-tree>

demo/src/app/treeTwo/treeTwo.component.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import {Component, OnDestroy, OnInit} from '@angular/core';
2-
import {IConfiguration, IContextMenu, ITreeData, TreeModel} from '../../../../main';
2+
import {IConfiguration, IContextMenu, IOuterNode, ITreeData, TreeModel} from '../../../../main';
33
import {Observable} from 'rxjs/Observable';
44
import {TreeInitializerService} from '../../../../src/service/initializer.service';
5-
import {TreeTwoNodeBackendService} from './treeTwoNodeBackend.service';
5+
import {TreeTwoNodeService} from './treeTwoNode.service';
66

77
@Component({
88
selector: 'app-tree-two',
@@ -24,7 +24,7 @@ export class TreeTwoComponent implements OnInit, OnDestroy {
2424
public treeModel: TreeModel;
2525

2626
public constructor(private treeInitializerService: TreeInitializerService,
27-
private treeTwoNodeService: TreeTwoNodeBackendService) {
27+
private treeTwoNodeService: TreeTwoNodeService) {
2828
}
2929

3030
public ngOnInit(): void {
@@ -34,4 +34,8 @@ export class TreeTwoComponent implements OnInit, OnDestroy {
3434
public ngOnDestroy(): void {
3535
this.treeModel.destroy();
3636
}
37+
38+
public trackByFn(item: IOuterNode): string {
39+
return item.id;
40+
}
3741
}

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,10 @@
1919
"clean:all": "rimraf dist/ && npm run clean:tmp",
2020
"clean:tmp": "rimraf tmp/",
2121
"lint": "ng lint",
22-
"e2e": "rm -rf e2e/screenshots/* && ng e2e -wu false -s false",
22+
"e2e": "rm -rf e2e/screenshots/* && ng e2e -wu false",
2323
"test": "./node_modules/.bin/karma --config karma.conf.js start",
2424
"gh-pages": "ng build --prod --base-href \"https://qjon.github.io/angular2-tree/\" && ./node_modules/.bin/angular-cli-ghpages -b gh-pages --name=\"Rafał Ignaszewski\" --email=\"[email protected]\" --no-silent",
25-
"ci": "npm run test && ng e2e -wu false"
25+
"ci": "npm run test && ng e2e"
2626
},
2727
"repository": {
2828
"type": "git",

src/item/item.component.html

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,10 @@
1717
</form>
1818
</div>
1919
<div class="tree" *ngIf="isExpanded" [@expand]>
20-
<ri-tree-item *ngFor="let child of children$ | async" [node]="child"
20+
<ri-tree-item *ngFor="let child of children$ | async; trackBy: trackByFn"
21+
[node]="child"
2122
[treeModel]="treeModel"
22-
[isExpanded]="treeModel.isExpanded(child.id)"
23-
[isSelected]="treeModel.isSelected(child.id)"
23+
[isExpanded]="treeModel.isExpanded(child)"
24+
[isSelected]="treeModel.isSelected(child)"
2425
[contextMenu]="contextMenu"></ri-tree-item>
2526
</div>

src/item/item.component.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,10 @@ export class ItemComponent implements OnInit, OnDestroy, OnChanges {
216216
}
217217
}
218218

219+
public trackByFn(item: IOuterNode): string {
220+
return item.id;
221+
}
222+
219223
protected getChildren(): Observable<IOuterNode[]> {
220224
return this.treeModel.getChildren(this.node.id);
221225
}

src/models/TreeModel.ts

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -112,12 +112,20 @@ export class TreeModel {
112112
this.store.dispatch(new TreeLoadPathAction({treeId: this.configuration.treeId, ids: path}));
113113
}
114114

115-
public isExpanded(nodeId: string): boolean {
116-
return this.expanded.has(nodeId);
115+
public isExpanded(node: IOuterNode): boolean {
116+
if (!node) {
117+
return false;
118+
}
119+
120+
return this.expanded.has(node.id);
117121
}
118122

119-
public isSelected(nodeId: string): boolean {
120-
return this.selected === nodeId;
123+
public isSelected(node: IOuterNode): boolean {
124+
if (!node) {
125+
return false;
126+
}
127+
128+
return this.selected === node.id;
121129
}
122130

123131
public wasPreviouslySelected(nodeId: string): boolean {

src/store/treeEffects.service.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,7 @@ export class TreeEffectsService {
179179
public insert$ = this.actions$
180180
.ofType(TreeActionTypes.TREE_INSERT_NODE)
181181
.pipe(
182+
filter((action: TreeInsertNodeAction) => !!action.payload.parentId),
182183
map((action: TreeInsertNodeAction) => {
183184
return new TreeExpandNodeAction({treeId: action.payload.treeId, id: action.payload.parentId});
184185
})

src/tree.component.html

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@
88
<div *ngIf="customTemplate.childNodes.length === 0">
99
<ri-tree-item
1010
class="root-node"
11-
*ngFor="let node of rootNodes$ | async"
11+
*ngFor="let node of rootNodes$ | async; trackBy: trackByFn"
1212
[node]="node"
1313
[treeModel]="treeModel"
14-
[isSelected]="treeModel.isSelected(node.id)"
15-
[isExpanded]="treeModel.isExpanded(node.id)"
14+
[isSelected]="treeModel.isSelected(node)"
15+
[isExpanded]="treeModel.isExpanded(node)"
1616
[contextMenu]="contextMenu"></ri-tree-item>
1717
</div>
1818
<ri-dropzone [treeModel]="treeModel"></ri-dropzone>

src/tree.component.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,10 @@ export class TreeComponent implements OnInit, OnChanges {
103103
}
104104
}
105105

106+
public trackByFn(item: IOuterNode): string {
107+
return item.id;
108+
}
109+
106110
/**
107111
* Register data "move event"
108112
*/

0 commit comments

Comments
 (0)