badguardhome/client/src/helpers/renderFormattedClientCell.js
Ainar Garipov b43aa86cae Pull request: client: use strict search by client
Updates #4271.

Squashed commit of the following:

commit 10a113126306fce51b4dd10a696b8c7d3213a445
Author: Ainar Garipov <A.Garipov@AdGuard.COM>
Date:   Fri Feb 11 18:37:18 2022 +0300

    client: more strict search

commit 7aa24129195c0eba442bfe43564469fdb2a5b138
Author: Ainar Garipov <A.Garipov@AdGuard.COM>
Date:   Fri Feb 11 18:22:18 2022 +0300

    client: use strict search by client
2022-02-11 18:56:08 +03:00

71 lines
2.2 KiB
JavaScript

import React from 'react';
import { Link } from 'react-router-dom';
import { normalizeWhois } from './helpers';
import { WHOIS_ICONS } from './constants';
const getFormattedWhois = (whois) => {
const whoisInfo = normalizeWhois(whois);
return (
Object.keys(whoisInfo)
.map((key) => {
const icon = WHOIS_ICONS[key];
return (
<span className="logs__whois text-muted" key={key} title={whoisInfo[key]}>
{icon && (
<>
<svg className="logs__whois-icon icons icon--18">
<use xlinkHref={`#${icon}`} />
</svg>
&nbsp;
</>
)}{whoisInfo[key]}
</span>
);
})
);
};
/**
* @param {string} value
* @param {object} info
* @param {string} info.name
* @param {object} info.whois_info
* @param {boolean} [isDetailed]
* @param {boolean} [isLogs]
* @returns {JSXElement}
*/
export const renderFormattedClientCell = (value, info, isDetailed = false, isLogs = false) => {
let whoisContainer = null;
let nameContainer = value;
if (info) {
const { name, whois_info } = info;
const whoisAvailable = whois_info && Object.keys(whois_info).length > 0;
if (name) {
const nameValue = <div className="logs__text logs__text--link logs__text--nowrap" title={`${name} (${value})`}>
{name}&nbsp;<small>{`(${value})`}</small>
</div>;
if (!isLogs) {
nameContainer = nameValue;
} else {
nameContainer = !whoisAvailable && isDetailed
? <small title={value}>{value}</small>
: nameValue;
}
}
if (whoisAvailable && isDetailed) {
whoisContainer = <div className="logs__text logs__text--wrap logs__text--whois">
{getFormattedWhois(whois_info)}
</div>;
}
}
return <div className="logs__text mw-100" title={value}>
<Link to={`logs?search="${encodeURIComponent(value)}"`}>{nameContainer}</Link>
{whoisContainer}
</div>;
};