Skip to content

Commit 4170ff7

Browse files
authored
Integrate 1920 Source Format, Add Prepend Editor, Add Autograding Tab (#527)
* Added new fields to IQuestion * added autograder tab for assessmentWorkspace * yarn format * Merged 'master' from source-academy/cadet-frontend * Resolved merge conflicts with Mission Control * Separated each code segments with newlines * Added read-only AceEditor for tasks with Prepend
1 parent 940633b commit 4170ff7

33 files changed

+617
-114
lines changed

README.md.orig

Lines changed: 0 additions & 93 deletions
This file was deleted.

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/actions/actionTypes.ts

100755100644
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ export const BEGIN_INTERRUPT_EXECUTION = 'BEGIN_INTERRUPT_EXECUTION';
1919
export const END_INTERRUPT_EXECUTION = 'END_INTERRUPT_EXECUTION';
2020
export const EVAL_INTERPRETER_ERROR = 'EVAL_INTERPRETER_ERROR';
2121
export const EVAL_INTERPRETER_SUCCESS = 'EVAL_INTERPRETER_SUCCESS';
22+
export const EVAL_TESTCASE_SUCCESS = 'EVAL_TESTCASE_SUCCESS';
2223
export const HANDLE_CONSOLE_LOG = 'HANDLE_CONSOLE_LOG';
2324
export const BEGIN_DEBUG_PAUSE = 'BEGIN_DEBUG_PAUSE';
2425
export const END_DEBUG_PAUSE = 'END_DEBUG_PAUSE';
@@ -31,6 +32,7 @@ export const BEGIN_CLEAR_CONTEXT = 'BEGIN_CLEAR_CONTEXT';
3132
export const BROWSE_REPL_HISTORY_DOWN = 'BROWSE_REPL_HISTORY_DOWN';
3233
export const BROWSE_REPL_HISTORY_UP = 'BROWSE_REPL_HISTORY_UP';
3334
export const CHANGE_ACTIVE_TAB = 'CHANGE_ACTIVE_TAB';
35+
export const CHANGE_EDITOR_HEIGHT = 'CHANGE_EDITOR_HEIGHT';
3436
export const CHANGE_EDITOR_WIDTH = 'CHANGE_EDITOR_WIDTH';
3537
export const CHANGE_PLAYGROUND_EXTERNAL = 'CHANGE_PLAYGROUND_EXTERNAL';
3638
export const CHANGE_SIDE_CONTENT_HEIGHT = 'CHANGE_SIDE_CONTENT_HEIGHT';
@@ -41,6 +43,7 @@ export const END_CLEAR_CONTEXT = 'END_CLEAR_CONTEXT';
4143
export const ENSURE_LIBRARIES_LOADED = 'ENSURE_LIBRARIES_LOADED';
4244
export const EVAL_EDITOR = 'EVAL_EDITOR';
4345
export const EVAL_REPL = 'EVAL_REPL';
46+
export const EVAL_TESTCASE = 'EVAL_TESTCASE';
4447
export const INVALID_EDITOR_SESSION_ID = 'INVALID_EDITOR_SESSION_ID';
4548
export const PLAYGROUND_EXTERNAL_SELECT = 'PLAYGROUND_EXTERNAL_SELECT ';
4649
export const RESET_WORKSPACE = 'RESET_WORKSPACE';

src/actions/interpreter.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,15 @@ export const evalInterpreterSuccess = (value: Value, workspaceLocation: Workspac
1313
payload: { type: 'result', value, workspaceLocation }
1414
});
1515

16+
export const evalTestcaseSuccess = (
17+
value: Value,
18+
workspaceLocation: WorkspaceLocation,
19+
index: number
20+
) => ({
21+
type: actionTypes.EVAL_TESTCASE_SUCCESS,
22+
payload: { type: 'result', value, workspaceLocation, index }
23+
});
24+
1625
export const evalInterpreterError = (
1726
errors: SourceError[],
1827
workspaceLocation: WorkspaceLocation

src/actions/workspaces.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,14 @@ export const changePlaygroundExternal: ActionCreator<actionTypes.IAction> = (
5151
payload: { newExternal }
5252
});
5353

