| 1 |
import React from "react"; |
| 2 |
// Navigation |
| 3 |
import { URL_PREFIX } from "src/navigation/NavRoutes"; |
| 4 |
import { NotFound } from "src/components/errors/PageErrors"; |
| 5 |
// Hooks |
| 6 |
import { useDnsRecordsData } from "src/hooks/useDnsRecordsData"; |
| 7 |
// Components |
| 8 |
import DataSpinner from "src/components/layouts/DataSpinner"; |
| 9 |
import { BreadCrumbItem } from "src/components/layouts/BreadCrumb/BreadCrumb"; |
| 10 |
import DnsResourceRecordsSettings from "./DnsResourceRecordsSettings"; |
| 11 |
import { useSafeParams } from "src/utils/paramsUtils"; |
| 12 |
|
| 13 |
type DnsParams = { |
| 14 |
idnsname: string; |
| 15 |
recordName: string; |
| 16 |
}; |
| 17 |
|
| 18 |
const DnsResourceRecordsPreSettings = () => { |
| 19 |
const pathname = "dns-zones"; |
| 20 |
|
| 21 |
// Params |
| 22 |
const { idnsname, recordName } = useSafeParams<DnsParams>([ |
| 23 |
"idnsname", |
| 24 |
"recordName", |
| 25 |
]); |
| 26 |
|
| 27 |
// Data loaded from the API |
| 28 |
const dnsrecordsSettingsData = useDnsRecordsData(idnsname, recordName); |
| 29 |
|
| 30 |
// Breadcrumbs |
| 31 |
const [breadcrumbItems, setBreadcrumbItems] = React.useState< |
| 32 |
BreadCrumbItem[] |
| 33 |
>([]); |
| 34 |
|
| 35 |
React.useEffect(() => { |
| 36 |
// Update breadcrumb route |
| 37 |
const currentPath: BreadCrumbItem[] = [ |
| 38 |
{ |
| 39 |
name: "DNS zones", |
| 40 |
url: URL_PREFIX + "/" + pathname, |
| 41 |
}, |
| 42 |
{ |
| 43 |
name: idnsname, |
| 44 |
url: URL_PREFIX + "/" + pathname + "/" + idnsname, |
| 45 |
}, |
| 46 |
{ |
| 47 |
name: recordName, |
| 48 |
url: URL_PREFIX + "/" + pathname + "/" + idnsname + "/" + recordName, |
| 49 |
isActive: true, |
| 50 |
}, |
| 51 |
]; |
| 52 |
setBreadcrumbItems(currentPath); |
| 53 |
}, [idnsname, recordName]); |
| 54 |
|
| 55 |
// Handling of the API data |
| 56 |
if (dnsrecordsSettingsData.isLoading || !dnsrecordsSettingsData.dnsRecord) { |
| 57 |
return <DataSpinner />; |
| 58 |
} |
| 59 |
|
| 60 |
// Show the 'NotFound' page if the certMapping is not found |
| 61 |
if ( |
| 62 |
!dnsrecordsSettingsData.isLoading && |
| 63 |
Object.keys(dnsrecordsSettingsData.dnsRecord).length === 0 |
| 64 |
) { |
| 65 |
return <NotFound />; |
| 66 |
} |
| 67 |
|
| 68 |
// Return component |
| 69 |
return ( |
| 70 |
<DnsResourceRecordsSettings |
| 71 |
idnsname={idnsname} |
| 72 |
recordName={recordName} |
| 73 |
dnsRecord={dnsrecordsSettingsData.dnsRecord} |
| 74 |
originalDnsRecord={dnsrecordsSettingsData.originalDnsRecord} |
| 75 |
host={dnsrecordsSettingsData.host} |
| 76 |
originalHost={dnsrecordsSettingsData.originalHost} // is this needed? |
| 77 |
metadata={dnsrecordsSettingsData.metadata} |
| 78 |
onDnsRecordChange={dnsrecordsSettingsData.setDnsRecord} |
| 79 |
onHostChange={dnsrecordsSettingsData.setHost} |
| 80 |
isModified={dnsrecordsSettingsData.modified} |
| 81 |
isDataLoading={dnsrecordsSettingsData.isLoading} |
| 82 |
modifiedValues={dnsrecordsSettingsData.modifiedValues} |
| 83 |
onResetValues={dnsrecordsSettingsData.resetValues} |
| 84 |
pathname={pathname} |
| 85 |
onRefresh={dnsrecordsSettingsData.refetch} |
| 86 |
breadcrumbItems={breadcrumbItems} |
| 87 |
/> |
| 88 |
); |
| 89 |
}; |
| 90 |
|
| 91 |
export default DnsResourceRecordsPreSettings; |