Skip to content

Commit 87695ae

Browse files
authored
fix: auto adjust min height of xblock previews [FC-0083] (#1813)
Sets minimum height of library block previews based on its render location and block type.
1 parent 6818542 commit 87695ae

5 files changed

Lines changed: 35 additions & 3 deletions

File tree

src/editors/AdvancedEditor.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ const AdvancedEditor = ({ usageKey, onClose }: AdvancedEditorProps) => {
5555
usageKey={usageKey}
5656
view="studio_view"
5757
scrolling="yes"
58+
minHeight="70vh"
5859
/>
5960
</IframeProvider>
6061
</EditorModalWrapper>

src/library-authoring/LibraryBlock/LibraryBlock.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ interface LibraryBlockProps {
1515
version?: VersionSpec;
1616
view?: string;
1717
scrolling?: string;
18+
minHeight?: string;
1819
}
1920
/**
2021
* React component that displays an XBlock in a sandboxed IFrame.
@@ -30,6 +31,7 @@ export const LibraryBlock = ({
3031
usageKey,
3132
version,
3233
view,
34+
minHeight,
3335
scrolling = 'no',
3436
}: LibraryBlockProps) => {
3537
const { iframeRef, setIframeRef } = useIframe();
@@ -61,7 +63,7 @@ export const LibraryBlock = ({
6163
loading="lazy"
6264
referrerPolicy="origin"
6365
style={{
64-
width: '100%', height: iframeHeight, pointerEvents: 'auto', minHeight: '700px',
66+
width: '100%', height: iframeHeight, pointerEvents: 'auto', minHeight,
6567
}}
6668
allow={IFRAME_FEATURE_POLICY}
6769
allowFullScreen

src/library-authoring/component-comparison/CompareChangesWidget.tsx

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,22 @@ const CompareChangesWidget = ({ usageKey, oldVersion = 'published', newVersion =
2929
<Tab eventKey="old" title={intl.formatMessage(messages.oldVersionTitle)}>
3030
<div className="p-2 bg-white">
3131
<IframeProvider>
32-
<LibraryBlock usageKey={usageKey} version={oldVersion} />
32+
<LibraryBlock
33+
usageKey={usageKey}
34+
version={oldVersion}
35+
minHeight="50vh"
36+
/>
3337
</IframeProvider>
3438
</div>
3539
</Tab>
3640
<Tab eventKey="new" title={intl.formatMessage(messages.newVersionTitle)}>
3741
<div className="p-2 bg-white">
3842
<IframeProvider>
39-
<LibraryBlock usageKey={usageKey} version={newVersion} />
43+
<LibraryBlock
44+
usageKey={usageKey}
45+
version={newVersion}
46+
minHeight="50vh"
47+
/>
4048
</IframeProvider>
4149
</div>
4250
</Tab>

src/library-authoring/component-info/ComponentPreview.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ const ModalComponentPreview = ({ isOpen, close, usageKey }: ModalComponentPrevie
3131
<LibraryBlock
3232
usageKey={usageKey}
3333
version={showOnlyPublished ? 'published' : undefined}
34+
minHeight="60vh"
3435
/>
3536
</StandardModal>
3637
);
@@ -71,6 +72,7 @@ const ComponentPreview = () => {
7172
usageKey={usageKey}
7273
key={componentMetadata.modified}
7374
version={showOnlyPublished ? 'published' : undefined}
75+
minHeight="60vh"
7476
/>
7577
)
7678
: null

src/library-authoring/units/LibraryUnitBlocks.tsx

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import DraggableList, { SortableItem } from '../../editors/sharedComponents/Drag
1212

1313
import ErrorAlert from '../../generic/alert-error';
1414
import { getItemIcon } from '../../generic/block-type-utils';
15+
import { COMPONENT_TYPES } from '../../generic/block-type-utils/constants';
1516
import { IframeProvider } from '../../generic/hooks/context/iFrameContext';
1617
import Loading from '../../generic/Loading';
1718
import TagCount from '../../generic/tag-count';
@@ -24,6 +25,15 @@ import { useLibraryRoutes } from '../routes';
2425
import messages from './messages';
2526
import { useSidebarContext } from '../common/context/SidebarContext';
2627

28+
/** Components that need large min height in preview */
29+
const LARGE_COMPONENTS = [
30+
COMPONENT_TYPES.advanced,
31+
COMPONENT_TYPES.dragAndDrop,
32+
COMPONENT_TYPES.discussion,
33+
'lti',
34+
'lti_consumer',
35+
];
36+
2737
export const LibraryUnitBlocks = () => {
2838
const intl = useIntl();
2939
const [orderedBlocks, setOrderedBlocks] = useState<LibraryBlockMetadata[]>([]);
@@ -79,6 +89,14 @@ export const LibraryUnitBlocks = () => {
7989
navigateTo({ componentId: block.id });
8090
};
8191

92+
/* istanbul ignore next */
93+
const calculateMinHeight = (block: LibraryBlockMetadata) => {
94+
if (LARGE_COMPONENTS.includes(block.blockType)) {
95+
return '700px';
96+
}
97+
return '200px';
98+
};
99+
82100
const renderedBlocks = orderedBlocks?.map((block) => (
83101
<IframeProvider key={block.id}>
84102
<SortableItem
@@ -124,6 +142,7 @@ export const LibraryUnitBlocks = () => {
124142
<LibraryBlock
125143
usageKey={block.id}
126144
version={showOnlyPublished ? 'published' : undefined}
145+
minHeight={calculateMinHeight(block)}
127146
/>
128147
</div>
129148
</SortableItem>

0 commit comments

Comments
 (0)