import React, { useContext, useState, useEffect } from 'react'; import { ExpandableSection, Flex, FlexItem } from '@patternfly/react-core'; import { ExclamationTriangleIcon } from '@patternfly/react-icons'; import { TableVariant, TableComposable, Thead, Tbody, Tr, Th, Td } from '@patternfly/react-table'; import { translate as __ } from 'foremanReact/common/I18n'; import { STATUS } from 'foremanReact/constants'; import CVDeleteContext from '../CVDeleteContext'; import { pluralize } from '../../../../utils/helpers'; import Loading from '../../../../components/Loading'; import './CVEnvironmentSelectionForm.scss'; import InactiveText from '../../components/InactiveText'; const CVDeleteEnvironmentSelection = () => { const { cvVersionResponse, cvDetailsResponse, cvVersionStatus, cvDetailsStatus, } = useContext(CVDeleteContext); const [versionExpanded, setVersionExpanded] = useState([]); const { results } = cvVersionResponse ?? {}; const { version_count: versionCount } = cvDetailsResponse ?? {}; const resolved = (cvVersionStatus === STATUS.RESOLVED && cvDetailsStatus === STATUS.RESOLVED); useEffect(() => { if (cvVersionResponse && results) { setVersionExpanded(new Array(results?.length).fill(false)); } }, [cvVersionResponse, results]); const columnHeaders = [ __('Environment'), __('Hosts'), __('Activation keys'), ]; const setExpanded = (index, expanded) => { setVersionExpanded(versionExpanded.map((val, i) => (i === index ? expanded : val))); }; return ( <>