* chore(packages): Update redux utils * feat(Panes): Invert control of panes map creation * feat(Modern): Add view * feat(Panes): Decouple panes from Challenges * fix(Challenges): Decouple challenge views from panes map * fix(Challenge/views): PanesMap => mapStateToPanesMap This clarifies what these functions are doing * fix(Challenges): Add view type * fix(Panes): Remove unneeded panes container * feat(Panes): Invert control of pane content render This decouples the Panes from the content they render, allowing for greater flexibility. * feat(Modern): Add side panel This is common between modern and classic * feat(seed): Array to string file content * fix(files): Modern files should be polyvinyls * feat(Modern): Create editors per file * fix(seed/React): Incorrect keyfile name * feat(Modern): Highligh jsx correctly This adds highlighting for jsx. Unfortunately, this disables linting for non-javascript files as jshint will only work for those * feat(rechallenge): Add jsx ext to babel transformer * feat(seed): Normalize challenge files head/tail/content * refactor(rechallenge/build): Rename function * fix(code-storage): Pull in files from localStorage * feat(Modern/React): Add Enzyme to test runner This enables testing of React challenges * feat(Modern): Add submission type * refactor(Panes): Rename panes map update action
151 lines
3.4 KiB
JavaScript
151 lines
3.4 KiB
JavaScript
import React, { PureComponent } from 'react';
|
|
import PropTypes from 'prop-types';
|
|
import { Button, ButtonGroup, Tooltip, OverlayTrigger } from 'react-bootstrap';
|
|
|
|
const unlockWarning = (
|
|
<Tooltip id='tooltip'>
|
|
<h4>
|
|
<strong>Careful!</strong> Only run code you trust
|
|
</h4>
|
|
</Tooltip>
|
|
);
|
|
|
|
const propTypes = {
|
|
executeChallenge: PropTypes.func.isRequired,
|
|
helpChatRoom: PropTypes.string,
|
|
hint: PropTypes.string,
|
|
isCodeLocked: PropTypes.bool,
|
|
makeToast: PropTypes.func.isRequired,
|
|
openBugModal: PropTypes.func.isRequired,
|
|
unlockUntrustedCode: PropTypes.func.isRequired,
|
|
updateHint: PropTypes.func.isRequired
|
|
};
|
|
|
|
export default class ToolPanel extends PureComponent {
|
|
constructor(...props) {
|
|
super(...props);
|
|
this.makeHint = this.makeHint.bind(this);
|
|
this.makeReset = this.makeReset.bind(this);
|
|
}
|
|
makeHint() {
|
|
this.props.makeToast({
|
|
message: this.props.hint,
|
|
timeout: 4000
|
|
});
|
|
this.props.updateHint();
|
|
}
|
|
|
|
makeReset() {
|
|
this.props.makeToast({
|
|
message: 'This will restore your code editor to its original state.',
|
|
action: 'clear my code',
|
|
actionCreator: 'clickOnReset',
|
|
timeout: 4000
|
|
});
|
|
}
|
|
|
|
renderHint(hint, makeHint) {
|
|
if (!hint) {
|
|
return null;
|
|
}
|
|
return (
|
|
<Button
|
|
block={ true }
|
|
bsStyle='primary'
|
|
className='btn-big'
|
|
onClick={ makeHint }
|
|
>
|
|
Hint
|
|
</Button>
|
|
);
|
|
}
|
|
|
|
renderExecute(isCodeLocked, executeChallenge, unlockUntrustedCode) {
|
|
if (isCodeLocked) {
|
|
return (
|
|
<OverlayTrigger
|
|
overlay={ unlockWarning }
|
|
placement='right'
|
|
>
|
|
<Button
|
|
block={ true }
|
|
bsStyle='primary'
|
|
className='btn-big'
|
|
onClick={ unlockUntrustedCode }
|
|
>
|
|
Code Locked. Unlock?
|
|
</Button>
|
|
</OverlayTrigger>
|
|
);
|
|
}
|
|
return (
|
|
<Button
|
|
block={ true }
|
|
bsStyle='primary'
|
|
className='btn-big'
|
|
onClick={ executeChallenge }
|
|
>
|
|
Run tests (ctrl + enter)
|
|
</Button>
|
|
);
|
|
}
|
|
|
|
render() {
|
|
const {
|
|
executeChallenge,
|
|
helpChatRoom,
|
|
hint,
|
|
isCodeLocked,
|
|
openBugModal,
|
|
unlockUntrustedCode
|
|
} = this.props;
|
|
return (
|
|
<div>
|
|
{ this.renderHint(hint, this.makeHint) }
|
|
{
|
|
this.renderExecute(
|
|
isCodeLocked,
|
|
executeChallenge,
|
|
unlockUntrustedCode
|
|
)
|
|
}
|
|
<div className='button-spacer' />
|
|
<ButtonGroup
|
|
className='input-group'
|
|
justified={ true }
|
|
>
|
|
<Button
|
|
bsSize='large'
|
|
bsStyle='primary'
|
|
componentClass='label'
|
|
onClick={ this.makeReset }
|
|
>
|
|
Reset
|
|
</Button>
|
|
<Button
|
|
bsSize='large'
|
|
bsStyle='primary'
|
|
componentClass='a'
|
|
href={ `https://gitter.im/freecodecamp/${helpChatRoom}` }
|
|
target='_blank'
|
|
>
|
|
Help
|
|
</Button>
|
|
<Button
|
|
bsSize='large'
|
|
bsStyle='primary'
|
|
componentClass='label'
|
|
onClick={ openBugModal }
|
|
>
|
|
Bug
|
|
</Button>
|
|
</ButtonGroup>
|
|
<div className='button-spacer' />
|
|
</div>
|
|
);
|
|
}
|
|
}
|
|
|
|
ToolPanel.displayName = 'ToolPanel';
|
|
ToolPanel.propTypes = propTypes;
|