From 15ec98539914624b7374bc409665a83da58c45aa Mon Sep 17 00:00:00 2001 From: Yi Cai Date: Tue, 28 May 2024 15:01:52 -0400 Subject: [PATCH 1/3] fix(rbac): add proper empty page for RBAC plugin Signed-off-by: Yi Cai --- plugins/rbac/src/components/Router.tsx | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/plugins/rbac/src/components/Router.tsx b/plugins/rbac/src/components/Router.tsx index f487586f4b..4560c8da2a 100644 --- a/plugins/rbac/src/components/Router.tsx +++ b/plugins/rbac/src/components/Router.tsx @@ -1,6 +1,7 @@ import React from 'react'; import { Route, Routes } from 'react-router-dom'; +import { ErrorPage } from '@backstage/core-components'; import { configApiRef, useApi } from '@backstage/core-plugin-api'; import { RequirePermission } from '@backstage/plugin-permission-react'; @@ -25,7 +26,13 @@ export const Router = ({ useHeader = true }: { useHeader?: boolean }) => { const isRBACPluginEnabled = config.getOptionalBoolean('permission.enabled'); if (!isRBACPluginEnabled) { - return null; + return ( + + ); } return ( From aea66bd560ae325d18f50064ef5ac2b14ebb45d7 Mon Sep 17 00:00:00 2001 From: Yi Cai Date: Tue, 28 May 2024 15:16:37 -0400 Subject: [PATCH 2/3] Updated unite test Signed-off-by: Yi Cai --- plugins/rbac/src/components/Router.test.tsx | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/plugins/rbac/src/components/Router.test.tsx b/plugins/rbac/src/components/Router.test.tsx index ce4fb2acd5..830aceb646 100644 --- a/plugins/rbac/src/components/Router.test.tsx +++ b/plugins/rbac/src/components/Router.test.tsx @@ -32,6 +32,10 @@ jest.mock('./CreateRole/EditRolePage', () => ({ EditRolePage: () =>
EditRole
, })); +jest.mock('@backstage/core-components', () => ({ + ErrorPage: jest.fn().mockImplementation(() =>
Mocked ErrorPage
), +})); + jest.mock('@backstage/plugin-permission-react', () => ({ RequirePermission: jest .fn() @@ -67,6 +71,17 @@ describe('Router component', () => { expect(screen.queryByText('RBAC')).not.toBeInTheDocument(); }); + it('should render ErrorPage when rbac-backend plugin is disabled', () => { + configMock.getOptionalBoolean.mockReturnValueOnce(false); + render( + + + , + ); + + expect(screen.queryByText('Mocked ErrorPage')).toBeInTheDocument(); + }); + it('renders RoleOverviewPage when path matches roleRouteRef', () => { render( From 89338ecfeed11792f05e7302df4b6c4057dfe795 Mon Sep 17 00:00:00 2001 From: Yi Cai Date: Thu, 30 May 2024 23:22:55 -0400 Subject: [PATCH 3/3] Updated error message Signed-off-by: Yi Cai --- plugins/rbac/src/components/Router.tsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugins/rbac/src/components/Router.tsx b/plugins/rbac/src/components/Router.tsx index 4560c8da2a..396d4c81f6 100644 --- a/plugins/rbac/src/components/Router.tsx +++ b/plugins/rbac/src/components/Router.tsx @@ -29,8 +29,8 @@ export const Router = ({ useHeader = true }: { useHeader?: boolean }) => { return ( ); }