Skip to content

Commit 4b73361

Browse files
authored
Fix 0-based task number (#370)
* Use typescript tuple type for question progress * Use questionProgress prop in workspace parents * Use questionProgress in ControlBar * Revert ControlBarProps order This was causing problems with the order of private properties (some tslint thing) This reverts commit f278e6e. * Fix props order * Fix 0-index usage * Format and update tests
1 parent be80458 commit 4b73361

File tree

5 files changed

+34
-36
lines changed

5 files changed

+34
-36
lines changed

src/components/Playground.tsx

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,9 +80,6 @@ class Playground extends React.Component<IPlaygroundProps, PlaygroundState> {
8080
public render() {
8181
const workspaceProps: WorkspaceProps = {
8282
controlBarProps: {
83-
hasAssessment: false,
84-
currentQuestion: 0,
85-
assessmentLength: 0,
8683
externalLibraryName: this.props.externalLibraryName,
8784
handleChapterSelect: ({ chapter }: { chapter: number }, e: any) =>
8885
this.props.handleChapterSelect(chapter),
@@ -98,6 +95,7 @@ class Playground extends React.Component<IPlaygroundProps, PlaygroundState> {
9895
hasShareButton: true,
9996
isRunning: this.props.isRunning,
10097
queryString: this.props.queryString,
98+
questionProgress: null,
10199
sourceChapter: this.props.sourceChapter
102100
},
103101
editorProps: {

src/components/academy/grading/GradingWorkspace.tsx

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ class GradingWorkspace extends React.Component<GradingWorkspaceProps> {
198198
)
199199
},
200200
{
201-
label: `Task ${questionId}`,
201+
label: `Task ${questionId + 1}`,
202202
icon: IconNames.NINJA,
203203
body: <Markdown content={props.grading![questionId].question.content} />
204204
}
@@ -213,9 +213,6 @@ class GradingWorkspace extends React.Component<GradingWorkspaceProps> {
213213
const listingPath = `/academy/grading`
214214
const gradingWorkspacePath = listingPath + `/${this.props.submissionId}`
215215
return {
216-
hasAssessment: true,
217-
currentQuestion: questionId + 1,
218-
assessmentLength: this.props.grading!.length,
219216
handleChapterSelect: this.props.handleChapterSelect,
220217
handleEditorEval: this.props.handleEditorEval,
221218
handleInterruptEval: this.props.handleInterruptEval,
@@ -228,6 +225,7 @@ class GradingWorkspace extends React.Component<GradingWorkspaceProps> {
228225
onClickNext: () => history.push(gradingWorkspacePath + `/${(questionId + 1).toString()}`),
229226
onClickPrevious: () => history.push(gradingWorkspacePath + `/${(questionId - 1).toString()}`),
230227
onClickReturn: () => history.push(listingPath),
228+
questionProgress: [questionId + 1, this.props.grading!.length],
231229
sourceChapter: this.props.grading![questionId].question.library.chapter
232230
}
233231
}

src/components/assessment/AssessmentWorkspace.tsx

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ class AssessmentWorkspace extends React.Component<
211211
) => {
212212
const tabs = [
213213
{
214-
label: `Task ${questionId}`,
214+
label: `Task ${questionId + 1}`,
215215
icon: IconNames.NINJA,
216216
body: <Markdown content={props.assessment!.questions[questionId].content} />
217217
},
@@ -253,9 +253,6 @@ class AssessmentWorkspace extends React.Component<
253253
const listingPath = `/academy/${assessmentCategoryLink(this.props.assessment!.category)}`
254254
const assessmentWorkspacePath = listingPath + `/${this.props.assessment!.id.toString()}`
255255
return {
256-
hasAssessment: true,
257-
currentQuestion: questionId + 1,
258-
assessmentLength: this.props.assessment!.questions.length,
259256
handleChapterSelect: this.props.handleChapterSelect,
260257
handleEditorEval: this.props.handleEditorEval,
261258
handleInterruptEval: this.props.handleInterruptEval,
@@ -277,6 +274,7 @@ class AssessmentWorkspace extends React.Component<
277274
this.props.assessment!.questions[questionId].id,
278275
this.props.editorValue!
279276
),
277+
questionProgress: [questionId + 1, this.props.assessment!.questions.length],
280278
sourceChapter: this.props.assessment!.questions[questionId].library.chapter
281279
}
282280
}

src/components/assessment/__tests__/__snapshots__/index.tsx.snap

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ exports[`Assessment page does not show attempt Button for upcoming assessments f
136136
<path d=\\"M8 0C3.58 0 0 3.58 0 8s3.58 8 8 8 8-3.58 8-8-3.58-8-8-8zm0 14c-3.31 0-6-2.69-6-6s2.69-6 6-6 6 2.69 6 6-2.69 6-6 6zm1-6.41V4c0-.55-.45-1-1-1s-1 .45-1 1v4c0 .28.11.53.29.71l2 2a1.003 1.003 0 0 0 1.42-1.42L9 7.59z\\" fillRule=\\"evenodd\\" />
137137
</svg>
138138
</Blueprint2.Icon>
139-
Opens at: 17th June, 22:24
139+
Opens at: 18th June, 13:24
140140
</div>
141141
</Text>
142142
</div>
@@ -230,7 +230,7 @@ exports[`Assessment page does not show attempt Button for upcoming assessments f
230230
<path d=\\"M8 0C3.58 0 0 3.58 0 8s3.58 8 8 8 8-3.58 8-8-3.58-8-8-8zm0 14c-3.31 0-6-2.69-6-6s2.69-6 6-6 6 2.69 6 6-2.69 6-6 6zm1-6.41V4c0-.55-.45-1-1-1s-1 .45-1 1v4c0 .28.11.53.29.71l2 2a1.003 1.003 0 0 0 1.42-1.42L9 7.59z\\" fillRule=\\"evenodd\\" />
231231
</svg>
232232
</Blueprint2.Icon>
233-
Due: 17th June, 22:24
233+
Due: 18th June, 13:24
234234
</div>
235235
</Text>
236236
<NavLink to=\\"/academy/missions/0/0\\" activeClassName=\\"active\\" ariaCurrent=\\"true\\">
@@ -326,7 +326,7 @@ exports[`Assessment page does not show attempt Button for upcoming assessments f
326326
<path d=\\"M8 0C3.58 0 0 3.58 0 8s3.58 8 8 8 8-3.58 8-8-3.58-8-8-8zm0 14c-3.31 0-6-2.69-6-6s2.69-6 6-6 6 2.69 6 6-2.69 6-6 6zm1-6.41V4c0-.55-.45-1-1-1s-1 .45-1 1v4c0 .28.11.53.29.71l2 2a1.003 1.003 0 0 0 1.42-1.42L9 7.59z\\" fillRule=\\"evenodd\\" />
327327
</svg>
328328
</Blueprint2.Icon>
329-
Due: 17th June, 22:24
329+
Due: 18th June, 13:24
330330
</div>
331331
</Text>
332332
<NavLink to=\\"/academy/missions/1/0\\" activeClassName=\\"active\\" ariaCurrent=\\"true\\">
@@ -422,7 +422,7 @@ exports[`Assessment page does not show attempt Button for upcoming assessments f
422422
<path d=\\"M8 0C3.58 0 0 3.58 0 8s3.58 8 8 8 8-3.58 8-8-3.58-8-8-8zm0 14c-3.31 0-6-2.69-6-6s2.69-6 6-6 6 2.69 6 6-2.69 6-6 6zm1-6.41V4c0-.55-.45-1-1-1s-1 .45-1 1v4c0 .28.11.53.29.71l2 2a1.003 1.003 0 0 0 1.42-1.42L9 7.59z\\" fillRule=\\"evenodd\\" />
423423
</svg>
424424
</Blueprint2.Icon>
425-
Due: 17th June, 22:24
425+
Due: 18th June, 13:24
426426
</div>
427427
</Text>
428428
<NavLink to=\\"/academy/quests/2/0\\" activeClassName=\\"active\\" ariaCurrent=\\"true\\">
@@ -626,7 +626,7 @@ exports[`Assessment page with multiple loaded missions renders correctly 1`] = `
626626
<path d=\\"M8 0C3.58 0 0 3.58 0 8s3.58 8 8 8 8-3.58 8-8-3.58-8-8-8zm0 14c-3.31 0-6-2.69-6-6s2.69-6 6-6 6 2.69 6 6-2.69 6-6 6zm1-6.41V4c0-.55-.45-1-1-1s-1 .45-1 1v4c0 .28.11.53.29.71l2 2a1.003 1.003 0 0 0 1.42-1.42L9 7.59z\\" fillRule=\\"evenodd\\" />
627627
</svg>
628628
</Blueprint2.Icon>
629-
Opens at: 17th June, 22:24
629+
Opens at: 18th June, 13:24
630630
</div>
631631
</Text>
632632
<NavLink to=\\"/academy/missions/0/0\\" activeClassName=\\"active\\" ariaCurrent=\\"true\\">
@@ -744,7 +744,7 @@ exports[`Assessment page with multiple loaded missions renders correctly 1`] = `
744744
<path d=\\"M8 0C3.58 0 0 3.58 0 8s3.58 8 8 8 8-3.58 8-8-3.58-8-8-8zm0 14c-3.31 0-6-2.69-6-6s2.69-6 6-6 6 2.69 6 6-2.69 6-6 6zm1-6.41V4c0-.55-.45-1-1-1s-1 .45-1 1v4c0 .28.11.53.29.71l2 2a1.003 1.003 0 0 0 1.42-1.42L9 7.59z\\" fillRule=\\"evenodd\\" />
745745
</svg>
746746
</Blueprint2.Icon>
747-
Due: 17th June, 22:24
747+
Due: 18th June, 13:24
748748
</div>
749749
</Text>
750750
<NavLink to=\\"/academy/missions/0/0\\" activeClassName=\\"active\\" ariaCurrent=\\"true\\">
@@ -840,7 +840,7 @@ exports[`Assessment page with multiple loaded missions renders correctly 1`] = `
840840
<path d=\\"M8 0C3.58 0 0 3.58 0 8s3.58 8 8 8 8-3.58 8-8-3.58-8-8-8zm0 14c-3.31 0-6-2.69-6-6s2.69-6 6-6 6 2.69 6 6-2.69 6-6 6zm1-6.41V4c0-.55-.45-1-1-1s-1 .45-1 1v4c0 .28.11.53.29.71l2 2a1.003 1.003 0 0 0 1.42-1.42L9 7.59z\\" fillRule=\\"evenodd\\" />
841841
</svg>
842842
</Blueprint2.Icon>
843-
Due: 17th June, 22:24
843+
Due: 18th June, 13:24
844844
</div>
845845
</Text>
846846
<NavLink to=\\"/academy/missions/1/0\\" activeClassName=\\"active\\" ariaCurrent=\\"true\\">
@@ -936,7 +936,7 @@ exports[`Assessment page with multiple loaded missions renders correctly 1`] = `
936936
<path d=\\"M8 0C3.58 0 0 3.58 0 8s3.58 8 8 8 8-3.58 8-8-3.58-8-8-8zm0 14c-3.31 0-6-2.69-6-6s2.69-6 6-6 6 2.69 6 6-2.69 6-6 6zm1-6.41V4c0-.55-.45-1-1-1s-1 .45-1 1v4c0 .28.11.53.29.71l2 2a1.003 1.003 0 0 0 1.42-1.42L9 7.59z\\" fillRule=\\"evenodd\\" />
937937
</svg>
938938
</Blueprint2.Icon>
939-
Due: 17th June, 22:24
939+
Due: 18th June, 13:24
940940
</div>
941941
</Text>
942942
<NavLink to=\\"/academy/quests/2/0\\" activeClassName=\\"active\\" ariaCurrent=\\"true\\">

src/components/workspace/ControlBar.tsx

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -9,25 +9,27 @@ import { sourceChapters } from '../../reducers/states'
99
import { ExternalLibraryName } from '../assessment/assessmentShape'
1010
import { controlButton } from '../commons'
1111

12+
/**
13+
* @prop questionProgress a tuple of (current question number, question length) where
14+
* the current question number is 1-based.
15+
*/
1216
export type ControlBarProps = {
13-
hasAssessment: boolean
14-
currentQuestion: number
15-
assessmentLength: number
16-
hasChapterSelect: boolean
17-
hasSaveButton: boolean
18-
hasShareButton: boolean
19-
hasUnsavedChanges?: boolean
20-
isRunning: boolean
2117
queryString?: string
18+
questionProgress: [number, number] | null
2219
sourceChapter: number
2320
externalLibraryName?: string
2421
handleChapterSelect?: (i: IChapter, e: React.ChangeEvent<HTMLSelectElement>) => void
25-
handleExternalSelect?: (i: IExternal, e: React.ChangeEvent<HTMLSelectElement>) => void
2622
handleEditorEval: () => void
23+
handleExternalSelect?: (i: IExternal, e: React.ChangeEvent<HTMLSelectElement>) => void
2724
handleGenerateLz?: () => void
2825
handleInterruptEval: () => void
2926
handleReplEval: () => void
3027
handleReplOutputClear: () => void
28+
hasChapterSelect: boolean
29+
hasSaveButton: boolean
30+
hasShareButton: boolean
31+
hasUnsavedChanges?: boolean
32+
isRunning: boolean
3133
onClickNext?(): any
3234
onClickPrevious?(): any
3335
onClickReturn?(): any
@@ -52,9 +54,6 @@ interface IExternal {
5254

5355
class ControlBar extends React.PureComponent<ControlBarProps, {}> {
5456
public static defaultProps: Partial<ControlBarProps> = {
55-
hasAssessment: false,
56-
currentQuestion: 0,
57-
assessmentLength: 0,
5857
hasChapterSelect: false,
5958
hasSaveButton: false,
6059
hasShareButton: true,
@@ -137,9 +136,9 @@ class ControlBar extends React.PureComponent<ControlBarProps, {}> {
137136
}
138137

139138
private flowControl() {
140-
const questionView = this.props.hasAssessment
139+
const questionView = this.props.questionProgress
141140
? controlButton(
142-
`Question ${this.props.currentQuestion} of ${this.props.assessmentLength} `,
141+
`Question ${this.props.questionProgress[0]} of ${this.props.questionProgress[1]} `,
143142
null,
144143
null,
145144
{},
@@ -185,15 +184,20 @@ class ControlBar extends React.PureComponent<ControlBarProps, {}> {
185184
}
186185

187186
private hasNextButton() {
188-
return this.props.hasAssessment && this.props.currentQuestion < this.props.assessmentLength
187+
return (
188+
this.props.questionProgress && this.props.questionProgress[0] < this.props.questionProgress[1]
189+
)
189190
}
190191

191192
private hasPreviousButton() {
192-
return this.props.hasAssessment && this.props!.currentQuestion > 0
193+
return this.props.questionProgress && this.props.questionProgress[0] > 0
193194
}
194195

195196
private hasReturnButton() {
196-
return this.props.hasAssessment && this.props.currentQuestion === this.props.assessmentLength
197+
return (
198+
this.props.questionProgress &&
199+
this.props.questionProgress[0] === this.props.questionProgress[1]
200+
)
197201
}
198202
}
199203

0 commit comments

Comments
 (0)