import React from "react"; import PropTypes from "prop-types"; import classNames from "classnames"; import { filter, includes, isEqual, noop } from "lodash"; import targetInterface from "interfaces/target"; import TargetDetails from "../TargetDetails"; import { targetFilter } from "./helpers"; import TargetOption from "../TargetOption"; const baseClass = "target-list"; const SelectTargetsMenuWrapper = ( onMoreInfoClick, moreInfoTarget, handleBackToResults, isPremiumTier ) => { const SelectTargetsMenu = ({ focusedOption, instancePrefix, onFocus, onSelect, optionClassName, optionComponent, options, valueArray = [], valueKey, onOptionRef, }) => { const Option = optionComponent; const renderTargets = (targetType) => { const targets = filter(options, targetFilter(targetType)); const targetsOutput = []; const targetTitle = targetType === "all" ? "all hosts" : targetType; targetsOutput.push(
{targetTitle}
); if (targets.length === 0) { if (targetType === "all") { return false; } targetsOutput.push( Unable to find any matching {targetType}. ); return targetsOutput; } targetsOutput.push( targets.map((target, index) => { const { disabled: isDisabled } = target; const isSelected = includes(valueArray, target); const isFocused = isEqual(focusedOption, target); const className = classNames(optionClassName, { "Select-option": true, "is-selected": isSelected, "is-focused": isFocused, "is-disabled": true, }); const setRef = (ref) => { onOptionRef(ref, isFocused); }; return ( ); }) ); return targetsOutput; }; const hasHostTargets = () => { return options.find((option) => option.count !== 0) !== undefined; }; const renderTargetGroups = ( <> {renderTargets("all")} {isPremiumTier && renderTargets("fleets")} {renderTargets("labels")} {renderTargets("hosts")} > ); return (