Expand unresolved comment threads in diff view by default
This change leverages the unresolved flag to automatically expand only the last UNRESOLVED_EXPAND_COUNT comments in unresolved threads. Feature: Issue 4752 Change-Id: Ia23920e1a210246838645d56a6bc81d0dff7da07
This commit is contained in:
@@ -14,6 +14,7 @@
|
||||
(function() {
|
||||
'use strict';
|
||||
|
||||
var UNRESOLVED_EXPAND_COUNT = 5;
|
||||
var NEWLINE_PATTERN = /\n/g;
|
||||
|
||||
Polymer({
|
||||
@@ -71,6 +72,7 @@
|
||||
this._getLoggedIn().then(function(loggedIn) {
|
||||
this._showActions = loggedIn;
|
||||
}.bind(this));
|
||||
this._setInitialExpandedState();
|
||||
},
|
||||
|
||||
addOrEditDraft: function(opt_lineNum) {
|
||||
@@ -125,6 +127,21 @@
|
||||
});
|
||||
},
|
||||
|
||||
/**
|
||||
* Sets the initial state of the comment thread to have the last
|
||||
* {UNRESOLVED_EXPAND_COUNT} comments expanded by default if the
|
||||
* thread is unresolved.
|
||||
*/
|
||||
_setInitialExpandedState: function() {
|
||||
var comment;
|
||||
for (var i = 0; i < this._orderedComments.length; i++) {
|
||||
comment = this._orderedComments[i];
|
||||
comment.collapsed =
|
||||
this._orderedComments.length - i - 1 >= UNRESOLVED_EXPAND_COUNT ||
|
||||
!this._unresolved;
|
||||
}
|
||||
},
|
||||
|
||||
_sortedComments: function(comments) {
|
||||
return comments.slice().sort(function(c1, c2) {
|
||||
var c1Date = c1.__date || util.parseDate(c1.updated);
|
||||
|
||||
@@ -40,6 +40,7 @@ limitations under the License.
|
||||
<script>
|
||||
suite('gr-diff-comment-thread tests', function() {
|
||||
var element;
|
||||
|
||||
setup(function() {
|
||||
stub('gr-rest-api-interface', {
|
||||
getLoggedIn: function() { return Promise.resolve(false); },
|
||||
@@ -465,6 +466,10 @@ limitations under the License.
|
||||
});
|
||||
|
||||
suite('jack and sally comment data test consolidation', function() {
|
||||
var getComments = function() {
|
||||
return Polymer.dom(element.root).querySelectorAll('gr-diff-comment');
|
||||
};
|
||||
|
||||
setup(function() {
|
||||
element.comments = [
|
||||
{
|
||||
@@ -518,6 +523,21 @@ limitations under the License.
|
||||
flushAsynchronousOperations();
|
||||
assert.isTrue(element._unresolved);
|
||||
});
|
||||
|
||||
test('_setInitialExpandedState', function() {
|
||||
element._unresolved = true;
|
||||
element._setInitialExpandedState();
|
||||
var comments = getComments();
|
||||
for (var i = 0; i < element.comments.length; i++) {
|
||||
assert.isFalse(element.comments[i].collapsed);
|
||||
}
|
||||
element._unresolved = false;
|
||||
element._setInitialExpandedState();
|
||||
var comments = getComments();
|
||||
for (var i = 0; i < element.comments.length; i++) {
|
||||
assert.isTrue(element.comments[i].collapsed);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
test('_computeHostClass', function() {
|
||||
|
||||
@@ -131,6 +131,8 @@
|
||||
attached: function() {
|
||||
if (this.editing) {
|
||||
this.collapsed = false;
|
||||
} else if (this.comment) {
|
||||
this.collapsed = this.comment.collapsed;
|
||||
}
|
||||
},
|
||||
|
||||
|
||||
Reference in New Issue
Block a user