Refactor show-alert, page-error events
Change-Id: I38b55a8ceaa5819742e819cea0349fcecfb4b1ce
This commit is contained in:
@@ -37,6 +37,7 @@ import {
|
||||
EncodedGroupId,
|
||||
GroupAuditEventInfo,
|
||||
} from '../../../types/common';
|
||||
import {firePageError} from '../../../utils/event-util';
|
||||
|
||||
const GROUP_EVENTS = ['ADD_GROUP', 'REMOVE_GROUP'];
|
||||
|
||||
@@ -85,15 +86,7 @@ export class GrGroupAuditLog extends ListViewMixin(
|
||||
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)
|
||||
|
||||
@@ -46,7 +46,7 @@ import {
|
||||
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} from '../../../utils/event-util';
|
||||
|
||||
const SUGGESTIONS_LIMIT = 15;
|
||||
const SAVING_ERROR_TEXT =
|
||||
@@ -142,15 +142,7 @@ export class GrGroupMembers extends GestureEventListeners(
|
||||
|
||||
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 +290,7 @@ export class GrGroupMembers extends GestureEventListeners(
|
||||
(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);
|
||||
|
||||
@@ -38,6 +38,7 @@ import {
|
||||
RestApiService,
|
||||
} from '../../../services/services/gr-rest-api/gr-rest-api';
|
||||
import {hasOwnProperty} from '../../../utils/common-util';
|
||||
import {firePageError} from '../../../utils/event-util';
|
||||
|
||||
const INTERNAL_GROUP_REGEX = /^[\da-f]{40}$/;
|
||||
|
||||
@@ -144,15 +145,7 @@ export class GrGroup extends GestureEventListeners(
|
||||
|
||||
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) {
|
||||
|
||||
@@ -30,6 +30,7 @@ import {customElement, property} from '@polymer/decorators';
|
||||
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';
|
||||
|
||||
interface PluginInfoWithName extends PluginInfo {
|
||||
name: string;
|
||||
@@ -102,15 +103,7 @@ export class GrPluginList extends ListViewMixin(
|
||||
}
|
||||
|
||||
_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 => {
|
||||
|
||||
@@ -52,7 +52,7 @@ import {
|
||||
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 @@ export class GrRepoAccess extends GestureEventListeners(
|
||||
}
|
||||
|
||||
_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 @@ export class GrRepoAccess extends GestureEventListeners(
|
||||
!Object.keys(addRemoveObj.remove).length &&
|
||||
!addRemoveObj.parent
|
||||
) {
|
||||
fire(this, EventType.SHOW_ALERT, NOTHING_TO_SAVE);
|
||||
fireAlert(this, NOTHING_TO_SAVE);
|
||||
return;
|
||||
}
|
||||
const obj: ProjectAccessInput = ({
|
||||
|
||||
@@ -42,7 +42,7 @@ import {
|
||||
} 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} from '../../../utils/event-util';
|
||||
|
||||
const GC_MESSAGE = 'Garbage collection completed successfully.';
|
||||
const CONFIG_BRANCH = 'refs/meta/config' as BranchName;
|
||||
@@ -110,13 +110,7 @@ export class GrRepoCommands extends GestureEventListeners(
|
||||
// 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 +137,7 @@ export class GrRepoCommands extends GestureEventListeners(
|
||||
.runRepoGC(this.repo)
|
||||
.then(response => {
|
||||
if (response?.status === 200) {
|
||||
fire(this, EventType.SHOW_ALERT, GC_MESSAGE);
|
||||
fireAlert(this, GC_MESSAGE);
|
||||
}
|
||||
})
|
||||
.finally(() => {
|
||||
@@ -185,7 +179,7 @@ export class GrRepoCommands extends GestureEventListeners(
|
||||
const message = change
|
||||
? CREATE_CHANGE_SUCCEEDED_MESSAGE
|
||||
: CREATE_CHANGE_FAILED_MESSAGE;
|
||||
fire(this, EventType.SHOW_ALERT, message);
|
||||
fireAlert(this, message);
|
||||
if (!change) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -27,6 +27,7 @@ import {customElement, property} from '@polymer/decorators';
|
||||
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 @@ export class GrRepoDashboards extends GestureEventListeners(
|
||||
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)
|
||||
|
||||
@@ -53,6 +53,7 @@ import {
|
||||
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 @@ export class GrRepoDetailList extends ListViewMixin(
|
||||
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)
|
||||
|
||||
@@ -48,6 +48,7 @@ import {PluginData} from '../gr-repo-plugin-config/gr-repo-plugin-config';
|
||||
import {ProjectState} from '../../../constants/constants';
|
||||
import {PolymerDeepPropertyChange} from '@polymer/polymer/interfaces';
|
||||
import {hasOwnProperty} from '../../../utils/common-util';
|
||||
import {firePageError} from '../../../utils/event-util';
|
||||
|
||||
const STATES = {
|
||||
active: {value: ProjectState.ACTIVE, label: 'Active'},
|
||||
@@ -181,15 +182,7 @@ export class GrRepo extends GestureEventListeners(
|
||||
|
||||
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 => {
|
||||
|
||||
@@ -58,6 +58,7 @@ import {GrOverlay} from '../../shared/gr-overlay/gr-overlay';
|
||||
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';
|
||||
|
||||
const PROJECT_PLACEHOLDER_PATTERN = /\$\{project\}/g;
|
||||
|
||||
@@ -149,15 +150,7 @@ export class GrDashboardView extends GestureEventListeners(
|
||||
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 => {
|
||||
|
||||
@@ -113,7 +113,7 @@ import {
|
||||
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 @@ export class GrChangeActions
|
||||
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 @@ export class GrChangeActions
|
||||
_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 @@ export class GrChangeActions
|
||||
_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();
|
||||
|
||||
@@ -153,7 +153,7 @@ 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';
|
||||
|
||||
const CHANGE_ID_ERROR = {
|
||||
@@ -1669,7 +1669,7 @@ export class GrChangeView extends KeyboardShortcutMixin(
|
||||
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 +1683,7 @@ export class GrChangeView extends KeyboardShortcutMixin(
|
||||
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);
|
||||
@@ -1726,7 +1726,7 @@ export class GrChangeView extends KeyboardShortcutMixin(
|
||||
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 +1748,7 @@ export class GrChangeView extends KeyboardShortcutMixin(
|
||||
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 +1872,7 @@ export class GrChangeView extends KeyboardShortcutMixin(
|
||||
}
|
||||
|
||||
_handleGetChangeDetailError(response?: Response | null) {
|
||||
this.dispatchEvent(
|
||||
new CustomEvent('page-error', {
|
||||
detail: {response},
|
||||
composed: true,
|
||||
bubbles: true,
|
||||
})
|
||||
);
|
||||
firePageError(this, response);
|
||||
}
|
||||
|
||||
_getLoggedIn() {
|
||||
|
||||
@@ -25,7 +25,7 @@ import {htmlTemplate} from './gr-confirm-revert-dialog_html';
|
||||
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 @@ export class GrConfirmRevertDialog extends GestureEventListeners(
|
||||
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 @@ export class GrConfirmRevertDialog extends GestureEventListeners(
|
||||
// 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;
|
||||
|
||||
@@ -24,7 +24,7 @@ import {htmlTemplate} from './gr-confirm-revert-submission-dialog_html';
|
||||
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 @@ export class GrConfirmRevertSubmissionDialog extends GestureEventListeners(
|
||||
// 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}`;
|
||||
|
||||
@@ -110,7 +110,7 @@ import {GrStorage, StorageLocation} from '../../shared/gr-storage/gr-storage';
|
||||
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 @@ export class GrReplyDialog extends KeyboardShortcutMixin(
|
||||
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 @@ export class GrReplyDialog extends KeyboardShortcutMixin(
|
||||
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)
|
||||
|
||||
@@ -48,7 +48,7 @@ import {GrDiffLine, LineNumber} from '../gr-diff/gr-diff-line';
|
||||
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 @@ export class GrDiffBuilderElement extends GestureEventListeners(
|
||||
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}`);
|
||||
}
|
||||
|
||||
|
||||
@@ -36,7 +36,7 @@ import {PolymerSpliceChange} from '@polymer/polymer/interfaces';
|
||||
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 @@ export class GrDiffCursor extends GestureEventListeners(
|
||||
);
|
||||
}
|
||||
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();
|
||||
|
||||
@@ -72,7 +72,7 @@ import {FilesWebLinks} from '../gr-patch-range-select/gr-patch-range-select';
|
||||
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 @@ export class GrDiffHost extends GestureEventListeners(
|
||||
.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 @@ export class GrDiffHost extends GestureEventListeners(
|
||||
return;
|
||||
}
|
||||
|
||||
this.dispatchEvent(
|
||||
new CustomEvent('page-error', {
|
||||
detail: {response},
|
||||
composed: true,
|
||||
bubbles: true,
|
||||
})
|
||||
);
|
||||
firePageError(this, response);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1022,18 +1016,16 @@ export class GrDiffHost extends GestureEventListeners(
|
||||
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.'
|
||||
);
|
||||
|
||||
@@ -101,7 +101,7 @@ import {CommentMap} from '../../../utils/comment-util';
|
||||
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} from '../../../utils/event-util';
|
||||
|
||||
const ERR_REVIEW_STATUS = 'Couldn’t change file review status.';
|
||||
const MSG_LOADING_BLAME = 'Loading blame...';
|
||||
@@ -458,7 +458,7 @@ export class GrDiffView extends KeyboardShortcutMixin(
|
||||
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 @@ export class GrDiffView extends KeyboardShortcutMixin(
|
||||
|
||||
_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 @@ export class GrDiffView extends KeyboardShortcutMixin(
|
||||
)
|
||||
? '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 @@ export class GrDiffView extends KeyboardShortcutMixin(
|
||||
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 @@ export class GrDiffView extends KeyboardShortcutMixin(
|
||||
return;
|
||||
}
|
||||
|
||||
fire(
|
||||
fireAlert(
|
||||
this,
|
||||
EventType.SHOW_ALERT,
|
||||
`File is unchanged between Patchset
|
||||
${this._patchRange.basePatchNum} and
|
||||
${this._patchRange.patchNum}. Showing diff of Base vs
|
||||
@@ -1672,12 +1669,12 @@ export class GrDiffView extends KeyboardShortcutMixin(
|
||||
|
||||
_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 +1720,7 @@ export class GrDiffView extends KeyboardShortcutMixin(
|
||||
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 +1737,7 @@ export class GrDiffView extends KeyboardShortcutMixin(
|
||||
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 +1759,7 @@ export class GrDiffView extends KeyboardShortcutMixin(
|
||||
|
||||
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 +1779,7 @@ export class GrDiffView extends KeyboardShortcutMixin(
|
||||
|
||||
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 +1801,7 @@ export class GrDiffView extends KeyboardShortcutMixin(
|
||||
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);
|
||||
|
||||
@@ -57,7 +57,7 @@ import {KeyLocations} from '../gr-diff-processor/gr-diff-processor';
|
||||
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 @@ export class GrDiff extends GestureEventListeners(
|
||||
|
||||
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 @@ export class GrDiff extends GestureEventListeners(
|
||||
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 @@ export class GrDiff extends GestureEventListeners(
|
||||
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;
|
||||
|
||||
@@ -47,7 +47,7 @@ import {
|
||||
} 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} from '../../../utils/event-util';
|
||||
|
||||
const RESTORED_MESSAGE = 'Content restored from a previous edit.';
|
||||
const SAVING_MESSAGE = 'Saving changes...';
|
||||
@@ -256,7 +256,7 @@ export class GrEditorView extends KeyboardShortcutMixin(
|
||||
storedContent.message &&
|
||||
storedContent.message !== content
|
||||
) {
|
||||
fire(this, EventType.SHOW_ALERT, RESTORED_MESSAGE);
|
||||
fireAlert(this, RESTORED_MESSAGE);
|
||||
|
||||
this._newContent = storedContent.message;
|
||||
} else {
|
||||
@@ -300,7 +300,7 @@ export class GrEditorView extends KeyboardShortcutMixin(
|
||||
}
|
||||
|
||||
_showAlert(message: string) {
|
||||
fire(this, EventType.SHOW_ALERT, message);
|
||||
fireAlert(this, message);
|
||||
}
|
||||
|
||||
_computeSaveDisabled(
|
||||
|
||||
@@ -32,7 +32,7 @@ import {
|
||||
GroupInfo,
|
||||
ContributorAgreementInfo,
|
||||
} from '../../../types/common';
|
||||
import {fire, EventType} from '../../../utils/event-util';
|
||||
import {fireAlert} from '../../../utils/event-util';
|
||||
|
||||
export interface GrClaView {
|
||||
$: {
|
||||
@@ -157,7 +157,7 @@ export class GrClaView extends GestureEventListeners(
|
||||
}
|
||||
|
||||
_createToast(message: string) {
|
||||
fire(this, EventType.SHOW_ALERT, message);
|
||||
fireAlert(this, message);
|
||||
}
|
||||
|
||||
_computeShowAgreementsClass(showAgreements: boolean) {
|
||||
|
||||
@@ -68,7 +68,7 @@ import {GrGpgEditor} from '../gr-gpg-editor/gr-gpg-editor';
|
||||
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} from '../../../utils/event-util';
|
||||
|
||||
const PREFS_SECTION_FIELDS: Array<keyof PreferencesInput> = [
|
||||
'changes_per_page',
|
||||
@@ -287,7 +287,7 @@ export class GrSettingsView extends ChangeTableMixin(
|
||||
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 +537,7 @@ export class GrSettingsView extends ChangeTableMixin(
|
||||
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) {
|
||||
|
||||
@@ -38,7 +38,7 @@ import {GrAccountEntry} from '../gr-account-entry/gr-account-entry';
|
||||
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 @@ export class GrAccountList extends GestureEventListeners(
|
||||
// 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};
|
||||
|
||||
@@ -60,7 +60,7 @@ import {
|
||||
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 @@ export class GrComment extends KeyboardShortcutMixin(
|
||||
// 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
|
||||
);
|
||||
|
||||
@@ -24,7 +24,7 @@ import {LegacyElementMixin} from '@polymer/polymer/lib/legacy/legacy-element-mix
|
||||
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 @@ export class GrEditableContent extends GestureEventListeners(
|
||||
);
|
||||
if (storedContent?.message) {
|
||||
content = storedContent.message;
|
||||
fire(this, EventType.SHOW_ALERT, RESTORED_MESSAGE);
|
||||
fireAlert(this, RESTORED_MESSAGE);
|
||||
}
|
||||
}
|
||||
if (!content) {
|
||||
|
||||
@@ -157,6 +157,7 @@ import {
|
||||
HttpMethod,
|
||||
ReviewerState,
|
||||
} from '../../../constants/constants';
|
||||
import {firePageError} from '../../../utils/event-util';
|
||||
|
||||
const JSON_PREFIX = ")]}'";
|
||||
const MAX_PROJECT_RESULTS = 25;
|
||||
@@ -3396,16 +3397,8 @@ export class GrRestApiInterface
|
||||
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) {
|
||||
|
||||
@@ -17,14 +17,25 @@
|
||||
|
||||
export enum EventType {
|
||||
SHOW_ALERT = 'show-alert',
|
||||
PAGE_ERROR = 'page-error',
|
||||
}
|
||||
|
||||
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,
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user