Skip to content

Commit 42b8271

Browse files
Game: Allow consistent, automatic switching between Game and Assessments (#3105)
* userstate.assessments.id and navigateToAssessment() now use the number field instead of id * Allow direct submission within AssessmentWorkspace when onSubmit == finish OR type == Visions * Rename onFinish flag from submit => submitAndReturnToGame * Rename and move isMinigame to assessment config in admin panel * Remove assessment console.log * Add isMinigame to a few more testcases... * removed notAttempted check * remove console log --------- Co-authored-by: Koh Wai Kei <[email protected]>
1 parent 8fa0650 commit 42b8271

File tree

16 files changed

+115
-11
lines changed

16 files changed

+115
-11
lines changed

public/assets/mockChapter0.txt

+6-6
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ objectives
44
finish
55

66
gameStartActions
7-
// replace 173 with assessment id
8-
show_dialogue(welcome) if userstate.assessments.173
9-
show_dialogue(unwelcome) if !userstate.assessments.173
7+
// replace S0 with assessment number
8+
show_dialogue(welcome) if userstate.assessments.S0
9+
show_dialogue(unwelcome) if !userstate.assessments.S0
1010

1111
checkpointCompleteActions
1212
show_dialogue(done)
@@ -96,8 +96,8 @@ dialogues
9696
1
9797
@scottie, sad
9898
You haven't finished assessment
99-
Finish assessment 173 first and come back?
100-
navigate_to_assessment(173)
99+
Finish assessment S0 first and come back?
100+
navigate_to_assessment(S0)
101101
goto 2
102102
2
103103
@scottie
@@ -113,7 +113,7 @@ dialogues
113113
Hmmm
114114
update_assessment_status*()
115115
Let me check
116-
goto 1 if !userstate.assessments.173 else 3
116+
goto 1 if !userstate.assessments.S0 else 3
117117

118118
what, What should I do now, Scottie?
119119
@you

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

+10
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,7 @@ test('setAssessmentConfigurations generates correct action object', () => {
264264
isManuallyGraded: true,
265265
isGradingAutoPublished: false,
266266
displayInDashboard: true,
267+
isMinigame: false,
267268
hasTokenCounter: false,
268269
hasVotingFeatures: false,
269270
hoursBeforeEarlyXpDecay: 48,
@@ -275,6 +276,7 @@ test('setAssessmentConfigurations generates correct action object', () => {
275276
isManuallyGraded: true,
276277
isGradingAutoPublished: false,
277278
displayInDashboard: true,
279+
isMinigame: false,
278280
hasTokenCounter: false,
279281
hasVotingFeatures: false,
280282
hoursBeforeEarlyXpDecay: 48,
@@ -286,6 +288,7 @@ test('setAssessmentConfigurations generates correct action object', () => {
286288
isManuallyGraded: true,
287289
isGradingAutoPublished: false,
288290
displayInDashboard: true,
291+
isMinigame: false,
289292
hasTokenCounter: false,
290293
hasVotingFeatures: false,
291294
hoursBeforeEarlyXpDecay: 48,
@@ -714,6 +717,7 @@ test('updateAssessmentTypes generates correct action object', () => {
714717
isManuallyGraded: true,
715718
isGradingAutoPublished: false,
716719
displayInDashboard: true,
720+
isMinigame: false,
717721
hasTokenCounter: false,
718722
hasVotingFeatures: false,
719723
hoursBeforeEarlyXpDecay: 48,
@@ -725,6 +729,7 @@ test('updateAssessmentTypes generates correct action object', () => {
725729
isManuallyGraded: true,
726730
isGradingAutoPublished: false,
727731
displayInDashboard: true,
732+
isMinigame: false,
728733
hasTokenCounter: false,
729734
hasVotingFeatures: false,
730735
hoursBeforeEarlyXpDecay: 48,
@@ -736,6 +741,7 @@ test('updateAssessmentTypes generates correct action object', () => {
736741
isManuallyGraded: false,
737742
isGradingAutoPublished: true,
738743
displayInDashboard: true,
744+
isMinigame: false,
739745
hasTokenCounter: false,
740746
hasVotingFeatures: false,
741747
hoursBeforeEarlyXpDecay: 48,
@@ -747,6 +753,7 @@ test('updateAssessmentTypes generates correct action object', () => {
747753
isManuallyGraded: true,
748754
isGradingAutoPublished: false,
749755
displayInDashboard: true,
756+
isMinigame: false,
750757
hasTokenCounter: false,
751758
hasVotingFeatures: false,
752759
hoursBeforeEarlyXpDecay: 48,
@@ -758,6 +765,7 @@ test('updateAssessmentTypes generates correct action object', () => {
758765
isManuallyGraded: false,
759766
isGradingAutoPublished: false,
760767
displayInDashboard: true,
768+
isMinigame: false,
761769
hasTokenCounter: false,
762770
hasVotingFeatures: false,
763771
hoursBeforeEarlyXpDecay: 0,
@@ -769,6 +777,7 @@ test('updateAssessmentTypes generates correct action object', () => {
769777
isManuallyGraded: true,
770778
isGradingAutoPublished: false,
771779
displayInDashboard: true,
780+
isMinigame: false,
772781
hasTokenCounter: false,
773782
hasVotingFeatures: false,
774783
hoursBeforeEarlyXpDecay: 48,
@@ -789,6 +798,7 @@ test('deleteAssessmentConfig generates correct action object', () => {
789798
isManuallyGraded: true,
790799
isGradingAutoPublished: false,
791800
displayInDashboard: true,
801+
isMinigame: false,
792802
hasTokenCounter: false,
793803
hasVotingFeatures: false,
794804
hoursBeforeEarlyXpDecay: 48,

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

+3
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,7 @@ test('SET_ASSESSMENT_CONFIGURATIONS works correctly', () => {
147147
isManuallyGraded: false,
148148
isGradingAutoPublished: false,
149149
displayInDashboard: true,
150+
isMinigame: false,
150151
hasTokenCounter: false,
151152
hasVotingFeatures: false
152153
},
@@ -161,6 +162,7 @@ test('SET_ASSESSMENT_CONFIGURATIONS works correctly', () => {
161162
isManuallyGraded: false,
162163
isGradingAutoPublished: false,
163164
displayInDashboard: true,
165+
isMinigame: false,
164166
hasTokenCounter: false,
165167
hasVotingFeatures: false
166168
},
@@ -175,6 +177,7 @@ test('SET_ASSESSMENT_CONFIGURATIONS works correctly', () => {
175177
isManuallyGraded: false,
176178
isGradingAutoPublished: false,
177179
displayInDashboard: true,
180+
isMinigame: false,
178181
hasTokenCounter: false,
179182
hasVotingFeatures: false
180183
}

src/commons/assessment/AssessmentTypes.ts

+2
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ export type Assessment = {
9292
globalDeployment?: Library; // For mission control
9393
graderDeployment?: Library; // For mission control
9494
hasTokenCounter?: boolean;
95+
isMinigame?: boolean;
9596
id: number;
9697
longSummary: string;
9798
missionPDF: string;
@@ -105,6 +106,7 @@ export type AssessmentConfiguration = {
105106
isManuallyGraded: boolean;
106107
isGradingAutoPublished: boolean;
107108
displayInDashboard: boolean;
109+
isMinigame: boolean;
108110
hoursBeforeEarlyXpDecay: number;
109111
earlySubmissionXp: number;
110112
hasTokenCounter: boolean;

src/commons/assessment/__tests__/Assessment.tsx

+1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ const mockAssessmentConfig: AssessmentConfiguration = {
1717
isManuallyGraded: true,
1818
isGradingAutoPublished: false,
1919
displayInDashboard: true,
20+
isMinigame: false,
2021
hasTokenCounter: false,
2122
hasVotingFeatures: false,
2223
hoursBeforeEarlyXpDecay: 48,

src/commons/assessmentWorkspace/AssessmentWorkspace.tsx

+24
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ const AssessmentWorkspace: React.FC<AssessmentWorkspaceProps> = props => {
9494
const [isSaving, setIsSaving] = useState(false);
9595
const [showResetTemplateOverlay, setShowResetTemplateOverlay] = useState(false);
9696
const [sessionId, setSessionId] = useState('');
97+
const [isSubmitted, setIsSubmitted] = useState(false);
9798
const { isMobileBreakpoint } = useResponsive();
9899

99100
const assessment = useTypedSelector(state => state.session.assessments[props.assessmentId]);
@@ -600,6 +601,10 @@ const AssessmentWorkspace: React.FC<AssessmentWorkspaceProps> = props => {
600601
setSelectedTab(SideContentType.questionOverview);
601602
};
602603
const onClickReturn = () => navigate(listingPath);
604+
const onClickSubmit = () => {
605+
dispatch(SessionActions.submitAssessment(assessment.id));
606+
setIsSubmitted(true);
607+
};
603608

604609
const onClickSave = () => {
605610
if (isSaving) return;
@@ -664,8 +669,14 @@ const AssessmentWorkspace: React.FC<AssessmentWorkspaceProps> = props => {
664669
? onClickProgress(onClickReturn, question, editorTestcases, isBlocked)
665670
: onClickReturn
666671
}
672+
onClickSubmit={
673+
question.blocking
674+
? onClickProgress(onClickSubmit, question, editorTestcases, isBlocked)
675+
: onClickSubmit
676+
}
667677
questionProgress={questionProgress}
668678
key="next_question"
679+
submitOnFinish={assessment.isMinigame}
669680
/>
670681
);
671682

@@ -834,6 +845,18 @@ const AssessmentWorkspace: React.FC<AssessmentWorkspaceProps> = props => {
834845
</Dialog>
835846
);
836847

848+
const submissionOverlay = (
849+
<Dialog className="assessment-briefing" isOpen={isSubmitted}>
850+
<Card>
851+
<Markdown
852+
content={`## ${assessment.type.substring(0, assessment.type.length - 1)} complete!
853+
You've successfully submitted this ${assessment.type.substring(0, assessment.type.length - 1)}!
854+
It is safe to close this window.`}
855+
/>
856+
</Card>
857+
</Dialog>
858+
);
859+
837860
const closeOverlay = () => setShowResetTemplateOverlay(false);
838861
const resetTemplateOverlay = (
839862
<Dialog
@@ -942,6 +965,7 @@ const AssessmentWorkspace: React.FC<AssessmentWorkspaceProps> = props => {
942965
};
943966
return (
944967
<div className={classNames('WorkspaceParent', Classes.DARK)}>
968+
{submissionOverlay}
945969
{overlay}
946970
{resetTemplateOverlay}
947971
{!isMobileBreakpoint ? (

src/commons/assessmentWorkspace/__tests__/AssessmentWorkspace.tsx

+1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ const defaultProps = assertType<AssessmentWorkspaceProps>()({
2121
isManuallyGraded: true,
2222
isGradingAutoPublished: false,
2323
displayInDashboard: true,
24+
isMinigame: false,
2425
hasTokenCounter: false,
2526
hasVotingFeatures: false,
2627
hoursBeforeEarlyXpDecay: 48,

src/commons/controlBar/ControlBarNextButton.tsx

+8-1
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,29 @@ import React from 'react';
33

44
import ControlButton from '../ControlButton';
55
import { ControlBarReturnToAcademyButton } from './ControlBarReturnToAcademyButton';
6+
import { ControlBarSubmit } from './ControlBarSubmit';
67

78
type ControlBarNextButtonProps = DispatchProps & StateProps;
89

910
type DispatchProps = {
1011
onClickNext?(): any;
1112
onClickReturn?(): any;
13+
onClickSubmit?(): any;
1214
};
1315

1416
type StateProps = {
1517
key: string;
1618
questionProgress: [number, number] | null;
19+
submitOnFinish?: boolean;
1720
};
1821

1922
export const ControlBarNextButton: React.FC<ControlBarNextButtonProps> = props => {
2023
return props.questionProgress![0] === props.questionProgress![1] ? (
21-
<ControlBarReturnToAcademyButton onClick={props.onClickReturn} key="return_to_academy" />
24+
props.submitOnFinish ? (
25+
<ControlBarSubmit onClick={props.onClickSubmit} />
26+
) : (
27+
<ControlBarReturnToAcademyButton onClick={props.onClickReturn} key="return_to_academy" />
28+
)
2229
) : (
2330
<ControlButton
2431
label="Next"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import { IconNames } from '@blueprintjs/icons';
2+
import React from 'react';
3+
4+
import ControlButton from '../ControlButton';
5+
6+
type Props = {
7+
onClick?(): any;
8+
};
9+
10+
export const ControlBarSubmit: React.FC<Props> = ({ onClick }) => {
11+
return (
12+
<ControlButton
13+
label="Submit"
14+
icon={IconNames.ARROW_RIGHT}
15+
onClick={onClick}
16+
options={{ iconOnRight: true }}
17+
/>
18+
);
19+
};

src/commons/mocks/AssessmentMocks.ts

+8
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ export const mockAssessmentConfigurations: AssessmentConfiguration[][] = [
2121
isManuallyGraded: true,
2222
isGradingAutoPublished: false,
2323
displayInDashboard: true,
24+
isMinigame: false,
2425
hoursBeforeEarlyXpDecay: 48,
2526
hasTokenCounter: false,
2627
hasVotingFeatures: false,
@@ -32,6 +33,7 @@ export const mockAssessmentConfigurations: AssessmentConfiguration[][] = [
3233
isManuallyGraded: true,
3334
isGradingAutoPublished: false,
3435
displayInDashboard: true,
36+
isMinigame: false,
3537
hoursBeforeEarlyXpDecay: 48,
3638
hasTokenCounter: false,
3739
hasVotingFeatures: false,
@@ -43,6 +45,7 @@ export const mockAssessmentConfigurations: AssessmentConfiguration[][] = [
4345
isManuallyGraded: false,
4446
isGradingAutoPublished: true,
4547
displayInDashboard: true,
48+
isMinigame: false,
4649
hoursBeforeEarlyXpDecay: 48,
4750
hasTokenCounter: false,
4851
hasVotingFeatures: false,
@@ -54,6 +57,7 @@ export const mockAssessmentConfigurations: AssessmentConfiguration[][] = [
5457
isManuallyGraded: true,
5558
isGradingAutoPublished: false,
5659
displayInDashboard: true,
60+
isMinigame: false,
5761
hoursBeforeEarlyXpDecay: 48,
5862
hasTokenCounter: false,
5963
hasVotingFeatures: true,
@@ -65,6 +69,7 @@ export const mockAssessmentConfigurations: AssessmentConfiguration[][] = [
6569
isManuallyGraded: true,
6670
isGradingAutoPublished: false,
6771
displayInDashboard: true,
72+
isMinigame: false,
6873
hoursBeforeEarlyXpDecay: 48,
6974
hasTokenCounter: false,
7075
hasVotingFeatures: false,
@@ -78,6 +83,7 @@ export const mockAssessmentConfigurations: AssessmentConfiguration[][] = [
7883
isManuallyGraded: true,
7984
isGradingAutoPublished: false,
8085
displayInDashboard: true,
86+
isMinigame: false,
8187
hoursBeforeEarlyXpDecay: 48,
8288
hasTokenCounter: false,
8389
hasVotingFeatures: false,
@@ -89,6 +95,7 @@ export const mockAssessmentConfigurations: AssessmentConfiguration[][] = [
8995
isManuallyGraded: true,
9096
isGradingAutoPublished: false,
9197
displayInDashboard: true,
98+
isMinigame: false,
9299
hoursBeforeEarlyXpDecay: 48,
93100
hasTokenCounter: false,
94101
hasVotingFeatures: false,
@@ -100,6 +107,7 @@ export const mockAssessmentConfigurations: AssessmentConfiguration[][] = [
100107
isManuallyGraded: true,
101108
isGradingAutoPublished: false,
102109
displayInDashboard: true,
110+
isMinigame: false,
103111
hoursBeforeEarlyXpDecay: 48,
104112
hasTokenCounter: false,
105113
hasVotingFeatures: false,

src/commons/profile/__tests__/Profile.tsx

+1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ const assessmentConfigurations: AssessmentConfiguration[] = [
2626
isManuallyGraded: false,
2727
isGradingAutoPublished: false,
2828
displayInDashboard: false,
29+
isMinigame: false,
2930
hasTokenCounter: false,
3031
hasVotingFeatures: false,
3132
hoursBeforeEarlyXpDecay: 0,

src/commons/sagas/BackendSaga.ts

+1
Original file line numberDiff line numberDiff line change
@@ -957,6 +957,7 @@ const newBackendSagaTwo = combineSagaHandlers(sagaActions, {
957957
isManuallyGraded: true,
958958
isGradingAutoPublished: false,
959959
displayInDashboard: true,
960+
isMinigame: false,
960961
hoursBeforeEarlyXpDecay: 0,
961962
hasTokenCounter: false,
962963
hasVotingFeatures: false,

0 commit comments

Comments
 (0)