import React from 'react'; import PropTypes from 'prop-types'; import { Chip, ChipGroup, Button } from '@patternfly/react-core'; import { translate as __ } from 'foremanReact/common/I18n'; import { hostMethods } from '../../JobWizardConstants'; const SelectedChip = ({ selected, setSelected, categoryName }) => { const deleteItem = itemToRemove => { setSelected(oldSelected => oldSelected.filter(({ id }) => id !== itemToRemove) ); }; return ( {selected.map(({ name, id }, index) => ( deleteItem(id)} closeBtnAriaLabel={`Close ${name}`} > {name} ))} ); }; export const SelectedChips = ({ selectedHosts, setSelectedHosts, selectedHostCollections, setSelectedHostCollections, selectedHostGroups, setSelectedHostGroups, hostsSearchQuery, clearSearch, }) => { const clearAll = () => { setSelectedHosts(() => []); setSelectedHostCollections(() => []); setSelectedHostGroups(() => []); clearSearch(); }; const showClear = selectedHosts.length || selectedHostCollections.length || selectedHostGroups.length || hostsSearchQuery; return (
{showClear && ( )}
); }; SelectedChips.propTypes = { selectedHosts: PropTypes.array.isRequired, setSelectedHosts: PropTypes.func.isRequired, selectedHostCollections: PropTypes.array.isRequired, setSelectedHostCollections: PropTypes.func.isRequired, selectedHostGroups: PropTypes.array.isRequired, setSelectedHostGroups: PropTypes.func.isRequired, hostsSearchQuery: PropTypes.string.isRequired, clearSearch: PropTypes.func.isRequired, }; SelectedChip.propTypes = { categoryName: PropTypes.string.isRequired, selected: PropTypes.array.isRequired, setSelected: PropTypes.func.isRequired, };