import React, { useEffect } from 'react'; import PropTypes from 'prop-types'; import ReactPaginate from 'react-paginate'; import { CCardBody, CDataTable, CButton, CLink, CCard, CCardHeader, CPopover, CSelect, CButtonToolbar, } from '@coreui/react'; import { cilSearch, cilPencil, cilPlus, cilTrash } from '@coreui/icons'; import CIcon from '@coreui/icons-react'; import ReactTooltip from 'react-tooltip'; import { FormattedDate } from 'ucentral-libs'; const BlacklistTable = ({ currentPage, devices, toggleAddBlacklist, toggleEditModal, devicesPerPage, loading, removeFromBlacklist, updateDevicesPerPage, pageCount, updatePage, t, }) => { const columns = [ { key: 'serialNumber', label: t('common.serial_number'), _style: { width: '6%' } }, { key: 'created', label: t('device.blacklisted_on'), _style: { width: '1%' } }, { key: 'author', label: t('common.by'), filter: false, _style: { width: '15%' } }, { key: 'reason', label: t('common.reason'), filter: false }, { key: 'actions', label: t('actions.actions'), _style: { width: '1%' } }, ]; const hideTooltips = () => ReactTooltip.hide(); const escFunction = (event) => { if (event.keyCode === 27) { hideTooltips(); } }; useEffect(() => { document.addEventListener('keydown', escFunction, false); return () => { document.removeEventListener('keydown', escFunction, false); }; }, []); return ( <> ( `/devices/${item.serialNumber}`} > {item.serialNumber} ), created: (item) => (
), author: (item) => {item.author}, reason: (item) => {item.reason}, actions: (item) => ( `/devices/${item.serialNumber}`} > removeFromBlacklist(item.serialNumber)} color="primary" variant="outline" shape="square" size="sm" className="mx-1" style={{ width: '33px', height: '30px' }} > toggleEditModal(item.serialNumber)} color="primary" variant="outline" shape="square" size="sm" className="mx-1" style={{ width: '33px', height: '30px' }} > ), }} />

{t('common.items_per_page')}

updateDevicesPerPage(e.target.value)} disabled={loading} >
); }; BlacklistTable.propTypes = { currentPage: PropTypes.string, devices: PropTypes.instanceOf(Array).isRequired, toggleAddBlacklist: PropTypes.func.isRequired, toggleEditModal: PropTypes.func.isRequired, updateDevicesPerPage: PropTypes.func.isRequired, pageCount: PropTypes.number.isRequired, updatePage: PropTypes.func.isRequired, devicesPerPage: PropTypes.string.isRequired, removeFromBlacklist: PropTypes.func.isRequired, t: PropTypes.func.isRequired, loading: PropTypes.bool.isRequired, }; BlacklistTable.defaultProps = { currentPage: '0', }; export default React.memo(BlacklistTable);