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
This commit is contained in:
Cédric Krier committed 2019-12-07 16:13:32 +01:00
1 parent 32cf93ba84
commit 4aa69d0641
1 file changed
+34 -8
+34 -8
View File
@@ -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();
}