11const React = require ( "react" ) ;
2- const { DOM : dom } = React ;
2+ const { DOM : dom , PropTypes } = React ;
33const { connect } = require ( "react-redux" ) ;
44const { bindActionCreators } = require ( "redux" ) ;
55const actions = require ( "../actions" ) ;
66const { isEnabled } = require ( "../feature" ) ;
7- const { getSelectedSource } = require ( "../selectors" ) ;
7+ const { getSelectedSource, getSourceText } = require ( "../selectors" ) ;
88const Svg = require ( "./utils/Svg" ) ;
9+ const ImPropTypes = require ( "react-immutable-proptypes" ) ;
10+ const classnames = require ( "classnames" ) ;
911
1012function debugBtn ( onClick , type , className = "active" , tooltip ) {
1113 className = `${ type } ${ className } ` ;
@@ -15,33 +17,58 @@ function debugBtn(onClick, type, className = "active", tooltip) {
1517 ) ;
1618}
1719
18- function SourceFooter ( { togglePrettyPrint, selectedSource } ) {
19- const commandsEnabled = selectedSource ? "" : "disabled" ;
20-
21- return dom . div (
22- {
23- className : "source-footer"
24- } ,
25- dom . div ( { className : "command-bar" } ,
26- isEnabled ( "blackbox" ) ? debugBtn (
27- ( ) => { } ,
28- "blackBox" ,
29- commandsEnabled ,
30- "Toggle Black Boxing"
31- ) : null ,
32- debugBtn (
33- ( ) => togglePrettyPrint ( selectedSource . get ( "id" ) ) ,
34- "prettyPrint" ,
35- commandsEnabled ,
36- "Prettify Source"
20+ const SourceFooter = React . createClass ( {
21+ propTypes : {
22+ selectedSource : ImPropTypes . map . isRequired ,
23+ togglePrettyPrint : PropTypes . func ,
24+ sourceText : ImPropTypes . map . isRequired
25+ } ,
26+
27+ displayName : "Editor" ,
28+
29+ blackboxButton ( ) {
30+ if ( ! isEnabled ( "blackbox" ) ) {
31+ return null ;
32+ }
33+
34+ return debugBtn (
35+ ( ) => { } ,
36+ "blackBox" ,
37+ this . props . selectedSource ,
38+ "Toggle Black Boxing"
39+ ) ;
40+ } ,
41+
42+ prettyPrintButton ( ) {
43+ const { selectedSource, sourceText, togglePrettyPrint } = this . props ;
44+ const sourceLoaded = selectedSource && ! sourceText . get ( "loading" ) ;
45+
46+ return debugBtn (
47+ ( ) => togglePrettyPrint ( selectedSource . get ( "id" ) ) ,
48+ "prettyPrint" ,
49+ classnames ( { active : sourceLoaded } ) ,
50+ "Prettify Source"
51+ ) ;
52+ } ,
53+
54+ render ( ) {
55+ return dom . div ( { className : "source-footer" } ,
56+ dom . div ( { className : "command-bar" } ,
57+ this . blackboxButton ( ) ,
58+ this . prettyPrintButton ( )
3759 )
38- )
39- ) ;
40- }
60+ ) ;
61+ }
62+ } ) ;
4163
4264module . exports = connect (
43- state => ( {
44- selectedSource : getSelectedSource ( state ) ,
45- } ) ,
65+ state => {
66+ const selectedSource = getSelectedSource ( state ) ;
67+ const selectedId = selectedSource && selectedSource . get ( "id" ) ;
68+ return {
69+ selectedSource,
70+ sourceText : getSourceText ( state , selectedId )
71+ } ;
72+ } ,
4673 dispatch => bindActionCreators ( actions , dispatch )
4774) ( SourceFooter ) ;
0 commit comments