| 1 |
import React, { useState } from "react"; |
| 2 |
// PatternFly |
| 3 |
import { PageSection, Tabs, Tab, TabTitleText } from "@patternfly/react-core"; |
| 4 |
// Components |
| 5 |
import UserSettings from "src/components/UsersSections/UserSettings"; |
| 6 |
import DataSpinner from "src/components/layouts/DataSpinner"; |
| 7 |
import BreadCrumb, { BreadCrumbItem } from "src/components/layouts/BreadCrumb"; |
| 8 |
import TitleLayout from "src/components/layouts/TitleLayout"; |
| 9 |
import ContextualHelpPanel from "src/components/ContextualHelpPanel/ContextualHelpPanel"; |
| 10 |
// Hooks |
| 11 |
import { useUserSettings } from "src/hooks/useUserSettingsData"; |
| 12 |
// Redux |
| 13 |
import { useAppDispatch } from "src/store/hooks"; |
| 14 |
import { updateBreadCrumbPath } from "src/store/Global/routes-slice"; |
| 15 |
// Navigation |
| 16 |
import { URL_PREFIX } from "src/navigation/NavRoutes"; |
| 17 |
import { NotFound } from "src/components/errors/PageErrors"; |
| 18 |
import { UidParams, useSafeParams } from "src/utils/paramsUtils"; |
| 19 |
|
| 20 |
const PreservedUsersTabs = () => { |
| 21 |
// Get location (React Router DOM) and get state data |
| 22 |
const { uid } = useSafeParams<UidParams>(["uid"]); |
| 23 |
const dispatch = useAppDispatch(); |
| 24 |
|
| 25 |
const [breadcrumbItems, setBreadcrumbItems] = React.useState< |
| 26 |
BreadCrumbItem[] |
| 27 |
>([]); |
| 28 |
|
| 29 |
React.useEffect(() => { |
| 30 |
// Update breadcrumb route |
| 31 |
const currentPath: BreadCrumbItem[] = [ |
| 32 |
{ |
| 33 |
name: "Preserved users", |
| 34 |
url: URL_PREFIX + "/preserved-users", |
| 35 |
}, |
| 36 |
{ |
| 37 |
name: uid, |
| 38 |
url: URL_PREFIX + "/preserved-users/" + uid, |
| 39 |
isActive: true, |
| 40 |
}, |
| 41 |
]; |
| 42 |
setBreadcrumbItems(currentPath); |
| 43 |
setActiveTabKey(0); |
| 44 |
dispatch(updateBreadCrumbPath(currentPath)); |
| 45 |
}, [uid]); |
| 46 |
|
| 47 |
// Contextual links panel |
| 48 |
const [fromPageSelected, setFromPageSelected] = React.useState( |
| 49 |
"preserved-users-settings" |
| 50 |
); |
| 51 |
const [isContextualPanelExpanded, setIsContextualPanelExpanded] = |
| 52 |
React.useState(false); |
| 53 |
|
| 54 |
const changeFromPage = (fromPage: string) => { |
| 55 |
setFromPageSelected(fromPage); |
| 56 |
}; |
| 57 |
|
| 58 |
const onOpenContextualPanel = () => { |
| 59 |
setIsContextualPanelExpanded(!isContextualPanelExpanded); |
| 60 |
}; |
| 61 |
|
| 62 |
const onCloseContextualPanel = () => { |
| 63 |
setIsContextualPanelExpanded(false); |
| 64 |
}; |
| 65 |
|
| 66 |
// Data loaded from DB |
| 67 |
const userSettingsData = useUserSettings(uid); |
| 68 |
|
| 69 |
// Tab |
| 70 |
const [activeTabKey, setActiveTabKey] = useState(0); |
| 71 |
|
| 72 |
const handleTabClick = ( |
| 73 |
_event: React.MouseEvent<HTMLElement, MouseEvent>, |
| 74 |
tabIndex: number | string |
| 75 |
) => { |
| 76 |
setActiveTabKey(tabIndex as number); |
| 77 |
}; |
| 78 |
|
| 79 |
if (userSettingsData.isLoading) { |
| 80 |
return <DataSpinner />; |
| 81 |
} |
| 82 |
|
| 83 |
// Show the 'NotFound' page if the user is not found |
| 84 |
if ( |
| 85 |
!userSettingsData.isLoading && |
| 86 |
Object.keys(userSettingsData.user).length === 0 |
| 87 |
) { |
| 88 |
return <NotFound />; |
| 89 |
} |
| 90 |
|
| 91 |
return ( |
| 92 |
<> |
| 93 |
<ContextualHelpPanel |
| 94 |
fromPage={fromPageSelected} |
| 95 |
isExpanded={isContextualPanelExpanded} |
| 96 |
onClose={onCloseContextualPanel} |
| 97 |
> |
| 98 |
<PageSection hasBodyWrapper={false}> |
| 99 |
<BreadCrumb breadcrumbItems={breadcrumbItems} /> |
| 100 |
<TitleLayout |
| 101 |
id={uid} |
| 102 |
preText="Preserved user:" |
| 103 |
text={uid} |
| 104 |
headingLevel="h1" |
| 105 |
/> |
| 106 |
</PageSection> |
| 107 |
<PageSection hasBodyWrapper={false} type="tabs" isFilled> |
| 108 |
<Tabs |
| 109 |
activeKey={activeTabKey} |
| 110 |
onSelect={handleTabClick} |
| 111 |
variant="secondary" |
| 112 |
isBox |
| 113 |
className="pf-v6-u-ml-lg" |
| 114 |
mountOnEnter |
| 115 |
unmountOnExit |
| 116 |
> |
| 117 |
<Tab |
| 118 |
eventKey={0} |
| 119 |
name="details" |
| 120 |
title={<TabTitleText>Settings</TabTitleText>} |
| 121 |
> |
| 122 |
<UserSettings |
| 123 |
originalUser={userSettingsData.originalUser} |
| 124 |
user={userSettingsData.user} |
| 125 |
metadata={userSettingsData.metadata} |
| 126 |
pwPolicyData={userSettingsData.pwPolicyData} |
| 127 |
krbPolicyData={userSettingsData.krbtPolicyData} |
| 128 |
certData={userSettingsData.certData} |
| 129 |
onUserChange={userSettingsData.setUser} |
| 130 |
isDataLoading={userSettingsData.isFetching} |
| 131 |
onRefresh={userSettingsData.refetch} |
| 132 |
isModified={userSettingsData.modified} |
| 133 |
onResetValues={userSettingsData.resetValues} |
| 134 |
modifiedValues={userSettingsData.modifiedValues} |
| 135 |
radiusProxyData={userSettingsData.radiusServers} |
| 136 |
idpData={userSettingsData.idpServers} |
| 137 |
from="preserved-users" |
| 138 |
changeFromPage={changeFromPage} |
| 139 |
onOpenContextualPanel={onOpenContextualPanel} |
| 140 |
/> |
| 141 |
</Tab> |
| 142 |
</Tabs> |
| 143 |
</PageSection> |
| 144 |
</ContextualHelpPanel> |
| 145 |
</> |
| 146 |
); |
| 147 |
}; |
| 148 |
|
| 149 |
export default PreservedUsersTabs; |