Skip to content

Commit f05650b

Browse files
committed
Minor sorting related fixes
1 parent ebb70ef commit f05650b

File tree

3 files changed

+16
-5
lines changed

3 files changed

+16
-5
lines changed

frontend/src/components/ReviewBox.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ const ReviewBox: React.FC<{
6868
setReviewsList(undefined);
6969
}
7070
}
71-
}, [endpoint]);
71+
}, [endpoint, initExpanded]);
7272

7373
useEffect(() => {
7474
if (isExpanded) {

frontend/src/components/SortBox.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,12 @@ const SortBox = <T extends ReviewableType>({
4747
setSortByAscending(false);
4848
}, [reviewableDefaultSortString(sortableData)]);
4949

50-
const disableForSize = sortableData === null || sortableData.length <= 1;
50+
const disableForSize =
51+
sortableData === null ||
52+
sortableData.reduce(
53+
(count, data) => count + (data.reviews_metadata.num_reviews > 0 ? 1 : 0),
54+
0
55+
) <= 1;
5156
return (
5257
<>
5358
<Typography variant="h5" color="secondary" gutterBottom>

frontend/src/sortutils.tsx

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,9 @@ const reviewableSort = <T extends ReviewableType>(
4545
sortBy: SortType | '' = '',
4646
sortByAscending: boolean = false
4747
) => {
48-
return [...sortableData].sort((a, b) => {
48+
const reviewableCompare = <T extends ReviewableType>(a: T, b: T) => {
4949
if (!sortBy) {
50-
return reviewableDefaultCompare(a, b);
50+
return 0;
5151
}
5252

5353
const left = a.reviews_metadata[sortBy];
@@ -74,7 +74,13 @@ const reviewableSort = <T extends ReviewableType>(
7474
} else {
7575
return 0;
7676
}
77-
});
77+
};
78+
79+
// First compare with reviewableCompare (uses sort parameters), and if that
80+
// returns 0 then use the default comparator (sorts by name/sem).
81+
return [...sortableData].sort(
82+
(a, b) => reviewableCompare(a, b) || reviewableDefaultCompare(a, b)
83+
);
7884
};
7985

8086
export {

0 commit comments

Comments
 (0)