import { Chip, IconButton } from "@mui/material"; import Box from "@mui/material/Box"; import Button from "@mui/material/Button"; import Checkbox from "@mui/material/Checkbox"; import Stack from "@mui/material/Stack"; import Table from "@mui/material/Table"; import TableBody from "@mui/material/TableBody"; import TableCell from "@mui/material/TableCell"; import TableContainer from "@mui/material/TableContainer"; import TableHead from "@mui/material/TableHead"; import TableRow from "@mui/material/TableRow"; import Typography from "@mui/material/Typography"; import classNames from "classnames"; import { Fragment, useState } from "react"; import iconCross from "../../assets/icons/icon-cross.svg"; import iconMore from "../../assets/icons/icon-more.svg"; import ImageNoSearch from "../../assets/images/no-search-results.png"; import Icon from "../Icon"; import CustomMenu from "../Menu"; import SearchBar from "../SearchBar"; import ShimmerTable from "./ShimmerTable"; import "./Table.css"; const TableToolBar = ({ selectedCount, actions = [], bulkActions = [], onClearAllClick, }) => { const actionsToRender = selectedCount > 0 ? bulkActions : actions; return ( {selectedCount > 0 ? ( <> {selectedCount} items selected in the list Clear All > ) : null} {actionsToRender .filter((action) => !action.disabled) // Exclude actions with disabled: true .map((action, index) => { const { label, onClick, endIcon, startIcon, classes, isSearch, onSearch, onClear, } = action; return ( {isSearch && } {!isSearch && ( onClick(event)} endIcon={endIcon} startIcon={startIcon} sx={{ textTransform: "none !important" }} > {label} )} ); })} ); }; const EnhancedTableHead = ({ headers = [], onSelectAllClick, numSelected = 0, rowCount = 0, noCheckBox, showMoreOptions, ifEmpty, }) => { return ( {!noCheckBox && ( 0 && numSelected === rowCount} onChange={onSelectAllClick} style={{ display: ifEmpty ? "none" : "" }} /> )} {showMoreOptions && ( )} {headers.map((header, index) => ( {header.label} ))} ); }; const EnhancedTableCell = ({ children, onClick, sticky, leftPosition, ...rest }) => { let tableCellProps = { ...rest, sx: { borderRight: 1, borderColor: ({ palette }) => palette.grey[200], cursor: onClick ? "pointer" : "default", position: sticky ? "sticky" : "static", left: sticky ? leftPosition : "auto", zIndex: sticky ? 2 : "auto", backgroundColor: sticky ? "#fff" : "inherit", }, }; if (onClick) { tableCellProps = { ...tableCellProps, onClick }; } return {children}; }; function extractLabels(values) { // Check if values is an array if (Array.isArray(values)) { return values.map((value) => { // If the value is in the 'id:label' format, return only the label (part after ':') if (typeof value === "string" && value.includes(":")) { return value.split(":")[1]; // Return the label part } return value; // If not in the correct format, return the value as it is }); } // If input is not an array, return the value as is (this is an edge case if you pass a single value) return values; } const FilterChips = ({ filters }) => ( <> {filters.map(({ attribute, condition, value }, index) => ( {index < filters.length - 1 && ( theme.palette.yellow?.light }} size="small" /> )} ))} > ); const AppliedFiltersDisplay = ({ appliedFilters }) => { const validAppliedFilters = appliedFilters.filter((filterBlock) => filterBlock.some(({ attribute, condition }) => attribute && condition), ); return ( <> {validAppliedFilters.map((filterBlock, blockIndex) => ( {blockIndex < validAppliedFilters.length - 1 && ( theme.palette.yellow?.light }} size="small" /> )} ))} > ); }; const TableContent = ({ headers, rows, selected, onSelectAllClick, onSelectRow, noCheckBox, moreOptions, handleMoreClick, setRowSelected, ifEmpty, showMoreOptions, }) => { return ( {ifEmpty ? ( No data available ) : ( rows.map((row, index) => ( index % 2 === 0 ? "#f9fafb" : "#ffffff", }} > {!noCheckBox && ( onSelectRow(row.id)} checked={selected.indexOf(row.id) !== -1} /> { handleMoreClick(event); setRowSelected(row); }} /> )} {showMoreOptions && ( {(!row.contactFieldType || row.contactFieldType !== "SYSTEM") && ( { handleMoreClick(event); setRowSelected(row); }} /> )} )} {headers.map( ({ numeric, key, render, onClick, sticky }, colIndex) => { const RenderComp = render; return ( onClick(row) : ""} align={numeric ? "right" : "left"} key={key} sticky={sticky} leftPosition={ colIndex === 0 ? 76 : colIndex * 140 + 100 } > {RenderComp ? : row[key] || "_"} ); }, )} )) )} ); }; const TableComp = ({ headers = [], isLoading = false, rows = [], noCheckBox = false, moreOptions, actions = [], bulkActions = [], rowActions = [], appliedFilters = [], onFilterEdit, ifEmpty, selected = [], setSelected, showMoreOptions = false, // New prop for Fields table }) => { const [rowSelected, setRowSelected] = useState([]); const isSearchLoading = false; const [anchorEl, setAnchorEl] = useState(null); const onSelectAllClick = (event) => { if (event.target.checked) { const newSelected = rows?.map((n) => n.id); setSelected(newSelected); return; } setSelected([]); }; const handleMoreClick = (event) => { setAnchorEl(event.currentTarget); }; const onClearAllClick = () => { setSelected([]); }; const onSelectRow = (id) => { let newSelected = []; const isSelected = selected.some((selectedId) => selectedId === id); if (isSelected) { newSelected = selected.filter((selectedId) => selectedId !== id); } else { newSelected = selected.concat(id); } setSelected(newSelected); }; return ( <> ({ ...bulkAction, onClick: (event) => { bulkAction.onClick(selected, event); }, }))} /> {appliedFilters.length > 0 && ( Filter {} )} palette.grey[200], }} > {isLoading || isSearchLoading ? ( ) : ( )} { const { onClick } = rowActions.find((rowAction) => rowAction.value === value) || {}; onClick?.(rowSelected); setAnchorEl(null); }} options={rowActions .filter((action) => !action.disabled) // Exclude disabled options .map((action) => ({ ...action, label: typeof action.label === "function" ? action.label(rowSelected) : action.label, icon: typeof action.icon === "function" ? action.icon(rowSelected) : action.icon, }))} open={!!anchorEl && rowActions.some((action) => !action.disabled)} // Open only if there are non-disabled options onClose={() => { setAnchorEl(null); }} horizontalAlignment="bottom" verticalAlighnment="bottom" anchorEl={anchorEl} /> > ); }; export default TableComp;