-
Notifications
You must be signed in to change notification settings - Fork 363
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: [UIE-8131] - RBAC-1: Routes, Menu, Feature Flag
- Loading branch information
1 parent
4b3fe8a
commit 703a31b
Showing
13 changed files
with
303 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@linode/manager": Added | ||
--- | ||
|
||
New routes for iam, feature flag and menu item ([#11310](https://github.com/linode/manager/pull/11310)) |
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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
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,86 @@ | ||
import * as React from 'react'; | ||
import { matchPath } from 'react-router-dom'; | ||
|
||
import { DocumentTitleSegment } from 'src/components/DocumentTitle'; | ||
import { LandingHeader } from 'src/components/LandingHeader'; | ||
import { SuspenseLoader } from 'src/components/SuspenseLoader'; | ||
import { SafeTabPanel } from 'src/components/Tabs/SafeTabPanel'; | ||
import { TabLinkList } from 'src/components/Tabs/TabLinkList'; | ||
import { TabPanels } from 'src/components/Tabs/TabPanels'; | ||
import { Tabs } from 'src/components/Tabs/Tabs'; | ||
|
||
import type { RouteComponentProps } from 'react-router-dom'; | ||
type Props = RouteComponentProps<{}>; | ||
|
||
const Users = React.lazy(() => | ||
import('./Users/Users').then((module) => ({ | ||
default: module.UsersLanding, | ||
})) | ||
); | ||
|
||
const Roles = React.lazy(() => | ||
import('./Roles/Roles').then((module) => ({ | ||
default: module.RolesLanding, | ||
})) | ||
); | ||
|
||
const IdentityAccessManagementLanding = React.memo((props: Props) => { | ||
const tabs = [ | ||
{ | ||
routeName: `${props.match.url}/users`, | ||
title: 'Users', | ||
}, | ||
{ | ||
routeName: `${props.match.url}/roles`, | ||
title: 'Roles', | ||
}, | ||
]; | ||
|
||
const navToURL = (index: number) => { | ||
props.history.push(tabs[index].routeName); | ||
}; | ||
|
||
const getDefaultTabIndex = () => { | ||
const tabChoice = tabs.findIndex((tab) => | ||
Boolean(matchPath(tab.routeName, { path: location.pathname })) | ||
); | ||
|
||
return tabChoice; | ||
}; | ||
|
||
const landingHeaderProps = { | ||
breadcrumbProps: { | ||
pathname: '/iam', | ||
}, | ||
docsLink: | ||
'https://www.linode.com/docs/platform/identity-access-management/', | ||
entity: 'Identity and Access', | ||
title: 'Identity and Access', | ||
}; | ||
|
||
let idx = 0; | ||
|
||
return ( | ||
<> | ||
<DocumentTitleSegment segment="Identity and Access" /> | ||
<LandingHeader {...landingHeaderProps} /> | ||
|
||
<Tabs index={getDefaultTabIndex()} onChange={navToURL}> | ||
<TabLinkList tabs={tabs} /> | ||
|
||
<React.Suspense fallback={<SuspenseLoader />}> | ||
<TabPanels> | ||
<SafeTabPanel index={idx}> | ||
<Users /> | ||
</SafeTabPanel> | ||
<SafeTabPanel index={++idx}> | ||
<Roles /> | ||
</SafeTabPanel> | ||
</TabPanels> | ||
</React.Suspense> | ||
</Tabs> | ||
</> | ||
); | ||
}); | ||
|
||
export default IdentityAccessManagementLanding; |
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,9 @@ | ||
import React from 'react'; | ||
|
||
export const RolesLanding = () => { | ||
return ( | ||
<> | ||
<p>Roles Table - UIE-8142 </p> | ||
</> | ||
); | ||
}; |
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,4 @@ | ||
// Various constants for the IAM package | ||
|
||
// Labels | ||
export const IAM_LABEL = 'Identity and Access'; |
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,18 @@ | ||
import { useFlags } from 'src/hooks/useFlags'; | ||
|
||
/** | ||
* Hook to determine if the IAM feature should be visible to the user. | ||
* Based on the user's account capability and the feature flag. | ||
* | ||
* @returns {boolean} - Whether the IAM feature is enabled for the current user. | ||
*/ | ||
export const useIsIAMEnabled = () => { | ||
const flags = useFlags(); | ||
|
||
const isIAMEnabled = flags.iam?.enabled; | ||
|
||
return { | ||
isIAMEnabled, | ||
isIAMBeta: flags.iam?.beta, | ||
}; | ||
}; |
83 changes: 83 additions & 0 deletions
83
packages/manager/src/features/IAM/Users/UserDetailsLanding.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,83 @@ | ||
import React from 'react'; | ||
import { | ||
useHistory, | ||
useLocation, | ||
useParams, | ||
matchPath, | ||
} from 'react-router-dom'; | ||
import { LandingHeader } from 'src/components/LandingHeader'; | ||
import { SafeTabPanel } from 'src/components/Tabs/SafeTabPanel'; | ||
import { TabLinkList } from 'src/components/Tabs/TabLinkList'; | ||
import { TabPanels } from 'src/components/Tabs/TabPanels'; | ||
import { Tabs } from 'src/components/Tabs/Tabs'; | ||
import { IAM_LABEL } from '../Shared/constants'; | ||
|
||
export const UserDetailsLanding = () => { | ||
const { username } = useParams<{ username: string }>(); | ||
const location = useLocation(); | ||
const history = useHistory(); | ||
|
||
const tabs = [ | ||
{ | ||
routeName: `/iam/users/${username}/details`, | ||
title: 'User Details', | ||
}, | ||
{ | ||
routeName: `/iam/users/${username}/roles`, | ||
title: 'Assigned Roles', | ||
}, | ||
{ | ||
routeName: `/iam/users/${username}/resources`, | ||
title: 'Assigned Resources', | ||
}, | ||
]; | ||
|
||
const navToURL = (index: number) => { | ||
history.push(tabs[index].routeName); | ||
}; | ||
|
||
const getDefaultTabIndex = () => { | ||
const tabChoice = tabs.findIndex((tab) => | ||
Boolean(matchPath(tab.routeName, { path: location.pathname })) | ||
); | ||
|
||
return tabChoice; | ||
}; | ||
|
||
let idx = 0; | ||
|
||
return ( | ||
<> | ||
<LandingHeader | ||
breadcrumbProps={{ | ||
crumbOverrides: [ | ||
{ | ||
label: IAM_LABEL, | ||
position: 1, | ||
}, | ||
], | ||
labelOptions: { | ||
noCap: true, | ||
}, | ||
pathname: location.pathname, | ||
}} | ||
removeCrumbX={4} | ||
title={username} | ||
/> | ||
<Tabs index={getDefaultTabIndex()} onChange={navToURL}> | ||
<TabLinkList tabs={tabs} /> | ||
<TabPanels> | ||
<SafeTabPanel index={idx}> | ||
<p>user details - UIE-8137</p> | ||
</SafeTabPanel> | ||
<SafeTabPanel index={++idx}> | ||
<p>UIE-8138 - User Roles - Assigned Roles Table</p> | ||
</SafeTabPanel> | ||
<SafeTabPanel index={++idx}> | ||
<p>Resources</p> | ||
</SafeTabPanel> | ||
</TabPanels> | ||
</Tabs> | ||
</> | ||
); | ||
}; |
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,34 @@ | ||
import React from 'react'; | ||
import { useHistory } from 'react-router-dom'; | ||
import { Action, ActionMenu } from 'src/components/ActionMenu/ActionMenu'; | ||
import { useProfile } from 'src/queries/profile/profile'; | ||
|
||
export const UsersLanding = () => { | ||
const history = useHistory(); | ||
const { data: profile } = useProfile(); | ||
|
||
const username = profile?.username; | ||
|
||
const actions: Action[] = [ | ||
{ | ||
onClick: () => { | ||
history.push(`/iam/users/${username}/details`); | ||
}, | ||
title: 'View User Details', | ||
}, | ||
{ | ||
onClick: () => { | ||
history.push(`/iam/users/${username}/roles`); | ||
}, | ||
title: 'View User Roles', | ||
}, | ||
]; | ||
|
||
return ( | ||
<> | ||
<p>Users Table - UIE-8136 </p> | ||
|
||
<ActionMenu actionsList={actions} ariaLabel={`Action menu for user`} /> | ||
</> | ||
); | ||
}; |
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,34 @@ | ||
import * as React from 'react'; | ||
import { Redirect, Route, Switch } from 'react-router-dom'; | ||
|
||
import { ProductInformationBanner } from 'src/components/ProductInformationBanner/ProductInformationBanner'; | ||
import { SuspenseLoader } from 'src/components/SuspenseLoader'; | ||
|
||
import type { RouteComponentProps } from 'react-router-dom'; | ||
|
||
const IAMLanding = React.lazy(() => import('./IAMLanding')); | ||
|
||
const UserDetails = React.lazy(() => | ||
import('./Users/UserDetailsLanding').then((module) => ({ | ||
default: module.UserDetailsLanding, | ||
})) | ||
); | ||
|
||
type CombinedProps = RouteComponentProps; | ||
|
||
export const IdentityAccessManagement: React.FC<CombinedProps> = (props) => { | ||
const path = props.match.path; | ||
|
||
return ( | ||
<React.Suspense fallback={<SuspenseLoader />}> | ||
<ProductInformationBanner bannerLocation="Identity and Access Management" /> | ||
<Switch> | ||
<Route component={UserDetails} path={`${path}/users/:username/`} /> | ||
<Redirect exact from={path} to={`${path}/users`} /> | ||
<Route component={IAMLanding} path={`${path}`} /> | ||
</Switch> | ||
</React.Suspense> | ||
); | ||
}; | ||
|
||
export default IdentityAccessManagement; |