@@ -5,10 +5,15 @@ import PullRequestCard from "../components/Cards/PullRequestCard";
55import {
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" ;
1318import Grid from "@mui/material/Grid2" ;
1419import LandingPage from "./LandingPage" ;
@@ -18,12 +23,17 @@ import { Navigate } from "react-router";
1823import PRLoadingPage from "./PRLoadingPage" ;
1924import { PullRequestFilters } from "../components/Dashboard/PullRequestFilters" ;
2025import { FilterList } from "@mui/icons-material" ;
26+ import SortIconOutlined from "@mui/icons-material/Sort" ;
2127
2228export 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