Skip to content

Enhancement lastUpdated cell styling #135

Merged
merged 22 commits into from
Jan 22, 2021
Merged
Changes from 4 commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
6e6492b
Added background state varible and created lastUpdatedCell component …
Nov 23, 2020
a6d8132
Removed uncesscary function and variables. Changed name of the state …
Nov 25, 2020
ab75000
Implemented logic for changing cell color based on last updated time.
Dec 2, 2020
6b67902
implemented logic that sets color of lastUpdated cell based on time o…
Dec 3, 2020
c418a5a
Forammting fixes, removed uneccessary overrides, fixed date received…
Dec 3, 2020
4c57b61
Created ItemTableCell and LastUpdated cell components for refactoring…
wrigh393 Dec 16, 2020
ae03e13
Fixed background color not displaying in LastUpdatedCell component
wrigh393 Dec 17, 2020
8ac1d92
Update Python requirements to fix Flask_JWT_Extended and PyJWT
campb303 Dec 30, 2020
7110cda
Update venv-manager to allow 60 second for requirement installation
campb303 Dec 30, 2020
f36ac8e
Moved ternary statements to swtich statement for readability
campb303 Jan 20, 2021
375b679
Formatting
campb303 Jan 20, 2021
55de973
Rename reactTableProps to TableCellProps
campb303 Jan 20, 2021
fc608a6
Renamed folder and update exports
campb303 Jan 20, 2021
0c3f1bb
Formatting
campb303 Jan 20, 2021
813438a
Remove unused backgroundColor prop
campb303 Jan 21, 2021
672b0f9
Refactir timeToBackgroundColor and inject background color into props
campb303 Jan 21, 2021
86b75a1
Rename reactTableProps to ItemTableCellProps
campb303 Jan 21, 2021
e3724de
Make time prop required
campb303 Jan 21, 2021
9df197e
Add docs
campb303 Jan 21, 2021
246e4d9
Add docs
campb303 Jan 21, 2021
1ed9daa
Update docs to show what values the time prop can be
campb303 Jan 21, 2021
1084d86
Merge branch 'staging' into enhancement-lastupdated-styling
campb303 Jan 22, 2021
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
68 changes: 59 additions & 9 deletions src/components/ItemTable/ItemTable.js
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 });


campb303 marked this conversation as resolved.
Show resolved Hide resolved
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
Copy link
Collaborator

Choose a reason for hiding this comment

The 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 // and the start of the comment. Use proper sentence case with comments.

Suggested change
{...reactTableCellProps} //expands table cell props to allow access to style props
// Expands table cell props to allow access to style props.
{...reactTableCellProps}

style={{ ...reactTableCellProps.style, backgroundColor: backgroundColor }} //expands style prop of table cell to allow addtion of custom styling without losing default styling
Copy link
Collaborator

Choose a reason for hiding this comment

The 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 // and the start of the comment. Use proper sentence case with comments.

Suggested change
style={{ ...reactTableCellProps.style, backgroundColor: backgroundColor }} //expands style prop of table cell to allow addtion of custom styling without losing default styling
// Expands style prop of table cell to allow addition of custom styling without losing default styling.
style={{ ...reactTableCellProps.style, backgroundColor: backgroundColor }}

>
<RelativeTime value={time} />
</TableCell>
);
};

const theme = useTheme();
const useStyles = makeStyles({
// Fully visible for active icons
Expand All @@ -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]
}
},

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove unnecessary blank line.

});
const classes = useStyles();

Expand All @@ -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} /> },
Copy link
Collaborator

Choose a reason for hiding this comment

The 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} /> },
Expand All @@ -66,7 +98,7 @@ export default function ItemTable({ data }) {
onChange={(event) => setFilter(event.target.value)}
/>
);
}
},
},
},
useFilters, useFlexLayout, useSortBy,
Expand All @@ -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"
Copy link
Collaborator

Choose a reason for hiding this comment

The 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
<Table {...getTableProps}
aria-label="Table of Queue Items"
<Table
{...getTableProps}
aria-label="Table of Queue Items"

size="small"
>
<TableHead>
{headerGroups.map(headerGroup => (
<TableRow {...headerGroup.getHeaderGroupProps()}>
Expand Down Expand Up @@ -135,9 +170,24 @@ export default function ItemTable({ data }) {
selected={isSelected}
{...row.getRowProps()} >
Copy link
Collaborator

Choose a reason for hiding this comment

The 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.getRowProps()} >
{...row.getRowProps()}
>

{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
Copy link
Collaborator

Choose a reason for hiding this comment

The 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
//conditonally renders custom cell component based on cell.column.id prop value
// Conditonally renders custom cell component based on cell.column.id prop value.

cell.column.id === "lastUpdated"
? <LastUpdatedCell
time={cell.value}
reactTableCellProps={cell.getCellProps()}
classes={{ root: classes.columnBorders }}
/>
:
<TableCell
{...cell.getCellProps()}
classes={{ root: classes.columnBorders }}
>
Copy link
Collaborator

Choose a reason for hiding this comment

The 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.column.id === "lastUpdated"
? <LastUpdatedCell
time={cell.value}
reactTableCellProps={cell.getCellProps()}
classes={{ root: classes.columnBorders }}
/>
:
<TableCell
{...cell.getCellProps()}
classes={{ root: classes.columnBorders }}
>
cell.column.id === "lastUpdated"
? (
<LastUpdatedCell
time={cell.value}
reactTableCellProps={cell.getCellProps()}
classes={{ root: classes.columnBorders }}
/>
)
: (
<TableCell
{...cell.getCellProps()}
classes={{ root: classes.columnBorders }}
>
)

{cell.value}
</TableCell>
)

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove extra blank line.

))}
</TableRow>
);
Expand Down