2024-08-01 13:52:03 +05:30
|
|
|
import React from "react";
|
2024-08-02 13:00:11 +05:30
|
|
|
import {
|
|
|
|
|
Table,
|
|
|
|
|
TableContainer,
|
|
|
|
|
Tbody,
|
|
|
|
|
Td,
|
|
|
|
|
Th,
|
|
|
|
|
Thead,
|
|
|
|
|
Tr,
|
|
|
|
|
Skeleton,
|
|
|
|
|
TableCaption,
|
|
|
|
|
Tfoot,
|
|
|
|
|
} from "@chakra-ui/react";
|
2024-08-01 13:52:03 +05:30
|
|
|
import EmptySearchList from "../EmptySearchList";
|
2024-08-12 12:22:01 +05:30
|
|
|
import { TABLE_PAGINATION } from "../../Constants/Paginations";
|
2024-08-01 13:52:03 +05:30
|
|
|
|
2024-08-02 13:00:11 +05:30
|
|
|
const DataTable = ({
|
|
|
|
|
data,
|
|
|
|
|
isLoading,
|
|
|
|
|
tableHeadRow,
|
|
|
|
|
emptyMessage,
|
|
|
|
|
centered,
|
2024-08-21 13:03:50 +05:30
|
|
|
total
|
2024-08-02 13:00:11 +05:30
|
|
|
}) => {
|
2024-08-12 12:22:01 +05:30
|
|
|
|
|
|
|
|
console.log(data);
|
|
|
|
|
|
2024-08-02 13:00:11 +05:30
|
|
|
const columnWidth =
|
|
|
|
|
data && data[0]
|
|
|
|
|
? `${(100 / Object.keys(data[0]).length).toFixed(2)}%`
|
|
|
|
|
: "auto";
|
2024-08-01 13:52:03 +05:30
|
|
|
return (
|
2024-08-26 14:12:56 +05:30
|
|
|
<TableContainer overflowX={"auto"} className="h-auto mb-3 w-100">
|
2024-08-01 13:52:03 +05:30
|
|
|
{data?.length === 0 ? (
|
|
|
|
|
<EmptySearchList message={emptyMessage} />
|
|
|
|
|
) : (
|
2024-08-02 13:00:11 +05:30
|
|
|
<Table size="sm">
|
2024-08-21 13:03:50 +05:30
|
|
|
<TableCaption p={total?0:null}>{total? total :"Tanami v1.0.0"}</TableCaption>
|
2024-08-23 22:01:17 +05:30
|
|
|
<Thead backgroundColor="gray.100">
|
2024-08-01 13:52:03 +05:30
|
|
|
<Tr>
|
|
|
|
|
{tableHeadRow.map((heading, index) => (
|
2024-08-02 13:00:11 +05:30
|
|
|
<Th
|
|
|
|
|
textAlign={
|
|
|
|
|
tableHeadRow.length - 1 === index || centered
|
|
|
|
|
? "center"
|
|
|
|
|
: "left"
|
|
|
|
|
}
|
|
|
|
|
key={index}
|
|
|
|
|
p={3}
|
2024-08-12 12:22:01 +05:30
|
|
|
width="20px" // Adjust width as needed
|
2024-08-05 17:56:07 +05:30
|
|
|
color={"#004118"}
|
|
|
|
|
whiteSpace="normal" // Allow text to wrap
|
|
|
|
|
wordBreak="normal" // Ensure long words break properly
|
|
|
|
|
overflowWrap="normal" // Break long words if necessary
|
2024-08-13 19:02:47 +05:30
|
|
|
textTransform={'none'}
|
|
|
|
|
|
2024-08-02 13:00:11 +05:30
|
|
|
>
|
2024-08-01 13:52:03 +05:30
|
|
|
{isLoading ? <Skeleton height="20px" /> : heading}
|
|
|
|
|
{/* {heading} */}
|
|
|
|
|
</Th>
|
|
|
|
|
))}
|
|
|
|
|
</Tr>
|
|
|
|
|
</Thead>
|
|
|
|
|
<Tbody className="web-text-small">
|
|
|
|
|
{isLoading
|
2024-08-12 12:22:01 +05:30
|
|
|
? Array.from({ length: TABLE_PAGINATION?.size }).map((_, index) => (
|
2024-08-01 13:52:03 +05:30
|
|
|
<Tr key={index}>
|
|
|
|
|
{tableHeadRow.map((_, i) => (
|
2024-08-02 13:00:11 +05:30
|
|
|
<Td
|
|
|
|
|
width={'fit-content'}
|
|
|
|
|
key={i}
|
|
|
|
|
style={{
|
|
|
|
|
whiteSpace: "nowrap",
|
|
|
|
|
textOverflow: "ellipsis",
|
|
|
|
|
}}
|
|
|
|
|
className="web-text-small"
|
|
|
|
|
w={columnWidth}
|
|
|
|
|
>
|
2024-08-01 13:52:03 +05:30
|
|
|
<Skeleton height="20px" mb={1} mt={1} />
|
|
|
|
|
</Td>
|
|
|
|
|
))}
|
|
|
|
|
</Tr>
|
|
|
|
|
))
|
|
|
|
|
: data?.map((item, index) => (
|
2024-08-23 22:01:17 +05:30
|
|
|
<Tr bg={index % 2 === 0 ? "" : "gray.50"} key={index}>
|
2024-08-01 13:52:03 +05:30
|
|
|
{tableHeadRow.map((heading, i) => (
|
2024-08-02 13:00:11 +05:30
|
|
|
<Td
|
|
|
|
|
textAlign={
|
|
|
|
|
tableHeadRow?.length - 1 === i || centered
|
|
|
|
|
? "center"
|
|
|
|
|
: "left"
|
|
|
|
|
}
|
|
|
|
|
color={"gray.600"}
|
|
|
|
|
key={i}
|
|
|
|
|
style={{
|
|
|
|
|
whiteSpace: "nowrap",
|
|
|
|
|
textOverflow: "ellipsis",
|
|
|
|
|
}}
|
|
|
|
|
className="web-text-small"
|
|
|
|
|
>
|
2024-08-01 13:52:03 +05:30
|
|
|
{item[heading]}
|
|
|
|
|
</Td>
|
|
|
|
|
))}
|
|
|
|
|
</Tr>
|
|
|
|
|
))}
|
|
|
|
|
</Tbody>
|
|
|
|
|
</Table>
|
|
|
|
|
)}
|
|
|
|
|
</TableContainer>
|
|
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export default DataTable;
|