-
Notifications
You must be signed in to change notification settings - Fork 843
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
Add ability to specify default page size for EuiInMemoryTable #477
Add ability to specify default page size for EuiInMemoryTable #477
Conversation
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.
Awesome! Thanks for doing this Jen. I just had a couple suggestions.
@@ -34,6 +34,10 @@ const InMemoryTablePropTypes = { | |||
PropTypes.bool, | |||
PropTypes.shape({ | |||
pageSizeOptions: PropTypes.arrayOf(PropTypes.number) | |||
}), | |||
PropTypes.shape({ | |||
defaultPageSize: PropTypes.number, |
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.
We've been using the term initial
in other places to indicate the initial value of a prop which the user can later change. Can we rename this to initialPageSize
?
@@ -54,7 +58,10 @@ const initialCriteria = (props) => { | |||
return { | |||
page: !pagination ? undefined : { | |||
index: 0, | |||
size: pagination.pageSizeOptions ? pagination.pageSizeOptions[0] : paginationBarDefaults.pageSizeOptions[0] | |||
size: pagination.pageSizeOptions ? ( |
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 was having a hard time parsing these nested ternaries. Can we simplify this a bit, and also throw an error if the user has misconfigured the initial page size?
const initialCriteria = (props) => {
if (!props.pagination) {
return {
page: undefined,
};
}
const {
pagination: {
pageSizeOptions,
initialPageSize,
}
} = props;
if (initialPageSize && !pageSizeOptions.includes(initialPageSize)) {
throw new Error(`EuiInMemoryTable received initialPageSize ${initialPageSize}, which wasn't provided within pageSizeOptions.`);
}
const defaultPageSize = pageSizeOptions ? pageSizeOptions[0] : paginationBarDefaults.pageSizeOptions[0];
return {
page: {
index: 0,
size: initialPageSize || defaultPageSize,
}
};
};
Thanks for the feedback @cjcenizal, updated! |
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.
🔥 LGTM!
Oh and don't forget to update the |
Currently
EuiInMemoryTable
uses the first element inpageSizeOptions
as the initial page size. This allows a different initial page size to be specified.