Skip to content

Commit 6cde6a7

Browse files
committed
feat: allows to hide the footer of the datatable
1 parent 13a535a commit 6cde6a7

File tree

2 files changed

+32
-14
lines changed

2 files changed

+32
-14
lines changed

packages/diracx-web-components/src/components/shared/DataTable.tsx

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,7 @@ function DataTableToolbar<T extends Record<string, unknown>>({
209209
* @property {React.ReactElement} toolbarComponents - the components to display in the toolbar
210210
* @property {MenuItem[]} menuItems - the menu items
211211
* @property {boolean} disableCheckbox - boolean to disable the checkbox
212+
* @property {boolean} hideFooter - boolean to hide the footer
212213
*/
213214
export interface DataTableProps<T extends Record<string, unknown>> {
214215
/** The title of the table */
@@ -231,6 +232,8 @@ export interface DataTableProps<T extends Record<string, unknown>> {
231232
menuItems?: MenuItem[];
232233
/** Boolean to disable the checkbox */
233234
disableCheckbox?: boolean;
235+
/** Whether to hide the footer */
236+
hideFooter?: boolean;
234237
}
235238

236239
/**
@@ -249,6 +252,7 @@ export function DataTable<T extends Record<string, unknown>>({
249252
toolbarComponents,
250253
menuItems,
251254
disableCheckbox = false,
255+
hideFooter = false,
252256
}: DataTableProps<T>) {
253257
const theme = useTheme();
254258
const isMobile = useMediaQuery(theme.breakpoints.down("sm"));
@@ -602,19 +606,22 @@ export function DataTable<T extends Record<string, unknown>>({
602606
);
603607
}}
604608
/>
605-
<TablePagination
606-
component="div"
607-
rowsPerPageOptions={[25, 50, 100, 500, 1000]}
608-
count={totalRows}
609-
showFirstButton
610-
showLastButton
611-
rowsPerPage={table.getState().pagination.pageSize}
612-
page={table.getState().pagination.pageIndex}
613-
onPageChange={handleChangePage}
614-
onRowsPerPageChange={handleChangeRowsPerPage}
615-
labelRowsPerPage={isMobile ? "" : "Rows per page"}
616-
sx={{ flexShrink: 0 }}
617-
/>
609+
{!hideFooter && (
610+
<TablePagination
611+
component="div"
612+
rowsPerPageOptions={[25, 50, 100, 500, 1000]}
613+
count={totalRows}
614+
showFirstButton
615+
showLastButton
616+
rowsPerPage={table.getState().pagination.pageSize}
617+
page={table.getState().pagination.pageIndex}
618+
onPageChange={handleChangePage}
619+
onRowsPerPageChange={handleChangeRowsPerPage}
620+
labelRowsPerPage={isMobile ? "" : "Rows per page"}
621+
sx={{ flexShrink: 0 }}
622+
data-testid="data-table-pagination"
623+
/>
624+
)}
618625
</Paper>
619626
{menuItems && (
620627
<Menu

packages/diracx-web-components/test/DataTable.test.tsx

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,17 @@
1-
import { render, screen, fireEvent } from "@testing-library/react";
1+
import { render, screen, fireEvent, cleanup } from "@testing-library/react";
22
import "@testing-library/jest-dom";
33
import { composeStories } from "@storybook/react";
4+
import { afterEach, describe, it, expect } from "@jest/globals";
45
import * as stories from "../stories/DataTable.stories";
56

67
// Compose the stories to get actual Storybook behavior (decorators, args, etc)
78
const { Default } = composeStories(stories);
89

10+
afterEach(() => {
11+
// Clean up the DOM after each test to avoid strange behavior
12+
cleanup();
13+
});
14+
915
describe("DataTable", () => {
1016
it("renders table title", () => {
1117
render(<Default />);
@@ -32,4 +38,9 @@ describe("DataTable", () => {
3238
expect(screen.getByText("Edit")).toBeInTheDocument();
3339
}
3440
});
41+
42+
it("hide footer when hideFooter prop is true", () => {
43+
const { queryByTestId } = render(<Default hideFooter={true} />);
44+
expect(queryByTestId("data-table-pagination")).not.toBeInTheDocument();
45+
});
3546
});

0 commit comments

Comments
 (0)