Convert gr-change-view to typescript
The change converts the following files to typescript: * elements/change/gr-change-view/gr-change-view.ts Change-Id: I32a2ca2683757c8922e298b3c2d4336d3eb40dcf
This commit is contained in:
@@ -190,6 +190,17 @@ export enum SubmitType {
|
||||
INHERIT = 'INHERIT',
|
||||
}
|
||||
|
||||
/**
|
||||
* https://gerrit-review.googlesource.com/Documentation/rest-api-changes.html#mergeable-info
|
||||
*/
|
||||
export enum MergeStrategy {
|
||||
RECURSIVE = 'recursive',
|
||||
RESOLVE = 'resolve',
|
||||
SIMPLE_TWO_WAY_IN_CORE = 'simple-two-way-in-core',
|
||||
OURS = 'ours',
|
||||
THEIRS = 'theirs',
|
||||
}
|
||||
|
||||
/*
|
||||
* Enum for possible configured value in InheritedBooleanInfo.
|
||||
* https://gerrit-review.googlesource.com/Documentation/rest-api-projects.html#inherited-boolean-info
|
||||
|
File diff suppressed because it is too large
Load Diff
@@ -300,6 +300,7 @@ suite('gr-change-view tests', () => {
|
||||
_fetchSharedCacheURL() { return Promise.resolve({}); },
|
||||
});
|
||||
element = fixture.instantiate();
|
||||
element._changeNum = '1';
|
||||
sinon.stub(element.$.actions, 'reload').returns(Promise.resolve());
|
||||
getPluginLoader().loadPlugins([]);
|
||||
pluginApi.install(
|
||||
@@ -333,6 +334,11 @@ suite('gr-change-view tests', () => {
|
||||
basePatchNum: 'PARENT',
|
||||
patchNum: 1,
|
||||
};
|
||||
element._change = {
|
||||
_number: '1',
|
||||
project: '',
|
||||
change_id: '1',
|
||||
};
|
||||
const getUrlStub = sinon.stub(GerritNav, 'getUrlForChange');
|
||||
const replaceStateStub = sinon.stub(history, 'replaceState');
|
||||
element._handleMessageAnchorTap({detail: {id: 'a12345'}});
|
||||
@@ -414,6 +420,7 @@ suite('gr-change-view tests', () => {
|
||||
|
||||
suite('plugins adding to file tab', () => {
|
||||
setup(done => {
|
||||
element._changeNum = '1';
|
||||
// Resolving it here instead of during setup() as other tests depend
|
||||
// on flush() not being called during setup.
|
||||
flush(() => done());
|
||||
@@ -459,6 +466,7 @@ suite('gr-change-view tests', () => {
|
||||
queryMap.set('tab', PrimaryTab.FINDINGS);
|
||||
// view is required
|
||||
element.params = {
|
||||
changeNum: '1',
|
||||
view: GerritNav.View.CHANGE,
|
||||
...element.params, queryMap};
|
||||
flush(() => {
|
||||
@@ -473,6 +481,7 @@ suite('gr-change-view tests', () => {
|
||||
queryMap.set('tab', 'random');
|
||||
// view is required
|
||||
element.params = {
|
||||
changeNum: '1',
|
||||
view: GerritNav.View.CHANGE,
|
||||
...element.params, queryMap};
|
||||
flush(() => {
|
||||
@@ -783,6 +792,7 @@ suite('gr-change-view tests', () => {
|
||||
getAllThreadsForChange: () => ([]),
|
||||
computeDraftCount: () => 1,
|
||||
}));
|
||||
element._changeNum = '1';
|
||||
});
|
||||
|
||||
test('drafts are reloaded when reload-drafts fired', done => {
|
||||
@@ -1415,6 +1425,7 @@ suite('gr-change-view tests', () => {
|
||||
});
|
||||
|
||||
test('_handleCommitMessageSave trims trailing whitespace', () => {
|
||||
element._change = {};
|
||||
const putStub = sinon.stub(element.$.restAPI, 'putChangeCommitMessage')
|
||||
.returns(Promise.resolve({}));
|
||||
|
||||
@@ -1609,14 +1620,16 @@ suite('gr-change-view tests', () => {
|
||||
});
|
||||
|
||||
test('_openReplyDialog called with `ANY` when coming from tap event',
|
||||
() => {
|
||||
const openStub = sinon.stub(element, '_openReplyDialog');
|
||||
element._serverConfig = {};
|
||||
MockInteractions.tap(element.$.replyBtn);
|
||||
assert(openStub.lastCall.calledWithExactly(
|
||||
element.$.replyDialog.FocusTarget.ANY),
|
||||
'_openReplyDialog should have been passed ANY');
|
||||
assert.equal(openStub.callCount, 1);
|
||||
done => {
|
||||
flush(() => {
|
||||
const openStub = sinon.stub(element, '_openReplyDialog');
|
||||
MockInteractions.tap(element.$.replyBtn);
|
||||
assert(openStub.lastCall.calledWithExactly(
|
||||
element.$.replyDialog.FocusTarget.ANY),
|
||||
'_openReplyDialog should have been passed ANY');
|
||||
assert.equal(openStub.callCount, 1);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
test('_openReplyDialog called with `BODY` when coming from message reply' +
|
||||
@@ -1806,10 +1819,13 @@ suite('gr-change-view tests', () => {
|
||||
});
|
||||
});
|
||||
|
||||
test('reply button is disabled until server config is loaded', () => {
|
||||
test('reply button is disabled until server config is loaded', done => {
|
||||
assert.isTrue(element._replyDisabled);
|
||||
element._serverConfig = {};
|
||||
assert.isFalse(element._replyDisabled);
|
||||
// fetches the server config on attached
|
||||
flush(() => {
|
||||
assert.isFalse(element._replyDisabled);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
suite('commit message expand/collapse', () => {
|
||||
@@ -2189,6 +2205,11 @@ suite('gr-change-view tests', () => {
|
||||
basePatchNum: 'PARENT',
|
||||
patchNum: 1,
|
||||
};
|
||||
element._change = {
|
||||
_number: '1',
|
||||
project: '',
|
||||
change_id: '1',
|
||||
};
|
||||
const fileList = element.$.fileList;
|
||||
const Actions = GrEditConstants.Actions;
|
||||
element.$.fileListHeader.editMode = true;
|
||||
@@ -2371,6 +2392,11 @@ suite('gr-change-view tests', () => {
|
||||
});
|
||||
|
||||
test('_handleStopEditTap', done => {
|
||||
element._change = {
|
||||
_number: '1',
|
||||
project: '',
|
||||
change_id: '1',
|
||||
};
|
||||
sinon.stub(element.$.metadata, '_computeLabelNames');
|
||||
navigateToChangeStub.restore();
|
||||
sinon.stub(GerritNav, 'navigateToChange').callsFake((...args) => {
|
||||
|
@@ -65,7 +65,7 @@ export class GrIncludedInDialog extends GestureEventListeners(
|
||||
|
||||
loadData() {
|
||||
if (!this.changeNum) {
|
||||
return;
|
||||
return Promise.reject(new Error('missing required property changeNum'));
|
||||
}
|
||||
this._filterText = '';
|
||||
return this.$.restAPI.getChangeIncludedIn(this.changeNum).then(configs => {
|
||||
|
@@ -113,7 +113,7 @@ import {isUnresolved} from '../../../utils/comment-util';
|
||||
|
||||
const STORAGE_DEBOUNCE_INTERVAL_MS = 400;
|
||||
|
||||
enum FocusTarget {
|
||||
export enum FocusTarget {
|
||||
ANY = 'any',
|
||||
BODY = 'body',
|
||||
CCS = 'cc',
|
||||
|
@@ -105,6 +105,15 @@ export interface AppElementDiffViewParam {
|
||||
leftSide?: boolean;
|
||||
commentLink?: boolean;
|
||||
}
|
||||
export interface AppElementChangeViewParams {
|
||||
view: GerritView.CHANGE;
|
||||
changeNum: NumericChangeId;
|
||||
project: RepoName;
|
||||
edit?: boolean;
|
||||
patchNum?: PatchSetNum;
|
||||
basePatchNum?: PatchSetNum;
|
||||
queryMap?: Map<string, string> | URLSearchParams;
|
||||
}
|
||||
|
||||
export interface AppElementJustRegisteredParams {
|
||||
// We use params.view === ... as a type guard.
|
||||
@@ -120,6 +129,7 @@ export type AppElementParams =
|
||||
| AppElementDashboardParams
|
||||
| AppElementGroupParams
|
||||
| AppElementAdminParams
|
||||
| AppElementChangeViewParams
|
||||
| AppElementRepoParams
|
||||
| AppElementDocSearchParams
|
||||
| AppElementPluginScreenParams
|
||||
|
@@ -35,6 +35,7 @@ import {
|
||||
} from './gr-js-api-types';
|
||||
import {EventType, TargetElement} from '../../plugins/gr-plugin-types';
|
||||
import {DiffLayer, HighlightJS} from '../../../types/types';
|
||||
import {ParsedChangeInfo} from '../gr-rest-api-interface/gr-reviewer-updates-parser';
|
||||
|
||||
const elements: {[key: string]: HTMLElement} = {};
|
||||
const eventCallbacks: {[key: string]: EventCallback[]} = {};
|
||||
@@ -177,7 +178,7 @@ export class GrJsApiInterface
|
||||
}
|
||||
}
|
||||
|
||||
handleCommitMessage(change: ChangeInfo, msg: string) {
|
||||
handleCommitMessage(change: ChangeInfo | ParsedChangeInfo, msg: string) {
|
||||
for (const cb of this._getEventCallbacks(EventType.COMMIT_MSG_EDIT)) {
|
||||
try {
|
||||
cb(change, msg);
|
||||
|
@@ -139,6 +139,7 @@ import {
|
||||
GroupName,
|
||||
Hashtag,
|
||||
TopMenuEntryInfo,
|
||||
MergeableInfo,
|
||||
} from '../../../types/common';
|
||||
import {
|
||||
CancelConditionCallback,
|
||||
@@ -1551,7 +1552,7 @@ export class GrRestApiInterface
|
||||
endpoint: '/commit?links',
|
||||
patchNum,
|
||||
reportEndpointAsIs: true,
|
||||
});
|
||||
}) as Promise<CommitInfo | undefined>;
|
||||
}
|
||||
|
||||
getChangeFiles(
|
||||
@@ -3582,7 +3583,7 @@ export class GrRestApiInterface
|
||||
changeNum,
|
||||
endpoint: '/revisions/current/mergeable',
|
||||
reportEndpointAsIs: true,
|
||||
});
|
||||
}) as Promise<MergeableInfo | undefined>;
|
||||
}
|
||||
|
||||
deleteDraftComments(query: string): Promise<Response> {
|
||||
|
@@ -17,6 +17,7 @@
|
||||
|
||||
import {patchNumEquals} from '../../../utils/patch-set-util';
|
||||
import {ChangeInfo, PatchSetNum} from '../../../types/common';
|
||||
import {ParsedChangeInfo} from '../gr-rest-api-interface/gr-reviewer-updates-parser';
|
||||
|
||||
type RevNumberToParentCountMap = {[revNumber: number]: number};
|
||||
|
||||
@@ -26,7 +27,7 @@ export class RevisionInfo {
|
||||
* @param change A change object resulting from a change detail
|
||||
* call that includes revision information.
|
||||
*/
|
||||
constructor(private change: ChangeInfo) {}
|
||||
constructor(private change: ChangeInfo | ParsedChangeInfo) {}
|
||||
|
||||
/**
|
||||
* Get the largest number of parents of the commit in any revision. For
|
||||
|
@@ -98,6 +98,8 @@ import {
|
||||
Hashtag,
|
||||
FileNameToFileInfoMap,
|
||||
TopMenuEntryInfo,
|
||||
MergeableInfo,
|
||||
CommitInfo,
|
||||
} from '../../../types/common';
|
||||
import {ParsedChangeInfo} from '../../../elements/shared/gr-rest-api-interface/gr-reviewer-updates-parser';
|
||||
import {HttpMethod, IgnoreWhitespaceType} from '../../../constants/constants';
|
||||
@@ -216,7 +218,7 @@ export interface RestApiService {
|
||||
|
||||
getChangeDetail(
|
||||
changeNum: number | string,
|
||||
opt_errFn?: Function,
|
||||
opt_errFn?: ErrorCallback,
|
||||
opt_cancelCondition?: Function
|
||||
): Promise<ParsedChangeInfo | null | undefined>;
|
||||
|
||||
@@ -851,4 +853,15 @@ export interface RestApiService {
|
||||
getTopMenus(errFn?: ErrorCallback): Promise<TopMenuEntryInfo[] | undefined>;
|
||||
|
||||
setInProjectLookup(changeNum: NumericChangeId, project: RepoName): void;
|
||||
getMergeable(changeNum: NumericChangeId): Promise<MergeableInfo | undefined>;
|
||||
|
||||
putChangeCommitMessage(
|
||||
changeNum: NumericChangeId,
|
||||
message: string
|
||||
): Promise<Response>;
|
||||
|
||||
getChangeCommitInfo(
|
||||
changeNum: NumericChangeId,
|
||||
patchNum: PatchSetNum
|
||||
): Promise<CommitInfo | undefined>;
|
||||
}
|
||||
|
@@ -44,6 +44,7 @@ import {
|
||||
NotifyType,
|
||||
EmailFormat,
|
||||
AuthType,
|
||||
MergeStrategy,
|
||||
} from '../constants/constants';
|
||||
import {PolymerDeepPropertyChange} from '@polymer/polymer/interfaces';
|
||||
|
||||
@@ -804,7 +805,7 @@ export interface ChangeConfigInfo {
|
||||
large_change: string;
|
||||
reply_label: string;
|
||||
reply_tooltip: string;
|
||||
update_delay: string;
|
||||
update_delay: number;
|
||||
submit_whole_topic: boolean;
|
||||
disable_private_changes: boolean;
|
||||
mergeability_computation_behavior: string;
|
||||
@@ -2235,3 +2236,16 @@ export interface CherryPickInput {
|
||||
topic?: TopicName;
|
||||
allow_empty?: boolean;
|
||||
}
|
||||
|
||||
/**
|
||||
* https://gerrit-review.googlesource.com/Documentation/rest-api-changes.html#mergeable-info
|
||||
*/
|
||||
export interface MergeableInfo {
|
||||
submit_type: SubmitType;
|
||||
strategy?: MergeStrategy;
|
||||
mergeable: boolean;
|
||||
commit_merged?: boolean;
|
||||
content_merged?: boolean;
|
||||
conflicts?: string[];
|
||||
mergeable_into?: string[];
|
||||
}
|
||||
|
@@ -20,6 +20,7 @@ import {GrDiffLine} from '../elements/diff/gr-diff/gr-diff-line';
|
||||
import {FlattenedNodesObserver} from '@polymer/polymer/lib/utils/flattened-nodes-observer';
|
||||
import {PaperInputElement} from '@polymer/paper-input/paper-input';
|
||||
import {CommitId, NumericChangeId, PatchRange, PatchSetNum} from './common';
|
||||
import {PolymerSpliceChange} from '@polymer/polymer/interfaces';
|
||||
|
||||
export function notUndefined<T>(x: T | undefined): x is T {
|
||||
return x !== undefined;
|
||||
@@ -213,3 +214,10 @@ export interface FileRange {
|
||||
basePath?: string;
|
||||
path: string;
|
||||
}
|
||||
|
||||
export function isPolymerSpliceChange<
|
||||
T,
|
||||
U extends Array<{} | null | undefined>
|
||||
>(x: T | PolymerSpliceChange<U>): x is PolymerSpliceChange<U> {
|
||||
return (x as PolymerSpliceChange<U>).indexSplices !== undefined;
|
||||
}
|
||||
|
@@ -57,10 +57,6 @@ interface PatchRange {
|
||||
basePatchNum?: PatchSetNum;
|
||||
}
|
||||
|
||||
interface PatchRangeRecord {
|
||||
base: PatchRange;
|
||||
}
|
||||
|
||||
/**
|
||||
* As patchNum can be either a string (e.g. 'edit', 'PARENT') OR a number,
|
||||
* this function checks for patchNum equality.
|
||||
@@ -246,7 +242,9 @@ function _computeWipForPatchSets(
|
||||
|
||||
export const _testOnly_computeWipForPatchSets = _computeWipForPatchSets;
|
||||
|
||||
export function computeLatestPatchNum(allPatchSets?: PatchSet[]) {
|
||||
export function computeLatestPatchNum(
|
||||
allPatchSets?: PatchSet[]
|
||||
): PatchSetNum | undefined {
|
||||
if (!allPatchSets || !allPatchSets.length) {
|
||||
return undefined;
|
||||
}
|
||||
@@ -263,11 +261,7 @@ export function hasEditBasedOnCurrentPatchSet(allPatchSets: PatchSet[]) {
|
||||
return allPatchSets[0].num === EditPatchSetNum;
|
||||
}
|
||||
|
||||
export function hasEditPatchsetLoaded(patchRangeRecord: PatchRangeRecord) {
|
||||
const patchRange = patchRangeRecord.base;
|
||||
if (!patchRange) {
|
||||
return false;
|
||||
}
|
||||
export function hasEditPatchsetLoaded(patchRange: PatchRange) {
|
||||
return (
|
||||
patchRange.patchNum === EditPatchSetNum ||
|
||||
patchRange.basePatchNum === EditPatchSetNum
|
||||
@@ -283,7 +277,7 @@ export function hasEditPatchsetLoaded(patchRangeRecord: PatchRangeRecord) {
|
||||
* meantime. The promise is rejected on network error.
|
||||
*/
|
||||
export function fetchChangeUpdates(
|
||||
change: ChangeInfo,
|
||||
change: ChangeInfo | ParsedChangeInfo,
|
||||
restAPI: RestApiService
|
||||
) {
|
||||
const knownLatest = computeLatestPatchNum(computeAllPatchSets(change));
|
||||
|
Reference in New Issue
Block a user