Skip to content

Change sort button to display both sorting directions at the same time. #88

Merged
merged 7 commits into from
Oct 30, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 37 additions & 15 deletions src/components/ItemTable/ItemTable.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
import React from "react";
import PropTypes from "prop-types";
import { useTable, useFilters, useFlexLayout, useSortBy } from "react-table";
import { makeStyles, Table, TableBody, TableCell, TableHead, TableRow, TableContainer, TableSortLabel,
Paper, Grid, useTheme } from "@material-ui/core";
import {
Table, TableBody, TableCell, TableHead, TableRow, TableContainer,
Paper, Grid, ButtonGroup, IconButton, makeStyles, useTheme
} from "@material-ui/core";
import { useHistory } from "react-router-dom";
import RelativeTime from "react-relative-time";
import ItemTableFilter from "../ItemTableFilter/"
import { ArrowDownward, ArrowUpward } from "@material-ui/icons";

export default function ItemTable({ data, onRowClick }) {
export default function ItemTable({ data }) {

const theme = useTheme();
const useStyles = makeStyles({
Expand Down Expand Up @@ -61,11 +64,11 @@ export default function ItemTable({ data, onRowClick }) {
/>
);
}
}
},
},
useFilters, useFlexLayout, useSortBy
useFilters, useFlexLayout, useSortBy,
);
const { getTableProps, getTableBodyProps, headerGroups, rows, prepareRow } = tableInstance;
const { getTableProps, getTableBodyProps, headerGroups, rows, prepareRow, } = tableInstance;

return (
<TableContainer component={Paper}>
Expand All @@ -81,14 +84,32 @@ export default function ItemTable({ data, onRowClick }) {
{column.render("Filter")}
</Grid>
<Grid item sm={2} alignItems='center' justify='center'>
<TableSortLabel {...column.getSortByToggleProps()}
active={column.isSorted ? true : false}
disableRipple={false}
focusRipple
classes={{ icon: (column.isSorted ? classes.activeSortIcon : classes.inactiveSortIcon) }}
direction={column.isSorted ? column.isSortedDesc ? 'desc' : 'asc' : 'asc'}
>
</TableSortLabel>
<ButtonGroup orientation="vertical" size="small">
<IconButton
size="small"
onClick={(_ => {
const isSortedAsc = column.isSorted && !column.isSortedDesc;
isSortedAsc ? column.clearSortBy() : column.toggleSortBy(false)
})}
>
<ArrowUpward {...column.getSortByToggleProps()}
fontSize="inherit"
color={column.isSorted && column.isSortedDesc === false ? "default" : "disabled"}
/>
</IconButton>
<IconButton
size="small"
onClick={(_ => {
const isSortedDesc = column.isSorted && column.isSortedDesc;
isSortedDesc ? column.clearSortBy() : column.toggleSortBy(true)
})}
>
<ArrowDownward {...column.getSortByToggleProps(column.isSortedDesc)}
fontSize="inherit"
color={column.isSorted && column.isSortedDesc ? "default" : "disabled"}
/>
</IconButton>
</ButtonGroup>
</Grid>
</Grid>
</TableCell>
Expand All @@ -103,7 +124,8 @@ export default function ItemTable({ data, onRowClick }) {
return (
<TableRow
onClick={() => history.push(`/${row.original.queue}/${row.original.number}`)}
className={classes.bandedRows} {...row.getRowProps()}>
className={classes.bandedRows}
{...row.getRowProps()} >
{row.cells.map(cell => (
<TableCell classes={{ root: classes.columnBorders }} {...cell.getCellProps()}>
{cell.render("Cell")}
Expand Down