Skip to content

Commit 7daad72

Browse files
committed
refactor: iframe min height and useIframeBehaviour spelling
1 parent a9b885a commit 7daad72

4 files changed

Lines changed: 18 additions & 16 deletions

File tree

src/course-unit/xblock-container-iframe/index.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ import {
3232
} from './types';
3333
import { formatAccessManagedXBlockData, getIframeUrl, getLegacyEditModalUrl } from './utils';
3434
import messages from './messages';
35-
import { useIFrameBehavior } from '../../generic/hooks/useIFrameBehavior';
35+
import { useIframeBehavior } from '../../generic/hooks/useIframeBehavior';
3636
import { useIframeContent } from '../../generic/hooks/useIframeContent';
3737
import { useIframeMessages } from '../../generic/hooks/useIframeMessages';
3838

@@ -56,7 +56,7 @@ const XBlockContainerIframe: FC<XBlockContainerIframeProps> = ({
5656
const legacyEditModalUrl = useMemo(() => getLegacyEditModalUrl(configureXBlockId), [configureXBlockId]);
5757

5858
const { iframeRef, setIframeRef, sendMessageToIframe } = useIframe();
59-
const { iframeHeight } = useIFrameBehavior({ id: blockId, iframeUrl, iframeRef });
59+
const { iframeHeight } = useIframeBehavior({ id: blockId, iframeUrl, iframeRef });
6060

6161
useIframeContent(iframeRef, setIframeRef);
6262

src/generic/hooks/tests/hooks.test.tsx

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { useKeyedState } from '@edx/react-unit-test-utils';
55
import { logError } from '@edx/frontend-platform/logging';
66
import { mockBroadcastChannel } from '../../data/api.mock';
77
import { iframeMessageTypes, iframeStateKeys } from '../../../constants';
8-
import { useIFrameBehavior } from '../useIFrameBehavior';
8+
import { useIframeBehavior } from '../useIframeBehavior';
99
import { useLoadBearingHook } from '../useLoadBearingHook';
1010

1111
jest.useFakeTimers();
@@ -20,7 +20,7 @@ jest.mock('@edx/frontend-platform/logging', () => ({
2020

2121
mockBroadcastChannel();
2222

23-
describe('useIFrameBehavior', () => {
23+
describe('useIframeBehavior', () => {
2424
const id = 'test-id';
2525
const iframeUrl = 'http://example.com';
2626
const setIframeHeight = jest.fn();
@@ -52,7 +52,7 @@ describe('useIFrameBehavior', () => {
5252
});
5353

5454
it('initializes state correctly', () => {
55-
const { result } = renderHook(() => useIFrameBehavior({ id, iframeUrl, iframeRef }));
55+
const { result } = renderHook(() => useIframeBehavior({ id, iframeUrl, iframeRef }));
5656

5757
expect(result.current.iframeHeight).toBe(0);
5858
expect(result.current.showError).toBe(false);
@@ -69,7 +69,7 @@ describe('useIFrameBehavior', () => {
6969
return [null, jest.fn()];
7070
});
7171

72-
renderHook(() => useIFrameBehavior({ id, iframeUrl, iframeRef }));
72+
renderHook(() => useIframeBehavior({ id, iframeUrl, iframeRef }));
7373

7474
const message = {
7575
data: {
@@ -86,7 +86,7 @@ describe('useIFrameBehavior', () => {
8686
});
8787

8888
it('handles resize message correctly', () => {
89-
renderHook(() => useIFrameBehavior({ id, iframeUrl, iframeRef }));
89+
renderHook(() => useIframeBehavior({ id, iframeUrl, iframeRef }));
9090

9191
const message = {
9292
data: {
@@ -105,7 +105,7 @@ describe('useIFrameBehavior', () => {
105105

106106
it('handles xblock-event message correctly', () => {
107107
const onBlockNotification = jest.fn();
108-
renderHook(() => useIFrameBehavior({
108+
renderHook(() => useIframeBehavior({
109109
id, iframeUrl, iframeRef, onBlockNotification,
110110
}));
111111

@@ -130,7 +130,7 @@ describe('useIFrameBehavior', () => {
130130
});
131131

132132
it('handles videoFullScreen message correctly', () => {
133-
renderHook(() => useIFrameBehavior({ id, iframeUrl, iframeRef }));
133+
renderHook(() => useIframeBehavior({ id, iframeUrl, iframeRef }));
134134

135135
const message = {
136136
data: {
@@ -148,7 +148,7 @@ describe('useIFrameBehavior', () => {
148148

149149
it('handles offset message correctly', () => {
150150
document.body.innerHTML = '<div id="unit-iframe" style="position: absolute; top: 50px;"></div>';
151-
renderHook(() => useIFrameBehavior({ id, iframeUrl, iframeRef }));
151+
renderHook(() => useIframeBehavior({ id, iframeUrl, iframeRef }));
152152

153153
const message = {
154154
data: { offset: 100 },
@@ -162,7 +162,7 @@ describe('useIFrameBehavior', () => {
162162
});
163163

164164
it('handles iframe load error correctly', () => {
165-
const { result } = renderHook(() => useIFrameBehavior({ id, iframeUrl, iframeRef }));
165+
const { result } = renderHook(() => useIframeBehavior({ id, iframeUrl, iframeRef }));
166166

167167
act(() => {
168168
result.current.handleIFrameLoad();
@@ -176,7 +176,7 @@ describe('useIFrameBehavior', () => {
176176

177177
it('resets state when iframeUrl changes', () => {
178178
// eslint-disable-next-line @typescript-eslint/no-shadow
179-
const { rerender } = renderHook(({ id, iframeUrl }) => useIFrameBehavior({ id, iframeUrl, iframeRef }), {
179+
const { rerender } = renderHook(({ id, iframeUrl }) => useIframeBehavior({ id, iframeUrl, iframeRef }), {
180180
initialProps: { id, iframeUrl },
181181
});
182182

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import { useEventListener } from './useEventListener';
2121
* @returns {boolean} return.showError - Flag to indicate if there was an error loading the iframe.
2222
* @returns {boolean} return.hasLoaded - Flag to indicate if the iframe has loaded.
2323
*/
24-
export const useIFrameBehavior = ({
24+
export const useIframeBehavior = ({
2525
id,
2626
iframeUrl,
2727
onLoaded = true,

src/library-authoring/LibraryBlock/LibraryBlock.tsx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { getConfig } from '@edx/frontend-platform';
33

44
import messages from './messages';
55
import { IFRAME_FEATURE_POLICY } from '../../constants';
6-
import { useIFrameBehavior } from '../../generic/hooks/useIFrameBehavior';
6+
import { useIframeBehavior } from '../../generic/hooks/useIframeBehavior';
77
import { useIframe } from '../../generic/hooks/context/hooks';
88
import { useIframeContent } from '../../generic/hooks/useIframeContent';
99

@@ -40,7 +40,7 @@ export const LibraryBlock = ({
4040
const intl = useIntl();
4141
const queryStr = version ? `?version=${version}` : '';
4242
const iframeUrl = `${studioBaseUrl}/xblocks/v2/${usageKey}/embed/${xblockView}/${queryStr}`;
43-
const { iframeHeight } = useIFrameBehavior({
43+
const { iframeHeight } = useIframeBehavior({
4444
id: usageKey,
4545
iframeUrl,
4646
iframeRef,
@@ -60,7 +60,9 @@ export const LibraryBlock = ({
6060
frameBorder="0"
6161
loading="lazy"
6262
referrerPolicy="origin"
63-
style={{ width: '100%', height: iframeHeight, pointerEvents: 'auto' }}
63+
style={{
64+
width: '100%', height: iframeHeight, pointerEvents: 'auto', minHeight: '30vh',
65+
}}
6466
allow={IFRAME_FEATURE_POLICY}
6567
allowFullScreen
6668
scrolling={scrolling}

0 commit comments

Comments
 (0)