-
Notifications
You must be signed in to change notification settings - Fork 0
Enhancement lastUpdated cell styling #135
Changes from 4 commits
6e6492b
a6d8132
ab75000
6b67902
c418a5a
4c57b61
ae03e13
8ac1d92
7110cda
f36ac8e
375b679
55de973
fc608a6
0c3f1bb
813438a
672b0f9
86b75a1
e3724de
9df197e
246e4d9
1ed9daa
1084d86
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -1,15 +1,46 @@ | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| import React, { useState } from "react"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| import PropTypes from "prop-types"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| import { useTable, useFilters, useFlexLayout, useSortBy } from "react-table"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| import { Table, TableBody, TableCell, TableHead, TableRow, TableContainer, Paper, Grid, ButtonGroup, IconButton, makeStyles, useTheme } from "@material-ui/core"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| import { Table, TableBody, TableCell, TableHead, TableRow, TableContainer, Paper, Grid, ButtonGroup, IconButton, makeStyles, useTheme, } from "@material-ui/core"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| import { red } from '@material-ui/core/colors'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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 }) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| const [selectedRow, setSelecetedRow] = useState({ queue: null, number: null }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
| const LastUpdatedCell = ({ time, reactTableCellProps, classes }) => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| const lastUpdated = new Date(time).getTime(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| const now = new Date().getTime(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| const timeDelta = now - lastUpdated; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| const day = 24 * 60 * 60 * 1000; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| const week = day * 7; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| const month = week * 4; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
| let backgroundColor = "white"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (timeDelta > day && timeDelta <= week) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| backgroundColor = red[100] | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| else if (timeDelta > week && timeDelta <= month) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| backgroundColor = red[300] | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| else if (timeDelta > month) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| backgroundColor = red[500] | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
| return ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| <TableCell | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| classes={classes} | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| {...reactTableCellProps} //expands table cell props to allow access to style props | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Move comment above line of code it applies to. Use a space between
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
| style={{ ...reactTableCellProps.style, backgroundColor: backgroundColor }} //expands style prop of table cell to allow addtion of custom styling without losing default styling | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Move comment above line of code it applies to. Use a space between
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
| > | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| <RelativeTime value={time} /> | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| </TableCell> | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
| const theme = useTheme(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| const useStyles = makeStyles({ | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| // Fully visible for active icons | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -34,7 +65,8 @@ export default function ItemTable({ data }) { | |||||||||||||||||||||||||||||||||||||||||||||||||||
| borderLeftWidth: "1px", | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| borderLeftStyle: "solid", | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| borderColor: theme.palette.type === "light" ? theme.palette.grey[300] : theme.palette.grey[500] | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Remove unnecessary blank line. |
||||||||||||||||||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| const classes = useStyles(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -48,7 +80,7 @@ export default function ItemTable({ data }) { | |||||||||||||||||||||||||||||||||||||||||||||||||||
| { Header: 'Subject', accessor: 'subject' }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| { Header: 'Status', accessor: 'status', }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| { Header: 'Priority', accessor: 'priority' }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| { Header: 'Last Updated', accessor: 'lastUpdated', Cell: ({ value }) => <RelativeTime value={value} /> }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| { Header: 'Last Updated', accessor: 'lastUpdated', Cell: ({ value }) => <LastUpdatedCell time={value} /> }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Remove Cell overrides because we're controlling them in the render statements below. The definitions here will never be used. |
||||||||||||||||||||||||||||||||||||||||||||||||||||
| { Header: 'Department', accessor: 'department' }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| { Header: 'Building', accessor: 'building' }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| { Header: 'Date Received', accessor: 'dateReceived', Cell: ({ value }) => <RelativeTime value={value} /> }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -66,7 +98,7 @@ export default function ItemTable({ data }) { | |||||||||||||||||||||||||||||||||||||||||||||||||||
| onChange={(event) => setFilter(event.target.value)} | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| /> | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| useFilters, useFlexLayout, useSortBy, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -75,7 +107,10 @@ export default function ItemTable({ data }) { | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
| return ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| <TableContainer component={Paper} > | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| <Table {...getTableProps} aria-label="Table of Queue Items" > | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| <Table {...getTableProps} | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| aria-label="Table of Queue Items" | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. When splitting component props across multiple lines, do not include props on the same line as the opening tag.
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
| size="small" | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| > | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| <TableHead> | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| {headerGroups.map(headerGroup => ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| <TableRow {...headerGroup.getHeaderGroupProps()}> | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -135,9 +170,24 @@ export default function ItemTable({ data }) { | |||||||||||||||||||||||||||||||||||||||||||||||||||
| selected={isSelected} | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| {...row.getRowProps()} > | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Like with starting tags and multi-line props, place tag endings on their own line.
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
| {row.cells.map(cell => ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| <TableCell classes={{ root: classes.columnBorders }} {...cell.getCellProps()}> | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| {cell.render("Cell")} | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| </TableCell> | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
| cell.render( | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| //conditonally renders custom cell component based on cell.column.id prop value | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Use a space between // and the start of the comment. Use proper sentence case with comments.
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
| cell.column.id === "lastUpdated" | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| ? <LastUpdatedCell | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| time={cell.value} | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| reactTableCellProps={cell.getCellProps()} | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| classes={{ root: classes.columnBorders }} | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| /> | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| : | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| <TableCell | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| {...cell.getCellProps()} | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| classes={{ root: classes.columnBorders }} | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| > | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. When using multi line values for ternary operators, wrap the value for true and false in parenthesis.
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
| {cell.value} | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| </TableCell> | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Remove extra blank line. |
||||||||||||||||||||||||||||||||||||||||||||||||||||
| ))} | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| </TableRow> | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
Uh oh!
There was an error while loading. Please reload this page.