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
43 changes: 42 additions & 1 deletion src/components/DataTable/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,15 @@ 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 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';

/**
* A table to display a set of data elements.
Expand All @@ -26,6 +28,12 @@ export default class DataTable extends Component {
sortByHeader: null,
sortDirection: 'desc',
noItemsMessage: 'No items for this page.',
isPaginate: false,
};

state = {
page: 0,
rowsPerPage: 10,
};

static propTypes = {
Expand Down Expand Up @@ -66,6 +74,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,6 +88,14 @@ export default class DataTable extends Component {
}
};

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

handleChangeRowsPerPage = event => {
this.setState({ rowsPerPage: event.target.value });
};

render() {
const {
items,
Expand All @@ -85,8 +105,10 @@ export default class DataTable extends Component {
sortByHeader,
sortDirection,
noItemsMessage,
isPaginate,
} = this.props;
const colSpan = columnsSize || (headers && headers.length) || 0;
const { page, rowsPerPage } = this.state;

return (
<Table>
Expand Down Expand Up @@ -115,9 +137,28 @@ export default class DataTable extends Component {
</TableCell>
</TableRow>
) : (
items.map(renderRow)
items
.slice(page * rowsPerPage, page * rowsPerPage + rowsPerPage)
.map(renderRow)
)}
</TableBody>
{isPaginate && (
<TablePagination
rowsPerPageOptions={[5, 10, 25]}
component="div"
count={items.length}
rowsPerPage={rowsPerPage}
page={page}
backIconButtonProps={{
'aria-label': 'Previous Page',
}}
nextIconButtonProps={{
'aria-label': 'Next Page',
}}
onChangePage={this.handleChangePage}
onChangeRowsPerPage={this.handleChangeRowsPerPage}
/>
)}
</Table>
);
}
Expand Down
Loading