Skip to content

Commit

Permalink
[#1959] Missing contribution bar for merged groups after refresh (#1960)
Browse files Browse the repository at this point in the history
Currently, upon refreshing the page, the contribution bar disappears 
due to getContributionBars returning NaN instead of the expected array. 
This was caused by division by 0, due to the user's 
checkedFileTypeContribution not being initialized properly. 

Let's fix this checkedFileTypeContribution not being initialized 
properly and add guard clauses against division by 0.
  • Loading branch information
MarcusTXK authored Apr 4, 2023
1 parent 4276116 commit bfb648b
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 9 deletions.
10 changes: 8 additions & 2 deletions frontend/src/components/c-summary-charts.vue
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,11 @@ export default {
let currentBarWidth = 0;
const fullBarWidth = 100;
const contributionPerFullBar = (this.avgContributionSize * 2);
const allFileTypesContributionBars = {};
if (contributionPerFullBar === 0) {
return allFileTypesContributionBars;
}
Object.keys(fileTypeContribution)
.filter((fileType) => this.checkedFileTypes.includes(fileType))
Expand All @@ -318,7 +322,7 @@ export default {
contributionBars.push(fullBarWidth);
}
const remainingBarWidth = barWidth % fullBarWidth;
if (remainingBarWidth !== 0) {
if (remainingBarWidth > 0) {
contributionBars.push(remainingBarWidth);
}
currentBarWidth = remainingBarWidth;
Expand Down Expand Up @@ -349,7 +353,9 @@ export default {
getContributionBars(totalContribution) {
const res = [];
const contributionLimit = (this.avgContributionSize * 2);
if (contributionLimit === 0) {
return res;
}
const cnt = Math.floor(totalContribution / contributionLimit);
for (let cntId = 0; cntId < cnt; cntId += 1) {
res.push(100);
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/types/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export function isCommit(commit: Commit | DailyCommit): commit is Commit {
}

export interface User {
checkedFileTypeContribution: number;
checkedFileTypeContribution: number | undefined;
commits?: Commit[];
dailyCommits: DailyCommit[];
displayName: string;
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/utils/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ window.api = {
searchPath: searchParams.join('_').toLowerCase(),
repoName: `${repo.displayName}`,
location: `${repo.location.location}`,
checkedFileTypeContribution: 0,
checkedFileTypeContribution: undefined,
});

res.push(user);
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/utils/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Commit, DailyCommit, User as UserType } from '../types/types';
import { AuthorFileTypeContributions } from '../types/zod/commits-type';

export default class User implements UserType {
checkedFileTypeContribution: number;
checkedFileTypeContribution: number | undefined;

commits: Commit[];

Expand All @@ -25,7 +25,7 @@ export default class User implements UserType {
variance: number;

constructor(userObj: User) {
this.checkedFileTypeContribution = userObj.checkedFileTypeContribution || 0;
this.checkedFileTypeContribution = userObj.checkedFileTypeContribution;
this.commits = userObj.commits || [];
this.dailyCommits = userObj.dailyCommits || [];
this.displayName = userObj.displayName || '';
Expand Down
9 changes: 6 additions & 3 deletions frontend/src/views/c-summary.vue
Original file line number Diff line number Diff line change
Expand Up @@ -219,13 +219,16 @@ export default defineComponent({
if (user.checkedFileTypeContribution === undefined) {
this.updateCheckedFileTypeContribution(user);
}
if (user.checkedFileTypeContribution > 0) {
if (user.checkedFileTypeContribution && user.checkedFileTypeContribution > 0) {
totalCount += 1;
totalLines += user.checkedFileTypeContribution;
}
});
});
if (totalCount === 0) {
return 0;
}
return totalLines / totalCount;
},
Expand Down Expand Up @@ -544,7 +547,7 @@ export default defineComponent({
this.mergeFileTypeContribution(user, mergedFileTypeContribution);
totalMergedCheckedFileTypeCommits += user.checkedFileTypeContribution;
totalMergedCheckedFileTypeCommits += user.checkedFileTypeContribution || 0;
mergedVariance += user.variance;
});
mergedCommits.sort(window.comparator((ele) => ele.date));
Expand Down

0 comments on commit bfb648b

Please sign in to comment.