From 5be8b8b1e501a056588bcf4210019f6159c228a4 Mon Sep 17 00:00:00 2001 From: Paladox none Date: Mon, 12 Jul 2021 13:10:09 +0000 Subject: 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 --- .../change/gr-change-view/gr-change-view.ts | 48 ++++++++++++++++++++-- 1 file changed, 45 insertions(+), 3 deletions(-) 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 fe4dbe33f5..8a0bf0fe63 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 @@ -77,7 +77,11 @@ import {EventType} from '../../plugins/gr-plugin-types'; import {customElement, property, observe} from '@polymer/decorators'; import {RestApiService} from '../../../services/services/gr-rest-api/gr-rest-api'; import {GrJsApiInterface} from '../../shared/gr-js-api-interface/gr-js-api-interface-element'; -import {changeIsMerged, changeIsAbandoned} from '../../../utils/change-util'; +import { + changeIsAbandoned, + changeIsMerged, + changeIsOpen, +} from '../../../utils/change-util'; import {GrApplyFixDialog} from '../../diff/gr-apply-fix-dialog/gr-apply-fix-dialog'; import {GrFileListHeader} from '../gr-file-list-header/gr-file-list-header'; import {GrEditableContent} from '../../shared/gr-editable-content/gr-editable-content'; @@ -1932,6 +1936,25 @@ export class GrChangeView extends KeyboardShortcutMixin( */ _processEdit(change: ParsedChangeInfo, edit?: EditInfo | false) { if ( + !edit && + this._patchRange?.patchNum === EditPatchSetNum && + changeIsOpen(change) + ) { + /* eslint-disable max-len */ + const message = 'Change edit not found. Please create a change edit.'; + this.dispatchEvent( + new CustomEvent('show-alert', { + detail: {message}, + bubbles: true, + composed: true, + }) + ); + GerritNav.navigateToChange(change); + return; + } + + if ( + !edit && (changeIsMerged(change) || changeIsAbandoned(change)) && this._editMode ) { @@ -2117,13 +2140,32 @@ export class GrChangeView extends KeyboardShortcutMixin( _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.$.restAPI - .getChangeCommitInfo(this._changeNum, this._patchRange.patchNum) + .getChangeCommitInfo(this._changeNum!, this._patchRange!.patchNum!) .then(commitInfo => { this._commitInfo = commitInfo; }); -- cgit v1.2.3