badguardhome/client/src/helpers/formatClientCell.js

56 lines
1.6 KiB
JavaScript
Raw Normal View History

import React, { Fragment } from 'react';
2019-09-24 12:28:59 +00:00
import { getClientInfo, normalizeWhois } from './helpers';
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) || getClientInfo(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 = (
<div className="logs__text logs__text--wrap mt-1">
{getFormattedWhois(whois, t)}
</div>
);
}
return (
2019-09-24 12:28:59 +00:00
<span className="logs__text">
<Fragment>
{nameContainer}
{whoisContainer}
</Fragment>
</span>
);
};