mirror of
https://git.vectorsigma.ru/public/AdGuardHome.git
synced 2026-08-03 20:29:34 +00:00
Close #2451
Squashed commit of the following:
commit f6d0a8fe4fa575dff67b2d2f4c9f6aaf6a6414d3
Merge: 3b13e529d 955b735c8
Author: Artem Baskal <a.baskal@adguard.com>
Date: Fri Dec 25 14:53:16 2020 +0300
Merge branch 'master' into feature/2451
commit 3b13e529da01823cbc674d81be065b68cd08bbd3
Author: Artem Baskal <a.baskal@adguard.com>
Date: Thu Dec 24 12:53:13 2020 +0300
Update JSXElement in jsdocs
commit f0749cd0466ef69d964b1c2575dffacb33f71b31
Author: Artem Baskal <a.baskal@adguard.com>
Date: Mon Dec 21 13:23:48 2020 +0300
minor
commit bd014b00e762a1895c132bc962c06f107c50fe17
Author: Artem Baskal <a.baskal@adguard.com>
Date: Mon Dec 21 12:49:29 2020 +0300
Minor helper update
commit 260a66b7b78eb80596b88fec14f409838727e4bb
Author: Artem Baskal <a.baskal@adguard.com>
Date: Mon Dec 21 12:31:08 2020 +0300
Rule locale update
commit c960cf9f658e52cb587676dceb97506880a9db94
Author: Artem Baskal <a.baskal@adguard.com>
Date: Mon Dec 21 12:27:50 2020 +0300
Add styles for filters list
commit 6f3b2176fd52598cddb147ad7828adb95abf08f0
Author: Artem Baskal <a.baskal@adguard.com>
Date: Fri Dec 18 18:34:17 2020 +0300
client: 2451 Support multiple matched rules in the UI
129 lines
4.5 KiB
JavaScript
129 lines
4.5 KiB
JavaScript
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 {
|
|
getRulesToFilterList,
|
|
formatElapsedMs,
|
|
getFilterNames,
|
|
getServiceName,
|
|
} 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,
|
|
rules,
|
|
service_name,
|
|
}) => {
|
|
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 = <span className="font-weight-bold">{statusLabel}</span>;
|
|
|
|
const renderResponses = (responseArr) => {
|
|
if (!responseArr || responseArr.length === 0) {
|
|
return '';
|
|
}
|
|
|
|
return <div>{responseArr.map((response) => {
|
|
const className = classNames('white-space--nowrap', {
|
|
'overflow-break': response.length > 100,
|
|
});
|
|
|
|
return <div key={response} className={className}>{`${response}\n`}</div>;
|
|
})}</div>;
|
|
};
|
|
|
|
const rulesList = getRulesToFilterList(rules, filters, whitelistFilters);
|
|
|
|
const COMMON_CONTENT = {
|
|
encryption_status: boldStatusLabel,
|
|
install_settings_dns: upstream,
|
|
elapsed: formattedElapsedMs,
|
|
response_code: status,
|
|
...(service_name
|
|
? { service_name: getServiceName(service_name) }
|
|
: { }
|
|
),
|
|
rule_label: rulesList,
|
|
response_table_header: renderResponses(response),
|
|
original_response: renderResponses(originalResponse),
|
|
};
|
|
|
|
const content = rules.length > 0
|
|
? Object.entries(COMMON_CONTENT)
|
|
: Object.entries({
|
|
...COMMON_CONTENT,
|
|
filter: '',
|
|
});
|
|
|
|
const getDetailedInfo = (reason) => {
|
|
switch (reason) {
|
|
case FILTERED_STATUS.FILTERED_BLOCKED_SERVICE:
|
|
if (!service_name) {
|
|
return formattedElapsedMs;
|
|
}
|
|
return getServiceName(service_name);
|
|
case FILTERED_STATUS.FILTERED_BLACK_LIST:
|
|
case FILTERED_STATUS.NOT_FILTERED_WHITE_LIST:
|
|
return getFilterNames(rules, filters, whitelistFilters).join(', ');
|
|
default:
|
|
return formattedElapsedMs;
|
|
}
|
|
};
|
|
|
|
const detailedInfo = getDetailedInfo(reason);
|
|
|
|
return <div className="logs__cell logs__cell--response" role="gridcell">
|
|
<IconTooltip
|
|
className={classNames('icons mr-4 icon--24 icon--lightgray', { 'my-3': isDetailed })}
|
|
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'
|
|
content={content}
|
|
placement='bottom'
|
|
/>
|
|
<div className="text-truncate">
|
|
<div className="text-truncate" title={statusLabel}>{statusLabel}</div>
|
|
{isDetailed && <div
|
|
className="detailed-info d-none d-sm-block pt-1 text-truncate"
|
|
title={detailedInfo}>{detailedInfo}</div>}
|
|
</div>
|
|
</div>;
|
|
};
|
|
|
|
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,
|
|
rules: propTypes.arrayOf(propTypes.shape({
|
|
text: propTypes.string.isRequired,
|
|
filter_list_id: propTypes.number.isRequired,
|
|
})),
|
|
service_name: propTypes.string,
|
|
};
|
|
|
|
export default ResponseCell;
|