Utilize gr-patch-range-select in the change view
Slight refactoring required in order to satisfy both use cases:
- Fire an event when patch range changes and let parent element
handle it.
- Support comment strings
- availablePatches becomes an array of objects instead of an
array of integers.
Change-Id: Ia8da9296f41eb2d45c9358d03fbec3940273ad9d
diff --git a/polygerrit-ui/app/elements/diff/gr-diff-view/gr-diff-view.html b/polygerrit-ui/app/elements/diff/gr-diff-view/gr-diff-view.html
index 10d30e4..f67abcc 100644
--- a/polygerrit-ui/app/elements/diff/gr-diff-view/gr-diff-view.html
+++ b/polygerrit-ui/app/elements/diff/gr-diff-view/gr-diff-view.html
@@ -37,6 +37,9 @@
:host {
background-color: var(--view-background-color);
}
+ gr-patch-range-select {
+ display: block;
+ }
gr-diff {
border: none;
}
@@ -271,12 +274,13 @@
<div class="subHeader">
<div class="patchRangeLeft">
<gr-patch-range-select
- path="[[_path]]"
+ id="rangeSelect"
change-num="[[_changeNum]]"
patch-range="[[_patchRange]]"
files-weblinks="[[_filesWeblinks]]"
available-patches="[[_computeAvailablePatches(_change.revisions, _change.revisions.*)]]"
- revisions="[[_change.revisions]]">
+ revisions="[[_change.revisions]]"
+ on-patch-range-change="_handlePatchChange">
</gr-patch-range-select>
<span class="download desktop">
<span class="separator">/</span>
diff --git a/polygerrit-ui/app/elements/diff/gr-diff-view/gr-diff-view.js b/polygerrit-ui/app/elements/diff/gr-diff-view/gr-diff-view.js
index 56be27d..30f1d58 100644
--- a/polygerrit-ui/app/elements/diff/gr-diff-view/gr-diff-view.js
+++ b/polygerrit-ui/app/elements/diff/gr-diff-view/gr-diff-view.js
@@ -580,7 +580,9 @@
},
_computeAvailablePatches(revs) {
- return this.sortRevisions(Object.values(revs)).map(e => e._number);
+ return this.sortRevisions(Object.values(revs)).map(e => {
+ return {num: e._number};
+ });
},
/**
@@ -672,6 +674,13 @@
this.$.dropdown.open();
},
+ _handlePatchChange(e) {
+ const rightPatch = e.detail.rightPatch;
+ const leftPatch = e.detail.leftPatch;
+ Gerrit.Nav.navigateToDiff(
+ this._change, this._path, rightPatch, leftPatch);
+ },
+
_handlePrefsTap(e) {
e.preventDefault();
this.$.diffPreferences.open();
diff --git a/polygerrit-ui/app/elements/diff/gr-diff-view/gr-diff-view_test.html b/polygerrit-ui/app/elements/diff/gr-diff-view/gr-diff-view_test.html
index 73dd94a..aad5681 100644
--- a/polygerrit-ui/app/elements/diff/gr-diff-view/gr-diff-view_test.html
+++ b/polygerrit-ui/app/elements/diff/gr-diff-view/gr-diff-view_test.html
@@ -446,6 +446,18 @@
});
});
+ test('_handlePatchChange calls navigateToDiff correctly', () => {
+ const leftPatch = 'PARENT';
+ const rightPatch = '3';
+ const navigateStub = sandbox.stub(Gerrit.Nav, 'navigateToDiff');
+ element._change = {_number: 321, project: 'foo/bar'};
+ element._path = 'path/to/file.txt';
+ element.$.rangeSelect.fire('patch-range-change', {leftPatch, rightPatch});
+
+ assert(navigateStub.lastCall.calledWithExactly(element._change,
+ element._path, rightPatch, leftPatch));
+ });
+
test('download link', () => {
element._changeNum = '42';
element._patchRange = {