import React from 'react'; import { nanoid } from 'nanoid'; import classNames from 'classnames'; import PropTypes from 'prop-types'; import { formatClientCell } from '../../../helpers/formatClientCell'; import getIconTooltip from './getIconTooltip'; import { checkFiltered } from '../../../helpers/helpers'; import { BLOCK_ACTIONS } from '../../../helpers/constants'; const getClientCell = ({ row, t, isDetailed, toggleBlocking, autoClients, processingRules, }) => { const { reason, client, domain, info: { name, whois_info }, } = row.original; const autoClient = autoClients.find((autoClient) => autoClient.name === client); const source = autoClient?.source; const whoisAvailable = whois_info && Object.keys(whois_info).length > 0; const id = nanoid(); const data = { address: client, name, country: whois_info?.country, city: whois_info?.city, network: whois_info?.orgname, source_label: source, }; const processedData = Object.entries(data); const isFiltered = checkFiltered(reason); const nameClass = classNames('w-90 o-hidden d-flex flex-column', { 'mt-2': isDetailed && !name && !whoisAvailable, 'white-space--nowrap': isDetailed, }); const hintClass = classNames('icons mr-4 icon--24 icon--lightgray', { 'my-3': isDetailed, }); const renderBlockingButton = (isFiltered, domain) => { const buttonType = isFiltered ? BLOCK_ACTIONS.UNBLOCK : BLOCK_ACTIONS.BLOCK; const buttonClass = classNames('logs__action button__action', { 'btn-outline-secondary': isFiltered, 'btn-outline-danger': !isFiltered, 'logs__action--detailed': isDetailed, }); const onClick = () => toggleBlocking(buttonType, domain); return (
); }; return (
{getIconTooltip({ className: hintClass, columnClass: 'grid grid--limited', tooltipClass: 'px-5 pb-5 pt-4 mw-75', xlinkHref: 'question', contentItemClass: 'text-truncate key-colon', title: 'client_details', content: processedData, placement: 'bottom', })}
{formatClientCell(row, isDetailed)}
{isDetailed && name && !whoisAvailable && (
{name}
)}
{renderBlockingButton(isFiltered, domain)}
); }; getClientCell.propTypes = { row: PropTypes.object.isRequired, t: PropTypes.func.isRequired, isDetailed: PropTypes.bool.isRequired, toggleBlocking: PropTypes.func.isRequired, autoClients: PropTypes.array.isRequired, processingRules: PropTypes.bool.isRequired, }; export default getClientCell;