| 1 |
import React from "react"; |
| 2 |
// PatternFly |
| 3 |
import { PageSection, Tabs, Tab, TabTitleText } from "@patternfly/react-core"; |
| 4 |
// React Router DOM |
| 5 |
import { useNavigate } from "react-router"; |
| 6 |
// Navigation |
| 7 |
import { URL_PREFIX } from "src/navigation/NavRoutes"; |
| 8 |
import { NotFound } from "src/components/errors/PageErrors"; |
| 9 |
// Hooks |
| 10 |
// import { useCertMappingSettingsData } from "src/hooks/useCertMappingSettingsData"; |
| 11 |
import { useCertificateMappingSettingsData } from "src/hooks/useCertificateMappingSettingsData"; |
| 12 |
// Components |
| 13 |
import TitleLayout from "src/components/layouts/TitleLayout"; |
| 14 |
import DataSpinner from "src/components/layouts/DataSpinner"; |
| 15 |
import BreadCrumb, { |
| 16 |
BreadCrumbItem, |
| 17 |
} from "src/components/layouts/BreadCrumb/BreadCrumb"; |
| 18 |
import CertificateMappingSettings from "./CertificateMappingSettings"; |
| 19 |
import { CnParams, useSafeParams } from "src/utils/paramsUtils"; |
| 20 |
|
| 21 |
// eslint-disable-next-line react/prop-types |
| 22 |
const CertificateMappingTabs = ({ section }) => { |
| 23 |
const { cn } = useSafeParams<CnParams>(["cn"]); |
| 24 |
const navigate = useNavigate(); |
| 25 |
const pathname = "cert-id-mapping-rules"; |
| 26 |
|
| 27 |
const [breadcrumbItems, setBreadcrumbItems] = React.useState< |
| 28 |
BreadCrumbItem[] |
| 29 |
>([]); |
| 30 |
|
| 31 |
// States - Identifier of the entity (Certificate mapping -> cn) |
| 32 |
const [id, setId] = React.useState(""); |
| 33 |
|
| 34 |
// Data loaded from the API |
| 35 |
const certMappingSettingsData = useCertificateMappingSettingsData(cn); |
| 36 |
|
| 37 |
const handleTabClick = ( |
| 38 |
_event: React.MouseEvent<HTMLElement, MouseEvent>, |
| 39 |
tabIndex: number | string |
| 40 |
) => { |
| 41 |
if (tabIndex === "settings") { |
| 42 |
navigate("/" + pathname + "/" + id); |
| 43 |
} |
| 44 |
}; |
| 45 |
|
| 46 |
React.useEffect(() => { |
| 47 |
setId(cn); |
| 48 |
// Update breadcrumb route |
| 49 |
const currentPath: BreadCrumbItem[] = [ |
| 50 |
{ |
| 51 |
name: "Certificate Identity Mapping Rule", |
| 52 |
url: URL_PREFIX + "/" + pathname, |
| 53 |
}, |
| 54 |
{ |
| 55 |
name: cn, |
| 56 |
url: URL_PREFIX + "/" + pathname + "/" + cn, |
| 57 |
isActive: true, |
| 58 |
}, |
| 59 |
]; |
| 60 |
setBreadcrumbItems(currentPath); |
| 61 |
}, [cn]); |
| 62 |
|
| 63 |
// Handling of the API data |
| 64 |
if ( |
| 65 |
certMappingSettingsData.isLoading || |
| 66 |
!certMappingSettingsData.certMapping |
| 67 |
) { |
| 68 |
return <DataSpinner />; |
| 69 |
} |
| 70 |
|
| 71 |
// Show the 'NotFound' page if the certMapping is not found |
| 72 |
if ( |
| 73 |
!certMappingSettingsData.isLoading && |
| 74 |
Object.keys(certMappingSettingsData.certMapping).length === 0 |
| 75 |
) { |
| 76 |
return <NotFound />; |
| 77 |
} |
| 78 |
|
| 79 |
// Return component |
| 80 |
return ( |
| 81 |
<> |
| 82 |
<PageSection hasBodyWrapper={false}> |
| 83 |
<BreadCrumb breadcrumbItems={breadcrumbItems} /> |
| 84 |
<TitleLayout |
| 85 |
id={id} |
| 86 |
preText="Certificate Identity Mapping Rule:" |
| 87 |
text={id} |
| 88 |
headingLevel="h1" |
| 89 |
/> |
| 90 |
</PageSection> |
| 91 |
<PageSection hasBodyWrapper={false} type="tabs" isFilled> |
| 92 |
<Tabs |
| 93 |
activeKey={section} |
| 94 |
onSelect={handleTabClick} |
| 95 |
variant="secondary" |
| 96 |
isBox |
| 97 |
className="pf-v6-u-ml-lg" |
| 98 |
mountOnEnter |
| 99 |
unmountOnExit |
| 100 |
> |
| 101 |
<Tab |
| 102 |
eventKey={"settings"} |
| 103 |
name="settings-details" |
| 104 |
title={<TabTitleText>Settings</TabTitleText>} |
| 105 |
> |
| 106 |
<CertificateMappingSettings |
| 107 |
certMapping={certMappingSettingsData.certMapping} |
| 108 |
originalCertMapping={certMappingSettingsData.originalCertMapping} |
| 109 |
metadata={certMappingSettingsData.metadata} |
| 110 |
onCertMappingChange={certMappingSettingsData.setCertMapping} |
| 111 |
onRefresh={certMappingSettingsData.refetch} |
| 112 |
isModified={certMappingSettingsData.modified} |
| 113 |
isDataLoading={certMappingSettingsData.isLoading} |
| 114 |
modifiedValues={certMappingSettingsData.modifiedValues} |
| 115 |
onResetValues={certMappingSettingsData.resetValues} |
| 116 |
pathname={pathname} |
| 117 |
/> |
| 118 |
</Tab> |
| 119 |
</Tabs> |
| 120 |
</PageSection> |
| 121 |
</> |
| 122 |
); |
| 123 |
}; |
| 124 |
|
| 125 |
export default CertificateMappingTabs; |