Skip to content

Commit 44b5dd2

Browse files
committed
Abstract controlButton into components/commons
Also fixed typescript type errors on yarn start.
1 parent 56b4c54 commit 44b5dd2

File tree

6 files changed

+38
-44
lines changed

6 files changed

+38
-44
lines changed
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import { Button, IconName, Intent } from '@blueprintjs/core'
2+
import * as React from 'react'
3+
4+
export const controlButton = (
5+
label: string,
6+
icon: IconName,
7+
handleClick = () => {},
8+
intent = Intent.NONE,
9+
minimal = true
10+
) => (
11+
<Button
12+
onClick={handleClick}
13+
className={(minimal ? 'pt-minimal' : '') + ' col-xs-12'}
14+
intent={intent}
15+
icon={icon}
16+
>
17+
{label}
18+
</Button>
19+
)

src/components/commons/index.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from './controlButton'

src/components/workspace/Editor.tsx

Lines changed: 3 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
import * as React from 'react'
2-
32
import AceEditor from 'react-ace'
43

5-
import { Button, IconName, Intent } from '@blueprintjs/core'
4+
import { controlButton } from '../commons'
65

76
import 'brace/mode/javascript'
87
import 'brace/theme/cobalt'
@@ -24,27 +23,11 @@ export interface IEditorProps {
2423

2524
class Editor extends React.Component<IEditorProps, {}> {
2625
public render() {
27-
const genericButton = (
28-
label: string,
29-
icon: IconName,
30-
handleClick = () => {},
31-
intent = Intent.NONE,
32-
notMinimal = false
33-
) => (
34-
<Button
35-
onClick={handleClick}
36-
className={(notMinimal ? '' : 'pt-minimal') + ' col-xs-12'}
37-
intent={intent}
38-
icon={icon}
39-
>
40-
{label}
41-
</Button>
42-
)
4326
const runButton = this.props.isRunning
4427
? null
45-
: genericButton('', 'play', this.props.handleEditorEval)
28+
: controlButton('', 'play', this.props.handleEditorEval)
4629
const stopButton = this.props.isRunning
47-
? genericButton('', 'stop', this.props.handleInterruptEval)
30+
? controlButton('', 'stop', this.props.handleInterruptEval)
4831
: null
4932
return (
5033
<div className="Editor">

src/components/workspace/ReplControl.tsx

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import { Button, IconName, Intent } from '@blueprintjs/core'
21
import * as React from 'react'
32

43
import { sourceChapters } from '../../reducers/states'
4+
import { controlButton } from '../commons'
55

66
/**
77
* @property handleEvalEditor - A callback function for evaluation
@@ -27,23 +27,6 @@ class ReplControl extends React.Component<IReplControlProps, {}> {
2727
}
2828
}
2929

30-
const controlButton = (
31-
label: string,
32-
icon: IconName,
33-
handleClick = () => {},
34-
intent = Intent.NONE,
35-
minimal = true
36-
) => (
37-
<Button
38-
onClick={handleClick}
39-
className={(minimal ? 'pt-minimal' : '') + ' col-xs-12'}
40-
intent={intent}
41-
icon={icon}
42-
>
43-
{label}
44-
</Button>
45-
)
46-
4730
const chapterSelect = (handleSelect = (e: React.ChangeEvent<HTMLSelectElement>) => {}) => (
4831
<div className="pt-select pt-select">
4932
<select defaultValue={sourceChapters.slice(-1)[0].toString()} onChange={handleSelect}>

src/components/workspace/__tests__/Repl.tsx

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,25 +2,32 @@ import { shallow } from 'enzyme'
22
import * as React from 'react'
33

44
import { mockTypeError } from '../../../mocks/context'
5+
import {
6+
CodeOutput,
7+
ErrorOutput,
8+
InterpreterOutput,
9+
ResultOutput,
10+
RunningOutput
11+
} from '../../../reducers/states'
512
import Repl, { Output } from '../Repl'
613

7-
const mockRunningOutput = {
14+
const mockRunningOutput: RunningOutput = {
815
type: 'running',
916
consoleLogs: ['a', 'bb', 'cccccccccccccccccccccccccccccccc', 'd']
1017
}
1118

12-
const mockCodeOutput = {
19+
const mockCodeOutput: CodeOutput = {
1320
type: 'code',
1421
value: "display('');"
1522
}
1623

17-
const mockResultOutput = {
24+
const mockResultOutput: ResultOutput = {
1825
type: 'result',
1926
value: 42,
2027
consoleLogs: []
2128
}
2229

23-
const mockErrorOutput = {
30+
const mockErrorOutput: ErrorOutput = {
2431
type: 'errors',
2532
errors: [mockTypeError()],
2633
consoleLogs: []
@@ -85,7 +92,7 @@ test('Error output (with consoleLogs) renders correctly', () => {
8592
})
8693

8794
test('Empty output renders an empty card', () => {
88-
const app = <Output {...{ output: {} }} />
95+
const app = <Output {...{ output: {} as InterpreterOutput }} />
8996
const tree = shallow(app)
9097
expect(tree.debug()).toMatchSnapshot()
9198
})

src/mocks/context.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { parse } from 'acorn'
12
import * as es from 'estree'
23

34
import { createContext } from '../slang'
@@ -34,5 +35,5 @@ export function mockClosure(): Closure {
3435
}
3536

3637
export function mockTypeError(): TypeError {
37-
return new TypeError({ loc: 0 } as es.Node, '', '', '')
38+
return new TypeError(parse(''), '', '', '')
3839
}

0 commit comments

Comments
 (0)