Updates #3972.
Squashed commit of the following:
commit 9dc0efe2453cb6c738d97d39b02c86eccb18a42c
Merge: 239550f8 8a935d4f
Author: Ainar Garipov <A.Garipov@AdGuard.COM>
Date: Thu Oct 27 14:42:38 2022 +0300
Merge branch 'master' into 3972-hostlists-services
commit 239550f84228e7c7a6f4ae6b1cadcc47e01f54d5
Author: Ainar Garipov <A.Garipov@AdGuard.COM>
Date: Thu Oct 27 14:41:42 2022 +0300
filtering: upd service list
commit b8bf3a6a4b1333059b886be95a1419612aebac39
Author: Ildar Kamalov <ik@adguard.com>
Date: Thu Oct 27 13:41:09 2022 +0300
client: remove todo
commit caa504b482befb804db2a1ca0b6d4834aa4da49a
Author: Ildar Kamalov <ik@adguard.com>
Date: Thu Oct 27 12:54:45 2022 +0300
fix build
commit 511797c305d9eef84a20553dab795414e00da51a
Author: Ildar Kamalov <ik@adguard.com>
Date: Thu Oct 27 12:40:33 2022 +0300
client: add titles with service names to the clients table
commit 79ed3157a85b489a0b13381cff867a8c73ba60e9
Author: Ildar Kamalov <ik@adguard.com>
Date: Thu Oct 27 12:36:59 2022 +0300
client: fix empty icons
commit ab69b95784de87665d5a1a3683f28e3b3df1c210
Author: Ildar Kamalov <ik@adguard.com>
Date: Thu Oct 27 11:55:48 2022 +0300
client: use all blocked services
commit 9a4a87665c8463224d8e93f1e162988107f6c7ca
Author: Ainar Garipov <A.Garipov@AdGuard.COM>
Date: Tue Oct 25 19:25:20 2022 +0300
all: fix json response
commit 86eb4493ce305cd5991176bd4cd8f7f5afdea330
Author: Ainar Garipov <A.Garipov@AdGuard.COM>
Date: Tue Oct 25 19:09:44 2022 +0300
all: use hostslists registry for blocked svcs
136 lines
4.9 KiB
JavaScript
136 lines
4.9 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,
|
|
cached,
|
|
}) => {
|
|
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 services = useSelector((store) => store?.services);
|
|
|
|
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 upstreamString = cached
|
|
? t('served_from_cache', { value: upstream, i: <i /> })
|
|
: upstream;
|
|
|
|
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 COMMON_CONTENT = {
|
|
encryption_status: boldStatusLabel,
|
|
install_settings_dns: upstreamString,
|
|
elapsed: formattedElapsedMs,
|
|
response_code: status,
|
|
...(service_name && services.allServices
|
|
&& { service_name: getServiceName(services.allServices, service_name) }
|
|
),
|
|
...(rules.length > 0
|
|
&& { rule_label: getRulesToFilterList(rules, filters, whitelistFilters) }
|
|
),
|
|
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 || !services.allServices) {
|
|
return formattedElapsedMs;
|
|
}
|
|
return getServiceName(services.allServices, 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 logs__question', { '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,
|
|
cached: propTypes.bool.isRequired,
|
|
rules: propTypes.arrayOf(propTypes.shape({
|
|
text: propTypes.string.isRequired,
|
|
filter_list_id: propTypes.number.isRequired,
|
|
})),
|
|
service_name: propTypes.string,
|
|
};
|
|
|
|
export default ResponseCell;
|