Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[#1959] Missing contribution bar for merged groups after refresh #1960

Merged
merged 10 commits into from
Apr 4, 2023
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;
}
Comment on lines +229 to +231
Copy link
Member Author

@MarcusTXK MarcusTXK Mar 24, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interestingly, this is what is causing the cypress test to fail. By adding this guard clause, the browser hangs if you check "breakdown by file type", uncheck "All" and then try to check any one of the file types. There is a part of the frontend that only works when the output is NaN due to the division of 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