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
59 changes: 58 additions & 1 deletion src/components/DataTable/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,27 @@ 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 TableFooter from '@material-ui/core/TableFooter';
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: {
display: 'none',
},
tablePaginationRoot: {
position: 'relative',
left: '207%',
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think we need this. You can look at how they do it in https://material-ui.com/demos/tables/.

},
}))
/**
* A table to display a set of data elements.
*/
Expand All @@ -26,6 +39,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 +84,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,17 +98,25 @@ 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>
Expand Down Expand Up @@ -115,9 +145,36 @@ export default class DataTable extends Component {
</TableCell>
</TableRow>
) : (
items.map(renderRow)
items
.slice(page * rowsPerPage, page * rowsPerPage + rowsPerPage)
.map(renderRow)
)}
</TableBody>
{isPaginate && (
<TableFooter>
<TableRow>
<TablePagination
Copy link
Contributor

Choose a reason for hiding this comment

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

Screen Shot 2019-03-13 at 9 03 49 AM

We should:

  • Have the TablePagination outside the table. This would make sure the pagination is always displayed to the user even when the table is being viewed on a small screen where scrolling is required to view the data. There's an example of that in https://material-ui.com/demos/tables/#sorting-amp-selecting. Basically you will need to remove TableFooter and TableRow and then have TablePagination outside the table.
  • The table should be scrollable similar to how all the tables are in the material site.

classes={{
root: classes.tablePaginationRoot,
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}
/>
</TableRow>
</TableFooter>
)}
</Table>
);
}
Expand Down
Loading