Skip to content

Commit

Permalink
fix: new library redirect
Browse files Browse the repository at this point in the history
  • Loading branch information
rpenido committed Jun 18, 2024
1 parent 7d6096e commit c63bc2f
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions src/studio-home/StudioHome.jsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React from 'react';
import React, { useCallback } from 'react';
import {
Button,
Container,
Expand All @@ -11,6 +11,7 @@ import { Add as AddIcon, Error } from '@openedx/paragon/icons';
import { injectIntl, intlShape } from '@edx/frontend-platform/i18n';
import { StudioFooter } from '@edx/frontend-component-footer';
import { getConfig, getPath } from '@edx/frontend-platform';
import { useLocation } from 'react-router-dom';

import { constructLibraryAuthoringURL } from '../utils';
import Loading from '../generic/Loading';
Expand All @@ -19,7 +20,7 @@ import Header from '../header';
import SubHeader from '../generic/sub-header/SubHeader';
import HomeSidebar from './home-sidebar';
import TabsSection from './tabs-section';
import { isMixedOrV2LibrariesMode } from './tabs-section/utils';
import { isMixedOrV1LibrariesMode, isMixedOrV2LibrariesMode } from './tabs-section/utils';
import OrganizationSection from './organization-section';
import VerifyEmailLayout from './verify-email-layout';
import CreateNewCourseForm from './create-new-course-form';
Expand All @@ -28,6 +29,8 @@ import { useStudioHome } from './hooks';
import AlertMessage from '../generic/alert-message';

const StudioHome = ({ intl }) => {
const location = useLocation();

const isPaginationCoursesEnabled = getConfig().ENABLE_HOME_PAGE_COURSE_API_V2;
const {
isLoadingPage,
Expand All @@ -47,6 +50,9 @@ const StudioHome = ({ intl }) => {

const libMode = getConfig().LIBRARY_MODE;

const v1LibraryTab = isMixedOrV1LibrariesMode(libMode) && location?.pathname.split('/').pop() === 'libraries-v1';
console.log('v1LibraryTab', v1LibraryTab);

Check warning on line 54 in src/studio-home/StudioHome.jsx

View workflow job for this annotation

GitHub Actions / tests

Unexpected console statement

const {
userIsActive,
studioShortName,
Expand All @@ -55,7 +61,7 @@ const StudioHome = ({ intl }) => {
redirectToLibraryAuthoringMfe,
} = studioHomeData;

function getHeaderButtons() {
const getHeaderButtons = useCallback(() => {
const headerButtons = [];

if (isFailedLoadingPage || !userIsActive) {
Expand Down Expand Up @@ -83,14 +89,15 @@ const StudioHome = ({ intl }) => {
}

let libraryHref = `${getConfig().STUDIO_BASE_URL}/home_library`;
if (isMixedOrV2LibrariesMode(libMode)) {
if (isMixedOrV2LibrariesMode(libMode) && !v1LibraryTab) {
libraryHref = libraryAuthoringMfeUrl && redirectToLibraryAuthoringMfe
? constructLibraryAuthoringURL(libraryAuthoringMfeUrl, 'create')
// Redirection to the placeholder is done in the MFE rather than
// through the backend i.e. redirection from cms, because this this will probably change,
// hence why we use the MFE's origin
: `${window.location.origin}${getPath(getConfig().PUBLIC_PATH)}library/create`;
}
console.log('libraryHref', libraryHref);

Check warning on line 100 in src/studio-home/StudioHome.jsx

View workflow job for this annotation

GitHub Actions / tests

Unexpected console statement

headerButtons.push(
<Button
Expand All @@ -106,7 +113,7 @@ const StudioHome = ({ intl }) => {
);

return headerButtons;
}
}, [location]);

const headerButtons = userIsActive ? getHeaderButtons() : [];
if (isLoadingPage && !isFiltered) {
Expand Down

3 comments on commit c63bc2f

@yusuf-musleh
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rpenido This is intended behavior when creating a new library in mixed or v2 mode based on the description in the github issue. The new library created should be a v2 library, regardless if pressed on from v2 tab or the legacy tab. A v1 (legacy) library should be created only when in "v1 only" mode.

@rpenido
Copy link
Member Author

@rpenido rpenido commented on c63bc2f Jun 19, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @yusuf-musleh! Thank you for pointing this!
Reverted here: efe0bed

Edit: I found out why I changed it!

@bradenmacdonald
Could you clarify this requirement for us? Should clicking "+ New library" in mixed mode while in the legacy tab create a v1 or v2 library?

We have the following conflict here

  1. Creating a new library from Studio Home should:
    a. Create a v2 library (if the mode is "v2 only" or "mixed")
    b. Create a v1 library (if the mode is "v1 only")

and here

Case 2: If the LIBRARY_MODE is mixed and the user is currently on the "Legacy Libraries" tab, it also redirects to the legacy Studio libraries page.

@bradenmacdonald
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rpenido @yusuf-musleh Sorry for the contradictory requirements. I think for now it's probably better to preserve the ability to create a v1 library even in mixed mode, so let's go with the second version for now: if mode is mixed and the legacy libraries tab is selected, redirect to the legacy studio page.

Please sign in to comment.