Merge "Add total change counts to file list in change view"

This commit is contained in:
Andrew Bonventre
2016-10-11 00:57:03 +00:00
committed by Gerrit Code Review
3 changed files with 73 additions and 2 deletions

View File

@@ -89,7 +89,8 @@ limitations under the License.
.invisible {
visibility: hidden;
}
.row:not(.header) .stats {
.row:not(.header) .stats,
.total-stats {
font-family: var(--monospace-font-family);
}
.added {
@@ -108,6 +109,11 @@ limitations under the License.
.fileListButton {
margin: .5em;
}
.totalChanges {
justify-content: flex-end;
padding-right: 2.6em;
text-align: right;
}
input.show-hide {
display: none;
}
@@ -221,6 +227,12 @@ limitations under the License.
project-config="[[projectConfig]]"
view-mode="[[_diffMode]]"></gr-diff>
</template>
<div class="row totalChanges">
<div class="total-stats" hidden$="[[_hideChangeTotals]]">
<span class="added">+[[_patchChange.inserted]]</span>
<span class="removed">-[[_patchChange.deleted]]</span>
</div>
</div>
<gr-button
class="fileListButton"
id="incrementButton"

View File

@@ -66,11 +66,19 @@
type: Number,
value: 75,
},
_patchChange: {
type: Object,
computed: '_calculatePatchChange(_files)',
},
_fileListIncrement: {
type: Number,
readOnly: true,
value: 75,
},
_hideChangeTotals: {
type: Boolean,
computed: '_shouldHideChangeTotals(_patchChange)',
},
_shownFiles: {
type: Array,
computed: '_computeFilesShown(_numFilesShown, _files.*)',
@@ -130,6 +138,22 @@
return Polymer.dom(this.root).querySelectorAll('gr-diff');
},
_calculatePatchChange: function(files) {
var filesNoCommitMsg = files.filter(function(files) {
return files.__path !== '/COMMIT_MSG';
});
return filesNoCommitMsg.reduce(function(acc, obj) {
var inserted = obj.lines_inserted ? obj.lines_inserted : 0;
var deleted = obj.lines_deleted ? obj.lines_deleted : 0;
return {
inserted: acc.inserted + inserted,
deleted: acc.deleted + deleted,
};
}, {inserted: 0, deleted: 0});
},
_getDiffPreferences: function() {
return this.$.restAPI.getDiffPreferences();
},
@@ -423,6 +447,10 @@
window.scrollTo(0, top - document.body.clientHeight / 2);
},
_shouldHideChangeTotals: function(_patchChange) {
return (_patchChange.inserted === 0 && _patchChange.deleted === 0);
},
_computeFileSelected: function(index, selectedIndex) {
return index === selectedIndex;
},

View File

@@ -97,6 +97,37 @@ limitations under the License.
});
});
test('calculate totals for patch number', function() {
element._files = [
{__path: '/COMMIT_MSG', lines_inserted: 9},
{__path: 'file_added_in_rev2.txt', lines_inserted: 1, lines_deleted: 1},
{__path: 'myfile.txt', lines_inserted: 1, lines_deleted: 1},
];
assert.deepEqual(element._patchChange, {inserted: 2, deleted: 2});
// Test with a commit message that isn't the first file.
element._files = [
{__path: 'file_added_in_rev2.txt', lines_inserted: 1, lines_deleted: 1},
{__path: '/COMMIT_MSG', lines_inserted: 9},
{__path: 'myfile.txt', lines_inserted: 1, lines_deleted: 1},
];
assert.deepEqual(element._patchChange, {inserted: 2, deleted: 2});
// Test with no commit message.
element._files = [
{__path: 'file_added_in_rev2.txt', lines_inserted: 1, lines_deleted: 1},
{__path: 'myfile.txt', lines_inserted: 1, lines_deleted: 1},
];
assert.deepEqual(element._patchChange, {inserted: 2, deleted: 2});
// Test with files missing either lines_inserted or lines_deleted.
element._files = [
{__path: 'file_added_in_rev2.txt', lines_inserted: 1},
{__path: 'myfile.txt', lines_deleted: 1},
];
assert.deepEqual(element._patchChange, {inserted: 1, deleted: 1});
});
suite('keyboard shortcuts', function() {
setup(function() {
element._files = [
@@ -128,7 +159,7 @@ limitations under the License.
flushAsynchronousOperations();
var elementItems = Polymer.dom(element.root).querySelectorAll(
'.row:not(.header)');
assert.equal(elementItems.length, 3);
assert.equal(elementItems.length, 4);
assert.isTrue(elementItems[0].hasAttribute('selected'));
assert.isFalse(elementItems[1].hasAttribute('selected'));
assert.isFalse(elementItems[2].hasAttribute('selected'));