-
Notifications
You must be signed in to change notification settings - Fork 80
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: In libraries, allow opening the editor for text (html) components
- Loading branch information
1 parent
dde8385
commit ac85a40
Showing
7 changed files
with
136 additions
and
44 deletions.
There are no files selected for viewing
This file contains 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 was deleted.
Oops, something went wrong.
This file contains 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 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 |
---|---|---|
@@ -0,0 +1,42 @@ | ||
/* eslint-disable react/require-default-props */ | ||
import React from 'react'; | ||
import { useParams } from 'react-router-dom'; | ||
import { getConfig } from '@edx/frontend-platform'; | ||
|
||
import EditorPage from './EditorPage'; | ||
|
||
interface Props { | ||
/** Course ID or Library ID */ | ||
learningContextId: string; | ||
/** Event handler for when user cancels out of the editor page */ | ||
onClose?: () => void; | ||
/** Event handler for when user saves changes using an editor */ | ||
onSave?: () => (newData: Record<string, any>) => void; | ||
} | ||
|
||
const EditorContainer: React.FC<Props> = ({ | ||
learningContextId, | ||
onClose, | ||
onSave, | ||
}) => { | ||
const { blockType, blockId } = useParams(); | ||
if (blockType === undefined || blockId === undefined) { | ||
// This shouldn't be possible; it's just here to satisfy the type checker. | ||
return <div>Error: missing URL parameters</div>; | ||
} | ||
return ( | ||
<div className="editor-page"> | ||
<EditorPage | ||
courseId={learningContextId} | ||
blockType={blockType} | ||
blockId={blockId} | ||
studioEndpointUrl={getConfig().STUDIO_BASE_URL} | ||
lmsEndpointUrl={getConfig().LMS_BASE_URL} | ||
onClose={onClose} | ||
returnFunction={onSave} | ||
/> | ||
</div> | ||
); | ||
}; | ||
|
||
export default EditorContainer; |
This file contains 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,11 +1,58 @@ | ||
import React from 'react'; | ||
import { | ||
Route, | ||
Routes, | ||
useNavigate, | ||
useParams, | ||
} from 'react-router-dom'; | ||
import { PageWrap } from '@edx/frontend-platform/react'; | ||
import { useQueryClient } from '@tanstack/react-query'; | ||
|
||
import EditorContainer from '../editors/EditorContainer'; | ||
import LibraryAuthoringPage from './LibraryAuthoringPage'; | ||
import { LibraryProvider } from './common/context'; | ||
import { invalidateComponentData } from './data/apiHooks'; | ||
|
||
const LibraryLayout = () => { | ||
const { libraryId } = useParams(); | ||
const queryClient = useQueryClient(); | ||
|
||
if (libraryId === undefined) { | ||
throw new Error('Error: route is missing libraryId.'); // Should never happen | ||
} | ||
|
||
const navigate = useNavigate(); | ||
const goBack = React.useCallback(() => { | ||
if (window.history.length > 1) { | ||
navigate(-1); // go back | ||
} else { | ||
navigate(`/library/${libraryId}`); | ||
} | ||
// The following function is called only if changes are saved: | ||
return ({ id: usageKey }) => { | ||
// invalidate any queries that involve this XBlock: | ||
invalidateComponentData(queryClient, libraryId, usageKey); | ||
}; | ||
}, []); | ||
|
||
const LibraryLayout = () => ( | ||
<LibraryProvider> | ||
<LibraryAuthoringPage /> | ||
</LibraryProvider> | ||
); | ||
return ( | ||
<LibraryProvider> | ||
<Routes> | ||
<Route | ||
path="editor/:blockType/:blockId?" | ||
element={( | ||
<PageWrap> | ||
<EditorContainer learningContextId={libraryId} onClose={goBack} onSave={goBack} /> | ||
</PageWrap> | ||
)} | ||
/> | ||
<Route | ||
path="*" | ||
element={<LibraryAuthoringPage />} | ||
/> | ||
</Routes> | ||
</LibraryProvider> | ||
); | ||
}; | ||
|
||
export default LibraryLayout; |
This file contains 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 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