Debian Codegraph @

install/freeipa-webui/src/pages/IdPReferences/IdpReferencesTabs.tsx

raw
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 { useIdpRefSettingsData } from "src/hooks/useIdpRefSettingsData";
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 IdpRefSettings from "./IdpReferencesSettings";
18 import { CnParams, useSafeParams } from "src/utils/paramsUtils";
19
20 // eslint-disable-next-line react/prop-types
21 const IdpReferencesTabs = ({ section }) => {
22 const { cn } = useSafeParams<CnParams>(["cn"]);
23 const navigate = useNavigate();
24 const pathname = "identity-provider-references";
25
26 const [breadcrumbItems, setBreadcrumbItems] = React.useState<
27 BreadCrumbItem[]
28 >([]);
29
30 // States - Identifier of the entity (IdP -> cn)
31 const [id, setId] = React.useState("");
32
33 // Data loaded from the API
34 const idpRefSettingsData = useIdpRefSettingsData(cn);
35
36 // Tab
37 const [activeTabKey, setActiveTabKey] = React.useState(section);
38
39 const handleTabClick = (
40 _event: React.MouseEvent<HTMLElement, MouseEvent>,
41 tabIndex: number | string
42 ) => {
43 if (tabIndex === "settings") {
44 navigate("/" + pathname + "/" + id);
45 }
46 };
47
48 React.useEffect(() => {
49 setId(cn);
50 // Update breadcrumb route
51 const currentPath: BreadCrumbItem[] = [
52 {
53 name: "Identity provider references",
54 url: URL_PREFIX + "/" + pathname,
55 },
56 {
57 name: cn,
58 url: URL_PREFIX + "/" + pathname + "/" + cn,
59 isActive: true,
60 },
61 ];
62 setBreadcrumbItems(currentPath);
63 setActiveTabKey("settings");
64 }, [cn]);
65
66 // Handling of the API data
67 if (idpRefSettingsData.isLoading || !idpRefSettingsData.idpRef) {
68 return <DataSpinner />;
69 }
70
71 // Show the 'NotFound' page if the host is not found
72 if (
73 !idpRefSettingsData.isLoading &&
74 Object.keys(idpRefSettingsData.idpRef).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="Identity provider reference:"
87 text={id}
88 headingLevel="h1"
89 />
90 </PageSection>
91 <PageSection hasBodyWrapper={false} type="tabs" isFilled>
92 <Tabs
93 activeKey={activeTabKey}
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 <IdpRefSettings
107 idpRef={idpRefSettingsData.idpRef}
108 originalIdpRef={idpRefSettingsData.originalIdpRef}
109 metadata={idpRefSettingsData.metadata}
110 onIdpRefChange={idpRefSettingsData.setIdpRef}
111 onRefresh={idpRefSettingsData.refetch}
112 isModified={idpRefSettingsData.modified}
113 isDataLoading={idpRefSettingsData.isLoading}
114 modifiedValues={idpRefSettingsData.modifiedValues}
115 onResetValues={idpRefSettingsData.resetValues}
116 pathname={pathname}
117 />
118 </Tab>
119 </Tabs>
120 </PageSection>
121 </>
122 );
123 };
124
125 export default IdpReferencesTabs;