Fix patch range select on diff
Previously, the patch range selector was updated to not use two way
bindings (https://gerrit-review.googlesource.com/c/gerrit/+/130453) but
the diff view's usage was not updated as well. This change updates the
diff view to use the patch range select in the same way as the file
list.
Bug: Issue 7420
Change-Id: I1baaf643e08d1a4661962021be890bafd6d5b4ef
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 cbc5c52..e896d10 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
@@ -284,11 +284,12 @@
<gr-patch-range-select
id="rangeSelect"
change-num="[[_changeNum]]"
- patch-num="{{_patchNum}}"
- base-patch-num="{{_basePatchNum}}"
+ patch-num="[[_patchRange.patchNum]]"
+ base-patch-num="[[_patchRange.basePatchNum]]"
files-weblinks="[[_filesWeblinks]]"
available-patches="[[_allPatchSets]]"
- 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 8455e1c..b97d974 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
@@ -61,24 +61,8 @@
value() { return {}; },
observer: '_changeViewStateChanged',
},
-
+ /** @type {?} */
_patchRange: Object,
- // These are kept as separate properties from the patchRange so that the
- // observer can be aware of the previous value. In order to view sub
- // property changes for _patchRange, a complex observer must be used, and
- // that only displays the new value.
- //
- // If a previous value did not exist, the change is not reloaded with the
- // new patches. This is just the initial setting from the change view vs.
- // an update coming from the two way data binding.
- _patchNum: {
- type: String,
- observer: '_patchOrBaseChanged',
- },
- _basePatchNum: {
- type: String,
- observer: '_patchOrBaseChanged',
- },
/**
* @type {{
* subject: string,
@@ -166,7 +150,6 @@
'_getProjectConfig(_change.project)',
'_getFiles(_changeNum, _patchRange.*)',
'_setReviewedObserver(_loggedIn, params.*)',
- '_patchRangeChanged(_patchRange.*)',
],
keyBindings: {
@@ -584,17 +567,6 @@
this.$.cursor.initialLineNumber = params.lineNum;
},
- _patchRangeChanged() {
- this._basePatchNum = this._patchRange.basePatchNum;
- this._patchNum = this._patchRange.patchNum;
- },
-
- _patchOrBaseChanged(patchNew, patchOld) {
- if (!patchOld) { return; }
-
- this._handlePatchChange(this._basePatchNum, this._patchNum);
- },
-
_pathChanged(path) {
if (path) {
this.fire('title-change',
@@ -701,7 +673,10 @@
this.$.dropdown.open();
},
- _handlePatchChange(basePatchNum, patchNum) {
+ _handlePatchChange(e) {
+ const {basePatchNum, patchNum} = e.detail;
+ if (this.patchNumEquals(basePatchNum, this._patchRange.basePatchNum) &&
+ this.patchNumEquals(patchNum, this._patchRange.patchNum)) { return; }
Gerrit.Nav.navigateToDiff(
this._change, this._path, patchNum, basePatchNum);
},
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 2c267e8..fa37eb9 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
@@ -456,11 +456,13 @@
patchNum: '3',
};
- assert.equal(element._basePatchNum, element._patchRange.basePatchNum);
- assert.equal(element._patchNum, element._patchRange.patchNum);
+ const detail = {
+ basePatchNum: 'PARENT',
+ patchNum: '1',
+ };
- element._patchNum = '1';
-
+ element.$.rangeSelect.dispatchEvent(
+ new CustomEvent('patch-range-change', {detail, bubbles: false}));
assert(navigateStub.lastCall.calledWithExactly(element._change,
element._path, '1', 'PARENT'));