From 2efc53029440a6148d1c1f0c35b7f78521cefe8d Mon Sep 17 00:00:00 2001 From: vvidday Date: Sat, 11 Mar 2023 23:50:06 +0800 Subject: [PATCH 01/13] Declare custom module for this.store and add type definitions --- frontend/src/types/types.ts | 20 +++++++++++ frontend/src/types/vuex.d.ts | 64 ++++++++++++++++++++++++++++++++++++ 2 files changed, 84 insertions(+) create mode 100644 frontend/src/types/vuex.d.ts diff --git a/frontend/src/types/types.ts b/frontend/src/types/types.ts index dc4417341a..4e8252de3c 100644 --- a/frontend/src/types/types.ts +++ b/frontend/src/types/types.ts @@ -45,3 +45,23 @@ export interface Repo extends RepoRaw { files?: FileResult[]; users?: User[]; } + +interface AuthorshipFileSegment { + authored: boolean; + lineNumbers: number[]; + lines: string[]; +} + +export interface AuthorshipFile { + active: boolean; + blankLineCount: number; + charCount: number; + fileSize: number | undefined; // not actually in schema - to verify relevancy when migrating c-authorship.vue + fileType: string; + isBinary: boolean; + isIgnored: boolean; + lineCount: number; + path: string; + segments: AuthorshipFileSegment[]; + wasCodeLoaded: boolean; +} diff --git a/frontend/src/types/vuex.d.ts b/frontend/src/types/vuex.d.ts new file mode 100644 index 0000000000..b928ee6eec --- /dev/null +++ b/frontend/src/types/vuex.d.ts @@ -0,0 +1,64 @@ +import { Store } from 'vuex'; +import { AuthorshipFile, User } from './types'; + +interface AuthorshipInfo { + author: string; + checkedFileTypes?: string[]; + files: AuthorshipFile[]; + isMergeGroup: boolean; + isRefresh?: boolean; + location: string | undefined; + maxDate: string; + minDate: string; + name: string; + repo: string; +} + +interface ZoomInfo { + isRefreshing?: boolean; + zAuthor: string; + zAvgCommitSize: number | string; + zFileTypeColors: { [key: string]: string }; + zFilterGroup: string; + zFilterSearch: string; + zFromRamp: boolean; + zIsMerged: boolean; + zLocation: string | undefined; + zRepo: string; + zSince: string; + zTimeFrame: string; + zUntil: string; + zUser: User; +} + +export interface SummaryDates { + since: string; + until: string; +} + +export interface StoreState { + tabAuthorshipInfo: AuthorshipInfo; + tabZoomInfo: ZoomInfo; + summaryDates: SummaryDates; + mergedGroups: string[] + fileTypeColors: { [key: string]: string } + loadingOverlayCount: number + loadingOverlayMessage: string + isTabActive: boolean +} + +declare module '@vue/runtime-core' { + interface State { + tabAuthorshipInfo: AuthorshipInfo; + tabZoomInfo: ZoomInfo; + summaryDates: SummaryDates; + mergedGroups: string[] + fileTypeColors: { [key: string]: string } + loadingOverlayCount: number + loadingOverlayMessage: string + isTabActive: boolean + } + interface ComponentCustomProperties { + $store: Store; + } +} From e3f84ac8c7cd40863918a75b63fa800edb2e904f Mon Sep 17 00:00:00 2001 From: vvidday Date: Sat, 11 Mar 2023 23:52:48 +0800 Subject: [PATCH 02/13] Convert store.js to TypeScript --- frontend/src/store/{store.js => store.ts} | 45 +++++++++++++---------- 1 file changed, 26 insertions(+), 19 deletions(-) rename frontend/src/store/{store.js => store.ts} (60%) diff --git a/frontend/src/store/store.js b/frontend/src/store/store.ts similarity index 60% rename from frontend/src/store/store.js rename to frontend/src/store/store.ts index 3c5c3de4de..1499b3558c 100644 --- a/frontend/src/store/store.js +++ b/frontend/src/store/store.ts @@ -1,55 +1,62 @@ import { createStore } from 'vuex'; +import { AuthorshipFile, CommitResult, DailyCommit } from '../types/types'; +import { + AuthorshipInfo, + StoreState, + SummaryDates, + ZoomInfo, +} from '../types/vuex.d'; export default createStore({ state: { - tabAuthorshipInfo: {}, - tabZoomInfo: {}, - summaryDates: {}, + tabAuthorshipInfo: {} as AuthorshipInfo, + tabZoomInfo: {} as ZoomInfo, + summaryDates: {} as SummaryDates, mergedGroups: [], fileTypeColors: {}, loadingOverlayCount: 0, loadingOverlayMessage: '', isTabActive: true, - }, + } as StoreState, mutations: { - updateTabZoomInfo(state, info) { + updateTabZoomInfo(state, info: ZoomInfo) { state.tabZoomInfo = info; }, - updateTabAuthorshipInfo(state, info) { + updateTabAuthorshipInfo(state, info: AuthorshipInfo) { state.tabAuthorshipInfo = info; }, - updateSummaryDates(state, info) { + updateSummaryDates(state, info: SummaryDates) { state.summaryDates = info; }, - updateFileTypeColors(state, info) { + updateFileTypeColors(state, info: { [key: string]: string }) { state.fileTypeColors = info; }, - updateMergedGroup(state, info) { + updateMergedGroup(state, info: string[]) { state.mergedGroups = info; }, - incrementLoadingOverlayCount(state, increment) { + incrementLoadingOverlayCount(state, increment: number) { state.loadingOverlayCount += increment; if (state.loadingOverlayCount === 0) { state.loadingOverlayMessage = 'Loading. Please wait...'; } }, - updateLoadingOverlayMessage(state, message) { + updateLoadingOverlayMessage(state, message: string) { state.loadingOverlayMessage = message; }, - updateTabState(state, isTabOpen) { + updateTabState(state, isTabOpen: boolean) { state.isTabActive = isTabOpen; - window.addHash('tabOpen', isTabOpen); + window.addHash('tabOpen', isTabOpen.toString()); if (!isTabOpen) { window.removeHash('tabType'); } window.encodeHash(); }, - toggleZoomCommitMessageBody(_, slice) { + toggleZoomCommitMessageBody(_, slice: CommitResult) { if (slice.isOpen !== undefined) { slice.isOpen = !slice.isOpen; } }, - setAllZoomCommitMessageBody(_, { isOpen, commits }) { + setAllZoomCommitMessageBody(_, { isOpen, commits }: { isOpen: boolean; commits: DailyCommit[] }) { commits.forEach((commit) => { commit.commitResults.forEach((slice) => { if (slice.isOpen !== undefined) { @@ -58,14 +65,14 @@ export default createStore({ }); }); }, - updateTabAuthorshipFiles(state, files) { + updateTabAuthorshipFiles(state, files: AuthorshipFile[]) { state.tabAuthorshipInfo.files.splice(0, state.tabAuthorshipInfo.files.length, ...files); }, - toggleAuthorshipFileActiveProperty(_, file) { + toggleAuthorshipFileActiveProperty(_, file: AuthorshipFile) { file.active = !file.active; file.wasCodeLoaded = file.wasCodeLoaded || file.active; }, - setAllAuthorshipFileActiveProperty(_, { isActive, files }) { + setAllAuthorshipFileActiveProperty(_, { isActive, files }: { isActive: boolean; files: AuthorshipFile[] }) { files.forEach((file) => { file.active = isActive; file.wasCodeLoaded = file.wasCodeLoaded || file.active; @@ -75,7 +82,7 @@ export default createStore({ actions: { // Actions are called with dispatch - async incrementLoadingOverlayCountForceReload({ commit }, increment) { + async incrementLoadingOverlayCountForceReload({ commit }, increment: number) { commit('incrementLoadingOverlayCount', increment); await new Promise(window.requestAnimationFrame); await new Promise(window.requestAnimationFrame); From 679eaa07902b7b8c10a1c246b8fda9f5ae8592a4 Mon Sep 17 00:00:00 2001 From: vvidday Date: Sat, 11 Mar 2023 23:54:24 +0800 Subject: [PATCH 03/13] Add missing isOpen field to CommitResult (from #1866) --- frontend/src/types/types.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/frontend/src/types/types.ts b/frontend/src/types/types.ts index 4e8252de3c..dce0ce79c3 100644 --- a/frontend/src/types/types.ts +++ b/frontend/src/types/types.ts @@ -11,6 +11,7 @@ export interface CommitResult extends CommitResultRaw { repoId: string; insertions: number; deletions: number; + isOpen?: boolean; } // Similar to AuthorDailyContributions, but uses the updated CommitResult with the three new fields From 611ad6dfb0770c90ad0dc39ef38934512fdc0550 Mon Sep 17 00:00:00 2001 From: vvidday Date: Sun, 12 Mar 2023 00:06:26 +0800 Subject: [PATCH 04/13] Remove unnecessary export statements in vuex.d.ts --- frontend/src/types/vuex.d.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/frontend/src/types/vuex.d.ts b/frontend/src/types/vuex.d.ts index b928ee6eec..e4b250f0a8 100644 --- a/frontend/src/types/vuex.d.ts +++ b/frontend/src/types/vuex.d.ts @@ -31,12 +31,12 @@ interface ZoomInfo { zUser: User; } -export interface SummaryDates { +interface SummaryDates { since: string; until: string; } -export interface StoreState { +interface StoreState { tabAuthorshipInfo: AuthorshipInfo; tabZoomInfo: ZoomInfo; summaryDates: SummaryDates; From 97467d0171da0abbde4bcbe32aedb5e33ea4fed7 Mon Sep 17 00:00:00 2001 From: vvidday Date: Sun, 12 Mar 2023 00:09:03 +0800 Subject: [PATCH 05/13] Add missing optional fields to fileResult schema --- frontend/src/types/zod/authorship-type.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/frontend/src/types/zod/authorship-type.ts b/frontend/src/types/zod/authorship-type.ts index bf2dcd6cfb..8938544d5a 100644 --- a/frontend/src/types/zod/authorship-type.ts +++ b/frontend/src/types/zod/authorship-type.ts @@ -11,6 +11,8 @@ const fileResult = z.object({ fileType: z.string(), lines: z.array(lineSchema), authorContributionMap: z.record(z.number()), + isBinary: z.boolean().optional(), + isIgnored: z.boolean().optional(), }); // Contains the zod validation schema for the authorship.json file From dfbb06f34eca6b3392aa51f451c1fc0f917d5060 Mon Sep 17 00:00:00 2001 From: vvidday Date: Sun, 12 Mar 2023 00:11:27 +0800 Subject: [PATCH 06/13] Add app property to window object as any and add eslint exception --- frontend/src/types/window.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/frontend/src/types/window.ts b/frontend/src/types/window.ts index 03db077232..15cc10353a 100644 --- a/frontend/src/types/window.ts +++ b/frontend/src/types/window.ts @@ -68,5 +68,7 @@ declare global { isSinceDateProvided: boolean; isUntilDateProvided: boolean; DOMAIN_URL_MAP: DomainUrlMap; + // eslint-disable-next-line @typescript-eslint/no-explicit-any + app: any; } } From 4bfc3aae9212d7860d3af802d63e53b891dc7be9 Mon Sep 17 00:00:00 2001 From: vvidday Date: Sun, 12 Mar 2023 00:12:15 +0800 Subject: [PATCH 07/13] Convert app.vue to TypeScript --- frontend/src/app.vue | 38 ++++++++++++++++++++++---------------- 1 file changed, 22 insertions(+), 16 deletions(-) diff --git a/frontend/src/app.vue b/frontend/src/app.vue index 180a919983..71b3767bee 100644 --- a/frontend/src/app.vue +++ b/frontend/src/app.vue @@ -75,24 +75,26 @@ input(type="file", accept=".zip", v-on:change="updateReportZip") -