-
Notifications
You must be signed in to change notification settings - Fork 210
feat: refactor library routes and add section/subsection tabs #2039
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
ChrisChV
merged 8 commits into
openedx:master
from
open-craft:rpenido/fal-4168/library-section-subsection-tabs
Jun 2, 2025
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
c6509a9
feat: refactor library routes and add section/subsection tabs
rpenido 950914d
fix: add section and subsection routes
rpenido 312ed20
fix: navigation on tab change
rpenido 9144414
fix: doesnt need to set values to context because it will be re-rendered
rpenido 3ccddc8
test: add test to check if we can change tabs while on ComponentPicke…
rpenido 636653d
fix: changing tabs while on component picker
rpenido a4a6d99
fix: component picker params for iframe
rpenido 3adac7d
fix: check container type
rpenido File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,13 +1,12 @@ | ||
| import { useCallback } from 'react'; | ||
| import React from 'react'; | ||
| import { | ||
| Outlet, | ||
| Route, | ||
| Routes, | ||
| useMatch, | ||
| useParams, | ||
| type PathMatch, | ||
| } from 'react-router-dom'; | ||
|
|
||
| import { BASE_ROUTE, ROUTES } from './routes'; | ||
| import { ROUTES } from './routes'; | ||
| import LibraryAuthoringPage from './LibraryAuthoringPage'; | ||
| import { LibraryProvider } from './common/context/LibraryContext'; | ||
| import { SidebarProvider } from './common/context/SidebarContext'; | ||
|
|
@@ -18,70 +17,65 @@ import { ComponentPicker } from './component-picker'; | |
| import { ComponentEditorModal } from './components/ComponentEditorModal'; | ||
| import { LibraryUnitPage } from './units'; | ||
|
|
||
| const LibraryLayout = () => { | ||
| const { libraryId } = useParams(); | ||
| const LibraryLayoutWrapper: React.FC<React.PropsWithChildren> = ({ children }) => { | ||
| const { libraryId, collectionId, unitId } = useParams(); | ||
|
|
||
| if (libraryId === undefined) { | ||
| // istanbul ignore next - This shouldn't be possible; it's just here to satisfy the type checker. | ||
| throw new Error('Error: route is missing libraryId.'); | ||
| } | ||
|
|
||
| // The top-level route is `${BASE_ROUTE}/*`, so match will always be non-null. | ||
| const matchCollection = useMatch(`${BASE_ROUTE}${ROUTES.COLLECTION}`) as PathMatch<'libraryId' | 'collectionId'> | null; | ||
| const collectionId = matchCollection?.params.collectionId; | ||
|
|
||
| // The top-level route is `${BASE_ROUTE}/*`, so match will always be non-null. | ||
| const matchUnit = useMatch(`${BASE_ROUTE}${ROUTES.UNIT}`) as PathMatch<'libraryId' | 'unitId'> | null; | ||
| const unitId = matchUnit?.params.unitId; | ||
|
|
||
| const context = useCallback((childPage) => ( | ||
| return ( | ||
| <LibraryProvider | ||
| /** We need to pass the collectionId or unitId as key to the LibraryProvider to force a re-render | ||
| * when we navigate to a collection or unit page. */ | ||
| /** NOTE: We need to pass the collectionId or unitId as key to the LibraryProvider to force a re-render | ||
| * when we navigate to a collection or unit page. This is necessary to make the back/forward navigation | ||
| * work correctly, as the LibraryProvider needs to rebuild the state from the URL. | ||
| * */ | ||
| key={collectionId || unitId} | ||
| libraryId={libraryId} | ||
| /** The component picker modal to use. We need to pass it as a reference instead of | ||
| /** NOTE: The component picker modal to use. We need to pass it as a reference instead of | ||
| * directly importing it to avoid the import cycle: | ||
| * ComponentPicker > LibraryAuthoringPage/LibraryCollectionPage > | ||
| * Sidebar > AddContent > ComponentPicker */ | ||
| componentPicker={ComponentPicker} | ||
| > | ||
| <SidebarProvider> | ||
| <> | ||
| {childPage} | ||
| <CreateCollectionModal /> | ||
| <CreateContainerModal /> | ||
| <ComponentEditorModal /> | ||
| </> | ||
| {children ?? <Outlet />} | ||
| <CreateCollectionModal /> | ||
| <CreateContainerModal /> | ||
| <ComponentEditorModal /> | ||
| </SidebarProvider> | ||
| </LibraryProvider> | ||
| ), [collectionId, unitId]); | ||
| ); | ||
| }; | ||
|
|
||
| return ( | ||
| <Routes> | ||
| const LibraryLayout = () => ( | ||
| <Routes> | ||
| <Route element={<LibraryLayoutWrapper />}> | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added the |
||
| {[ | ||
| ROUTES.HOME, | ||
| ROUTES.COMPONENT, | ||
| ROUTES.COMPONENTS, | ||
| ROUTES.COLLECTIONS, | ||
| ROUTES.UNITS, | ||
| ROUTES.SECTIONS, | ||
| ROUTES.SUBSECTIONS, | ||
| ].map((route) => ( | ||
| <Route | ||
| key={route} | ||
| path={route} | ||
| element={context(<LibraryAuthoringPage />)} | ||
| Component={LibraryAuthoringPage} | ||
| /> | ||
| ))} | ||
| <Route | ||
| path={ROUTES.COLLECTION} | ||
| element={context(<LibraryCollectionPage />)} | ||
| Component={LibraryCollectionPage} | ||
| /> | ||
| <Route | ||
| path={ROUTES.UNIT} | ||
| element={context(<LibraryUnitPage />)} | ||
| Component={LibraryUnitPage} | ||
| /> | ||
| </Routes> | ||
| ); | ||
| }; | ||
| </Route> | ||
| </Routes> | ||
| ); | ||
|
|
||
| export default LibraryLayout; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems to be a temporary/not used code commented