Debian Codegraph @

install/freeipa-webui/src/pages/Trusts/TrustsTabs.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 { useTrustsSettingsData } from "src/hooks/useTrustsSettingsData";
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 TrustsSettings from "src/pages/Trusts/TrustsSettings";
18 import { CnParams, useSafeParams } from "src/utils/paramsUtils";
19
20 const TrustsTabs = ({ section }: { section: string }) => {
21 const { cn } = useSafeParams<CnParams>(["cn"]);
22 const navigate = useNavigate();
23 const pathname = "trusts";
24
25 // Data loaded from the API
26 const trustsSettingsData = useTrustsSettingsData(cn);
27
28 const handleTabClick = (
29 _event: React.MouseEvent<HTMLElement, MouseEvent>,
30 tabIndex: number | string
31 ) => {
32 if (tabIndex === "settings") {
33 navigate("/" + pathname + "/" + cn);
34 } else if (tabIndex === "trusted-domains") {
35 navigate("/" + pathname + "/" + cn + "/trusted-domains");
36 }
37 };
38
39 const breadcrumbItems: BreadCrumbItem[] = React.useMemo(
40 () => [
41 {
42 name: "Trusts",
43 url: URL_PREFIX + "/" + pathname,
44 },
45 ],
46 [pathname]
47 );
48
49 // Handling of the API data
50 if (trustsSettingsData.isLoading || !trustsSettingsData.trust) {
51 return <DataSpinner />;
52 }
53
54 // Show the 'NotFound' page if the trust is not found
55 if (
56 !trustsSettingsData.isLoading &&
57 (!trustsSettingsData.trust || trustsSettingsData.trust.cn === "")
58 ) {
59 return <NotFound />;
60 }
61
62 // Return component
63 return (
64 <>
65 <PageSection hasBodyWrapper={false}>
66 <BreadCrumb breadcrumbItems={breadcrumbItems} />
67 </PageSection>
68 <PageSection hasBodyWrapper={true}>
69 <TitleLayout id={cn} preText="Trust:" text={cn} headingLevel="h1" />
70 <Tabs
71 activeKey={section}
72 onSelect={handleTabClick}
73 variant="secondary"
74 isBox
75 className="pf-v6-u-ml-lg"
76 mountOnEnter
77 unmountOnExit
78 >
79 <Tab
80 eventKey="settings"
81 name="settings-details"
82 title={<TabTitleText>Settings</TabTitleText>}
83 data-cy="trusts-tab-settings"
84 >
85 <TrustsSettings
86 trust={trustsSettingsData.trust}
87 originalTrust={trustsSettingsData.originalTrust}
88 metadata={trustsSettingsData.metadata}
89 onTrustChange={trustsSettingsData.setTrust}
90 onRefresh={trustsSettingsData.refetch}
91 isModified={trustsSettingsData.modified}
92 isDataLoading={trustsSettingsData.isLoading}
93 modifiedValues={trustsSettingsData.modifiedValues}
94 onResetValues={trustsSettingsData.resetValues}
95 pathname={pathname}
96 />
97 </Tab>
98 </Tabs>
99 </PageSection>
100 </>
101 );
102 };
103
104 export default TrustsTabs;