import { useState } from 'react' import PropTypes from 'prop-types' import { useSelector } from 'react-redux' import moment from 'moment' import { styled } from '@mui/material/styles' import { Box, Chip, Paper, Skeleton, Stack, Table, TableBody, TableCell, TableContainer, TableHead, TableRow, TableSortLabel, Tooltip, Typography, useTheme } from '@mui/material' import { tableCellClasses } from '@mui/material/TableCell' import FlowListMenu from '../button/FlowListMenu' import { Link } from 'react-router-dom' import { useAuth } from '@/hooks/useAuth' import MoreItemsTooltip from '../tooltip/MoreItemsTooltip' const StyledTableCell = styled(TableCell)(({ theme }) => ({ borderColor: theme.palette.grey[900] + 25, [`&.${tableCellClasses.head}`]: { color: theme.palette.grey[900] }, [`&.${tableCellClasses.body}`]: { fontSize: 14, height: 64 } })) const StyledTableRow = styled(TableRow)(() => ({ // hide last border '&:last-child td, &:last-child th': { border: 0 } })) const getLocalStorageKeyName = (name, isAgentCanvas) => { return (isAgentCanvas ? 'agentcanvas' : 'chatflowcanvas') + '_' + name } export const FlowListTable = ({ data, images = {}, icons = {}, isLoading, filterFunction, updateFlowsApi, setError, isAgentCanvas, isAgentflowV2 }) => { const { hasPermission } = useAuth() const isActionsAvailable = isAgentCanvas ? hasPermission('agentflows:update,agentflows:delete,agentflows:config,agentflows:domains,templates:flowexport,agentflows:export') : hasPermission('chatflows:update,chatflows:delete,chatflows:config,chatflows:domains,templates:flowexport,chatflows:export') const theme = useTheme() const customization = useSelector((state) => state.customization) const localStorageKeyOrder = getLocalStorageKeyName('order', isAgentCanvas) const localStorageKeyOrderBy = getLocalStorageKeyName('orderBy', isAgentCanvas) const [order, setOrder] = useState(localStorage.getItem(localStorageKeyOrder) || 'desc') const [orderBy, setOrderBy] = useState(localStorage.getItem(localStorageKeyOrderBy) || 'updatedDate') const handleRequestSort = (property) => { const isAsc = orderBy === property && order === 'asc' const newOrder = isAsc ? 'desc' : 'asc' setOrder(newOrder) setOrderBy(property) localStorage.setItem(localStorageKeyOrder, newOrder) localStorage.setItem(localStorageKeyOrderBy, property) } const onFlowClick = (row) => { if (!isAgentCanvas) { return `/canvas/${row.id}` } else { return isAgentflowV2 ? `/v2/agentcanvas/${row.id}` : `/agentcanvas/${row.id}` } } const sortedData = data ? [...data].sort((a, b) => { if (orderBy === 'name') { return order === 'asc' ? (a.name || '').localeCompare(b.name || '') : (b.name || '').localeCompare(a.name || '') } else if (orderBy === 'updatedDate') { return order === 'asc' ? new Date(a.updatedDate) - new Date(b.updatedDate) : new Date(b.updatedDate) - new Date(a.updatedDate) } return 0 }) : [] return ( <> handleRequestSort('name')}> Name Category Nodes handleRequestSort('updatedDate')} > Last Modified Date {isActionsAvailable && ( Actions )} {isLoading ? ( <> {isActionsAvailable && ( )} {isActionsAvailable && ( )} ) : ( <> {sortedData.filter(filterFunction).map((row, index) => ( {row.templateName || row.name}
  {row.category && row.category .split(';') .map((tag, index) => ( ))}
{(images[row.id] || icons[row.id]) && ( {[ ...(images[row.id] || []).map((img) => ({ type: 'image', src: img.imageSrc, label: img.label })), ...(icons[row.id] || []).map((ic) => ({ type: 'icon', icon: ic.icon, color: ic.color, title: ic.name })) ] .slice(0, 5) .map((item, index) => ( {item.type === 'image' ? ( ) : (
)}
))} {(images[row.id]?.length || 0) + (icons[row.id]?.length || 0) > 5 && ( ({ label: ic.name })) ]} > + {(images[row.id]?.length || 0) + (icons[row.id]?.length || 0) - 5} More )}
)}
{moment(row.updatedDate).format('MMMM Do, YYYY HH:mm:ss')} {isActionsAvailable && ( )}
))} )}
) } FlowListTable.propTypes = { data: PropTypes.array, images: PropTypes.object, icons: PropTypes.object, isLoading: PropTypes.bool, filterFunction: PropTypes.func, updateFlowsApi: PropTypes.object, setError: PropTypes.func, isAgentCanvas: PropTypes.bool, isAgentflowV2: PropTypes.bool }