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' ;
2
11
import { IconNames } from '@blueprintjs/icons' ;
3
12
import * as React from 'react' ;
4
13
5
14
import { InterpreterOutput , IWorkspaceState } from '../../reducers/states' ;
6
15
import { beforeNow } from '../../utils/dateHelpers' ;
7
16
import { history } from '../../utils/history' ;
8
17
import { assessmentCategoryLink } from '../../utils/paramParseHelpers' ;
18
+ import { controlButton } from '../commons' ;
9
19
import Markdown from '../commons/Markdown' ;
10
20
import Workspace , { WorkspaceProps } from '../workspace' ;
11
21
import { ControlBarProps } from '../workspace/ControlBar' ;
@@ -67,13 +77,15 @@ export type DispatchProps = {
67
77
68
78
class AssessmentWorkspace extends React . Component <
69
79
AssessmentWorkspaceProps ,
70
- { showOverlay : boolean }
80
+ { showOverlay : boolean ; showResetOverlay : boolean }
71
81
> {
72
82
public constructor ( props : AssessmentWorkspaceProps ) {
73
83
super ( props ) ;
74
84
this . state = {
75
- showOverlay : false
85
+ showOverlay : false ,
86
+ showResetOverlay : false
76
87
} ;
88
+ this . props . handleEditorValueChange ( '' ) ;
77
89
}
78
90
79
91
/**
@@ -86,6 +98,20 @@ class AssessmentWorkspace extends React.Component<
86
98
if ( this . props . questionId === 0 && this . props . notAttempted ) {
87
99
this . setState ( { showOverlay : true } ) ;
88
100
}
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
+ }
89
115
}
90
116
91
117
/**
@@ -119,24 +145,53 @@ class AssessmentWorkspace extends React.Component<
119
145
</ Card >
120
146
</ Dialog >
121
147
) ;
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
+ ) ;
122
183
/* If questionId is out of bounds, set it to the max. */
123
184
const questionId =
124
185
this . props . questionId >= this . props . assessment . questions . length
125
186
? this . props . assessment . questions . length - 1
126
187
: this . props . questionId ;
127
188
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 ;
134
189
const workspaceProps : WorkspaceProps = {
135
190
controlBarProps : this . controlBarProps ( this . props , questionId ) ,
136
191
editorProps :
137
192
question . type === QuestionTypes . programming
138
193
? {
139
- editorValue : editorValue ! ,
194
+ editorValue : this . props . editorValue ! ,
140
195
handleEditorEval : this . props . handleEditorEval ,
141
196
handleEditorValueChange : this . props . handleEditorValueChange ,
142
197
handleUpdateHasUnsavedChanges : this . props . handleUpdateHasUnsavedChanges
@@ -165,6 +220,7 @@ class AssessmentWorkspace extends React.Component<
165
220
return (
166
221
< div className = "WorkspaceParent pt-dark" >
167
222
{ overlay }
223
+ { resetOverlay }
168
224
< Workspace { ...workspaceProps } />
169
225
</ div >
170
226
) ;
@@ -194,7 +250,7 @@ class AssessmentWorkspace extends React.Component<
194
250
? question . answer !== null
195
251
? ( ( question as IProgrammingQuestion ) . answer as string )
196
252
: ( question as IProgrammingQuestion ) . solutionTemplate
197
- : null ;
253
+ : '' ;
198
254
this . props . handleUpdateCurrentAssessmentId ( assessmentId , questionId ) ;
199
255
this . props . handleResetWorkspace ( { editorValue } ) ;
200
256
this . props . handleClearContext ( question . library ) ;
@@ -286,6 +342,9 @@ class AssessmentWorkspace extends React.Component<
286
342
this . props . assessment ! . questions [ questionId ] . id ,
287
343
this . props . editorValue !
288
344
) ,
345
+ onClickReset : ( ) => {
346
+ this . setState ( { showResetOverlay : true } ) ;
347
+ } ,
289
348
questionProgress : [ questionId + 1 , this . props . assessment ! . questions . length ] ,
290
349
sourceChapter : this . props . assessment ! . questions [ questionId ] . library . chapter
291
350
} ;
0 commit comments