Convert files to typescript

The change converts the following files to typescript:

* elements/change/gr-file-list/gr-file-list.ts

Change-Id: I03e0f92f73e2aa7c95fa53810b2c7dea069fff0f
This commit is contained in:
Dmitrii Filippov
2020-10-13 15:23:19 +02:00
parent 0437b86684
commit 53f21316e6
11 changed files with 1031 additions and 704 deletions

View File

@@ -37,7 +37,6 @@ import '../../shared/gr-icons/gr-icons.js';
import '../gr-commit-info/gr-commit-info.js';
import '../gr-download-dialog/gr-download-dialog.js';
import '../gr-file-list-header/gr-file-list-header.js';
import '../gr-file-list/gr-file-list.js';
import '../gr-included-in-dialog/gr-included-in-dialog.js';
import '../gr-messages-list/gr-messages-list.js';
import '../gr-related-changes-list/gr-related-changes-list.js';
@@ -73,6 +72,7 @@ import {
} from '../../../utils/patch-set-util.js';
import {changeStatuses, changeStatusString} from '../../../utils/change-util.js';
import {EventType} from '../../plugins/gr-plugin-types.js';
import {DEFAULT_NUM_FILES_SHOWN} from '../gr-file-list/gr-file-list.js';
const CHANGE_ID_ERROR = {
MISMATCH: 'mismatch',
@@ -82,7 +82,6 @@ const CHANGE_ID_REGEX_PATTERN =
/^(Change-Id\:\s|Link:.*\/id\/)(I[0-9a-f]{8,40})/gm;
const MIN_LINES_FOR_COMMIT_COLLAPSE = 30;
const DEFAULT_NUM_FILES_SHOWN = 200;
const REVIEWERS_REGEX = /^(R|CC)=/gm;
const MIN_CHECK_INTERVAL_SECS = 0;

File diff suppressed because it is too large Load Diff

View File

@@ -375,7 +375,7 @@ export const htmlTemplate = html`
<div class="stickyArea">
<div
class$="file-row row [[_computePathClass(file.__path, _expandedFiles.*)]]"
data-file$="[[_computeFileRange(file)]]"
data-file$="[[_computePatchSetFile(file)]]"
tabindex="-1"
role="row"
>
@@ -657,7 +657,7 @@ export const htmlTemplate = html`
hidden="[[!_isFileExpanded(file.__path, _expandedFiles.*)]]"
change-num="[[changeNum]]"
patch-range="[[patchRange]]"
file="[[_computeFileRange(file)]]"
file="[[_computePatchSetFile(file)]]"
path="[[file.__path]]"
prefs="[[diffPrefs]]"
project-name="[[change.project]]"

View File

@@ -312,7 +312,7 @@ suite('gr-file-list tests', () => {
for (const bytes in table) {
if (table.hasOwnProperty(bytes)) {
assert.equal(element._formatBytes(bytes), table[bytes]);
assert.equal(element._formatBytes(Number(bytes)), table[bytes]);
}
}
});
@@ -1329,15 +1329,23 @@ suite('gr-file-list tests', () => {
suite('size bars', () => {
test('_computeSizeBarLayout', () => {
assert.isUndefined(element._computeSizeBarLayout(null));
assert.isUndefined(element._computeSizeBarLayout({}));
assert.deepEqual(element._computeSizeBarLayout({base: []}), {
const defaultSizeBarLayout = {
maxInserted: 0,
maxDeleted: 0,
maxAdditionWidth: 0,
maxDeletionWidth: 0,
deletionOffset: 0,
});
};
assert.deepEqual(
element._computeSizeBarLayout(null),
defaultSizeBarLayout);
assert.deepEqual(
element._computeSizeBarLayout({}),
defaultSizeBarLayout);
assert.deepEqual(
element._computeSizeBarLayout({base: []}),
defaultSizeBarLayout);
const files = [
{__path: '/COMMIT_MSG', lines_inserted: 10000},

View File

@@ -32,6 +32,7 @@ import {
ParentPatchSetNum,
ServerInfo,
} from '../../../types/common';
import {ParsedChangeInfo} from '../../shared/gr-rest-api-interface/gr-reviewer-updates-parser';
// Navigation parameters object format:
//
@@ -664,7 +665,7 @@ export const GerritNav = {
* @param basePatchNum The string 'PARENT' can be used for none.
*/
getUrlForDiff(
change: ChangeInfo,
change: ChangeInfo | ParsedChangeInfo,
filePath: string,
patchNum?: PatchSetNum,
basePatchNum?: PatchSetNum,
@@ -723,7 +724,7 @@ export const GerritNav = {
},
getEditUrlForDiff(
change: ChangeInfo,
change: ChangeInfo | ParsedChangeInfo,
filePath: string,
patchNum?: PatchSetNum,
lineNum?: number
@@ -763,7 +764,7 @@ export const GerritNav = {
* @param basePatchNum The string 'PARENT' can be used for none.
*/
navigateToDiff(
change: ChangeInfo,
change: ChangeInfo | ParsedChangeInfo,
filePath: string,
patchNum?: PatchSetNum,
basePatchNum?: PatchSetNum,

View File

@@ -143,7 +143,7 @@ export class GrCommentThread extends KeyboardShortcutMixin(
notify: true,
computed: '_computeRootId(comments.*)',
})
rootId?: string;
rootId?: UrlEncodedCommentId;
@property({type: Boolean})
showFilePath = false;

View File

@@ -1603,7 +1603,10 @@ export class GrRestApiInterface
}) as Promise<string[] | undefined>;
}
getChangeOrEditFiles(changeNum: NumericChangeId, patchRange: PatchRange) {
getChangeOrEditFiles(
changeNum: NumericChangeId,
patchRange: PatchRange
): Promise<FileNameToFileInfoMap | undefined> {
if (patchNumEquals(patchRange.patchNum, EditPatchSetNum)) {
return this.getChangeEditFiles(changeNum, patchRange).then(
res => res && res.files
@@ -2086,13 +2089,16 @@ export class GrRestApiInterface
}) as Promise<ChangeInfo[] | undefined>;
}
getReviewedFiles(changeNum: NumericChangeId, patchNum: PatchSetNum) {
getReviewedFiles(
changeNum: NumericChangeId,
patchNum: PatchSetNum
): Promise<string[] | undefined> {
return this._getChangeURLAndFetch({
changeNum,
endpoint: '/files?reviewed',
patchNum,
reportEndpointAsIs: true,
});
}) as Promise<string[] | undefined>;
}
saveFileReviewed(

View File

@@ -1082,7 +1082,7 @@ export interface KeyboardShortcutMixinInterface {
_shortcut_v_key_last_pressed: number | null;
_shortcut_go_table: Map<string, string>;
_shortcut_v_table: Map<string, string>;
keyboardShortcuts(): {[key: string]: string};
keyboardShortcuts(): {[key: string]: string | null};
createTitle(name: Shortcut, section: ShortcutSection): string;
bindShortcut(shortcut: Shortcut, ...bindings: string[]): void;
shouldSuppressKeyboardShortcut(event: CustomKeyboardEvent): boolean;

View File

@@ -96,6 +96,7 @@ import {
DashboardId,
HashtagsInput,
Hashtag,
FileNameToFileInfoMap,
} from '../../../types/common';
import {ParsedChangeInfo} from '../../../elements/shared/gr-rest-api-interface/gr-reviewer-updates-parser';
import {HttpMethod, IgnoreWhitespaceType} from '../../../constants/constants';
@@ -815,4 +816,29 @@ export interface RestApiService {
changeNum: NumericChangeId,
topic: string | null
): Promise<string>;
getChangeOrEditFiles(
changeNum: NumericChangeId,
patchRange: PatchRange
): Promise<FileNameToFileInfoMap | undefined>;
getReviewedFiles(
changeNum: NumericChangeId,
patchNum: PatchSetNum
): Promise<string[] | undefined>;
saveFileReviewed(
changeNum: NumericChangeId,
patchNum: PatchSetNum,
path: string,
reviewed: boolean
): Promise<Response>;
saveFileReviewed(
changeNum: NumericChangeId,
patchNum: PatchSetNum,
path: string,
reviewed: boolean,
errFn: ErrorCallback
): Promise<Response | undefined>;
}

View File

@@ -26,7 +26,7 @@
*/
export function asyncForeach<T>(
array: T[],
fn: (item: T, stopCallback: () => void) => Promise<T>
fn: (item: T, stopCallback: () => void) => Promise<unknown>
): Promise<T | void> {
if (!array.length) {
return Promise.resolve();

View File

@@ -211,13 +211,13 @@ export function getEventPath<T extends PolymerEvent>(e?: T) {
export function descendedFromClass(
element: Element,
className: string,
opt_stopElement: Element
stopElement?: Element
) {
let isDescendant = element.classList.contains(className);
while (
!isDescendant &&
element.parentElement &&
(!opt_stopElement || element.parentElement !== opt_stopElement)
(!stopElement || element.parentElement !== stopElement)
) {
isDescendant = element.classList.contains(className);
element = element.parentElement;