import React from "react"; import classnames from "classnames"; import { ISelectTargetsEntity } from "interfaces/target"; // @ts-ignore import Button from "components/buttons/Button/Button"; // @ts-ignore import Icon from "components/Icon"; // @ts-ignore import TargetIcon from "./TargetIcon"; import { isTargetHost, isTargetLabel, isTargetTeam } from "../helpers"; const baseClass = "target-option"; interface ITargetOptionProps { onMoreInfoClick: ( target: ISelectTargetsEntity ) => (event: React.MouseEvent) => void; onSelect: (target: ISelectTargetsEntity, event: React.MouseEvent) => void; target: ISelectTargetsEntity; } const TargetOption = ({ onMoreInfoClick, onSelect, target, }: ITargetOptionProps): JSX.Element => { const handleSelect = (evt: React.MouseEvent) => { return onSelect(target, evt); }; const renderTargetDetail = () => { if (isTargetHost(target)) { const { primary_ip: hostIpAddress } = target; if (!hostIpAddress) { return null; } return ( {hostIpAddress} ); } if (isTargetTeam(target) || isTargetLabel(target)) { return ( {target.count} hosts ); } return <>>; }; const { display_text: displayText, target_type: targetType } = target; const wrapperClassName = classnames(`${baseClass}__wrapper`, { "is-team": targetType === "teams", "is-label": targetType === "labels", "is-host": targetType === "hosts", }); return (