diff --git a/src/CourseAuthoringRoutes.jsx b/src/CourseAuthoringRoutes.jsx index 51599317e6..0c9d2a1680 100644 --- a/src/CourseAuthoringRoutes.jsx +++ b/src/CourseAuthoringRoutes.jsx @@ -88,7 +88,7 @@ const CourseAuthoringRoutes = () => { /> } + element={} /> { - const { blockType, blockId } = useParams(); - return ( -
- -
- ); -}; -EditorContainer.propTypes = { - courseId: PropTypes.string.isRequired, -}; - -export default EditorContainer; diff --git a/src/editors/EditorContainer.test.jsx b/src/editors/EditorContainer.test.jsx index a6186050ae..d57d14c6b1 100644 --- a/src/editors/EditorContainer.test.jsx +++ b/src/editors/EditorContainer.test.jsx @@ -10,7 +10,7 @@ jest.mock('react-router', () => ({ }), })); -const props = { courseId: 'cOuRsEId' }; +const props = { learningContextId: 'cOuRsEId' }; describe('Editor Container', () => { describe('snapshots', () => { diff --git a/src/editors/EditorContainer.tsx b/src/editors/EditorContainer.tsx new file mode 100644 index 0000000000..aaa8680b61 --- /dev/null +++ b/src/editors/EditorContainer.tsx @@ -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) => void; +} + +const EditorContainer: React.FC = ({ + 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
Error: missing URL parameters
; + } + return ( +
+ +
+ ); +}; + +export default EditorContainer; diff --git a/src/library-authoring/LibraryLayout.tsx b/src/library-authoring/LibraryLayout.tsx index 95d829606f..0ea21a670b 100644 --- a/src/library-authoring/LibraryLayout.tsx +++ b/src/library-authoring/LibraryLayout.tsx @@ -1,11 +1,54 @@ import React from 'react'; +import { + Route, + Routes, + useNavigate, + useParams, +} from 'react-router-dom'; +import { PageWrap } from '@edx/frontend-platform/react'; + +import EditorContainer from '../editors/EditorContainer'; import LibraryAuthoringPage from './LibraryAuthoringPage'; import { LibraryProvider } from './common/context'; -const LibraryLayout = () => ( - - - -); +const LibraryLayout = () => { + const { libraryId } = useParams(); + + 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 }) => { + // TODO:: invalidate any queries that involve ID. + }; + }, []); + + return ( + + + + + + )} + /> + } + /> + + + ); +}; export default LibraryLayout; diff --git a/src/library-authoring/components/ComponentCard.tsx b/src/library-authoring/components/ComponentCard.tsx index f460bc3ba4..aca18c4521 100644 --- a/src/library-authoring/components/ComponentCard.tsx +++ b/src/library-authoring/components/ComponentCard.tsx @@ -1,5 +1,5 @@ import React, { useContext, useMemo, useState } from 'react'; -import { useIntl } from '@edx/frontend-platform/i18n'; +import { FormattedMessage, useIntl } from '@edx/frontend-platform/i18n'; import { ActionRow, Card, @@ -10,6 +10,7 @@ import { Stack, } from '@openedx/paragon'; import { MoreVert } from '@openedx/paragon/icons'; +import { Link, useParams } from 'react-router-dom'; import { getItemIcon, getComponentStyleColor } from '../../generic/block-type-utils'; import { updateClipboard } from '../../generic/data/api'; @@ -27,6 +28,9 @@ type ComponentCardProps = { export const ComponentMenu = ({ usageKey }: { usageKey: string }) => { const intl = useIntl(); + // Get the block type (e.g. "html") from a lib block usage key string like "lb:org:lib:block_type:id" + const blockType: string = usageKey.split(':')[3] ?? 'unknown'; + const { libraryId } = useParams(); const { showToast } = useContext(ToastContext); const [clipboardBroadcastChannel] = useState(() => new BroadcastChannel(STUDIO_CLIPBOARD_CHANNEL)); const updateClipboardClick = () => { @@ -50,14 +54,22 @@ export const ComponentMenu = ({ usageKey }: { usageKey: string }) => { data-testid="component-card-menu-toggle" /> - - {intl.formatMessage(messages.menuEdit)} - + { + blockType === 'html' ? ( + + + + ) : ( + + + + ) + } - {intl.formatMessage(messages.menuCopyToClipboard)} + - {intl.formatMessage(messages.menuAddToCollection)} +