1- import { Button , Card , Dialog , NonIdealState , Spinner } from '@blueprintjs/core'
1+ import {
2+ Button ,
3+ ButtonGroup ,
4+ Card ,
5+ Classes ,
6+ Dialog ,
7+ Intent ,
8+ NonIdealState ,
9+ Spinner
10+ } from '@blueprintjs/core'
211import { IconNames } from '@blueprintjs/icons'
312import * as React from 'react'
413
514import { InterpreterOutput , IWorkspaceState } from '../../reducers/states'
615import { beforeNow } from '../../utils/dateHelpers'
716import { history } from '../../utils/history'
817import { assessmentCategoryLink } from '../../utils/paramParseHelpers'
18+ import { controlButton } from '../commons'
919import Markdown from '../commons/Markdown'
1020import Workspace , { WorkspaceProps } from '../workspace'
1121import { ControlBarProps } from '../workspace/ControlBar'
@@ -67,13 +77,15 @@ export type DispatchProps = {
6777
6878class AssessmentWorkspace extends React . Component <
6979 AssessmentWorkspaceProps ,
70- { showOverlay : boolean }
80+ { showOverlay : boolean ; showResetOverlay : boolean }
7181> {
7282 public constructor ( props : AssessmentWorkspaceProps ) {
7383 super ( props )
7484 this . state = {
75- showOverlay : false
85+ showOverlay : false ,
86+ showResetOverlay : false
7687 }
88+ this . props . handleEditorValueChange ( '' )
7789 }
7890
7991 /**
@@ -86,6 +98,20 @@ class AssessmentWorkspace extends React.Component<
8698 if ( this . props . questionId === 0 && this . props . notAttempted ) {
8799 this . setState ( { showOverlay : true } )
88100 }
101+ if ( this . props . assessment ) {
102+ const question : IQuestion = this . props . assessment . questions [
103+ this . props . questionId >= this . props . assessment . questions . length
104+ ? this . props . assessment . questions . length - 1
105+ : this . props . questionId
106+ ]
107+ this . props . handleEditorValueChange (
108+ question . type === QuestionTypes . programming
109+ ? question . answer !== null
110+ ? ( ( question as IProgrammingQuestion ) . answer as string )
111+ : ( question as IProgrammingQuestion ) . solutionTemplate
112+ : ''
113+ )
114+ }
89115 }
90116
91117 /**
@@ -119,24 +145,53 @@ class AssessmentWorkspace extends React.Component<
119145 </ Card >
120146 </ Dialog >
121147 )
148+
149+ const resetOverlay = (
150+ < Dialog
151+ className = "assessment-reset"
152+ icon = { IconNames . ERROR }
153+ isCloseButtonShown = { false }
154+ isOpen = { this . state . showResetOverlay }
155+ title = "Confirmation: Reset editor?"
156+ >
157+ < div className = { Classes . DIALOG_BODY } >
158+ < Markdown content = "Are you sure you want to reset the template?" />
159+ < Markdown content = "*Note this will not affect the saved copy of your code, unless you save over it.*" />
160+ </ div >
161+ < div className = { Classes . DIALOG_FOOTER } >
162+ < ButtonGroup >
163+ { controlButton ( 'Cancel' , null , ( ) => this . setState ( { showResetOverlay : false } ) , {
164+ minimal : false
165+ } ) }
166+ { controlButton (
167+ 'Confirm' ,
168+ null ,
169+ ( ) => {
170+ this . setState ( { showResetOverlay : false } )
171+ this . props . handleEditorValueChange (
172+ ( this . props . assessment ! . questions [ questionId ] as IProgrammingQuestion )
173+ . solutionTemplate
174+ )
175+ this . props . handleUpdateHasUnsavedChanges ( true )
176+ } ,
177+ { minimal : false , intent : Intent . DANGER }
178+ ) }
179+ </ ButtonGroup >
180+ </ div >
181+ </ Dialog >
182+ )
122183 /* If questionId is out of bounds, set it to the max. */
123184 const questionId =
124185 this . props . questionId >= this . props . assessment . questions . length
125186 ? this . props . assessment . questions . length - 1
126187 : this . props . questionId
127188 const question : IQuestion = this . props . assessment . questions [ questionId ]
128- const editorValue =
129- question . type === QuestionTypes . programming
130- ? question . answer !== null
131- ? ( ( question as IProgrammingQuestion ) . answer as string )
132- : ( question as IProgrammingQuestion ) . solutionTemplate
133- : null
134189 const workspaceProps : WorkspaceProps = {
135190 controlBarProps : this . controlBarProps ( this . props , questionId ) ,
136191 editorProps :
137192 question . type === QuestionTypes . programming
138193 ? {
139- editorValue : editorValue ! ,
194+ editorValue : this . props . editorValue ! ,
140195 handleEditorEval : this . props . handleEditorEval ,
141196 handleEditorValueChange : this . props . handleEditorValueChange ,
142197 handleUpdateHasUnsavedChanges : this . props . handleUpdateHasUnsavedChanges
@@ -165,6 +220,7 @@ class AssessmentWorkspace extends React.Component<
165220 return (
166221 < div className = "WorkspaceParent pt-dark" >
167222 { overlay }
223+ { resetOverlay }
168224 < Workspace { ...workspaceProps } />
169225 </ div >
170226 )
@@ -194,7 +250,7 @@ class AssessmentWorkspace extends React.Component<
194250 ? question . answer !== null
195251 ? ( ( question as IProgrammingQuestion ) . answer as string )
196252 : ( question as IProgrammingQuestion ) . solutionTemplate
197- : null
253+ : ''
198254 this . props . handleUpdateCurrentAssessmentId ( assessmentId , questionId )
199255 this . props . handleResetWorkspace ( { editorValue } )
200256 this . props . handleClearContext ( question . library )
@@ -285,6 +341,9 @@ class AssessmentWorkspace extends React.Component<
285341 this . props . assessment ! . questions [ questionId ] . id ,
286342 this . props . editorValue !
287343 ) ,
344+ onClickReset : ( ) => {
345+ this . setState ( { showResetOverlay : true } )
346+ } ,
288347 questionProgress : [ questionId + 1 , this . props . assessment ! . questions . length ] ,
289348 sourceChapter : this . props . assessment ! . questions [ questionId ] . library . chapter
290349 }
0 commit comments