Skip to content

Commit

Permalink
client: handle cached upstream
Browse files Browse the repository at this point in the history
  • Loading branch information
IldarKamalov committed Dec 7, 2021
1 parent a56804c commit a2a9f90
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 24 deletions.
4 changes: 2 additions & 2 deletions client/src/__locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@
"form_error_server_name": "Invalid server name",
"form_error_subnet": "Subnet \"{{cidr}}\" does not contain the IP address \"{{ip}}\"",
"form_error_positive": "Must be greater than 0",
"form_error_negative": "Must be equal to 0 or greater",
"out_of_range_error": "Must be out of range \"{{start}}\"-\"{{end}}\"",
"lower_range_start_error": "Must be lower than range start",
"greater_range_start_error": "Must be greater than range start",
Expand Down Expand Up @@ -625,5 +624,6 @@
"filter_allowlist": "WARNING: This action also will exclude the rule \"{{disallowed_rule}}\" from the list of allowed clients.",
"last_rule_in_allowlist": "Cannot disallow this client because excluding the rule \"{{disallowed_rule}}\" will DISABLE \"Allowed clients\" list.",
"experimental": "Experimental",
"use_saved_key": "Use the previously saved key"
"use_saved_key": "Use the previously saved key",
"served_from_cache": "{{value}} <i>(served from cache)</i>"
}
28 changes: 18 additions & 10 deletions client/src/components/Logs/Cells/ResponseCell.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ const ResponseCell = ({
upstream,
rules,
service_name,
cached,
}) => {
const { t } = useTranslation();
const filters = useSelector((state) => state.filtering.filters, shallowEqual);
Expand All @@ -36,6 +37,9 @@ const ResponseCell = ({

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) {
Expand All @@ -53,7 +57,7 @@ const ResponseCell = ({

const COMMON_CONTENT = {
encryption_status: boldStatusLabel,
install_settings_dns: upstream,
install_settings_dns: upstreamString,
elapsed: formattedElapsedMs,
response_code: status,
...(service_name
Expand Down Expand Up @@ -90,8 +94,9 @@ const ResponseCell = ({

const detailedInfo = getDetailedInfo(reason);

return <div className="logs__cell logs__cell--response" role="gridcell">
<IconTooltip
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'
Expand All @@ -100,14 +105,16 @@ const ResponseCell = ({
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>}
/>
{/* {t('served_from_cache')} */}
<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>
</div>;
);
};

ResponseCell.propTypes = {
Expand All @@ -122,6 +129,7 @@ ResponseCell.propTypes = {
filter_list_id: propTypes.number.isRequired,
})),
service_name: propTypes.string,
cached: propTypes.bool,
};

export default ResponseCell;
7 changes: 6 additions & 1 deletion client/src/components/Logs/Cells/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ const Row = memo(({
originalResponse,
status,
service_name,
cached,
} = rowProps;

const hasTracker = !!tracker;
Expand Down Expand Up @@ -116,6 +117,9 @@ const Row = memo(({

const blockingForClientKey = isFiltered ? 'unblock_for_this_client_only' : 'block_for_this_client_only';
const clientNameBlockingFor = getBlockingClientName(clients, client);
const upstreamString = cached
? t('served_from_cache', { value: upstream, i: <i /> })
: upstream;

const onBlockingForClientClick = () => {
dispatch(toggleBlockingForClient(buttonType, domain, clientNameBlockingFor));
Expand Down Expand Up @@ -175,7 +179,7 @@ const Row = memo(({
className="link--green">{sourceData.name}
</a>,
response_details: 'title',
install_settings_dns: upstream,
install_settings_dns: upstreamString,
elapsed: formattedElapsedMs,
...(rules.length > 0
&& { rule_label: getRulesToFilterList(rules, filters, whitelistFilters) }
Expand Down Expand Up @@ -230,6 +234,7 @@ Row.propTypes = {
time: propTypes.string.isRequired,
tracker: propTypes.object,
upstream: propTypes.string.isRequired,
cached: propTypes.bool.isRequired,
type: propTypes.string.isRequired,
client_proto: propTypes.string.isRequired,
client_id: propTypes.string,
Expand Down
2 changes: 2 additions & 0 deletions client/src/helpers/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ export const normalizeLogs = (logs) => logs.map((log) => {
service_name,
original_answer,
upstream,
cached,
} = log;

const { name: domain, unicode_name: unicodeName, type } = question;
Expand Down Expand Up @@ -117,6 +118,7 @@ export const normalizeLogs = (logs) => logs.map((log) => {
answer_dnssec,
elapsedMs,
upstream,
cached,
};
});

Expand Down
11 changes: 0 additions & 11 deletions client/src/helpers/validators.js
Original file line number Diff line number Diff line change
Expand Up @@ -230,17 +230,6 @@ export const validateMac = (value) => {
return undefined;
};

/**
* @param value {number}
* @returns {boolean|*}
*/
export const validateBiggerOrEqualZeroValue = (value) => {
if (value < 0) {
return 'form_error_negative';
}
return false;
};

/**
* @param value {number}
* @returns {undefined|string}
Expand Down

0 comments on commit a2a9f90

Please sign in to comment.