Merge "gr-account-chip to lit"
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..53bdb91 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,
@@ -676,7 +677,6 @@
);
this.addEventListener('open-fix-preview', e => this._onOpenFixPreview(e));
this.addEventListener('close-fix-preview', e => this._onCloseFixPreview(e));
- window.addEventListener('scroll', this.handleScroll);
document.addEventListener('visibilitychange', this.handleVisibilityChange);
this.addEventListener(EventType.SHOW_PRIMARY_TAB, e =>
@@ -693,7 +693,6 @@
/** @override */
disconnectedCallback() {
this.disconnected$.next();
- window.removeEventListener('scroll', this.handleScroll);
document.removeEventListener(
'visibilitychange',
this.handleVisibilityChange
@@ -1139,14 +1138,6 @@
this._openReplyDialog(target);
}
- readonly handleScroll = () => {
- this.scrollTask = debounce(
- this.scrollTask,
- () => (this.viewState.scrollTop = document.body.scrollTop),
- 150
- );
- };
-
_setShownFiles(e: CustomEvent<{length: number}>) {
this._shownFileCount = e.detail.length;
}
@@ -1283,11 +1274,7 @@
this._sendShowChangeEvent();
setTimeout(() => {
- if (this.viewState.scrollTop) {
- document.documentElement.scrollTop = document.body.scrollTop = this.viewState.scrollTop;
- } else {
- this._maybeScrollToMessage(window.location.hash);
- }
+ this._maybeScrollToMessage(window.location.hash);
this._initialLoadComplete = true;
});
}
@@ -1407,7 +1394,6 @@
_resetFileListViewState() {
this.set('viewState.selectedFileIndex', 0);
- this.set('viewState.scrollTop', 0);
if (
!!this.viewState.changeNum &&
this.viewState.changeNum !== this._changeNum
@@ -1768,6 +1754,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 +1967,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;
});
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 e882920..867b3a7 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
@@ -128,8 +128,6 @@
TestKeyboardShortcutBinder.pop();
});
- const TEST_SCROLL_TOP_PX = 100;
-
const ROBOT_COMMENTS_LIMIT = 10;
// TODO: should have a mock service to generate VALID fake data
@@ -1805,42 +1803,6 @@
assert.isTrue(awaitPluginsLoadedStub.called);
});
- suite('scroll related tests', () => {
- test('document scrolling calls function to set scroll height', done => {
- const originalHeight = document.body.scrollHeight;
- const scrollStub = sinon.stub(element, 'handleScroll').callsFake(() => {
- assert.isTrue(scrollStub.called);
- document.body.style.height = `${originalHeight}px`;
- scrollStub.restore();
- done();
- });
- document.body.style.height = '10000px';
- element.handleScroll();
- });
-
- test('scrollTop is set correctly', async () => {
- element.viewState = {scrollTop: TEST_SCROLL_TOP_PX};
-
- sinon.stub(element, 'loadData').callsFake(() => {
- // When element is reloaded, ensure that the history
- // state has the scrollTop set earlier. This will then
- // be reset.
- assert.isTrue(element.viewState.scrollTop === TEST_SCROLL_TOP_PX);
- return Promise.resolve([]);
- });
-
- // simulate reloading component, which is done when route
- // changes to match a regex of change view type.
- element.params = {...createAppElementChangeViewParams()};
- await flush();
- });
-
- test('scrollTop is reset when new change is loaded', () => {
- element._resetFileListViewState();
- assert.equal(element.viewState.scrollTop, 0);
- });
- });
-
suite('reply dialog tests', () => {
setup(() => {
sinon.stub(element.$.replyDialog, '_draftChanged');
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 71b4ac4..ff303e3 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
@@ -31,8 +31,6 @@
import {
AccountInfo,
ChangeInfo,
- EditPatchSetNum,
- ParentPatchSetNum,
PatchSetNum,
CommitInfo,
ServerInfo,
@@ -189,10 +187,6 @@
) {
return;
}
- if (patchNum === EditPatchSetNum && basePatchNum === ParentPatchSetNum) {
- GerritNav.navigateToChange(this.change, undefined, undefined, true);
- return;
- }
GerritNav.navigateToChange(this.change, patchNum, basePatchNum);
}
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 9bc243d..dd70678 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
@@ -22,7 +22,6 @@
import 'lodash/lodash.js';
import {createRevisions} from '../../../test/test-data-generators.js';
import {stubRestApi} from '../../../test/test-utils.js';
-import {EditPatchSetNum, ParentPatchSetNum} from '../../../types/common.js';
const basicFixture = fixtureFromElement('gr-file-list-header');
@@ -162,34 +161,6 @@
.calledWithExactly(element.change, 3, 1));
});
- test('navigateToChange called when range select changes with edit', () => {
- const navigateToChangeStub = sinon.stub(GerritNav, 'navigateToChange');
- element.change = {
- change_id: 'Iad9dc96274af6946f3632be53b106ef80f7ba6ca',
- revisions: {
- rev2: {_number: 2},
- rev1: {_number: 1},
- rev13: {_number: 13},
- rev3: {_number: 3},
- },
- status: 'NEW',
- labels: {},
- };
- element.basePatchNum = 1;
- element.patchNum = EditPatchSetNum;
-
- const detail = {
- detail: {
- basePatchNum: ParentPatchSetNum,
- patchNum: EditPatchSetNum,
- },
- };
- element._handlePatchChange(detail);
- assert.equal(navigateToChangeStub.callCount, 1);
- assert.isTrue(navigateToChangeStub.lastCall
- .calledWithExactly(element.change, undefined, undefined, true));
- });
-
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),
diff --git a/polygerrit-ui/app/elements/core/gr-router/gr-router.ts b/polygerrit-ui/app/elements/core/gr-router/gr-router.ts
index 015fdf3..7532101 100644
--- a/polygerrit-ui/app/elements/core/gr-router/gr-router.ts
+++ b/polygerrit-ui/app/elements/core/gr-router/gr-router.ts
@@ -51,7 +51,6 @@
import {
BasePatchSetNum,
DashboardId,
- EditPatchSetNum,
GroupId,
NumericChangeId,
PatchSetNum,
@@ -1601,15 +1600,6 @@
queryMap: ctx.queryMap,
};
- // We do not want to allow "edit" to be used as a
- // patch number. Instead redirect to ,edit.
- if (ctx.params[4] === EditPatchSetNum && !ctx.params[6]) {
- params.basePatchNum = undefined;
- params.edit = true;
- this._redirect(this._generateUrl(params));
- return;
- }
-
this.reporting.setRepoName(params.project);
this.reporting.setChangeId(changeNum);
this._redirectOrNavigate(params);
diff --git a/polygerrit-ui/app/elements/core/gr-router/gr-router_test.js b/polygerrit-ui/app/elements/core/gr-router/gr-router_test.js
index c4674d2..6e80a35 100644
--- a/polygerrit-ui/app/elements/core/gr-router/gr-router_test.js
+++ b/polygerrit-ui/app/elements/core/gr-router/gr-router_test.js
@@ -22,7 +22,6 @@
import {stubBaseUrl, stubRestApi, addListenerForTest} from '../../../test/test-utils.js';
import {_testOnly_RoutePattern} from './gr-router.js';
import {GerritView} from '../../../services/router/router-model.js';
-import {EditPatchSetNum} from '../../../types/common.js';
const basicFixture = fixtureFromElement('gr-router');
@@ -1430,16 +1429,16 @@
suite('_handleChangeRoute', () => {
let normalizeRangeStub;
- function makeParams(path, hash, baseNum, patchNum) {
+ function makeParams(path, hash) {
return {
params: [
'foo/bar', // 0 Project
1234, // 1 Change number
null, // 2 Unused
null, // 3 Unused
- baseNum ? baseNum : 4, // 4 Base patch number
+ 4, // 4 Base patch number
null, // 5 Unused
- patchNum ? patchNum : 7, // 6 Patch number
+ 7, // 6 Patch number
],
queryMap: new Map(),
};
@@ -1477,23 +1476,6 @@
assert.isFalse(redirectStub.called);
assert.isTrue(normalizeRangeStub.called);
});
-
- test('redirect due to patchNum being an edit', () => {
- normalizeRangeStub.returns(true);
- const ctx = makeParams(null, '');
- element._handleChangeRoute(ctx, undefined, EditPatchSetNum, false);
- assert.isTrue(normalizeRangeStub.called);
- assert.isFalse(setParamsStub.called);
- assert.isTrue(redirectStub.calledOnce);
-
- const params = {
- view: GerritView.CHANGE,
- changeNum: '1234',
- project: 'test',
- edit: true,
- };
- assert.equal(element._generateUrl(params), '/c/test/+/1234,edit');
- });
});
suite('_handleDiffRoute', () => {
diff --git a/polygerrit-ui/app/elements/gr-app-element.ts b/polygerrit-ui/app/elements/gr-app-element.ts
index c9f0506..ebd143c 100644
--- a/polygerrit-ui/app/elements/gr-app-element.ts
+++ b/polygerrit-ui/app/elements/gr-app-element.ts
@@ -295,7 +295,6 @@
showDownloadDialog: false,
diffMode: null,
numFilesShown: null,
- scrollTop: 0,
},
changeListView: {
query: null,
diff --git a/polygerrit-ui/app/types/types.ts b/polygerrit-ui/app/types/types.ts
index fd41cc9..2d4d412 100644
--- a/polygerrit-ui/app/types/types.ts
+++ b/polygerrit-ui/app/types/types.ts
@@ -189,7 +189,6 @@
showDownloadDialog: boolean;
diffMode: DiffViewMode | null;
numFilesShown: number | null;
- scrollTop?: number;
diffViewMode?: boolean;
}