import React, { useState } from 'react'; import PropTypes from 'prop-types'; import useDeepCompareEffect from 'use-deep-compare-effect'; import { useDispatch, useSelector } from 'react-redux'; import { useParams } from 'react-router-dom'; import { isEmpty } from 'lodash'; import { Button, ExpandableSection, ExpandableSectionToggle, List, ListItem, Split, SplitItem, Stack, StackItem, TextContent, TextList, TextListItem, TextListItemVariants, TextListVariants, Flex, FlexItem, } from '@patternfly/react-core'; import { PencilAltIcon } from '@patternfly/react-icons'; import { STATUS } from 'foremanReact/constants'; import { urlBuilder } from 'foremanReact/common/urlHelpers'; import { translate as __ } from 'foremanReact/common/I18n'; import { getACSDetails } from '../ACSActions'; import { selectACSDetails, selectACSDetailsError, selectACSDetailsStatus } from '../ACSSelectors'; import Loading from '../../../components/Loading'; import InactiveText from '../../ContentViews/components/InactiveText'; import ACSEditDetails from './EditModals/ACSEditDetails'; import ACSEditURLPaths from './EditModals/ACSEditURLPaths'; import ACSEditSmartProxies from './EditModals/ACSEditSmartProxies'; import ACSEditCredentials from './EditModals/ACSEditCredentials'; import ACSEditProducts from './EditModals/ACSEditProducts'; import EmptyStateMessage from '../../../components/Table/EmptyStateMessage'; import '../Acs.scss'; import { hasPermission } from '../../ContentViews/helpers'; import { HelpToolTip } from '../../ContentViews/Create/ContentViewFormComponents'; const ACSExpandableDetails = ({ expandedId }) => { const { id } = useParams(); const acsId = Number(expandedId) || Number(id); const details = useSelector(state => selectACSDetails(state, acsId)); const status = useSelector(state => selectACSDetailsStatus(state, acsId)); const error = useSelector(state => selectACSDetailsError(state, acsId)); const dispatch = useDispatch(); const [showDetails, setShowDetails] = useState(true); const [showSmartProxies, setShowSmartProxies] = useState(false); const [showProducts, setShowProducts] = useState(false); const [showUrlPaths, setShowUrlPaths] = useState(false); const [showCredentials, setShowCredentials] = useState(false); const [editDetailsModalOpen, setEditDetailsModalOpen] = useState(false); const [editUrlModalOpen, setEditUrlModalOpen] = useState(false); const [editSmartProxiesModalOpen, setEditSmartProxiesModalOpen] = useState(false); const [editProductsModalOpen, setEditProductsModalOpen] = useState(false); const [editCredentialsModalOpen, setEditCredentialsModalOpen] = useState(false); useDeepCompareEffect(() => { if (isEmpty(details)) { dispatch(getACSDetails(acsId)); } }, [acsId, details, dispatch]); if (status === STATUS.PENDING) return ; const { name, alternate_content_source_type: acsType, content_type: contentType, subpaths, description, base_url: url, smart_proxies: smartProxies, use_http_proxies: useHttpProxies, verify_ssl: verifySsl, ssl_ca_cert: sslCaCert, ssl_client_cert: sslClientCert, ssl_client_key: sslClientKey, upstream_username: username, products, permissions, } = details; if (error) { return ; } const canEdit = hasPermission(permissions, 'edit_alternate_content_sources'); return ( <> { setShowDetails(expanded); setShowSmartProxies(false); setShowProducts(false); setShowUrlPaths(false); setShowCredentials(false); }} contentId="showDetails" > {__('Details')} {canEdit && } {__('Name')} {name} {__('Description')} {description || } {__('Type')} {acsType} {__('Content type')} {contentType} { setShowDetails(false); setShowSmartProxies(expanded); setShowUrlPaths(false); setShowCredentials(false); setShowProducts(false); }} contentId="showSmartProxies" > {__('Smart proxies')} {canEdit && } {smartProxies?.length > 0 && smartProxies.map(sp => ( {sp?.name} ))} {smartProxies?.length === 0 && } {__('Use HTTP proxies')} {useHttpProxies ? 'true' : 'false'} {acsType === 'simplified' && <> { setShowDetails(false); setShowSmartProxies(false); setShowProducts(expanded); setShowUrlPaths(false); setShowCredentials(false); }} isExpanded={showProducts} contentId="showProducts" > {__('Products')} {canEdit && } {products.map(product => ( {product?.name} ))} } {(acsType === 'custom' || acsType === 'rhui') && <> { setShowDetails(false); setShowSmartProxies(false); setShowUrlPaths(expanded); setShowCredentials(false); }} isExpanded={showUrlPaths} contentId="showUrlPaths" > {__('URL and subpaths')} {canEdit && } {__('URL')} {url} {__('Subpaths')} {subpaths.join()} { setShowDetails(false); setShowSmartProxies(false); setShowUrlPaths(false); setShowCredentials(expanded); }} isExpanded={showCredentials} contentId="showCredentials" > {__('Credentials')} {canEdit && } {__('Verify SSL')} {verifySsl ? 'true' : 'false'} {__('SSL CA certificate')} {sslCaCert ? {sslCaCert?.name} : } {__('SSL client certificate')} {sslClientCert ? {sslClientCert?.name} : } {__('SSL client key')} {sslClientKey ? {sslClientKey?.name} : } {__('Username')} {username || } {__('Password')} {username ? '****' : } } {editDetailsModalOpen && setEditDetailsModalOpen(false)} /> } {editUrlModalOpen && setEditUrlModalOpen(false)} /> } {editSmartProxiesModalOpen && setEditSmartProxiesModalOpen(false)} /> } {editProductsModalOpen && setEditProductsModalOpen(false)} /> } {editCredentialsModalOpen && setEditCredentialsModalOpen(false)} /> } ); }; ACSExpandableDetails.propTypes = { expandedId: PropTypes.oneOfType([ PropTypes.number, PropTypes.string, ]), }; ACSExpandableDetails.defaultProps = { expandedId: null, }; export default ACSExpandableDetails;