From 55b78153b1b775c855e759011141bbbe6d4b962c Mon Sep 17 00:00:00 2001 From: Artem Baskal Date: Fri, 2 Apr 2021 16:55:39 +0300 Subject: [PATCH] Update client_info in case of null --- .../src/components/Logs/Cells/ClientCell.js | 43 ++++++++++--------- client/src/components/Logs/Cells/index.js | 35 +++++++-------- 2 files changed, 40 insertions(+), 38 deletions(-) diff --git a/client/src/components/Logs/Cells/ClientCell.js b/client/src/components/Logs/Cells/ClientCell.js index 16f89e20fc1..fa579d46924 100644 --- a/client/src/components/Logs/Cells/ClientCell.js +++ b/client/src/components/Logs/Cells/ClientCell.js @@ -18,17 +18,6 @@ const ClientCell = ({ client, client_id, client_info, - client_info: { - name, - whois, - whois: { - country, - city, - orgname, - }, - disallowed, - disallowed_rule, - }, domain, reason, }) => { @@ -41,18 +30,22 @@ const ClientCell = ({ const autoClient = autoClients.find((autoClient) => autoClient.name === client); const source = autoClient?.source; - const whoisAvailable = Object.keys(whois).length > 0; - const clientName = name || client_id; - const clientInfo = { ...client_info, whois_info: whois, name: clientName }; + const whoisAvailable = client_info && Object.keys(client_info.whois).length > 0; + const clientName = client_info?.name || client_id; + const clientInfo = client_info && { + ...client_info, + whois_info: client_info?.whois, + name: clientName, + }; const id = nanoid(); const data = { address: client, name: clientName, - country, - city, - network: orgname, + country: client_info?.whois?.country, + city: client_info?.whois?.city, + network: client_info?.whois?.orgname, source_label: source, }; @@ -61,7 +54,7 @@ const ClientCell = ({ const isFiltered = checkFiltered(reason); const nameClass = classNames('w-90 o-hidden d-flex flex-column', { - 'mt-2': isDetailed && !name && !whoisAvailable, + 'mt-2': isDetailed && !client_info?.name && !whoisAvailable, 'white-space--nowrap': isDetailed, }); @@ -77,7 +70,11 @@ const ClientCell = ({ confirmMessage, buttonKey: blockingClientKey, isNotInAllowedList, - } = getBlockClientInfo(client, disallowed, disallowed_rule); + } = getBlockClientInfo( + client, + client_info?.disallowed || false, + client_info?.disallowed_rule || '', + ); const blockingForClientKey = isFiltered ? 'unblock_for_this_client_only' : 'block_for_this_client_only'; const clientNameBlockingFor = getBlockingClientName(clients, client); @@ -93,7 +90,11 @@ const ClientCell = ({ name: blockingClientKey, onClick: async () => { if (window.confirm(confirmMessage)) { - await dispatch(toggleClientBlock(client, disallowed, disallowed_rule)); + await dispatch(toggleClientBlock( + client, + client_info?.disallowed || false, + client_info?.disallowed_rule || '', + )); await dispatch(updateLogs()); } }, @@ -217,7 +218,7 @@ ClientCell.propTypes = { }).isRequired, disallowed: propTypes.bool.isRequired, disallowed_rule: propTypes.string.isRequired, - }).isRequired, + }), domain: propTypes.string.isRequired, reason: propTypes.string.isRequired, }; diff --git a/client/src/components/Logs/Cells/index.js b/client/src/components/Logs/Cells/index.js index 509d0fb526c..5740bbd0ce3 100644 --- a/client/src/components/Logs/Cells/index.js +++ b/client/src/components/Logs/Cells/index.js @@ -62,16 +62,7 @@ const Row = memo(({ client, domain, elapsedMs, - client_info: { - name, - disallowed, - disallowed_rule, - whois: { - country, - city, - orgname, - }, - }, + client_info, response, time, tracker, @@ -114,7 +105,11 @@ const Row = memo(({ confirmMessage, buttonKey: blockingClientKey, isNotInAllowedList, - } = getBlockClientInfo(client, disallowed, disallowed_rule); + } = getBlockClientInfo( + client, + client_info?.disallowed || false, + client_info?.disallowed_rule || '', + ); const blockingForClientKey = isFiltered ? 'unblock_for_this_client_only' : 'block_for_this_client_only'; const clientNameBlockingFor = getBlockingClientName(clients, client); @@ -125,7 +120,13 @@ const Row = memo(({ const onBlockingClientClick = async () => { if (window.confirm(confirmMessage)) { - await dispatch(toggleClientBlock(client, disallowed, disallowed_rule)); + await dispatch( + toggleClientBlock( + client, + client_info?.disallowed || false, + client_info?.disallowed_rule || '', + ), + ); await dispatch(updateLogs()); setModalOpened(false); } @@ -180,10 +181,10 @@ const Row = memo(({ response_code: status, client_details: 'title', ip_address: client, - name: name || client_id, - country, - city, - network: orgname, + name: client_info?.name || client_id, + country: client_info?.whois?.country, + city: client_info?.whois?.city, + network: client_info?.whois?.orgname, source_label: source, validated_with_dnssec: dnssec_enabled ? Boolean(answer_dnssec) : false, original_response: originalResponse?.join('\n'), @@ -239,7 +240,7 @@ Row.propTypes = { }).isRequired, disallowed: propTypes.bool.isRequired, disallowed_rule: propTypes.string.isRequired, - }).isRequired, + }), rules: propTypes.arrayOf(propTypes.shape({ text: propTypes.string.isRequired, filter_list_id: propTypes.number.isRequired,