54+
export const changeEditorHeight: ActionCreator<actionTypes.IAction> = (
55+
height: number,
56+
workspaceLocation: WorkspaceLocation
57+
) => ({
58+
type: actionTypes.CHANGE_EDITOR_HEIGHT,
59+
payload: { height, workspaceLocation }
60+
});
61+
5462
export const changeEditorWidth: ActionCreator<actionTypes.IAction> = (
5563
widthChange: string,
5664
workspaceLocation: WorkspaceLocation
@@ -161,6 +169,11 @@ export const evalRepl = (workspaceLocation: WorkspaceLocation) => ({
161169
payload: { workspaceLocation }
162170
});
163171

172+
export const evalTestcase = (workspaceLocation: WorkspaceLocation, testcaseId: number) => ({
173+
type: actionTypes.EVAL_TESTCASE,
174+
payload: { workspaceLocation, testcaseId }
175+
});
176+
164177
export const invalidEditorSessionId = () => ({
165178
type: actionTypes.INVALID_EDITOR_SESSION_ID
166179
});

src/components/Playground.tsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ export interface IStateProps {
3838
activeTab: number;
3939
editorSessionId: string;
4040
editorValue: string;
41+
editorHeight?: number;
4142
editorWidth: string;
4243
breakpoints: string[];
4344
highlightedLines: number[][];
@@ -60,6 +61,7 @@ export interface IDispatchProps {
6061
handleChangeActiveTab: (activeTab: number) => void;
6162
handleChapterSelect: (chapter: number) => void;
6263
handleEditorEval: () => void;
64+
handleEditorHeightChange: (height: number) => void;
6365
handleEditorValueChange: (val: string) => void;
6466
handleEditorWidthChange: (widthChange: number) => void;
6567
handleEditorUpdateBreakpoints: (breakpoints: string[]) => void;
@@ -131,6 +133,8 @@ class Playground extends React.Component<IPlaygroundProps, PlaygroundState> {
131133
websocketStatus: this.props.websocketStatus
132134
},
133135
editorProps: {
136+
editorPrepend: '',
137+
editorPrependLines: 0,
134138
editorValue: this.props.editorValue,
135139
editorSessionId: this.props.editorSessionId,
136140
handleEditorEval: this.props.handleEditorEval,
@@ -141,7 +145,9 @@ class Playground extends React.Component<IPlaygroundProps, PlaygroundState> {
141145
handleEditorUpdateBreakpoints: this.props.handleEditorUpdateBreakpoints,
142146
handleSetWebsocketStatus: this.props.handleSetWebsocketStatus
143147
},
148+
editorHeight: this.props.editorHeight,
144149
editorWidth: this.props.editorWidth,
150+
handleEditorHeightChange: this.props.handleEditorHeightChange,
145151
handleEditorWidthChange: this.props.handleEditorWidthChange,
146152
handleSideContentHeightChange: this.props.handleSideContentHeightChange,
147153
replProps: {

src/components/__tests__/Playground.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ const baseProps = {
2727
handleChangeActiveTab: (n: number) => {},
2828
handleChapterSelect: (chapter: number) => {},
2929
handleEditorEval: () => {},
30+
handleEditorHeightChange: (height: number) => {},
3031
handleEditorValueChange: () => {},
3132
handleEditorWidthChange: (widthChange: number) => {},
3233
handleEditorUpdateBreakpoints: (breakpoints: string[]) => {},

src/components/__tests__/__snapshots__/Playground.tsx.snap

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@
22

33
exports[`Playground renders correctly 1`] = `
44
"<HotKeys className=\\"Playground pt-dark\\" keyMap={{...}} handlers={{...}}>
5-
<Workspace controlBarProps={{...}} editorProps={{...}} editorWidth=\\"50%\\" handleEditorWidthChange={[Function: handleEditorWidthChange]} handleSideContentHeightChange={[Function: handleSideContentHeightChange]} replProps={{...}} sideContentHeight={40} sideContentProps={{...}} />
5+
<Workspace controlBarProps={{...}} editorProps={{...}} editorHeight={[undefined]} editorWidth=\\"50%\\" handleEditorHeightChange={[Function: handleEditorHeightChange]} handleEditorWidthChange={[Function: handleEditorWidthChange]} handleSideContentHeightChange={[Function: handleSideContentHeightChange]} replProps={{...}} sideContentHeight={40} sideContentProps={{...}} />
66
</HotKeys>"
77
`;
88

99
exports[`Playground with link renders correctly 1`] = `
1010
"<HotKeys className=\\"Playground pt-dark\\" keyMap={{...}} handlers={{...}}>
11-
<Workspace controlBarProps={{...}} editorProps={{...}} editorWidth=\\"50%\\" handleEditorWidthChange={[Function: handleEditorWidthChange]} handleSideContentHeightChange={[Function: handleSideContentHeightChange]} replProps={{...}} sideContentHeight={40} sideContentProps={{...}} />
11+
<Workspace controlBarProps={{...}} editorProps={{...}} editorHeight={[undefined]} editorWidth=\\"50%\\" handleEditorHeightChange={[Function: handleEditorHeightChange]} handleEditorWidthChange={[Function: handleEditorWidthChange]} handleSideContentHeightChange={[Function: handleSideContentHeightChange]} replProps={{...}} sideContentHeight={40} sideContentProps={{...}} />
1212
</HotKeys>"
1313
`;

src/components/academy/grading/GradingWorkspace.tsx

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import {
99
IMCQQuestion,
1010
IProgrammingQuestion,
1111
IQuestion,
12+
ITestcase,
1213
Library,
1314
QuestionTypes
1415
} from '../../assessment/assessmentShape';
@@ -23,7 +24,11 @@ export type GradingWorkspaceProps = DispatchProps & OwnProps & StateProps;
2324
export type StateProps = {
2425
activeTab: number;
2526
grading?: Grading;
27+
editorPrepend: string | null;
2628
editorValue: string | null;
29+
editorPostpend: string | null;
30+
editorTestcases: ITestcase[] | null;
31+
editorHeight?: number;
2732
editorWidth: string;
2833
breakpoints: string[];
2934
highlightedLines: number[][];
@@ -51,6 +56,7 @@ export type DispatchProps = {
5156
handleClearContext: (library: Library) => void;
5257
handleEditorEval: () => void;
5358
handleEditorValueChange: (val: string) => void;
59+
handleEditorHeightChange: (height: number) => void;
5460
handleEditorWidthChange: (widthChange: number) => void;
5561
handleEditorUpdateBreakpoints: (breakpoints: string[]) => void;
5662
handleGradingFetch: (submissionId: number) => void;
@@ -113,6 +119,11 @@ class GradingWorkspace extends React.Component<GradingWorkspaceProps> {
113119
editorProps:
114120
question.type === QuestionTypes.programming
115121
? {
122+
editorPrepend: this.props.editorPrepend!,
123+
editorPrependLines:
124+
this.props.editorPrepend === null || this.props.editorPrepend.length === 0
125+
? 0
126+
: this.props.editorPrepend.split('\n').length,
116127
editorSessionId: '',
117128
editorValue: editorValue!,
118129
handleEditorEval: this.props.handleEditorEval,
@@ -123,7 +134,9 @@ class GradingWorkspace extends React.Component<GradingWorkspaceProps> {
123134
isEditorAutorun: false
124135
}
125136
: undefined,
137+
editorHeight: this.props.editorHeight,
126138
editorWidth: this.props.editorWidth,
139+
handleEditorHeightChange: this.props.handleEditorHeightChange,
127140
handleEditorWidthChange: this.props.handleEditorWidthChange,
128141
handleSideContentHeightChange: this.props.handleSideContentHeightChange,
129142
mcqProps: {
@@ -173,9 +186,32 @@ class GradingWorkspace extends React.Component<GradingWorkspaceProps> {
173186
? ((question as IProgrammingQuestion).answer as string)
174187
: (question as IProgrammingQuestion).solutionTemplate
175188
: null;
189+
const editorPrepend =
190+
question.type === QuestionTypes.programming
191+
? (question as IProgrammingQuestion).prepend !== null
192+
? (question as IProgrammingQuestion).prepend
193+
: ''
194+
: '';
195+
const editorPostpend =
196+
question.type === QuestionTypes.programming
197+
? (question as IProgrammingQuestion).postpend !== null
198+
? (question as IProgrammingQuestion).postpend
199+
: ''
200+
: '';
201+
const editorTestcases =
202+
question.type === QuestionTypes.programming
203+
? (question as IProgrammingQuestion).testcases !== null
204+
? (question as IProgrammingQuestion).testcases
205+
: []
206+
: [];
176207
this.props.handleEditorUpdateBreakpoints([]);
177208
this.props.handleUpdateCurrentSubmissionId(submissionId, questionId);
178-
this.props.handleResetWorkspace({ editorValue });
209+
this.props.handleResetWorkspace({
210+
editorPrepend,
211+
editorValue,
212+
editorPostpend,
213+
editorTestcases
214+
});
179215
this.props.handleClearContext(question.library);
180216
this.props.handleUpdateHasUnsavedChanges(false);
181217
if (editorValue) {

0 commit comments

Comments
 (0)