import React from "react"; import { Table, TableContainer, Tbody, Td, Th, Thead, Tr, Skeleton, TableCaption, Checkbox, } from "@chakra-ui/react"; import EmptySearchList from "../EmptySearchList"; import { TABLE_PAGINATION } from "../../Constants/Paginations"; const NormalTable = ({ data, isLoading, tableHeadRow, emptyMessage, centered, total, showRadioButton, // Prop for showing the checkboxes selectedRadio, setSelectedRadio, // State for managing selected checkboxes }) => { const columnWidth = data && data[0] ? `${(100 / Object.keys(data[0]).length).toFixed(2)}%` : "auto"; // Toggle checkbox selection for individual rows const handleCheckboxChange = (value) => { setSelectedRadio((prev) => { if (prev.includes(value)) { // Remove if already selected return prev.filter((id) => id !== value); } else { // Add to selected return [...prev, value]; } }); }; // Handle "Check All" checkbox const handleCheckAllChange = () => { if (selectedRadio.length === data.length) { setSelectedRadio([]); // Deselect all if already selected } else { const allIds = data.map((item) => item.id); setSelectedRadio(allIds); // Select all } }; return ( {data?.length === 0 ? ( ) : ( {total ? total : "Tanami v1.0.0"} {showRadioButton && ( )} {tableHeadRow.map((heading, index) => ( ))} {isLoading ? Array.from({ length: TABLE_PAGINATION?.size }).map( (_, index) => ( {tableHeadRow.map((_, i) => ( ))} ) ) : data?.map((item, index) => ( {showRadioButton && ( )} {tableHeadRow.map((heading, i) => ( ))} ))}
{isLoading ? : heading}
handleCheckboxChange(item.id)} /> {item[heading]}
)}
); }; export default NormalTable;