-
Notifications
You must be signed in to change notification settings - Fork 585
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Have Teacher Tool Request Iframe to Run Evaluation for Specified Shar…
…e Link (#9821) At a high level, this change does the following: 1. Connects the iframe to the share link that has been provided (except in localhost, because cross-domain localhost <-> makecode.com messaging doesn't work) 2. Saves project metadata and rubric info in app state 3. Adds a request to the iframe to get evaluation results. This request includes the rubric json as a parameter. A few notable points: - Logging Service I added a logging service for convenient, consistent output and telemetry. There's LogError, which sends a tick event and does a console error output, LogInfo which does a tick event and non-error console output, and LogDebug, which sends console output but only if you're running the app locally. - State in MakeCode Frame I went back and forth on this, but in the end, in order to be consistent with our other component usage, I pushed the state for the project metadata into the MakecodeFrame. I can pull this out and have it passed in as props instead if desired, but I wasn't sure if there was all that much value in doing so at the moment. - Fix for Promise Resolution in makecodeEditorService Without the fix, when a message got queued up by Caller A but not sent immediately (editor not ready), then another caller has to come in and clear the queue once the editor is ready (Caller B). This was working okay, except it would assign the message's handler to the resolve function from the promise associated with Caller B's request, not Caller A's. As such, when a response comes back for the message, we'd end up resolving Caller B's promise instead of Caller A's, so Caller A would never return. To fix this, I assign the message metadata (including the handler) when we queue the message rather than when we dequeue it. This way, the handler will always get set to the resolve function for the promise returned to the caller that tried to send the message initially. - Renamed loadProjectAsync to loadProjectMetadataAsync Wanted to avoid confusion between loading the metadata and the project "loading" in the iframe. - Placeholders The EvaluationResult class and editor-side handler for the runeval request are just placeholders until we have actual evaluation running. I expect these to change in the near future. - Try it Here Upload target: https://arcade.makecode.com/app/e620e5c33cf3af44b631781f582f4ebcc34223c7-c7c3f7a5ad--eval
- Loading branch information
Showing
15 changed files
with
270 additions
and
70 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
namespace pxt.blocks { | ||
export interface EvaluationResult { | ||
passed: boolean; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
/// <reference path="../../../built/pxtblocks.d.ts"/> | ||
|
||
import { useContext, useState } from "react"; | ||
import { AppStateContext } from "../state/appStateContext"; | ||
|
||
interface IProps {} | ||
|
||
const EvalResultDisplay: React.FC<IProps> = ({}) => { | ||
const { state: teacherTool } = useContext(AppStateContext); | ||
|
||
return ( | ||
<> | ||
{teacherTool.projectMetadata && ( | ||
<div className="eval-results-container"> | ||
<h3>{lf("Project: {0}", teacherTool.projectMetadata.name)}</h3> | ||
{teacherTool.currentEvalResult === undefined && <div className="common-spinner" />} | ||
{teacherTool.currentEvalResult?.passed === true && <h4 className="positive-text">Passed!</h4>} | ||
{teacherTool.currentEvalResult?.passed === false && <h4 className="negative-text">Failed!</h4>} | ||
</div> | ||
)} | ||
</> | ||
); | ||
|
||
}; | ||
|
||
export default EvalResultDisplay; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,39 @@ | ||
/// <reference path="../../../built/pxteditor.d.ts" /> | ||
import * as React from "react"; | ||
import { useContext } from "react"; | ||
import { setEditorRef } from "../services/makecodeEditorService"; | ||
interface MakeCodeFrameProps { | ||
pageSourceUrl: string; | ||
tutorialEventHandler?: (event: pxt.editor.EditorMessageTutorialEventRequest) => void; | ||
} | ||
import { AppStateContext } from "../state/appStateContext"; | ||
import { getEditorUrl } from "../utils"; | ||
|
||
interface MakeCodeFrameProps {} | ||
export const MakeCodeFrame: React.FC<MakeCodeFrameProps> = () => { | ||
const { state: teacherTool } = useContext(AppStateContext) | ||
|
||
export const MakeCodeFrame: React.FC<MakeCodeFrameProps> = | ||
( { pageSourceUrl} ) => { | ||
function createIFrameUrl(shareId: string): string { | ||
const editorUrl: string = pxt.BrowserUtils.isLocalHost() ? "http://localhost:3232/index.html" : getEditorUrl((window as any).pxtTargetBundle.appTheme.embedUrl); | ||
|
||
let url = editorUrl; | ||
if (editorUrl.charAt(editorUrl.length - 1) === "/" && !pxt.BrowserUtils.isLocalHost()) { | ||
url = editorUrl.substr(0, editorUrl.length - 1); | ||
} | ||
url += `?controller=1&ws=browser&nocookiebanner=1#pub:${shareId}`; | ||
return url; | ||
} | ||
|
||
const handleIFrameRef = (el: HTMLIFrameElement | null) => { | ||
setEditorRef(el ?? undefined); | ||
} | ||
|
||
/* eslint-disable @microsoft/sdl/react-iframe-missing-sandbox */ | ||
return <div className="makecode-frame-outer" style={{ display: "block" }}> | ||
<iframe className="makecode-frame" src={pageSourceUrl} title={"title"} ref={handleIFrameRef}></iframe> | ||
</div> | ||
return ( | ||
<div className="makecode-frame-outer" style={{ display: "block" }}> | ||
{teacherTool.projectMetadata && ( | ||
<iframe | ||
className="makecode-frame" | ||
src={createIFrameUrl(teacherTool.projectMetadata.id)} | ||
title={"title"} | ||
ref={handleIFrameRef} /> | ||
)} | ||
</div> | ||
); | ||
/* eslint-enable @microsoft/sdl/react-iframe-missing-sandbox */ | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
const formatMessageForConsole = (message: string) => { | ||
const time = new Date(); | ||
return `[${time.getHours()}:${time.getMinutes()}:${time.getSeconds()}] ${message}`; | ||
} | ||
|
||
const formatName = (name: string) => { | ||
return name.toLowerCase().replace(/ /g, "_"); | ||
} | ||
|
||
export const logError = (name: string, details: string) => { | ||
pxt.tickEvent("teachertool.error", { name: formatName(name), message: details }); | ||
console.error(formatMessageForConsole(`${name}: ${details}`)); | ||
} | ||
|
||
export const logInfo = (name: string, message: string) => { | ||
pxt.tickEvent(`teachertool.${formatName(name)}`, { message: message }); | ||
console.log(formatMessageForConsole(message)); | ||
} | ||
|
||
export const logDebug = (message: string) => { | ||
if (pxt.BrowserUtils.isLocalHost() || pxt.options.debug) { | ||
console.log(formatMessageForConsole(message)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.