Skip to content

Commit

Permalink
feat: remove new library button if user does not have create access f…
Browse files Browse the repository at this point in the history
…or v1 libraries (#1216)
  • Loading branch information
kaustavb12 authored Sep 6, 2024
1 parent 3a61e84 commit 6b10fa7
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 25 deletions.
54 changes: 29 additions & 25 deletions src/studio-home/StudioHome.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,15 @@ const StudioHome = ({ intl }) => {
const libMode = getConfig().LIBRARY_MODE;

const v1LibraryTab = isMixedOrV1LibrariesMode(libMode) && location?.pathname.split('/').pop() === 'libraries-v1';
const showV2LibraryURL = isMixedOrV2LibrariesMode(libMode) && !v1LibraryTab;

const {
userIsActive,
studioShortName,
studioRequestEmail,
libraryAuthoringMfeUrl,
redirectToLibraryAuthoringMfe,
showNewLibraryButton,
} = studioHomeData;

const getHeaderButtons = useCallback(() => {
Expand Down Expand Up @@ -88,33 +90,35 @@ const StudioHome = ({ intl }) => {
);
}

const newLibraryClick = () => {
if (isMixedOrV2LibrariesMode(libMode) && !v1LibraryTab) {
if (libraryAuthoringMfeUrl && redirectToLibraryAuthoringMfe) {
// Library authoring MFE
window.open(constructLibraryAuthoringURL(libraryAuthoringMfeUrl, 'create'));
if (showNewLibraryButton || showV2LibraryURL) {
const newLibraryClick = () => {
if (showV2LibraryURL) {
if (libraryAuthoringMfeUrl && redirectToLibraryAuthoringMfe) {
// Library authoring MFE
window.open(constructLibraryAuthoringURL(libraryAuthoringMfeUrl, 'create'));
} else {
// Use course-authoring route
navigate('/library/create');
}
} else {
// Use course-authoring route
navigate('/library/create');
// Studio home library for legacy libraries
window.open(`${getConfig().STUDIO_BASE_URL}/home_library`);
}
} else {
// Studio home library for legacy libraries
window.open(`${getConfig().STUDIO_BASE_URL}/home_library`);
}
};

headerButtons.push(
<Button
variant="outline-primary"
iconBefore={AddIcon}
size="sm"
disabled={showNewCourseContainer}
onClick={newLibraryClick}
data-testid="new-library-button"
>
{intl.formatMessage(messages.addNewLibraryBtnText)}
</Button>,
);
};

headerButtons.push(
<Button
variant="outline-primary"
iconBefore={AddIcon}
size="sm"
disabled={showNewCourseContainer}
onClick={newLibraryClick}
data-testid="new-library-button"
>
{intl.formatMessage(messages.addNewLibraryBtnText)}
</Button>,
);
}

return headerButtons;
}, [location, userIsActive, isFailedLoadingPage]);
Expand Down
26 changes: 26 additions & 0 deletions src/studio-home/StudioHome.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,32 @@ describe('<StudioHome />', () => {
});
});

it('do not render new library button for "v1 only" mode if showNewLibraryButton is False', () => {
setConfig({
...getConfig(),
LIBRARY_MODE: 'v1 only',
});
useSelector.mockReturnValue({
...studioHomeMock,
showNewLibraryButton: false,
});
const { queryByTestId } = render(<RootWrapper />);
expect(queryByTestId('new-library-button')).not.toBeInTheDocument();
});

it('render new library button for "v2 only" mode even if showNewLibraryButton is False', () => {
setConfig({
...getConfig(),
LIBRARY_MODE: 'v2 only',
});
useSelector.mockReturnValue({
...studioHomeMock,
showNewLibraryButton: false,
});
const { queryByTestId } = render(<RootWrapper />);
expect(queryByTestId('new-library-button')).toBeInTheDocument();
});

it('should render create new course container', async () => {
useSelector.mockReturnValue({
...studioHomeMock,
Expand Down

0 comments on commit 6b10fa7

Please sign in to comment.