Remove patchNumEquals method After TS conversion, we do not require special handling when comparing patchsets and can replace with === comparison Change-Id: I6fa855ecab52ca600fd2d434cf3453cc13150508
diff --git a/polygerrit-ui/app/elements/change/gr-change-actions/gr-change-actions.ts b/polygerrit-ui/app/elements/change/gr-change-actions/gr-change-actions.ts index febf18a..fdf2811 100644 --- a/polygerrit-ui/app/elements/change/gr-change-actions/gr-change-actions.ts +++ b/polygerrit-ui/app/elements/change/gr-change-actions/gr-change-actions.ts
@@ -38,11 +38,7 @@ import {GerritNav} from '../../core/gr-navigation/gr-navigation'; import {getPluginLoader} from '../../shared/gr-js-api-interface/gr-plugin-loader'; import {appContext} from '../../../services/app-context'; -import { - fetchChangeUpdates, - patchNumEquals, - CURRENT, -} from '../../../utils/patch-set-util'; +import {fetchChangeUpdates, CURRENT} from '../../../utils/patch-set-util'; import { changeIsOpen, isOwner, @@ -1153,7 +1149,7 @@ _getRevision(change: ChangeViewChangeInfo, patchNum?: PatchSetNum) { for (const rev of Object.values(change.revisions)) { - if (patchNumEquals(rev._number, patchNum)) { + if (rev._number === patchNum) { return rev; } }
diff --git a/polygerrit-ui/app/elements/change/gr-change-actions/gr-change-actions_test.js b/polygerrit-ui/app/elements/change/gr-change-actions/gr-change-actions_test.js index 0279b7e..f7bca82 100644 --- a/polygerrit-ui/app/elements/change/gr-change-actions/gr-change-actions_test.js +++ b/polygerrit-ui/app/elements/change/gr-change-actions/gr-change-actions_test.js
@@ -258,7 +258,7 @@ rev2: revObj, }, }; - assert.deepEqual(element._getRevision(change, '2'), revObj); + assert.deepEqual(element._getRevision(change, 2), revObj); }); test('_actionComparator sort order', () => {
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 684891f..126d017 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
@@ -69,7 +69,6 @@ fetchChangeUpdates, hasEditBasedOnCurrentPatchSet, hasEditPatchsetLoaded, - patchNumEquals, PatchSet, } from '../../../utils/patch-set-util'; import {changeStatuses, changeStatusString} from '../../../utils/change-util'; @@ -1656,7 +1655,7 @@ if (!this._change) throw new Error('missing required change property'); if (!this._patchRange) throw new Error('missing required _patchRange property'); - if (patchNumEquals(this._patchRange.basePatchNum, ParentPatchSetNum)) { + if (this._patchRange.basePatchNum === ParentPatchSetNum) { fireAlert(this, 'Base is already selected.'); return; } @@ -1670,7 +1669,7 @@ if (!this._change) throw new Error('missing required change property'); if (!this._patchRange) throw new Error('missing required _patchRange property'); - if (patchNumEquals(this._patchRange.basePatchNum, ParentPatchSetNum)) { + if (this._patchRange.basePatchNum === ParentPatchSetNum) { fireAlert(this, 'Left is already base.'); return; } @@ -1685,7 +1684,7 @@ if (!this._patchRange) throw new Error('missing required _patchRange property'); const latestPatchNum = computeLatestPatchNum(this._allPatchSets); - if (patchNumEquals(this._patchRange.patchNum, latestPatchNum)) { + if (this._patchRange.patchNum === latestPatchNum) { fireAlert(this, 'Latest is already selected.'); return; } @@ -1704,7 +1703,7 @@ const latestPatchNum = computeLatestPatchNum(this._allPatchSets); if (!this._patchRange) throw new Error('missing required _patchRange property'); - if (patchNumEquals(this._patchRange.patchNum, latestPatchNum)) { + if (this._patchRange.patchNum === latestPatchNum) { fireAlert(this, 'Right is already latest.'); return; } @@ -1724,8 +1723,8 @@ throw new Error('missing required _patchRange property'); const latestPatchNum = computeLatestPatchNum(this._allPatchSets); if ( - patchNumEquals(this._patchRange.patchNum, latestPatchNum) && - patchNumEquals(this._patchRange.basePatchNum, ParentPatchSetNum) + this._patchRange.patchNum === latestPatchNum && + this._patchRange.basePatchNum === ParentPatchSetNum ) { fireAlert(this, 'Already diffing base against latest.'); return; @@ -1967,7 +1966,7 @@ if ( !this._patchRange || !this._patchRange.patchNum || - patchNumEquals(this._patchRange.patchNum, currentRevision._number) + this._patchRange.patchNum === currentRevision._number ) { // CommitInfo.commit is optional, and may need patching. if (currentRevision.commit && !currentRevision.commit.commit) { @@ -2567,7 +2566,7 @@ } const patchRange = patchRangeRecord.base || {}; - return patchNumEquals(patchRange.patchNum, EditPatchSetNum); + return patchRange.patchNum === EditPatchSetNum; } _handleFileActionTap(e: CustomEvent<{path: string; action: string}>) { @@ -2651,10 +2650,7 @@ throw new Error('missing required _patchRange property'); let patchNum; if ( - !patchNumEquals( - this._patchRange.patchNum, - computeLatestPatchNum(this._allPatchSets) - ) + !(this._patchRange.patchNum === computeLatestPatchNum(this._allPatchSets)) ) { patchNum = this._patchRange.patchNum; }
diff --git a/polygerrit-ui/app/elements/change/gr-download-dialog/gr-download-dialog.ts b/polygerrit-ui/app/elements/change/gr-download-dialog/gr-download-dialog.ts index 27d9756..5949513 100644 --- a/polygerrit-ui/app/elements/change/gr-download-dialog/gr-download-dialog.ts +++ b/polygerrit-ui/app/elements/change/gr-download-dialog/gr-download-dialog.ts
@@ -20,7 +20,6 @@ import {LegacyElementMixin} from '@polymer/polymer/lib/legacy/legacy-element-mixin'; import {PolymerElement} from '@polymer/polymer/polymer-element'; import {htmlTemplate} from './gr-download-dialog_html'; -import {patchNumEquals} from '../../../utils/patch-set-util'; import {changeBaseURL} from '../../../utils/change-util'; import {customElement, property, computed, observe} from '@polymer/decorators'; import {ChangeInfo, ServerInfo, PatchSetNum} from '../../../types/common'; @@ -72,7 +71,7 @@ } for (const rev of Object.values(this.change.revisions || {})) { - if (patchNumEquals(rev._number, this.patchNum)) { + if (rev._number === this.patchNum) { const fetch = rev.fetch; if (fetch) { return Object.keys(fetch).sort(); @@ -113,7 +112,7 @@ if (!change || !selectedScheme) return []; for (const rev of Object.values(change.revisions || {})) { if ( - patchNumEquals(rev._number, patchNum) && + rev._number === patchNum && rev && rev.fetch && hasOwnProperty(rev.fetch, selectedScheme) @@ -171,7 +170,7 @@ let shortRev = ''; for (const rev in change.revisions) { - if (patchNumEquals(change.revisions[rev]._number, patchNum)) { + if (change.revisions[rev]._number === patchNum) { shortRev = rev.substr(0, 7); break; } @@ -185,7 +184,7 @@ return false; } for (const rev of Object.values(change.revisions || {})) { - if (patchNumEquals(rev._number, patchNum)) { + if (rev._number === patchNum) { const parentLength = rev.commit && rev.commit.parents ? rev.commit.parents.length : 0; return parentLength === 0 || parentLength > 1;
diff --git a/polygerrit-ui/app/elements/change/gr-file-list-header/gr-file-list-header.ts b/polygerrit-ui/app/elements/change/gr-file-list-header/gr-file-list-header.ts index 3c99648..146b3e2 100644 --- a/polygerrit-ui/app/elements/change/gr-file-list-header/gr-file-list-header.ts +++ b/polygerrit-ui/app/elements/change/gr-file-list-header/gr-file-list-header.ts
@@ -35,7 +35,6 @@ import { computeLatestPatchNum, getRevisionByPatchNum, - patchNumEquals, PatchSet, } from '../../../utils/patch-set-util'; import {property, computed, observe, customElement} from '@polymer/decorators'; @@ -321,8 +320,7 @@ _handlePatchChange(e: CustomEvent) { const {basePatchNum, patchNum} = e.detail; if ( - (patchNumEquals(basePatchNum, this.basePatchNum) && - patchNumEquals(patchNum, this.patchNum)) || + (basePatchNum === this.basePatchNum && patchNum === this.patchNum) || !this.change ) { return; @@ -354,7 +352,7 @@ _computePatchInfoClass(patchNum?: PatchSetNum, allPatchSets?: PatchSet[]) { const latestNum = computeLatestPatchNum(allPatchSets); - if (patchNumEquals(patchNum, latestNum)) { + if (patchNum === latestNum) { return ''; } return 'patchInfoOldPatchSet';
diff --git a/polygerrit-ui/app/elements/change/gr-file-list-header/gr-file-list-header_test.js b/polygerrit-ui/app/elements/change/gr-file-list-header/gr-file-list-header_test.js index cee0262..b8670c0 100644 --- a/polygerrit-ui/app/elements/change/gr-file-list-header/gr-file-list-header_test.js +++ b/polygerrit-ui/app/elements/change/gr-file-list-header/gr-file-list-header_test.js
@@ -249,11 +249,11 @@ test('class is applied to file list on old patch set', () => { const allPatchSets = [{num: 4}, {num: 2}, {num: 1}]; - assert.equal(element._computePatchInfoClass('1', allPatchSets), + assert.equal(element._computePatchInfoClass(1, allPatchSets), 'patchInfoOldPatchSet'); - assert.equal(element._computePatchInfoClass('2', allPatchSets), + assert.equal(element._computePatchInfoClass(2, allPatchSets), 'patchInfoOldPatchSet'); - assert.equal(element._computePatchInfoClass('4', allPatchSets), ''); + assert.equal(element._computePatchInfoClass(4, allPatchSets), ''); }); suite('editMode behavior', () => {
diff --git a/polygerrit-ui/app/elements/change/gr-related-changes-list/gr-related-changes-list.ts b/polygerrit-ui/app/elements/change/gr-related-changes-list/gr-related-changes-list.ts index fc6b5ba..e6c9f42 100644 --- a/polygerrit-ui/app/elements/change/gr-related-changes-list/gr-related-changes-list.ts +++ b/polygerrit-ui/app/elements/change/gr-related-changes-list/gr-related-changes-list.ts
@@ -25,7 +25,7 @@ import {htmlTemplate} from './gr-related-changes-list_html'; import {GerritNav} from '../../core/gr-navigation/gr-navigation'; import {ChangeStatus} from '../../../constants/constants'; -import {patchNumEquals} from '../../../utils/patch-set-util'; + import {changeIsOpen} from '../../../utils/change-util'; import {getPluginEndpoints} from '../../shared/gr-js-api-interface/gr-plugin-endpoints'; import {customElement, observe, property} from '@polymer/decorators'; @@ -410,7 +410,7 @@ return []; } for (const rev in change.revisions) { - if (patchNumEquals(change.revisions[rev]._number, patchNum)) { + if (change.revisions[rev]._number === patchNum) { changeRevision = rev; } }