| 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 { useDnsZonesData } from "src/hooks/useDnsZonesData"; |
| 11 |
// Components |
| 12 |
import TitleLayout from "src/components/layouts/TitleLayout"; |
| 13 |
import DataSpinner from "src/components/layouts/DataSpinner"; |
| 14 |
import BreadCrumb, { |
| 15 |
BreadCrumbItem, |
| 16 |
} from "src/components/layouts/BreadCrumb/BreadCrumb"; |
| 17 |
import DnsZonesSettings from "./DnsZonesSettings"; |
| 18 |
import DnsResourceRecords from "./DnsResourceRecords"; |
| 19 |
import { useSafeParams } from "src/utils/paramsUtils"; |
| 20 |
|
| 21 |
type DnsParams = { |
| 22 |
idnsname: string; |
| 23 |
}; |
| 24 |
|
| 25 |
const DnsZonesTabs = ({ section }: { section: string }) => { |
| 26 |
const { idnsname } = useSafeParams<DnsParams>(["idnsname"]); |
| 27 |
const navigate = useNavigate(); |
| 28 |
const pathname = "dns-zones"; |
| 29 |
|
| 30 |
const [breadcrumbItems, setBreadcrumbItems] = React.useState< |
| 31 |
BreadCrumbItem[] |
| 32 |
>([]); |
| 33 |
|
| 34 |
// States - Identifier of the entity (DNS Zone -> idnsname) |
| 35 |
const [id, setId] = React.useState(""); |
| 36 |
|
| 37 |
// Data loaded from the API |
| 38 |
const dnsZonesSettingsData = useDnsZonesData(idnsname); |
| 39 |
|
| 40 |
const handleTabClick = ( |
| 41 |
_event: React.MouseEvent<HTMLElement, MouseEvent>, |
| 42 |
tabIndex: number | string |
| 43 |
) => { |
| 44 |
if (tabIndex === "settings") { |
| 45 |
navigate("/" + pathname + "/" + id); |
| 46 |
} else if (tabIndex === "dns-records") { |
| 47 |
navigate("/" + pathname + "/" + id + "/dns-records"); |
| 48 |
} |
| 49 |
}; |
| 50 |
|
| 51 |
React.useEffect(() => { |
| 52 |
setId(idnsname); |
| 53 |
// Update breadcrumb route |
| 54 |
const currentPath: BreadCrumbItem[] = [ |
| 55 |
{ |
| 56 |
name: "DNS zones", |
| 57 |
url: URL_PREFIX + "/" + pathname, |
| 58 |
}, |
| 59 |
{ |
| 60 |
name: idnsname, |
| 61 |
url: URL_PREFIX + "/" + pathname + "/" + idnsname, |
| 62 |
isActive: true, |
| 63 |
}, |
| 64 |
]; |
| 65 |
setBreadcrumbItems(currentPath); |
| 66 |
}, [idnsname]); |
| 67 |
|
| 68 |
// Handling of the API data |
| 69 |
if (dnsZonesSettingsData.isLoading || !dnsZonesSettingsData.dnsZone) { |
| 70 |
return <DataSpinner />; |
| 71 |
} |
| 72 |
|
| 73 |
// Show the 'NotFound' page if the certMapping is not found |
| 74 |
if ( |
| 75 |
!dnsZonesSettingsData.isLoading && |
| 76 |
Object.keys(dnsZonesSettingsData.dnsZone).length === 0 |
| 77 |
) { |
| 78 |
return <NotFound />; |
| 79 |
} |
| 80 |
|
| 81 |
// Return component |
| 82 |
return ( |
| 83 |
<> |
| 84 |
<PageSection hasBodyWrapper={false}> |
| 85 |
<BreadCrumb breadcrumbItems={breadcrumbItems} /> |
| 86 |
<TitleLayout id={id} preText="DNS zone:" text={id} headingLevel="h1" /> |
| 87 |
</PageSection> |
| 88 |
<PageSection hasBodyWrapper={false} type="tabs" isFilled> |
| 89 |
<Tabs |
| 90 |
activeKey={section} |
| 91 |
onSelect={handleTabClick} |
| 92 |
variant="secondary" |
| 93 |
isBox |
| 94 |
className="pf-v6-u-ml-lg" |
| 95 |
mountOnEnter |
| 96 |
unmountOnExit |
| 97 |
> |
| 98 |
<Tab |
| 99 |
eventKey={"settings"} |
| 100 |
name="settings-details" |
| 101 |
title={<TabTitleText>Settings</TabTitleText>} |
| 102 |
data-cy="dns-zones-tab-settings" |
| 103 |
> |
| 104 |
<DnsZonesSettings |
| 105 |
dnsZone={dnsZonesSettingsData.dnsZone} |
| 106 |
originalDnsZone={dnsZonesSettingsData.originalDnsZone} |
| 107 |
permissionsData={dnsZonesSettingsData.permissionsData} |
| 108 |
metadata={dnsZonesSettingsData.metadata} |
| 109 |
onDnsZoneChange={dnsZonesSettingsData.setDnsZone} |
| 110 |
onRefresh={dnsZonesSettingsData.refetch} |
| 111 |
isModified={dnsZonesSettingsData.modified} |
| 112 |
isDataLoading={dnsZonesSettingsData.isLoading} |
| 113 |
modifiedValues={dnsZonesSettingsData.modifiedValues} |
| 114 |
onResetValues={dnsZonesSettingsData.resetValues} |
| 115 |
pathname={pathname} |
| 116 |
/> |
| 117 |
</Tab> |
| 118 |
<Tab |
| 119 |
eventKey={"dns-records"} |
| 120 |
name="dns-records" |
| 121 |
title={<TabTitleText>DNS records</TabTitleText>} |
| 122 |
data-cy="dns-zones-tab-dns-records" |
| 123 |
> |
| 124 |
<DnsResourceRecords dnsZoneId={id} /> |
| 125 |
</Tab> |
| 126 |
</Tabs> |
| 127 |
</PageSection> |
| 128 |
</> |
| 129 |
); |
| 130 |
}; |
| 131 |
|
| 132 |
export default DnsZonesTabs; |