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

[#1420] Extract some code from summary.js #1421

Merged

Conversation

gerhean
Copy link
Contributor

@gerhean gerhean commented Jan 19, 2021

Some of [#1420], but more can certainly be done.

Currently summary.js is very long (900+ lines).

This makes maintaining code hard 
as it not always clear which code causes
changes in the components state.

Ideally, all code which do not modify
state should be moved out.

This further helps to decouple code,
as it forces the dependencies of the functions
to be written clearly as arguments,
allowing the function to act as a reliable
black box which is also easier to test.

Lets move some code out of summary.js.

Comment on lines 1 to 29
function getTotalCommits(total, group) {
return total + group.checkedFileTypeContribution;
}

function getGroupCommitsVariance(total, group) {
return total + group.variance;
}

// function getGroupCommitsVariance(sortingOption) {
// return function (total, group) {
// if (sortingOption === 'totalCommits') {
// return total + group.checkedFileTypeContribution;
// }
// return total + group[sortingOption];
// };
// }

function sortingHelper(element, sortingOption) {
// return sortingOption === 'totalCommits' || sortingOption === 'variance'
// ? element.reduce(getGroupCommitsVariance, 0)
// : element[0][sortingOption];
if (sortingOption === 'totalCommits') {
return element.reduce(getTotalCommits, 0);
}
if (sortingOption === 'variance') {
return element.reduce(getGroupCommitsVariance, 0);
}
return element[0][sortingOption];
}
Copy link
Contributor Author

@gerhean gerhean Jan 19, 2021

Choose a reason for hiding this comment

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

The change I made to the code. Will remove comments once verified is ok.

Copy link
Contributor

Choose a reason for hiding this comment

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

Any reason for making this change?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Actually I realized that the commented code was not the original code sorry.

The reason why I changed the original code is because it was using this.sortingOption which is not available when extracted, and that returning an anonymous function is not the best idea (I think there was a warning).

@gerhean gerhean requested a review from a team January 19, 2021 15:26
Copy link
Contributor

@Tejas2805 Tejas2805 left a comment

Choose a reason for hiding this comment

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

Left a few initial comments.

Comment on lines 1 to 29
function getTotalCommits(total, group) {
return total + group.checkedFileTypeContribution;
}

function getGroupCommitsVariance(total, group) {
return total + group.variance;
}

// function getGroupCommitsVariance(sortingOption) {
// return function (total, group) {
// if (sortingOption === 'totalCommits') {
// return total + group.checkedFileTypeContribution;
// }
// return total + group[sortingOption];
// };
// }

function sortingHelper(element, sortingOption) {
// return sortingOption === 'totalCommits' || sortingOption === 'variance'
// ? element.reduce(getGroupCommitsVariance, 0)
// : element[0][sortingOption];
if (sortingOption === 'totalCommits') {
return element.reduce(getTotalCommits, 0);
}
if (sortingOption === 'variance') {
return element.reduce(getGroupCommitsVariance, 0);
}
return element[0][sortingOption];
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Any reason for making this change?

@fzdy1914
Copy link
Member

fzdy1914 commented Feb 7, 2021

@gerhean Pls answer the questions and proceed with PR.

@gerhean
Copy link
Contributor Author

gerhean commented Feb 15, 2021

Would it be good to merge this first and extract more stuff in another PR?

@0blivious
Copy link
Contributor

What are the other changes you plan to extract? Can you give some line number?

Comment on lines +1 to +27
function getTotalCommits(total, group) {
return total + group.checkedFileTypeContribution;
}

function getGroupCommitsVariance(total, group) {
return total + group.variance;
}

// function getGroupCommitsVariance(total, group) {
// if (this.sortingOption === 'totalCommits') {
// return total + group.checkedFileTypeContribution;
// }
// return total + group[this.sortingOption];
// }

function sortingHelper(element, sortingOption) {
// return sortingOption === 'totalCommits' || sortingOption === 'variance'
// ? element.reduce(getGroupCommitsVariance, 0)
// : element[0][sortingOption];
if (sortingOption === 'totalCommits') {
return element.reduce(getTotalCommits, 0);
}
if (sortingOption === 'variance') {
return element.reduce(getGroupCommitsVariance, 0);
}
return element[0][sortingOption];
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Actually I realized that the previously commented code was not the original code sorry.

The reason why I changed the original code is because it was using this.sortingOption which is not available when extracted, and that returning an anonymous function is not the best idea (I think there was a warning).

frontend/src/static/js/v_summary.js Show resolved Hide resolved
@gerhean
Copy link
Contributor Author

gerhean commented Feb 19, 2021

What are the other changes you plan to extract? Can you give some line number?

At the moment I'm not really focusing on this so nothing yet.

@fzdy1914 fzdy1914 merged commit 0f70ff3 into reposense:master Mar 4, 2021
fzdy1914 pushed a commit that referenced this pull request Mar 8, 2021
Repositories with more than 19 different types of files will crash,
which can be traced from line 448 of `v_summary.js`.

Bug is caused by a function not being copied properly in #1421,
leading to an undefined function call.

Let's copy the function over properly.
@gerhean gerhean deleted the abstract-color-generator-and-sort-repo branch March 29, 2021 03:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants