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

Add ability to specify default page size for EuiInMemoryTable #477

Merged

Conversation

jen-huang
Copy link
Contributor

Currently EuiInMemoryTable uses the first element in pageSizeOptions as the initial page size. This allows a different initial page size to be specified.

Copy link
Contributor

@cjcenizal cjcenizal left a 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,
Copy link
Contributor

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 ? (
Copy link
Contributor

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,
    }
  };
};

@jen-huang
Copy link
Contributor Author

Thanks for the feedback @cjcenizal, updated!

Copy link
Contributor

@cjcenizal cjcenizal left a comment

Choose a reason for hiding this comment

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

🔥 LGTM!

@cjcenizal
Copy link
Contributor

Oh and don't forget to update the CHANGELOG.md.

@jen-huang jen-huang merged commit b3dd10b into elastic:master Mar 8, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants