Merge "Merge branch 'stable-3.3' into master"
diff --git a/plugins/delete-project b/plugins/delete-project
index 60ce67d..bfe159d 160000
--- a/plugins/delete-project
+++ b/plugins/delete-project
@@ -1 +1 @@
-Subproject commit 60ce67dd53ad64c33a2c34aae31e9ee823979109
+Subproject commit bfe159d3007db0f07e967473b53f679ba8f432df
diff --git a/plugins/replication b/plugins/replication
index b37a255..1b822fa 160000
--- a/plugins/replication
+++ b/plugins/replication
@@ -1 +1 @@
-Subproject commit b37a255e9500dabdf6aa5385b87624a2108f04d3
+Subproject commit 1b822fa63b04596faa93a13df7fcb8682bccb98b
diff --git a/polygerrit-ui/app/elements/admin/gr-admin-group-list/gr-admin-group-list.ts b/polygerrit-ui/app/elements/admin/gr-admin-group-list/gr-admin-group-list.ts
index 9d40e28..44ab784 100644
--- a/polygerrit-ui/app/elements/admin/gr-admin-group-list/gr-admin-group-list.ts
+++ b/polygerrit-ui/app/elements/admin/gr-admin-group-list/gr-admin-group-list.ts
@@ -34,6 +34,7 @@
import {GroupId, GroupInfo, GroupName} from '../../../types/common';
import {RestApiService} from '../../../services/services/gr-rest-api/gr-rest-api';
import {GrCreateGroupDialog} from '../gr-create-group-dialog/gr-create-group-dialog';
+import {fireTitleChange} from '../../../utils/event-util';
declare global {
interface HTMLElementTagNameMap {
@@ -100,13 +101,7 @@
attached() {
super.attached();
this._getCreateGroupCapability();
- this.dispatchEvent(
- new CustomEvent('title-change', {
- detail: {title: 'Groups'},
- composed: true,
- bubbles: true,
- })
- );
+ fireTitleChange(this, 'Groups');
this._maybeOpenCreateOverlay(this.params);
}
diff --git a/polygerrit-ui/app/elements/admin/gr-group-audit-log/gr-group-audit-log.ts b/polygerrit-ui/app/elements/admin/gr-group-audit-log/gr-group-audit-log.ts
index f7cffac..2582170 100644
--- a/polygerrit-ui/app/elements/admin/gr-group-audit-log/gr-group-audit-log.ts
+++ b/polygerrit-ui/app/elements/admin/gr-group-audit-log/gr-group-audit-log.ts
@@ -37,6 +37,7 @@
EncodedGroupId,
GroupAuditEventInfo,
} from '../../../types/common';
+import {firePageError, fireTitleChange} from '../../../utils/event-util';
const GROUP_EVENTS = ['ADD_GROUP', 'REMOVE_GROUP'];
@@ -65,13 +66,7 @@
/** @override */
attached() {
super.attached();
- this.dispatchEvent(
- new CustomEvent('title-change', {
- detail: {title: 'Audit Log'},
- composed: true,
- bubbles: true,
- })
- );
+ fireTitleChange(this, 'Audit Log');
}
/** @override */
@@ -85,15 +80,7 @@
return '';
}
- const errFn: ErrorCallback = response => {
- this.dispatchEvent(
- new CustomEvent('page-error', {
- detail: {response},
- composed: true,
- bubbles: true,
- })
- );
- };
+ const errFn: ErrorCallback = response => firePageError(this, response);
return this.$.restAPI
.getGroupAuditLog(this.groupId, errFn)
diff --git a/polygerrit-ui/app/elements/admin/gr-group-members/gr-group-members.ts b/polygerrit-ui/app/elements/admin/gr-group-members/gr-group-members.ts
index e94a933..1cd55ca 100644
--- a/polygerrit-ui/app/elements/admin/gr-group-members/gr-group-members.ts
+++ b/polygerrit-ui/app/elements/admin/gr-group-members/gr-group-members.ts
@@ -46,7 +46,11 @@
import {AutocompleteQuery} from '../../shared/gr-autocomplete/gr-autocomplete';
import {PolymerDomRepeatEvent} from '../../../types/types';
import {hasOwnProperty} from '../../../utils/common-util';
-import {EventType, fire} from '../../../utils/event-util';
+import {
+ fireAlert,
+ firePageError,
+ fireTitleChange,
+} from '../../../utils/event-util';
const SUGGESTIONS_LIMIT = 15;
const SAVING_ERROR_TEXT =
@@ -126,13 +130,7 @@
super.attached();
this._loadGroupDetails();
- this.dispatchEvent(
- new CustomEvent('title-change', {
- detail: {title: 'Members'},
- composed: true,
- bubbles: true,
- })
- );
+ fireTitleChange(this, 'Members');
}
_loadGroupDetails() {
@@ -142,15 +140,7 @@
const promises: Promise<void>[] = [];
- const errFn: ErrorCallback = response => {
- this.dispatchEvent(
- new CustomEvent('page-error', {
- detail: {response},
- composed: true,
- bubbles: true,
- })
- );
- };
+ const errFn: ErrorCallback = response => firePageError(this, response);
return this.$.restAPI.getGroupConfig(this.groupId, errFn).then(config => {
if (!config || !config.name) {
@@ -298,7 +288,7 @@
(errResponse, err) => {
if (errResponse) {
if (errResponse.status === 404) {
- fire(this, EventType.SHOW_ALERT, SAVING_ERROR_TEXT);
+ fireAlert(this, SAVING_ERROR_TEXT);
return errResponse;
}
throw Error(errResponse.statusText);
diff --git a/polygerrit-ui/app/elements/admin/gr-group/gr-group.ts b/polygerrit-ui/app/elements/admin/gr-group/gr-group.ts
index 511bf5c..95a6e5d 100644
--- a/polygerrit-ui/app/elements/admin/gr-group/gr-group.ts
+++ b/polygerrit-ui/app/elements/admin/gr-group/gr-group.ts
@@ -38,6 +38,7 @@
RestApiService,
} from '../../../services/services/gr-rest-api/gr-rest-api';
import {hasOwnProperty} from '../../../utils/common-util';
+import {firePageError, fireTitleChange} from '../../../utils/event-util';
const INTERNAL_GROUP_REGEX = /^[\da-f]{40}$/;
@@ -144,15 +145,7 @@
const promises: Promise<unknown>[] = [];
- const errFn: ErrorCallback = response => {
- this.dispatchEvent(
- new CustomEvent('page-error', {
- detail: {response},
- composed: true,
- bubbles: true,
- })
- );
- };
+ const errFn: ErrorCallback = response => firePageError(this, response);
return this.$.restAPI.getGroupConfig(this.groupId, errFn).then(config => {
if (!config || !config.name) {
@@ -183,13 +176,7 @@
}
this._groupConfig = config;
- this.dispatchEvent(
- new CustomEvent('title-change', {
- detail: {title: config.name},
- composed: true,
- bubbles: true,
- })
- );
+ fireTitleChange(this, config.name);
return Promise.all(promises).then(() => {
this._loading = false;
diff --git a/polygerrit-ui/app/elements/admin/gr-plugin-list/gr-plugin-list.ts b/polygerrit-ui/app/elements/admin/gr-plugin-list/gr-plugin-list.ts
index 5039972..922f592 100644
--- a/polygerrit-ui/app/elements/admin/gr-plugin-list/gr-plugin-list.ts
+++ b/polygerrit-ui/app/elements/admin/gr-plugin-list/gr-plugin-list.ts
@@ -30,6 +30,8 @@
import {RestApiService} from '../../../services/services/gr-rest-api/gr-rest-api';
import {ErrorCallback} from '../../../services/services/gr-rest-api/gr-rest-api';
import {PluginInfo} from '../../../types/common';
+import {firePageError} from '../../../utils/event-util';
+import {fireTitleChange} from '../../../utils/event-util';
interface PluginInfoWithName extends PluginInfo {
name: string;
@@ -84,13 +86,7 @@
/** @override */
attached() {
super.attached();
- this.dispatchEvent(
- new CustomEvent('title-change', {
- detail: {title: 'Plugins'},
- composed: true,
- bubbles: true,
- })
- );
+ fireTitleChange(this, 'Plugins');
}
_paramsChanged(params: ListViewParams) {
@@ -102,15 +98,7 @@
}
_getPlugins(filter: string, pluginsPerPage: number, offset?: number) {
- const errFn: ErrorCallback = response => {
- this.dispatchEvent(
- new CustomEvent('page-error', {
- detail: {response},
- composed: true,
- bubbles: true,
- })
- );
- };
+ const errFn: ErrorCallback = response => firePageError(this, response);
return this.$.restAPI
.getPlugins(filter, pluginsPerPage, offset, errFn)
.then(plugins => {
diff --git a/polygerrit-ui/app/elements/admin/gr-repo-access/gr-repo-access.ts b/polygerrit-ui/app/elements/admin/gr-repo-access/gr-repo-access.ts
index ac65297..fde7234 100644
--- a/polygerrit-ui/app/elements/admin/gr-repo-access/gr-repo-access.ts
+++ b/polygerrit-ui/app/elements/admin/gr-repo-access/gr-repo-access.ts
@@ -52,7 +52,7 @@
PropertyTreeNode,
PrimitiveValue,
} from './gr-repo-access-interfaces';
-import {EventType, fire} from '../../../utils/event-util';
+import {firePageError, fireAlert} from '../../../utils/event-util';
const NOTHING_TO_SAVE = 'No changes to save.';
@@ -155,15 +155,7 @@
}
_reload(repo: RepoName) {
- const errFn = (response?: Response | null) => {
- this.dispatchEvent(
- new CustomEvent('page-error', {
- detail: {response},
- composed: true,
- bubbles: true,
- })
- );
- };
+ const errFn = (response?: Response | null) => firePageError(this, response);
this._editing = false;
@@ -517,7 +509,7 @@
!Object.keys(addRemoveObj.remove).length &&
!addRemoveObj.parent
) {
- fire(this, EventType.SHOW_ALERT, NOTHING_TO_SAVE);
+ fireAlert(this, NOTHING_TO_SAVE);
return;
}
const obj: ProjectAccessInput = ({
diff --git a/polygerrit-ui/app/elements/admin/gr-repo-commands/gr-repo-commands.ts b/polygerrit-ui/app/elements/admin/gr-repo-commands/gr-repo-commands.ts
index 7fce91f..14cfedd 100644
--- a/polygerrit-ui/app/elements/admin/gr-repo-commands/gr-repo-commands.ts
+++ b/polygerrit-ui/app/elements/admin/gr-repo-commands/gr-repo-commands.ts
@@ -42,7 +42,11 @@
} from '../../../types/common';
import {GrOverlay} from '../../shared/gr-overlay/gr-overlay';
import {GrCreateChangeDialog} from '../gr-create-change-dialog/gr-create-change-dialog';
-import {fire, EventType} from '../../../utils/event-util';
+import {
+ fireAlert,
+ firePageError,
+ fireTitleChange,
+} from '../../../utils/event-util';
const GC_MESSAGE = 'Garbage collection completed successfully.';
const CONFIG_BRANCH = 'refs/meta/config' as BranchName;
@@ -96,13 +100,7 @@
super.attached();
this._loadRepo();
- this.dispatchEvent(
- new CustomEvent('title-change', {
- detail: {title: 'Repo Commands'},
- composed: true,
- bubbles: true,
- })
- );
+ fireTitleChange(this, 'Repo Commands');
}
_loadRepo() {
@@ -110,13 +108,7 @@
// Do not process the error, if the component is not attached to the DOM
// anymore, which at least in tests can happen.
if (!this.isConnected) return;
- this.dispatchEvent(
- new CustomEvent('page-error', {
- detail: {response},
- composed: true,
- bubbles: true,
- })
- );
+ firePageError(this, response);
};
this.$.restAPI.getProjectConfig(this.repo, errFn).then(config => {
@@ -143,7 +135,7 @@
.runRepoGC(this.repo)
.then(response => {
if (response?.status === 200) {
- fire(this, EventType.SHOW_ALERT, GC_MESSAGE);
+ fireAlert(this, GC_MESSAGE);
}
})
.finally(() => {
@@ -185,7 +177,7 @@
const message = change
? CREATE_CHANGE_SUCCEEDED_MESSAGE
: CREATE_CHANGE_FAILED_MESSAGE;
- fire(this, EventType.SHOW_ALERT, message);
+ fireAlert(this, message);
if (!change) {
return;
}
diff --git a/polygerrit-ui/app/elements/admin/gr-repo-dashboards/gr-repo-dashboards.ts b/polygerrit-ui/app/elements/admin/gr-repo-dashboards/gr-repo-dashboards.ts
index d9d8560..f2735fb 100644
--- a/polygerrit-ui/app/elements/admin/gr-repo-dashboards/gr-repo-dashboards.ts
+++ b/polygerrit-ui/app/elements/admin/gr-repo-dashboards/gr-repo-dashboards.ts
@@ -27,6 +27,7 @@
import {RestApiService} from '../../../services/services/gr-rest-api/gr-rest-api';
import {RepoName, DashboardId, DashboardInfo} from '../../../types/common';
import {ErrorCallback} from '../../../services/services/gr-rest-api/gr-rest-api';
+import {firePageError} from '../../../utils/event-util';
interface DashboardRef {
section: string;
@@ -61,15 +62,7 @@
return Promise.resolve();
}
- const errFn: ErrorCallback = response => {
- this.dispatchEvent(
- new CustomEvent('page-error', {
- detail: {response},
- composed: true,
- bubbles: true,
- })
- );
- };
+ const errFn: ErrorCallback = response => firePageError(this, response);
return this.$.restAPI
.getRepoDashboards(repo, errFn)
diff --git a/polygerrit-ui/app/elements/admin/gr-repo-detail-list/gr-repo-detail-list.ts b/polygerrit-ui/app/elements/admin/gr-repo-detail-list/gr-repo-detail-list.ts
index 2fce6e1..e4e9d34 100644
--- a/polygerrit-ui/app/elements/admin/gr-repo-detail-list/gr-repo-detail-list.ts
+++ b/polygerrit-ui/app/elements/admin/gr-repo-detail-list/gr-repo-detail-list.ts
@@ -53,6 +53,7 @@
import {AppElementRepoParams} from '../../gr-app-types';
import {PolymerDomRepeatEvent} from '../../../types/types';
import {RepoDetailView} from '../../core/gr-navigation/gr-navigation';
+import {firePageError} from '../../../utils/event-util';
const PGP_START = '-----BEGIN PGP SIGNATURE-----';
@@ -181,15 +182,8 @@
this._loading = true;
this._items = [];
flush();
- const errFn: ErrorCallback = response => {
- this.dispatchEvent(
- new CustomEvent('page-error', {
- detail: {response},
- composed: true,
- bubbles: true,
- })
- );
- };
+ const errFn: ErrorCallback = response => firePageError(this, response);
+
if (detailType === RepoDetailView.BRANCHES) {
return this.$.restAPI
.getRepoBranches(filter, repo, itemsPerPage, offset, errFn)
diff --git a/polygerrit-ui/app/elements/admin/gr-repo-list/gr-repo-list.ts b/polygerrit-ui/app/elements/admin/gr-repo-list/gr-repo-list.ts
index ba2d850..a566eb0 100644
--- a/polygerrit-ui/app/elements/admin/gr-repo-list/gr-repo-list.ts
+++ b/polygerrit-ui/app/elements/admin/gr-repo-list/gr-repo-list.ts
@@ -34,6 +34,7 @@
import {RepoName, ProjectInfoWithName} from '../../../types/common';
import {GrCreateRepoDialog} from '../gr-create-repo-dialog/gr-create-repo-dialog';
import {ProjectState} from '../../../constants/constants';
+import {fireTitleChange} from '../../../utils/event-util';
declare global {
interface HTMLElementTagNameMap {
@@ -93,13 +94,7 @@
attached() {
super.attached();
this._getCreateRepoCapability();
- this.dispatchEvent(
- new CustomEvent('title-change', {
- detail: {title: 'Repos'},
- composed: true,
- bubbles: true,
- })
- );
+ fireTitleChange(this, 'Repos');
this._maybeOpenCreateOverlay(this.params);
}
diff --git a/polygerrit-ui/app/elements/admin/gr-repo/gr-repo.ts b/polygerrit-ui/app/elements/admin/gr-repo/gr-repo.ts
index 101c77a..3acf8fa 100644
--- a/polygerrit-ui/app/elements/admin/gr-repo/gr-repo.ts
+++ b/polygerrit-ui/app/elements/admin/gr-repo/gr-repo.ts
@@ -48,6 +48,7 @@
import {ProjectState} from '../../../constants/constants';
import {PolymerDeepPropertyChange} from '@polymer/polymer/interfaces';
import {hasOwnProperty} from '../../../utils/common-util';
+import {firePageError, fireTitleChange} from '../../../utils/event-util';
const STATES = {
active: {value: ProjectState.ACTIVE, label: 'Active'},
@@ -149,13 +150,7 @@
super.attached();
this._loadRepo();
- this.dispatchEvent(
- new CustomEvent('title-change', {
- detail: {title: this.repo},
- composed: true,
- bubbles: true,
- })
- );
+ fireTitleChange(this, `${this.repo}`);
}
_computePluginData(
@@ -181,15 +176,7 @@
const promises = [];
- const errFn: ErrorCallback = response => {
- this.dispatchEvent(
- new CustomEvent('page-error', {
- detail: {response},
- composed: true,
- bubbles: true,
- })
- );
- };
+ const errFn: ErrorCallback = response => firePageError(this, response);
promises.push(
this._getLoggedIn().then(loggedIn => {
diff --git a/polygerrit-ui/app/elements/change-list/gr-change-list-view/gr-change-list-view.ts b/polygerrit-ui/app/elements/change-list/gr-change-list-view/gr-change-list-view.ts
index 927d32f..3391901 100644
--- a/polygerrit-ui/app/elements/change-list/gr-change-list-view/gr-change-list-view.ts
+++ b/polygerrit-ui/app/elements/change-list/gr-change-list-view/gr-change-list-view.ts
@@ -41,6 +41,7 @@
import {ChangeStarToggleStarDetail} from '../../shared/gr-change-star/gr-change-star';
import {hasOwnProperty} from '../../../utils/common-util';
import {ChangeListViewState} from '../../../types/types';
+import {fireTitleChange} from '../../../utils/event-util';
const LookupQueryPatterns = {
CHANGE_ID: /^\s*i?[0-9a-f]{7,40}\s*$/i,
@@ -143,15 +144,7 @@
// NOTE: This method may be called before attachment. Fire title-change
// in an async so that attachment to the DOM can take place first.
- this.async(() =>
- this.dispatchEvent(
- new CustomEvent('title-change', {
- detail: {title: this._query},
- composed: true,
- bubbles: true,
- })
- )
- );
+ this.async(() => fireTitleChange(this, this._query));
this.$.restAPI
.getPreferences()
diff --git a/polygerrit-ui/app/elements/change-list/gr-dashboard-view/gr-dashboard-view.ts b/polygerrit-ui/app/elements/change-list/gr-dashboard-view/gr-dashboard-view.ts
index 57d3dd9..dbaed07 100644
--- a/polygerrit-ui/app/elements/change-list/gr-dashboard-view/gr-dashboard-view.ts
+++ b/polygerrit-ui/app/elements/change-list/gr-dashboard-view/gr-dashboard-view.ts
@@ -58,6 +58,7 @@
import {ChangeListToggleReviewedDetail} from '../gr-change-list-item/gr-change-list-item';
import {ChangeStarToggleStarDetail} from '../../shared/gr-change-star/gr-change-star';
import {DashboardViewState} from '../../../types/types';
+import {firePageError, fireTitleChange} from '../../../utils/event-util';
const PROJECT_PLACEHOLDER_PATTERN = /\$\{project\}/g;
@@ -149,15 +150,7 @@
project: RepoName,
dashboard: DashboardId
): Promise<UserDashboard | undefined> {
- const errFn = (response?: Response | null) => {
- this.dispatchEvent(
- new CustomEvent('page-error', {
- detail: {response},
- composed: true,
- bubbles: true,
- })
- );
- };
+ const errFn = (response?: Response | null) => firePageError(this, response);
return this.$.restAPI
.getDashboard(project, dashboard, errFn)
.then(response => {
@@ -228,13 +221,7 @@
return dashboardPromise
.then(res => {
if (res && res.title) {
- this.dispatchEvent(
- new CustomEvent('title-change', {
- detail: {title: res.title},
- composed: true,
- bubbles: true,
- })
- );
+ fireTitleChange(this, res.title);
}
return this._fetchDashboardChanges(res, checkForNewUser);
})
@@ -243,15 +230,7 @@
this.reporting.dashboardDisplayed();
})
.catch(err => {
- this.dispatchEvent(
- new CustomEvent('title-change', {
- detail: {
- title: title || this._computeTitle(user),
- },
- composed: true,
- bubbles: true,
- })
- );
+ fireTitleChange(this, title || this._computeTitle(user));
console.warn(err);
})
.then(() => {
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 1eff047..8989440 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
@@ -113,7 +113,7 @@
RevisionActions,
UIActionInfo,
} from '../../shared/gr-js-api-interface/gr-change-actions-js-api';
-import {fire, EventType} from '../../../utils/event-util';
+import {fireAlert} from '../../../utils/event-util';
const ERR_BRANCH_EMPTY = 'The destination branch can’t be empty.';
const ERR_COMMIT_EMPTY = 'The commit message can’t be empty.';
@@ -613,7 +613,7 @@
this._handleLoadingComplete();
})
.catch(err => {
- fire(this, EventType.SHOW_ALERT, ERR_REVISION_ACTIONS);
+ fireAlert(this, ERR_REVISION_ACTIONS);
this._loading = false;
throw err;
});
@@ -1368,11 +1368,11 @@
_handleCherryPickRestApi(conflicts: boolean) {
const el = this.$.confirmCherrypick;
if (!el.branch) {
- fire(this, EventType.SHOW_ALERT, ERR_BRANCH_EMPTY);
+ fireAlert(this, ERR_BRANCH_EMPTY);
return;
}
if (!el.message) {
- fire(this, EventType.SHOW_ALERT, ERR_COMMIT_EMPTY);
+ fireAlert(this, ERR_COMMIT_EMPTY);
return;
}
this.$.overlay.close();
@@ -1393,7 +1393,7 @@
_handleMoveConfirm() {
const el = this.$.confirmMove;
if (!el.branch) {
- fire(this, EventType.SHOW_ALERT, ERR_BRANCH_EMPTY);
+ fireAlert(this, ERR_BRANCH_EMPTY);
return;
}
this.$.overlay.close();
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 26b553e..24841fc 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
@@ -146,15 +146,15 @@
CustomKeyboardEvent,
EditableContentSaveEvent,
OpenFixPreviewEvent,
- ShowAlertEventDetail,
SwitchTabEvent,
} from '../../../types/events';
import {GrButton} from '../../shared/gr-button/gr-button';
import {GrMessagesList} from '../gr-messages-list/gr-messages-list';
import {GrThreadList} from '../gr-thread-list/gr-thread-list';
import {PORTING_COMMENTS_CHANGE_LATENCY_LABEL} from '../../../services/gr-reporting/gr-reporting';
-import {fire, EventType} from '../../../utils/event-util';
+import {fireAlert, firePageError} from '../../../utils/event-util';
import {KnownExperimentId} from '../../../services/flags/flags';
+import {fireTitleChange} from '../../../utils/event-util';
const CHANGE_ID_ERROR = {
MISMATCH: 'mismatch',
@@ -1489,13 +1489,7 @@
this.set('_patchRange.basePatchNum', parent);
const title = change.subject + ' (' + change.change_id.substr(0, 9) + ')';
- this.dispatchEvent(
- new CustomEvent('title-change', {
- detail: {title},
- composed: true,
- bubbles: true,
- })
- );
+ fireTitleChange(this, title);
}
/**
@@ -1669,7 +1663,7 @@
if (!this._patchRange)
throw new Error('missing required _patchRange property');
if (patchNumEquals(this._patchRange.basePatchNum, ParentPatchSetNum)) {
- fire(this, EventType.SHOW_ALERT, 'Base is already selected.');
+ fireAlert(this, 'Base is already selected.');
return;
}
GerritNav.navigateToChange(this._change, this._patchRange.patchNum);
@@ -1683,7 +1677,7 @@
if (!this._patchRange)
throw new Error('missing required _patchRange property');
if (patchNumEquals(this._patchRange.basePatchNum, ParentPatchSetNum)) {
- fire(this, EventType.SHOW_ALERT, 'Left is already base.');
+ fireAlert(this, 'Left is already base.');
return;
}
GerritNav.navigateToChange(this._change, this._patchRange.basePatchNum);
@@ -1698,16 +1692,7 @@
throw new Error('missing required _patchRange property');
const latestPatchNum = computeLatestPatchNum(this._allPatchSets);
if (patchNumEquals(this._patchRange.patchNum, latestPatchNum)) {
- const detail: ShowAlertEventDetail = {
- message: 'Latest is already selected.',
- };
- this.dispatchEvent(
- new CustomEvent('show-alert', {
- detail,
- composed: true,
- bubbles: true,
- })
- );
+ fireAlert(this, 'Latest is already selected.');
return;
}
GerritNav.navigateToChange(
@@ -1726,7 +1711,7 @@
if (!this._patchRange)
throw new Error('missing required _patchRange property');
if (patchNumEquals(this._patchRange.patchNum, latestPatchNum)) {
- fire(this, EventType.SHOW_ALERT, 'Right is already latest.');
+ fireAlert(this, 'Right is already latest.');
return;
}
GerritNav.navigateToChange(
@@ -1748,7 +1733,7 @@
patchNumEquals(this._patchRange.patchNum, latestPatchNum) &&
patchNumEquals(this._patchRange.basePatchNum, ParentPatchSetNum)
) {
- fire(this, EventType.SHOW_ALERT, 'Already diffing base against latest.');
+ fireAlert(this, 'Already diffing base against latest.');
return;
}
GerritNav.navigateToChange(this._change, latestPatchNum);
@@ -1872,13 +1857,7 @@
}
_handleGetChangeDetailError(response?: Response | null) {
- this.dispatchEvent(
- new CustomEvent('page-error', {
- detail: {response},
- composed: true,
- bubbles: true,
- })
- );
+ firePageError(this, response);
}
_getLoggedIn() {
diff --git a/polygerrit-ui/app/elements/change/gr-confirm-revert-dialog/gr-confirm-revert-dialog.ts b/polygerrit-ui/app/elements/change/gr-confirm-revert-dialog/gr-confirm-revert-dialog.ts
index b3e054f..3facde1 100644
--- a/polygerrit-ui/app/elements/change/gr-confirm-revert-dialog/gr-confirm-revert-dialog.ts
+++ b/polygerrit-ui/app/elements/change/gr-confirm-revert-dialog/gr-confirm-revert-dialog.ts
@@ -25,7 +25,7 @@
import {customElement, property} from '@polymer/decorators';
import {JsApiService} from '../../shared/gr-js-api-interface/gr-js-api-types';
import {ChangeInfo, CommitId} from '../../../types/common';
-import {fire, EventType} from '../../../utils/event-util';
+import {fireAlert} from '../../../utils/event-util';
const ERR_COMMIT_NOT_FOUND = 'Unable to find the commit hash of this change.';
const CHANGE_SUBJECT_LIMIT = 50;
@@ -125,7 +125,7 @@
const originalTitle = (commitMessage || '').split('\n')[0];
const revertTitle = `Revert "${originalTitle}"`;
if (!commitHash) {
- fire(this, EventType.SHOW_ALERT, ERR_COMMIT_NOT_FOUND);
+ fireAlert(this, ERR_COMMIT_NOT_FOUND);
return;
}
const revertCommitText = `This reverts commit ${commitHash}.`;
@@ -163,7 +163,7 @@
// Follow the same convention of the revert
const commitHash = change.current_revision;
if (!commitHash) {
- fire(this, EventType.SHOW_ALERT, ERR_COMMIT_NOT_FOUND);
+ fireAlert(this, ERR_COMMIT_NOT_FOUND);
return;
}
if (!changes || changes.length <= 1) return;
diff --git a/polygerrit-ui/app/elements/change/gr-confirm-revert-submission-dialog/gr-confirm-revert-submission-dialog.ts b/polygerrit-ui/app/elements/change/gr-confirm-revert-submission-dialog/gr-confirm-revert-submission-dialog.ts
index 2f9f800..ac52664 100644
--- a/polygerrit-ui/app/elements/change/gr-confirm-revert-submission-dialog/gr-confirm-revert-submission-dialog.ts
+++ b/polygerrit-ui/app/elements/change/gr-confirm-revert-submission-dialog/gr-confirm-revert-submission-dialog.ts
@@ -24,7 +24,7 @@
import {customElement, property} from '@polymer/decorators';
import {JsApiService} from '../../shared/gr-js-api-interface/gr-js-api-types';
import {ChangeInfo} from '../../../types/common';
-import {fire, EventType} from '../../../utils/event-util';
+import {fireAlert} from '../../../utils/event-util';
const ERR_COMMIT_NOT_FOUND = 'Unable to find the commit hash of this change.';
const CHANGE_SUBJECT_LIMIT = 50;
@@ -87,7 +87,7 @@
// Follow the same convention of the revert
const commitHash = change.current_revision;
if (!commitHash) {
- fire(this, EventType.SHOW_ALERT, ERR_COMMIT_NOT_FOUND);
+ fireAlert(this, ERR_COMMIT_NOT_FOUND);
return;
}
const revertTitle = `Revert submission ${change.submission_id}`;
diff --git a/polygerrit-ui/app/elements/change/gr-reply-dialog/gr-reply-dialog.ts b/polygerrit-ui/app/elements/change/gr-reply-dialog/gr-reply-dialog.ts
index 12f8021..f42adc6 100644
--- a/polygerrit-ui/app/elements/change/gr-reply-dialog/gr-reply-dialog.ts
+++ b/polygerrit-ui/app/elements/change/gr-reply-dialog/gr-reply-dialog.ts
@@ -110,7 +110,7 @@
import {isAttentionSetEnabled} from '../../../utils/attention-set-util';
import {CODE_REVIEW, getMaxAccounts} from '../../../utils/label-util';
import {isUnresolved} from '../../../utils/comment-util';
-import {fire, EventType} from '../../../utils/event-util';
+import {fireAlert} from '../../../utils/event-util';
const STORAGE_DEBOUNCE_INTERVAL_MS = 400;
@@ -549,7 +549,7 @@
const moveTo = isReviewer ? 'reviewer' : 'CC';
const id = account.name || account.email || key;
const message = `${id} moved from ${moveFrom} to ${moveTo}.`;
- fire(this, EventType.SHOW_ALERT, message);
+ fireAlert(this, message);
}
}
}
@@ -1270,7 +1270,7 @@
return;
}
if (this._sendDisabled) {
- fire(this, EventType.SHOW_ALERT, EMPTY_REPLY_MESSAGE);
+ fireAlert(this, EMPTY_REPLY_MESSAGE);
return;
}
return this.send(this._includeComments, this.canBeStarted)
diff --git a/polygerrit-ui/app/elements/core/gr-error-manager/gr-error-manager.ts b/polygerrit-ui/app/elements/core/gr-error-manager/gr-error-manager.ts
index 7a56d1c..4f3d7ce6 100644
--- a/polygerrit-ui/app/elements/core/gr-error-manager/gr-error-manager.ts
+++ b/polygerrit-ui/app/elements/core/gr-error-manager/gr-error-manager.ts
@@ -39,6 +39,7 @@
import {FetchRequest} from '../../shared/gr-rest-api-interface/gr-rest-apis/gr-rest-api-helper';
import {ErrorType, FixIronA11yAnnouncer} from '../../../types/types';
import {AccountId} from '../../../types/common';
+import {EventType} from '../../../utils/event-util';
const HIDE_ALERT_TIMEOUT_MS = 5000;
const CHECK_SIGN_IN_INTERVAL_MS = 60 * 1000;
@@ -129,7 +130,7 @@
super.attached();
this.listen(document, 'server-error', '_handleServerError');
this.listen(document, 'network-error', '_handleNetworkError');
- this.listen(document, 'show-alert', '_handleShowAlert');
+ this.listen(document, EventType.SHOW_ALERT, '_handleShowAlert');
this.listen(document, 'hide-alert', '_hideAlert');
this.listen(document, 'show-error', '_handleShowErrorDialog');
this.listen(document, 'visibilitychange', '_handleVisibilityChange');
@@ -151,7 +152,7 @@
this._clearHideAlertHandle();
this.unlisten(document, 'server-error', '_handleServerError');
this.unlisten(document, 'network-error', '_handleNetworkError');
- this.unlisten(document, 'show-alert', '_handleShowAlert');
+ this.unlisten(document, EventType.SHOW_ALERT, '_handleShowAlert');
this.unlisten(document, 'hide-alert', '_hideAlert');
this.unlisten(document, 'show-error', '_handleShowErrorDialog');
this.unlisten(document, 'visibilitychange', '_handleVisibilityChange');
diff --git a/polygerrit-ui/app/elements/diff/gr-diff-builder/gr-diff-builder-element.ts b/polygerrit-ui/app/elements/diff/gr-diff-builder/gr-diff-builder-element.ts
index b48efb4..2f85a0b 100644
--- a/polygerrit-ui/app/elements/diff/gr-diff-builder/gr-diff-builder-element.ts
+++ b/polygerrit-ui/app/elements/diff/gr-diff-builder/gr-diff-builder-element.ts
@@ -48,7 +48,7 @@
import {GrDiffGroup} from '../gr-diff/gr-diff-group';
import {PolymerSpliceChange} from '@polymer/polymer/interfaces';
import {getLineNumber} from '../gr-diff/gr-diff-utils';
-import {fire, EventType} from '../../../utils/event-util';
+import {fireAlert} from '../../../utils/event-util';
const DiffViewMode = {
SIDE_BY_SIDE: 'SIDE_BY_SIDE',
@@ -360,7 +360,7 @@
const message =
`The value of the '${pref}' user preference is ` +
'invalid. Fix in diff preferences';
- fire(this, EventType.SHOW_ALERT, message);
+ fireAlert(this, message);
throw Error(`Invalid preference value: ${pref}`);
}
diff --git a/polygerrit-ui/app/elements/diff/gr-diff-cursor/gr-diff-cursor.ts b/polygerrit-ui/app/elements/diff/gr-diff-cursor/gr-diff-cursor.ts
index 5090462..684a58a 100644
--- a/polygerrit-ui/app/elements/diff/gr-diff-cursor/gr-diff-cursor.ts
+++ b/polygerrit-ui/app/elements/diff/gr-diff-cursor/gr-diff-cursor.ts
@@ -36,7 +36,7 @@
import {PolymerDomWrapper} from '../../../types/types';
import {GrDiffGroupType} from '../gr-diff/gr-diff-group';
import {GrDiff} from '../gr-diff/gr-diff';
-import {fire, EventType} from '../../../utils/event-util';
+import {fireAlert} from '../../../utils/event-util';
const DiffViewMode = {
SIDE_BY_SIDE: 'SIDE_BY_SIDE',
@@ -228,11 +228,7 @@
);
}
this.lastDisplayedNavigateToNextFileToast = Date.now();
- fire(
- this,
- EventType.SHOW_ALERT,
- 'Press n again to navigate to next unreviewed file'
- );
+ fireAlert(this, 'Press n again to navigate to next unreviewed file');
}
this._fixSide();
diff --git a/polygerrit-ui/app/elements/diff/gr-diff-host/gr-diff-host.ts b/polygerrit-ui/app/elements/diff/gr-diff-host/gr-diff-host.ts
index 4b0208a..8c08084 100644
--- a/polygerrit-ui/app/elements/diff/gr-diff-host/gr-diff-host.ts
+++ b/polygerrit-ui/app/elements/diff/gr-diff-host/gr-diff-host.ts
@@ -72,7 +72,7 @@
import {LineNumber, FILE} from '../gr-diff/gr-diff-line';
import {GrCommentThread} from '../../shared/gr-comment-thread/gr-comment-thread';
import {KnownExperimentId} from '../../../services/flags/flags';
-import {EventType, fire} from '../../../utils/event-util';
+import {firePageError, fireAlert} from '../../../utils/event-util';
const MSG_EMPTY_BLAME = 'No blame information for this diff.';
@@ -513,7 +513,7 @@
.getBlame(this.changeNum, this.patchRange.patchNum, this.path, true)
.then(blame => {
if (!blame || !blame.length) {
- fire(this, EventType.SHOW_ALERT, MSG_EMPTY_BLAME);
+ fireAlert(this, MSG_EMPTY_BLAME);
return Promise.reject(MSG_EMPTY_BLAME);
}
@@ -612,13 +612,7 @@
return;
}
- this.dispatchEvent(
- new CustomEvent('page-error', {
- detail: {response},
- composed: true,
- bubbles: true,
- })
- );
+ firePageError(this, response);
}
/**
@@ -1022,18 +1016,16 @@
return false;
}
if (this._anyLineTooLong(diff)) {
- fire(
+ fireAlert(
this,
- EventType.SHOW_ALERT,
`A line is longer than ${SYNTAX_MAX_LINE_LENGTH}.` +
' Syntax Highlighting was turned off.'
);
return false;
}
if (this.$.diff.getDiffLength(diff) > SYNTAX_MAX_DIFF_LENGTH) {
- fire(
+ fireAlert(
this,
- EventType.SHOW_ALERT,
`A diff is longer than ${SYNTAX_MAX_DIFF_LENGTH}.` +
' Syntax Highlighting was turned off.'
);
diff --git a/polygerrit-ui/app/elements/diff/gr-diff-view/gr-diff-view.ts b/polygerrit-ui/app/elements/diff/gr-diff-view/gr-diff-view.ts
index cbee7c5..c169bf4 100644
--- a/polygerrit-ui/app/elements/diff/gr-diff-view/gr-diff-view.ts
+++ b/polygerrit-ui/app/elements/diff/gr-diff-view/gr-diff-view.ts
@@ -101,7 +101,7 @@
import {AppElementParams} from '../../gr-app-types';
import {CustomKeyboardEvent, OpenFixPreviewEvent} from '../../../types/events';
import {PORTING_COMMENTS_DIFF_LATENCY_LABEL} from '../../../services/gr-reporting/gr-reporting';
-import {fire, EventType} from '../../../utils/event-util';
+import {fireAlert, fireTitleChange} from '../../../utils/event-util';
const ERR_REVIEW_STATUS = 'Couldn’t change file review status.';
const MSG_LOADING_BLAME = 'Loading blame...';
@@ -458,7 +458,7 @@
this.$.reviewed.checked = reviewed;
if (!this._patchRange?.patchNum) return;
this._saveReviewedState(reviewed).catch(err => {
- fire(this, EventType.SHOW_ALERT, ERR_REVIEW_STATUS);
+ fireAlert(this, ERR_REVIEW_STATUS);
throw err;
});
}
@@ -876,9 +876,8 @@
_displayDiffBaseAgainstLeftToast() {
if (!this._patchRange) return;
- fire(
+ fireAlert(
this,
- EventType.SHOW_ALERT,
`Patchset ${this._patchRange.basePatchNum} vs ` +
`${this._patchRange.patchNum} selected. Press v + \u2190 to view ` +
`Base vs ${this._patchRange.basePatchNum}`
@@ -893,9 +892,8 @@
)
? 'Base'
: `Patchset ${this._patchRange.basePatchNum}`;
- fire(
+ fireAlert(
this,
- EventType.SHOW_ALERT,
`${leftPatchset} vs
${this._patchRange.patchNum} selected\n. Press v + \u2191 to view
${leftPatchset} vs Patchset ${latestPatchNum}`
@@ -967,7 +965,7 @@
this.params.commentId
);
if (!comment) {
- fire(this, EventType.SHOW_ALERT, 'comment not found');
+ fireAlert(this, 'comment not found');
GerritNav.navigateToChange(this._change);
return;
}
@@ -1122,9 +1120,8 @@
return;
}
- fire(
+ fireAlert(
this,
- EventType.SHOW_ALERT,
`File is unchanged between Patchset
${this._patchRange.basePatchNum} and
${this._patchRange.patchNum}. Showing diff of Base vs
@@ -1226,13 +1223,7 @@
_pathChanged(path: string) {
if (path) {
- this.dispatchEvent(
- new CustomEvent('title-change', {
- detail: {title: computeTruncatedPath(path)},
- composed: true,
- bubbles: true,
- })
- );
+ fireTitleChange(this, computeTruncatedPath(path));
}
if (!this._fileList || this._fileList.length === 0) return;
@@ -1672,12 +1663,12 @@
_loadBlame() {
this._isBlameLoading = true;
- fire(this, EventType.SHOW_ALERT, MSG_LOADING_BLAME);
+ fireAlert(this, MSG_LOADING_BLAME);
this.$.diffHost
.loadBlame()
.then(() => {
this._isBlameLoading = false;
- fire(this, EventType.SHOW_ALERT, MSG_LOADED_BLAME);
+ fireAlert(this, MSG_LOADED_BLAME);
})
.catch(() => {
this._isBlameLoading = false;
@@ -1723,7 +1714,7 @@
if (!this._patchRange) return;
if (patchNumEquals(this._patchRange.basePatchNum, ParentPatchSetNum)) {
- fire(this, EventType.SHOW_ALERT, 'Base is already selected.');
+ fireAlert(this, 'Base is already selected.');
return;
}
GerritNav.navigateToDiff(
@@ -1740,7 +1731,7 @@
if (!this._patchRange) return;
if (patchNumEquals(this._patchRange.basePatchNum, ParentPatchSetNum)) {
- fire(this, EventType.SHOW_ALERT, 'Left is already base.');
+ fireAlert(this, 'Left is already base.');
return;
}
GerritNav.navigateToDiff(
@@ -1762,7 +1753,7 @@
const latestPatchNum = computeLatestPatchNum(this._allPatchSets);
if (patchNumEquals(this._patchRange.patchNum, latestPatchNum)) {
- fire(this, EventType.SHOW_ALERT, 'Latest is already selected.');
+ fireAlert(this, 'Latest is already selected.');
return;
}
@@ -1782,7 +1773,7 @@
const latestPatchNum = computeLatestPatchNum(this._allPatchSets);
if (patchNumEquals(this._patchRange.patchNum, latestPatchNum)) {
- fire(this, EventType.SHOW_ALERT, 'Right is already latest.');
+ fireAlert(this, 'Right is already latest.');
return;
}
GerritNav.navigateToDiff(
@@ -1804,7 +1795,7 @@
patchNumEquals(this._patchRange.patchNum, latestPatchNum) &&
patchNumEquals(this._patchRange.basePatchNum, ParentPatchSetNum)
) {
- fire(this, EventType.SHOW_ALERT, 'Already diffing base against latest.');
+ fireAlert(this, 'Already diffing base against latest.');
return;
}
GerritNav.navigateToDiff(this._change, this._path, latestPatchNum);
diff --git a/polygerrit-ui/app/elements/diff/gr-diff/gr-diff.ts b/polygerrit-ui/app/elements/diff/gr-diff/gr-diff.ts
index a63b468..f64d940 100644
--- a/polygerrit-ui/app/elements/diff/gr-diff/gr-diff.ts
+++ b/polygerrit-ui/app/elements/diff/gr-diff/gr-diff.ts
@@ -57,7 +57,7 @@
import {FlattenedNodesObserver} from '@polymer/polymer/lib/utils/flattened-nodes-observer';
import {PolymerDeepPropertyChange} from '@polymer/polymer/interfaces';
import {AbortStop} from '../../shared/gr-cursor-manager/gr-cursor-manager';
-import {fire, EventType} from '../../../utils/event-util';
+import {fireAlert} from '../../../utils/event-util';
const NO_NEWLINE_BASE = 'No newline at end of base file.';
const NO_NEWLINE_REVISION = 'No newline at end of revision file.';
@@ -571,7 +571,7 @@
const lineNum = getLineNumber(el);
if (lineNum === null) {
- fire(this, EventType.SHOW_ALERT, 'Invalid line number');
+ fireAlert(this, 'Invalid line number');
return;
}
@@ -613,11 +613,7 @@
return false;
}
if (!this.patchRange) {
- fire(
- this,
- EventType.SHOW_ALERT,
- 'Cannot create comment. Patch range undefined.'
- );
+ fireAlert(this, 'Cannot create comment. Patch range undefined.');
return false;
}
const patchNum = el.classList.contains(Side.LEFT)
@@ -630,15 +626,11 @@
patchNumEquals(this.patchRange.patchNum, EditPatchSetNum);
if (isEdit) {
- fire(this, EventType.SHOW_ALERT, 'You cannot comment on an edit.');
+ fireAlert(this, 'You cannot comment on an edit.');
return false;
}
if (isEditBase) {
- fire(
- this,
- EventType.SHOW_ALERT,
- 'You cannot comment on the base patchset of an edit.'
- );
+ fireAlert(this, 'You cannot comment on the base patchset of an edit.');
return false;
}
return true;
diff --git a/polygerrit-ui/app/elements/diff/gr-diff/gr-diff_html.ts b/polygerrit-ui/app/elements/diff/gr-diff/gr-diff_html.ts
index b587d8a..ee5e1c0 100644
--- a/polygerrit-ui/app/elements/diff/gr-diff/gr-diff_html.ts
+++ b/polygerrit-ui/app/elements/diff/gr-diff/gr-diff_html.ts
@@ -222,6 +222,7 @@
}
.moveControls {
text-align: right;
+ font-style: italic;
}
/* ignoredWhitespaceOnly */
diff --git a/polygerrit-ui/app/elements/documentation/gr-documentation-search/gr-documentation-search.ts b/polygerrit-ui/app/elements/documentation/gr-documentation-search/gr-documentation-search.ts
index 5967b03..79c4359 100644
--- a/polygerrit-ui/app/elements/documentation/gr-documentation-search/gr-documentation-search.ts
+++ b/polygerrit-ui/app/elements/documentation/gr-documentation-search/gr-documentation-search.ts
@@ -30,6 +30,7 @@
import {customElement, property} from '@polymer/decorators';
import {RestApiService} from '../../../services/services/gr-rest-api/gr-rest-api';
import {DocResult} from '../../../types/common';
+import {fireTitleChange} from '../../../utils/event-util';
export interface GrDocumentationSearch {
$: {
@@ -62,9 +63,7 @@
/** @override */
attached() {
super.attached();
- this.dispatchEvent(
- new CustomEvent('title-change', {detail: {title: 'Documentation Search'}})
- );
+ fireTitleChange(this, 'Documentation Search');
}
_paramsChanged(params: ListViewParams) {
diff --git a/polygerrit-ui/app/elements/edit/gr-editor-view/gr-editor-view.ts b/polygerrit-ui/app/elements/edit/gr-editor-view/gr-editor-view.ts
index 8121855..60944d0 100644
--- a/polygerrit-ui/app/elements/edit/gr-editor-view/gr-editor-view.ts
+++ b/polygerrit-ui/app/elements/edit/gr-editor-view/gr-editor-view.ts
@@ -47,7 +47,7 @@
} from '../../../types/common';
import {GrStorage} from '../../shared/gr-storage/gr-storage';
import {HttpMethod, NotifyType} from '../../../constants/constants';
-import {fire, EventType} from '../../../utils/event-util';
+import {fireAlert, fireTitleChange} from '../../../utils/event-util';
const RESTORED_MESSAGE = 'Content restored from a previous edit.';
const SAVING_MESSAGE = 'Saving changes...';
@@ -177,13 +177,7 @@
// has been queued, the event can bubble up to the handler in gr-app.
this.async(() => {
const title = `Editing ${computeTruncatedPath(value.path)}`;
- this.dispatchEvent(
- new CustomEvent('title-change', {
- detail: {title},
- composed: true,
- bubbles: true,
- })
- );
+ fireTitleChange(this, title);
});
const promises = [];
@@ -256,7 +250,7 @@
storedContent.message &&
storedContent.message !== content
) {
- fire(this, EventType.SHOW_ALERT, RESTORED_MESSAGE);
+ fireAlert(this, RESTORED_MESSAGE);
this._newContent = storedContent.message;
} else {
@@ -300,7 +294,7 @@
}
_showAlert(message: string) {
- fire(this, EventType.SHOW_ALERT, message);
+ fireAlert(this, message);
}
_computeSaveDisabled(
diff --git a/polygerrit-ui/app/elements/gr-app-element.ts b/polygerrit-ui/app/elements/gr-app-element.ts
index c2fb124..c15634b 100644
--- a/polygerrit-ui/app/elements/gr-app-element.ts
+++ b/polygerrit-ui/app/elements/gr-app-element.ts
@@ -79,6 +79,7 @@
TitleChangeEventDetail,
} from '../types/events';
import {ViewState} from '../types/types';
+import {EventType} from '../utils/event-util';
interface ErrorInfo {
text: string;
@@ -209,8 +210,10 @@
created() {
super.created();
this._bindKeyboardShortcuts();
- this.addEventListener('page-error', e => this._handlePageError(e));
- this.addEventListener('title-change', e => this._handleTitleChange(e));
+ this.addEventListener(EventType.PAGE_ERROR, e => this._handlePageError(e));
+ this.addEventListener(EventType.TITLE_CHANGE, e =>
+ this._handleTitleChange(e)
+ );
this.addEventListener('location-change', e =>
this._handleLocationChange(e)
);
diff --git a/polygerrit-ui/app/elements/settings/gr-cla-view/gr-cla-view.ts b/polygerrit-ui/app/elements/settings/gr-cla-view/gr-cla-view.ts
index 6a906fa..891fdf6 100644
--- a/polygerrit-ui/app/elements/settings/gr-cla-view/gr-cla-view.ts
+++ b/polygerrit-ui/app/elements/settings/gr-cla-view/gr-cla-view.ts
@@ -32,7 +32,7 @@
GroupInfo,
ContributorAgreementInfo,
} from '../../../types/common';
-import {fire, EventType} from '../../../utils/event-util';
+import {fireAlert, fireTitleChange} from '../../../utils/event-util';
export interface GrClaView {
$: {
@@ -80,13 +80,7 @@
super.attached();
this.loadData();
- this.dispatchEvent(
- new CustomEvent('title-change', {
- detail: {title: 'New Contributor Agreement'},
- composed: true,
- bubbles: true,
- })
- );
+ fireTitleChange(this, 'New Contributor Agreement');
}
loadData() {
@@ -157,7 +151,7 @@
}
_createToast(message: string) {
- fire(this, EventType.SHOW_ALERT, message);
+ fireAlert(this, message);
}
_computeShowAgreementsClass(showAgreements: boolean) {
diff --git a/polygerrit-ui/app/elements/settings/gr-settings-view/gr-settings-view.ts b/polygerrit-ui/app/elements/settings/gr-settings-view/gr-settings-view.ts
index 6fcb6e8..4293a83 100644
--- a/polygerrit-ui/app/elements/settings/gr-settings-view/gr-settings-view.ts
+++ b/polygerrit-ui/app/elements/settings/gr-settings-view/gr-settings-view.ts
@@ -68,7 +68,7 @@
import {GerritView} from '../../core/gr-navigation/gr-navigation';
import {GrEmailEditor} from '../gr-email-editor/gr-email-editor';
import {CustomKeyboardEvent} from '../../../types/events';
-import {fire, EventType} from '../../../utils/event-util';
+import {fireAlert, fireTitleChange} from '../../../utils/event-util';
const PREFS_SECTION_FIELDS: Array<keyof PreferencesInput> = [
'changes_per_page',
@@ -220,13 +220,7 @@
// Polymer 2: anchor tag won't work on shadow DOM
// we need to manually calling scrollIntoView when hash changed
this.listen(window, 'location-change', '_handleLocationChange');
- this.dispatchEvent(
- new CustomEvent('title-change', {
- detail: {title: 'Settings'},
- composed: true,
- bubbles: true,
- })
- );
+ fireTitleChange(this, 'Settings');
this._isDark = !!window.localStorage.getItem('dark-theme');
@@ -287,7 +281,7 @@
promises.push(
this.$.restAPI.confirmEmail(this.params.emailToken).then(message => {
if (message) {
- fire(this, EventType.SHOW_ALERT, message);
+ fireAlert(this, message);
}
this.$.emailEditor.loadData();
})
@@ -537,11 +531,7 @@
applyDarkTheme();
}
this._isDark = !!window.localStorage.getItem('dark-theme');
- fire(
- this,
- EventType.SHOW_ALERT,
- `Theme changed to ${this._isDark ? 'dark' : 'light'}.`
- );
+ fireAlert(this, `Theme changed to ${this._isDark ? 'dark' : 'light'}.`);
}
_showHttpAuth(config?: ServerInfo) {
diff --git a/polygerrit-ui/app/elements/shared/gr-account-list/gr-account-list.ts b/polygerrit-ui/app/elements/shared/gr-account-list/gr-account-list.ts
index e5f0367..5cc1240 100644
--- a/polygerrit-ui/app/elements/shared/gr-account-list/gr-account-list.ts
+++ b/polygerrit-ui/app/elements/shared/gr-account-list/gr-account-list.ts
@@ -38,7 +38,7 @@
import {GrAccountChip} from '../gr-account-chip/gr-account-chip';
import {PolymerDeepPropertyChange} from '@polymer/polymer/interfaces';
import {PaperInputElementExt} from '../../../types/types';
-import {fire, EventType} from '../../../utils/event-util';
+import {fireAlert} from '../../../utils/event-util';
const VALID_EMAIL_ALERT = 'Please input a valid email.';
@@ -257,7 +257,7 @@
// Repopulate the input with what the user tried to enter and have
// a toast tell them why they can't enter it.
this.$.entry.setText(item);
- fire(this, EventType.SHOW_ALERT, VALID_EMAIL_ALERT);
+ fireAlert(this, VALID_EMAIL_ALERT);
return false;
} else {
const account = {email: item, _pendingAdd: true};
diff --git a/polygerrit-ui/app/elements/shared/gr-comment/gr-comment.ts b/polygerrit-ui/app/elements/shared/gr-comment/gr-comment.ts
index 48fbb69..bba6bf1 100644
--- a/polygerrit-ui/app/elements/shared/gr-comment/gr-comment.ts
+++ b/polygerrit-ui/app/elements/shared/gr-comment/gr-comment.ts
@@ -60,7 +60,7 @@
UIRobot,
} from '../../../utils/comment-util';
import {OpenFixPreviewEventDetail} from '../../../types/events';
-import {fire, EventType} from '../../../utils/event-util';
+import {fireAlert} from '../../../utils/event-util';
const STORAGE_DEBOUNCE_INTERVAL = 400;
const TOAST_DEBOUNCE_INTERVAL = 200;
@@ -851,7 +851,7 @@
// Note: the event is fired on the body rather than this element because
// this element may not be attached by the time this executes, in which
// case the event would not bubble.
- fire(document.body, EventType.SHOW_ALERT, message);
+ fireAlert(document.body, message);
},
TOAST_DEBOUNCE_INTERVAL
);
diff --git a/polygerrit-ui/app/elements/shared/gr-editable-content/gr-editable-content.ts b/polygerrit-ui/app/elements/shared/gr-editable-content/gr-editable-content.ts
index 71287a7..9c9363b 100644
--- a/polygerrit-ui/app/elements/shared/gr-editable-content/gr-editable-content.ts
+++ b/polygerrit-ui/app/elements/shared/gr-editable-content/gr-editable-content.ts
@@ -24,7 +24,7 @@
import {PolymerElement} from '@polymer/polymer/polymer-element';
import {customElement, property} from '@polymer/decorators';
import {htmlTemplate} from './gr-editable-content_html';
-import {fire, EventType} from '../../../utils/event-util';
+import {fireAlert} from '../../../utils/event-util';
const RESTORED_MESSAGE = 'Content restored from a previous edit.';
const STORAGE_DEBOUNCE_INTERVAL_MS = 400;
@@ -150,7 +150,7 @@
);
if (storedContent?.message) {
content = storedContent.message;
- fire(this, EventType.SHOW_ALERT, RESTORED_MESSAGE);
+ fireAlert(this, RESTORED_MESSAGE);
}
}
if (!content) {
diff --git a/polygerrit-ui/app/elements/shared/gr-rest-api-interface/gr-rest-api-interface.ts b/polygerrit-ui/app/elements/shared/gr-rest-api-interface/gr-rest-api-interface.ts
index 3f3ded2..ddcb0e2 100644
--- a/polygerrit-ui/app/elements/shared/gr-rest-api-interface/gr-rest-api-interface.ts
+++ b/polygerrit-ui/app/elements/shared/gr-rest-api-interface/gr-rest-api-interface.ts
@@ -157,6 +157,7 @@
HttpMethod,
ReviewerState,
} from '../../../constants/constants';
+import {firePageError} from '../../../utils/event-util';
const JSON_PREFIX = ")]}'";
const MAX_PROJECT_RESULTS = 25;
@@ -3396,16 +3397,8 @@
return Promise.resolve(project);
}
- const onError = (response?: Response | null) => {
- // Fire a page error so that the visual 404 is displayed.
- this.dispatchEvent(
- new CustomEvent('page-error', {
- detail: {response},
- composed: true,
- bubbles: true,
- })
- );
- };
+ const onError = (response?: Response | null) =>
+ firePageError(this, response);
return this.getChange(changeNum, onError).then(change => {
if (!change || !change.project) {
diff --git a/polygerrit-ui/app/utils/event-util.ts b/polygerrit-ui/app/utils/event-util.ts
index 5684b40..0af8fe2 100644
--- a/polygerrit-ui/app/utils/event-util.ts
+++ b/polygerrit-ui/app/utils/event-util.ts
@@ -17,14 +17,36 @@
export enum EventType {
SHOW_ALERT = 'show-alert',
+ PAGE_ERROR = 'page-error',
+ TITLE_CHANGE = 'title-change',
}
-export function fire(target: EventTarget, type: EventType, message: string) {
+export function fireAlert(target: EventTarget, message: string) {
target.dispatchEvent(
- new CustomEvent(type, {
+ new CustomEvent(EventType.SHOW_ALERT, {
detail: {message},
composed: true,
bubbles: true,
})
);
}
+
+export function firePageError(target: EventTarget, response?: Response | null) {
+ target.dispatchEvent(
+ new CustomEvent(EventType.PAGE_ERROR, {
+ detail: {response},
+ composed: true,
+ bubbles: true,
+ })
+ );
+}
+
+export function fireTitleChange(target: EventTarget, title: string) {
+ target.dispatchEvent(
+ new CustomEvent(EventType.TITLE_CHANGE, {
+ detail: {title},
+ composed: true,
+ bubbles: true,
+ })
+ );
+}