11import React from "react" ;
2- import { e } from "react-router/dist/production/fog-of-war-BLArG-qZ" ;
32
43export function ProblemInitialState ( ) {
54 return {
@@ -61,7 +60,10 @@ export function ProblemReducer(problem, action) {
6160 return p
6261
6362 case "add_group" :
64- p . test_groups . push ( { } )
63+ p . test_groups . push ( {
64+ "scoring_type" : 1 ,
65+ "feedback_type" : 3 ,
66+ } )
6567 return p
6668
6769 case "group" :
@@ -84,15 +86,21 @@ export function ProblemReducer(problem, action) {
8486 if ( newScoringType !== 1 ) {
8587 removeRequired ( idx )
8688 }
89+ p . test_groups [ idx ] [ action . groupAction ] = newScoringType
90+ return p
8791
8892 // Score fields
89- case "score " :
93+ case "group_score " :
9094 case "test_score" :
91- delete p . test_groups [ idx ] [ "score" ]
95+ console . log ( action )
96+ delete p . test_groups [ idx ] [ "group_score" ]
9297 delete p . test_groups [ idx ] [ "test_score" ]
93- if ( action . value !== "" ) {
94- p [ action . groupAction ] = parseFloat ( action . value )
98+ if ( action . value === "" ) {
99+ delete p . test_groups [ idx ] [ action . groupAction ]
100+ } else {
101+ p . test_groups [ idx ] [ action . groupAction ] = parseFloat ( action . value )
95102 }
103+ console . log ( p )
96104 return p
97105
98106 case "add_required" :
@@ -178,7 +186,7 @@ export function RenderProblemForm(
178186 < option value = "" key = "none" > </ option >
179187 ) }
180188 { values . map ( ( value , index ) => (
181- < option key = { index } value = { value . value } > value.name</ option >
189+ < option key = { index } value = { value . value } > { value . name } </ option >
182190 ) ) }
183191 </ select >
184192 </ div >
@@ -217,23 +225,31 @@ function renderGroups(problem, changeProblem) {
217225 return null
218226 }
219227 return (
220- < table >
221- < thead >
222- < tr >
223- < th scope = "row" > Name</ th >
224- < th scope = "row" > First test</ th >
225- < th scope = "row" > Last test</ th >
226- < th scope = "row" > Score</ th >
227- < th scope = "row" > Scoring Type</ th >
228- < th scope = "row" > Feedback Type</ th >
229- < th scope = "row" > Required</ th >
230- < th scope = "row" > Delete</ th >
231- </ tr >
232- </ thead >
233- < tbody >
234- { problem . test_groups . map ( ( group , index ) => renderGroup ( group , index , problem , changeProblem ) ) }
235- </ tbody >
236- </ table >
228+ < >
229+ < table className = "table table-striped" >
230+ < thead >
231+ < tr >
232+ < th style = { { width : "10%" } } scope = "row" > Name</ th >
233+ < th style = { { width : "10%" } } scope = "row" > First test</ th >
234+ < th style = { { width : "10%" } } scope = "row" > Last test</ th >
235+ < th style = { { width : "10%" } } scope = "row" > Score</ th >
236+ < th style = { { width : "10%" } } scope = "row" > Scoring Type</ th >
237+ < th style = { { width : "10%" } } scope = "row" > Feedback Type</ th >
238+ < th style = { { width : "30%" } } scope = "row" > Required</ th >
239+ < th style = { { width : "10%" } } scope = "row" > Delete</ th >
240+ </ tr >
241+ </ thead >
242+ < tbody >
243+ { problem . test_groups . map ( ( group , index ) => renderGroup ( group , index , problem , changeProblem ) ) }
244+ </ tbody >
245+ </ table >
246+ < a href = "#" onClick = { ( e ) => {
247+ e . preventDefault ( ) ;
248+ changeProblem ( {
249+ action : "add_group" ,
250+ } )
251+ } } > Add group</ a >
252+ </ >
237253 )
238254}
239255
@@ -246,7 +262,7 @@ function renderGroup(group, index, problem, changeProblem) {
246262 name = { name }
247263 type = { type }
248264 required = { required }
249- value = { group [ name ] || "" }
265+ value = { group [ name ] == null ? "" : group [ name ] }
250266 onChange = { ( e ) => {
251267 changeProblem ( {
252268 action : "group" ,
@@ -288,9 +304,9 @@ function renderGroup(group, index, problem, changeProblem) {
288304 { tableInput ( "first_test" , "number" , true ) }
289305 { tableInput ( "last_test" , "number" , true ) }
290306 { group . scoring_type === 2 ? (
291- tableInput ( "test_score" , "number" , true , "Test score" )
307+ tableInput ( "test_score" , "number" , true )
292308 ) : (
293- tableInput ( "test_score " , "number" , true , "Group score" )
309+ tableInput ( "group_score " , "number" , true )
294310 ) }
295311 { tableSelect ( "scoring_type" , [
296312 { value : 1 , name : "Complete" } ,
@@ -311,7 +327,7 @@ function renderGroup(group, index, problem, changeProblem) {
311327 changeProblem ( {
312328 action : "group" ,
313329 groupIndex : index ,
314- groupAction : "delete " ,
330+ groupAction : "remove " ,
315331 } )
316332 } } > Delete</ a >
317333 </ td >
@@ -323,7 +339,7 @@ function renderRequiredGroups(group, index, problem, changeProblem) {
323339 let canAdd = [ ]
324340 for ( let i = 0 ; i < index ; i ++ ) {
325341 const gName = problem . test_groups [ i ] . name
326- if ( problem . test_groups [ i ] . scoring_type === 1 || ! required . includes ( gName ) ) {
342+ if ( problem . test_groups [ i ] . scoring_type === 1 && ! required . includes ( gName ) ) {
327343 canAdd . push ( gName )
328344 }
329345 }
0 commit comments