From 5c63e40f22101aa6a173cdd6b128544a51d52d6f Mon Sep 17 00:00:00 2001 From: supermii2 Date: Mon, 5 Feb 2024 12:05:20 +0800 Subject: [PATCH 01/16] Add return types to frontend components --- frontend/src/components/c-ramp.vue | 28 +++++++++---------- frontend/src/components/c-resizer.vue | 20 +++++++------ .../src/components/c-segment-collection.vue | 6 ++-- frontend/src/components/c-segment.vue | 8 ++++-- frontend/src/components/c-summary-charts.vue | 24 ++++++++++------ 5 files changed, 51 insertions(+), 35 deletions(-) diff --git a/frontend/src/components/c-ramp.vue b/frontend/src/components/c-ramp.vue index 55e130d7ec..7f80fadb19 100644 --- a/frontend/src/components/c-ramp.vue +++ b/frontend/src/components/c-ramp.vue @@ -84,7 +84,7 @@ export default defineComponent({ default: false, }, }, - data() { + data(): {rampSize: number} { return { rampSize: 0.01 as number, }; @@ -100,16 +100,16 @@ export default defineComponent({ }, methods: { - getLink(commit: CommitResult) { + getLink(commit: CommitResult): string | undefined { return window.getCommitLink(commit.repoId, commit.hash); }, - getContributions(commit: CommitResult | Commit) { + getContributions(commit: CommitResult | Commit): number { return commit.insertions + commit.deletions; }, - isDeletesContribution(commit: CommitResult | Commit) { + isDeletesContribution(commit: CommitResult | Commit): boolean { return commit.insertions === 0 && commit.deletions > 0; }, - getWidth(slice: CommitResult | Commit) { + getWidth(slice: CommitResult | Commit): number { // Check if slice contains 'isMergeCommit' attribute if ('isMergeCommit' in slice && slice.isMergeCommit) { return this.mergeCommitRampSize; @@ -124,17 +124,17 @@ export default defineComponent({ const newSize = 100 * (slice.insertions / +this.avgsize); return Math.max(newSize * this.rampSize, 0.5); }, - getContributionMessageByCommit(slice: Commit, commit: CommitResult) { + getContributionMessageByCommit(slice: Commit, commit: CommitResult): string { return `[${slice.date}] ${commit.messageTitle}: +${commit.insertions} -${commit.deletions} lines `; }, - getContributionMessage(slice: Commit) { + getContributionMessage(slice: Commit): string { let title = this.tframe === 'day' ? `[${slice.date}] Daily ` : `[${slice.date} till ${slice.endDate}] Weekly `; title += `contribution: +${slice.insertions} -${slice.deletions} lines`; return title; }, - openTabZoom(user: User, slice: Commit, evt: MouseEvent) { + openTabZoom(user: User, slice: Commit, evt: MouseEvent): void { // prevent opening of zoom tab when cmd/ctrl click if (window.isMacintosh ? evt.metaKey : evt.ctrlKey) { return; @@ -171,21 +171,21 @@ export default defineComponent({ }, // position for commit granularity - getCommitPos(i: number, total: number) { + getCommitPos(i: number, total: number): number { return (((total - i - 1) * window.DAY_IN_MS) / total) / (this.getTotalForPos(this.sdate, this.udate) + window.DAY_IN_MS); }, // position for day granularity - getSlicePos(date: string) { + getSlicePos(date: string): number { const total = this.getTotalForPos(this.sdate, this.udate); return (new Date(this.udate).valueOf() - new Date(date).valueOf()) / (total + window.DAY_IN_MS); }, // get duration in miliseconds between 2 date - getTotalForPos(sinceDate: string, untilDate: string) { + getTotalForPos(sinceDate: string, untilDate: string): number { return new Date(untilDate).valueOf() - new Date(sinceDate).valueOf(); }, - getRampColor(commit: CommitResult, slice: Commit) { + getRampColor(commit: CommitResult, slice: Commit): number | '-deletes' { if (this.isDeletesContribution(commit)) { return '-deletes'; } @@ -203,13 +203,13 @@ export default defineComponent({ }, // Prevent browser from switching to new tab when clicking ramp - rampClick(evt: MouseEvent) { + rampClick(evt: MouseEvent): void { const isKeyPressed = window.isMacintosh ? evt.metaKey : evt.ctrlKey; if (isKeyPressed) { evt.preventDefault(); } }, - getReportLink() { + getReportLink(): string | undefined { if (this.isWidgetMode) { const url = window.location.href; const regexToRemoveWidget = /([?&])((chartIndex|chartGroupIndex)=\d+)/g; diff --git a/frontend/src/components/c-resizer.vue b/frontend/src/components/c-resizer.vue index a315140e78..5a59a6beaa 100644 --- a/frontend/src/components/c-resizer.vue +++ b/frontend/src/components/c-resizer.vue @@ -47,7 +47,11 @@ const throttledEvent = (delay: number, handler: (event: MouseEvent) => unknown) export default defineComponent({ name: 'c-resizer', - data() { + data(): { + guideWidth: number, + flexWidth: number, + isResizing: boolean + } { return { guideWidth: (0.5 * window.innerWidth - (GUIDE_BAR_WIDTH / 2)) / window.innerWidth, flexWidth: 0.5, @@ -56,23 +60,23 @@ export default defineComponent({ }, computed: { - appStyles() { + appStyles(): string { return this.isResizing ? 'user-select: none; cursor: col-resize;' : ''; }, - guideStyles() { + guideStyles(): string { return this.isResizing ? `display: block; right: ${this.guideWidth * 100}%;` : ''; }, - rightContainerStyles() { + rightContainerStyles(): string { return `flex: 0 0 ${this.flexWidth * 100}%;`; }, - mouseMove() { + mouseMove(): Function { if (this.isResizing) { return throttledEvent(25, (event: MouseEvent) => { this.guideWidth = ( @@ -94,17 +98,17 @@ export default defineComponent({ }, methods: { - registerMouseMove() { + registerMouseMove(): void { this.isResizing = true; }, - deregisterMouseMove() { + deregisterMouseMove(): void { this.isResizing = false; this.flexWidth = (this.guideWidth * window.innerWidth + (GUIDE_BAR_WIDTH / 2)) / window.innerWidth; }, - closeTab() { + closeTab(): void { this.$store.commit('updateTabState', false); }, }, diff --git a/frontend/src/components/c-segment-collection.vue b/frontend/src/components/c-segment-collection.vue index 591dbb247d..321be95c08 100644 --- a/frontend/src/components/c-segment-collection.vue +++ b/frontend/src/components/c-segment-collection.vue @@ -24,13 +24,15 @@ export default defineComponent({ required: true, }, }, - data() { + data(): { + isRendered: boolean, + } { return { isRendered: false, }; }, methods: { - visibilityChanged(isVisible: boolean) { + visibilityChanged(isVisible: boolean): void { if (isVisible) { this.isRendered = true; } diff --git a/frontend/src/components/c-segment.vue b/frontend/src/components/c-segment.vue index 7e16cc5fd9..2ad6932d95 100644 --- a/frontend/src/components/c-segment.vue +++ b/frontend/src/components/c-segment.vue @@ -49,7 +49,11 @@ export default defineComponent({ required: true, }, }, - data() { + data(): { + isOpen: boolean, + canOpen: boolean, + transparencyValue: string, + } { return { isOpen: (this.segment.knownAuthor !== null) || this.segment.lines.length < 5 as boolean, canOpen: (this.segment.knownAuthor === null) && this.segment.lines.length > 4 as boolean, @@ -62,7 +66,7 @@ export default defineComponent({ }), }, methods: { - toggleCode() { + toggleCode(): void { this.isOpen = !this.isOpen; }, }, diff --git a/frontend/src/components/c-summary-charts.vue b/frontend/src/components/c-summary-charts.vue index c97410880a..53fc565cca 100644 --- a/frontend/src/components/c-summary-charts.vue +++ b/frontend/src/components/c-summary-charts.vue @@ -372,7 +372,13 @@ export default defineComponent({ default: undefined, }, }, - data() { + data(): { + drags: Array, + activeRepo: string | null, + activeUser: string | null, + activeTabType: string | null, + isTabOnMergedGroup: boolean, + } { return { drags: [] as Array, activeRepo: null as string | null, @@ -398,17 +404,17 @@ export default defineComponent({ }); return totalCommits / totalCount; }, - filteredRepos() { + filteredRepos(): Array> { const repos = this.filtered.filter((repo) => repo.length > 0); if (this.isChartGroupWidgetMode && this.chartGroupIndex! < repos.length) { return [repos[this.chartGroupIndex!]]; } return repos; }, - isChartGroupWidgetMode() { + isChartGroupWidgetMode(): boolean { return this.chartGroupIndex !== undefined && this.chartGroupIndex >= 0; }, - isChartWidgetMode() { + isChartWidgetMode(): boolean { return this.chartIndex !== undefined && this.chartIndex >= 0 && this.isChartGroupWidgetMode; }, ...mapState({ @@ -423,7 +429,7 @@ export default defineComponent({ } }, }, - created() { + created(): void { this.retrieveSelectedTabHash(); }, methods: { @@ -629,7 +635,7 @@ export default defineComponent({ this.$store.commit('updateTabZoomInfo', info); }, - async getEmbeddedIframe(chartGroupIndex: number, chartIndex: number = -1) { + async getEmbeddedIframe(chartGroupIndex: number, chartIndex: number = -1): Promise { const isChartIndexProvided = chartIndex !== -1; // Set height of iframe according to number of charts to avoid scrolling let totalChartHeight = 0; @@ -666,7 +672,7 @@ export default defineComponent({ const tooltipId = `tooltip-${chartGroupIndex}${isChartIndexProvided ? `-${chartIndex}` : ''}`; this.updateCopyTooltip(tooltipId, 'Copied iframe'); }, - updateCopyTooltip(tooltipId: string, text: string) { + updateCopyTooltip(tooltipId: string, text: string): void { const tooltipElement = document.getElementById(tooltipId); if (tooltipElement && tooltipElement.querySelector('.tooltip-text')) { const tooltipTextElement = tooltipElement.querySelector('.tooltip-text'); @@ -677,12 +683,12 @@ export default defineComponent({ }, 2000); } }, - getReportLink() { + getReportLink(): string { const url = window.location.href; const regexToRemoveWidget = /([?&])((chartIndex|chartGroupIndex)=\d+)/g; return url.replace(regexToRemoveWidget, ''); }, - getRepo(repo: Array) { + getRepo(repo: Array): Array { if (this.isChartGroupWidgetMode && this.isChartWidgetMode) { return [repo[this.chartIndex!]]; } From 6cbe8ff576c583e7f0c9ce85a5e28d77704c4e53 Mon Sep 17 00:00:00 2001 From: supermii2 Date: Mon, 5 Feb 2024 12:11:27 +0800 Subject: [PATCH 02/16] Add return types to frontend mixins --- frontend/src/mixin/brokenLinkMixin.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/frontend/src/mixin/brokenLinkMixin.ts b/frontend/src/mixin/brokenLinkMixin.ts index cda35dbb3c..0b9be83603 100644 --- a/frontend/src/mixin/brokenLinkMixin.ts +++ b/frontend/src/mixin/brokenLinkMixin.ts @@ -1,13 +1,13 @@ import { defineComponent } from 'vue'; export default defineComponent({ - data() { + data(): { disabledLinkMessage: string } { return { disabledLinkMessage: 'This remote link is unsupported', }; }, methods: { - isBrokenLink(link: string | undefined) { + isBrokenLink(link: string | undefined): boolean { return link === undefined; }, getLinkMessage(link: string | undefined, linkMessage: string): string { From 14c2d6c7c93cd03a119da048e0a8e52c3cfe4087 Mon Sep 17 00:00:00 2001 From: supermii2 Date: Mon, 19 Feb 2024 12:11:46 +0800 Subject: [PATCH 03/16] Add return types to store --- frontend/src/store/store.ts | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/frontend/src/store/store.ts b/frontend/src/store/store.ts index c69d2a4204..17106c7b49 100644 --- a/frontend/src/store/store.ts +++ b/frontend/src/store/store.ts @@ -20,34 +20,34 @@ export default createStore({ isTabActive: true, } as StoreState, mutations: { - updateTabZoomInfo(state: StoreState, info: ZoomInfo) { + updateTabZoomInfo(state: StoreState, info: ZoomInfo): void { state.tabZoomInfo = info; }, - updateTabAuthorshipInfo(state: StoreState, info: AuthorshipInfo) { + updateTabAuthorshipInfo(state: StoreState, info: AuthorshipInfo): void { state.tabAuthorshipInfo = info; }, - updateSummaryDates(state: StoreState, info: SummaryDates) { + updateSummaryDates(state: StoreState, info: SummaryDates): void { state.summaryDates = info; }, - updateFileTypeColors(state: StoreState, info: { [key: string]: string }) { + updateFileTypeColors(state: StoreState, info: { [key: string]: string }): void { state.fileTypeColors = info; }, - updateAuthorColors(state: StoreState, info: { [key: string]: string }) { + updateAuthorColors(state: StoreState, info: { [key: string]: string }): void { state.tabAuthorColors = info; }, - updateMergedGroup(state: StoreState, info: string[]) { + updateMergedGroup(state: StoreState, info: string[]): void { state.mergedGroups = info; }, - incrementLoadingOverlayCount(state: StoreState, increment: number) { + incrementLoadingOverlayCount(state: StoreState, increment: number): void { state.loadingOverlayCount += increment; if (state.loadingOverlayCount === 0) { state.loadingOverlayMessage = 'Loading. Please wait...'; } }, - updateLoadingOverlayMessage(state: StoreState, message: string) { + updateLoadingOverlayMessage(state: StoreState, message: string): void { state.loadingOverlayMessage = message; }, - updateTabState(state: StoreState, isTabOpen: boolean) { + updateTabState(state: StoreState, isTabOpen: boolean): void { state.isTabActive = isTabOpen; window.addHash('tabOpen', isTabOpen.toString()); if (!isTabOpen) { @@ -55,12 +55,12 @@ export default createStore({ } window.encodeHash(); }, - toggleZoomCommitMessageBody(_, slice: CommitResult) { + toggleZoomCommitMessageBody(_, slice: CommitResult): void { if (slice.isOpen !== undefined) { slice.isOpen = !slice.isOpen; } }, - setAllZoomCommitMessageBody(_, { isOpen, commits }: { isOpen: boolean; commits: DailyCommit[] }) { + setAllZoomCommitMessageBody(_, { isOpen, commits }: { isOpen: boolean; commits: DailyCommit[] }): void { commits.forEach((commit) => { commit.commitResults.forEach((slice) => { if (slice.isOpen !== undefined) { @@ -69,14 +69,14 @@ export default createStore({ }); }); }, - updateTabAuthorshipFiles(state: StoreState, files: AuthorshipFile[]) { + updateTabAuthorshipFiles(state: StoreState, files: AuthorshipFile[]): void { state.tabAuthorshipInfo.files.splice(0, state.tabAuthorshipInfo.files.length, ...files); }, - toggleAuthorshipFileActiveProperty(_, file: AuthorshipFile) { + toggleAuthorshipFileActiveProperty(_, file: AuthorshipFile): void { file.active = !file.active; file.wasCodeLoaded = file.wasCodeLoaded || file.active; }, - setAllAuthorshipFileActiveProperty(_, { isActive, files }: { isActive: boolean; files: AuthorshipFile[] }) { + setAllAuthorshipFileActiveProperty(_, { isActive, files }: { isActive: boolean; files: AuthorshipFile[] }): void { files.forEach((file) => { file.active = isActive; file.wasCodeLoaded = file.wasCodeLoaded || file.active; @@ -86,7 +86,7 @@ export default createStore({ actions: { // Actions are called with dispatch - async incrementLoadingOverlayCountForceReload({ commit }, increment: number) { + async incrementLoadingOverlayCountForceReload({ commit }, increment: number): Promise { commit('incrementLoadingOverlayCount', increment); await new Promise(window.requestAnimationFrame); await new Promise(window.requestAnimationFrame); From 80a22b601f452ac90626c2320cf86e1f432d747e Mon Sep 17 00:00:00 2001 From: supermii2 Date: Mon, 19 Feb 2024 13:24:57 +0800 Subject: [PATCH 04/16] Add return types to frontend views --- frontend/src/views/c-authorship.vue | 56 +++++++++--- frontend/src/views/c-home.vue | 8 +- frontend/src/views/c-summary.vue | 128 +++++++++++++++++----------- frontend/src/views/c-zoom.vue | 60 ++++++++----- 4 files changed, 163 insertions(+), 89 deletions(-) diff --git a/frontend/src/views/c-authorship.vue b/frontend/src/views/c-authorship.vue index b901e8f4fe..e046f07ebc 100644 --- a/frontend/src/views/c-authorship.vue +++ b/frontend/src/views/c-authorship.vue @@ -214,7 +214,23 @@ const filesSortDict = { fileType: (file: AuthorshipFile) => file.fileType, }; -function authorshipInitialState() { +function authorshipInitialState(): { + isLoaded: boolean, + selectedFiles: Array, + filterType: FilterType, + selectedFileTypes: Array, + fileTypes: Array + filesLinesObj: {[key: string]: number} + fileTypeBlankLinesObj: { [key: string]: number }, + filesSortType: FilesSortType, + toReverseSortFiles: boolean, + isBinaryFilesChecked: boolean, + isIgnoredFilesChecked: boolean, + searchBarValue: string, + authorDisplayName: string, + authors: Set, + selectedColors: Array + } { return { isLoaded: false, selectedFiles: [] as Array, @@ -246,7 +262,23 @@ export default defineComponent({ emits: [ 'deactivate-tab', ], - data() { + data(): { + isLoaded: boolean, + selectedFiles: Array, + filterType: FilterType, + selectedFileTypes: Array, + fileTypes: Array + filesLinesObj: {[key: string]: number} + fileTypeBlankLinesObj: { [key: string]: number }, + filesSortType: FilesSortType, + toReverseSortFiles: boolean, + isBinaryFilesChecked: boolean, + isIgnoredFilesChecked: boolean, + searchBarValue: string, + authorDisplayName: string, + authors: Set, + selectedColors: Array + } { return authorshipInitialState(); }, @@ -260,7 +292,7 @@ export default defineComponent({ get(): boolean { return this.selectedFileTypes.length === this.fileTypes.length; }, - set(value: boolean) { + set(value: boolean): void { if (value) { this.selectedFileTypes = this.fileTypes.slice(); } else { @@ -275,7 +307,7 @@ export default defineComponent({ get(): boolean { return this.isBinaryFilesChecked; }, - set(value: boolean) { + set(value: boolean): void { if (value) { this.isBinaryFilesChecked = true; } else { @@ -291,7 +323,7 @@ export default defineComponent({ get(): boolean { return this.isIgnoredFilesChecked; }, - set(value: boolean) { + set(value: boolean): void { if (value) { this.isIgnoredFilesChecked = true; } else { @@ -341,13 +373,13 @@ export default defineComponent({ }, watch: { - filesSortType() { + filesSortType(): void { window.addHash('authorshipSortBy', this.filesSortType); window.encodeHash(); this.updateSelectedFiles(); }, - searchBarValue() { + searchBarValue(): void { this.updateSelectedFiles(); }, @@ -358,23 +390,23 @@ export default defineComponent({ }, }, - toReverseSortFiles() { + toReverseSortFiles(): void { window.addHash('reverseAuthorshipOrder', this.toReverseSortFiles); window.encodeHash(); this.updateSelectedFiles(); }, - info() { + info(): void { Object.assign(this.$data, authorshipInitialState()); this.initiate(); }, }, - created() { + created(): void { this.initiate(); }, - beforeUnmount() { + beforeUnmount(): void { this.removeAuthorshipHashes(); }, @@ -769,7 +801,7 @@ export default defineComponent({ return `${file.lineCount} (${file.lineCount - (file.blankLineCount ?? 0)})`; }, - getFontColor(color: string) { + getFontColor(color: string): string { return window.getFontColor(color); }, }, diff --git a/frontend/src/views/c-home.vue b/frontend/src/views/c-home.vue index 87a21d82cc..e0154c6b19 100644 --- a/frontend/src/views/c-home.vue +++ b/frontend/src/views/c-home.vue @@ -121,7 +121,7 @@ const home = defineComponent({ }, }, methods: { - getRepoSenseHomeLink() { + getRepoSenseHomeLink(): string { const version = window.repoSenseVersion; if (!version) { return `${window.HOME_PAGE_URL}/RepoSense/`; @@ -129,7 +129,7 @@ const home = defineComponent({ return `${window.HOME_PAGE_URL}`; }, - getSpecificCommitLink() { + getSpecificCommitLink(): string { const version = window.repoSenseVersion; if (!version) { return `${window.REPOSENSE_REPO_URL}`; @@ -140,7 +140,7 @@ const home = defineComponent({ return `${window.REPOSENSE_REPO_URL}/commit/${version}`; }, - getUserGuideLink() { + getUserGuideLink(): string { const version = window.repoSenseVersion; if (!version) { return `${window.HOME_PAGE_URL}/RepoSense/ug/index.html`; @@ -148,7 +148,7 @@ const home = defineComponent({ return `${window.HOME_PAGE_URL}/ug/index.html`; }, - getUsingReportsUserGuideLink() { + getUsingReportsUserGuideLink(): string { const version = window.repoSenseVersion; if (!version) { return `${window.HOME_PAGE_URL}/RepoSense/ug/usingReports.html`; diff --git a/frontend/src/views/c-summary.vue b/frontend/src/views/c-summary.vue index 1d8887f45e..f09e4ffcb8 100644 --- a/frontend/src/views/c-summary.vue +++ b/frontend/src/views/c-summary.vue @@ -174,7 +174,33 @@ export default defineComponent({ default: false, }, }, - data() { + data(): { + checkedFileTypes: Array, + fileTypes: Array, + filtered: Array>, + filterSearch: string, + filterGroupSelection: FilterGroupSelection, + sortGroupSelection: SortGroupSelection, + sortWithinGroupSelection: SortWithinGroupSelection, + sortingOption: string, + isSortingDsc: string, + sortingWithinOption: string, + isSortingWithinDsc: string, + filterTimeFrame: FilterTimeFrame, + filterBreakdown: boolean, + tmpFilterSinceDate: string, + tmpFilterUntilDate: string, + hasModifiedSinceDate: boolean, + hasModifiedUntilDate: boolean, + filterHash: string, + minDate: string, + maxDate: string, + fileTypeColors: { [key: string]: string }, + isSafariBrowser: boolean, + filterGroupSelectionWatcherFlag: boolean, + chartGroupIndex: number | undefined, + chartIndex: number | undefined, + } { return { checkedFileTypes: [] as Array, fileTypes: [] as Array, @@ -205,10 +231,10 @@ export default defineComponent({ }, computed: { checkAllFileTypes: { - get() { + get(): boolean { return this.checkedFileTypes.length === this.fileTypes.length; }, - set(value: boolean) { + set(value: boolean): void { if (value) { this.checkedFileTypes = this.fileTypes.slice(); } else { @@ -218,7 +244,7 @@ export default defineComponent({ }, }, - avgContributionSize() { + avgContributionSize(): number { let totalLines = 0; let totalCount = 0; this.repos.forEach((repo) => { @@ -240,13 +266,13 @@ export default defineComponent({ }, allGroupsMerged: { - get() { + get(): boolean { if (this.mergedGroups.length === 0) { return false; } return this.mergedGroups.length === this.filtered.length; }, - set(value: boolean) { + set(value: boolean): void { if (value) { const mergedGroups: Array = []; this.filtered.forEach((group) => { @@ -260,7 +286,7 @@ export default defineComponent({ }, }, - filterSinceDate() { + filterSinceDate(): string { if (this.tmpFilterSinceDate && this.tmpFilterSinceDate >= this.minDate) { return this.tmpFilterSinceDate; } @@ -268,7 +294,7 @@ export default defineComponent({ return this.minDate; }, - filterUntilDate() { + filterUntilDate(): string { if (this.tmpFilterUntilDate && this.tmpFilterUntilDate <= this.maxDate) { return this.tmpFilterUntilDate; } @@ -279,7 +305,7 @@ export default defineComponent({ }, watch: { - filterGroupSelection() { + filterGroupSelection(): void { // Deactivates watcher if (!this.filterGroupSelectionWatcherFlag) { return; @@ -293,7 +319,7 @@ export default defineComponent({ }); }, - '$store.state.summaryDates': function () { + '$store.state.summaryDates': function (): void { this.hasModifiedSinceDate = true; this.hasModifiedUntilDate = true; this.tmpFilterSinceDate = this.$store.state.summaryDates.since; @@ -304,12 +330,12 @@ export default defineComponent({ mergedGroups: { deep: true, - handler() { + handler(): void { this.getFiltered(); }, }, }, - created() { + created(): void { this.processFileTypes(); this.renderFilterHash(); this.getFiltered(); @@ -318,7 +344,7 @@ export default defineComponent({ this.restoreZoomFiltered(zoomInfo); } }, - mounted() { + mounted(): void { // Delay execution of filterGroupSelection watcher // to prevent clearing of merged groups setTimeout(() => { @@ -326,47 +352,47 @@ export default defineComponent({ }, 0); }, methods: { - dismissTab(event: Event) { + dismissTab(event: Event): void { if (event.target instanceof Element && event.target.parentNode instanceof HTMLElement) { event.target.parentNode.style.display = 'none'; } }, // view functions // - getReportIssueGitHubLink(stackTrace: string) { + getReportIssueGitHubLink(stackTrace: string): string { return `${window.REPOSENSE_REPO_URL}/issues/new?title=${this.getReportIssueTitle() }&body=${this.getReportIssueMessage(stackTrace)}`; }, - getReportIssueEmailAddress() { + getReportIssueEmailAddress(): string { return 'seer@comp.nus.edu.sg'; }, - getReportIssueEmailLink(stackTrace: string) { + getReportIssueEmailLink(stackTrace: string): string { return `mailto:${this.getReportIssueEmailAddress()}?subject=${this.getReportIssueTitle() }&body=${this.getReportIssueMessage(stackTrace)}`; }, - getReportIssueTitle() { + getReportIssueTitle(): string { return `${encodeURI('Unexpected error with RepoSense version ')}${window.repoSenseVersion}`; }, - getReportIssueMessage(message: string) { + getReportIssueMessage(message: string): string { return encodeURI(message); }, // model functions // - resetFilterSearch() { + resetFilterSearch(): void { this.filterSearch = ''; this.getFiltered(); }, - updateFilterSearch(evt: Event) { + updateFilterSearch(evt: Event): void { // Only called from an input onchange event, target guaranteed to be input element this.filterSearch = (evt.target as HTMLInputElement).value; this.getFiltered(); }, - setSummaryHash() { + setSummaryHash(): void { const { addHash, encodeHash } = window; addHash('search', this.filterSearch); @@ -404,7 +430,7 @@ export default defineComponent({ encodeHash(); }, - renderFilterHash() { + renderFilterHash(): void { const convertBool = (txt: string) => (txt === 'true'); const hash = Object.assign({}, window.hashParams); @@ -451,18 +477,18 @@ export default defineComponent({ } }, - getGroupName(group: Array) { + getGroupName(group: Array): string { return window.getGroupName(group, this.filterGroupSelection); }, - isMatchSearchedUser(filterSearch: string, user: User) { + isMatchSearchedUser(filterSearch: string, user: User): boolean { return !filterSearch || filterSearch.toLowerCase() .split(' ') .filter(Boolean) .some((param) => user.searchPath.includes(param)); }, - toggleBreakdown() { + toggleBreakdown(): void { // Reset the file type filter if (this.checkedFileTypes.length !== this.fileTypes.length) { this.checkedFileTypes = this.fileTypes.slice(); @@ -470,7 +496,7 @@ export default defineComponent({ this.getFiltered(); }, - async getFiltered() { + async getFiltered(): Promise { this.setSummaryHash(); window.deactivateAllOverlays(); @@ -480,7 +506,7 @@ export default defineComponent({ this.$store.commit('incrementLoadingOverlayCount', -1); }, - getFilteredRepos() { + getFilteredRepos(): void { // array of array, sorted by repo const full: Array> = []; @@ -521,7 +547,7 @@ export default defineComponent({ this.filtered = sortFiltered(this.filtered, filterControl); }, - updateMergedGroup(allGroupsMerged: boolean) { + updateMergedGroup(allGroupsMerged: boolean): void { // merge group is not allowed when group by none // also reset merged groups if (this.filterGroupSelection === 'groupByNone' || !allGroupsMerged) { @@ -535,7 +561,7 @@ export default defineComponent({ } }, - getMergedRepos() { + getMergedRepos(): void { this.filtered.forEach((group, groupIndex) => { if (this.mergedGroups.includes(this.getGroupName(group))) { this.mergeGroupByIndex(this.filtered, groupIndex); @@ -543,7 +569,7 @@ export default defineComponent({ }); }, - mergeGroupByIndex(filtered: Array>, groupIndex: number) { + mergeGroupByIndex(filtered: Array>, groupIndex: number): void { const dateToIndexMap: { [key: string]: number } = {}; const dailyIndexMap: { [key: string]: number } = {}; const mergedCommits: Array = []; @@ -575,7 +601,7 @@ export default defineComponent({ filtered[groupIndex] = filtered[groupIndex].slice(0, 1); }, - hasMergedGroups() { + hasMergedGroups(): boolean { return this.mergedGroups.length > 0; }, @@ -584,7 +610,7 @@ export default defineComponent({ user: User, dateToIndexMap: { [key: string]: number }, merged: Array | Array, - ) { + ): void { const { commitResults, date, } = commit; @@ -611,7 +637,7 @@ export default defineComponent({ } }, - mergeFileTypeContribution(user: User, merged: AuthorFileTypeContributions) { + mergeFileTypeContribution(user: User, merged: AuthorFileTypeContributions): void { Object.entries(user.fileTypeContribution).forEach((fileType) => { const key = fileType[0]; const value = fileType[1]; @@ -623,7 +649,7 @@ export default defineComponent({ }); }, - processFileTypes() { + processFileTypes(): void { const selectedColors = ['#ffe119', '#4363d8', '#3cb44b', '#f58231', '#911eb4', '#46f0f0', '#f032e6', '#bcf60c', '#fabebe', '#008080', '#e6beff', '#9a6324', '#fffac8', '#800000', '#aaffc3', '#808000', '#ffd8b1', '#000075', '#808080']; @@ -653,7 +679,7 @@ export default defineComponent({ this.$store.commit('updateFileTypeColors', this.fileTypeColors); }, - splitCommitsWeek(user: User, sinceDate: string, untilDate: string) { + splitCommitsWeek(user: User, sinceDate: string, untilDate: string): void { const { commits } = user; if (commits === undefined) { return; @@ -676,7 +702,7 @@ export default defineComponent({ user.commits = res; }, - pushCommitsWeek(sinceMs: number, untilMs: number, res: Array, commits: Array) { + pushCommitsWeek(sinceMs: number, untilMs: number, res: Array, commits: Array): void { const diff = Math.round(Math.abs((untilMs - sinceMs) / window.DAY_IN_MS)); const weekInMS = window.DAY_IN_MS * 7; @@ -700,7 +726,7 @@ export default defineComponent({ } }, - addLineContributionWeek(endOfWeekMs: number, week: Commit, commits: Array) { + addLineContributionWeek(endOfWeekMs: number, week: Commit, commits: Array): void { // commits are not contiguous, meaning there are gaps of days without // commits, so we are going to check each commit's date and make sure // it is within the duration of a week @@ -718,7 +744,7 @@ export default defineComponent({ } }, - getUserCommits(user: User, sinceDate: string, untilDate: string) { + getUserCommits(user: User, sinceDate: string, untilDate: string): null { user.commits = []; const userFirst = user.dailyCommits[0]; const userLast = user.dailyCommits[user.dailyCommits.length - 1]; @@ -757,7 +783,7 @@ export default defineComponent({ return null; }, - filterCommitByCheckedFileTypes(commit: DailyCommit) { + filterCommitByCheckedFileTypes(commit: DailyCommit): void { let commitResults = commit.commitResults.map((result) => { const filteredFileTypes = this.getFilteredFileTypes(result); this.updateCommitResultWithFileTypes(result, filteredFileTypes); @@ -776,7 +802,7 @@ export default defineComponent({ commit.commitResults = commitResults; }, - getFilteredFileTypes(commitResult: CommitResult) { + getFilteredFileTypes(commitResult: CommitResult): { [key: string]: { insertions: number; deletions: number; }; } { return Object.keys(commitResult.fileTypesAndContributionMap) .filter(this.isFileTypeChecked) .reduce((obj: { [key: string]: FileTypeAndContribution }, fileType) => { @@ -785,7 +811,7 @@ export default defineComponent({ }, {}); }, - isFileTypeChecked(fileType: string) { + isFileTypeChecked(fileType: string): boolean { if (this.filterBreakdown) { return this.checkedFileTypes.includes(fileType); } @@ -795,7 +821,7 @@ export default defineComponent({ updateCommitResultWithFileTypes( commitResult: CommitResult, filteredFileTypes: { [key: string]: FileTypeAndContribution }, - ) { + ): void { commitResult.insertions = Object.values(filteredFileTypes) .reduce((acc, fileType) => acc + fileType.insertions, 0); commitResult.deletions = Object.values(filteredFileTypes) @@ -803,13 +829,13 @@ export default defineComponent({ commitResult.fileTypesAndContributionMap = filteredFileTypes; }, - getOptionWithOrder() { + getOptionWithOrder(): void { [this.sortingOption, this.isSortingDsc] = this.sortGroupSelection.split(' '); [this.sortingWithinOption, this.isSortingWithinDsc] = this.sortWithinGroupSelection.split(' '); }, // updating filters programically // - resetDateRange() { + resetDateRange(): void { this.hasModifiedSinceDate = false; this.hasModifiedUntilDate = false; this.tmpFilterSinceDate = ''; @@ -819,7 +845,7 @@ export default defineComponent({ this.getFiltered(); }, - updateTmpFilterSinceDate(event: Event) { + updateTmpFilterSinceDate(event: Event): void { // Only called from an input onchange event, target guaranteed to be input element const since = (event.target as HTMLInputElement).value; this.hasModifiedSinceDate = true; @@ -838,7 +864,7 @@ export default defineComponent({ } }, - updateTmpFilterUntilDate(event: Event) { + updateTmpFilterUntilDate(event: Event): void { // Only called from an input onchange event, target guaranteed to be input element const until = (event.target as HTMLInputElement).value; this.hasModifiedUntilDate = true; @@ -857,7 +883,7 @@ export default defineComponent({ } }, - updateCheckedFileTypeContribution(ele: User) { + updateCheckedFileTypeContribution(ele: User): void { let validCommits = 0; Object.keys(ele.fileTypeContribution).forEach((fileType) => { if (!this.filterBreakdown) { @@ -869,7 +895,7 @@ export default defineComponent({ ele.checkedFileTypeContribution = validCommits; }, - restoreZoomFiltered(info: ZoomInfo) { + restoreZoomFiltered(info: ZoomInfo): void { const { zSince, zUntil, zTimeFrame, zIsMerged, zFilterSearch, } = info; @@ -904,7 +930,7 @@ export default defineComponent({ info.isRefreshing = false; this.$store.commit('updateTabZoomInfo', info); }, - matchZoomUser(info: ZoomInfo, user: User) { + matchZoomUser(info: ZoomInfo, user: User): boolean { const { zIsMerged, zFilterGroup, zRepo, zAuthor, } = info; @@ -916,7 +942,7 @@ export default defineComponent({ return user.repoName === zRepo && user.name === zAuthor; }, - dateRounding(datestr: string, roundDown: number) { + dateRounding(datestr: string, roundDown: number): string { // rounding up to nearest monday const date = new Date(datestr); const day = date.getUTCDay(); diff --git a/frontend/src/views/c-zoom.vue b/frontend/src/views/c-zoom.vue index 51494f0b92..74e95398bc 100644 --- a/frontend/src/views/c-zoom.vue +++ b/frontend/src/views/c-zoom.vue @@ -164,7 +164,15 @@ import { import CommitsSortType from '../types/zoom'; import { StoreState } from '../types/vuex.d'; -function zoomInitialState() { +function zoomInitialState(): { + showAllCommitMessageBody: boolean, + showDiffstat: boolean, + commitsSortType: CommitsSortType, + toReverseSortedCommits: boolean, + isCommitsFinalized: boolean, + selectedFileTypes: Array, + fileTypes: Array, + } { return { showAllCommitMessageBody: true, showDiffstat: true, @@ -184,7 +192,15 @@ export default defineComponent({ cStackedBarChart, }, mixins: [brokenLinkDisabler, tooltipPositioner], - data() { + data(): { + showAllCommitMessageBody: boolean, + showDiffstat: boolean, + commitsSortType: CommitsSortType, + toReverseSortedCommits: boolean, + isCommitsFinalized: boolean, + selectedFileTypes: Array, + fileTypes: Array, + } { return { ...zoomInitialState(), }; @@ -280,10 +296,10 @@ export default defineComponent({ ), 0); }, isSelectAllChecked: { - get() { + get(): boolean { return this.selectedFileTypes.length === this.fileTypes.length; }, - set(value: boolean) { + set(value: boolean): void { if (value) { this.selectedFileTypes = this.fileTypes.slice(); } else { @@ -300,7 +316,7 @@ export default defineComponent({ }, watch: { - info() { + info(): void { const newData = { ...zoomInitialState(), }; @@ -308,26 +324,26 @@ export default defineComponent({ this.initiate(); this.setInfoHash(); }, - commitsSortType() { + commitsSortType(): void { window.addHash('zCST', this.commitsSortType); window.encodeHash(); }, - toReverseSortedCommits() { + toReverseSortedCommits(): void { window.addHash('zRSC', this.toReverseSortedCommits.toString()); window.encodeHash(); }, }, - created() { + created(): void { this.initiate(); this.retrieveHashes(); this.setInfoHash(); }, - beforeUnmount() { + beforeUnmount(): void { this.removeZoomHashes(); }, methods: { - initiate() { + initiate(): void { // This code crashes if info.zUser is not defined this.updateFileTypes(); this.selectedFileTypes = this.fileTypes.slice(); @@ -396,14 +412,14 @@ export default defineComponent({ return window.getCommitLink(this.info.zUser!.repoId, slice.hash); }, - scrollToCommit(tag: string, commit: string) { + scrollToCommit(tag: string, commit: string): void { const el = this.$el.getElementsByClassName(`${commit} ${tag}`)[0]; if (el) { el.focus(); } }, - updateFileTypes() { + updateFileTypes(): void { const commitsFileTypes = new Set(); this.filteredUser.commits.forEach((commit) => { commit.commitResults.forEach((slice) => { @@ -417,12 +433,12 @@ export default defineComponent({ ); }, - retrieveHashes() { + retrieveHashes(): void { this.retrieveSortHash(); this.retrieveSelectedFileTypesHash(); }, - retrieveSortHash() { + retrieveSortHash(): void { const hash = window.hashParams; if (hash.zCST && Object.values(CommitsSortType).includes(hash.zCST as CommitsSortType)) { this.commitsSortType = hash.zCST as CommitsSortType; @@ -432,7 +448,7 @@ export default defineComponent({ } }, - retrieveSelectedFileTypesHash() { + retrieveSelectedFileTypesHash(): void { const hash = window.hashParams; if (hash.zFT || hash.zFT === '') { @@ -442,7 +458,7 @@ export default defineComponent({ } }, - updateSelectedFileTypesHash() { + updateSelectedFileTypesHash(): void { const fileTypeHash = this.selectedFileTypes.length > 0 ? this.selectedFileTypes.reduce((a, b) => `${a}~${b}`) : ''; @@ -451,7 +467,7 @@ export default defineComponent({ window.encodeHash(); }, - setInfoHash() { + setInfoHash(): void { const { addHash, encodeHash } = window; const { zAvgCommitSize, zSince, zUntil, zFilterGroup, @@ -470,11 +486,11 @@ export default defineComponent({ encodeHash(); }, - toggleSelectedCommitMessageBody(slice: CommitResult) { + toggleSelectedCommitMessageBody(slice: CommitResult): void { this.$store.commit('toggleZoomCommitMessageBody', slice); }, - toggleAllCommitMessagesBody(isOpen: boolean) { + toggleAllCommitMessagesBody(isOpen: boolean): void { this.showAllCommitMessageBody = isOpen; this.$store.commit('setAllZoomCommitMessageBody', { isOpen, @@ -482,11 +498,11 @@ export default defineComponent({ }); }, - toggleDiffstatView(isVisible: boolean) { + toggleDiffstatView(isVisible: boolean): void { this.showDiffstat = isVisible; }, - removeZoomHashes() { + removeZoomHashes(): void { window.removeHash('zA'); window.removeHash('zR'); window.removeHash('zFS'); @@ -511,7 +527,7 @@ export default defineComponent({ return false; }, - getFontColor(color: string) { + getFontColor(color: string): string { return window.getFontColor(color); }, }, From b09a78741bb5750bba12af20d090ab1fb3a52573 Mon Sep 17 00:00:00 2001 From: supermii2 Date: Mon, 19 Feb 2024 13:32:08 +0800 Subject: [PATCH 05/16] Add return types to frontend app --- frontend/src/app.vue | 37 +++++++++++++++++++++++-------------- 1 file changed, 23 insertions(+), 14 deletions(-) diff --git a/frontend/src/app.vue b/frontend/src/app.vue index 24651b6390..0dc2424b8a 100644 --- a/frontend/src/app.vue +++ b/frontend/src/app.vue @@ -38,7 +38,16 @@ const app = defineComponent({ components: { LoadingOverlay, }, - data() { + data(): { + repos: { [key: string]: Repo }, + users: Array + userUpdated: boolean, + loadingOverlayOpacity: number, + tabType: string, + creationDate: string, + reportGenerationTime: string, + errorMessages: {[key: string]: ErrorMessage } + } { return { repos: {} as { [key: string]: Repo }, users: [] as Array, @@ -56,17 +65,17 @@ const app = defineComponent({ ...mapState(['loadingOverlayCount', 'loadingOverlayMessage', 'isTabActive']), }, watch: { - '$store.state.tabZoomInfo': function () { + '$store.state.tabZoomInfo': function (): void { if (this.$store.state.tabZoomInfo.isRefreshing) { return; } this.activateTab('zoom'); }, - '$store.state.tabAuthorshipInfo': function () { + '$store.state.tabAuthorshipInfo': function (): void { this.activateTab('authorship'); }, }, - created() { + created(): void { try { window.decodeHash(); } catch (error) { @@ -76,7 +85,7 @@ const app = defineComponent({ }, methods: { // model functions // - updateReportZip(evt: Event) { + updateReportZip(evt: Event): void { this.users = []; const target = evt.target as HTMLInputElement; if (target.files === null) { @@ -92,14 +101,14 @@ const app = defineComponent({ .then(() => this.updateReportView()); }, - updateReportDir() { + updateReportDir(): void { window.REPORT_ZIP = null; this.users = []; this.updateReportView(); }, - async updateReportView() { + async updateReportView(): Promise { this.$store.commit('updateLoadingOverlayMessage', loadingResourcesMessage); this.userUpdated = false; await this.$store.dispatch('incrementLoadingOverlayCountForceReload', 1); @@ -131,7 +140,7 @@ const app = defineComponent({ this.$store.commit('incrementLoadingOverlayCount', -1); } }, - getUsers() { + getUsers(): void { const full: Array = []; Object.keys(this.repos).forEach((repo) => { if (this.repos[repo].users) { @@ -142,7 +151,7 @@ const app = defineComponent({ }, // handle opening of sidebar // - activateTab(tabName: string) { + activateTab(tabName: string): void { if (this.$refs.tabWrapper) { (this.$refs.tabWrapper as HTMLElement).scrollTop = 0; } @@ -153,7 +162,7 @@ const app = defineComponent({ window.encodeHash(); }, - renderAuthorShipTabHash(minDate: string, maxDate: string) { + renderAuthorShipTabHash(minDate: string, maxDate: string): void { const hash = window.hashParams; const info: AuthorshipInfo = { author: hash.tabAuthor, @@ -173,7 +182,7 @@ const app = defineComponent({ } }, - renderZoomTabHash() { + renderZoomTabHash(): void { const hash = window.hashParams; const zoomInfo: ZoomInfo = { isRefreshing: true, @@ -196,7 +205,7 @@ const app = defineComponent({ } }, - renderTabHash() { + renderTabHash(): void { const hash = window.hashParams; if (!hash.tabOpen) { return; @@ -217,7 +226,7 @@ const app = defineComponent({ } }, - getRepoSenseHomeLink() { + getRepoSenseHomeLink(): string { const version = window.repoSenseVersion; if (!version) { return `${window.HOME_PAGE_URL}/RepoSense/`; @@ -225,7 +234,7 @@ const app = defineComponent({ return `${window.HOME_PAGE_URL}`; }, - getRepoLink() { + getRepoLink(): string | undefined { const { REPOS, hashParams } = window; const { location, branch } = REPOS[hashParams.tabRepo]; From 7e21c94b52bb4628397ff8e97716099f485d43ac Mon Sep 17 00:00:00 2001 From: supermii2 Date: Mon, 19 Feb 2024 13:34:12 +0800 Subject: [PATCH 06/16] Fix style problem in app.vue --- frontend/src/app.vue | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frontend/src/app.vue b/frontend/src/app.vue index 0dc2424b8a..533f3f30a4 100644 --- a/frontend/src/app.vue +++ b/frontend/src/app.vue @@ -47,7 +47,7 @@ const app = defineComponent({ creationDate: string, reportGenerationTime: string, errorMessages: {[key: string]: ErrorMessage } - } { + } { return { repos: {} as { [key: string]: Repo }, users: [] as Array, From 2a59ffe590b248ea119bb2574a2228613f3ca625 Mon Sep 17 00:00:00 2001 From: supermii2 Date: Mon, 4 Mar 2024 13:28:14 +0800 Subject: [PATCH 07/16] Fix formatting issues with typescript types --- frontend/src/components/c-ramp.vue | 2 +- frontend/src/components/c-summary-charts.vue | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/frontend/src/components/c-ramp.vue b/frontend/src/components/c-ramp.vue index 7f80fadb19..65e1fe780c 100644 --- a/frontend/src/components/c-ramp.vue +++ b/frontend/src/components/c-ramp.vue @@ -191,7 +191,7 @@ export default defineComponent({ } return this.getSliceColor(slice); }, - getSliceColor(slice: Commit) { + getSliceColor(slice: Commit): number | '-deletes' { if (this.isDeletesContribution(slice)) { return '-deletes'; } diff --git a/frontend/src/components/c-summary-charts.vue b/frontend/src/components/c-summary-charts.vue index 53fc565cca..e017ec6045 100644 --- a/frontend/src/components/c-summary-charts.vue +++ b/frontend/src/components/c-summary-charts.vue @@ -373,7 +373,7 @@ export default defineComponent({ }, }, data(): { - drags: Array, + drags: Array, activeRepo: string | null, activeUser: string | null, activeTabType: string | null, From 452e4b26cfedf98c30e8fa573a6e9977423b140d Mon Sep 17 00:00:00 2001 From: Alvis Ng Date: Mon, 11 Mar 2024 12:16:33 +0800 Subject: [PATCH 08/16] Test Commit to switch branch in closed PR Commit to be reverted later --- frontend/src/main.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frontend/src/main.ts b/frontend/src/main.ts index e419f9492d..95962e2237 100644 --- a/frontend/src/main.ts +++ b/frontend/src/main.ts @@ -8,7 +8,7 @@ import 'muicss/dist/css/mui.min.css'; import 'normalize.css/normalize.css'; import 'vue-loading-overlay/dist/vue-loading.css'; import '@fontsource/titillium-web'; - +// // Need to import for side effects import './utils/api'; import './utils/safari_date'; From 85a12fd6eafba4e1a78f6b4224d451e103597093 Mon Sep 17 00:00:00 2001 From: supermii2 Date: Mon, 11 Mar 2024 13:26:30 +0800 Subject: [PATCH 09/16] Add missing spaces between braces --- frontend/src/app.vue | 2 +- frontend/src/views/c-authorship.vue | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/frontend/src/app.vue b/frontend/src/app.vue index 533f3f30a4..65ea1c248c 100644 --- a/frontend/src/app.vue +++ b/frontend/src/app.vue @@ -46,7 +46,7 @@ const app = defineComponent({ tabType: string, creationDate: string, reportGenerationTime: string, - errorMessages: {[key: string]: ErrorMessage } + errorMessages: { [key: string]: ErrorMessage } } { return { repos: {} as { [key: string]: Repo }, diff --git a/frontend/src/views/c-authorship.vue b/frontend/src/views/c-authorship.vue index 5fe496e84c..f7e847f204 100644 --- a/frontend/src/views/c-authorship.vue +++ b/frontend/src/views/c-authorship.vue @@ -131,7 +131,7 @@ function authorshipInitialState(): { filterType: FilterType, selectedFileTypes: Array, fileTypes: Array - filesLinesObj: {[key: string]: number} + filesLinesObj: { [key: string]: number} fileTypeBlankLinesObj: { [key: string]: number }, filesSortType: FilesSortType, toReverseSortFiles: boolean, @@ -179,7 +179,7 @@ export default defineComponent({ filterType: FilterType, selectedFileTypes: Array, fileTypes: Array - filesLinesObj: {[key: string]: number} + filesLinesObj: { [key: string]: number} fileTypeBlankLinesObj: { [key: string]: number }, filesSortType: FilesSortType, toReverseSortFiles: boolean, From e16e76d2187c6030f3fe0b4267ff4174aa104237 Mon Sep 17 00:00:00 2001 From: supermii2 Date: Wed, 13 Mar 2024 13:34:05 +0800 Subject: [PATCH 10/16] Add return types for anonymous functions --- frontend/src/components/c-resizer.vue | 4 ++-- frontend/src/views/c-authorship.vue | 8 ++++---- frontend/src/views/c-summary.vue | 2 +- frontend/src/views/c-zoom.vue | 8 ++++---- 4 files changed, 11 insertions(+), 11 deletions(-) diff --git a/frontend/src/components/c-resizer.vue b/frontend/src/components/c-resizer.vue index 5a59a6beaa..5ffa046d12 100644 --- a/frontend/src/components/c-resizer.vue +++ b/frontend/src/components/c-resizer.vue @@ -34,9 +34,9 @@ const GUIDE_BAR_WIDTH = 2; * parameters, i.e. an event of type MouseEvent. */ // eslint-disable-next-line no-unused-vars -const throttledEvent = (delay: number, handler: (event: MouseEvent) => unknown) => { +const throttledEvent = (delay: number, handler: (event: MouseEvent) => unknown): ((event: MouseEvent) => void) => { let lastCalled = 0; - return (event: MouseEvent) => { + return (event: MouseEvent): void => { if (Date.now() - lastCalled > delay) { lastCalled = Date.now(); handler(event); diff --git a/frontend/src/views/c-authorship.vue b/frontend/src/views/c-authorship.vue index f7e847f204..44008e9c79 100644 --- a/frontend/src/views/c-authorship.vue +++ b/frontend/src/views/c-authorship.vue @@ -119,10 +119,10 @@ import { AuthorshipFile, AuthorshipFileSegment } from '../types/types'; import { FilesSortType, FilterType } from '../types/authorship'; const filesSortDict = { - linesOfCode: (file: AuthorshipFile) => file.lineCount, - path: (file: AuthorshipFile) => file.path, - fileName: (file: AuthorshipFile) => file.path.split(/[/]+/).pop() || '', - fileType: (file: AuthorshipFile) => file.fileType, + linesOfCode: (file: AuthorshipFile): number => file.lineCount, + path: (file: AuthorshipFile): string => file.path, + fileName: (file: AuthorshipFile): string => file.path.split(/[/]+/).pop() || '', + fileType: (file: AuthorshipFile): string => file.fileType, }; function authorshipInitialState(): { diff --git a/frontend/src/views/c-summary.vue b/frontend/src/views/c-summary.vue index f09e4ffcb8..a7f0bc9c59 100644 --- a/frontend/src/views/c-summary.vue +++ b/frontend/src/views/c-summary.vue @@ -431,7 +431,7 @@ export default defineComponent({ }, renderFilterHash(): void { - const convertBool = (txt: string) => (txt === 'true'); + const convertBool = (txt: string): boolean => (txt === 'true'); const hash = Object.assign({}, window.hashParams); if (hash.search) { this.filterSearch = hash.search; } diff --git a/frontend/src/views/c-zoom.vue b/frontend/src/views/c-zoom.vue index 74e95398bc..3ec12a90b7 100644 --- a/frontend/src/views/c-zoom.vue +++ b/frontend/src/views/c-zoom.vue @@ -209,10 +209,10 @@ export default defineComponent({ computed: { sortingFunction() { const commitSortFunction = this.commitsSortType === CommitsSortType.Time - ? (commit: Commit) => commit.date - : (commit: Commit) => commit.insertions; + ? (commit: Commit): string => commit.date + : (commit: Commit): number => commit.insertions; - return (a: Commit, b: Commit) => (this.toReverseSortedCommits ? -1 : 1) + return (a: Commit, b: Commit): number => (this.toReverseSortedCommits ? -1 : 1) * window.comparator(commitSortFunction)(a, b); }, filteredUser(): User { @@ -247,7 +247,7 @@ export default defineComponent({ ? commit.commitResults.slice().reverse() : commit.commitResults.slice(); } else { - const cResultsSortingFunction = (a: CommitResult, b: CommitResult) => (this.toReverseSortedCommits ? -1 : 1) + const cResultsSortingFunction = (a: CommitResult, b: CommitResult): number => (this.toReverseSortedCommits ? -1 : 1) * window.comparator((cResult: CommitResult) => cResult.insertions)(a, b); newCommit.commitResults = commit.commitResults.slice().sort(cResultsSortingFunction); } From 7647568513c39f0ffc708e74b7d891165fee7ece Mon Sep 17 00:00:00 2001 From: supermii2 Date: Wed, 13 Mar 2024 13:38:32 +0800 Subject: [PATCH 11/16] Fix lines that were too long --- frontend/src/views/c-authorship.vue | 2 +- frontend/src/views/c-zoom.vue | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/frontend/src/views/c-authorship.vue b/frontend/src/views/c-authorship.vue index 44008e9c79..25003381fd 100644 --- a/frontend/src/views/c-authorship.vue +++ b/frontend/src/views/c-authorship.vue @@ -195,7 +195,7 @@ export default defineComponent({ computed: { sortingFunction() { - return (a: AuthorshipFile, b: AuthorshipFile) => (this.toReverseSortFiles ? -1 : 1) + return (a: AuthorshipFile, b: AuthorshipFile): number => (this.toReverseSortFiles ? -1 : 1) * window.comparator(filesSortDict[this.filesSortType])(a, b); }, diff --git a/frontend/src/views/c-zoom.vue b/frontend/src/views/c-zoom.vue index 3ec12a90b7..08a2a5f376 100644 --- a/frontend/src/views/c-zoom.vue +++ b/frontend/src/views/c-zoom.vue @@ -247,8 +247,9 @@ export default defineComponent({ ? commit.commitResults.slice().reverse() : commit.commitResults.slice(); } else { - const cResultsSortingFunction = (a: CommitResult, b: CommitResult): number => (this.toReverseSortedCommits ? -1 : 1) - * window.comparator((cResult: CommitResult) => cResult.insertions)(a, b); + const cResultsSortingFunction = (a: CommitResult, b: CommitResult): number => ( + this.toReverseSortedCommits ? -1 : 1 + ) * window.comparator((cResult: CommitResult) => cResult.insertions)(a, b); newCommit.commitResults = commit.commitResults.slice().sort(cResultsSortingFunction); } tempUser.commits.push(newCommit); From 8d8d342c7c0d41859d01da3f8647e5d0b3adae13 Mon Sep 17 00:00:00 2001 From: supermii2 Date: Wed, 13 Mar 2024 14:58:23 +0800 Subject: [PATCH 12/16] Revert changes to .ts files --- frontend/.eslintrc.json | 4 +++- frontend/src/mixin/brokenLinkMixin.ts | 4 ++-- frontend/src/store/store.ts | 30 +++++++++++++-------------- 3 files changed, 20 insertions(+), 18 deletions(-) diff --git a/frontend/.eslintrc.json b/frontend/.eslintrc.json index 7899f4ecf6..3a2a245692 100644 --- a/frontend/.eslintrc.json +++ b/frontend/.eslintrc.json @@ -97,7 +97,9 @@ "default": "generic", "readonly": "generic" } - ] + ], + "no-unused-vars": "off", + "@typescript-eslint/no-unused-vars": ["error"] } } ] diff --git a/frontend/src/mixin/brokenLinkMixin.ts b/frontend/src/mixin/brokenLinkMixin.ts index 0b9be83603..cda35dbb3c 100644 --- a/frontend/src/mixin/brokenLinkMixin.ts +++ b/frontend/src/mixin/brokenLinkMixin.ts @@ -1,13 +1,13 @@ import { defineComponent } from 'vue'; export default defineComponent({ - data(): { disabledLinkMessage: string } { + data() { return { disabledLinkMessage: 'This remote link is unsupported', }; }, methods: { - isBrokenLink(link: string | undefined): boolean { + isBrokenLink(link: string | undefined) { return link === undefined; }, getLinkMessage(link: string | undefined, linkMessage: string): string { diff --git a/frontend/src/store/store.ts b/frontend/src/store/store.ts index 17106c7b49..c69d2a4204 100644 --- a/frontend/src/store/store.ts +++ b/frontend/src/store/store.ts @@ -20,34 +20,34 @@ export default createStore({ isTabActive: true, } as StoreState, mutations: { - updateTabZoomInfo(state: StoreState, info: ZoomInfo): void { + updateTabZoomInfo(state: StoreState, info: ZoomInfo) { state.tabZoomInfo = info; }, - updateTabAuthorshipInfo(state: StoreState, info: AuthorshipInfo): void { + updateTabAuthorshipInfo(state: StoreState, info: AuthorshipInfo) { state.tabAuthorshipInfo = info; }, - updateSummaryDates(state: StoreState, info: SummaryDates): void { + updateSummaryDates(state: StoreState, info: SummaryDates) { state.summaryDates = info; }, - updateFileTypeColors(state: StoreState, info: { [key: string]: string }): void { + updateFileTypeColors(state: StoreState, info: { [key: string]: string }) { state.fileTypeColors = info; }, - updateAuthorColors(state: StoreState, info: { [key: string]: string }): void { + updateAuthorColors(state: StoreState, info: { [key: string]: string }) { state.tabAuthorColors = info; }, - updateMergedGroup(state: StoreState, info: string[]): void { + updateMergedGroup(state: StoreState, info: string[]) { state.mergedGroups = info; }, - incrementLoadingOverlayCount(state: StoreState, increment: number): void { + incrementLoadingOverlayCount(state: StoreState, increment: number) { state.loadingOverlayCount += increment; if (state.loadingOverlayCount === 0) { state.loadingOverlayMessage = 'Loading. Please wait...'; } }, - updateLoadingOverlayMessage(state: StoreState, message: string): void { + updateLoadingOverlayMessage(state: StoreState, message: string) { state.loadingOverlayMessage = message; }, - updateTabState(state: StoreState, isTabOpen: boolean): void { + updateTabState(state: StoreState, isTabOpen: boolean) { state.isTabActive = isTabOpen; window.addHash('tabOpen', isTabOpen.toString()); if (!isTabOpen) { @@ -55,12 +55,12 @@ export default createStore({ } window.encodeHash(); }, - toggleZoomCommitMessageBody(_, slice: CommitResult): void { + toggleZoomCommitMessageBody(_, slice: CommitResult) { if (slice.isOpen !== undefined) { slice.isOpen = !slice.isOpen; } }, - setAllZoomCommitMessageBody(_, { isOpen, commits }: { isOpen: boolean; commits: DailyCommit[] }): void { + setAllZoomCommitMessageBody(_, { isOpen, commits }: { isOpen: boolean; commits: DailyCommit[] }) { commits.forEach((commit) => { commit.commitResults.forEach((slice) => { if (slice.isOpen !== undefined) { @@ -69,14 +69,14 @@ export default createStore({ }); }); }, - updateTabAuthorshipFiles(state: StoreState, files: AuthorshipFile[]): void { + updateTabAuthorshipFiles(state: StoreState, files: AuthorshipFile[]) { state.tabAuthorshipInfo.files.splice(0, state.tabAuthorshipInfo.files.length, ...files); }, - toggleAuthorshipFileActiveProperty(_, file: AuthorshipFile): void { + toggleAuthorshipFileActiveProperty(_, file: AuthorshipFile) { file.active = !file.active; file.wasCodeLoaded = file.wasCodeLoaded || file.active; }, - setAllAuthorshipFileActiveProperty(_, { isActive, files }: { isActive: boolean; files: AuthorshipFile[] }): void { + setAllAuthorshipFileActiveProperty(_, { isActive, files }: { isActive: boolean; files: AuthorshipFile[] }) { files.forEach((file) => { file.active = isActive; file.wasCodeLoaded = file.wasCodeLoaded || file.active; @@ -86,7 +86,7 @@ export default createStore({ actions: { // Actions are called with dispatch - async incrementLoadingOverlayCountForceReload({ commit }, increment: number): Promise { + async incrementLoadingOverlayCountForceReload({ commit }, increment: number) { commit('incrementLoadingOverlayCount', increment); await new Promise(window.requestAnimationFrame); await new Promise(window.requestAnimationFrame); From c3ac9f616d78c9f1ec8d995cca035da501de2e61 Mon Sep 17 00:00:00 2001 From: Alvis Ng Date: Mon, 1 Apr 2024 00:53:29 +0800 Subject: [PATCH 13/16] Remove extra comment in main.ts --- frontend/src/main.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frontend/src/main.ts b/frontend/src/main.ts index 95962e2237..e419f9492d 100644 --- a/frontend/src/main.ts +++ b/frontend/src/main.ts @@ -8,7 +8,7 @@ import 'muicss/dist/css/mui.min.css'; import 'normalize.css/normalize.css'; import 'vue-loading-overlay/dist/vue-loading.css'; import '@fontsource/titillium-web'; -// + // Need to import for side effects import './utils/api'; import './utils/safari_date'; From 4053ab4bb90a288ff7eff4c05460066f382cb36e Mon Sep 17 00:00:00 2001 From: Alvis Ng Date: Thu, 4 Apr 2024 00:00:25 +0800 Subject: [PATCH 14/16] Remove trailing whitespace from filtered.vue --- frontend/src/views/c-summary.vue | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frontend/src/views/c-summary.vue b/frontend/src/views/c-summary.vue index 037c6c37eb..2015e71600 100644 --- a/frontend/src/views/c-summary.vue +++ b/frontend/src/views/c-summary.vue @@ -971,7 +971,7 @@ export default defineComponent({ if (res.length) { filtered.push(res); } -natural + if (zIsMerged) { this.mergeGroupByIndex(filtered, 0); } From 126e6696f343f851ed1ba847dd1e453269e159dc Mon Sep 17 00:00:00 2001 From: supermii2 Date: Thu, 4 Apr 2024 00:14:46 +0800 Subject: [PATCH 15/16] Add new variables to return type in c-summary --- frontend/src/views/c-summary.vue | 2 ++ 1 file changed, 2 insertions(+) diff --git a/frontend/src/views/c-summary.vue b/frontend/src/views/c-summary.vue index 2015e71600..3d6b8e68d1 100644 --- a/frontend/src/views/c-summary.vue +++ b/frontend/src/views/c-summary.vue @@ -212,6 +212,8 @@ export default defineComponent({ filterGroupSelectionWatcherFlag: boolean, chartGroupIndex: number | undefined, chartIndex: number | undefined, + errorIsShowingMore: boolean, + numberOfErrorMessagesToShow: number } { return { checkedFileTypes: [] as Array, From 77053e1cdb4b81abdca55991328f1aa31c23304c Mon Sep 17 00:00:00 2001 From: David Date: Thu, 4 Apr 2024 15:17:31 +0800 Subject: [PATCH 16/16] add return types to functions in c-zoom-commit-message --- frontend/src/components/c-zoom-commit-message.vue | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/frontend/src/components/c-zoom-commit-message.vue b/frontend/src/components/c-zoom-commit-message.vue index 20ee4f78ff..f0e96cbb9a 100644 --- a/frontend/src/components/c-zoom-commit-message.vue +++ b/frontend/src/components/c-zoom-commit-message.vue @@ -162,7 +162,7 @@ export default defineComponent({ } return window.getCommitLink(this.info.zUser!.repoId, slice.hash); }, - toggleSelectedCommitMessageBody(slice: CommitResult) { + toggleSelectedCommitMessageBody(slice: CommitResult): void { this.$store.commit('toggleZoomCommitMessageBody', slice); }, containsAtLeastOneSelected(fileTypes: Array): boolean { @@ -173,7 +173,7 @@ export default defineComponent({ } return false; }, - getFontColor(color: string) { + getFontColor(color: string): string { return window.getFontColor(color); }, },