Skip to content

Commit

Permalink
Update client_info in case of null
Browse files Browse the repository at this point in the history
  • Loading branch information
ArtemBaskal committed Apr 2, 2021
1 parent 5c80c14 commit 55b7815
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 38 deletions.
43 changes: 22 additions & 21 deletions client/src/components/Logs/Cells/ClientCell.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,6 @@ const ClientCell = ({
client,
client_id,
client_info,
client_info: {
name,
whois,
whois: {
country,
city,
orgname,
},
disallowed,
disallowed_rule,
},
domain,
reason,
}) => {
Expand All @@ -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,
};

Expand All @@ -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,
});

Expand All @@ -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);
Expand All @@ -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());
}
},
Expand Down Expand Up @@ -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,
};
Expand Down
35 changes: 18 additions & 17 deletions client/src/components/Logs/Cells/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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);
Expand All @@ -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);
}
Expand Down Expand Up @@ -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'),
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 55b7815

Please sign in to comment.