changeset be89d412427d in sao:default
details: https://hg.tryton.org/sao?cmd=changeset;node=be89d412427d
description:
Do not re-construct tree view if the same records are to display
Re-construct the tree looses the cursor, the expand state and the
editable
cell. Until now, we always re-constructed the tree on display because
there was
no simple test like the size for the list.
Now we compare the flat list of records following the expanded row. We
re-construct the table only if they are different.
issue8854
review264671003
diffstat:
src/view/tree.js | 42 ++++++++++++++++++++++++++++++++++--------
1 files changed, 34 insertions(+), 8 deletions(-)
diffs (63 lines):
diff -r 69bce9f6d279 -r be89d412427d src/view/tree.js
--- a/src/view/tree.js Sat Dec 07 16:07:42 2019 +0100
+++ b/src/view/tree.js Sat Dec 07 16:13:32 2019 +0100
@@ -541,25 +541,51 @@
this.selection.hide();
}
- var row_records = function() {
- return this.rows.map(function(row) {
- return row.record;
- });
+ var group_records = function(group, root) {
+ var records = [];
+ for (var i = 0; i < group.length; i++) {
+ var record = group[i];
+ records.push(record);
+ var path = root.concat([record.id]);
+ if (Sao.common.contains(expanded, path)) {
+ var children = record.field_get_client(
+ this.children_field);
+ Array.prototype.push.apply(
+ records, group_records(children, path));
+ }
+ }
+ return records;
+ }.bind(this);
+
+ var row_records = function(rows) {
+ var records = [];
+ for (var i = 0; i < rows.length; i++) {
+ var row = rows[i];
+ records.push(row.record);
+ if (row.is_expanded()) {
+ Array.prototype.push.apply(
+ records, row_records(row.rows));
+ }
+ }
+ return records;
}.bind(this);
var min_display_size = Math.min(
this.group.length, this.display_size);
- // XXX find better check to keep focus and expanded
if (this.children_field) {
- this.construct();
+ if (!Sao.common.compare(
+ group_records(this.group.slice(0, min_display_size), []),
+ row_records(this.rows))) {
+ this.construct();
+ }
} else if ((min_display_size > this.rows.length) &&
Sao.common.compare(
this.group.slice(0, this.rows.length),
- row_records())) {
+ row_records(this.rows))) {
this.construct(true);
} else if ((min_display_size != this.rows.length) ||
!Sao.common.compare(
this.group.slice(0, this.rows.length),
- row_records())){
+ row_records(this.rows))){
this.construct();
}