Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
112 changes: 70 additions & 42 deletions src/js/components/common/ListTable/TablePagination.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,44 @@ interface PaginationControlsProps {
setCurrentPage: (page: number) => void
}

type NavigationLinksProps = Omit<PaginationControlsProps, 'totalItems'>

const NavigationLinks: React.FC<NavigationLinksProps> = ({
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

What's the benefit in taking this block out specifically? I don't think the original component was overly complex, and this leads to more mass prop-drilling.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Lint warning:

Arrow function has too many lines (52). Maximum allowed is 50 max-lines-per-function

which,
disabled,
totalPages,
inputValue,
currentPage,
useQueryVars,
setCurrentPage,
setInputValue
}) => (
<span className="pagination-links">
<BackwardNavigationButtons
disabled={disabled}
currentPage={currentPage}
renderAsLinks={useQueryVars}
setCurrentPage={setCurrentPage}
/>
<CurrentPage
which={which}
disabled={disabled}
totalPages={totalPages}
currentPage={currentPage}
inputValue={inputValue}
setInputValue={setInputValue}
confirmInputValue={() => setCurrentPage(inputValue)}
/>{'\n'}
<ForwardNavigationButtons
disabled={disabled}
totalPages={totalPages}
currentPage={currentPage}
renderAsLinks={useQueryVars}
setCurrentPage={setCurrentPage}
/>
</span>
)

const PaginationControls: React.FC<PaginationControlsProps> = ({
which,
disabled,
Expand All @@ -188,49 +226,39 @@ const PaginationControls: React.FC<PaginationControlsProps> = ({
useQueryVars,
setCurrentPage,
setInputValue
}) =>
<form
className={classnames('tablenav-pages', {
'one-page': totalPages && 1 === totalPages,
'no-pages': !totalPages
})}
onSubmit={event => {
event.preventDefault()
setCurrentPage(inputValue)
}}
>
<span className="displaying-num">
{/* translators: %s: Number of items. */}
{sprintf(_n('%s item', '%s items', totalItems), totalItems)}
</span>{'\n'}

<span className="pagination-links">
<BackwardNavigationButtons
disabled={disabled}
currentPage={currentPage}
renderAsLinks={useQueryVars}
setCurrentPage={setCurrentPage}
/>

<CurrentPage
which={which}
disabled={disabled}
totalPages={totalPages}
currentPage={currentPage}
inputValue={inputValue}
setInputValue={setInputValue}
confirmInputValue={() => setCurrentPage(inputValue)}
/>{'\n'}
}) => {
const navLabel = 'top' === which
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This variable would be cleaner inlined, IMO.

? __('Pagination, before the table', 'code-snippets')
: __('Pagination, after the table', 'code-snippets')

<ForwardNavigationButtons
disabled={disabled}
totalPages={totalPages}
currentPage={currentPage}
renderAsLinks={useQueryVars}
setCurrentPage={setCurrentPage}
/>
</span>
</form>
return (
<nav aria-label={navLabel}>
<form
className={classnames('tablenav-pages', {
'one-page': totalPages && 1 === totalPages,
'no-pages': !totalPages
})}
onSubmit={event => {
event.preventDefault()
setCurrentPage(inputValue)
}}
>
<span className="displaying-num">
{
sprintf(
// translators: %s: Number of items.
_n('%s item', '%s items', totalItems),
totalItems
)
}
</span>{'\n'}
<NavigationLinks
{...{ which, disabled, totalPages, inputValue, currentPage, useQueryVars, setCurrentPage, setInputValue }}
/>
</form>
</nav>
)
}

export interface TablePaginationProps extends Omit<ListTablePaginationProps, 'totalPages'>,
Required<Pick<ListTablePaginationProps, 'totalPages'>> {
Expand Down
Loading