2020-06-17 21:36:19 +00:00
|
|
|
import React from 'react';
|
|
|
|
import classNames from 'classnames';
|
|
|
|
import { formatElapsedMs } from '../../../helpers/helpers';
|
|
|
|
import {
|
|
|
|
FILTERED_STATUS,
|
|
|
|
FILTERED_STATUS_TO_META_MAP,
|
|
|
|
} from '../../../helpers/constants';
|
2020-07-17 12:24:39 +00:00
|
|
|
import getIconTooltip from './getIconTooltip';
|
2020-06-17 21:36:19 +00:00
|
|
|
|
2020-07-06 16:28:07 +00:00
|
|
|
const getResponseCell = (row, filtering, t, isDetailed, getFilterName) => {
|
2020-06-17 21:36:19 +00:00
|
|
|
const {
|
2020-07-15 17:55:13 +00:00
|
|
|
reason, filterId, rule, status, upstream, elapsedMs, response, originalResponse,
|
2020-06-17 21:36:19 +00:00
|
|
|
} = row.original;
|
|
|
|
|
|
|
|
const { filters, whitelistFilters } = filtering;
|
|
|
|
const formattedElapsedMs = formatElapsedMs(elapsedMs, t);
|
|
|
|
|
2020-07-13 12:23:13 +00:00
|
|
|
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);
|
2020-06-17 21:36:19 +00:00
|
|
|
const boldStatusLabel = <span className="font-weight-bold">{statusLabel}</span>;
|
|
|
|
const filter = getFilterName(filters, whitelistFilters, filterId, t);
|
|
|
|
|
|
|
|
const renderResponses = (responseArr) => {
|
2020-07-13 12:23:13 +00:00
|
|
|
if (responseArr?.length === 0) {
|
2020-06-17 21:36:19 +00:00
|
|
|
return '';
|
|
|
|
}
|
|
|
|
|
|
|
|
return <div>{responseArr.map((response) => {
|
|
|
|
const className = classNames('white-space--nowrap', {
|
2020-06-18 14:17:46 +00:00
|
|
|
'overflow-break': response.length > 100,
|
2020-06-17 21:36:19 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
return <div key={response} className={className}>{`${response}\n`}</div>;
|
|
|
|
})}</div>;
|
|
|
|
};
|
|
|
|
|
2020-07-24 12:27:13 +00:00
|
|
|
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),
|
2020-06-17 21:36:19 +00:00
|
|
|
};
|
|
|
|
|
2020-07-24 16:19:51 +00:00
|
|
|
const content = rule
|
|
|
|
? Object.entries(COMMON_CONTENT)
|
|
|
|
: Object.entries({ ...COMMON_CONTENT, filter: '' });
|
2020-07-13 12:23:13 +00:00
|
|
|
const detailedInfo = isBlocked ? filter : formattedElapsedMs;
|
2020-06-17 21:36:19 +00:00
|
|
|
|
|
|
|
return (
|
|
|
|
<div className="logs__row">
|
2020-07-17 12:24:39 +00:00
|
|
|
{getIconTooltip({
|
|
|
|
className: classNames('icons mr-4 icon--24 icon--lightgray', { 'my-3': isDetailed }),
|
2020-06-17 21:36:19 +00:00
|
|
|
columnClass: 'grid grid--limited',
|
|
|
|
tooltipClass: 'px-5 pb-5 pt-4 mw-75 custom-tooltip__response-details',
|
|
|
|
contentItemClass: 'text-truncate key-colon o-hidden',
|
|
|
|
xlinkHref: 'question',
|
|
|
|
title: 'response_details',
|
2020-07-15 17:55:13 +00:00
|
|
|
content,
|
2020-06-18 14:17:46 +00:00
|
|
|
placement: 'bottom',
|
2020-06-17 21:36:19 +00:00
|
|
|
})}
|
|
|
|
<div className="text-truncate">
|
|
|
|
<div className="text-truncate" title={statusLabel}>{statusLabel}</div>
|
|
|
|
{isDetailed && <div
|
2020-07-13 12:23:13 +00:00
|
|
|
className="detailed-info d-none d-sm-block pt-1 text-truncate"
|
|
|
|
title={detailedInfo}>{detailedInfo}</div>}
|
2020-06-17 21:36:19 +00:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
export default getResponseCell;
|