-
Notifications
You must be signed in to change notification settings - Fork 174
Scaffold playground page #8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 28 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 42d4cb6
Make first NavbarGroup's align left explicit
ning-y e917cf0
Change playground icon
remo5000 c00bfeb
Add routes to Playground
ning-y c70d46a
Update test snapshots
ning-y 0ab401a
Fix bad test for Playground component
ning-y c9de874
Add react-ace for IDE
ning-y b4f37b7
Try passing props into playground
ning-y c1d11a6
Load a preset "Hello World" onto the ace editor.
remo5000 8145a2a
Remove unused onChange()
remo5000 c8add20
Add stored state for playground editor text
remo5000 48bd369
Change initialValue prop to editorValue
remo5000 023f277
Made playground actions a separate file
ning-y dd585f9
Modify actions and dispatch call
remo5000 053b2c9
Change redux import statement
remo5000 b17cb25
Add IPlaygroundState to IState in index reducer
remo5000 8d480a3
Add playground reducer
remo5000 7c3ad6d
Remove playgroundCode from IApplicationState
ning-y fcf1c60
Fix type errors
ning-y 4004d64
Re-disable console.logs (tslint)
ning-y 1879083
Fix missing imports for react-ace mode, theme
ning-y 1f5edb7
Add playground CSS
ning-y 376ec46
Add JSDoc style comments for playground
ning-y eb37db7
Fix some tests
ning-y 931a204
Fix semantics of mapStateToProps for ApplicationContainer
remo5000 b451e08
Do trivial formatting
remo5000 7ac707c
Make 16/05 code review changes
remo5000 b2a3d60
Fix test snapshot (name of onChange for ReactAce)
ning-y caf551b
Revert Playground as SFC, make Editor container
ning-y 51ea83d
Make Playground stateless
remo5000 9758bb7
Add test and fix export type
remo5000 a203e5e
Fix test snapshots
remo5000 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 | ||
| }) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| import * as React from 'react' | ||
| import AceEditor from 'react-ace' | ||
|
|
||
| import 'brace/mode/javascript' | ||
| import 'brace/theme/github' | ||
|
|
||
| /** | ||
| * A prop that is passed to the Playground | ||
| * @property editorValue - The string content of the react-ace editor | ||
| * @property updateCode - A callback function for the react-ace editor's `onChange` | ||
| */ | ||
| export interface IPlaygroundProps { | ||
| editorValue: string | ||
| handleEditorChange: (newCode: string) => void | ||
| } | ||
|
|
||
| /** | ||
| * A component representing the Playground | ||
| */ | ||
| export default class Playground extends React.Component<IPlaygroundProps, {}> { | ||
| public render() { | ||
| return ( | ||
| <div className="Playground"> | ||
| <h2>Playground</h2> | ||
| <AceEditor | ||
| height="90%" | ||
| width="90%" | ||
| mode="javascript" | ||
| theme="github" | ||
| value={this.props.editorValue} | ||
| onChange={this.props.handleEditorChange} | ||
| /> | ||
| </div> | ||
| ) | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| import * as React from 'react' | ||
|
|
||
| import { shallow } from 'enzyme' | ||
|
|
||
| import Playground from '../Playground' | ||
| import { IPlaygroundProps as PlaygroundProps } from '../Playground' | ||
|
|
||
| test('Playground renders correctly', () => { | ||
| const props: PlaygroundProps = { | ||
| editorValue: '', | ||
| handleEditorChange: (newCode: string) => { | ||
| return | ||
| } | ||
| } | ||
| const app = <Playground {...props} /> | ||
| const tree = shallow(app) | ||
| expect(tree.debug()).toMatchSnapshot() | ||
| }) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 10 additions & 0 deletions
10
src/components/__tests__/__snapshots__/Playground.tsx.snap
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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> | ||
| <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} /> | ||
| </div>" | ||
| `; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| import { connect, MapDispatchToProps, MapStateToProps } from 'react-redux' | ||
| import { Dispatch } from 'redux' | ||
|
|
||
| import { updateEditorValue } from '../actions/playground' | ||
| import { | ||
| default as PlaygroundComponent, | ||
| IPlaygroundProps as PlaygroundProps | ||
| } from '../components/Playground' | ||
| import { IState } from '../reducers' | ||
|
|
||
| type StateProps = Pick<PlaygroundProps, 'editorValue'> | ||
| type DispatchProps = Pick<PlaygroundProps, '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)(PlaygroundComponent) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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; | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You should always default to
React.SFCuntil you need stateThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In this case, our editor would need to call upon a
dispatchto update theeditorValuewithin theIPlaygroundState, whenever someone edits code in the ace editor. Is a Component warranted in this case?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, so in this case the editor component is stateful, but the playground component itself should be stateless
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, I understand now. Will do!