Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Table] Add a TableFooter for pagination #8254

Merged
merged 14 commits into from
Sep 20, 2017

Conversation

leMaik
Copy link
Member

@leMaik leMaik commented Sep 18, 2017

This PR adds a new TableFooter component and extends the EnhancedTable demo to demonstrate pagination. It also adds the missing Android versions to the nutrition list. 🍰 🍭

Specs:
image

This PR:
image

  • Add a TableFooter, similar to TableHead
  • Add pixel-perfect pagination footer for tables
  • Add tests for TableFooter
  • Move the pagination code into a TablePagination component as suggested in [Table] Add support for pagination #7746 (comment) and immediately add tests this time
  • Refactor TablePagination to a class and fix a bug when increasing the rows per page results in displaying pages that don't exist anymore
  • Add TypeScript typings

Closes #7746

This also adds more demo data, and yes, the nutrition information of Marshmallow, Nougat and Oreo is actually real.
Copy link
Member

@oliviertassinari oliviertassinari left a comment

Choose a reason for hiding this comment

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

I'm happy to see this PR :).
I have only noticed one important issue. The checkbox logic seems to be broken with the pagination. For instance, try selection everything. The top checkbox won't be checked.

@@ -148,6 +154,118 @@ EnhancedTableToolbar.propTypes = {

EnhancedTableToolbar = withStyles(toolbarStyles)(EnhancedTableToolbar);

const footerStyles = theme => ({
cell: {
padding: '0 !important',
Copy link
Member

Choose a reason for hiding this comment

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

What's the important for? It's the first introduction of such pattern. It shouldn't be needed. And if we do, something is wrong.

Copy link
Member Author

Choose a reason for hiding this comment

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

Maybe something is wrong, because something forced the cell to keep having padding even if I set padding to zero here. !important fixed this. I'll look into that later.

Copy link
Member

Choose a reason for hiding this comment

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

I can have a look at this.

Copy link
Member Author

Choose a reason for hiding this comment

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

I'd really appreciate your help on this, I'll focus on the other things in the meantime. 👍

flex: '1 1 100%',
},
select: {
marginLeft: 8,
Copy link
Member

Choose a reason for hiding this comment

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

don't hesitate to use theme.spacing.unit.

},
});

let EnhancedTableFooter = props => {
Copy link
Member

Choose a reason for hiding this comment

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

It's the first introduction of an anonymous arrow function, please stick to the function convention we use.

Copy link
Member Author

Choose a reason for hiding this comment

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

It isn't, look at EnhancedTableToolbar. 😉

Copy link
Member

@oliviertassinari oliviertassinari Sep 18, 2017

Choose a reason for hiding this comment

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

🙈 oh nooo entropyyyy -sum p*log(p)

Copy link
Member Author

Choose a reason for hiding this comment

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

Don't worry, I'll change both.

Copy link
Member Author

Choose a reason for hiding this comment

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

I know why this is an anonymous arrow function! To apply the styles, the variable is re-assigned, which throws a linter error (no-func-assign) if they are functions.
What to do now?

value={rowsPerPage}
onChange={onChangeRowsPerPage}
>
{rowsPerPageOptions.map(v => (
Copy link
Member

Choose a reason for hiding this comment

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

It would be better to use an explicit variable name instead of v.


type AllProps = DefaultProps & Props;

class TableFooter extends React.Component<AllProps, void> {
Copy link
Member

Choose a reason for hiding this comment

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

Is void needed? I thought that React.Component<AllProps> was enough. I could be wrong, I'm not much involved into flow.

Copy link
Member Author

@leMaik leMaik Sep 18, 2017

Choose a reason for hiding this comment

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

I'm pretty sure that I didn't write that but just copied this or the prettier added this. 🤔

Edit: It's React.Component<AllProps, void> in the other Table components, too.

@oliviertassinari oliviertassinari added component: table This is the name of the generic UI component, not the React module! docs Improvements or additions to the documentation v1 labels Sep 18, 2017
@oliviertassinari
Copy link
Member

oliviertassinari commented Sep 18, 2017

Move the pagination code into a TablePagination

@leMaik What do you have in mind for this abstraction? For instance. How do you want to design the API?

@oliviertassinari oliviertassinari added the PR: needs revision The pull request can't be merged. More details is available on the code review or fails in the CI label Sep 18, 2017
component: 'tfoot',
};

getChildContext() {
Copy link
Member Author

Choose a reason for hiding this comment

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

Same as in TableHead, it makes a TableRow know that it is nested inside a TableFooter so that it doesn't show the bottom line.

@leMaik
Copy link
Member Author

leMaik commented Sep 18, 2017

@oliviertassinari Basically, I'd just move the EnhancedTableFooter and rename and refactor it a bit. I'll also add a way to customize the strings (for i18n). I really care about the design and layout to look as shown in the specs, so I'd rather not make this too flexible for now.

@oliviertassinari
Copy link
Member

oliviertassinari commented Sep 18, 2017

@leMaik Sounds good. I have found that having placeholders is what provides a good correctness/flexibility ratio.

@leMaik
Copy link
Member Author

leMaik commented Sep 18, 2017

@oliviertassinari Fixed the things you mentioned in the review, now working on tests and refactoring. ⚙️

Regarding flexibility: After all, the entire footer can be swapped out, this component just adds one way of doing pagination. It can be seen as a pretty big placeholder already.

@leMaik
Copy link
Member Author

leMaik commented Sep 18, 2017

Just found another major issue thanks to argos: I completely broke the sorting. 😅
Edit: Fixed

@leMaik
Copy link
Member Author

leMaik commented Sep 19, 2017

@oliviertassinari I'm done with this so far, would you mind taking another look at the PR? CI doesn't want to run because I increased the build size, but obviously adding a component increases it. 😅

@codecov-io
Copy link

codecov-io commented Sep 19, 2017

Codecov Report

Merging #8254 into v1-beta will decrease coverage by 0.08%.
The diff coverage is 87.5%.

Impacted file tree graph

@@             Coverage Diff             @@
##           v1-beta    #8254      +/-   ##
===========================================
- Coverage    99.42%   99.33%   -0.09%     
===========================================
  Files          147      149       +2     
  Lines         2242     2258      +16     
===========================================
+ Hits          2229     2243      +14     
- Misses          13       15       +2
Impacted Files Coverage Δ
src/Table/TableCell.js 100% <ø> (ø) ⬆️
src/Table/TableFooter.js 100% <100%> (ø)
src/Table/TablePagination.js 77.77% <77.77%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 7b4b53a...32008a9. Read the comment docs.

@@ -178,9 +191,10 @@ class EnhancedTable extends React.Component {
order = 'asc';
}

const data = this.state.data.sort(
(a, b) => (order === 'desc' ? b[orderBy] > a[orderBy] : a[orderBy] > b[orderBy]),
Copy link
Member

Choose a reason for hiding this comment

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

Yeah, I think that the logic was broken 👍

Copy link
Member Author

Choose a reason for hiding this comment

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

It returned true and false instead of a negative or positive number.

@@ -220,11 +234,19 @@ class EnhancedTable extends React.Component {
this.setState({ selected: newSelected });
};

handleChangePage = (e, page) => {
Copy link
Member

Choose a reason for hiding this comment

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

💣 Please stick to verbose variable names: event.

@oliviertassinari
Copy link
Member

oliviertassinari commented Sep 19, 2017

@leMaik Excellent work so far. I think that we only miss the typescript definition of TablePagination and some test coverage to merge this PR 💃 .

@leMaik
Copy link
Member Author

leMaik commented Sep 19, 2017

@oliviertassinari Currently working on the test coverage and the bug that argos just discovered (EnhancedTable is not sorted after mounting).
Look at the last item in my TODO list above, there's still some work left but we're getting there. :)

@oliviertassinari
Copy link
Member

@leMaik Oh ok, feel free to continue the PR then :). If you plan to keep opening great PRs like this one here, I will give you the push right access to the repository. It can make the process easier.

@leMaik
Copy link
Member Author

leMaik commented Sep 19, 2017

@oliviertassinari Could you manually confirm the changes in argos? The table is now properly sorted, it just looks different because there are new sweets.

I added more tests and typings, so now I'm really actually done as long as you don't have any further suggestions. 🎉

If you plan to keep opening great PRs like this one here, I will give you the push right access to the repository. It can make the process easier.

I feel honored. :) While I do plan to keep contributing to material-ui, I can't guarantee the interval of the contributions. 😅

@@ -16,7 +16,10 @@ import KeyboardArrowRight from '../svg-icons/KeyboardArrowRight';

export const styles = (theme: Object) => ({
cell: {
padding: '0 !important',
// Increase the specificity to override TableCell.
'&:last-child': {
Copy link
Member Author

Choose a reason for hiding this comment

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

Nice! Didn't think about this.

@oliviertassinari oliviertassinari merged commit 35989a9 into mui:v1-beta Sep 20, 2017
@oliviertassinari oliviertassinari added PR: accepted and removed PR: needs revision The pull request can't be merged. More details is available on the code review or fails in the CI labels Sep 20, 2017
@oliviertassinari
Copy link
Member

@leMaik Awesome

I feel honored. :)

You do deserve it. You have been, with your team, did a great job: https://mui.wertarbyte.com/. Yes, no pressure :).

@leMaik leMaik deleted the table-footer branch September 20, 2017 09:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component: table This is the name of the generic UI component, not the React module! docs Improvements or additions to the documentation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants