feat: add sortBy network members

About #120
This commit is contained in:
NoobTW 2023-04-16 13:38:12 +08:00
commit a5bcff7d8c
No known key found for this signature in database
GPG key ID: 3C04B63FD6FB4159

View file

@ -4,8 +4,11 @@ import {
AccordionSummary, AccordionSummary,
Checkbox, Checkbox,
Divider, Divider,
FormControlLabel,
Grid, Grid,
IconButton, IconButton,
Radio,
RadioGroup,
TextField, TextField,
Typography, Typography,
} from "@material-ui/core"; } from "@material-ui/core";
@ -29,6 +32,7 @@ function NetworkMembers({ network }) {
const [filter, setFilter] = useState(""); const [filter, setFilter] = useState("");
const [filterActive, setFilterActive] = useState(false); const [filterActive, setFilterActive] = useState(false);
const [filterInactive, setFilterInactive] = useState(false); const [filterInactive, setFilterInactive] = useState(false);
const [sortBy, setSortBy] = useState("id");
const fetchData = useCallback(async () => { const fetchData = useCallback(async () => {
try { try {
@ -175,14 +179,14 @@ function NetworkMembers({ network }) {
<RefreshIcon /> <RefreshIcon />
</IconButton> </IconButton>
<Grid container> <Grid container>
<Grid item sm={6}> <Grid item sm={3}>
<Typography>Search (Addr/Name)</Typography> <Typography>Search (Addr/Name)</Typography>
<TextField <TextField
value={filter} value={filter}
onChange={(e) => setFilter(e.target.value)} onChange={(e) => setFilter(e.target.value)}
/> />
</Grid> </Grid>
<Grid item sm="auto"> <Grid item sm={3}>
<Typography>Display Filter</Typography> <Typography>Display Filter</Typography>
<Checkbox <Checkbox
checked={filterActive} checked={filterActive}
@ -197,6 +201,13 @@ function NetworkMembers({ network }) {
/> />
<span>Inactive</span> <span>Inactive</span>
</Grid> </Grid>
<Grid item sm={3}>
<Typography>Sort by</Typography>
<RadioGroup value={sortBy} onChange={(e) => setSortBy(e.target.value)}>
<FormControlLabel value="name" control={<Radio />} label="Name" />
<FormControlLabel value="id" control={<Radio />} label="Address" />
</RadioGroup>
</Grid>
<Divider /> <Divider />
</Grid> </Grid>
<Grid container> <Grid container>
@ -212,6 +223,7 @@ function NetworkMembers({ network }) {
(filterInactive ? x.online === 0 : true) (filterInactive ? x.online === 0 : true)
) )
}) })
.sort((a, b) => a[sortBy].localeCompare(b[sortBy]))
} }
/> />
) : ( ) : (