Skip to content

Commit

Permalink
feat: Add AdvancedEditors with an iframe
Browse files Browse the repository at this point in the history
  • Loading branch information
ChrisChV committed Dec 12, 2024
1 parent 73490a5 commit c80b2fd
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 15 deletions.
18 changes: 18 additions & 0 deletions src/editors/AdvancedEditor.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { LibraryBlock } from '../library-authoring/LibraryBlock';
import { EditorModalWrapper } from './containers/EditorContainer';

interface AdvancedEditorProps {
usageKey: string,
onClose: Function | null,
}

const AdvancedEditor = ({ usageKey, onClose }: AdvancedEditorProps) => (
<EditorModalWrapper onClose={onClose as () => void}>
<LibraryBlock
usageKey={usageKey}
view="studio_view"
/>
</EditorModalWrapper>
);

export default AdvancedEditor;
17 changes: 12 additions & 5 deletions src/editors/Editor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,13 @@
// <EditorPage> as its parent, so they are tested together in EditorPage.test.tsx
import React from 'react';
import { useDispatch } from 'react-redux';
import { FormattedMessage } from '@edx/frontend-platform/i18n';

import messages from './messages';
import * as hooks from './hooks';

import supportedEditors from './supportedEditors';
import type { EditorComponent } from './EditorComponent';
import { useEditorContext } from './EditorContext';
import AdvancedEditor from './AdvancedEditor';

export interface Props extends EditorComponent {
blockType: string;
Expand Down Expand Up @@ -43,9 +42,17 @@ const Editor: React.FC<Props> = ({
const { fullScreen } = useEditorContext();

const EditorComponent = supportedEditors[blockType];
const innerEditor = (EditorComponent !== undefined)
? <EditorComponent {...{ onClose, returnFunction }} />
: <FormattedMessage {...messages.couldNotFindEditor} />;

if (EditorComponent === undefined && blockId) {
return (
<AdvancedEditor
usageKey={blockId}
onClose={onClose}
/>
);
}

const innerEditor = <EditorComponent {...{ onClose, returnFunction }} />;

if (fullScreen) {
return (
Expand Down
5 changes: 0 additions & 5 deletions src/editors/messages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,6 @@ import { defineMessages } from '@edx/frontend-platform/i18n';

const messages = defineMessages({

couldNotFindEditor: {
id: 'authoring.editorpage.selecteditor.error',
defaultMessage: 'Error: Could Not find Editor',
description: 'Error Message Dispayed When An unsopported Editor is desired in V2',
},
dropVideoFileHere: {
defaultMessage: 'Drag and drop video here or click to upload',
id: 'VideoUploadEditor.dropVideoFileHere',
Expand Down
12 changes: 10 additions & 2 deletions src/library-authoring/LibraryBlock/LibraryBlock.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ interface LibraryBlockProps {
onBlockNotification?: (event: { eventType: string; [key: string]: any }) => void;
usageKey: string;
version?: VersionSpec;
view?: string;
}
/**
* React component that displays an XBlock in a sandboxed IFrame.
Expand All @@ -20,7 +21,12 @@ interface LibraryBlockProps {
* cannot access things like the user's cookies, nor can it make GET/POST
* requests as the user. However, it is allowed to call any XBlock handlers.
*/
export const LibraryBlock = ({ onBlockNotification, usageKey, version }: LibraryBlockProps) => {
export const LibraryBlock = ({
onBlockNotification,
usageKey,
version,
view,
}: LibraryBlockProps) => {
const iframeRef = useRef<HTMLIFrameElement>(null);
const [iFrameHeight, setIFrameHeight] = useState(50);
const studioBaseUrl = getConfig().STUDIO_BASE_URL;
Expand Down Expand Up @@ -71,6 +77,8 @@ export const LibraryBlock = ({ onBlockNotification, usageKey, version }: Library

const queryStr = version ? `?version=${version}` : '';

const xblockView = view ?? 'student_view';

return (
<div style={{
height: `${iFrameHeight}vh`,
Expand All @@ -83,7 +91,7 @@ export const LibraryBlock = ({ onBlockNotification, usageKey, version }: Library
<iframe
ref={iframeRef}
title={intl.formatMessage(messages.iframeTitle)}
src={`${studioBaseUrl}/xblocks/v2/${usageKey}/embed/student_view/${queryStr}`}
src={`${studioBaseUrl}/xblocks/v2/${usageKey}/embed/${xblockView}/${queryStr}`}
data-testid="block-preview"
style={{
width: '100%',
Expand Down
4 changes: 1 addition & 3 deletions src/library-authoring/components/ComponentEditorModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,7 @@ export function canEditComponent(usageKey: string): boolean {
return false;
}

// Which XBlock/component types are supported by the 'editors' built in to this repo?
const mfeEditorTypes = ['html', 'problem', 'video'];
return mfeEditorTypes.includes(blockType);
return getConfig().LIBRARY_SUPPORTED_BLOCKS.includes(blockType);
}

export const ComponentEditorModal: React.FC<Record<never, never>> = () => {
Expand Down

0 comments on commit c80b2fd

Please sign in to comment.