Update gr-diff-comment unresolved toggle

This changes updates the unresolved toggle so that it only attempts to
save when explicitly tapped (as opposed to the value of resolved
changing on its own).

This was causing issues with comment synchronization between
gr-thread-view and diff comments, and also re-rendering the order of
comments in gr-thread-list within the dom-repeat.

This change also lets the resolved checkbox get selected via the enter
key.

Change-Id: I6065c745a0eabcf19df38f3cd6fd2c0d7e7434f3
This commit is contained in:
Becky Siegel
2018-03-08 17:29:09 -08:00
parent 98cfaedebe
commit fc18085eeb
3 changed files with 10 additions and 14 deletions

View File

@@ -290,7 +290,8 @@ limitations under the License.
<div class="action resolve hideOnPublished"> <div class="action resolve hideOnPublished">
<label> <label>
<input type="checkbox" <input type="checkbox"
checked$="[[resolved]]" id="resolvedCheckbox"
checked="[[resolved]]"
on-change="_handleToggleResolved"> on-change="_handleToggleResolved">
Resolved Resolved
</label> </label>

View File

@@ -113,10 +113,7 @@
}, },
commentSide: String, commentSide: String,
resolved: { resolved: Boolean,
type: Boolean,
observer: '_toggleResolved',
},
_numPendingDraftRequests: { _numPendingDraftRequests: {
type: Object, type: Object,
@@ -581,17 +578,10 @@
_handleToggleResolved() { _handleToggleResolved() {
this.resolved = !this.resolved; this.resolved = !this.resolved;
},
_toggleResolved(resolved, previousValue) {
// Do not proceed if this call is for the initial definition of the
// resolved property.
if (previousValue === undefined) { return; }
// Modify payload instead of this.comment, as this.comment is passed from // Modify payload instead of this.comment, as this.comment is passed from
// the parent by ref. // the parent by ref.
const payload = this._getEventPayload(); const payload = this._getEventPayload();
payload.comment.unresolved = !resolved; payload.comment.unresolved = !this.$.resolvedCheckbox.checked;
this.fire('comment-update', payload); this.fire('comment-update', payload);
if (!this.editing) { if (!this.editing) {
// Save the resolved state immediately. // Save the resolved state immediately.

View File

@@ -636,7 +636,9 @@ limitations under the License.
test('draft prevent save when disabled', () => { test('draft prevent save when disabled', () => {
const saveStub = sandbox.stub(element, 'save'); const saveStub = sandbox.stub(element, 'save');
element.showActions = true;
element.draft = true; element.draft = true;
MockInteractions.tap(element.$.header);
MockInteractions.tap(element.$$('.edit')); MockInteractions.tap(element.$$('.edit'));
element._messageText = 'good news, everyone!'; element._messageText = 'good news, everyone!';
element.flushDebouncer('fire-update'); element.flushDebouncer('fire-update');
@@ -680,7 +682,7 @@ limitations under the License.
assert.isFalse(element.$$('.resolve input').checked); assert.isFalse(element.$$('.resolve input').checked);
}); });
test('resolved checkbox saves when !editing', () => { test('resolved checkbox saves with tap when !editing', () => {
element.editing = false; element.editing = false;
const save = sandbox.stub(element, 'save'); const save = sandbox.stub(element, 'save');
@@ -688,6 +690,9 @@ limitations under the License.
assert.isTrue(element.$$('.resolve input').checked); assert.isTrue(element.$$('.resolve input').checked);
element.comment = {unresolved: true}; element.comment = {unresolved: true};
assert.isFalse(element.$$('.resolve input').checked); assert.isFalse(element.$$('.resolve input').checked);
assert.isFalse(save.called);
MockInteractions.tap(element.$.resolvedCheckbox);
assert.isTrue(element.$$('.resolve input').checked);
assert.isTrue(save.called); assert.isTrue(save.called);
}); });