52 lines
1.2 KiB
TypeScript
52 lines
1.2 KiB
TypeScript
import React from "react";
|
|
import { Paginated } from "../../services/Paginated";
|
|
import Column from "./columns";
|
|
import Pagination from "./Pagination";
|
|
|
|
export interface TableFooterProps<T> {
|
|
data: Paginated<T>;
|
|
columns: Column<T>[];
|
|
showEdit: boolean;
|
|
showDelete: boolean;
|
|
showAudit: boolean;
|
|
showSecondaryAudit: boolean;
|
|
onChangePage?: (page: number, pageSize: number) => void;
|
|
onUnselectRow?: () => void;
|
|
}
|
|
|
|
export default function TableFooter<T>({
|
|
data,
|
|
columns,
|
|
showEdit,
|
|
showDelete,
|
|
showAudit,
|
|
showSecondaryAudit,
|
|
onChangePage,
|
|
onUnselectRow,
|
|
}: TableFooterProps<T>): JSX.Element | null {
|
|
let staticColumnCount = 0;
|
|
if (showEdit) staticColumnCount++;
|
|
if (showDelete) staticColumnCount++;
|
|
if (showAudit) staticColumnCount++;
|
|
if (showAudit && showSecondaryAudit) staticColumnCount++;
|
|
|
|
const pagination =
|
|
onChangePage === undefined ? undefined : (
|
|
<Pagination
|
|
data={data}
|
|
onChangePage={onChangePage}
|
|
onUnselect={onUnselectRow}
|
|
/>
|
|
);
|
|
|
|
if (!pagination) return null;
|
|
|
|
return (
|
|
<tfoot>
|
|
<tr>
|
|
<td colSpan={columns.length + staticColumnCount}>{pagination}</td>
|
|
</tr>
|
|
</tfoot>
|
|
);
|
|
}
|