Skip to content

Commit 40051e6

Browse files
authored
Merge branch 'master' into DisplayPopularVotesLeaderboard
2 parents ac4943c + e842e48 commit 40051e6

File tree

69 files changed

+962
-700
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

69 files changed

+962
-700
lines changed

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
"@blueprintjs/popover2": "^2.0.0",
3333
"@blueprintjs/select": "^5.0.0",
3434
"@octokit/rest": "^20.0.0",
35+
"@reduxjs/toolkit": "^1.9.7",
3536
"@sentry/browser": "^7.57.0",
3637
"@sourceacademy/sharedb-ace": "^2.0.2",
3738
"@sourceacademy/sling-client": "^0.1.0",
@@ -48,7 +49,7 @@
4849
"flexboxgrid": "^6.3.1",
4950
"flexboxgrid-helpers": "^1.1.3",
5051
"hastscript": "^9.0.0",
51-
"js-slang": "^1.0.42",
52+
"js-slang": "^1.0.45",
5253
"js-yaml": "^4.1.0",
5354
"konva": "^9.2.0",
5455
"lodash": "^4.17.21",

src/commons/application/ApplicationTypes.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { Chapter, Language, SourceError, Variant } from 'js-slang/dist/types';
33
import { AcademyState } from '../../features/academy/AcademyTypes';
44
import { AchievementState } from '../../features/achievement/AchievementTypes';
55
import { DashboardState } from '../../features/dashboard/DashboardTypes';
6-
import { Grading } from '../../features/grading/GradingTypes';
6+
import { GradingQuery } from '../../features/grading/GradingTypes';
77
import { PlaygroundState } from '../../features/playground/PlaygroundTypes';
88
import { PlaybackStatus, RecordingStatus } from '../../features/sourceRecorder/SourceRecorderTypes';
99
import { StoriesEnvState, StoriesState } from '../../features/stories/StoriesTypes';
@@ -508,7 +508,7 @@ export const defaultSession: SessionState = {
508508
sessionId: Date.now(),
509509
githubOctokitObject: { octokit: undefined },
510510
gradingOverviews: undefined,
511-
gradings: new Map<number, Grading>(),
511+
gradings: new Map<number, GradingQuery>(),
512512
notifications: []
513513
};
514514

Lines changed: 54 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1+
import { createAction } from '@reduxjs/toolkit';
12
import { SourceError, Value } from 'js-slang/dist/types';
2-
import { action } from 'typesafe-actions';
33

