Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
de9df9b
Add button for playground at Navbar
ning-y May 14, 2018
42d4cb6
Make first NavbarGroup's align left explicit
ning-y May 14, 2018
e917cf0
Change playground icon
remo5000 May 14, 2018
c00bfeb
Add routes to Playground
ning-y May 14, 2018
c70d46a
Update test snapshots
ning-y May 14, 2018
0ab401a
Fix bad test for Playground component
ning-y May 14, 2018
c9de874
Add react-ace for IDE
ning-y May 14, 2018
b4f37b7
Try passing props into playground
ning-y May 15, 2018
c1d11a6
Load a preset "Hello World" onto the ace editor.
remo5000 May 15, 2018
8145a2a
Remove unused onChange()
remo5000 May 15, 2018
c8add20
Add stored state for playground editor text
remo5000 May 15, 2018
48bd369
Change initialValue prop to editorValue
remo5000 May 15, 2018
023f277
Made playground actions a separate file
ning-y May 15, 2018
dd585f9
Modify actions and dispatch call
remo5000 May 15, 2018
053b2c9
Change redux import statement
remo5000 May 15, 2018
b17cb25
Add IPlaygroundState to IState in index reducer
remo5000 May 15, 2018
8d480a3
Add playground reducer
remo5000 May 15, 2018
7c3ad6d
Remove playgroundCode from IApplicationState
ning-y May 15, 2018
fcf1c60
Fix type errors
ning-y May 15, 2018
4004d64
Re-disable console.logs (tslint)
ning-y May 15, 2018
1879083
Fix missing imports for react-ace mode, theme
ning-y May 15, 2018
1f5edb7
Add playground CSS
ning-y May 15, 2018
376ec46
Add JSDoc style comments for playground
ning-y May 15, 2018
eb37db7
Fix some tests
ning-y May 15, 2018
931a204
Fix semantics of mapStateToProps for ApplicationContainer
remo5000 May 16, 2018
b451e08
Do trivial formatting
remo5000 May 16, 2018
7ac707c
Make 16/05 code review changes
remo5000 May 16, 2018
b2a3d60
Fix test snapshot (name of onChange for ReactAce)
ning-y May 17, 2018
caf551b
Revert Playground as SFC, make Editor container
ning-y May 17, 2018
51ea83d
Make Playground stateless
remo5000 May 17, 2018
9758bb7
Add test and fix export type
remo5000 May 17, 2018
a203e5e
Fix test snapshots
remo5000 May 17, 2018
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
"@blueprintjs/core": "^2.1.1",
"normalize.css": "^8.0.0",
"react": "^16.3.1",
"react-ace": "^6.1.1",
"react-dom": "^16.3.1",
"react-redux": "^5.0.7",
"react-router": "^4.2.0",
Expand Down
1 change: 0 additions & 1 deletion src/actions/index.ts

This file was deleted.

26 changes: 26 additions & 0 deletions src/actions/playground.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { Action, ActionCreator } from 'redux'

/**
* The `type` attribute for an `Action` which updates the `IPlaygroundState`
* `editorValue`
*/
export const UPDATE_EDITOR_VALUE = 'UPDATE_EDITOR_VALUE'

/**
* Represents an `Action` which updates the `editorValue` of a
* `IPlaygroundState`
* @property type - Unique string identifier for this `Action`
* @property newEditorValue - The new string value for `editorValue`
*/
export interface IUpdateEditorValue extends Action {
payload: string
}

/**
* An `ActionCreator` returning an `IUpdateEditorValue` `Action`
* @param newEditorValue - The new string value for `editorValue`
*/
export const updateEditorValue: ActionCreator<IUpdateEditorValue> = (newEditorValue: string) => ({
type: UPDATE_EDITOR_VALUE,
payload: newEditorValue
})
10 changes: 6 additions & 4 deletions src/components/Application.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,25 @@ import * as React from 'react'
import { Redirect, Route, RouteComponentProps, Switch } from 'react-router'

import DashboardContainer from '../containers/DashboardContainer'
import { IApplicationState } from '../reducers/application'

import NavigationBar from './NavigationBar'
import NotFound from './NotFound'
import Playground from './Playground'

export interface IApplicationProps extends RouteComponentProps<{}> {
application: IApplicationState
title: string
}

