feat: [FC-0070] rendering split test content in unit page (#1492)

Introduces functionality to display Split Test Content within the new Unit page interface.
This commit is contained in:
Ihor Romaniuk
2025-04-01 16:37:14 +02:00
committed by GitHub
parent 272e30f1b1
commit 3685dbd6a1
29 changed files with 775 additions and 258 deletions

View File

@@ -5,7 +5,7 @@ import { logError } from '@edx/frontend-platform/logging';
export interface IframeContextType {
setIframeRef: (ref: MutableRefObject<HTMLIFrameElement | null>) => void;
sendMessageToIframe: (messageType: string, payload: unknown) => void;
sendMessageToIframe: (messageType: string, payload: unknown, consumerWindow?: Window | null) => void;
}
export const IframeContext = createContext<IframeContextType | undefined>(undefined);
@@ -16,11 +16,12 @@ export const IframeProvider: React.FC = ({ children }: { children: ReactNode })
iframeRef.current = ref.current;
}, []);
const sendMessageToIframe = useCallback((messageType: string, payload: any) => {
const sendMessageToIframe = useCallback((messageType: string, payload: any, consumerWindow?: Window | null) => {
const iframeWindow = iframeRef?.current?.contentWindow;
if (iframeWindow) {
const targetWindow = consumerWindow || iframeWindow;
if (targetWindow) {
try {
iframeWindow.postMessage({ type: messageType, payload }, '*');
targetWindow.postMessage({ type: messageType, payload }, '*');
} catch (error) {
logError('Failed to send message to iframe:', error);
}