Proyectos de Subversion LeadersLinked - Backend

Rev

Rev 15318 | Autoría | Comparar con el anterior | Ultima modificación | Ver Log |

import React from 'react'

// Object that initialize the options to render icon 
const DEFAULT_OPTION = {
        permission: false,
        icon: (value) => <i className='fa fa-edit' onClick={() => console.log(value)} /> // Function to render icon and received url by props
}

const TableRow = ({
        item = {},
        editOptions = DEFAULT_OPTION,
        deleteOptions = DEFAULT_OPTION
}) => {

        // Validate if action have permision to render 
        const renderActions = (key, value) => {
                if (key === 'link_edit' && editOptions.permission) return editOptions.icon(value)
                if (key === 'link_delete' && deleteOptions.permission) return deleteOptions.icon(value)
                return null
        }

        return (
                <tr>
                        {Object.entries(item)
                                .map(([key, value], index) => {
                                        if (key === 'id' || key === 'uuid') return null
                                        if (key === 'status') {
                                                let status = value === 'a' ? 'Activo' : 'Inactivo'
                                                return <td key={index}>{status}</td>
                                        }
                                        if (key === 'actions') {
                                                return <td className='d-flex' key={index} style={{ gap: '.5rem' }}>
                                                        {Object.entries(value)
                                                                .map(([key, value]) => renderActions(key, value))}
                                                </td>
                                        }
                                        return <td key={index}>{value}</td>
                                }
                                )}

                </tr>
        )
}

export default TableRow