Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,8 @@ export const REGEX_RULES = {
* This policy was selected in conference with the edX Security Working Group.
* Changes to it should be vetted by them (security@edx.org).
*/
export const ADVANCED_EDITOR_MIN_HEIGHT = '70vh';

Comment on lines +95 to +96

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

please move these lines higher or lower. They are currently separating the important comment above from the IFRAME_FEATURE_POLICY variable that the comment is describing. Also please describe what this constant is for and why it's set to 70vh.

export const IFRAME_FEATURE_POLICY =
'microphone *; camera *; midi *; geolocation *; encrypted-media *; clipboard-write *';

Expand Down
28 changes: 27 additions & 1 deletion src/editors/AdvancedEditor.test.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { getConfig } from '@edx/frontend-platform';
import userEvent from '@testing-library/user-event';

import {
render,
Expand All @@ -8,10 +9,15 @@ import {
act,
fireEvent,
} from '../testUtils';
import { LibraryBlock } from '../library-authoring/LibraryBlock';
import messages from './messages';
import AdvancedEditor from './AdvancedEditor';

jest.mock('./containers/EditorContainer', () => ({
EditorModalWrapper: jest.fn(() => <div>Advanced Editor Iframe</div>),
EditorModalWrapper: jest.fn(({ children }) => <div>Advanced Editor Iframe{children}</div>),
}));
jest.mock('../library-authoring/LibraryBlock', () => ({
LibraryBlock: jest.fn(() => <div>Library Block</div>),
}));
const onCloseMock = jest.fn();

Expand Down Expand Up @@ -99,4 +105,24 @@ describe('AdvancedEditor', () => {

expect(onCloseMock).not.toHaveBeenCalled();
});

it('lets the block fill the modal only in fullscreen', async () => {
const user = userEvent.setup();
render(<AdvancedEditor usageKey="test" onClose={onCloseMock} />);

expect(LibraryBlock).toHaveBeenLastCalledWith(
expect.objectContaining({ fillContainer: false }),
expect.anything(),
);

const toggleButton = await screen.findByRole('button', {
name: messages.advancedEditorFullscreenButtonAlt.defaultMessage,
});
await user.click(toggleButton);

expect(LibraryBlock).toHaveBeenLastCalledWith(
expect.objectContaining({ fillContainer: true }),
expect.anything(),
);
});
});
5 changes: 4 additions & 1 deletion src/editors/AdvancedEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import {
} from '@openedx/paragon';
import { Close, CloseFullscreen, OpenInFull } from '@openedx/paragon/icons';

import { ADVANCED_EDITOR_MIN_HEIGHT } from '@src/constants';

import { LibraryBlock } from '../library-authoring/LibraryBlock';
import { EditorModalWrapper } from './containers/EditorContainer';
import { ToastContext } from '../generic/toast-context';
Expand Down Expand Up @@ -88,7 +90,8 @@ const AdvancedEditor = ({ usageKey, onClose }: AdvancedEditorProps) => {
usageKey={usageKey}
view="studio_view"
scrolling="yes"
minHeight="70vh"
minHeight={ADVANCED_EDITOR_MIN_HEIGHT}
fillContainer={isFullscreen}
/>
</IframeProvider>
</EditorModalWrapper>
Expand Down
21 changes: 21 additions & 0 deletions src/editors/containers/EditorContainer/index.scss
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,24 @@
overflow: visible;
}
}

// Pass the fullscreen height down: flex-basis outranks h-75 and TinyMCE's inline height.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I don't see any flex-basis nor h-75 here, so could you please just clarify this comment?

.editor-modal.pgn__modal-fullscreen {
.pgn__modal-body,
.pgn__modal-body-content,
.editor-body {
display: flex;
flex-direction: column;
}

.pgn__modal-body-content,
.editor-body,
.tox-tinymce {
flex: 1 1 0;
min-height: 0;
}

.pgn__modal-body-content {
overflow-y: auto;
}
}
1 change: 1 addition & 0 deletions src/editors/containers/EditorContainer/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ export const EditorModalWrapper: React.FC<WrapperProps & { onClose: () => void;
isOpen
onClose={onClose}
title={title}
className="editor-modal"
size={fullscreen ? 'fullscreen' : 'xl'}
isOverflowVisible={false}
hasCloseButton={false}
Expand Down
36 changes: 36 additions & 0 deletions src/library-authoring/LibraryBlock/LibraryBlock.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import { initializeMocks, render, screen } from '../../testUtils';
import { ADVANCED_EDITOR_MIN_HEIGHT } from '../../constants';
import { IframeProvider } from '../../generic/hooks/context/iFrameContext';
import { LibraryBlock } from '.';

const usageKey = 'lb:Org:Lib:html:block-1';

const renderBlock = (props = {}) =>
render(
<IframeProvider>
<LibraryBlock usageKey={usageKey} minHeight={ADVANCED_EDITOR_MIN_HEIGHT} {...props} />

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

It's not obvious why this is using ADVANCED_EDITOR_MIN_HEIGHT since nothing else in this file or even this whole folder has anything to do with editors.

</IframeProvider>,
);

describe('LibraryBlock', () => {
beforeEach(() => {
initializeMocks();
});

it('sizes the frame to the height the block reports', async () => {
renderBlock();

const iframe = await screen.findByTestId('block-preview');
expect(iframe.style.minHeight).toBe(ADVANCED_EDITOR_MIN_HEIGHT);
expect(iframe.style.flex).toBe('');
Comment on lines +20 to +25

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This test doesn't really confirm that the height matches "the height the block reports" - the reported height is not listed anywhere in the test. It just checks that a minimum height is set, and that the flex style is not set.

The test is fine, I think, but the description should be simplified to be more accurate about what we are testing. Or just add a comment to explain a bit more.

});

it('stretches the frame to its container when asked to', async () => {
renderBlock({ fillContainer: true });

const iframe = await screen.findByTestId('block-preview');
expect(iframe.style.flex).toBe('1 1 auto');
expect(iframe.style.height).toBe('auto');
expect(iframe.style.minHeight).toBe('0');
});
});
7 changes: 5 additions & 2 deletions src/library-authoring/LibraryBlock/LibraryBlock.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ interface LibraryBlockProps {
view?: string;
scrolling?: string;
minHeight?: string;
fillContainer?: boolean;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I don't really understand why we need this change to LibraryBlock. Could you please add a before/after screenshot for this one too? And add a JSDoc comment here explaining this parameter?

scrollIntoView?: boolean;
showTitle?: boolean;
addHeight?: number;
Expand All @@ -38,6 +39,7 @@ export const LibraryBlock = ({
version,
view,
minHeight,
fillContainer = false,
scrolling = 'no',
scrollIntoView = false,
showTitle = false,
Expand Down Expand Up @@ -99,9 +101,10 @@ export const LibraryBlock = ({
referrerPolicy="origin"
style={{
width: '100%',
height: iframeHeight + addHeight,
pointerEvents: 'auto',
minHeight,
...(fillContainer
? { flex: '1 1 auto', height: 'auto', minHeight: 0 }
: { height: iframeHeight + addHeight, minHeight }),
}}
allow={IFRAME_FEATURE_POLICY}
allowFullScreen
Expand Down