-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'staging' into enhancement-default-sort-order
- Loading branch information
Showing
10 changed files
with
281 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30,4 +30,5 @@ yarn-error.log* | |
/api/venv | ||
__pycache__/ | ||
venv-manager.log | ||
/api/.env | ||
/api/.env | ||
/api/webqueueapi.egg-info |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import React from 'react' | ||
import PropTypes from "prop-types"; | ||
import { makeStyles, TableCell, useTheme } from '@material-ui/core' | ||
|
||
export default function ItemTableCell({ children, TableCellProps }) { | ||
const theme = useTheme(); | ||
const useStyles = makeStyles({ | ||
columnBorders: { | ||
// Add column borders | ||
borderLeftWidth: "1px", | ||
borderLeftStyle: "solid", | ||
borderColor: theme.palette.type === "light" ? theme.palette.grey[300] : theme.palette.grey[500] | ||
}, | ||
}) | ||
|
||
const classes = useStyles(); | ||
return ( | ||
<TableCell | ||
classes={{ root: classes.columnBorders }} | ||
{...TableCellProps} | ||
> | ||
{children} | ||
</TableCell> | ||
); | ||
} | ||
|
||
ItemTableCell.propTypes = { | ||
/** Child object passed to display cell data. */ | ||
"children": PropTypes.object, | ||
/** Props applied to the TableCell component. */ | ||
"TableCellProps": PropTypes.object | ||
}; | ||
|
||
ItemTableCell.defaultProps = { | ||
"children": {}, | ||
"TableCellProps": {}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
The ItemTableCell wraps an [MUI TableCell](https://material-ui.com/api/table-cell/) and adds styling. | ||
|
||
## Default Usage | ||
```jsx | ||
import { Paper } from '@material-ui/core'; | ||
import ItemTableCell from "./ItemTableCell"; | ||
|
||
<Paper> | ||
<ItemTableCell> | ||
Hello, moto! | ||
</ItemTableCell> | ||
</Paper> | ||
``` | ||
|
||
```jsx static | ||
<Paper> | ||
<ItemTableCell> | ||
Hello, moto! | ||
</ItemTableCell> | ||
</Paper> | ||
``` | ||
|
||
## Forwarded TableCell Props | ||
Props can be passed to the TableCell component using the TableCellProps prop. | ||
```jsx | ||
import { Paper } from '@material-ui/core'; | ||
import ItemTableCell from "./ItemTableCell"; | ||
|
||
<ItemTableCell TableCellProps={{ component: Paper, variant: "footer" }}> | ||
Hello, moto! | ||
</ItemTableCell> | ||
``` | ||
|
||
```jsx static | ||
<ItemTableCell TableCellProps={{ component: Paper, variant: "footer" }}> | ||
Hello, moto! | ||
</ItemTableCell> | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import ItemTableCell from "./ItemTableCell"; | ||
|
||
export default ItemTableCell; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
import React from 'react' | ||
import PropTypes from "prop-types"; | ||
import { useTheme } from '@material-ui/core'; | ||
import { red } from '@material-ui/core/colors'; | ||
import RelativeTime from 'react-relative-time'; | ||
import ItemTableCell from '../ItemTableCell'; | ||
|
||
export default function LastUpdatedCell({ time, ItemTableCellProps }) { | ||
|
||
const theme = useTheme(); | ||
|
||
/** | ||
* Returns a color showing how old an item is. | ||
* @param {string} time ISO 8601 formatted time string. | ||
* @example | ||
* // Returns "#e57373" | ||
* timeToBackgroundColor("2021-01-04T11:47:00-0500") | ||
* @returns {string} Hex color code. | ||
*/ | ||
const timeToBackgroundColor = (time) => { | ||
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 = theme.palette.background.paper; | ||
|
||
// 1-6 days old | ||
if (timeDelta > day && timeDelta <= week) { | ||
backgroundColor = red[100]; | ||
} | ||
// 7-28 days old | ||
else if (timeDelta > week && timeDelta <= month) { | ||
backgroundColor = red[300]; | ||
} | ||
// 29+ days old | ||
else if (timeDelta > month) { | ||
backgroundColor = red[500]; | ||
} | ||
|
||
return backgroundColor; | ||
} | ||
|
||
// Insert the calculated background color into props so it isn't overriden. | ||
// Inspired by: https://github.com/mui-org/material-ui/issues/19479 | ||
ItemTableCellProps = { | ||
...ItemTableCellProps, | ||
style: { | ||
...ItemTableCellProps.style, | ||
backgroundColor: timeToBackgroundColor(time) | ||
} | ||
}; | ||
|
||
return ( | ||
<ItemTableCell TableCellProps={ItemTableCellProps}> | ||
<RelativeTime value={time} /> | ||
</ItemTableCell> | ||
); | ||
}; | ||
|
||
LastUpdatedCell.propTypes = { | ||
/** ISO 8601 formatted time string, Date object or UNIX time. See: https://www.npmjs.com/package/react-relative-time */ | ||
"time": PropTypes.string.isRequired, | ||
/** Props to be applied to the ItemTableCell. */ | ||
"ItemTableCellProps": PropTypes.object, | ||
}; | ||
|
||
LastUpdatedCell.defaultProps = { | ||
"ItemTableCellProps": {}, | ||
}; |
Oops, something went wrong.