|
1 | 1 | import*asTfrom'typings'
|
2 | 2 | import*asTTfrom'typings/tutorial'
|
3 | 3 |
|
4 |
| -interfaceProps{ |
| 4 | +interfaceInput{ |
5 | 5 | progress:T.Progress
|
6 | 6 | position:T.Position
|
7 | 7 | levels:TT.Level[]
|
8 | 8 | testStatus:T.TestStatus|null
|
9 | 9 | }
|
10 | 10 |
|
| 11 | +typeOutput={ |
| 12 | +level:T.LevelUI |
| 13 | +stepIndex:number |
| 14 | +} |
| 15 | + |
11 | 16 | /*
|
12 | 17 | * Format levels to include:
|
13 | 18 | * - level.status = 'ACTIVE' | 'COMPLETE' | 'INCOMPLETE'
|
14 | 19 | * - step.status = 'ACTIVE' | 'COMPLETE' | 'INCOMPLETE' | 'FAIL'
|
15 |
| - * - step.subtasks as { name: string,pass: boolean }[] |
| 20 | + * - step.subtasks as { name: string,status: 'ACTIVE' | 'COMPLETE' | 'INCOMPLETE' }[] |
16 | 21 | */
|
17 |
| -constformatLevels=({ |
18 |
| - progress, |
19 |
| - position, |
20 |
| - levels, |
21 |
| - testStatus, |
22 |
| -}:Props):{levels:TT.Level[];level:TT.Level;stepIndex:number}=>{ |
| 22 | +constformatLevels=({ progress, position, levels, testStatus}:Input):Output=>{ |
23 | 23 | // clone levels
|
24 |
| -constformattedLevels=[...levels] |
25 | 24 |
|
26 |
| -constlevel=formattedLevels.find((l:TT.Level)=>l.id===position.levelId) |
| 25 | +constlevel:TT.Level|undefined=levels.find((l:TT.Level)=>l.id===position.levelId) |
27 | 26 |
|
28 | 27 | if(!level){
|
29 |
| -thrownewError(`Level"${position.levelId}" not found`) |
| 28 | +thrownewError(`Level${position.levelId} not found`) |
30 | 29 | }
|
31 | 30 |
|
32 |
| -// add level status |
33 |
| -level.status=progress.levels[position.levelId] ?'COMPLETE' :'ACTIVE' |
34 |
| - |
35 |
| -// add step status |
36 |
| -level.steps=level.steps.map((step:TT.Step)=>{ |
37 |
| -// label step status for step component |
38 |
| -letstatus:T.ProgressStatus='INCOMPLETE' |
39 |
| -if(progress.steps[step.id]){ |
40 |
| -status='COMPLETE' |
41 |
| -}elseif(step.id===position.stepId){ |
42 |
| -status='ACTIVE' |
43 |
| -if(step.subtasks&&step.subtasks){ |
44 |
| -step.subtasks.map((subtask:string,subtaskIndex:number)=>({ |
45 |
| -name:subtask, |
46 |
| -pass:!!(testStatus?.summary ?testStatus.summary[subtaskIndex] :false), |
47 |
| -})) |
| 31 | +constlevelUI:T.LevelUI={ |
| 32 | + ...level, |
| 33 | +status:progress.levels[position.levelId] ?'COMPLETE' :'ACTIVE', |
| 34 | +steps:level.steps.map((step:TT.Step)=>{ |
| 35 | +// label step status for step component |
| 36 | +letstatus:T.ProgressStatus='INCOMPLETE' |
| 37 | +letsubtasks |
| 38 | +if(progress.steps[step.id]){ |
| 39 | +status='COMPLETE' |
| 40 | +}elseif(step.id===position.stepId){ |
| 41 | +status='ACTIVE' |
| 42 | +if(step.subtasks&&step.subtasks){ |
| 43 | +subtasks=step.subtasks.map((subtask:string,subtaskIndex:number)=>{ |
| 44 | +letsubtaskStatus:T.ProgressStatus='INCOMPLETE' |
| 45 | +// task is complete, subtasks must be complete |
| 46 | +if(status==='COMPLETE'){ |
| 47 | +subtaskStatus='COMPLETE' |
| 48 | +// task is active, check which are complete from test results |
| 49 | +}elseif(status==='ACTIVE'){ |
| 50 | +subtaskStatus=!!(testStatus?.summary&&testStatus.summary[subtaskIndex]) ?'COMPLETE' :'ACTIVE' |
| 51 | +} |
| 52 | +return{ |
| 53 | +name:subtask, |
| 54 | +status:subtaskStatus, |
| 55 | +} |
| 56 | +}) |
| 57 | +} |
48 | 58 | }
|
49 |
| -} |
50 |
| -return{ ...step, status} |
51 |
| -}) |
52 |
| - |
53 |
| -letstepIndex=level.steps.findIndex((s:TT.Step)=>s.status==='ACTIVE') |
| 59 | +return{ ...step, status, subtasks} |
| 60 | +}), |
| 61 | +} |
| 62 | +letstepIndex=levelUI.steps.findIndex((s:T.StepUI)=>s.status==='ACTIVE') |
54 | 63 | if(stepIndex===-1){
|
55 | 64 | stepIndex=level.steps.length
|
56 | 65 | }
|
57 |
| -return{levels:formattedLevels, level, stepIndex} |
| 66 | +return{level:levelUI, stepIndex} |
58 | 67 | }
|
59 | 68 |
|
60 | 69 | exportdefaultformatLevels
|