Skip to content

Commit da0a679

Browse files
remo5000ning-y
authored andcommitted
Add side content to view comments (#282)
* Add comments field * Remove comments from IAssessment * Add comments to mockAssessmentQuestions * Add comments to type * Update gradingShape * Pass comments to tabs * Format files * Rename comments -> comment * Fix rebase errors * Add check for activeTab being out of bounds * Add active button effect for active tab * Use minimal prop instead of classname * Remove outline using a class style * Format file * Add documentation for having at least 1 tab
1 parent 0d9754e commit da0a679

File tree

7 files changed

+52
-7
lines changed

7 files changed

+52
-7
lines changed

src/components/academy/grading/gradingShape.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,12 @@ export type GradingQuestion = {
4242
* grading a submission. This means that
4343
* either of (library & solutionTemplate) xor (choices) must
4444
* be present, and either of (solution) xor (answer) must be present.
45+
*
46+
* @property comment This property is already present in GradingQuestion,
47+
* and thus does not need to be used here, and is set to null
4548
*/
4649
interface IAnsweredQuestion extends IQuestion {
50+
comment: null
4751
solution?: number
4852
answer: string | number | null
4953
solutionTemplate?: string

src/components/assessment/AssessmentWorkspace.tsx

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -207,10 +207,8 @@ class AssessmentWorkspace extends React.Component<
207207
private sideContentProps: (p: AssessmentWorkspaceProps, q: number) => SideContentProps = (
208208
props: AssessmentWorkspaceProps,
209209
questionId: number
210-
) => ({
211-
activeTab: props.activeTab,
212-
handleChangeActiveTab: props.handleChangeActiveTab,
213-
tabs: [
210+
) => {
211+
const tabs = [
214212
{
215213
label: `Task ${questionId}`,
216214
icon: IconNames.NINJA,
@@ -222,7 +220,20 @@ class AssessmentWorkspace extends React.Component<
222220
body: <Markdown content={props.assessment!.longSummary} />
223221
}
224222
]
225-
})
223+
const comment = props.assessment!.questions[questionId].comment
224+
if (comment !== null) {
225+
tabs.push({
226+
label: `Comments`,
227+
icon: IconNames.CHAT,
228+
body: <Markdown content={comment} />
229+
})
230+
}
231+
return {
232+
activeTab: props.activeTab,
233+
handleChangeActiveTab: props.handleChangeActiveTab,
234+
tabs
235+
}
236+
}
226237

227238
/** Pre-condition: IAssessment has been loaded */
228239
private controlBarProps: (p: AssessmentWorkspaceProps, q: number) => ControlBarProps = (

src/components/assessment/assessmentShape.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ export interface IMCQQuestion extends IQuestion {
6565

6666
export interface IQuestion {
6767
answer: string | number | null
68+
comment: string | null
6869
content: string
6970
id: number
7071
library: Library

src/components/workspace/side-content/index.tsx

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
import { Button, Card, IconName, Tooltip } from '@blueprintjs/core'
22
import * as React from 'react'
33

4+
/**
5+
* @property tabs an Array of SideContentTabs,
6+
* which must be non-empty i.e contain at least one SideContentTab
7+
*/
48
export type SideContentProps = {
59
activeTab: number
610
tabs: SideContentTab[]
@@ -15,11 +19,20 @@ export type SideContentTab = {
1519

1620
class SideContent extends React.PureComponent<SideContentProps, {}> {
1721
public render() {
22+
/**
23+
* The check here prevents a runtime error when the activeTab is momentarily out of
24+
* bounds of this.props.tabs length. It is set to 0 becuase of the asssumption that tabs
25+
* is at least length 1 (@see SideContentProps)
26+
*/
27+
const activeTab =
28+
this.props.activeTab < 0 || this.props.activeTab >= this.props.tabs.length
29+
? 0
30+
: this.props.activeTab
1831
return (
1932
<div className="side-content">
2033
<Card>
2134
{this.renderHeader()}
22-
<div className="side-content-text">{this.props.tabs[this.props.activeTab].body}</div>
35+
<div className="side-content-text">{this.props.tabs[activeTab].body}</div>
2336
</Card>
2437
</div>
2538
)
@@ -32,7 +45,13 @@ class SideContent extends React.PureComponent<SideContentProps, {}> {
3245
const click = (i: number) => () => this.props.handleChangeActiveTab(i)
3346
const buttons = this.props.tabs.map((tab, i) => (
3447
<Tooltip key={i} content={tab.label}>
35-
<Button icon={tab.icon as IconName} className="pt-minimal" onClick={click(i)} />
48+
<Button
49+
className="side-content-header-button"
50+
icon={tab.icon as IconName}
51+
minimal={true}
52+
onClick={click(i)}
53+
active={i === this.props.activeTab}
54+
/>
3655
</Tooltip>
3756
))
3857
return (

src/mocks/assessmentAPI.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,13 +172,15 @@ This question has an id of \`0\`.
172172
What's your favourite dinner food?
173173
\`\`\`
174174
`,
175+
comment: null,
175176
id: 0,
176177
library: mockSoundLibrary,
177178
solutionTemplate: '0th question mock solution template',
178179
type: 'programming'
179180
},
180181
{
181182
answer: null,
183+
comment: '`Great Job` **young padawan**',
182184
content: 'Hello and welcome to this assessment! This is the 1st question.',
183185
id: 1,
184186
library: mock3DRuneLibrary,
@@ -187,6 +189,7 @@ What's your favourite dinner food?
187189
},
188190
{
189191
answer: 3,
192+
comment: '## Money trees is the *perfect place for shade* and ``` thats just how i feel ``` ',
190193
content:
191194
'This is the 3rd question. Oddly enough, it is an ungraded MCQ question that uses the curves library! Option C has a null hint!',
192195
choices: [
@@ -214,6 +217,7 @@ What's your favourite dinner food?
214217
},
215218
{
216219
answer: 3,
220+
comment: null,
217221
content:
218222
'This is the 4rth question. Oddly enough, it is a graded MCQ question that uses the curves library!',
219223
choices: [

src/mocks/gradingAPI.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ Hello and welcome to this assessment! This is the *0th question*.
6969
>>> import this
7070
\`\`\`
7171
`,
72+
comment: null,
7273
id: 0,
7374
library: mockLibrary,
7475
solutionTemplate: '0th question mock solution template',
@@ -84,6 +85,7 @@ Hello and welcome to this assessment! This is the *0th question*.
8485
{
8586
question: {
8687
answer: "This student's answer to the 1st question",
88+
comment: null,
8789
content: 'Hello and welcome to this assessment! This is the 1st question.',
8890
id: 1,
8991
library: mockLibrary,
@@ -101,6 +103,7 @@ Hello and welcome to this assessment! This is the *0th question*.
101103
question: {
102104
// C is the answer
103105
answer: 3,
106+
comment: null,
104107
solution: 2,
105108
content:
106109
'Hello and welcome to this assessment! This is the 2nd question. Oddly enough, it is an MCQ question!',

src/styles/_workspace.scss

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,9 @@ $code-color-error: #ff4444;
120120
flex-wrap: wrap;
121121
justify-content: center;
122122
padding-bottom: 0.2rem;
123+
.side-content-header-button:focus {
124+
outline: 0;
125+
}
123126
}
124127

125128
.side-content-divider {

0 commit comments

Comments
 (0)