Skip to content

Commit 80818d5

Browse files
feat: Enhance Pull Requests dashboard with sorting options (#17)
1 parent 8805852 commit 80818d5

File tree

2 files changed

+71
-14
lines changed

2 files changed

+71
-14
lines changed

src/components/PullRequestsApprovals.tsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,10 @@ export const PullRequestsApprovals: React.FC<PullRequestsApprovalsProps> = ({
5656
const approvalAvatars = React.useMemo(
5757
() =>
5858
allApprovals?.map((approval) => (
59-
<Tooltip key={approval.user.login} title={approval.state}>
59+
<Tooltip
60+
key={approval.user.login}
61+
title={`${approval.state} by ${approval.user.login}`}
62+
>
6063
<Badge
6164
{...getBadgeProps(approval.state)}
6265
sx={{ height: "1em", display: "flex", alignItems: "center" }}
@@ -88,7 +91,7 @@ export const PullRequestsApprovals: React.FC<PullRequestsApprovalsProps> = ({
8891
{isLoading ? (
8992
<CircularProgress size={24} />
9093
) : (
91-
<Box sx={{ display: "flex", alignItems: "center" }}>
94+
<Box sx={{ display: "flex", alignItems: "center", gap: 1 }}>
9295
{" "}
9396
{approvals.length ? approvalAvatars : "No reviews"}{" "}
9497
</Box>

src/pages/Dashboard.tsx

Lines changed: 66 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,15 @@ import PullRequestCard from "../components/Cards/PullRequestCard";
55
import {
66
Box,
77
Button,
8-
FormControlLabel,
8+
FormControl,
99
FormGroup,
10+
IconButton,
11+
InputLabel,
12+
MenuItem,
13+
Select,
1014
Switch,
1115
Tooltip,
16+
Typography,
1217
} from "@mui/material";
1318
import Grid from "@mui/material/Grid2";
1419
import LandingPage from "./LandingPage";
@@ -18,12 +23,17 @@ import { Navigate } from "react-router";
1823
import PRLoadingPage from "./PRLoadingPage";
1924
import { PullRequestFilters } from "../components/Dashboard/PullRequestFilters";
2025
import { FilterList } from "@mui/icons-material";
26+
import SortIconOutlined from "@mui/icons-material/Sort";
2127

2228
export const Dashboard: React.FC = () => {
2329
const { octokit, repositorySettings } = React.useContext(ConfigContext);
2430
const [activeRepositories, setActiveRepositories] = React.useState<string[]>(
2531
[]
2632
);
33+
const [orderByDate, setOrderByDate] = React.useState<"Repository" | "Date">(
34+
"Repository"
35+
);
36+
const [order, setOrder] = React.useState<"asc" | "desc">("asc");
2737

2838
useEffect(() => {
2939
setActiveRepositories(
@@ -58,15 +68,29 @@ export const Dashboard: React.FC = () => {
5868
const [showFilters, setShowFilters] = React.useState<boolean>(false);
5969

6070
const filteredPulls = React.useMemo(() => {
61-
return data.filter((pull) => {
71+
const pullRequests = data.filter((pull) => {
6272
if (!pull) return false;
6373
if (!showDrafts && pull.draft) return false;
6474
if (!pull.title.toLowerCase().includes(filter.toLowerCase()))
6575
return false;
6676

6777
return true;
6878
});
69-
}, [data, filter, showDrafts]);
79+
80+
pullRequests.sort((a, b) => {
81+
if (orderByDate === "Repository") {
82+
return order === "asc"
83+
? a.base.repo.name.localeCompare(b.base.repo.name)
84+
: b.base.repo.name.localeCompare(a.base.repo.name);
85+
} else {
86+
return order === "asc"
87+
? new Date(b.created_at).getTime() - new Date(a.created_at).getTime()
88+
: new Date(a.created_at).getTime() - new Date(b.created_at).getTime();
89+
}
90+
});
91+
92+
return pullRequests;
93+
}, [data, filter, showDrafts, orderByDate, order]);
7094

7195
const [displayedPulls, setDisplayedPulls] = React.useState<PullRequest[]>(
7296
filteredPulls as PullRequest[]
@@ -94,15 +118,45 @@ export const Dashboard: React.FC = () => {
94118
onChange={setFilter}
95119
size="small"
96120
/>
97-
<FormGroup sx={{ m: 1 }}>
98-
<FormControlLabel
99-
control={
100-
<Switch
101-
checked={showDrafts}
102-
onChange={() => setShowDrafts(!showDrafts)}
103-
/>
104-
}
105-
label="Show Drafts"
121+
<FormControl
122+
sx={{ m: 1, alignItems: "center", flexDirection: "row" }}
123+
>
124+
<Typography id="select-order-label" sx={{ pr: 2 }}>
125+
Order By:
126+
</Typography>
127+
<Select
128+
value={orderByDate}
129+
variant="standard"
130+
labelId="select-order-label"
131+
label="Order By"
132+
onChange={(e) => setOrderByDate(e.target.value as any)}
133+
sx={{ minWidth: 120 }}
134+
>
135+
<MenuItem value={"Repository"}>Repository</MenuItem>
136+
<MenuItem value={"Date"}>Date</MenuItem>
137+
</Select>
138+
</FormControl>
139+
<Tooltip title={order === "asc" ? "Ascending" : "Descending"}>
140+
<IconButton
141+
size="small"
142+
onClick={() => setOrder(order === "asc" ? "desc" : "asc")}
143+
>
144+
<SortIconOutlined
145+
sx={{
146+
transform: order === "asc" ? "rotate(180deg)" : "none",
147+
}}
148+
/>
149+
</IconButton>
150+
</Tooltip>
151+
<FormGroup
152+
sx={{ m: 1, alignItems: "center", flexDirection: "row" }}
153+
>
154+
<InputLabel id="select-order-label" sx={{ pr: 2 }}>
155+
Show Drafts
156+
</InputLabel>
157+
<Switch
158+
checked={showDrafts}
159+
onChange={() => setShowDrafts(!showDrafts)}
106160
/>
107161
</FormGroup>
108162
<Tooltip title={showFilters ? "Hide Filters" : "Show Filters"}>

0 commit comments

Comments
 (0)