-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0cbadd7
commit cc9aae7
Showing
6 changed files
with
233 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
187 changes: 187 additions & 0 deletions
187
src/smart-components/access-management/UserDetailsDrawer.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,187 @@ | ||
import { | ||
Drawer, | ||
DrawerActions, | ||
DrawerCloseButton, | ||
DrawerContent, | ||
DrawerContentBody, | ||
DrawerHead, | ||
DrawerPanelContent, | ||
Icon, | ||
Popover, | ||
Tab, | ||
TabTitleText, | ||
Tabs, | ||
Text, | ||
TextContent, | ||
Title, | ||
} from '@patternfly/react-core'; | ||
import React, { useCallback, useEffect } from 'react'; | ||
import { User } from '../../redux/reducers/user-reducer'; | ||
import { OutlinedQuestionCircleIcon } from '@patternfly/react-icons'; | ||
import { DataView, DataViewTable } from '@patternfly/react-data-view'; | ||
import { useDispatch, useSelector } from 'react-redux'; | ||
import { RBACStore } from '../../redux/store'; | ||
import { fetchGroups } from '../../redux/actions/group-actions'; | ||
import { mappedProps } from '../../helpers/shared/helpers'; | ||
import { fetchRoles } from '../../redux/actions/role-actions'; | ||
import { useIntl } from 'react-intl'; | ||
import messages from '../../Messages'; | ||
|
||
interface UserGroupsViewProps { | ||
userId: string; | ||
ouiaId: string; | ||
} | ||
|
||
const UserGroupsView: React.FunctionComponent<UserGroupsViewProps> = ({ userId, ouiaId }) => { | ||
const dispatch = useDispatch(); | ||
const intl = useIntl(); | ||
const columns: string[] = [intl.formatMessage(messages.userGroup), intl.formatMessage(messages.users)]; | ||
|
||
const { groups } = useSelector((state: RBACStore) => ({ | ||
groups: state.groupReducer?.groups?.data || [], | ||
})); | ||
|
||
const fetchData = useCallback( | ||
(apiProps: { username: string }) => { | ||
const { username } = apiProps; | ||
dispatch(fetchGroups({ ...mappedProps({ username }), usesMetaInURL: true, system: false })); | ||
}, | ||
[dispatch] | ||
); | ||
|
||
useEffect(() => { | ||
fetchData({ | ||
username: userId, | ||
}); | ||
}, [fetchData, userId]); | ||
|
||
const rows = groups.map((group: any) => ({ | ||
row: [group.name, group.principalCount || '?'], // TODO: principalCount is not available from API? | ||
})); | ||
|
||
return ( | ||
<div className="pf-v5-u-pt-md"> | ||
<DataView ouiaId={ouiaId}> | ||
<DataViewTable variant="compact" aria-label="UserGroupsView" ouiaId={`${ouiaId}-table`} columns={columns} rows={rows} /> | ||
</DataView> | ||
</div> | ||
); | ||
}; | ||
|
||
interface UserRolesViewProps { | ||
userId: string; | ||
ouiaId: string; | ||
} | ||
|
||
const UserRolesView: React.FunctionComponent<UserRolesViewProps> = ({ userId, ouiaId }) => { | ||
const dispatch = useDispatch(); | ||
const intl = useIntl(); | ||
const USER_ROLES_COLUMNS: string[] = [ | ||
intl.formatMessage(messages.roles), | ||
intl.formatMessage(messages.userGroup), | ||
intl.formatMessage(messages.workspace), | ||
]; | ||
|
||
const { roles } = useSelector((state: RBACStore) => ({ | ||
roles: state.roleReducer?.roles?.data || [], | ||
})); | ||
|
||
const fetchData = useCallback( | ||
(apiProps: { username: string }) => { | ||
const { username } = apiProps; | ||
dispatch(fetchRoles({ ...mappedProps({ username }), usesMetaInURL: true, system: false })); | ||
}, | ||
[dispatch] | ||
); | ||
|
||
useEffect(() => { | ||
fetchData({ | ||
username: userId, | ||
}); | ||
}, [fetchData, userId]); | ||
|
||
const rows = roles.map((role: any) => ({ | ||
row: [role.name, role.display_name, '?'], // TODO: Update once API provides workspace data | ||
})); | ||
|
||
return ( | ||
<div className="pf-v5-u-pt-md"> | ||
<DataView ouiaId={ouiaId}> | ||
<DataViewTable variant="compact" aria-label="UserRolesView" ouiaId={`${ouiaId}-table`} columns={USER_ROLES_COLUMNS} rows={rows} /> | ||
</DataView> | ||
</div> | ||
); | ||
}; | ||
|
||
interface UserDetailsProps { | ||
focusedUser?: User; | ||
onClose: () => void; | ||
ouiaId: string; | ||
} | ||
|
||
export const UserDetailsDrawerContent: React.FunctionComponent<UserDetailsProps> = ({ focusedUser, onClose, ouiaId }) => { | ||
const [activeTabKey, setActiveTabKey] = React.useState<string | number>(0); | ||
const intl = useIntl(); | ||
|
||
return ( | ||
<DrawerPanelContent> | ||
<DrawerHead> | ||
<Title headingLevel="h2">{`${focusedUser?.first_name} ${focusedUser?.last_name}`}</Title> | ||
<TextContent> | ||
<Text>{focusedUser?.email}</Text> | ||
</TextContent> | ||
<DrawerActions> | ||
<DrawerCloseButton onClick={() => onClose()} /> | ||
</DrawerActions> | ||
</DrawerHead> | ||
<Tabs isFilled activeKey={activeTabKey} onSelect={(_, tabIndex) => setActiveTabKey(tabIndex)}> | ||
<Tab eventKey={0} title={intl.formatMessage(messages.userGroups)}> | ||
{focusedUser && <UserGroupsView ouiaId={`${ouiaId}-user-groups-view`} userId={focusedUser.username} />} | ||
</Tab> | ||
<Tab | ||
eventKey={1} | ||
title={ | ||
<TabTitleText> | ||
{intl.formatMessage(messages.assignedRoles)} | ||
<Popover | ||
triggerAction="hover" | ||
position="top-end" | ||
headerContent={intl.formatMessage(messages.assignedRoles)} | ||
bodyContent={intl.formatMessage(messages.assignedRolesDescription)} | ||
> | ||
<Icon className="pf-v5-u-pl-sm" isInline> | ||
<OutlinedQuestionCircleIcon /> | ||
</Icon> | ||
</Popover> | ||
</TabTitleText> | ||
} | ||
> | ||
{focusedUser && <UserRolesView userId={focusedUser.username} ouiaId={`${ouiaId}-assigned-users-view`} />} | ||
</Tab> | ||
</Tabs> | ||
</DrawerPanelContent> | ||
); | ||
}; | ||
|
||
interface DetailDrawerProps { | ||
isOpen: boolean; | ||
focusedUser?: User; | ||
onClose: () => void; | ||
children: React.ReactNode; | ||
ouiaId: string; | ||
} | ||
|
||
export const UserDetailsDrawer: React.FunctionComponent<DetailDrawerProps> = ({ isOpen, focusedUser, onClose, children, ouiaId }) => { | ||
const drawerRef = React.useRef<HTMLDivElement>(null); | ||
|
||
return ( | ||
<Drawer isExpanded={isOpen} onExpand={() => drawerRef.current?.focus()} data-ouia-component-id={ouiaId}> | ||
<DrawerContent | ||
panelContent={<UserDetailsDrawerContent ouiaId={`${ouiaId}-panel-content`} focusedUser={focusedUser} onClose={onClose} />} | ||
ref={drawerRef} | ||
> | ||
<DrawerContentBody hasPadding>{children}</DrawerContentBody> | ||
</DrawerContent> | ||
</Drawer> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters