Fix UI for "Mark Reviewed"/"Mark Unreviewed"
The _shownFiles is a computed property and it return subarray of
_files array. The items in the _shownFiles are shared with the _files.
Due to it, changes of isReviewed property of a file in _files array
should fire a changed event for _shownFiles item. In Polymer 1 it can
be done with set(...) method. In Polymer 2 this doesn't work, because
set(...) doesn't change anything. Instead notifyPath should be used.
The _shownFiles array itself must be updated only when _files array
is changed and shouldn't be updated when some nested property is
changed.
Bug: Issue 11542
Change-Id: I30102aed67f8f7bd7a31ca6a2e0709bf29e83227
diff --git a/polygerrit-ui/app/elements/change/gr-file-list/gr-file-list.js b/polygerrit-ui/app/elements/change/gr-file-list/gr-file-list.js
index 37beff4..9e6997c 100644
--- a/polygerrit-ui/app/elements/change/gr-file-list/gr-file-list.js
+++ b/polygerrit-ui/app/elements/change/gr-file-list/gr-file-list.js
@@ -148,7 +148,7 @@
_shownFiles: {
type: Array,
- computed: '_computeFilesShown(numFilesShown, _files.*)',
+ computed: '_computeFilesShown(numFilesShown, _files)',
},
/**
@@ -473,7 +473,7 @@
this.set(['_files', index, 'isReviewed'], reviewed);
if (index < this._shownFiles.length) {
- this.set(['_shownFiles', index, 'isReviewed'], reviewed);
+ this.notifyPath(`_shownFiles.${index}.isReviewed`);
}
this._saveReviewedState(path, reviewed);
@@ -855,7 +855,7 @@
const previousNumFilesShown = this._shownFiles ?
this._shownFiles.length : 0;
- const filesShown = files.base.slice(0, numFilesShown);
+ const filesShown = files.slice(0, numFilesShown);
this.fire('files-shown-changed', {length: filesShown.length});
// Start the timer for the rendering work hwere because this is where the
diff --git a/polygerrit-ui/app/elements/change/gr-file-list/gr-file-list_test.html b/polygerrit-ui/app/elements/change/gr-file-list/gr-file-list_test.html
index 9529d38..cc3e937 100644
--- a/polygerrit-ui/app/elements/change/gr-file-list/gr-file-list_test.html
+++ b/polygerrit-ui/app/elements/change/gr-file-list/gr-file-list_test.html
@@ -1709,8 +1709,9 @@
// Commit message should not have edit controls.
const editControls =
- Polymer.dom(element.root).querySelectorAll('.row:not(.header)')
- .map(row => row.querySelector('gr-edit-file-controls'));
+ Array.from(
+ Polymer.dom(element.root).querySelectorAll('.row:not(.header)'))
+ .map(row => row.querySelector('gr-edit-file-controls'));
assert.isTrue(editControls[0].classList.contains('invisible'));
});