Skip to content

Commit

Permalink
Merge branch 'master' into branch-DynamicPositionTooltip
Browse files Browse the repository at this point in the history
  • Loading branch information
MarcusTXK committed Oct 30, 2023
2 parents d348f40 + 056fa5f commit 0f7c6f6
Show file tree
Hide file tree
Showing 6 changed files with 247 additions and 178 deletions.
4 changes: 2 additions & 2 deletions frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
"scripts": {
"serve": "vue-cli-service serve",
"build": "vue-cli-service build",
"lint": "eslint src/**/*.{ts,js,vue} cypress/tests/**/*.js cypress/support.js && stylelint ./src/**/*.{vue,scss} && npm run puglint",
"lint": "eslint src/**/*.{ts,vue} cypress/tests/**/*.js cypress/support.js && stylelint ./src/**/*.{vue,scss} && npm run puglint",
"devbuild": "vue-cli-service build --mode development",
"lintfix": "eslint --fix src/**/*.{ts,js,vue} cypress/tests/**/*.js cypress/support.js && stylelint --fix ./src/**/*.{vue,scss}",
"lintfix": "eslint --fix src/**/*.{ts,vue} cypress/tests/**/*.js cypress/support.js && stylelint --fix ./src/**/*.{vue,scss}",
"puglint": "pug-lint-vue src",
"serveOpen": "vue-cli-service serve --open"
},
Expand Down
11 changes: 9 additions & 2 deletions frontend/src/components/c-ramp.vue
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,15 @@ export default defineComponent({
}
const zoomUser = { ...user };
// Type cast here is unsafe
zoomUser.commits = user.dailyCommits as Commit[];
// Calculate total commit result insertion and deletion for the daily/weekly commit selected
zoomUser.commits = user.dailyCommits.map(
(dailyCommit) => ({
insertions: dailyCommit.commitResults.reduce((acc, currCommitResult) => acc + currCommitResult.insertions, 0),
deletions: dailyCommit.commitResults.reduce((acc, currCommitResult) => acc + currCommitResult.deletions, 0),
...dailyCommit,
commitResults: dailyCommit.commitResults.map((commitResult) => ({ ...commitResult, isOpen: true })),
}),
) as Commit[];
const info = {
zRepo: user.repoName,
Expand Down
125 changes: 0 additions & 125 deletions frontend/src/utils/repo-sorter.js

This file was deleted.

182 changes: 182 additions & 0 deletions frontend/src/utils/repo-sorter.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,182 @@
import { User } from '../types/types';
import { FilterGroupSelection } from '../types/summary';

function getTotalCommits(total: number, group: User): number {
// If group.checkedFileTypeContribution === undefined, then we treat it as 0 contribution
return total + (group.checkedFileTypeContribution ?? 0);
}

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

function checkKeyAndGetValue<T extends object>(element: T, key?: string) {
// invalid key provided
if (key === undefined || !(key in element)) {
return undefined;
}
return element[key as keyof T];
}

/**
* Returns an empty string if an invalid/no key is provided or if the value retrieved is not a ComparablePrimitive.
* This permits and results in no sorting being done in the above cases. If function is to be made stricter, assertions
* or errors may be thrown where empty strings are returned.
*/
function getComparablePrimitive(element: User, key?: string): string | number {
const val = checkKeyAndGetValue(element, key);
// value retrieved is not a comparable primitive
if (typeof val !== 'string' && typeof val !== 'number') {
return '';
}
return val;
}

/**
* Array is not sorted when sortingOption is not provided. sortingOption is optional to allow it to fit the
* SortingFunction<T> interface.
* */
function sortingHelper(element: User[], sortingOption?: string): string | number {
switch (sortingOption) {
case 'totalCommits':
return element.reduce(getTotalCommits, 0);
case 'variance':
return element.reduce(getGroupCommitsVariance, 0);
case 'displayName':
return window.getAuthorDisplayName(element);
default:
return getComparablePrimitive(element[0], sortingOption);
}
}

function groupByRepos(
repos: User[][],
sortingControl: {
sortingOption: string;
sortingWithinOption: string;
isSortingDsc: string;
isSortingWithinDsc: string; },
): User[][] {
const sortedRepos: User[][] = [];
const {
sortingWithinOption, sortingOption, isSortingDsc, isSortingWithinDsc,
} = sortingControl;
const sortWithinOption = sortingWithinOption === 'title' ? 'displayName' : sortingWithinOption;
const sortOption = sortingOption === 'groupTitle' ? 'searchPath' : sortingOption;
repos.forEach((users) => {
if (sortWithinOption === 'totalCommits') {
users.sort(window.comparator((ele) => ele.checkedFileTypeContribution ?? 0));
} else {
users.sort(window.comparator((ele) => getComparablePrimitive(ele, sortWithinOption)));
}

if (isSortingWithinDsc) {
users.reverse();
}
sortedRepos.push(users);
});
sortedRepos.sort(window.comparator(sortingHelper, sortOption));
if (isSortingDsc) {
sortedRepos.reverse();
}
return sortedRepos;
}

function groupByNone(
repos: User[][],
sortingControl: {
sortingOption: string;
isSortingDsc: string; },
): User[] {
const sortedRepos: User[] = [];
const { sortingOption, isSortingDsc } = sortingControl;
const isSortingGroupTitle = sortingOption === 'groupTitle';
repos.forEach((users) => {
users.forEach((user) => {
sortedRepos.push(user);
});
});
sortedRepos.sort(window.comparator((repo) => {
if (isSortingGroupTitle) {
return `${repo.searchPath}${repo.name}`;
}
if (sortingOption === 'totalCommits') {
return repo.checkedFileTypeContribution ?? 0;
}
return getComparablePrimitive(repo, sortingOption);
}));
if (isSortingDsc) {
sortedRepos.reverse();
}

return sortedRepos;
}

function groupByAuthors(
repos: User[][],
sortingControl: {
sortingOption: string;
sortingWithinOption: string;
isSortingDsc: string;
isSortingWithinDsc: string; },
): User[][] {
const authorMap: { [userName: string]: User[] } = {};
const filtered: User[][] = [];
const {
sortingWithinOption, sortingOption, isSortingDsc, isSortingWithinDsc,
} = sortingControl;
const sortWithinOption = sortingWithinOption === 'title' ? 'searchPath' : sortingWithinOption;
const sortOption = sortingOption === 'groupTitle' ? 'displayName' : sortingOption;
repos.forEach((users) => {
users.forEach((user) => {
if (Object.keys(authorMap).includes(user.name)) {
authorMap[user.name].push(user);
} else {
authorMap[user.name] = [user];
}
});
});
Object.keys(authorMap).forEach((author) => {
if (sortWithinOption === 'totalCommits') {
authorMap[author].sort(window.comparator((repo) => repo.checkedFileTypeContribution ?? 0));
} else {
authorMap[author].sort(window.comparator((repo) => getComparablePrimitive(repo, sortingWithinOption)));
}
if (isSortingWithinDsc) {
authorMap[author].reverse();
}
filtered.push(authorMap[author]);
});

filtered.sort(window.comparator(sortingHelper, sortOption));
if (isSortingDsc) {
filtered.reverse();
}
return filtered;
}

function sortFiltered(
filtered: User[][],
filterControl: {
filterGroupSelection: FilterGroupSelection;
sortingOption: string;
sortingWithinOption: string;
isSortingDsc: string;
isSortingWithinDsc: string; },
): User[][] {
const { filterGroupSelection } = filterControl;
let full = [];

if (filterGroupSelection === 'groupByNone') {
// push all repos into the same group
full[0] = groupByNone(filtered, filterControl);
} else if (filterGroupSelection === 'groupByAuthors') {
full = groupByAuthors(filtered, filterControl);
} else {
full = groupByRepos(filtered, filterControl);
}

return full;
}

export default sortFiltered;
49 changes: 0 additions & 49 deletions frontend/src/utils/safari_date.js

This file was deleted.

Loading

0 comments on commit 0f7c6f6

Please sign in to comment.