Skip to content

Commit

Permalink
[#1936] Migrate c-authorship.vue to TypeScript (#1969)
Browse files Browse the repository at this point in the history
Currently, despite the addition of TypeScript support, the frontend is
still largely written in JavaScript. This results in a lack of type
safety and many complex objects being passed around as unknown types,
which may in turn lead to errors.

Let's migrate one of the main components, c-authorship.vue, to
TypeScript. This will provide better type safety and reduce runtime
errors.
  • Loading branch information
vvidday authored Apr 10, 2023
1 parent 0abc0d2 commit 000bc28
Show file tree
Hide file tree
Showing 8 changed files with 137 additions and 122 deletions.
2 changes: 1 addition & 1 deletion frontend/cypress/tests/codeView/codeView_reload.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ describe('reload page', () => {
cy.reload();

cy.get('#tab-authorship > .title > .contribution > .sorting > .sort-by > select')
.should('have.value', 'lineOfCode');
.should('have.value', 'linesOfCode');

cy.get('#tab-authorship > .title > .contribution > .sorting > .sort-order > select')
.should('have.value', 'true');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ describe('switch authorship', () => {
// check default controls
cy.get('#tab-authorship > .title > .contribution > .sorting > .sort-by > select')
.should('not.have.value', 'path')
.should('have.value', 'lineOfCode');
.should('have.value', 'linesOfCode');

cy.get('#tab-authorship > .title > .contribution > .sorting > .sort-order > select')
.should('have.value', 'true');
Expand Down
11 changes: 11 additions & 0 deletions frontend/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
"@fortawesome/free-brands-svg-icons": "^6.0.0",
"@fortawesome/free-solid-svg-icons": "^6.0.0",
"@fortawesome/vue-fontawesome": "^3.0.3",
"@types/minimatch": "^5.1.2",
"core-js": "^3.6.5",
"highlight.js": "^10.5.0",
"jszip": "^3.5.0",
Expand Down
11 changes: 11 additions & 0 deletions frontend/src/types/authorship.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
export enum FilesSortType {
LinesOfCode = 'linesOfCode',
Path = 'path',
FileName = 'fileName',
FileType = 'fileType',
}

export enum FilterType {
Checkboxes = 'checkboxes',
Search = 'search',
}
11 changes: 5 additions & 6 deletions frontend/src/types/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,22 +59,21 @@ export interface Repo extends RepoRaw {
users?: User[];
}

interface AuthorshipFileSegment {
authored: boolean;
export interface AuthorshipFileSegment {
knownAuthor: string | null;
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
blankLineCount?: number;
charCount?: number;
fileType: string;
isBinary: boolean;
isIgnored: boolean;
lineCount: number;
path: string;
segments: AuthorshipFileSegment[];
segments?: AuthorshipFileSegment[];
wasCodeLoaded: boolean;
}
1 change: 1 addition & 0 deletions frontend/src/types/zod/authorship-type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,4 @@ export const authorshipSchema = z.array(fileResult);
// Export typescript types
export type AuthorshipSchema = z.infer<typeof authorshipSchema>;
export type FileResult = z.infer<typeof fileResult>;
export type Line = z.infer<typeof lineSchema>;
Loading

0 comments on commit 000bc28

Please sign in to comment.