Refactor show-alert, page-error events
Change-Id: I38b55a8ceaa5819742e819cea0349fcecfb4b1ce
This commit is contained in:
		@@ -37,6 +37,7 @@ import {
 | 
				
			|||||||
  EncodedGroupId,
 | 
					  EncodedGroupId,
 | 
				
			||||||
  GroupAuditEventInfo,
 | 
					  GroupAuditEventInfo,
 | 
				
			||||||
} from '../../../types/common';
 | 
					} from '../../../types/common';
 | 
				
			||||||
 | 
					import {firePageError} from '../../../utils/event-util';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
const GROUP_EVENTS = ['ADD_GROUP', 'REMOVE_GROUP'];
 | 
					const GROUP_EVENTS = ['ADD_GROUP', 'REMOVE_GROUP'];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -85,15 +86,7 @@ export class GrGroupAuditLog extends ListViewMixin(
 | 
				
			|||||||
      return '';
 | 
					      return '';
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    const errFn: ErrorCallback = response => {
 | 
					    const errFn: ErrorCallback = response => firePageError(this, response);
 | 
				
			||||||
      this.dispatchEvent(
 | 
					 | 
				
			||||||
        new CustomEvent('page-error', {
 | 
					 | 
				
			||||||
          detail: {response},
 | 
					 | 
				
			||||||
          composed: true,
 | 
					 | 
				
			||||||
          bubbles: true,
 | 
					 | 
				
			||||||
        })
 | 
					 | 
				
			||||||
      );
 | 
					 | 
				
			||||||
    };
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
    return this.$.restAPI
 | 
					    return this.$.restAPI
 | 
				
			||||||
      .getGroupAuditLog(this.groupId, errFn)
 | 
					      .getGroupAuditLog(this.groupId, errFn)
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -46,7 +46,7 @@ import {
 | 
				
			|||||||
import {AutocompleteQuery} from '../../shared/gr-autocomplete/gr-autocomplete';
 | 
					import {AutocompleteQuery} from '../../shared/gr-autocomplete/gr-autocomplete';
 | 
				
			||||||
import {PolymerDomRepeatEvent} from '../../../types/types';
 | 
					import {PolymerDomRepeatEvent} from '../../../types/types';
 | 
				
			||||||
import {hasOwnProperty} from '../../../utils/common-util';
 | 
					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 SUGGESTIONS_LIMIT = 15;
 | 
				
			||||||
const SAVING_ERROR_TEXT =
 | 
					const SAVING_ERROR_TEXT =
 | 
				
			||||||
@@ -142,15 +142,7 @@ export class GrGroupMembers extends GestureEventListeners(
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    const promises: Promise<void>[] = [];
 | 
					    const promises: Promise<void>[] = [];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    const errFn: ErrorCallback = response => {
 | 
					    const errFn: ErrorCallback = response => firePageError(this, response);
 | 
				
			||||||
      this.dispatchEvent(
 | 
					 | 
				
			||||||
        new CustomEvent('page-error', {
 | 
					 | 
				
			||||||
          detail: {response},
 | 
					 | 
				
			||||||
          composed: true,
 | 
					 | 
				
			||||||
          bubbles: true,
 | 
					 | 
				
			||||||
        })
 | 
					 | 
				
			||||||
      );
 | 
					 | 
				
			||||||
    };
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
    return this.$.restAPI.getGroupConfig(this.groupId, errFn).then(config => {
 | 
					    return this.$.restAPI.getGroupConfig(this.groupId, errFn).then(config => {
 | 
				
			||||||
      if (!config || !config.name) {
 | 
					      if (!config || !config.name) {
 | 
				
			||||||
@@ -298,7 +290,7 @@ export class GrGroupMembers extends GestureEventListeners(
 | 
				
			|||||||
        (errResponse, err) => {
 | 
					        (errResponse, err) => {
 | 
				
			||||||
          if (errResponse) {
 | 
					          if (errResponse) {
 | 
				
			||||||
            if (errResponse.status === 404) {
 | 
					            if (errResponse.status === 404) {
 | 
				
			||||||
              fire(this, EventType.SHOW_ALERT, SAVING_ERROR_TEXT);
 | 
					              fireAlert(this, SAVING_ERROR_TEXT);
 | 
				
			||||||
              return errResponse;
 | 
					              return errResponse;
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
            throw Error(errResponse.statusText);
 | 
					            throw Error(errResponse.statusText);
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -38,6 +38,7 @@ import {
 | 
				
			|||||||
  RestApiService,
 | 
					  RestApiService,
 | 
				
			||||||
} from '../../../services/services/gr-rest-api/gr-rest-api';
 | 
					} from '../../../services/services/gr-rest-api/gr-rest-api';
 | 
				
			||||||
import {hasOwnProperty} from '../../../utils/common-util';
 | 
					import {hasOwnProperty} from '../../../utils/common-util';
 | 
				
			||||||
 | 
					import {firePageError} from '../../../utils/event-util';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
const INTERNAL_GROUP_REGEX = /^[\da-f]{40}$/;
 | 
					const INTERNAL_GROUP_REGEX = /^[\da-f]{40}$/;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -144,15 +145,7 @@ export class GrGroup extends GestureEventListeners(
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    const promises: Promise<unknown>[] = [];
 | 
					    const promises: Promise<unknown>[] = [];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    const errFn: ErrorCallback = response => {
 | 
					    const errFn: ErrorCallback = response => firePageError(this, response);
 | 
				
			||||||
      this.dispatchEvent(
 | 
					 | 
				
			||||||
        new CustomEvent('page-error', {
 | 
					 | 
				
			||||||
          detail: {response},
 | 
					 | 
				
			||||||
          composed: true,
 | 
					 | 
				
			||||||
          bubbles: true,
 | 
					 | 
				
			||||||
        })
 | 
					 | 
				
			||||||
      );
 | 
					 | 
				
			||||||
    };
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
    return this.$.restAPI.getGroupConfig(this.groupId, errFn).then(config => {
 | 
					    return this.$.restAPI.getGroupConfig(this.groupId, errFn).then(config => {
 | 
				
			||||||
      if (!config || !config.name) {
 | 
					      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 {RestApiService} from '../../../services/services/gr-rest-api/gr-rest-api';
 | 
				
			||||||
import {ErrorCallback} 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 {PluginInfo} from '../../../types/common';
 | 
				
			||||||
 | 
					import {firePageError} from '../../../utils/event-util';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
interface PluginInfoWithName extends PluginInfo {
 | 
					interface PluginInfoWithName extends PluginInfo {
 | 
				
			||||||
  name: string;
 | 
					  name: string;
 | 
				
			||||||
@@ -102,15 +103,7 @@ export class GrPluginList extends ListViewMixin(
 | 
				
			|||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  _getPlugins(filter: string, pluginsPerPage: number, offset?: number) {
 | 
					  _getPlugins(filter: string, pluginsPerPage: number, offset?: number) {
 | 
				
			||||||
    const errFn: ErrorCallback = response => {
 | 
					    const errFn: ErrorCallback = response => firePageError(this, response);
 | 
				
			||||||
      this.dispatchEvent(
 | 
					 | 
				
			||||||
        new CustomEvent('page-error', {
 | 
					 | 
				
			||||||
          detail: {response},
 | 
					 | 
				
			||||||
          composed: true,
 | 
					 | 
				
			||||||
          bubbles: true,
 | 
					 | 
				
			||||||
        })
 | 
					 | 
				
			||||||
      );
 | 
					 | 
				
			||||||
    };
 | 
					 | 
				
			||||||
    return this.$.restAPI
 | 
					    return this.$.restAPI
 | 
				
			||||||
      .getPlugins(filter, pluginsPerPage, offset, errFn)
 | 
					      .getPlugins(filter, pluginsPerPage, offset, errFn)
 | 
				
			||||||
      .then(plugins => {
 | 
					      .then(plugins => {
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -52,7 +52,7 @@ import {
 | 
				
			|||||||
  PropertyTreeNode,
 | 
					  PropertyTreeNode,
 | 
				
			||||||
  PrimitiveValue,
 | 
					  PrimitiveValue,
 | 
				
			||||||
} from './gr-repo-access-interfaces';
 | 
					} 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.';
 | 
					const NOTHING_TO_SAVE = 'No changes to save.';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -155,15 +155,7 @@ export class GrRepoAccess extends GestureEventListeners(
 | 
				
			|||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  _reload(repo: RepoName) {
 | 
					  _reload(repo: RepoName) {
 | 
				
			||||||
    const errFn = (response?: Response | null) => {
 | 
					    const errFn = (response?: Response | null) => firePageError(this, response);
 | 
				
			||||||
      this.dispatchEvent(
 | 
					 | 
				
			||||||
        new CustomEvent('page-error', {
 | 
					 | 
				
			||||||
          detail: {response},
 | 
					 | 
				
			||||||
          composed: true,
 | 
					 | 
				
			||||||
          bubbles: true,
 | 
					 | 
				
			||||||
        })
 | 
					 | 
				
			||||||
      );
 | 
					 | 
				
			||||||
    };
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
    this._editing = false;
 | 
					    this._editing = false;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -517,7 +509,7 @@ export class GrRepoAccess extends GestureEventListeners(
 | 
				
			|||||||
      !Object.keys(addRemoveObj.remove).length &&
 | 
					      !Object.keys(addRemoveObj.remove).length &&
 | 
				
			||||||
      !addRemoveObj.parent
 | 
					      !addRemoveObj.parent
 | 
				
			||||||
    ) {
 | 
					    ) {
 | 
				
			||||||
      fire(this, EventType.SHOW_ALERT, NOTHING_TO_SAVE);
 | 
					      fireAlert(this, NOTHING_TO_SAVE);
 | 
				
			||||||
      return;
 | 
					      return;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    const obj: ProjectAccessInput = ({
 | 
					    const obj: ProjectAccessInput = ({
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -42,7 +42,7 @@ import {
 | 
				
			|||||||
} from '../../../types/common';
 | 
					} from '../../../types/common';
 | 
				
			||||||
import {GrOverlay} from '../../shared/gr-overlay/gr-overlay';
 | 
					import {GrOverlay} from '../../shared/gr-overlay/gr-overlay';
 | 
				
			||||||
import {GrCreateChangeDialog} from '../gr-create-change-dialog/gr-create-change-dialog';
 | 
					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 GC_MESSAGE = 'Garbage collection completed successfully.';
 | 
				
			||||||
const CONFIG_BRANCH = 'refs/meta/config' as BranchName;
 | 
					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
 | 
					      // Do not process the error, if the component is not attached to the DOM
 | 
				
			||||||
      // anymore, which at least in tests can happen.
 | 
					      // anymore, which at least in tests can happen.
 | 
				
			||||||
      if (!this.isConnected) return;
 | 
					      if (!this.isConnected) return;
 | 
				
			||||||
      this.dispatchEvent(
 | 
					      firePageError(this, response);
 | 
				
			||||||
        new CustomEvent('page-error', {
 | 
					 | 
				
			||||||
          detail: {response},
 | 
					 | 
				
			||||||
          composed: true,
 | 
					 | 
				
			||||||
          bubbles: true,
 | 
					 | 
				
			||||||
        })
 | 
					 | 
				
			||||||
      );
 | 
					 | 
				
			||||||
    };
 | 
					    };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    this.$.restAPI.getProjectConfig(this.repo, errFn).then(config => {
 | 
					    this.$.restAPI.getProjectConfig(this.repo, errFn).then(config => {
 | 
				
			||||||
@@ -143,7 +137,7 @@ export class GrRepoCommands extends GestureEventListeners(
 | 
				
			|||||||
      .runRepoGC(this.repo)
 | 
					      .runRepoGC(this.repo)
 | 
				
			||||||
      .then(response => {
 | 
					      .then(response => {
 | 
				
			||||||
        if (response?.status === 200) {
 | 
					        if (response?.status === 200) {
 | 
				
			||||||
          fire(this, EventType.SHOW_ALERT, GC_MESSAGE);
 | 
					          fireAlert(this, GC_MESSAGE);
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
      })
 | 
					      })
 | 
				
			||||||
      .finally(() => {
 | 
					      .finally(() => {
 | 
				
			||||||
@@ -185,7 +179,7 @@ export class GrRepoCommands extends GestureEventListeners(
 | 
				
			|||||||
        const message = change
 | 
					        const message = change
 | 
				
			||||||
          ? CREATE_CHANGE_SUCCEEDED_MESSAGE
 | 
					          ? CREATE_CHANGE_SUCCEEDED_MESSAGE
 | 
				
			||||||
          : CREATE_CHANGE_FAILED_MESSAGE;
 | 
					          : CREATE_CHANGE_FAILED_MESSAGE;
 | 
				
			||||||
        fire(this, EventType.SHOW_ALERT, message);
 | 
					        fireAlert(this, message);
 | 
				
			||||||
        if (!change) {
 | 
					        if (!change) {
 | 
				
			||||||
          return;
 | 
					          return;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -27,6 +27,7 @@ import {customElement, property} from '@polymer/decorators';
 | 
				
			|||||||
import {RestApiService} from '../../../services/services/gr-rest-api/gr-rest-api';
 | 
					import {RestApiService} from '../../../services/services/gr-rest-api/gr-rest-api';
 | 
				
			||||||
import {RepoName, DashboardId, DashboardInfo} from '../../../types/common';
 | 
					import {RepoName, DashboardId, DashboardInfo} from '../../../types/common';
 | 
				
			||||||
import {ErrorCallback} from '../../../services/services/gr-rest-api/gr-rest-api';
 | 
					import {ErrorCallback} from '../../../services/services/gr-rest-api/gr-rest-api';
 | 
				
			||||||
 | 
					import {firePageError} from '../../../utils/event-util';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
interface DashboardRef {
 | 
					interface DashboardRef {
 | 
				
			||||||
  section: string;
 | 
					  section: string;
 | 
				
			||||||
@@ -61,15 +62,7 @@ export class GrRepoDashboards extends GestureEventListeners(
 | 
				
			|||||||
      return Promise.resolve();
 | 
					      return Promise.resolve();
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    const errFn: ErrorCallback = response => {
 | 
					    const errFn: ErrorCallback = response => firePageError(this, response);
 | 
				
			||||||
      this.dispatchEvent(
 | 
					 | 
				
			||||||
        new CustomEvent('page-error', {
 | 
					 | 
				
			||||||
          detail: {response},
 | 
					 | 
				
			||||||
          composed: true,
 | 
					 | 
				
			||||||
          bubbles: true,
 | 
					 | 
				
			||||||
        })
 | 
					 | 
				
			||||||
      );
 | 
					 | 
				
			||||||
    };
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
    return this.$.restAPI
 | 
					    return this.$.restAPI
 | 
				
			||||||
      .getRepoDashboards(repo, errFn)
 | 
					      .getRepoDashboards(repo, errFn)
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -53,6 +53,7 @@ import {
 | 
				
			|||||||
import {AppElementRepoParams} from '../../gr-app-types';
 | 
					import {AppElementRepoParams} from '../../gr-app-types';
 | 
				
			||||||
import {PolymerDomRepeatEvent} from '../../../types/types';
 | 
					import {PolymerDomRepeatEvent} from '../../../types/types';
 | 
				
			||||||
import {RepoDetailView} from '../../core/gr-navigation/gr-navigation';
 | 
					import {RepoDetailView} from '../../core/gr-navigation/gr-navigation';
 | 
				
			||||||
 | 
					import {firePageError} from '../../../utils/event-util';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
const PGP_START = '-----BEGIN PGP SIGNATURE-----';
 | 
					const PGP_START = '-----BEGIN PGP SIGNATURE-----';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -181,15 +182,8 @@ export class GrRepoDetailList extends ListViewMixin(
 | 
				
			|||||||
    this._loading = true;
 | 
					    this._loading = true;
 | 
				
			||||||
    this._items = [];
 | 
					    this._items = [];
 | 
				
			||||||
    flush();
 | 
					    flush();
 | 
				
			||||||
    const errFn: ErrorCallback = response => {
 | 
					    const errFn: ErrorCallback = response => firePageError(this, response);
 | 
				
			||||||
      this.dispatchEvent(
 | 
					
 | 
				
			||||||
        new CustomEvent('page-error', {
 | 
					 | 
				
			||||||
          detail: {response},
 | 
					 | 
				
			||||||
          composed: true,
 | 
					 | 
				
			||||||
          bubbles: true,
 | 
					 | 
				
			||||||
        })
 | 
					 | 
				
			||||||
      );
 | 
					 | 
				
			||||||
    };
 | 
					 | 
				
			||||||
    if (detailType === RepoDetailView.BRANCHES) {
 | 
					    if (detailType === RepoDetailView.BRANCHES) {
 | 
				
			||||||
      return this.$.restAPI
 | 
					      return this.$.restAPI
 | 
				
			||||||
        .getRepoBranches(filter, repo, itemsPerPage, offset, errFn)
 | 
					        .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 {ProjectState} from '../../../constants/constants';
 | 
				
			||||||
import {PolymerDeepPropertyChange} from '@polymer/polymer/interfaces';
 | 
					import {PolymerDeepPropertyChange} from '@polymer/polymer/interfaces';
 | 
				
			||||||
import {hasOwnProperty} from '../../../utils/common-util';
 | 
					import {hasOwnProperty} from '../../../utils/common-util';
 | 
				
			||||||
 | 
					import {firePageError} from '../../../utils/event-util';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
const STATES = {
 | 
					const STATES = {
 | 
				
			||||||
  active: {value: ProjectState.ACTIVE, label: 'Active'},
 | 
					  active: {value: ProjectState.ACTIVE, label: 'Active'},
 | 
				
			||||||
@@ -181,15 +182,7 @@ export class GrRepo extends GestureEventListeners(
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    const promises = [];
 | 
					    const promises = [];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    const errFn: ErrorCallback = response => {
 | 
					    const errFn: ErrorCallback = response => firePageError(this, response);
 | 
				
			||||||
      this.dispatchEvent(
 | 
					 | 
				
			||||||
        new CustomEvent('page-error', {
 | 
					 | 
				
			||||||
          detail: {response},
 | 
					 | 
				
			||||||
          composed: true,
 | 
					 | 
				
			||||||
          bubbles: true,
 | 
					 | 
				
			||||||
        })
 | 
					 | 
				
			||||||
      );
 | 
					 | 
				
			||||||
    };
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
    promises.push(
 | 
					    promises.push(
 | 
				
			||||||
      this._getLoggedIn().then(loggedIn => {
 | 
					      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 {ChangeListToggleReviewedDetail} from '../gr-change-list-item/gr-change-list-item';
 | 
				
			||||||
import {ChangeStarToggleStarDetail} from '../../shared/gr-change-star/gr-change-star';
 | 
					import {ChangeStarToggleStarDetail} from '../../shared/gr-change-star/gr-change-star';
 | 
				
			||||||
import {DashboardViewState} from '../../../types/types';
 | 
					import {DashboardViewState} from '../../../types/types';
 | 
				
			||||||
 | 
					import {firePageError} from '../../../utils/event-util';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
const PROJECT_PLACEHOLDER_PATTERN = /\$\{project\}/g;
 | 
					const PROJECT_PLACEHOLDER_PATTERN = /\$\{project\}/g;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -149,15 +150,7 @@ export class GrDashboardView extends GestureEventListeners(
 | 
				
			|||||||
    project: RepoName,
 | 
					    project: RepoName,
 | 
				
			||||||
    dashboard: DashboardId
 | 
					    dashboard: DashboardId
 | 
				
			||||||
  ): Promise<UserDashboard | undefined> {
 | 
					  ): Promise<UserDashboard | undefined> {
 | 
				
			||||||
    const errFn = (response?: Response | null) => {
 | 
					    const errFn = (response?: Response | null) => firePageError(this, response);
 | 
				
			||||||
      this.dispatchEvent(
 | 
					 | 
				
			||||||
        new CustomEvent('page-error', {
 | 
					 | 
				
			||||||
          detail: {response},
 | 
					 | 
				
			||||||
          composed: true,
 | 
					 | 
				
			||||||
          bubbles: true,
 | 
					 | 
				
			||||||
        })
 | 
					 | 
				
			||||||
      );
 | 
					 | 
				
			||||||
    };
 | 
					 | 
				
			||||||
    return this.$.restAPI
 | 
					    return this.$.restAPI
 | 
				
			||||||
      .getDashboard(project, dashboard, errFn)
 | 
					      .getDashboard(project, dashboard, errFn)
 | 
				
			||||||
      .then(response => {
 | 
					      .then(response => {
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -113,7 +113,7 @@ import {
 | 
				
			|||||||
  RevisionActions,
 | 
					  RevisionActions,
 | 
				
			||||||
  UIActionInfo,
 | 
					  UIActionInfo,
 | 
				
			||||||
} from '../../shared/gr-js-api-interface/gr-change-actions-js-api';
 | 
					} 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_BRANCH_EMPTY = 'The destination branch can’t be empty.';
 | 
				
			||||||
const ERR_COMMIT_EMPTY = 'The commit message can’t be empty.';
 | 
					const ERR_COMMIT_EMPTY = 'The commit message can’t be empty.';
 | 
				
			||||||
@@ -613,7 +613,7 @@ export class GrChangeActions
 | 
				
			|||||||
        this._handleLoadingComplete();
 | 
					        this._handleLoadingComplete();
 | 
				
			||||||
      })
 | 
					      })
 | 
				
			||||||
      .catch(err => {
 | 
					      .catch(err => {
 | 
				
			||||||
        fire(this, EventType.SHOW_ALERT, ERR_REVISION_ACTIONS);
 | 
					        fireAlert(this, ERR_REVISION_ACTIONS);
 | 
				
			||||||
        this._loading = false;
 | 
					        this._loading = false;
 | 
				
			||||||
        throw err;
 | 
					        throw err;
 | 
				
			||||||
      });
 | 
					      });
 | 
				
			||||||
@@ -1368,11 +1368,11 @@ export class GrChangeActions
 | 
				
			|||||||
  _handleCherryPickRestApi(conflicts: boolean) {
 | 
					  _handleCherryPickRestApi(conflicts: boolean) {
 | 
				
			||||||
    const el = this.$.confirmCherrypick;
 | 
					    const el = this.$.confirmCherrypick;
 | 
				
			||||||
    if (!el.branch) {
 | 
					    if (!el.branch) {
 | 
				
			||||||
      fire(this, EventType.SHOW_ALERT, ERR_BRANCH_EMPTY);
 | 
					      fireAlert(this, ERR_BRANCH_EMPTY);
 | 
				
			||||||
      return;
 | 
					      return;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    if (!el.message) {
 | 
					    if (!el.message) {
 | 
				
			||||||
      fire(this, EventType.SHOW_ALERT, ERR_COMMIT_EMPTY);
 | 
					      fireAlert(this, ERR_COMMIT_EMPTY);
 | 
				
			||||||
      return;
 | 
					      return;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    this.$.overlay.close();
 | 
					    this.$.overlay.close();
 | 
				
			||||||
@@ -1393,7 +1393,7 @@ export class GrChangeActions
 | 
				
			|||||||
  _handleMoveConfirm() {
 | 
					  _handleMoveConfirm() {
 | 
				
			||||||
    const el = this.$.confirmMove;
 | 
					    const el = this.$.confirmMove;
 | 
				
			||||||
    if (!el.branch) {
 | 
					    if (!el.branch) {
 | 
				
			||||||
      fire(this, EventType.SHOW_ALERT, ERR_BRANCH_EMPTY);
 | 
					      fireAlert(this, ERR_BRANCH_EMPTY);
 | 
				
			||||||
      return;
 | 
					      return;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    this.$.overlay.close();
 | 
					    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 {GrMessagesList} from '../gr-messages-list/gr-messages-list';
 | 
				
			||||||
import {GrThreadList} from '../gr-thread-list/gr-thread-list';
 | 
					import {GrThreadList} from '../gr-thread-list/gr-thread-list';
 | 
				
			||||||
import {PORTING_COMMENTS_CHANGE_LATENCY_LABEL} from '../../../services/gr-reporting/gr-reporting';
 | 
					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 {KnownExperimentId} from '../../../services/flags/flags';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
const CHANGE_ID_ERROR = {
 | 
					const CHANGE_ID_ERROR = {
 | 
				
			||||||
@@ -1669,7 +1669,7 @@ export class GrChangeView extends KeyboardShortcutMixin(
 | 
				
			|||||||
    if (!this._patchRange)
 | 
					    if (!this._patchRange)
 | 
				
			||||||
      throw new Error('missing required _patchRange property');
 | 
					      throw new Error('missing required _patchRange property');
 | 
				
			||||||
    if (patchNumEquals(this._patchRange.basePatchNum, ParentPatchSetNum)) {
 | 
					    if (patchNumEquals(this._patchRange.basePatchNum, ParentPatchSetNum)) {
 | 
				
			||||||
      fire(this, EventType.SHOW_ALERT, 'Base is already selected.');
 | 
					      fireAlert(this, 'Base is already selected.');
 | 
				
			||||||
      return;
 | 
					      return;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    GerritNav.navigateToChange(this._change, this._patchRange.patchNum);
 | 
					    GerritNav.navigateToChange(this._change, this._patchRange.patchNum);
 | 
				
			||||||
@@ -1683,7 +1683,7 @@ export class GrChangeView extends KeyboardShortcutMixin(
 | 
				
			|||||||
    if (!this._patchRange)
 | 
					    if (!this._patchRange)
 | 
				
			||||||
      throw new Error('missing required _patchRange property');
 | 
					      throw new Error('missing required _patchRange property');
 | 
				
			||||||
    if (patchNumEquals(this._patchRange.basePatchNum, ParentPatchSetNum)) {
 | 
					    if (patchNumEquals(this._patchRange.basePatchNum, ParentPatchSetNum)) {
 | 
				
			||||||
      fire(this, EventType.SHOW_ALERT, 'Left is already base.');
 | 
					      fireAlert(this, 'Left is already base.');
 | 
				
			||||||
      return;
 | 
					      return;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    GerritNav.navigateToChange(this._change, this._patchRange.basePatchNum);
 | 
					    GerritNav.navigateToChange(this._change, this._patchRange.basePatchNum);
 | 
				
			||||||
@@ -1726,7 +1726,7 @@ export class GrChangeView extends KeyboardShortcutMixin(
 | 
				
			|||||||
    if (!this._patchRange)
 | 
					    if (!this._patchRange)
 | 
				
			||||||
      throw new Error('missing required _patchRange property');
 | 
					      throw new Error('missing required _patchRange property');
 | 
				
			||||||
    if (patchNumEquals(this._patchRange.patchNum, latestPatchNum)) {
 | 
					    if (patchNumEquals(this._patchRange.patchNum, latestPatchNum)) {
 | 
				
			||||||
      fire(this, EventType.SHOW_ALERT, 'Right is already latest.');
 | 
					      fireAlert(this, 'Right is already latest.');
 | 
				
			||||||
      return;
 | 
					      return;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    GerritNav.navigateToChange(
 | 
					    GerritNav.navigateToChange(
 | 
				
			||||||
@@ -1748,7 +1748,7 @@ export class GrChangeView extends KeyboardShortcutMixin(
 | 
				
			|||||||
      patchNumEquals(this._patchRange.patchNum, latestPatchNum) &&
 | 
					      patchNumEquals(this._patchRange.patchNum, latestPatchNum) &&
 | 
				
			||||||
      patchNumEquals(this._patchRange.basePatchNum, ParentPatchSetNum)
 | 
					      patchNumEquals(this._patchRange.basePatchNum, ParentPatchSetNum)
 | 
				
			||||||
    ) {
 | 
					    ) {
 | 
				
			||||||
      fire(this, EventType.SHOW_ALERT, 'Already diffing base against latest.');
 | 
					      fireAlert(this, 'Already diffing base against latest.');
 | 
				
			||||||
      return;
 | 
					      return;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    GerritNav.navigateToChange(this._change, latestPatchNum);
 | 
					    GerritNav.navigateToChange(this._change, latestPatchNum);
 | 
				
			||||||
@@ -1872,13 +1872,7 @@ export class GrChangeView extends KeyboardShortcutMixin(
 | 
				
			|||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  _handleGetChangeDetailError(response?: Response | null) {
 | 
					  _handleGetChangeDetailError(response?: Response | null) {
 | 
				
			||||||
    this.dispatchEvent(
 | 
					    firePageError(this, response);
 | 
				
			||||||
      new CustomEvent('page-error', {
 | 
					 | 
				
			||||||
        detail: {response},
 | 
					 | 
				
			||||||
        composed: true,
 | 
					 | 
				
			||||||
        bubbles: true,
 | 
					 | 
				
			||||||
      })
 | 
					 | 
				
			||||||
    );
 | 
					 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  _getLoggedIn() {
 | 
					  _getLoggedIn() {
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -25,7 +25,7 @@ import {htmlTemplate} from './gr-confirm-revert-dialog_html';
 | 
				
			|||||||
import {customElement, property} from '@polymer/decorators';
 | 
					import {customElement, property} from '@polymer/decorators';
 | 
				
			||||||
import {JsApiService} from '../../shared/gr-js-api-interface/gr-js-api-types';
 | 
					import {JsApiService} from '../../shared/gr-js-api-interface/gr-js-api-types';
 | 
				
			||||||
import {ChangeInfo, CommitId} from '../../../types/common';
 | 
					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 ERR_COMMIT_NOT_FOUND = 'Unable to find the commit hash of this change.';
 | 
				
			||||||
const CHANGE_SUBJECT_LIMIT = 50;
 | 
					const CHANGE_SUBJECT_LIMIT = 50;
 | 
				
			||||||
@@ -125,7 +125,7 @@ export class GrConfirmRevertDialog extends GestureEventListeners(
 | 
				
			|||||||
    const originalTitle = (commitMessage || '').split('\n')[0];
 | 
					    const originalTitle = (commitMessage || '').split('\n')[0];
 | 
				
			||||||
    const revertTitle = `Revert "${originalTitle}"`;
 | 
					    const revertTitle = `Revert "${originalTitle}"`;
 | 
				
			||||||
    if (!commitHash) {
 | 
					    if (!commitHash) {
 | 
				
			||||||
      fire(this, EventType.SHOW_ALERT, ERR_COMMIT_NOT_FOUND);
 | 
					      fireAlert(this, ERR_COMMIT_NOT_FOUND);
 | 
				
			||||||
      return;
 | 
					      return;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    const revertCommitText = `This reverts commit ${commitHash}.`;
 | 
					    const revertCommitText = `This reverts commit ${commitHash}.`;
 | 
				
			||||||
@@ -163,7 +163,7 @@ export class GrConfirmRevertDialog extends GestureEventListeners(
 | 
				
			|||||||
    // Follow the same convention of the revert
 | 
					    // Follow the same convention of the revert
 | 
				
			||||||
    const commitHash = change.current_revision;
 | 
					    const commitHash = change.current_revision;
 | 
				
			||||||
    if (!commitHash) {
 | 
					    if (!commitHash) {
 | 
				
			||||||
      fire(this, EventType.SHOW_ALERT, ERR_COMMIT_NOT_FOUND);
 | 
					      fireAlert(this, ERR_COMMIT_NOT_FOUND);
 | 
				
			||||||
      return;
 | 
					      return;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    if (!changes || changes.length <= 1) 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 {customElement, property} from '@polymer/decorators';
 | 
				
			||||||
import {JsApiService} from '../../shared/gr-js-api-interface/gr-js-api-types';
 | 
					import {JsApiService} from '../../shared/gr-js-api-interface/gr-js-api-types';
 | 
				
			||||||
import {ChangeInfo} from '../../../types/common';
 | 
					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 ERR_COMMIT_NOT_FOUND = 'Unable to find the commit hash of this change.';
 | 
				
			||||||
const CHANGE_SUBJECT_LIMIT = 50;
 | 
					const CHANGE_SUBJECT_LIMIT = 50;
 | 
				
			||||||
@@ -87,7 +87,7 @@ export class GrConfirmRevertSubmissionDialog extends GestureEventListeners(
 | 
				
			|||||||
    // Follow the same convention of the revert
 | 
					    // Follow the same convention of the revert
 | 
				
			||||||
    const commitHash = change.current_revision;
 | 
					    const commitHash = change.current_revision;
 | 
				
			||||||
    if (!commitHash) {
 | 
					    if (!commitHash) {
 | 
				
			||||||
      fire(this, EventType.SHOW_ALERT, ERR_COMMIT_NOT_FOUND);
 | 
					      fireAlert(this, ERR_COMMIT_NOT_FOUND);
 | 
				
			||||||
      return;
 | 
					      return;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    const revertTitle = `Revert submission ${change.submission_id}`;
 | 
					    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 {isAttentionSetEnabled} from '../../../utils/attention-set-util';
 | 
				
			||||||
import {CODE_REVIEW, getMaxAccounts} from '../../../utils/label-util';
 | 
					import {CODE_REVIEW, getMaxAccounts} from '../../../utils/label-util';
 | 
				
			||||||
import {isUnresolved} from '../../../utils/comment-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;
 | 
					const STORAGE_DEBOUNCE_INTERVAL_MS = 400;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -549,7 +549,7 @@ export class GrReplyDialog extends KeyboardShortcutMixin(
 | 
				
			|||||||
            const moveTo = isReviewer ? 'reviewer' : 'CC';
 | 
					            const moveTo = isReviewer ? 'reviewer' : 'CC';
 | 
				
			||||||
            const id = account.name || account.email || key;
 | 
					            const id = account.name || account.email || key;
 | 
				
			||||||
            const message = `${id} moved from ${moveFrom} to ${moveTo}.`;
 | 
					            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;
 | 
					      return;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    if (this._sendDisabled) {
 | 
					    if (this._sendDisabled) {
 | 
				
			||||||
      fire(this, EventType.SHOW_ALERT, EMPTY_REPLY_MESSAGE);
 | 
					      fireAlert(this, EMPTY_REPLY_MESSAGE);
 | 
				
			||||||
      return;
 | 
					      return;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    return this.send(this._includeComments, this.canBeStarted)
 | 
					    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 {GrDiffGroup} from '../gr-diff/gr-diff-group';
 | 
				
			||||||
import {PolymerSpliceChange} from '@polymer/polymer/interfaces';
 | 
					import {PolymerSpliceChange} from '@polymer/polymer/interfaces';
 | 
				
			||||||
import {getLineNumber} from '../gr-diff/gr-diff-utils';
 | 
					import {getLineNumber} from '../gr-diff/gr-diff-utils';
 | 
				
			||||||
import {fire, EventType} from '../../../utils/event-util';
 | 
					import {fireAlert} from '../../../utils/event-util';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
const DiffViewMode = {
 | 
					const DiffViewMode = {
 | 
				
			||||||
  SIDE_BY_SIDE: 'SIDE_BY_SIDE',
 | 
					  SIDE_BY_SIDE: 'SIDE_BY_SIDE',
 | 
				
			||||||
@@ -360,7 +360,7 @@ export class GrDiffBuilderElement extends GestureEventListeners(
 | 
				
			|||||||
    const message =
 | 
					    const message =
 | 
				
			||||||
      `The value of the '${pref}' user preference is ` +
 | 
					      `The value of the '${pref}' user preference is ` +
 | 
				
			||||||
      'invalid. Fix in diff preferences';
 | 
					      'invalid. Fix in diff preferences';
 | 
				
			||||||
    fire(this, EventType.SHOW_ALERT, message);
 | 
					    fireAlert(this, message);
 | 
				
			||||||
    throw Error(`Invalid preference value: ${pref}`);
 | 
					    throw Error(`Invalid preference value: ${pref}`);
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -36,7 +36,7 @@ import {PolymerSpliceChange} from '@polymer/polymer/interfaces';
 | 
				
			|||||||
import {PolymerDomWrapper} from '../../../types/types';
 | 
					import {PolymerDomWrapper} from '../../../types/types';
 | 
				
			||||||
import {GrDiffGroupType} from '../gr-diff/gr-diff-group';
 | 
					import {GrDiffGroupType} from '../gr-diff/gr-diff-group';
 | 
				
			||||||
import {GrDiff} from '../gr-diff/gr-diff';
 | 
					import {GrDiff} from '../gr-diff/gr-diff';
 | 
				
			||||||
import {fire, EventType} from '../../../utils/event-util';
 | 
					import {fireAlert} from '../../../utils/event-util';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
const DiffViewMode = {
 | 
					const DiffViewMode = {
 | 
				
			||||||
  SIDE_BY_SIDE: 'SIDE_BY_SIDE',
 | 
					  SIDE_BY_SIDE: 'SIDE_BY_SIDE',
 | 
				
			||||||
@@ -228,11 +228,7 @@ export class GrDiffCursor extends GestureEventListeners(
 | 
				
			|||||||
        );
 | 
					        );
 | 
				
			||||||
      }
 | 
					      }
 | 
				
			||||||
      this.lastDisplayedNavigateToNextFileToast = Date.now();
 | 
					      this.lastDisplayedNavigateToNextFileToast = Date.now();
 | 
				
			||||||
      fire(
 | 
					      fireAlert(this, 'Press n again to navigate to next unreviewed file');
 | 
				
			||||||
        this,
 | 
					 | 
				
			||||||
        EventType.SHOW_ALERT,
 | 
					 | 
				
			||||||
        'Press n again to navigate to next unreviewed file'
 | 
					 | 
				
			||||||
      );
 | 
					 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    this._fixSide();
 | 
					    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 {LineNumber, FILE} from '../gr-diff/gr-diff-line';
 | 
				
			||||||
import {GrCommentThread} from '../../shared/gr-comment-thread/gr-comment-thread';
 | 
					import {GrCommentThread} from '../../shared/gr-comment-thread/gr-comment-thread';
 | 
				
			||||||
import {KnownExperimentId} from '../../../services/flags/flags';
 | 
					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.';
 | 
					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)
 | 
					      .getBlame(this.changeNum, this.patchRange.patchNum, this.path, true)
 | 
				
			||||||
      .then(blame => {
 | 
					      .then(blame => {
 | 
				
			||||||
        if (!blame || !blame.length) {
 | 
					        if (!blame || !blame.length) {
 | 
				
			||||||
          fire(this, EventType.SHOW_ALERT, MSG_EMPTY_BLAME);
 | 
					          fireAlert(this, MSG_EMPTY_BLAME);
 | 
				
			||||||
          return Promise.reject(MSG_EMPTY_BLAME);
 | 
					          return Promise.reject(MSG_EMPTY_BLAME);
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -612,13 +612,7 @@ export class GrDiffHost extends GestureEventListeners(
 | 
				
			|||||||
      return;
 | 
					      return;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    this.dispatchEvent(
 | 
					    firePageError(this, response);
 | 
				
			||||||
      new CustomEvent('page-error', {
 | 
					 | 
				
			||||||
        detail: {response},
 | 
					 | 
				
			||||||
        composed: true,
 | 
					 | 
				
			||||||
        bubbles: true,
 | 
					 | 
				
			||||||
      })
 | 
					 | 
				
			||||||
    );
 | 
					 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  /**
 | 
					  /**
 | 
				
			||||||
@@ -1022,18 +1016,16 @@ export class GrDiffHost extends GestureEventListeners(
 | 
				
			|||||||
      return false;
 | 
					      return false;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    if (this._anyLineTooLong(diff)) {
 | 
					    if (this._anyLineTooLong(diff)) {
 | 
				
			||||||
      fire(
 | 
					      fireAlert(
 | 
				
			||||||
        this,
 | 
					        this,
 | 
				
			||||||
        EventType.SHOW_ALERT,
 | 
					 | 
				
			||||||
        `A line is longer than ${SYNTAX_MAX_LINE_LENGTH}.` +
 | 
					        `A line is longer than ${SYNTAX_MAX_LINE_LENGTH}.` +
 | 
				
			||||||
          ' Syntax Highlighting was turned off.'
 | 
					          ' Syntax Highlighting was turned off.'
 | 
				
			||||||
      );
 | 
					      );
 | 
				
			||||||
      return false;
 | 
					      return false;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    if (this.$.diff.getDiffLength(diff) > SYNTAX_MAX_DIFF_LENGTH) {
 | 
					    if (this.$.diff.getDiffLength(diff) > SYNTAX_MAX_DIFF_LENGTH) {
 | 
				
			||||||
      fire(
 | 
					      fireAlert(
 | 
				
			||||||
        this,
 | 
					        this,
 | 
				
			||||||
        EventType.SHOW_ALERT,
 | 
					 | 
				
			||||||
        `A diff is longer than ${SYNTAX_MAX_DIFF_LENGTH}.` +
 | 
					        `A diff is longer than ${SYNTAX_MAX_DIFF_LENGTH}.` +
 | 
				
			||||||
          ' Syntax Highlighting was turned off.'
 | 
					          ' Syntax Highlighting was turned off.'
 | 
				
			||||||
      );
 | 
					      );
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -101,7 +101,7 @@ import {CommentMap} from '../../../utils/comment-util';
 | 
				
			|||||||
import {AppElementParams} from '../../gr-app-types';
 | 
					import {AppElementParams} from '../../gr-app-types';
 | 
				
			||||||
import {CustomKeyboardEvent, OpenFixPreviewEvent} from '../../../types/events';
 | 
					import {CustomKeyboardEvent, OpenFixPreviewEvent} from '../../../types/events';
 | 
				
			||||||
import {PORTING_COMMENTS_DIFF_LATENCY_LABEL} from '../../../services/gr-reporting/gr-reporting';
 | 
					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 ERR_REVIEW_STATUS = 'Couldn’t change file review status.';
 | 
				
			||||||
const MSG_LOADING_BLAME = 'Loading blame...';
 | 
					const MSG_LOADING_BLAME = 'Loading blame...';
 | 
				
			||||||
@@ -458,7 +458,7 @@ export class GrDiffView extends KeyboardShortcutMixin(
 | 
				
			|||||||
    this.$.reviewed.checked = reviewed;
 | 
					    this.$.reviewed.checked = reviewed;
 | 
				
			||||||
    if (!this._patchRange?.patchNum) return;
 | 
					    if (!this._patchRange?.patchNum) return;
 | 
				
			||||||
    this._saveReviewedState(reviewed).catch(err => {
 | 
					    this._saveReviewedState(reviewed).catch(err => {
 | 
				
			||||||
      fire(this, EventType.SHOW_ALERT, ERR_REVIEW_STATUS);
 | 
					      fireAlert(this, ERR_REVIEW_STATUS);
 | 
				
			||||||
      throw err;
 | 
					      throw err;
 | 
				
			||||||
    });
 | 
					    });
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
@@ -876,9 +876,8 @@ export class GrDiffView extends KeyboardShortcutMixin(
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
  _displayDiffBaseAgainstLeftToast() {
 | 
					  _displayDiffBaseAgainstLeftToast() {
 | 
				
			||||||
    if (!this._patchRange) return;
 | 
					    if (!this._patchRange) return;
 | 
				
			||||||
    fire(
 | 
					    fireAlert(
 | 
				
			||||||
      this,
 | 
					      this,
 | 
				
			||||||
      EventType.SHOW_ALERT,
 | 
					 | 
				
			||||||
      `Patchset ${this._patchRange.basePatchNum} vs ` +
 | 
					      `Patchset ${this._patchRange.basePatchNum} vs ` +
 | 
				
			||||||
        `${this._patchRange.patchNum} selected. Press v + \u2190 to view ` +
 | 
					        `${this._patchRange.patchNum} selected. Press v + \u2190 to view ` +
 | 
				
			||||||
        `Base vs ${this._patchRange.basePatchNum}`
 | 
					        `Base vs ${this._patchRange.basePatchNum}`
 | 
				
			||||||
@@ -893,9 +892,8 @@ export class GrDiffView extends KeyboardShortcutMixin(
 | 
				
			|||||||
    )
 | 
					    )
 | 
				
			||||||
      ? 'Base'
 | 
					      ? 'Base'
 | 
				
			||||||
      : `Patchset ${this._patchRange.basePatchNum}`;
 | 
					      : `Patchset ${this._patchRange.basePatchNum}`;
 | 
				
			||||||
    fire(
 | 
					    fireAlert(
 | 
				
			||||||
      this,
 | 
					      this,
 | 
				
			||||||
      EventType.SHOW_ALERT,
 | 
					 | 
				
			||||||
      `${leftPatchset} vs
 | 
					      `${leftPatchset} vs
 | 
				
			||||||
            ${this._patchRange.patchNum} selected\n. Press v + \u2191 to view
 | 
					            ${this._patchRange.patchNum} selected\n. Press v + \u2191 to view
 | 
				
			||||||
            ${leftPatchset} vs Patchset ${latestPatchNum}`
 | 
					            ${leftPatchset} vs Patchset ${latestPatchNum}`
 | 
				
			||||||
@@ -967,7 +965,7 @@ export class GrDiffView extends KeyboardShortcutMixin(
 | 
				
			|||||||
        this.params.commentId
 | 
					        this.params.commentId
 | 
				
			||||||
      );
 | 
					      );
 | 
				
			||||||
      if (!comment) {
 | 
					      if (!comment) {
 | 
				
			||||||
        fire(this, EventType.SHOW_ALERT, 'comment not found');
 | 
					        fireAlert(this, 'comment not found');
 | 
				
			||||||
        GerritNav.navigateToChange(this._change);
 | 
					        GerritNav.navigateToChange(this._change);
 | 
				
			||||||
        return;
 | 
					        return;
 | 
				
			||||||
      }
 | 
					      }
 | 
				
			||||||
@@ -1122,9 +1120,8 @@ export class GrDiffView extends KeyboardShortcutMixin(
 | 
				
			|||||||
            return;
 | 
					            return;
 | 
				
			||||||
          }
 | 
					          }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
          fire(
 | 
					          fireAlert(
 | 
				
			||||||
            this,
 | 
					            this,
 | 
				
			||||||
            EventType.SHOW_ALERT,
 | 
					 | 
				
			||||||
            `File is unchanged between Patchset
 | 
					            `File is unchanged between Patchset
 | 
				
			||||||
                  ${this._patchRange.basePatchNum} and
 | 
					                  ${this._patchRange.basePatchNum} and
 | 
				
			||||||
                  ${this._patchRange.patchNum}. Showing diff of Base vs
 | 
					                  ${this._patchRange.patchNum}. Showing diff of Base vs
 | 
				
			||||||
@@ -1672,12 +1669,12 @@ export class GrDiffView extends KeyboardShortcutMixin(
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
  _loadBlame() {
 | 
					  _loadBlame() {
 | 
				
			||||||
    this._isBlameLoading = true;
 | 
					    this._isBlameLoading = true;
 | 
				
			||||||
    fire(this, EventType.SHOW_ALERT, MSG_LOADING_BLAME);
 | 
					    fireAlert(this, MSG_LOADING_BLAME);
 | 
				
			||||||
    this.$.diffHost
 | 
					    this.$.diffHost
 | 
				
			||||||
      .loadBlame()
 | 
					      .loadBlame()
 | 
				
			||||||
      .then(() => {
 | 
					      .then(() => {
 | 
				
			||||||
        this._isBlameLoading = false;
 | 
					        this._isBlameLoading = false;
 | 
				
			||||||
        fire(this, EventType.SHOW_ALERT, MSG_LOADED_BLAME);
 | 
					        fireAlert(this, MSG_LOADED_BLAME);
 | 
				
			||||||
      })
 | 
					      })
 | 
				
			||||||
      .catch(() => {
 | 
					      .catch(() => {
 | 
				
			||||||
        this._isBlameLoading = false;
 | 
					        this._isBlameLoading = false;
 | 
				
			||||||
@@ -1723,7 +1720,7 @@ export class GrDiffView extends KeyboardShortcutMixin(
 | 
				
			|||||||
    if (!this._patchRange) return;
 | 
					    if (!this._patchRange) return;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if (patchNumEquals(this._patchRange.basePatchNum, ParentPatchSetNum)) {
 | 
					    if (patchNumEquals(this._patchRange.basePatchNum, ParentPatchSetNum)) {
 | 
				
			||||||
      fire(this, EventType.SHOW_ALERT, 'Base is already selected.');
 | 
					      fireAlert(this, 'Base is already selected.');
 | 
				
			||||||
      return;
 | 
					      return;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    GerritNav.navigateToDiff(
 | 
					    GerritNav.navigateToDiff(
 | 
				
			||||||
@@ -1740,7 +1737,7 @@ export class GrDiffView extends KeyboardShortcutMixin(
 | 
				
			|||||||
    if (!this._patchRange) return;
 | 
					    if (!this._patchRange) return;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if (patchNumEquals(this._patchRange.basePatchNum, ParentPatchSetNum)) {
 | 
					    if (patchNumEquals(this._patchRange.basePatchNum, ParentPatchSetNum)) {
 | 
				
			||||||
      fire(this, EventType.SHOW_ALERT, 'Left is already base.');
 | 
					      fireAlert(this, 'Left is already base.');
 | 
				
			||||||
      return;
 | 
					      return;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    GerritNav.navigateToDiff(
 | 
					    GerritNav.navigateToDiff(
 | 
				
			||||||
@@ -1762,7 +1759,7 @@ export class GrDiffView extends KeyboardShortcutMixin(
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    const latestPatchNum = computeLatestPatchNum(this._allPatchSets);
 | 
					    const latestPatchNum = computeLatestPatchNum(this._allPatchSets);
 | 
				
			||||||
    if (patchNumEquals(this._patchRange.patchNum, latestPatchNum)) {
 | 
					    if (patchNumEquals(this._patchRange.patchNum, latestPatchNum)) {
 | 
				
			||||||
      fire(this, EventType.SHOW_ALERT, 'Latest is already selected.');
 | 
					      fireAlert(this, 'Latest is already selected.');
 | 
				
			||||||
      return;
 | 
					      return;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -1782,7 +1779,7 @@ export class GrDiffView extends KeyboardShortcutMixin(
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    const latestPatchNum = computeLatestPatchNum(this._allPatchSets);
 | 
					    const latestPatchNum = computeLatestPatchNum(this._allPatchSets);
 | 
				
			||||||
    if (patchNumEquals(this._patchRange.patchNum, latestPatchNum)) {
 | 
					    if (patchNumEquals(this._patchRange.patchNum, latestPatchNum)) {
 | 
				
			||||||
      fire(this, EventType.SHOW_ALERT, 'Right is already latest.');
 | 
					      fireAlert(this, 'Right is already latest.');
 | 
				
			||||||
      return;
 | 
					      return;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    GerritNav.navigateToDiff(
 | 
					    GerritNav.navigateToDiff(
 | 
				
			||||||
@@ -1804,7 +1801,7 @@ export class GrDiffView extends KeyboardShortcutMixin(
 | 
				
			|||||||
      patchNumEquals(this._patchRange.patchNum, latestPatchNum) &&
 | 
					      patchNumEquals(this._patchRange.patchNum, latestPatchNum) &&
 | 
				
			||||||
      patchNumEquals(this._patchRange.basePatchNum, ParentPatchSetNum)
 | 
					      patchNumEquals(this._patchRange.basePatchNum, ParentPatchSetNum)
 | 
				
			||||||
    ) {
 | 
					    ) {
 | 
				
			||||||
      fire(this, EventType.SHOW_ALERT, 'Already diffing base against latest.');
 | 
					      fireAlert(this, 'Already diffing base against latest.');
 | 
				
			||||||
      return;
 | 
					      return;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    GerritNav.navigateToDiff(this._change, this._path, latestPatchNum);
 | 
					    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 {FlattenedNodesObserver} from '@polymer/polymer/lib/utils/flattened-nodes-observer';
 | 
				
			||||||
import {PolymerDeepPropertyChange} from '@polymer/polymer/interfaces';
 | 
					import {PolymerDeepPropertyChange} from '@polymer/polymer/interfaces';
 | 
				
			||||||
import {AbortStop} from '../../shared/gr-cursor-manager/gr-cursor-manager';
 | 
					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_BASE = 'No newline at end of base file.';
 | 
				
			||||||
const NO_NEWLINE_REVISION = 'No newline at end of revision 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);
 | 
					    const lineNum = getLineNumber(el);
 | 
				
			||||||
    if (lineNum === null) {
 | 
					    if (lineNum === null) {
 | 
				
			||||||
      fire(this, EventType.SHOW_ALERT, 'Invalid line number');
 | 
					      fireAlert(this, 'Invalid line number');
 | 
				
			||||||
      return;
 | 
					      return;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -613,11 +613,7 @@ export class GrDiff extends GestureEventListeners(
 | 
				
			|||||||
      return false;
 | 
					      return false;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    if (!this.patchRange) {
 | 
					    if (!this.patchRange) {
 | 
				
			||||||
      fire(
 | 
					      fireAlert(this, 'Cannot create comment. Patch range undefined.');
 | 
				
			||||||
        this,
 | 
					 | 
				
			||||||
        EventType.SHOW_ALERT,
 | 
					 | 
				
			||||||
        'Cannot create comment. Patch range undefined.'
 | 
					 | 
				
			||||||
      );
 | 
					 | 
				
			||||||
      return false;
 | 
					      return false;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    const patchNum = el.classList.contains(Side.LEFT)
 | 
					    const patchNum = el.classList.contains(Side.LEFT)
 | 
				
			||||||
@@ -630,15 +626,11 @@ export class GrDiff extends GestureEventListeners(
 | 
				
			|||||||
      patchNumEquals(this.patchRange.patchNum, EditPatchSetNum);
 | 
					      patchNumEquals(this.patchRange.patchNum, EditPatchSetNum);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if (isEdit) {
 | 
					    if (isEdit) {
 | 
				
			||||||
      fire(this, EventType.SHOW_ALERT, 'You cannot comment on an edit.');
 | 
					      fireAlert(this, 'You cannot comment on an edit.');
 | 
				
			||||||
      return false;
 | 
					      return false;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    if (isEditBase) {
 | 
					    if (isEditBase) {
 | 
				
			||||||
      fire(
 | 
					      fireAlert(this, 'You cannot comment on the base patchset of an edit.');
 | 
				
			||||||
        this,
 | 
					 | 
				
			||||||
        EventType.SHOW_ALERT,
 | 
					 | 
				
			||||||
        'You cannot comment on the base patchset of an edit.'
 | 
					 | 
				
			||||||
      );
 | 
					 | 
				
			||||||
      return false;
 | 
					      return false;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    return true;
 | 
					    return true;
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -47,7 +47,7 @@ import {
 | 
				
			|||||||
} from '../../../types/common';
 | 
					} from '../../../types/common';
 | 
				
			||||||
import {GrStorage} from '../../shared/gr-storage/gr-storage';
 | 
					import {GrStorage} from '../../shared/gr-storage/gr-storage';
 | 
				
			||||||
import {HttpMethod, NotifyType} from '../../../constants/constants';
 | 
					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 RESTORED_MESSAGE = 'Content restored from a previous edit.';
 | 
				
			||||||
const SAVING_MESSAGE = 'Saving changes...';
 | 
					const SAVING_MESSAGE = 'Saving changes...';
 | 
				
			||||||
@@ -256,7 +256,7 @@ export class GrEditorView extends KeyboardShortcutMixin(
 | 
				
			|||||||
          storedContent.message &&
 | 
					          storedContent.message &&
 | 
				
			||||||
          storedContent.message !== content
 | 
					          storedContent.message !== content
 | 
				
			||||||
        ) {
 | 
					        ) {
 | 
				
			||||||
          fire(this, EventType.SHOW_ALERT, RESTORED_MESSAGE);
 | 
					          fireAlert(this, RESTORED_MESSAGE);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
          this._newContent = storedContent.message;
 | 
					          this._newContent = storedContent.message;
 | 
				
			||||||
        } else {
 | 
					        } else {
 | 
				
			||||||
@@ -300,7 +300,7 @@ export class GrEditorView extends KeyboardShortcutMixin(
 | 
				
			|||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  _showAlert(message: string) {
 | 
					  _showAlert(message: string) {
 | 
				
			||||||
    fire(this, EventType.SHOW_ALERT, message);
 | 
					    fireAlert(this, message);
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  _computeSaveDisabled(
 | 
					  _computeSaveDisabled(
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -32,7 +32,7 @@ import {
 | 
				
			|||||||
  GroupInfo,
 | 
					  GroupInfo,
 | 
				
			||||||
  ContributorAgreementInfo,
 | 
					  ContributorAgreementInfo,
 | 
				
			||||||
} from '../../../types/common';
 | 
					} from '../../../types/common';
 | 
				
			||||||
import {fire, EventType} from '../../../utils/event-util';
 | 
					import {fireAlert} from '../../../utils/event-util';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
export interface GrClaView {
 | 
					export interface GrClaView {
 | 
				
			||||||
  $: {
 | 
					  $: {
 | 
				
			||||||
@@ -157,7 +157,7 @@ export class GrClaView extends GestureEventListeners(
 | 
				
			|||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  _createToast(message: string) {
 | 
					  _createToast(message: string) {
 | 
				
			||||||
    fire(this, EventType.SHOW_ALERT, message);
 | 
					    fireAlert(this, message);
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  _computeShowAgreementsClass(showAgreements: boolean) {
 | 
					  _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 {GerritView} from '../../core/gr-navigation/gr-navigation';
 | 
				
			||||||
import {GrEmailEditor} from '../gr-email-editor/gr-email-editor';
 | 
					import {GrEmailEditor} from '../gr-email-editor/gr-email-editor';
 | 
				
			||||||
import {CustomKeyboardEvent} from '../../../types/events';
 | 
					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> = [
 | 
					const PREFS_SECTION_FIELDS: Array<keyof PreferencesInput> = [
 | 
				
			||||||
  'changes_per_page',
 | 
					  'changes_per_page',
 | 
				
			||||||
@@ -287,7 +287,7 @@ export class GrSettingsView extends ChangeTableMixin(
 | 
				
			|||||||
      promises.push(
 | 
					      promises.push(
 | 
				
			||||||
        this.$.restAPI.confirmEmail(this.params.emailToken).then(message => {
 | 
					        this.$.restAPI.confirmEmail(this.params.emailToken).then(message => {
 | 
				
			||||||
          if (message) {
 | 
					          if (message) {
 | 
				
			||||||
            fire(this, EventType.SHOW_ALERT, message);
 | 
					            fireAlert(this, message);
 | 
				
			||||||
          }
 | 
					          }
 | 
				
			||||||
          this.$.emailEditor.loadData();
 | 
					          this.$.emailEditor.loadData();
 | 
				
			||||||
        })
 | 
					        })
 | 
				
			||||||
@@ -537,11 +537,7 @@ export class GrSettingsView extends ChangeTableMixin(
 | 
				
			|||||||
      applyDarkTheme();
 | 
					      applyDarkTheme();
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    this._isDark = !!window.localStorage.getItem('dark-theme');
 | 
					    this._isDark = !!window.localStorage.getItem('dark-theme');
 | 
				
			||||||
    fire(
 | 
					    fireAlert(this, `Theme changed to ${this._isDark ? 'dark' : 'light'}.`);
 | 
				
			||||||
      this,
 | 
					 | 
				
			||||||
      EventType.SHOW_ALERT,
 | 
					 | 
				
			||||||
      `Theme changed to ${this._isDark ? 'dark' : 'light'}.`
 | 
					 | 
				
			||||||
    );
 | 
					 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  _showHttpAuth(config?: ServerInfo) {
 | 
					  _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 {GrAccountChip} from '../gr-account-chip/gr-account-chip';
 | 
				
			||||||
import {PolymerDeepPropertyChange} from '@polymer/polymer/interfaces';
 | 
					import {PolymerDeepPropertyChange} from '@polymer/polymer/interfaces';
 | 
				
			||||||
import {PaperInputElementExt} from '../../../types/types';
 | 
					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.';
 | 
					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
 | 
					        // Repopulate the input with what the user tried to enter and have
 | 
				
			||||||
        // a toast tell them why they can't enter it.
 | 
					        // a toast tell them why they can't enter it.
 | 
				
			||||||
        this.$.entry.setText(item);
 | 
					        this.$.entry.setText(item);
 | 
				
			||||||
        fire(this, EventType.SHOW_ALERT, VALID_EMAIL_ALERT);
 | 
					        fireAlert(this, VALID_EMAIL_ALERT);
 | 
				
			||||||
        return false;
 | 
					        return false;
 | 
				
			||||||
      } else {
 | 
					      } else {
 | 
				
			||||||
        const account = {email: item, _pendingAdd: true};
 | 
					        const account = {email: item, _pendingAdd: true};
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -60,7 +60,7 @@ import {
 | 
				
			|||||||
  UIRobot,
 | 
					  UIRobot,
 | 
				
			||||||
} from '../../../utils/comment-util';
 | 
					} from '../../../utils/comment-util';
 | 
				
			||||||
import {OpenFixPreviewEventDetail} from '../../../types/events';
 | 
					import {OpenFixPreviewEventDetail} from '../../../types/events';
 | 
				
			||||||
import {fire, EventType} from '../../../utils/event-util';
 | 
					import {fireAlert} from '../../../utils/event-util';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
const STORAGE_DEBOUNCE_INTERVAL = 400;
 | 
					const STORAGE_DEBOUNCE_INTERVAL = 400;
 | 
				
			||||||
const TOAST_DEBOUNCE_INTERVAL = 200;
 | 
					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
 | 
					        // 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
 | 
					        // this element may not be attached by the time this executes, in which
 | 
				
			||||||
        // case the event would not bubble.
 | 
					        // case the event would not bubble.
 | 
				
			||||||
        fire(document.body, EventType.SHOW_ALERT, message);
 | 
					        fireAlert(document.body, message);
 | 
				
			||||||
      },
 | 
					      },
 | 
				
			||||||
      TOAST_DEBOUNCE_INTERVAL
 | 
					      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 {PolymerElement} from '@polymer/polymer/polymer-element';
 | 
				
			||||||
import {customElement, property} from '@polymer/decorators';
 | 
					import {customElement, property} from '@polymer/decorators';
 | 
				
			||||||
import {htmlTemplate} from './gr-editable-content_html';
 | 
					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 RESTORED_MESSAGE = 'Content restored from a previous edit.';
 | 
				
			||||||
const STORAGE_DEBOUNCE_INTERVAL_MS = 400;
 | 
					const STORAGE_DEBOUNCE_INTERVAL_MS = 400;
 | 
				
			||||||
@@ -150,7 +150,7 @@ export class GrEditableContent extends GestureEventListeners(
 | 
				
			|||||||
      );
 | 
					      );
 | 
				
			||||||
      if (storedContent?.message) {
 | 
					      if (storedContent?.message) {
 | 
				
			||||||
        content = storedContent.message;
 | 
					        content = storedContent.message;
 | 
				
			||||||
        fire(this, EventType.SHOW_ALERT, RESTORED_MESSAGE);
 | 
					        fireAlert(this, RESTORED_MESSAGE);
 | 
				
			||||||
      }
 | 
					      }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    if (!content) {
 | 
					    if (!content) {
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -157,6 +157,7 @@ import {
 | 
				
			|||||||
  HttpMethod,
 | 
					  HttpMethod,
 | 
				
			||||||
  ReviewerState,
 | 
					  ReviewerState,
 | 
				
			||||||
} from '../../../constants/constants';
 | 
					} from '../../../constants/constants';
 | 
				
			||||||
 | 
					import {firePageError} from '../../../utils/event-util';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
const JSON_PREFIX = ")]}'";
 | 
					const JSON_PREFIX = ")]}'";
 | 
				
			||||||
const MAX_PROJECT_RESULTS = 25;
 | 
					const MAX_PROJECT_RESULTS = 25;
 | 
				
			||||||
@@ -3396,16 +3397,8 @@ export class GrRestApiInterface
 | 
				
			|||||||
      return Promise.resolve(project);
 | 
					      return Promise.resolve(project);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    const onError = (response?: Response | null) => {
 | 
					    const onError = (response?: Response | null) =>
 | 
				
			||||||
      // Fire a page error so that the visual 404 is displayed.
 | 
					      firePageError(this, response);
 | 
				
			||||||
      this.dispatchEvent(
 | 
					 | 
				
			||||||
        new CustomEvent('page-error', {
 | 
					 | 
				
			||||||
          detail: {response},
 | 
					 | 
				
			||||||
          composed: true,
 | 
					 | 
				
			||||||
          bubbles: true,
 | 
					 | 
				
			||||||
        })
 | 
					 | 
				
			||||||
      );
 | 
					 | 
				
			||||||
    };
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
    return this.getChange(changeNum, onError).then(change => {
 | 
					    return this.getChange(changeNum, onError).then(change => {
 | 
				
			||||||
      if (!change || !change.project) {
 | 
					      if (!change || !change.project) {
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -17,14 +17,25 @@
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
export enum EventType {
 | 
					export enum EventType {
 | 
				
			||||||
  SHOW_ALERT = 'show-alert',
 | 
					  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(
 | 
					  target.dispatchEvent(
 | 
				
			||||||
    new CustomEvent(type, {
 | 
					    new CustomEvent(EventType.SHOW_ALERT, {
 | 
				
			||||||
      detail: {message},
 | 
					      detail: {message},
 | 
				
			||||||
      composed: true,
 | 
					      composed: true,
 | 
				
			||||||
      bubbles: 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