-
-
Notifications
You must be signed in to change notification settings - Fork 32.3k
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
Conversation
This also adds more demo data, and yes, the nutrition information of Marshmallow, Nougat and Oreo is actually real.
There was a problem hiding this 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', |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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, |
There was a problem hiding this comment.
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 => { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
. 😉
There was a problem hiding this comment.
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)
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 => ( |
There was a problem hiding this comment.
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> { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
@leMaik What do you have in mind for this abstraction? For instance. How do you want to design the API? |
component: 'tfoot', | ||
}; | ||
|
||
getChildContext() { |
There was a problem hiding this comment.
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.
@oliviertassinari Basically, I'd just move the |
@leMaik Sounds good. I have found that having placeholders is what provides a good correctness/flexibility ratio. |
…rding to the review
@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. |
Just found another major issue thanks to argos: I completely broke the sorting. 😅 |
…fix the sorting order in the EnhancedTable demo
@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 Report
@@ 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
Continue to review full report at Codecov.
|
@@ -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]), |
There was a problem hiding this comment.
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 👍
There was a problem hiding this comment.
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) => { |
There was a problem hiding this comment.
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
.
@leMaik Excellent work so far. I think that we only miss the typescript definition of |
@oliviertassinari Currently working on the test coverage and the bug that argos just discovered (EnhancedTable is not sorted after mounting). |
@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. |
…hanging the rows per page, lint the code
@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. 🎉
I feel honored. :) While I do plan to keep contributing to material-ui, I can't guarantee the interval of the contributions. 😅 |
src/Table/TablePagination.js
Outdated
@@ -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': { |
There was a problem hiding this comment.
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.
@leMaik Awesome
You do deserve it. You have been, with your team, did a great job: https://mui.wertarbyte.com/. Yes, no pressure :). |
This PR adds a new
TableFooter
component and extends theEnhancedTable
demo to demonstrate pagination. It also adds the missing Android versions to the nutrition list. 🍰 🍭Specs:
This PR:
TableFooter
, similar toTableHead
TableFooter
TablePagination
component as suggested in [Table] Add support for pagination #7746 (comment) and immediately add tests this timeTablePagination
to a class and fix a bug when increasing the rows per page results in displaying pages that don't exist anymoreCloses #7746