Skip to content

Commit

Permalink
feat: add keyboard shortcut for submitting the Code View
Browse files Browse the repository at this point in the history
  • Loading branch information
grailian committed Jul 4, 2017
1 parent fa3af7c commit e92a322
Showing 1 changed file with 24 additions and 6 deletions.
30 changes: 24 additions & 6 deletions app/components/Explorer/ExplorerBody/Views/ExplorerCodeView.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import React from 'react';
import classNames from 'classnames';
import ace from 'brace';
import { connect } from "react-redux";
import Segment from '../../../../services/segment.service';
import { saveRow } from '../../../../actions';

// Looks weird, but this is necessary to apply the theme to ace editor
require('brace/mode/json');
Expand Down Expand Up @@ -42,8 +44,14 @@ const ExplorerCodeView = React.createClass({
});

this.editor.getSession().on('changeScrollTop', this.handleScroll);
this.editor.commands.addCommand({
name: "submit",
bindKey: { win: "Ctrl-Enter", mac: "Command-Enter" },
exec: (editor) =>{
this.props.save(this.props.dbConnection, this.props.selectedTable, editor.getValue());
}
});
this.handleScroll(0);

},
handleScroll: function(scrollPos) {

Expand Down Expand Up @@ -105,26 +113,28 @@ const ExplorerCodeView = React.createClass({
<div className="explorer-code-view" style={{
'height': window.innerHeight - 105,
'width': '100%'
}}>
}}
onKeyUp={this.handleKeyPress}>
<div className={toastClasses}>
<div className="row">
<i className="btn fa fa-close pull-right" onClick={this.props.clearCodeBodyError}/>
<pre style={{ margin: '5px' }}>{this.props.selectedTable.codeBodyError}</pre>
</div>
</div>
<div id="editor"></div>
<div id="editor"/>
<div className="fixedDataTableLayout_topShadow public_fixedDataTable_topShadow"
style={this.state.topShadowStyle}></div>
style={this.state.topShadowStyle}/>
<div className="fixedDataTableLayout_bottomShadow public_fixedDataTable_bottomShadow"
style={this.state.bottomShadowStyle}></div>
style={this.state.bottomShadowStyle}/>
</div>
);
}
});

const mapStateToProps = (state) => {
return {
selectedTable: state.main.selectedTable
selectedTable: state.main.selectedTable,
dbConnection: state.main.dbConnection
};
};

Expand All @@ -141,6 +151,14 @@ const mapDispatchToProps = (dispatch) => {
type: 'SET_CODE_BODY',
codeBody
});
},
save: (dbConnection, selectedTable, string) => {
dispatch(saveRow(dbConnection, selectedTable, string));

Segment.track({
event: 'Save Record',
properties: {}
});
}
};
};
Expand Down

0 comments on commit e92a322

Please sign in to comment.