badguardhome/client/src/helpers/formatClientCell.js

59 lines
1.6 KiB
JavaScript
Raw Normal View History

import React, { Fragment } from 'react';
2019-11-28 14:59:55 +00:00
import { 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>
);
})
);
};
2019-11-28 14:59:55 +00:00
export const formatClientCell = (row, t) => {
const { value, original: { info } } = row;
2019-09-24 12:28:59 +00:00
let whoisContainer = '';
let nameContainer = value;
2019-11-28 14:59:55 +00:00
if (info) {
const { name, whois } = info;
2019-11-28 14:59:55 +00:00
if (name) {
nameContainer = (
<span className="logs__text logs__text--wrap" title={`${name} (${value})`}>
{name} <small>({value})</small>
</span>
);
}
if (whois) {
whoisContainer = (
<div className="logs__text logs__text--wrap logs__text--whois">
{getFormattedWhois(whois, t)}
</div>
);
}
2019-09-24 12:28:59 +00:00
}
return (
2019-09-24 12:28:59 +00:00
<span className="logs__text">
<Fragment>
{nameContainer}
{whoisContainer}
</Fragment>
</span>
);
};