Fix deleting edits when change is merged This fixes supporting deleting a change edit after change is merged or abandoned. This also improves the user interaction so a dialog is not shown because a change edit didn't exist on /commit?links. Rather we now write to the console log. This also has the benefit of making the redirect of /edit -> ,edit seamless because no more dialog showing and having to press close which could cause some confusion with the user. Since we're redirecting /edit -> ,edit anyways we don't need the dialog. Change-Id: I2e478d203ae7eb95acf92b518b73c9ad6b73c77d
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 39a80e6..0c55f67 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
@@ -76,8 +76,9 @@ PatchSet, } from '../../../utils/patch-set-util'; import { - changeIsMerged, changeIsAbandoned, + changeIsMerged, + changeIsOpen, changeStatuses, isCc, isOwner, @@ -1768,6 +1769,17 @@ */ _processEdit(change: ParsedChangeInfo, edit?: EditInfo | false) { if ( + !edit && + this._patchRange?.patchNum === EditPatchSetNum && + changeIsOpen(change) + ) { + fireAlert(this, 'Change edit not found. Please create a change edit.'); + GerritNav.navigateToChange(change); + return; + } + + if ( + !edit && (changeIsMerged(change) || changeIsAbandoned(change)) && this._editMode ) { @@ -1970,13 +1982,32 @@ _getCommitInfo() { if (!this._changeNum) - throw new Error('missing required changeNum property'); + throw new Error('missing required _changeNum property'); if (!this._patchRange) throw new Error('missing required _patchRange property'); if (this._patchRange.patchNum === undefined) throw new Error('missing required patchNum property'); + + // We only call _getEdit if the patchset number is an edit. + // We have to do this to ensure we can tell if an edit + // exists or not. + // This safely works even if a edit does not exist. + if (this._patchRange!.patchNum! === EditPatchSetNum) { + return this._getEdit().then(edit => { + if (!edit) { + return Promise.resolve(); + } + + return this._getChangeCommitInfo(); + }); + } + + return this._getChangeCommitInfo(); + } + + _getChangeCommitInfo() { return this.restApiService - .getChangeCommitInfo(this._changeNum, this._patchRange.patchNum) + .getChangeCommitInfo(this._changeNum!, this._patchRange!.patchNum!) .then(commitInfo => { this._commitInfo = commitInfo; });