2024-06-25 18:41:41 +05:30
|
|
|
import React, { useContext } from "react";
|
2024-06-21 20:32:14 +05:30
|
|
|
import {
|
|
|
|
|
Table,
|
|
|
|
|
TableContainer,
|
|
|
|
|
Tbody,
|
|
|
|
|
Td,
|
|
|
|
|
Th,
|
|
|
|
|
Thead,
|
|
|
|
|
Tr,
|
|
|
|
|
Skeleton,
|
|
|
|
|
TableCaption,
|
|
|
|
|
Tfoot,
|
|
|
|
|
} from "@chakra-ui/react";
|
2024-06-20 12:09:48 +05:30
|
|
|
import EmptySearchList from "../EmptySearchList";
|
2024-06-24 12:08:21 +05:30
|
|
|
import Pagination from "../Pagination";
|
2024-06-25 19:16:55 +05:30
|
|
|
import { useNavigate } from "react-router-dom";
|
2024-06-20 12:09:48 +05:30
|
|
|
|
2024-06-25 18:41:41 +05:30
|
|
|
import GlobalStateContext from "../../Contexts/GlobalStateContext";
|
2024-06-20 12:09:48 +05:30
|
|
|
|
2024-06-25 19:24:26 +05:30
|
|
|
const DataTable = ({
|
|
|
|
|
data,
|
|
|
|
|
isLoading,
|
|
|
|
|
tableHeadRow,
|
|
|
|
|
emptyMessage,
|
|
|
|
|
totalPages,
|
2024-06-25 19:16:55 +05:30
|
|
|
setMouseEntered,
|
2024-06-25 19:24:26 +05:30
|
|
|
setMouseEnteredId,
|
|
|
|
|
}) => {
|
|
|
|
|
const navigate = useNavigate();
|
2024-06-25 18:41:41 +05:30
|
|
|
const { slideFromRight } = useContext(GlobalStateContext);
|
|
|
|
|
|
2024-06-25 19:24:26 +05:30
|
|
|
const columnWidth =
|
|
|
|
|
data && data[0]
|
|
|
|
|
? `${(100 / Object.keys(data[0]).length).toFixed(2)}%`
|
|
|
|
|
: "auto";
|
2024-06-20 12:09:48 +05:30
|
|
|
return (
|
|
|
|
|
<TableContainer overflowX={"hidden"} className="h-auto mb-3 w-100">
|
|
|
|
|
{data?.length === 0 ? (
|
|
|
|
|
<EmptySearchList message={emptyMessage} />
|
|
|
|
|
) : (
|
2024-06-25 19:24:26 +05:30
|
|
|
<Table size="sm">
|
|
|
|
|
{/* <TableCaption><Pagination totalItems={totalPages} /></TableCaption> */}
|
|
|
|
|
<TableCaption>Tanami v1.0</TableCaption>
|
|
|
|
|
<Thead backgroundColor="gray.50">
|
2024-06-20 12:09:48 +05:30
|
|
|
<Tr>
|
|
|
|
|
{tableHeadRow.map((heading, index) => (
|
2024-06-25 19:24:26 +05:30
|
|
|
<Th
|
|
|
|
|
textAlign={slideFromRight ? "right" : "left"}
|
|
|
|
|
key={index}
|
|
|
|
|
p={3}
|
|
|
|
|
w={"auto"}
|
|
|
|
|
color={"#004118"}
|
|
|
|
|
>
|
2024-06-26 12:03:13 +05:30
|
|
|
<Skeleton isLoaded={!isLoading}
|
|
|
|
|
fadeDuration={0.4} height="20px" >{heading}</Skeleton>
|
2024-06-20 12:09:48 +05:30
|
|
|
</Th>
|
|
|
|
|
))}
|
|
|
|
|
</Tr>
|
|
|
|
|
</Thead>
|
|
|
|
|
<Tbody className="web-text-small">
|
2024-06-26 12:03:13 +05:30
|
|
|
{ data?.map((item, index) => (
|
2024-06-25 19:24:26 +05:30
|
|
|
<Tr
|
|
|
|
|
// onMouseEnter={(e) => {
|
|
|
|
|
// e.currentTarget.style.backgroundColor = "transparent"; // Change the background color on hover
|
|
|
|
|
// e.currentTarget.style.transition = "0.1s";
|
|
|
|
|
// e.currentTarget.style.boxShadow =
|
|
|
|
|
// "rgba(0, 0, 0, 0.24) 0px 1px 8px";
|
|
|
|
|
// setMouseEntered(true);
|
|
|
|
|
// setMouseEnteredId(item.id);
|
|
|
|
|
// }}
|
|
|
|
|
// onMouseLeave={(e) => {
|
|
|
|
|
// e.currentTarget.style.backgroundColor = "transparent"; // Revert to default background color on hover out
|
|
|
|
|
// e.currentTarget.style.transition = "0.3s";
|
|
|
|
|
// e.currentTarget.style.boxShadow = "none";
|
|
|
|
|
// setMouseEntered(false);
|
|
|
|
|
// }}
|
|
|
|
|
transition={"0.5s all"}
|
|
|
|
|
_hover={{
|
|
|
|
|
bg: "green.50",
|
|
|
|
|
cursor: "pointer",
|
|
|
|
|
}}
|
|
|
|
|
key={index}
|
|
|
|
|
>
|
2024-06-20 12:09:48 +05:30
|
|
|
{tableHeadRow.map((heading, i) => (
|
2024-06-21 20:32:14 +05:30
|
|
|
<Td
|
2024-06-25 19:24:26 +05:30
|
|
|
textAlign={slideFromRight ? "right" : "left"}
|
2024-06-21 20:32:14 +05:30
|
|
|
color={"gray.600"}
|
|
|
|
|
key={i}
|
|
|
|
|
style={{
|
|
|
|
|
whiteSpace: "nowrap",
|
|
|
|
|
textOverflow: "ellipsis",
|
|
|
|
|
}}
|
|
|
|
|
className="web-text-small"
|
2024-06-25 20:35:03 +05:30
|
|
|
// onClick={
|
|
|
|
|
// i === tableHeadRow.length - 1 || i === 0
|
|
|
|
|
// ? null
|
|
|
|
|
// : () => navigate(`edit-sponser/${item.id}`) // Define the onClick handler for other cells
|
|
|
|
|
// }
|
2024-06-21 20:32:14 +05:30
|
|
|
>
|
2024-06-26 12:03:13 +05:30
|
|
|
<Skeleton fadeDuration={index / 12} isLoaded={!isLoading} >{item[heading]}</Skeleton>
|
2024-06-20 12:09:48 +05:30
|
|
|
</Td>
|
|
|
|
|
))}
|
|
|
|
|
</Tr>
|
|
|
|
|
))}
|
|
|
|
|
</Tbody>
|
|
|
|
|
</Table>
|
|
|
|
|
)}
|
|
|
|
|
</TableContainer>
|
|
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export default DataTable;
|