2024-06-20 12:09:48 +05:30
|
|
|
import React 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-20 12:09:48 +05:30
|
|
|
|
2024-06-24 12:08:21 +05:30
|
|
|
const DataTable = ({ data, isLoading, tableHeadRow, emptyMessage, totalPages }) => {
|
2024-06-20 12:09:48 +05:30
|
|
|
const columnWidth = data && data[0] ? `${(100 / Object.keys(data[0]).length).toFixed(2)}%` : "auto";
|
|
|
|
|
return (
|
|
|
|
|
<TableContainer overflowX={"hidden"} className="h-auto mb-3 w-100">
|
|
|
|
|
{data?.length === 0 ? (
|
|
|
|
|
<EmptySearchList message={emptyMessage} />
|
|
|
|
|
) : (
|
|
|
|
|
<Table size="sm">
|
2024-06-24 12:08:21 +05:30
|
|
|
{/* <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-21 20:32:14 +05:30
|
|
|
<Th key={index} p={3} w={"auto"} color={"#004118"}>
|
2024-06-20 12:09:48 +05:30
|
|
|
{isLoading ? <Skeleton height="20px" /> : heading}
|
|
|
|
|
{/* {heading} */}
|
|
|
|
|
</Th>
|
|
|
|
|
))}
|
|
|
|
|
</Tr>
|
|
|
|
|
</Thead>
|
|
|
|
|
<Tbody className="web-text-small">
|
|
|
|
|
{isLoading
|
2024-06-24 12:08:21 +05:30
|
|
|
? Array?.from({ length: 10 }).map((_, index) => (
|
2024-06-20 12:09:48 +05:30
|
|
|
<Tr key={index}>
|
|
|
|
|
{tableHeadRow.map((_, i) => (
|
2024-06-21 20:32:14 +05:30
|
|
|
<Td
|
|
|
|
|
key={i}
|
|
|
|
|
style={{
|
|
|
|
|
whiteSpace: "nowrap",
|
|
|
|
|
textOverflow: "ellipsis",
|
|
|
|
|
}}
|
|
|
|
|
className="web-text-small"
|
|
|
|
|
w={columnWidth}
|
|
|
|
|
>
|
2024-06-20 12:09:48 +05:30
|
|
|
<Skeleton height="20px" mb={1} mt={1} />
|
|
|
|
|
</Td>
|
|
|
|
|
))}
|
|
|
|
|
</Tr>
|
|
|
|
|
))
|
|
|
|
|
: data?.map((item, index) => (
|
|
|
|
|
<Tr key={index}>
|
|
|
|
|
{tableHeadRow.map((heading, i) => (
|
2024-06-21 20:32:14 +05:30
|
|
|
<Td
|
|
|
|
|
color={"gray.600"}
|
|
|
|
|
key={i}
|
|
|
|
|
style={{
|
|
|
|
|
whiteSpace: "nowrap",
|
|
|
|
|
textOverflow: "ellipsis",
|
|
|
|
|
}}
|
|
|
|
|
className="web-text-small"
|
|
|
|
|
>
|
2024-06-20 12:09:48 +05:30
|
|
|
{item[heading]}
|
|
|
|
|
</Td>
|
|
|
|
|
))}
|
|
|
|
|
</Tr>
|
|
|
|
|
))}
|
|
|
|
|
</Tbody>
|
|
|
|
|
</Table>
|
|
|
|
|
)}
|
|
|
|
|
</TableContainer>
|
|
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export default DataTable;
|