Fix automatically switching to the EDIT patchset if it exists
Going to the ,edit URL means that you want to enter edit mode. If you
do not qualify a patchset (i.e. .../edit or .../6 in the URL), then we
assume that you want to continue editing the your edit, if it already
exists.
We cannot use `_patchRange.patchNum` anymore for checking whether the
user did not specify a patchset in the URL, because the timing has
changed and we are updating `_patchRange.patchNum` to the latest
patchset of the change before the code is executed. So we have to
inspect the routerPatchNum directly.
Bug: Issue 15353
Change-Id: I4a11eccddce98029d5d579d79009fcca4c27d8b3
diff --git a/polygerrit-ui/app/elements/change/gr-change-view/gr-change-view.ts b/polygerrit-ui/app/elements/change/gr-change-view/gr-change-view.ts
index b6bfdb3..a018edb 100644
--- a/polygerrit-ui/app/elements/change/gr-change-view/gr-change-view.ts
+++ b/polygerrit-ui/app/elements/change/gr-change-view/gr-change-view.ts
@@ -630,6 +630,10 @@
*/
private scrollPosition?: number;
+ /** Simply reflects the router-model value. */
+ // visible for testing
+ routerPatchNum?: PatchSetNum;
+
override ready() {
super.ready();
this.subscriptions.push(
@@ -643,6 +647,11 @@
})
);
this.subscriptions.push(
+ this.routerModel.routerPatchNum$.subscribe(patchNum => {
+ this.routerPatchNum = patchNum;
+ })
+ );
+ this.subscriptions.push(
this.commentsModel.drafts$.subscribe(drafts => {
this._diffDrafts = {...drafts};
})
@@ -1854,7 +1863,7 @@
// is under change-model control. `_patchRange.patchNum` should eventually
// also be model managed, so we can reconcile these two code snippets into
// one location.
- if (!this._patchRange.patchNum && latestPsNum === editParentRev._number) {
+ if (!this.routerPatchNum && latestPsNum === editParentRev._number) {
this.set('_patchRange.patchNum', EditPatchSetNum);
}
}
diff --git a/polygerrit-ui/app/elements/change/gr-change-view/gr-change-view_test.ts b/polygerrit-ui/app/elements/change/gr-change-view/gr-change-view_test.ts
index 611537e..69cca9f 100644
--- a/polygerrit-ui/app/elements/change/gr-change-view/gr-change-view_test.ts
+++ b/polygerrit-ui/app/elements/change/gr-change-view/gr-change-view_test.ts
@@ -1847,6 +1847,7 @@
// When edit is set, but patchNum as well, then keep patchNum.
element._patchRange.patchNum = 5 as RevisionPatchSetNum;
+ element.routerPatchNum = 5 as RevisionPatchSetNum;
element._processEdit(change);
assert.equal(element._patchRange.patchNum, 5 as RevisionPatchSetNum);
});