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

[EuiTablePagination] Incorrect type for itemsPerPage and itemsPerPageOptions depending on pagination.pageSizeOptions #5697

Closed
thompsongl opened this issue Mar 7, 2022 · 1 comment · Fixed by #5699

Comments

@thompsongl
Copy link
Contributor

thompsongl commented Mar 7, 2022

Given the following configuration:

const [pageIndex, setPageIndex] = useState(0);
const [pageSize, setPageSize] = useState(5);

return (
<EuiInMemoryTable
  items={items}
  columns={columns}
  pagination={{
    pageIndex,
    pageSize,
    totalItemCount,
    pageSizeOptions: [5, 10, 15, 20],
  }}
  onTableChange={({ page: { index, size } }) => {
    setPageIndex(index);
    setPageSize(size);
  }}
/>
);

Consumers will get confusing type warnings for setPageSize(size) of the following shape:

Argument of type 'number | "all"' is not assignable to parameter of type 'SetStateAction<number>'.
  Type 'string' is not assignable to type 'SetStateAction<number>'.

'all' is not a valid return value for page.size in this scenario because the return type of onTableChange has not taken pagination.pageSizeOptions into account.
'number | "all"' should only be the return type if pagination.pageSizeOptions also includes 'all'.

Similarly, itemsPerPage page should only accept 'all' when pagination.pageSizeOptions also includes 'all'

NB: 'all' was introduced in #5547

@thompsongl
Copy link
Contributor Author

This causes quite a few type errors in elastic/kibana#126926, mostly related to EuiInMemoryTable.onTableChange (as noted in the summary).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
1 participant