import React, { Component } from "react"; import PropTypes from "prop-types"; import classnames from "classnames"; import targetInterface from "interfaces/target"; import TargetIcon from "./TargetIcon"; const baseClass = "target-option"; class TargetOption extends Component { static propTypes = { onMoreInfoClick: PropTypes.func, onSelect: PropTypes.func, target: targetInterface.isRequired, }; handleSelect = (evt) => { const { onSelect, target } = this.props; return onSelect(target, evt); }; renderTargetDetail = () => { const { target } = this.props; const { count, primary_ip: hostIpAddress, target_type: targetType, } = target; if (targetType === "hosts") { if (!hostIpAddress) { return false; } return ( {hostIpAddress} ); } return {count} hosts; }; render() { const { onMoreInfoClick, target } = this.props; const { display_text: displayText, target_type: targetType } = target; const { handleSelect, renderTargetDetail } = this; const wrapperClassName = classnames(`${baseClass}__wrapper`, { "is-team": targetType === "teams", "is-label": targetType === "labels", "is-host": targetType === "hosts", }); return (
); } } export default TargetOption;