44
import { WorkspaceLocation } from '../../workspace/WorkspaceTypes';
55
import {
@@ -16,41 +16,66 @@ import {
1616
HANDLE_CONSOLE_LOG
1717
} from '../types/InterpreterTypes';
1818

19-
export const handleConsoleLog = (workspaceLocation: WorkspaceLocation, ...logString: string[]) =>
20-
action(HANDLE_CONSOLE_LOG, { logString, workspaceLocation });
19+
export const handleConsoleLog = createAction(
20+
HANDLE_CONSOLE_LOG,
21+
(workspaceLocation: WorkspaceLocation, ...logString: string[]) => ({
22+
payload: { logString, workspaceLocation }
23+
})
24+
);
2125

22-
export const evalInterpreterSuccess = (value: Value, workspaceLocation: WorkspaceLocation) =>
23-
action(EVAL_INTERPRETER_SUCCESS, { type: 'result', value, workspaceLocation });
26+
export const evalInterpreterSuccess = createAction(
27+
EVAL_INTERPRETER_SUCCESS,
28+
(value: Value, workspaceLocation: WorkspaceLocation) => ({
29+
payload: { type: 'result', value, workspaceLocation }
30+
})
31+
);
2432

25-
export const evalTestcaseSuccess = (
26-
value: Value,
27-
workspaceLocation: WorkspaceLocation,
28-
index: number
29-
) => action(EVAL_TESTCASE_SUCCESS, { type: 'result', value, workspaceLocation, index });
33+
export const evalTestcaseSuccess = createAction(
34+
EVAL_TESTCASE_SUCCESS,
35+
(value: Value, workspaceLocation: WorkspaceLocation, index: number) => ({
36+
payload: { type: 'result', value, workspaceLocation, index }
37+
})
38+
);
3039

31-
export const evalTestcaseFailure = (
32-
value: Value,
33-
workspaceLocation: WorkspaceLocation,
34-
index: number
35-
) => action(EVAL_TESTCASE_FAILURE, { type: 'errors', value, workspaceLocation, index });
40+
export const evalTestcaseFailure = createAction(
41+
EVAL_TESTCASE_FAILURE,
42+
(value: Value, workspaceLocation: WorkspaceLocation, index: number) => ({
43+
payload: { type: 'errors', value, workspaceLocation, index }
44+
})
45+
);
3646

37-
export const evalInterpreterError = (errors: SourceError[], workspaceLocation: WorkspaceLocation) =>
38-
action(EVAL_INTERPRETER_ERROR, { type: 'errors', errors, workspaceLocation });
47+
export const evalInterpreterError = createAction(
48+
EVAL_INTERPRETER_ERROR,
49+
(errors: SourceError[], workspaceLocation: WorkspaceLocation) => ({
50+
payload: { type: 'errors', errors, workspaceLocation }
51+
})
52+
);
3953

40-
export const beginInterruptExecution = (workspaceLocation: WorkspaceLocation) =>
41-
action(BEGIN_INTERRUPT_EXECUTION, { workspaceLocation });
54+
export const beginInterruptExecution = createAction(
55+
BEGIN_INTERRUPT_EXECUTION,
56+
(workspaceLocation: WorkspaceLocation) => ({ payload: { workspaceLocation } })
57+
);
4258

43-
export const endInterruptExecution = (workspaceLocation: WorkspaceLocation) =>
44-
action(END_INTERRUPT_EXECUTION, { workspaceLocation });
59+
export const endInterruptExecution = createAction(
60+
END_INTERRUPT_EXECUTION,
61+
(workspaceLocation: WorkspaceLocation) => ({ payload: { workspaceLocation } })
62+
);
4563

46-
export const beginDebuggerPause = (workspaceLocation: WorkspaceLocation) =>
47-
action(BEGIN_DEBUG_PAUSE, { workspaceLocation });
64+
export const beginDebuggerPause = createAction(
65+
BEGIN_DEBUG_PAUSE,
66+
(workspaceLocation: WorkspaceLocation) => ({ payload: { workspaceLocation } })
67+
);
4868

49-
export const endDebuggerPause = (workspaceLocation: WorkspaceLocation) =>
50-
action(END_DEBUG_PAUSE, { workspaceLocation });
69+
export const endDebuggerPause = createAction(
70+
END_DEBUG_PAUSE,
71+
(workspaceLocation: WorkspaceLocation) => ({ payload: { workspaceLocation } })
72+
);
5173

52-
export const debuggerResume = (workspaceLocation: WorkspaceLocation) =>
53-
action(DEBUG_RESUME, { workspaceLocation });
74+
export const debuggerResume = createAction(
75+
DEBUG_RESUME,
76+
(workspaceLocation: WorkspaceLocation) => ({ payload: { workspaceLocation } })
77+
);
5478

55-
export const debuggerReset = (workspaceLocation: WorkspaceLocation) =>
56-
action(DEBUG_RESET, { workspaceLocation });
79+
export const debuggerReset = createAction(DEBUG_RESET, (workspaceLocation: WorkspaceLocation) => ({
80+
payload: { workspaceLocation }
81+
}));

src/commons/application/actions/SessionActions.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { action } from 'typesafe-actions'; // EDITED
22

3-
import { Grading, GradingOverview } from '../../../features/grading/GradingTypes';
3+
import { GradingOverview, GradingQuery } from '../../../features/grading/GradingTypes';
44
import {
55
Assessment,
66
AssessmentConfiguration,
@@ -209,7 +209,7 @@ export const updateGradingOverviews = (overviews: GradingOverview[]) =>
209209
* An extra id parameter is included here because of
210210
* no id for Grading.
211211
*/
212-
export const updateGrading = (submissionId: number, grading: Grading) =>
212+
export const updateGrading = (submissionId: number, grading: GradingQuery) =>
213213
action(UPDATE_GRADING, {
214214
submissionId,
215215
grading

src/commons/application/actions/__tests__/SessionActions.ts

Lines changed: 30 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { Chapter, Variant } from 'js-slang/dist/types';
22

3-
import { Grading, GradingOverview } from '../../../../features/grading/GradingTypes';
3+
import { GradingOverview, GradingQuery } from '../../../../features/grading/GradingTypes';
44
import { Assessment, AssessmentOverview } from '../../../assessment/AssessmentTypes';
55
import { Notification } from '../../../notificationBadge/NotificationBadgeTypes';
66
import { GameState, Role, Story } from '../../ApplicationTypes';
@@ -542,26 +542,38 @@ test('updateGradingOverviews generates correct action object', () => {
542542

543543
test('updateGrading generates correct action object', () => {
544544
const submissionId = 3;
545-
const grading: Grading = [
546-
{
547-
question: jest.genMockFromModule('../../../../features/grading/GradingTypes'),
548-
student: {
549-
name: 'test student',
550-
username: 'E0123456',
551-
id: 234
552-
},
553-
grade: {
554-
xp: 100,
555-
xpAdjustment: 0,
556-
comments: 'Well done.',
557-
grader: {
558-
name: 'HARTIN MENZ',
559-
id: 100
545+
const grading: GradingQuery = {
546+
answers: [
547+
{
548+
question: jest.genMockFromModule('../../../../features/grading/GradingTypes'),
549+
student: {
550+
name: 'test student',
551+
username: 'E0123456',
552+
id: 234
560553
},
561-
gradedAt: '2019-08-16T13:26:32+00:00'
554+
grade: {
555+
xp: 100,
556+
xpAdjustment: 0,
557+
comments: 'Well done.',
558+
grader: {
559+
name: 'HARTIN MENZ',
560+
id: 100
561+
},
562+
gradedAt: '2019-08-16T13:26:32+00:00'
563+
}
562564
}
565+
],
566+
assessment: {
567+
coverPicture: 'https://i.imgur.com/dR7zBPI.jpeg',
568+
id: 1,
569+
number: '5',
570+
reading: 'reading here',
571+
story: 'story here',
572+
summaryLong: 'long summary here',
573+
summaryShort: 'short summary here',
574+
title: 'assessment title here'
563575
}
564-
];
576+
};
565577

566578
const action = updateGrading(submissionId, grading);
567579
expect(action).toEqual({

src/commons/application/reducers/__tests__/SessionReducer.ts

Lines changed: 56 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { Chapter, Variant } from 'js-slang/dist/types';
22

3-
import { Grading, GradingOverview } from '../../../../features/grading/GradingTypes';
3+
import { GradingOverview, GradingQuery } from '../../../../features/grading/GradingTypes';
44
import {
55
Assessment,
66
AssessmentOverview,
@@ -381,37 +381,61 @@ test('UPDATE_ASSESSMENT_OVERVIEWS works correctly in updating assessment overvie
381381
});
382382

383383
// Test data for UPDATE_GRADING
384-
const gradingTest1: Grading = [
385-
{
386-
question: jest.genMockFromModule('../../../../features/grading/GradingTypes'),
387-
student: {
388-
name: 'test student',
389-
username: 'E0123456',
390-
id: 234
391-
},
392-
grade: {
393-
xp: 100,
394-
xpAdjustment: 0,
395-
comments: 'Well done. Please try the quest!'
384+
const gradingTest1: GradingQuery = {
385+
answers: [
386+
{
387+
question: jest.genMockFromModule('../../../../features/grading/GradingTypes'),
388+
student: {
389+
name: 'test student',
390+
username: 'E0123456',
391+
id: 234
392+
},
393+
grade: {
394+
xp: 100,
395+
xpAdjustment: 0,
396+
comments: 'Well done. Please try the quest!'
397+
}
396398
}
399+
],
400+
assessment: {
401+
coverPicture: 'test string',
402+
id: 1,
403+
number: 'M1A',
404+
reading: 'test string',
405+
story: 'test string',
406+
summaryLong: 'test string',
407+
summaryShort: 'test string',
408+
title: 'test string'
397409
}
398-
];
410+
};
399411

400-
const gradingTest2: Grading = [
401-
{
402-
question: jest.genMockFromModule('../../../../features/grading/GradingTypes'),
403-
student: {
404-
name: 'another test student',
405-
username: 'E0000000',
406-
id: 345
407-
},
408-
grade: {
409-
xp: 500,
410-
xpAdjustment: 20,
411-
comments: 'Good job! All the best for the finals.'
412+
const gradingTest2: GradingQuery = {
413+
answers: [
414+
{
415+
question: jest.genMockFromModule('../../../../features/grading/GradingTypes'),
416+
student: {
417+
name: 'another test student',
418+
username: 'E0000000',
419+
id: 345
420+
},
421+
grade: {
422+
xp: 500,
423+
xpAdjustment: 20,
424+
comments: 'Good job! All the best for the finals.'
425+
}
412426
}
427+
],
428+
assessment: {
429+
coverPicture: 'another test string',
430+
id: 2,
431+
number: 'P2',
432+
reading: 'another test string',
433+
story: 'another test string',
434+
summaryLong: 'another test string',
435+
summaryShort: 'another test string',
436+
title: 'another test string'
413437
}
414-
];
438+
};
415439

416440
test('UPDATE_GRADING works correctly in inserting gradings', () => {
417441
const submissionId = 23;
@@ -423,14 +447,14 @@ test('UPDATE_GRADING works correctly in inserting gradings', () => {
423447
}
424448
};
425449

426-
const gradingMap: Map<number, Grading> = SessionsReducer(defaultSession, action).gradings;
450+
const gradingMap: Map<number, GradingQuery> = SessionsReducer(defaultSession, action).gradings;
427451
expect(gradingMap.get(submissionId)).toEqual(gradingTest1);
428452
});
429453

430454
test('UPDATE_GRADING works correctly in inserting gradings and retains old data', () => {
431455
const submissionId1 = 45;
432456
const submissionId2 = 56;
433-
const gradings = new Map<number, Grading>();
457+
const gradings = new Map<number, GradingQuery>();
434458
gradings.set(submissionId1, gradingTest1);
435459

436460
const newDefaultSession = {
@@ -446,14 +470,14 @@ test('UPDATE_GRADING works correctly in inserting gradings and retains old data'
446470
}
447471
};
448472

449-
const gradingMap: Map<number, Grading> = SessionsReducer(newDefaultSession, action).gradings;
473+
const gradingMap: Map<number, GradingQuery> = SessionsReducer(newDefaultSession, action).gradings;
450474
expect(gradingMap.get(submissionId1)).toEqual(gradingTest1);
451475
expect(gradingMap.get(submissionId2)).toEqual(gradingTest2);
452476
});
453477

454478
test('UPDATE_GRADING works correctly in updating gradings', () => {
455479
const submissionId = 23;
456-
const gradings = new Map<number, Grading>();
480+
const gradings = new Map<number, GradingQuery>();
457481
gradings.set(submissionId, gradingTest1);
458482
const newDefaultSession = {
459483
...defaultSession,
@@ -468,7 +492,7 @@ test('UPDATE_GRADING works correctly in updating gradings', () => {
468492
}
469493
};
470494

471-
const gradingMap: Map<number, Grading> = SessionsReducer(newDefaultSession, action).gradings;
495+
const gradingMap: Map<number, GradingQuery> = SessionsReducer(newDefaultSession, action).gradings;
472496
expect(gradingMap.get(submissionId)).toEqual(gradingTest2);
473497
});
474498

src/commons/application/types/SessionTypes.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { Octokit } from '@octokit/rest';
22
import { Chapter, Variant } from 'js-slang/dist/types';
33

4-
import { Grading, GradingOverview } from '../../../features/grading/GradingTypes';
4+
import { GradingOverview, GradingQuery } from '../../../features/grading/GradingTypes';
55
import { Device, DeviceSession } from '../../../features/remoteExecution/RemoteExecutionTypes';
66
import {
77
Assessment,
@@ -115,7 +115,7 @@ export type SessionState = {
115115
readonly assessmentOverviews?: AssessmentOverview[];
116116
readonly assessments: Map<number, Assessment>;
117117
readonly gradingOverviews?: GradingOverview[];
118-
readonly gradings: Map<number, Grading>;
118+
readonly gradings: Map<number, GradingQuery>;
119119
readonly notifications: Notification[];
120120
readonly googleUser?: string;
121121
readonly githubAssessment?: MissionRepoData;

0 commit comments

Comments
 (0)