badguardhome/client/src/helpers/formatClientCell.js

56 lines
1.7 KiB
JavaScript
Raw Normal View History

import React, { Fragment } from 'react';
import { getClientInfo, getAutoClientInfo, normalizeWhois } from './helpers';
2019-09-24 12:28:59 +00:00
import { WHOIS_ICONS } from './constants';
2019-09-24 12:28:59 +00:00
const getFormattedWhois = (whois, t) => {
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={t(key)}>
{icon && (
<Fragment>
<svg className="logs__whois-icon icons">
<use xlinkHref={`#${icon}`} />
</svg>&nbsp;
</Fragment>
)}{whoisInfo[key]}
</span>
);
})
);
};
export const formatClientCell = (value, clients, autoClients, t) => {
const clientInfo = getClientInfo(clients, value) || getAutoClientInfo(autoClients, value);
const { name, whois } = clientInfo;
2019-09-24 12:28:59 +00:00
let whoisContainer = '';
let nameContainer = value;
2019-09-24 12:28:59 +00:00
if (name) {
nameContainer = (
<span className="logs__text logs__text--wrap" title={`${name} (${value})`}>
{name} <small>({value})</small>
</span>
);
}
2019-09-24 12:28:59 +00:00
if (whois) {
whoisContainer = (
2019-10-10 15:57:39 +00:00
<div className="logs__text logs__text--wrap logs__text--whois">
2019-09-24 12:28:59 +00:00
{getFormattedWhois(whois, t)}
</div>
);
}
return (
2019-09-24 12:28:59 +00:00
<span className="logs__text">
<Fragment>
{nameContainer}
{whoisContainer}
</Fragment>
</span>
);
};