Fix binding for visible file number

File numbers were added to the diff view in c5069b1cd2, but would not
appear because the binding passed the file number whereas the visibility
method expected a file path. With this change, the method is rewritten
to accept the file number and a JSDoc comment is added to prevent the
type mismatch. The CSS is also modified to hide the element until the
dependent properties have evaluated.

Bug: Issue 4917
Change-Id: I7b880e65612e3b75e80b66dfd7a258608199c49b
This commit is contained in:
Wyatt Allen 2018-03-06 11:27:36 -08:00
parent 50f823a0f5
commit 54ce5dc8e3
3 changed files with 17 additions and 13 deletions
polygerrit-ui/app/elements/diff/gr-diff-view

@ -124,10 +124,12 @@ limitations under the License.
.editMode .hideOnEdit {
display: none;
}
.blameLoader {
.blameLoader,
.fileNum {
display: none;
}
.blameLoader.show,
.fileNum.show ,
.download,
.preferences,
.rightControls {
@ -230,7 +232,7 @@ limitations under the License.
</div>
</h3>
<div class="navLinks desktop">
<span class$="fileNum [[_computeFileNumVisible(_fileNum, _formattedFiles)]]">
<span class$="fileNum [[_computeFileNumClass(_fileNum, _formattedFiles)]]">
File [[_fileNum]] of [[_formattedFiles.length]]
<span class="separator"></span>
</span>

@ -959,14 +959,16 @@
return files.findIndex(({value}) => value === file) + 1;
},
_computeFileNumVisible(file, files) {
if (!files) { return 'hidden'; }
const fileNum = this._computeFileNum(file, files);
if (!isNaN(fileNum) && isFinite(fileNum) && fileNum > 0) {
return '';
} else {
return 'hidden';
/**
* @param {number} fileNum
* @param {!Array<string>} files
* @return {string}
*/
_computeFileNumClass(fileNum, files) {
if (files && fileNum > 0) {
return 'show';
}
return '';
},
});
})();

@ -988,10 +988,10 @@ limitations under the License.
[{value: '/foo'}, {value: '/bar'}]), 2);
});
test('_computeFileNumVisible', () => {
assert.equal(element._computeFileNumVisible('', []), 'hidden');
assert.equal(element._computeFileNumVisible('/bar',
[{value: '/foo'}, {value: '/bar'}]), '');
test('_computeFileNumClass', () => {
assert.equal(element._computeFileNumClass(0, []), '');
assert.equal(element._computeFileNumClass(1,
[{value: '/foo'}, {value: '/bar'}]), 'show');
});
suite('editMode behavior', () => {