Files
tanami-admin-panel/src/Components/DataTable/NormalTable.jsx

116 lines
3.5 KiB
React
Raw Normal View History

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-26 18:59:29 +05:30
total,
2024-08-02 13:00:11 +05:30
}) => {
2024-08-12 12:22:01 +05:30
console.log(data);
2024-08-26 18:59:29 +05:30
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-30 16:50:05 +05:30
<TableContainer overflowX={"auto"} className="h-auto mb-3 w-100 table-scroll">
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-26 18:59:29 +05:30
<TableCaption p={total ? 0 : null}>
{total ? total : "Tanami v1.0.0"}
</TableCaption>
2024-08-30 16:50:05 +05:30
<Thead backgroundColor="forestGreen.100">
2024-08-01 13:52:03 +05:30
<Tr>
{tableHeadRow.map((heading, index) => (
2024-09-23 12:25:30 +05:30
<Th
2024-08-02 13:00:11 +05:30
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-26 18:59:29 +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-26 18:59:29 +05:30
? Array.from({ length: TABLE_PAGINATION?.size }).map(
(_, index) => (
2024-09-02 15:48:46 +05:30
<Tr bg={index % 2 === 0 ? "" : "forestGreen.50"} key={index}>
2024-08-26 18:59:29 +05:30
{tableHeadRow.map((_, i) => (
<Td
width={"fit-content"}
key={i}
style={{
whiteSpace: "nowrap",
textOverflow: "ellipsis",
}}
className="web-text-small"
w={columnWidth}
>
<Skeleton height="20px" mb={1} mt={1} />
</Td>
))}
</Tr>
)
)
2024-08-01 13:52:03 +05:30
: data?.map((item, index) => (
2024-08-30 16:50:05 +05:30
<Tr bg={index % 2 === 0 ? "" : "forestGreen.50"} key={index}>
2024-08-01 13:52:03 +05:30
{tableHeadRow.map((heading, i) => (
2024-09-23 12:25:30 +05:30
<Td
2024-08-02 13:00:11 +05:30
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;