Skip to content
This repository has been archived by the owner on Mar 23, 2019. It is now read-only.

Bug 1520857- add support in tc-web for displaying information from the lastFire table #413

Open
wants to merge 14 commits into
base: master
Choose a base branch
from
4 changes: 2 additions & 2 deletions src/components/Button/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export default class Button extends Component {
spanProps: object,
};

handleButtonClick = () => {
handleButtonClick = e => {
const { onClick, track } = this.props;

if (track && process.env.GA_TRACKING_ID) {
Expand All @@ -60,7 +60,7 @@ export default class Button extends Component {
}

if (onClick) {
onClick();
onClick(e);
}
};

Expand Down
117 changes: 87 additions & 30 deletions src/components/DataTable/index.jsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { Component } from 'react';
import React, { Component, Fragment } from 'react';
import {
arrayOf,
func,
Expand All @@ -7,14 +7,28 @@ import {
oneOf,
oneOfType,
object,
bool,
Copy link
Contributor

Choose a reason for hiding this comment

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

Why are we adding pagination? Is the last fire endpoint paginated (i.e., uses continuation token)?

Copy link
Author

Choose a reason for hiding this comment

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

As per discussion with Dustin in irc we are keeping as many as 100 lastfire info rows for each hookId (expiration logic). Hence I think showing all rows at once won't be good.

Copy link
Contributor

Choose a reason for hiding this comment

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

We also only purge those once per day, so a particularly active hook might have many more rows than that at some time during the day!

} from 'prop-types';
import { withStyles } from '@material-ui/core/styles';
import Table from '@material-ui/core/Table';
import TableBody from '@material-ui/core/TableBody';
import TableCell from '@material-ui/core/TableCell';
import TableHead from '@material-ui/core/TableHead';
import TableSortLabel from '@material-ui/core/TableSortLabel';
import TableRow from '@material-ui/core/TableRow';
import TablePagination from '@material-ui/core/TablePagination';

@withStyles(() => ({
noDisplay: {
visibility: 'hidden',
},
table: {
minWidth: 1020,
},
tableWrapper: {
overflowX: 'auto',
},
}))
/**
* A table to display a set of data elements.
*/
Expand All @@ -26,6 +40,11 @@ export default class DataTable extends Component {
sortByHeader: null,
sortDirection: 'desc',
noItemsMessage: 'No items for this page.',
isPaginate: false,
};

state = {
page: 0,
};

static propTypes = {
Expand Down Expand Up @@ -66,6 +85,10 @@ export default class DataTable extends Component {
* A message to display when there is no items to display.
*/
noItemsMessage: string,
/**
* Whether to paginate the table
*/
isPaginate: bool,
};

handleHeaderClick = ({ target }) => {
Expand All @@ -76,49 +99,83 @@ export default class DataTable extends Component {
}
};

handleChangePage = (event, page) => {
this.setState({ page });
};

render() {
const {
classes,
items,
columnsSize,
renderRow,
headers,
sortByHeader,
sortDirection,
noItemsMessage,
isPaginate,
} = this.props;
const colSpan = columnsSize || (headers && headers.length) || 0;
const { page } = this.state;
const rowsPerPage = 5;

return (
<Table>
{headers && (
<TableHead>
<TableRow>
{headers.map(header => (
<TableCell key={`table-header-${header}`}>
<TableSortLabel
id={header}
active={header === sortByHeader}
direction={sortDirection || 'desc'}
onClick={this.handleHeaderClick}>
{header}
</TableSortLabel>
</TableCell>
))}
</TableRow>
</TableHead>
<Fragment>
<div className={classes.tableWrapper}>
<Table className={classes.table}>
{headers && (
<TableHead>
<TableRow>
{headers.map(header => (
<TableCell key={`table-header-${header}`}>
<TableSortLabel
id={header}
active={header === sortByHeader}
direction={sortDirection || 'desc'}
onClick={this.handleHeaderClick}>
{header}
</TableSortLabel>
</TableCell>
))}
</TableRow>
</TableHead>
)}
<TableBody>
{items.length === 0 ? (
<TableRow>
<TableCell colSpan={colSpan}>
<em>{noItemsMessage}</em>
</TableCell>
</TableRow>
) : (
items
.slice(page * rowsPerPage, page * rowsPerPage + rowsPerPage)
.map(renderRow)
)}
</TableBody>
</Table>
</div>
{isPaginate && (
<TablePagination
classes={{
spacer: classes.noDisplay,
caption: classes.noDisplay,
}}
component="div"
count={items.length}
rowsPerPage={rowsPerPage}
rowsPerPageOptions={[rowsPerPage]}
page={page}
backIconButtonProps={{
'aria-label': 'Previous Page',
}}
nextIconButtonProps={{
'aria-label': 'Next Page',
}}
onChangePage={this.handleChangePage}
/>
)}
<TableBody>
{items.length === 0 ? (
<TableRow>
<TableCell colSpan={colSpan}>
<em>{noItemsMessage}</em>
</TableCell>
</TableRow>
) : (
items.map(renderRow)
)}
</TableBody>
</Table>
</Fragment>
);
}
}
Loading