Create gr-apply-fix-dialog and show fix preview.

in this change:
- add "Show Fix" option to gr-comment when fixes exist
- add GET /preview and POST /apply endpoints to gr-rest-api-interface
- create gr-apply-fix-dialog that fetch preview and supports showing
multiple diffs for a single fix, apply fix button that navigate to
edit-change view, and cancel that close dialog

Screenshots: https://imgur.com/a/6xQIoz8

next:
- support switching between multiple fixes

Change-Id: I9ba5121dd3b5b51791540ac9758f98c8669b44b2
This commit is contained in:
Julie Pan
2019-10-07 07:37:02 -07:00
parent 96c56f5180
commit 49d0a6e10d
13 changed files with 463 additions and 2 deletions

View File

@@ -358,6 +358,15 @@ limitations under the License.
Please Fix
</gr-button>
</template>
<gr-button
link
secondary
class="action show-fix"
hidden$="[[_hasNoFix(comment)]]"
on-click="_handleShowFix"
disabled="[[robotButtonDisabled]]">
Show Fix
</gr-button>
<gr-endpoint-decorator name="robot-comment-controls">
<gr-endpoint-param name="comment" value="[[comment]]">
</gr-endpoint-param>

View File

@@ -48,6 +48,12 @@
* @event create-fix-comment
*/
/**
* Fired when the show fix preview action is triggered.
*
* @event open-fix-preview
*/
/**
* Fired when this comment is discarded.
*
@@ -505,6 +511,18 @@
}));
}
_handleShowFix() {
this.dispatchEvent(new CustomEvent('open-fix-preview', {
bubbles: true,
composed: true,
detail: this._getEventPayload(),
}));
}
_hasNoFix(comment) {
return !comment || !comment.fix_suggestions;
}
_handleDiscard(e) {
e.preventDefault();
this.$.reporting.recordDraftInteraction();

View File

@@ -1007,5 +1007,17 @@ limitations under the License.
flushAsynchronousOperations();
assert.isNotNull(element.$$('.robotActions gr-button'));
});
test('_handleShowFix fires open-fix-preview event', done => {
element.addEventListener('open-fix-preview', e => {
assert.deepEqual(e.detail, element._getEventPayload());
done();
});
element.comment = {fix_suggestions: [{}]};
element.isRobotComment = true;
flushAsynchronousOperations();
MockInteractions.tap(element.$$('.show-fix'));
});
});
</script>

View File

@@ -1860,6 +1860,25 @@
});
}
getRobotCommentFixPreview(changeNum, patchNum, fixId) {
return this._getChangeURLAndFetch({
changeNum,
patchNum,
endpoint: `/fixes/${encodeURIComponent(fixId)}/preview`,
reportEndpointAsId: true,
});
}
applyFixSuggestion(changeNum, patchNum, fixId) {
return this._getChangeURLAndSend({
method: 'POST',
changeNum,
patchNum,
endpoint: `/fixes/${encodeURIComponent(fixId)}/apply`,
reportEndpointAsId: true,
});
}
// Deprecated, prefer to use putChangeCommitMessage instead.
saveChangeCommitMessageEdit(changeNum, message) {
return this._getChangeURLAndSend({