Refactor title-change events to use event-util
Change-Id: I0da001065b6f4d789544b5713aa4b803295ce6fc
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 bf987f9..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,7 +37,7 @@
EncodedGroupId,
GroupAuditEventInfo,
} from '../../../types/common';
-import {firePageError} from '../../../utils/event-util';
+import {firePageError, fireTitleChange} from '../../../utils/event-util';
const GROUP_EVENTS = ['ADD_GROUP', 'REMOVE_GROUP'];
@@ -66,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 */
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 af8edea..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 {fireAlert, firePageError} 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() {
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 b9854c2..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,7 +38,7 @@
RestApiService,
} from '../../../services/services/gr-rest-api/gr-rest-api';
import {hasOwnProperty} from '../../../utils/common-util';
-import {firePageError} from '../../../utils/event-util';
+import {firePageError, fireTitleChange} from '../../../utils/event-util';
const INTERNAL_GROUP_REGEX = /^[\da-f]{40}$/;
@@ -176,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 762d5fc..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
@@ -31,6 +31,7 @@
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;
@@ -85,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) {
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 98c6db0..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 {fireAlert, firePageError} 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() {
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 ff4e6ef..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,7 +48,7 @@
import {ProjectState} from '../../../constants/constants';
import {PolymerDeepPropertyChange} from '@polymer/polymer/interfaces';
import {hasOwnProperty} from '../../../utils/common-util';
-import {firePageError} from '../../../utils/event-util';
+import {firePageError, fireTitleChange} from '../../../utils/event-util';
const STATES = {
active: {value: ProjectState.ACTIVE, label: 'Active'},
@@ -150,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(
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 5f90169..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,7 +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} from '../../../utils/event-util';
+import {firePageError, fireTitleChange} from '../../../utils/event-util';
const PROJECT_PLACEHOLDER_PATTERN = /\$\{project\}/g;
@@ -221,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);
})
@@ -236,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-view/gr-change-view.ts b/polygerrit-ui/app/elements/change/gr-change-view/gr-change-view.ts
index c763aef..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,7 +146,6 @@
CustomKeyboardEvent,
EditableContentSaveEvent,
OpenFixPreviewEvent,
- ShowAlertEventDetail,
SwitchTabEvent,
} from '../../../types/events';
import {GrButton} from '../../shared/gr-button/gr-button';
@@ -155,6 +154,7 @@
import {PORTING_COMMENTS_CHANGE_LATENCY_LABEL} from '../../../services/gr-reporting/gr-reporting';
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);
}
/**
@@ -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(
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-view/gr-diff-view.ts b/polygerrit-ui/app/elements/diff/gr-diff-view/gr-diff-view.ts
index e1780f8..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 {fireAlert} 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...';
@@ -1223,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;
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 5863ee3..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 {fireAlert} 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 = [];
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 092c5de..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 {fireAlert} 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() {
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 84bdf78..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 {fireAlert} 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');
diff --git a/polygerrit-ui/app/utils/event-util.ts b/polygerrit-ui/app/utils/event-util.ts
index 6587dfa..0af8fe2 100644
--- a/polygerrit-ui/app/utils/event-util.ts
+++ b/polygerrit-ui/app/utils/event-util.ts
@@ -18,6 +18,7 @@
export enum EventType {
SHOW_ALERT = 'show-alert',
PAGE_ERROR = 'page-error',
+ TITLE_CHANGE = 'title-change',
}
export function fireAlert(target: EventTarget, message: string) {
@@ -39,3 +40,13 @@
})
);
}
+
+export function fireTitleChange(target: EventTarget, title: string) {
+ target.dispatchEvent(
+ new CustomEvent(EventType.TITLE_CHANGE, {
+ detail: {title},
+ composed: true,
+ bubbles: true,
+ })
+ );
+}