Skip to content

Commit 0972b7e

Browse files
authored
feat: [FC-0099] redirect to admin console MFE (#2570)
* feat: redirect to admin console MFE This PR redirects to admin console MFE if the URL is configured, to leverage the new experience of team management this is part of the AuthZ project https://github.com/openedx/openedx-authz/tree/main/docs/decisions * refactor: split the logic into 2 variables for readability
1 parent 15a728d commit 0972b7e

5 files changed

Lines changed: 31 additions & 4 deletions

File tree

.env

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,3 +48,4 @@ LIBRARY_UNSUPPORTED_BLOCKS="conditional,step-builder,problem-builder"
4848
# Fallback in local style files
4949
PARAGON_THEME_URLS={}
5050
COURSE_TEAM_SUPPORT_EMAIL=''
51+
ADMIN_CONSOLE_URL='http://localhost:2025/admin-console'

.env.development

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,3 +51,4 @@ LIBRARY_UNSUPPORTED_BLOCKS="conditional,step-builder,problem-builder"
5151
# Fallback in local style files
5252
PARAGON_THEME_URLS={}
5353
COURSE_TEAM_SUPPORT_EMAIL=''
54+
ADMIN_CONSOLE_URL='http://localhost:2025/admin-console'

src/index.jsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,7 @@ initialize({
178178
ENABLE_GRADING_METHOD_IN_PROBLEMS: process.env.ENABLE_GRADING_METHOD_IN_PROBLEMS === 'true',
179179
LIBRARY_UNSUPPORTED_BLOCKS: (process.env.LIBRARY_UNSUPPORTED_BLOCKS || 'conditional,step-builder,problem-builder').split(','),
180180
COURSE_TEAM_SUPPORT_EMAIL: process.env.COURSE_TEAM_SUPPORT_EMAIL || null,
181+
ADMIN_CONSOLE_URL: process.env.ADMIN_CONSOLE_URL || null,
181182
}, 'CourseAuthoringConfig');
182183
},
183184
},

src/library-authoring/library-info/LibraryInfo.test.tsx

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import type MockAdapter from 'axios-mock-adapter';
2+
import { mergeConfig } from '@edx/frontend-platform';
23

34
import {
45
fireEvent,
@@ -27,7 +28,7 @@ const {
2728
} = mockContentLibrary;
2829

2930
const render = (libraryId: string = mockLibraryId) => baseRender(<LibraryInfo />, {
30-
extraWrapper: ({ children }) => <LibraryProvider libraryId={libraryId}>{ children }</LibraryProvider>,
31+
extraWrapper: ({ children }) => <LibraryProvider libraryId={libraryId}>{children}</LibraryProvider>,
3132
});
3233

3334
let axiosMock: MockAdapter;
@@ -270,4 +271,13 @@ describe('<LibraryInfo />', () => {
270271
expect(publishButton).not.toBeInTheDocument();
271272
expect(discardButton).not.toBeInTheDocument();
272273
});
274+
275+
it('display a redirection button when ADMIN_CONSOLE_URL is setted', async () => {
276+
const ADMIN_CONSOLE_URL = 'http://localhost:2025/admin-console';
277+
mergeConfig({ ADMIN_CONSOLE_URL });
278+
render();
279+
const manageTeam = await screen.getByText('Manage Access');
280+
expect(manageTeam).toBeInTheDocument();
281+
expect(manageTeam).toHaveAttribute('href', `${ADMIN_CONSOLE_URL}/authz/libraries/${libraryData.id}`);
282+
});
273283
});

src/library-authoring/library-info/LibraryInfo.tsx

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { useCallback } from 'react';
2-
import { Button, Stack } from '@openedx/paragon';
2+
import { Button, Hyperlink, Stack } from '@openedx/paragon';
3+
import { getConfig } from '@edx/frontend-platform';
34
import { FormattedDate, useIntl } from '@edx/frontend-platform/i18n';
45

56
import messages from './messages';
@@ -10,9 +11,17 @@ import { SidebarActions, useSidebarContext } from '../common/context/SidebarCont
1011

1112
const LibraryInfo = () => {
1213
const intl = useIntl();
13-
const { libraryData, readOnly } = useLibraryContext();
14+
const { libraryId, libraryData, readOnly } = useLibraryContext();
1415
const { sidebarAction, setSidebarAction, resetSidebarAction } = useSidebarContext();
1516
const isLibraryTeamModalOpen = (sidebarAction === SidebarActions.ManageTeam);
17+
const adminConsoleUrl = getConfig().ADMIN_CONSOLE_URL;
18+
19+
// always show link to admin console MFE if it is being used
20+
const shouldShowAdminConsoleLink = !!adminConsoleUrl;
21+
22+
// if the admin console MFE isn't being used, show team modal button for non–read-only users
23+
const shouldShowTeamModalButton = !adminConsoleUrl && !readOnly;
24+
1625
const openLibraryTeamModal = useCallback(() => {
1726
setSidebarAction(SidebarActions.ManageTeam);
1827
}, [setSidebarAction]);
@@ -30,11 +39,16 @@ const LibraryInfo = () => {
3039
<span>
3140
{libraryData?.org}
3241
</span>
33-
{!readOnly && (
42+
{shouldShowTeamModalButton && (
3443
<Button variant="outline-primary" onClick={openLibraryTeamModal}>
3544
{intl.formatMessage(messages.libraryTeamButtonTitle)}
3645
</Button>
3746
)}
47+
{shouldShowAdminConsoleLink && (
48+
<Button as={Hyperlink} variant="outline-primary" destination={`${adminConsoleUrl}/authz/libraries/${libraryId}`} target="_blank">
49+
{intl.formatMessage(messages.libraryTeamButtonTitle)}
50+
</Button>
51+
)}
3852
</Stack>
3953
<Stack gap={3}>
4054
<span className="font-weight-bold">

0 commit comments

Comments
 (0)