import React, { Component, PropTypes } from 'react'; import { noop } from 'lodash'; import AceEditor from 'react-ace'; import classnames from 'classnames'; import hostHelpers from 'components/hosts/HostDetails/helpers'; import Icon from 'components/icons/Icon'; import targetInterface from 'interfaces/target'; const baseClass = 'target-details'; class TargetDetails extends Component { static propTypes = { target: targetInterface, className: PropTypes.string, handleBackToResults: PropTypes.func, }; static defaultProps = { handleBackToResults: noop, }; onlineHosts = (labelBaseClass, online) => { if (online > 0) { return ( ({online}% ONLINE) ); } return false; }; renderHost = () => { const { className, handleBackToResults, target } = this.props; const { display_text: displayText, ip, mac, memory, osqueryVersion, osVersion, platform, status, } = target; const hostBaseClass = 'host-target'; const isOnline = status === 'online'; const isOffline = status === 'offline'; const statusClassName = classnames( `${hostBaseClass}__status`, { [`${hostBaseClass}__status--is-online`]: isOnline }, { [`${hostBaseClass}__status--is-offline`]: isOffline }, ); return (

{displayText}

{isOnline && } {isOffline && } {status}

IP Address {ip}
MAC Address {mac}
Platform {platform}
Operating System {osVersion}
Osquery Version {osqueryVersion}
Memory {hostHelpers.humanMemory(memory)}

Labels

); } renderLabel = () => { const { onlineHosts } = this; const { handleBackToResults, className, target } = this.props; const { count, description, display_text: displayText, label_type: labelType, online, query, } = target; const labelBaseClass = 'label-target'; return (

{displayText}

{count}HOSTS { onlineHosts(labelBaseClass, online) }

{description || 'No Description'}

{labelType !== 1 &&
}
); } render () { const { target } = this.props; if (!target) { return false; } const { target_type: targetType } = target; const { renderHost, renderLabel } = this; if (targetType === 'labels') { return renderLabel(); } return renderHost(); } } export default TargetDetails;