Skip to content
This repository was archived by the owner on Aug 7, 2020. It is now read-only.

Commit 7e63fb7

Browse files
authored
Merge pull request #76 from ovh-ux/fixDatagridRowLoader
fix(datagrid): prevent useless calls to row-loader
2 parents 88faaf0 + 5bfbebf commit 7e63fb7

File tree

4 files changed

+24
-6
lines changed

4 files changed

+24
-6
lines changed

packages/oui-datagrid/src/datagrid.controller.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,10 @@ export default class DatagridController {
119119
if (!angular.equals(this.previousRows, this.rows)) {
120120
this.previousRows = angular.copy(this.rows);
121121

122-
if (this.rows && this.paging) {
122+
// Prevent recall this if there is no page change.
123+
// this.paging.preventLoadingRows is true if there has been no page
124+
// or page size change since last call.
125+
if (this.rows && this.paging && !this.paging.preventLoadingRows) {
123126
this.refreshData(() => this.paging.setRows(this.rows));
124127
}
125128
}

packages/oui-datagrid/src/paging/datagrid-local-paging.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ export default class DatagridLocalPaging extends DatagridPagingAbstract {
66

77
this.rows = rows;
88
this.rowLoader = rowLoader;
9-
109
this.totalCount = rows ? rows.length : 0;
1110
}
1211

@@ -28,7 +27,15 @@ export default class DatagridLocalPaging extends DatagridPagingAbstract {
2827
}
2928
})
3029
.then(result => {
31-
this.loadRowsData(result.data);
30+
this.preventLoadingRows = true;
31+
this.loadRowsData(result.data)
32+
.finally(() => {
33+
// Delay the change of the value to prevent $doCheck of DatagridController
34+
// calling refreshData for the last update.
35+
this.$timeout(() => {
36+
this.preventLoadingRows = false;
37+
});
38+
});
3239
this.totalCount = result.meta.totalCount;
3340

3441
return result;

packages/oui-datagrid/src/paging/datagrid-paging-abstract.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,10 @@ export default class DatagridPagingAbstract {
99
this.rowLoader = rowLoader;
1010

1111
this.$q = pagingService.$q;
12+
this.$timeout = pagingService.$timeout;
1213
this.orderByFilter = pagingService.orderByFilter;
14+
15+
this.preventLoadingRows = false;
1316
}
1417

1518
setOffset (offset) {
@@ -69,10 +72,10 @@ export default class DatagridPagingAbstract {
6972

7073
loadRowsData (rows) {
7174
if (!this.rowLoader) {
72-
return;
75+
return this.$q.when();
7376
}
7477

75-
rows.forEach(row => this.loadRowData(row));
78+
return this.$q.all(rows.map(row => this.loadRowData(row)));
7679
}
7780

7881
loadRowData (row) {
@@ -83,9 +86,13 @@ export default class DatagridPagingAbstract {
8386
delete row.$promise;
8487
});
8588

89+
return row.$promise;
90+
8691
// TODO: Find a way to forward those error to datagrid
8792
/* .catch(this.handleError.bind(this)) */
8893
}
94+
95+
return this.$q.when();
8996
}
9097

9198
/**

packages/oui-datagrid/src/paging/datagrid-paging.service.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,11 @@ import DatagridLocalPaging from "./datagrid-local-paging";
22
import DatagridRemotePaging from "./datagrid-remote-paging";
33

44
export default class {
5-
constructor ($q, orderByFilter) {
5+
constructor ($q, $timeout, orderByFilter) {
66
"ngInject";
77

88
this.$q = $q;
9+
this.$timeout = $timeout;
910
this.orderByFilter = orderByFilter;
1011
}
1112

0 commit comments

Comments
 (0)