diff --git a/client/src/components/Logs/index.js b/client/src/components/Logs/index.js index c511edc7..1281db28 100644 --- a/client/src/components/Logs/index.js +++ b/client/src/components/Logs/index.js @@ -11,7 +11,7 @@ import { formatDateTime, isToday, } from '../../helpers/helpers'; -import { SERVICES, FILTERED_STATUS, TABLE_DEFAULT_PAGE_SIZE } from '../../helpers/constants'; +import { SERVICES, FILTERED_STATUS, TABLE_DEFAULT_PAGE_SIZE, CUSTOM_FILTERING_RULES_ID } from '../../helpers/constants'; import { getTrackerData } from '../../helpers/trackers/trackers'; import { formatClientCell } from '../../helpers/formatClientCell'; @@ -116,6 +116,9 @@ class Logs extends Component { checkWhiteList = reason => reason === FILTERED_STATUS.NOT_FILTERED_WHITE_LIST; + checkBlackList = reason => reason === FILTERED_STATUS.FILTERED_BLACK_LIST; + + checkBlockedService = reason => reason === FILTERED_STATUS.FILTERED_BLOCKED_SERVICE; getDateCell = row => CellWrap( row, @@ -142,6 +145,25 @@ class Logs extends Component { }) ); + getFilterName = (filters, filterId, t) => { + if (filterId === CUSTOM_FILTERING_RULES_ID) { + return t('custom_filter_rules'); + } + + const filter = filters.find(filter => filter.id === filterId); + let filterName = ''; + + if (filter) { + filterName = filter.name; + } + + if (!filterName) { + filterName = t('unknown_filter', { filterId }); + } + + return filterName; + } + getResponseCell = ({ value: responses, original }) => { const { reason, filterId, rule, status, originalAnswer, @@ -150,43 +172,50 @@ class Logs extends Component { const { filters } = filtering; const isFiltered = this.checkFiltered(reason); - const filterKey = reason.replace(FILTERED_REASON, ''); - const parsedFilteredReason = t('query_log_filtered', { filter: filterKey }); + const isBlackList = this.checkBlackList(reason); const isRewrite = this.checkRewrite(reason); const isWhiteList = this.checkWhiteList(reason); - const isBlockedService = reason === FILTERED_STATUS.FILTERED_BLOCKED_SERVICE; + const isBlockedService = this.checkBlockedService(reason); + const isBlockedCnameIp = originalAnswer; + + const filterKey = reason.replace(FILTERED_REASON, ''); + const parsedFilteredReason = t('query_log_filtered', { filter: filterKey }); const currentService = SERVICES.find(service => service.id === original.serviceName); const serviceName = currentService && currentService.name; - const normalizedAnswer = originalAnswer && this.normalizeResponse(originalAnswer); - let filterName = ''; + const filterName = this.getFilterName(filters, filterId, t); - if (filterId === 0) { - filterName = t('custom_filter_rules'); - } else { - const filterItem = Object.keys(filters).filter(key => filters[key].id === filterId)[0]; + if (isBlockedCnameIp) { + const normalizedAnswer = this.normalizeResponse(originalAnswer); - if (typeof filterItem !== 'undefined' && typeof filters[filterItem] !== 'undefined') { - filterName = filters[filterItem].name; - } - - if (!filterName) { - filterName = t('unknown_filter', { filterId }); - } + return ( +
+
+ + blocked_by_response + +
+
+ {this.renderResponseList(normalizedAnswer, status)} +
+
+ ); } return (
- {originalAnswer && ( - - blocked_by_response - - )} - {!originalAnswer && (isFiltered || isBlockedService) && ( + {(isFiltered || isBlockedService) && !isBlackList && ( {parsedFilteredReason} )} + {isBlackList && ( + + + query_log_filtered + + + )} {isBlockedService ? this.renderTooltip(isFiltered, '', '', serviceName) : this.renderTooltip(isFiltered, rule, filterName)} @@ -197,10 +226,7 @@ class Logs extends Component { )}
- {originalAnswer - ? this.renderResponseList(normalizedAnswer, status) - : this.renderResponseList(responses, status) - } + {this.renderResponseList(responses, status)} {isWhiteList && this.renderTooltip(isWhiteList, rule, filterName)}
diff --git a/client/src/helpers/constants.js b/client/src/helpers/constants.js index 218d8e43..65f8cc5d 100644 --- a/client/src/helpers/constants.js +++ b/client/src/helpers/constants.js @@ -450,3 +450,5 @@ export const DETAILED_DATE_FORMAT_OPTIONS = { ...DEFAULT_DATE_FORMAT_OPTIONS, month: 'long', }; + +export const CUSTOM_FILTERING_RULES_ID = 0;