Skip to content

Commit

Permalink
feat(rbac): use relative links (janus-idp#1185)
Browse files Browse the repository at this point in the history
This change updates the links between components from absolute links to
relative links to better support being run from a different route root.
This commit also adds a property to help better integrate this plugin
into the backstage-showcase Administration page while still retaining
it's existing functionality.

Signed-off-by: Stan Lewis <[email protected]>
  • Loading branch information
gashcrumb authored Feb 8, 2024
1 parent d625cb2 commit 9fcab95
Show file tree
Hide file tree
Showing 9 changed files with 39 additions and 26 deletions.
2 changes: 1 addition & 1 deletion plugins/rbac/src/components/CreateRole/CreateRolePage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export const CreateRolePage = () => {
resourceRef={catalogEntityReadPermission.resourceType}
>
<Page themeId="tool">
<Header title="Create role" type="RBAC" typeLink="/rbac" />
<Header title="Create role" type="RBAC" typeLink=".." />
<Content>
<RoleForm
initialValues={initialValues}
Expand Down
2 changes: 1 addition & 1 deletion plugins/rbac/src/components/CreateRole/EditRolePage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export const EditRolePage = () => {
}
return (
<>
<Header title="Edit role" type="RBAC" typeLink="/rbac" />
<Header title="Edit role" type="RBAC" typeLink=".." />
<Content>
<RoleForm
initialValues={initialValues}
Expand Down
4 changes: 2 additions & 2 deletions plugins/rbac/src/components/CreateRole/RoleForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,9 @@ export const RoleForm = ({
if (step && roleName) {
const { kind, namespace, name } = getKindNamespaceName(roleName);

navigate(`/rbac/roles/${kind}/${namespace}/${name}`);
navigate(`../roles/${kind}/${namespace}/${name}`);
} else {
navigate('/rbac');
navigate('..');
}
};

Expand Down
2 changes: 1 addition & 1 deletion plugins/rbac/src/components/EditRole.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ const EditRole = ({
aria-label="Update"
disabled={disable}
title={tooltip || 'Edit Role'}
to={to || `/rbac/role/${kind}/${namespace}/${name}`}
to={to || `../role/${kind}/${namespace}/${name}`}
>
<EditIcon />
</IconButton>
Expand Down
45 changes: 29 additions & 16 deletions plugins/rbac/src/components/RbacPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,33 @@ import { policyEntityReadPermission } from '@janus-idp/backstage-plugin-rbac-com
import { DeleteDialogContextProvider } from './RolesList/DeleteDialogContext';
import { RolesList } from './RolesList/RolesList';

export const RbacPage = () => (
<RequirePermission
permission={policyEntityReadPermission}
resourceRef={policyEntityReadPermission.resourceType}
>
<Page themeId="tool">
<Header title="Administration" />
<DeleteDialogContextProvider>
<TabbedLayout>
<TabbedLayout.Route path="/rbac" title="RBAC">
<RolesList />
</TabbedLayout.Route>
</TabbedLayout>
</DeleteDialogContextProvider>
</Page>
</RequirePermission>
export const RbacPage = ({ useHeader = true }: { useHeader?: boolean }) => (
<>
{useHeader ? (
<RequirePermission
permission={policyEntityReadPermission}
resourceRef={policyEntityReadPermission.resourceType}
>
<Page themeId="tool">
<Header title="Administration" />
<DeleteDialogContextProvider>
<TabbedLayout>
<TabbedLayout.Route path="/rbac" title="RBAC">
<RolesList />
</TabbedLayout.Route>
</TabbedLayout>
</DeleteDialogContextProvider>
</Page>
</RequirePermission>
) : (
<RequirePermission
permission={policyEntityReadPermission}
resourceRef={policyEntityReadPermission.resourceType}
>
<DeleteDialogContextProvider>
<RolesList />
</DeleteDialogContextProvider>
</RequirePermission>
)}
</>
);
2 changes: 1 addition & 1 deletion plugins/rbac/src/components/RoleOverview/MembersCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ const getEditIcon = (isAllowed: boolean, roleName: string) => {
dataTestId={isAllowed ? 'update-members' : 'disable-update-members'}
roleName={roleName}
disable={!isAllowed}
to={`/rbac/role/${kind}/${namespace}/${name}?activeStep=${1}`}
to={`../../role/${kind}/${namespace}/${name}?activeStep=${1}`}
/>
);
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ const getEditIcon = (isAllowed: boolean, roleName: string) => {
dataTestId={isAllowed ? 'update-policies' : 'disable-update-policies'}
roleName={roleName}
disable={!isAllowed}
to={`/rbac/role/${kind}/${namespace}/${name}?activeStep=${2}`}
to={`../../role/${kind}/${namespace}/${name}?activeStep=${2}`}
/>
);
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export const RoleOverviewPage = () => {
<Header
title={`${roleKind}:${roleNamespace}/${roleName}`}
type="RBAC"
typeLink="/rbac"
typeLink=".."
/>
<TabbedLayout>
<TabbedLayout.Route path="" title="Overview">
Expand Down
4 changes: 2 additions & 2 deletions plugins/rbac/src/components/Router.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ import { ToastContextProvider } from './ToastContext';
*
* @public
*/
export const Router = () => (
export const Router = ({ useHeader = true }: { useHeader?: boolean }) => (
<ToastContextProvider>
<Routes>
<Route path="/" element={<RbacPage />} />
<Route path="/" element={<RbacPage useHeader={useHeader} />} />
<Route path={roleRouteRef.path} element={<RoleOverviewPage />} />
<Route
path={createRoleRouteRef.path}
Expand Down

0 comments on commit 9fcab95

Please sign in to comment.