A few updates to gr-diff-comment-thread-group
- getPatchNum should check patch_set rather than patchNum. This fixes a previous bug due to checking the wrong attribute that is surfaced when threads in a unified view's thread group come from both the patch and base patch num. - Adds logic for sorting drafts, which should always be at the end, regardless of date - Use the draftID as rootId if it's the first (only) comment in a thread Change-Id: I93c92dc77e158e245697e2f0ae01cde0af3a7ae1
This commit is contained in:
@@ -138,12 +138,15 @@
|
|||||||
* there are unsaved drafts.
|
* there are unsaved drafts.
|
||||||
*/
|
*/
|
||||||
_getPatchNum(comment) {
|
_getPatchNum(comment) {
|
||||||
return comment.patchNum || this.patchForNewThreads;
|
return comment.patch_set || this.patchForNewThreads;
|
||||||
},
|
},
|
||||||
|
|
||||||
_getThreads(comments) {
|
_getThreads(comments) {
|
||||||
const sortedComments = comments.slice(0).sort((a, b) =>
|
const sortedComments = comments.slice(0).sort((a, b) => {
|
||||||
util.parseDate(a.updated) - util.parseDate(b.updated));
|
if (b.__draft && !a.__draft ) { return 0; }
|
||||||
|
if (a.__draft && !b.__draft ) { return 1; }
|
||||||
|
return util.parseDate(a.updated) - util.parseDate(b.updated);
|
||||||
|
});
|
||||||
|
|
||||||
const threads = [];
|
const threads = [];
|
||||||
for (const comment of sortedComments) {
|
for (const comment of sortedComments) {
|
||||||
@@ -164,7 +167,7 @@
|
|||||||
comments: [comment],
|
comments: [comment],
|
||||||
commentSide: comment.__commentSide,
|
commentSide: comment.__commentSide,
|
||||||
patchNum: this._getPatchNum(comment),
|
patchNum: this._getPatchNum(comment),
|
||||||
rootId: comment.id,
|
rootId: comment.id || comment.__draftID,
|
||||||
};
|
};
|
||||||
if (comment.range) {
|
if (comment.range) {
|
||||||
newThread.range = Object.assign({}, comment.range);
|
newThread.range = Object.assign({}, comment.range);
|
||||||
|
|||||||
@@ -65,6 +65,13 @@ limitations under the License.
|
|||||||
__commentSide: 'left',
|
__commentSide: 'left',
|
||||||
in_reply_to: 'sallys_confession',
|
in_reply_to: 'sallys_confession',
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
__draftID: 'new_draft',
|
||||||
|
message: 'i do not like either of you',
|
||||||
|
__commentSide: 'left',
|
||||||
|
__draft: true,
|
||||||
|
updated: '2015-12-20 15:01:20.396000000',
|
||||||
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
let expectedThreadGroups = [
|
let expectedThreadGroups = [
|
||||||
@@ -86,6 +93,21 @@ limitations under the License.
|
|||||||
rootId: 'sallys_confession',
|
rootId: 'sallys_confession',
|
||||||
patchNum: 3,
|
patchNum: 3,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
start_datetime: '2015-12-20 15:01:20.396000000',
|
||||||
|
commentSide: 'left',
|
||||||
|
comments: [
|
||||||
|
{
|
||||||
|
__draftID: 'new_draft',
|
||||||
|
message: 'i do not like either of you',
|
||||||
|
__commentSide: 'left',
|
||||||
|
__draft: true,
|
||||||
|
updated: '2015-12-20 15:01:20.396000000',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
rootId: 'new_draft',
|
||||||
|
patchNum: 3,
|
||||||
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
assert.deepEqual(element._getThreads(comments), expectedThreadGroups);
|
assert.deepEqual(element._getThreads(comments), expectedThreadGroups);
|
||||||
@@ -147,6 +169,21 @@ limitations under the License.
|
|||||||
end_character: 2,
|
end_character: 2,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
start_datetime: '2015-12-20 15:01:20.396000000',
|
||||||
|
commentSide: 'left',
|
||||||
|
comments: [
|
||||||
|
{
|
||||||
|
__draftID: 'new_draft',
|
||||||
|
message: 'i do not like either of you',
|
||||||
|
__commentSide: 'left',
|
||||||
|
__draft: true,
|
||||||
|
updated: '2015-12-20 15:01:20.396000000',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
rootId: 'new_draft',
|
||||||
|
patchNum: 3,
|
||||||
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
assert.deepEqual(element._getThreads(comments), expectedThreadGroups);
|
assert.deepEqual(element._getThreads(comments), expectedThreadGroups);
|
||||||
@@ -266,7 +303,7 @@ limitations under the License.
|
|||||||
updated: '2015-12-23 15:00:20.396000000',
|
updated: '2015-12-23 15:00:20.396000000',
|
||||||
};
|
};
|
||||||
assert.equal(element._getPatchNum(comment), 3);
|
assert.equal(element._getPatchNum(comment), 3);
|
||||||
comment.patchNum = 4;
|
comment.patch_set = 4;
|
||||||
assert.equal(element._getPatchNum(comment), 4);
|
assert.equal(element._getPatchNum(comment), 4);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user