import React, { useContext, useState } from 'react'; import { translate as __ } from 'foremanReact/common/I18n'; import { FormattedMessage } from 'react-intl'; import { TreeView, Button, Text, TextContent, TextVariants, Flex, FlexItem, Dropdown, DropdownItem, DropdownToggle } from '@patternfly/react-core'; import { useWizardContext } from '@patternfly/react-core/next'; import { CaretDownIcon } from '@patternfly/react-icons'; import { BulkPackagesWizardContext, UPGRADE_ALL, INSTALL, REMOVE, UPGRADE } from './BulkPackagesWizard'; export const dropdownOptions = [ __('via remote execution'), __('via customized remote execution'), ]; export const BulkPackagesReview = () => { const { goToStepById } = useWizardContext(); const { selectedAction, finishButtonText, selectedRexOption, setSelectedRexOption, finishButtonLoading, packagesBulkSelect: { selectedResults: selectedPackageResults, selectedCount: currentSelectedPackagesCount, }, hostsBulkSelect: { selectedCount: currentSelectedHostsCount, }, } = useContext(BulkPackagesWizardContext); const [isDropdownOpen, setIsDropdownOpen] = useState(false); const toggleDropdownOpen = () => setIsDropdownOpen(prev => !prev); const handleSelect = () => { setIsDropdownOpen(false); }; const dropdownItems = dropdownOptions.map(text => ( setSelectedRexOption(text)}>{text} )); const packageActionsDescriptions = { [INSTALL]: __('Packages to install'), [REMOVE]: __('Packages to be removed'), [UPGRADE]: __('Packages to be updated'), [UPGRADE_ALL]: __('Packages to be updated'), }; const treeViewTitle = packageActionsDescriptions[selectedAction]; const treeViewData = [ { name: treeViewTitle, id: 'packages-treeview-title', customBadgeContent: selectedAction === UPGRADE_ALL ? 'All' : currentSelectedPackagesCount, children: selectedAction === UPGRADE_ALL ? undefined : selectedPackageResults.map(({ id, name }) => ({ name, id, key: id, })), action: ( ), actionProps: { 'aria-label': 'Edit packages list', }, }, ]; const hostTreeViewData = [ { name: __('Hosts'), id: 'packages-host-treeview-title', customBadgeContent: currentSelectedHostsCount, expandedIcon: null, action: ( ), actionProps: { 'aria-label': 'Edit host selection', }, }, ]; return ( <> {__('Review')} {finishButtonText}, }} />
{selectedRexOption} } onSelect={handleSelect} isOpen={isDropdownOpen} dropdownItems={dropdownItems} menuAppendTo="parent" /> ); }; export default BulkPackagesReview;