Skip to content

Commit 96bd05a

Browse files
JamieXiaotektaxi
authored andcommitted
fixed sort for review status and review score
1 parent 9b9ead5 commit 96bd05a

File tree

1 file changed

+41
-33
lines changed

1 file changed

+41
-33
lines changed

src/features/Search/ResultsTable.tsx

Lines changed: 41 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,41 @@ interface IResultsTableProps {
1717
triggerUpdate: () => void;
1818
}
1919

20+
// calculate review status
21+
const calculateReviewStatusCount = (hacker: IHacker): number => {
22+
if (hacker.reviewerStatus != HackerReviewerStatus.HACKER_REVIEWER_STATUS_NONE && hacker.reviewerStatus2 != HackerReviewerStatus.HACKER_REVIEWER_STATUS_NONE) {
23+
return 2;
24+
} else if (hacker.reviewerStatus != HackerReviewerStatus.HACKER_REVIEWER_STATUS_NONE || hacker.reviewerStatus2 != HackerReviewerStatus.HACKER_REVIEWER_STATUS_NONE) {
25+
return 1;
26+
} else {
27+
return 0;
28+
}
29+
};
30+
31+
// calculate review score
32+
const calculateReviewScoreCount = (hacker: IHacker): number => {
33+
const arr = [hacker.reviewerStatus, hacker.reviewerStatus2];
34+
if (arr[0] == HackerReviewerStatus.HACKER_REVIEWER_STATUS_NONE && arr[1] == HackerReviewerStatus.HACKER_REVIEWER_STATUS_NONE) {
35+
return -1;
36+
} else if (arr[0] == HackerReviewerStatus.HACKER_REVIEWER_STATUS_WHITELIST || arr[1] == HackerReviewerStatus.HACKER_REVIEWER_STATUS_WHITELIST) {
37+
return 5;
38+
} else {
39+
let score = 0;
40+
let numberOfReviews = 0;
41+
arr.forEach((val) => {
42+
if (val != HackerReviewerStatus.HACKER_REVIEWER_STATUS_NONE && val != HackerReviewerStatus.HACKER_REVIEWER_STATUS_WHITELIST) {
43+
numberOfReviews += 1;
44+
// Poor=0, Weak=1, Average=2, Strong=3, Outstanding=4
45+
if (val == HackerReviewerStatus.HACKER_REVIEWER_STATUS_WEAK) score += 1;
46+
else if (val == HackerReviewerStatus.HACKER_REVIEWER_STATUS_AVERAGE) score += 2;
47+
else if (val == HackerReviewerStatus.HACKER_REVIEWER_STATUS_STRONG) score += 3;
48+
else if (val == HackerReviewerStatus.HACKER_REVIEWER_STATUS_OUTSTANDING) score += 4;
49+
}
50+
});
51+
return score / numberOfReviews;
52+
}
53+
};
54+
2055
const ResultsTable: React.FunctionComponent<IResultsTableProps> = (props) => {
2156
const volunteerColumns = [
2257
{
@@ -52,45 +87,18 @@ const ResultsTable: React.FunctionComponent<IResultsTableProps> = (props) => {
5287
},
5388
{ // Number of reviewers that have reviewed this hacker
5489
Header: 'Review Status',
55-
accessor: 'hacker.reviewerStatus',
90+
id: 'reviewStatus', // required since accessor is a non-string
91+
accessor: (row: any) => calculateReviewStatusCount(row.hacker),
5692
Cell: (cellProps: any) => {
57-
const reviewerStatus = cellProps.original.hacker.reviewerStatus;
58-
const reviewerStatus2 = cellProps.original.hacker.reviewerStatus2;
59-
if (reviewerStatus!=HackerReviewerStatus.HACKER_REVIEWER_STATUS_NONE && reviewerStatus2!=HackerReviewerStatus.HACKER_REVIEWER_STATUS_NONE) {
60-
return <span>2</span>;
61-
} else if (reviewerStatus!=HackerReviewerStatus.HACKER_REVIEWER_STATUS_NONE || reviewerStatus2!=HackerReviewerStatus.HACKER_REVIEWER_STATUS_NONE) {
62-
return <span>1</span>;
63-
} else {
64-
return <span>0</span>;
65-
}
93+
return cellProps.value;
6694
},
6795
},
6896
{ // Average score of the reviews for this hacker
6997
Header: 'Review Score',
70-
accessor: 'hacker.reviewerStatus',
98+
id: 'reviewScore', // required since accessor is a non-string
99+
accessor: (row: any) => calculateReviewScoreCount(row.hacker),
71100
Cell: (cellProps: any) => {
72-
const reviewerStatus = cellProps.original.hacker.reviewerStatus;
73-
const reviewerStatus2 = cellProps.original.hacker.reviewerStatus2;
74-
const arr = [reviewerStatus, reviewerStatus2];
75-
if (arr[0]==HackerReviewerStatus.HACKER_REVIEWER_STATUS_NONE && arr[1]==HackerReviewerStatus.HACKER_REVIEWER_STATUS_NONE) {
76-
return <span>-1</span>;
77-
} else if (arr[0]==HackerReviewerStatus.HACKER_REVIEWER_STATUS_WHITELIST || arr[1]==HackerReviewerStatus.HACKER_REVIEWER_STATUS_WHITELIST) {
78-
return <span>5</span>;
79-
} else {
80-
let score = 0;
81-
let numberOfReviews = 0;
82-
arr.forEach((val) => {
83-
if (val!=HackerReviewerStatus.HACKER_REVIEWER_STATUS_NONE && val!=HackerReviewerStatus.HACKER_REVIEWER_STATUS_WHITELIST) {
84-
numberOfReviews += 1;
85-
// Poor=0, Weak=1, Average=2, Strong=3, Outstanding=4
86-
if (val==HackerReviewerStatus.HACKER_REVIEWER_STATUS_WEAK) score += 1;
87-
else if (val==HackerReviewerStatus.HACKER_REVIEWER_STATUS_AVERAGE) score += 2;
88-
else if (val==HackerReviewerStatus.HACKER_REVIEWER_STATUS_STRONG) score += 3;
89-
else if (val==HackerReviewerStatus.HACKER_REVIEWER_STATUS_OUTSTANDING) score += 4;
90-
}
91-
});
92-
return <span>{score/numberOfReviews}</span>;
93-
}
101+
return cellProps.value;
94102
},
95103
},
96104
{

0 commit comments

Comments
 (0)