Skip to content

Commit b578e12

Browse files
authored
Merge pull request #49 from david-roper/client-table-pages
Add Client table first and last page buttons
2 parents aae29aa + 31e6630 commit b578e12

File tree

4 files changed

+58
-1
lines changed

4 files changed

+58
-1
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import { render, screen } from '@testing-library/react';
2+
import { describe, expect, it } from 'vitest';
3+
4+
import { ClientTable } from './ClientTable';
5+
6+
const TEST_ID = 'ClientTable';
7+
const FIRST_BUTTON_ID = 'first-page-button';
8+
const PREVIOUS_BUTTON_ID = 'previous-page-button';
9+
const NEXT_BUTTON_ID = 'next-page-button';
10+
const LAST_BUTTON_ID = 'last-page-button';
11+
12+
describe('ClientTable', () => {
13+
it('should render', () => {
14+
render(<ClientTable columns={[]} data={[]} minRows={10} />);
15+
expect(screen.getByTestId(TEST_ID)).toBeInTheDocument();
16+
expect(screen.getByTestId(FIRST_BUTTON_ID)).toBeInTheDocument();
17+
expect(screen.getByTestId(PREVIOUS_BUTTON_ID)).toBeInTheDocument();
18+
expect(screen.getByTestId(NEXT_BUTTON_ID)).toBeInTheDocument();
19+
expect(screen.getByTestId(LAST_BUTTON_ID)).toBeInTheDocument();
20+
});
21+
it('should contain a custom class name', () => {
22+
render(<ClientTable className="foo" columns={[]} data={[]} minRows={10} />);
23+
expect(screen.getByTestId(TEST_ID)).toHaveClass('foo');
24+
});
25+
});

src/components/ClientTable/ClientTable.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ export const ClientTable = <T extends ClientTableEntry>({
8585
const nRows = Math.max(currentEntries.length, minRows ?? -1);
8686

8787
return (
88-
<div className={className} {...props}>
88+
<div className={className} {...props} data-testid="ClientTable">
8989
<div className="rounded-md border bg-card tracking-tight text-muted-foreground shadow-sm">
9090
<Table>
9191
<Table.Header>

src/components/ClientTable/ClientTablePagination.tsx

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,18 @@ export const ClientTablePagination = ({
2727
</div>
2828
<div className="flex flex-1 justify-between gap-3 sm:justify-end">
2929
<Button
30+
data-testid="first-page-button"
31+
disabled={currentPage === 1}
32+
type="button"
33+
variant="outline"
34+
onClick={() => {
35+
setCurrentPage(1);
36+
}}
37+
>
38+
{t('pagination.firstPage')}
39+
</Button>
40+
<Button
41+
data-testid="previous-page-button"
3042
disabled={currentPage === 1}
3143
type="button"
3244
variant="outline"
@@ -37,6 +49,7 @@ export const ClientTablePagination = ({
3749
{t('pagination.previous')}
3850
</Button>
3951
<Button
52+
data-testid="next-page-button"
4053
disabled={currentPage === pageCount}
4154
type="button"
4255
variant="outline"
@@ -46,6 +59,17 @@ export const ClientTablePagination = ({
4659
>
4760
{t('pagination.next')}
4861
</Button>
62+
<Button
63+
data-testid="last-page-button"
64+
disabled={currentPage === pageCount}
65+
type="button"
66+
variant="outline"
67+
onClick={() => {
68+
setCurrentPage(pageCount);
69+
}}
70+
>
71+
{t('pagination.lastPage')}
72+
</Button>
4973
</div>
5074
</div>
5175
);

src/i18n/translations/libui.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,14 @@
143143
"previous": {
144144
"en": "Previous",
145145
"fr": "Précédent"
146+
},
147+
"firstPage": {
148+
"en": "<< First",
149+
"fr": "<< Première"
150+
},
151+
"lastPage": {
152+
"en": "Last >>",
153+
"fr": "Dernière >>"
146154
}
147155
},
148156
"searchBar": {

0 commit comments

Comments
 (0)