Skip to content

Commit f705123

Browse files
committed
test status indicator progress
Signed-off-by: shmck <[email protected]>
1 parent 3a79d1d commit f705123

File tree

4 files changed

+48
-22
lines changed

4 files changed

+48
-22
lines changed

typings/index.d.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import * as E from './error'
22
import * as TT from './tutorial'
33

4-
export type ProgressStatus = 'ACTIVE' | 'COMPLETE' | 'INCOMPLETE'
4+
export type ProgressStatus = 'ACTIVE' | 'COMPLETE' | 'INCOMPLETE' | 'FAIL'
55

66
export interface Progress {
77
levels: {

web-app/src/containers/Tutorial/components/Step.tsx

+17-8
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import * as React from 'react'
22
import * as T from 'typings'
33
import { css, jsx } from '@emotion/core'
44
import TestStatusIcon from './TestStatusIcon'
5+
import Icon from '../../../components/Icon'
56
import Hints from './Hints'
67
import Markdown from '../../../components/Markdown'
78

@@ -54,8 +55,7 @@ const Step = (props: Props) => {
5455
<div>
5556
<div css={styles.card}>
5657
<div css={styles.statusContainer}>
57-
{props.status === 'ACTIVE' && <TestStatusIcon size="small" />}
58-
{props.status === 'COMPLETE' && <TestStatusIcon size="small" checked />}
58+
<TestStatusIcon size="small" status={props.status} />
5959
</div>
6060
<div>
6161
{/* content */}
@@ -65,13 +65,22 @@ const Step = (props: Props) => {
6565
{/* subtasks */}
6666
{props.subtasks ? (
6767
<ul css={styles.subtasks}>
68-
{props.subtasks.map((subtask) => (
69-
<li key={subtask.name} css={styles.subtask}>
70-
<TestStatusIcon size="xs" checked={props.status === 'COMPLETE' || subtask.pass} />
68+
{props.subtasks.map((subtask) => {
69+
let subtaskStatus: 'COMPLETE' | 'ACTIVE'
70+
if (props.status === 'COMPLETE') {
71+
subtaskStatus = 'COMPLETE'
72+
} else {
73+
subtaskStatus = subtask.pass ? 'COMPLETE' : 'ACTIVE'
74+
}
7175

72-
<span style={{ marginLeft: '0.5rem' }}>{subtask.name}</span>
73-
</li>
74-
))}
76+
return (
77+
<li key={subtask.name} css={styles.subtask}>
78+
<TestStatusIcon size="xs" status={subtaskStatus} />
79+
80+
<span style={{ marginLeft: '0.5rem' }}>{subtask.name}</span>
81+
</li>
82+
)
83+
})}
7584
</ul>
7685
) : null}
7786
{/* hints */}

web-app/src/containers/Tutorial/components/TestStatusIcon.tsx

+18-12
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,29 @@ import * as React from 'react'
22
import Icon from '../../../components/Icon'
33

44
interface Props {
5-
size: 'small' | 'xs' | 'xxs'
6-
checked?: boolean
5+
size: 'small' | 'xs'
6+
status: 'COMPLETE' | 'ACTIVE' | 'INCOMPLETE' | 'FAIL'
77
}
88

9-
const colors = {
10-
complete: '#37B809',
11-
incomplete: 'lightgrey',
9+
const styles = {
10+
complete: {
11+
icon: 'success-filling',
12+
color: '#37B809',
13+
},
14+
active: {
15+
icon: 'success-filling',
16+
color: 'lightgrey',
17+
},
18+
fail: {
19+
icon: 'warning',
20+
color: '#ff9300',
21+
},
1222
}
1323

1424
const TestStatusIcon = (props: Props) => {
15-
return (
16-
<Icon
17-
type="success-filling"
18-
size={props.size}
19-
style={{ color: props.checked ? colors.complete : colors.incomplete }}
20-
/>
21-
)
25+
// @ts-ignore
26+
const style: { icon: string; color: string } = styles[props.status.toLowerCase()]
27+
return <Icon type="success-filling" size={props.size} style={{ color: style.color }} />
2228
}
2329

2430
export default TestStatusIcon

web-app/stories/Step.stories.tsx

+12-1
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,17 @@ storiesOf('Step', module)
6969
setHintIndex={action('setHintIndex')}
7070
/>
7171
))
72+
.add('Fail Step', () => (
73+
<Step
74+
index={1}
75+
content={text('text', stepText)}
76+
status="FAIL"
77+
onLoadSolution={action('onLoadSolution')}
78+
subtasks={null}
79+
hintIndex={0}
80+
setHintIndex={action('setHintIndex')}
81+
/>
82+
))
7283
.add('Step Markdown', () => (
7384
<Step
7485
index={2}
@@ -80,7 +91,7 @@ storiesOf('Step', module)
8091
setHintIndex={action('setHintIndex')}
8192
/>
8293
))
83-
.add('Substasks', () => (
94+
.add('Subtasks', () => (
8495
<Step
8596
index={2}
8697
content={'A task with subtasks'}

0 commit comments

Comments
 (0)