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

Do not show page stats when data set is empty #2994

Merged
merged 1 commit into from
Sep 18, 2024
Merged
Show file tree
Hide file tree
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
3 changes: 3 additions & 0 deletions assets/js/common/Pagination/PageStats.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ function PageStats({
itemsTotal = 1,
selectedPage,
}) {
if (itemsTotal === 0) {
return null;
}
const itemsBase = (selectedPage - 1) * currentItemsPerPage;
const lowerBound = itemsBase + 1;
const upperBound = itemsBase + itemsPresent;
Expand Down
8 changes: 8 additions & 0 deletions assets/js/common/Pagination/PageStats.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,14 @@ import '@testing-library/jest-dom';
import Pagination from '.';

describe('Page stats', () => {
it('should not render when there are no items', () => {
render(<Pagination itemsTotal={0} />);

expect(
screen.queryByText('Showing', { exact: false })
).not.toBeInTheDocument();
});

it('should render', () => {
render(
<Pagination
Expand Down
16 changes: 12 additions & 4 deletions assets/js/common/Pagination/Pagination.stories.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,15 @@ export default {
},
defaultValue: [10],
},
itemsTotal: {
control: {
type: 'number',
},
},
},
render: (args) => (
<Pagination
pages={args.pages}
currentPage={args.currentPage}
currentItemsPerPage={args.currentItemsPerPage}
itemsPerPageOptions={args.itemsPerPageOptions}
{...args}
onSelect={(value) => {
action('onSelect')(value);
}}
Expand All @@ -64,3 +66,9 @@ export const WithManyPages = {
currentPage: 20,
},
};

export const EmptyDataset = {
args: {
itemsTotal: 0,
},
};
Loading