import { useTranslation } from 'react-i18next'; import { shallowEqual, useSelector } from 'react-redux'; import classNames from 'classnames'; import React from 'react'; import propTypes from 'prop-types'; import { formatElapsedMs, getFilterName } from '../../../helpers/helpers'; import { FILTERED_STATUS, FILTERED_STATUS_TO_META_MAP } from '../../../helpers/constants'; import IconTooltip from './IconTooltip'; const ResponseCell = ({ elapsedMs, originalResponse, reason, response, status, upstream, rule, filterId, }) => { const { t } = useTranslation(); const filters = useSelector((state) => state.filtering.filters, shallowEqual); const whitelistFilters = useSelector((state) => state.filtering.whitelistFilters, shallowEqual); const isDetailed = useSelector((state) => state.queryLogs.isDetailed); const formattedElapsedMs = formatElapsedMs(elapsedMs, t); const isBlocked = reason === FILTERED_STATUS.FILTERED_BLACK_LIST || reason === FILTERED_STATUS.FILTERED_BLOCKED_SERVICE; const isBlockedByResponse = originalResponse.length > 0 && isBlocked; const statusLabel = t(isBlockedByResponse ? 'blocked_by_cname_or_ip' : FILTERED_STATUS_TO_META_MAP[reason]?.LABEL || reason); const boldStatusLabel = {statusLabel}; const filter = getFilterName(filters, whitelistFilters, filterId); const renderResponses = (responseArr) => { if (!responseArr || responseArr.length === 0) { return ''; } return
{responseArr.map((response) => { const className = classNames('white-space--nowrap', { 'overflow-break': response.length > 100, }); return
{`${response}\n`}
; })}
; }; const COMMON_CONTENT = { encryption_status: boldStatusLabel, install_settings_dns: upstream, elapsed: formattedElapsedMs, response_code: status, filter, rule_label: rule, response_table_header: renderResponses(response), original_response: renderResponses(originalResponse), }; const content = rule ? Object.entries(COMMON_CONTENT) : Object.entries({ ...COMMON_CONTENT, filter: '', }); const detailedInfo = isBlocked ? filter : formattedElapsedMs; return
{statusLabel}
{isDetailed &&
{detailedInfo}
}
; }; ResponseCell.propTypes = { elapsedMs: propTypes.string.isRequired, originalResponse: propTypes.array.isRequired, reason: propTypes.string.isRequired, response: propTypes.array.isRequired, status: propTypes.string.isRequired, upstream: propTypes.string.isRequired, rule: propTypes.string, filterId: propTypes.number, }; export default ResponseCell;