const Application: React.SFC<IApplicationProps> = ({ application }) => {
const Application: React.SFC<IApplicationProps> = props => {
const redirectToDashboard = () => <Redirect to="/dashboard" />

return (
<div className="Application">
<NavigationBar title={application.title} />
<NavigationBar title={props.title} />
<div className="Application__main">
<Switch>
<Route path="/dashboard" component={DashboardContainer} />
<Route path="/playground" component={Playground} />
<Route exact={true} path="/" component={redirectToDashboard} />
<Route component={NotFound} />
</Switch>
Expand Down
31 changes: 31 additions & 0 deletions src/components/Editor.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import * as React from 'react'
import AceEditor from 'react-ace'

import 'brace/mode/javascript'
import 'brace/theme/github'

/**
* @property editorValue - The string content of the react-ace editor
* @property updateCode - A callback function for the react-ace editor's `onChange`
*/
export interface IEditorProps {
editorValue: string
handleEditorChange: (newCode: string) => void
}

class Editor extends React.Component<IEditorProps, {}> {
public render() {
return (
<AceEditor
height="90%"
width="90%"
mode="javascript"
theme="github"
value={this.props.editorValue}
onChange={this.props.handleEditorChange}
/>
)
}
}

export default Editor
13 changes: 12 additions & 1 deletion src/components/NavigationBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export interface INavigationBarProps {

const NavigationBar: React.SFC<INavigationBarProps> = ({ title }) => (
<Navbar className="NavigationBar pt-dark">
<NavbarGroup>
<NavbarGroup className="pt-align-left">
<NavbarHeading>{title}</NavbarHeading>
<NavbarDivider />
<NavLink
Expand All @@ -21,6 +21,17 @@ const NavigationBar: React.SFC<INavigationBarProps> = ({ title }) => (
Dashboard
</NavLink>
</NavbarGroup>

<NavbarGroup className="pt-align-right">
<NavLink
to="/playground"
activeClassName="pt-active"
className="NavigationBar__link pt-button pt-minimal"
>
<Icon icon="code" />
Playground
</NavLink>
</NavbarGroup>
</Navbar>
)

Expand Down
13 changes: 13 additions & 0 deletions src/components/Playground.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import * as React from 'react'
import EditorContainer from '../containers/EditorContainer'

const Playground: React.SFC<{}> = ()=> {
return (
<div className="Playground">
<h2>Playground</h2>
<EditorContainer />
</div>
)
}

export default Playground
6 changes: 1 addition & 5 deletions src/components/__tests__/Application.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,12 @@ import * as React from 'react'
import { shallow } from 'enzyme'

import { mockRouterProps } from '../../mocks/components'
import { ApplicationEnvironment } from '../../reducers/application'
import Application, { IApplicationProps } from '../Application'

test('Application renders correctly', () => {
const props: IApplicationProps = {
...mockRouterProps('/dashboard', {}),
application: {
title: 'Cadet',
environment: ApplicationEnvironment.Development
}
title: 'Cadet'
}
const app = <Application {...props} />
const tree = shallow(app)
Expand Down
15 changes: 15 additions & 0 deletions src/components/__tests__/Editor.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import * as React from 'react'

import { shallow } from 'enzyme'

import Editor, { IEditorProps } from '../Editor'

test('Editor renders correctly', () => {
const props: IEditorProps = {
editorValue: ''
handleEditorChange: (newCode) =>
}
const app = <Editor { props }/>
const tree = shallow(app)
expect(tree.debug()).toMatchSnapshot()
})
11 changes: 11 additions & 0 deletions src/components/__tests__/Playground.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import * as React from 'react'

import { shallow } from 'enzyme'

import Playground from '../Playground'

test('Playground renders correctly', () => {
const app = <Playground />
const tree = shallow(app)
expect(tree.debug()).toMatchSnapshot()
})
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ exports[`Application renders correctly 1`] = `
<div className=\\"Application__main\\">
<Switch>
<Route path=\\"/dashboard\\" component={[Function: Connect]} />
<Route path=\\"/playground\\" component={[Function: Playground]} />
<Route exact={true} path=\\"/\\" component={[Function: redirectToDashboard]} />
<Route component={[Function: NotFound]} />
</Switch>
Expand Down
3 changes: 3 additions & 0 deletions src/components/__tests__/__snapshots__/Editor.tsx.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`Editor renders correctly 1`] = `"<ReactAce height=\\"90%\\" width=\\"90%\\" mode=\\"javascript\\" theme=\\"github\\" value=\\"\\" onChange={[Function: handleEditorChange]} name=\\"brace-editor\\" focus={false} fontSize={12} showGutter={true} onPaste={{...}} onLoad={{...}} onScroll={{...}} minLines={{...}} maxLines={{...}} readOnly={false} highlightActiveLine={true} showPrintMargin={true} tabSize={4} cursorStart={1} editorProps={{...}} style={{...}} scrollMargin={{...}} setOptions={{...}} wrapEnabled={false} enableBasicAutocompletion={false} enableLiveAutocompletion={false} />"`;
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

exports[`NavigationBar renders correctly 1`] = `
"<Blueprint2.Navbar className=\\"NavigationBar pt-dark\\">
<Blueprint2.NavbarGroup align=\\"left\\">
<Blueprint2.NavbarGroup className=\\"pt-align-left\\" align=\\"left\\">
<Blueprint2.NavbarHeading>
Cadet
</Blueprint2.NavbarHeading>
Expand All @@ -12,5 +12,11 @@ exports[`NavigationBar renders correctly 1`] = `
Dashboard
</NavLink>
</Blueprint2.NavbarGroup>
<Blueprint2.NavbarGroup className=\\"pt-align-right\\" align=\\"left\\">
<NavLink to=\\"/playground\\" activeClassName=\\"pt-active\\" className=\\"NavigationBar__link pt-button pt-minimal\\" ariaCurrent=\\"true\\">
<Blueprint2.Icon icon=\\"code\\" />
Playground
</NavLink>
</Blueprint2.NavbarGroup>
</Blueprint2.Navbar>"
`;
10 changes: 10 additions & 0 deletions src/components/__tests__/__snapshots__/Playground.tsx.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`Playground renders correctly 1`] = `
"<div className=\\"Playground\\">
<h2>
Playground
</h2>
<Connect(Editor) />
</div>"
`;
14 changes: 10 additions & 4 deletions src/containers/ApplicationContainer.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
import { connect, MapStateToProps } from 'react-redux'
import { withRouter } from 'react-router'

import Application, { IApplicationProps } from '../components/Application'
import Application from '../components/Application'
import { IState } from '../reducers'

const mapStateToProps: MapStateToProps<IState, {}, IApplicationProps> = state => ({
application: state.application
/**
* Provides the title of the application for display.
* An object with the relevant properties must be
* returned instead of an object of type @type {IApplicationProps},
* as the routing properties of @type {RouteComponentProps} are
* provided using the withRouter() method below.
*/
const mapStateToProps: MapStateToProps<{ title: string }, {}, IState> = state => ({
title: state.application.title
})

export default withRouter(connect(mapStateToProps)(Application))
32 changes: 32 additions & 0 deletions src/containers/EditorContainer.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { connect, MapDispatchToProps, MapStateToProps } from 'react-redux'
import { Dispatch } from 'redux'

import { updateEditorValue } from '../actions/playground'
import Editor, { IEditorProps } from '../components/Editor'
import { IState } from '../reducers'

type StateProps = Pick<IEditorProps, 'editorValue'>
type DispatchProps = Pick<IEditorProps, 'handleEditorChange'>

/** Provides the editorValue of the `IPlaygroundState` of the `IState` as a
* `StateProps` to the Playground component
*/
const mapStateToProps: MapStateToProps<StateProps, {}, IState> = state => {
return {
editorValue: state.playground.editorValue
}
}

/** Provides a callback function `updateCode` which supplies the `Action`
* `updateEditorValue` with `newCode`, the updated contents of the react-ace
* editor.
*/
const mapDispatchToProps: MapDispatchToProps<DispatchProps, {}> = (dispatch: Dispatch<any>) => {
return {
handleEditorChange: (newCode: string) => {
dispatch(updateEditorValue(newCode))
}
}
}

export default connect(mapStateToProps, mapDispatchToProps)(Editor)
3 changes: 3 additions & 0 deletions src/mocks/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ export function mockInitialStore<P>(): Store<IState> {
application: {
title: 'Cadet',
environment: ApplicationEnvironment.Development
},
playground: {
editorValue: ''
}
}
return createStore(state)
Expand Down
2 changes: 1 addition & 1 deletion src/reducers/__tests__/__snapshots__/application.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
exports[`initial state should match a snapshot 1`] = `
Object {
"environment": "test",
"title": "Conveyor",
"title": "Cadet",
}
`;
5 changes: 4 additions & 1 deletion src/reducers/index.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
import { IApplicationState, reducer as application } from './application'
import { IPlaygroundState, reducer as playground } from './playground'

export interface IState {
readonly application: IApplicationState
readonly playground: IPlaygroundState
}

export default {
application
application,
playground
}
30 changes: 30 additions & 0 deletions src/reducers/playground.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { Action, Reducer } from 'redux'
import { IUpdateEditorValue, UPDATE_EDITOR_VALUE } from '../actions/playground'

export interface IPlaygroundState {
editorValue: string
}

/**
* The default (initial) state of the `IPlaygroundState`
*/
const defaultState: IPlaygroundState = {
editorValue: ''
}

/**
* The reducer for `IPlaygroundState`
*
* UPDATE_EDITOR_VALUE: Update the `editorValue` property
*/
export const reducer: Reducer<IPlaygroundState> = (state = defaultState, action: Action) => {
switch (action.type) {
case UPDATE_EDITOR_VALUE:
return {
...state,
editorValue: (action as IUpdateEditorValue).payload
}
default:
return state
}
}
1 change: 1 addition & 0 deletions src/styles/index.css
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@
@import "~@blueprintjs/core/lib/css/blueprint.css";
@import "./blueprint.css";
@import "./application.css";
@import "./playground.css";
@import "./navigationBar.css";
11 changes: 11 additions & 0 deletions src/styles/playground.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
.Playground {
display: flex;
flex-direction: column;
height: 100vh;
width: 100vh;
}

.Playground__main {
margin-top: 1rem;
margin-left: 1rem;
}
Loading