import React, { useState } from 'react'; 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, } 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, 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'; const ACSExpandableDetails = () => { const { id } = useParams(); const acsId = Number(id); const details = useSelector(state => selectACSDetails(state, acsId)); const status = useSelector(state => selectACSDetailsStatus(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, verify_ssl: verifySsl, ssl_ca_cert: sslCaCert, ssl_client_cert: sslClientCert, ssl_client_key: sslClientKey, upstream_username: username, products, } = details; return ( <> { setShowDetails(expanded); setShowSmartProxies(false); setShowProducts(false); setShowUrlPaths(false); setShowCredentials(false); }} contentId="showDetails" > {showDetails ? __('Hide details') : __('Show details')} {__('Name')} {name} {__('Description')} {description} {__('Type')} {acsType} {__('Content type')} {contentType} { setShowDetails(false); setShowSmartProxies(expanded); setShowUrlPaths(false); setShowCredentials(false); }} contentId="showSmartProxies" > {showSmartProxies ? 'Hide smart proxies' : 'Show smart proxies'} {smartProxies?.length > 0 && smartProxies.map(sp => ( {sp?.name} ))} {smartProxies?.length === 0 && } {acsType === 'simplified' && <> { setShowDetails(false); setShowSmartProxies(false); setShowProducts(expanded); setShowUrlPaths(false); setShowCredentials(false); }} isExpanded={showProducts} contentId="showProducts" > {showProducts ? 'Hide products' : 'Show products'} {products.map(product => ( {product?.name} ))} } {acsType === 'custom' && <> { setShowDetails(false); setShowSmartProxies(false); setShowUrlPaths(expanded); setShowCredentials(false); }} isExpanded={showUrlPaths} contentId="showUrlPaths" > {showUrlPaths ? 'Hide URL and subpaths' : 'Show URL and subpaths'} {__('URL')} {url} {__('Subpaths')} {subpaths.join()} { setShowDetails(false); setShowSmartProxies(false); setShowUrlPaths(false); setShowCredentials(expanded); }} isExpanded={showCredentials} contentId="showCredentials" > {showCredentials ? 'Hide credentials' : 'Show credentials'} {__('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)} /> } ); }; export default ACSExpandableDetails;