-
Notifications
You must be signed in to change notification settings - Fork 14.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
26 changed files
with
631 additions
and
265 deletions.
There are no files selected for viewing
This file contains 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 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.
18 changes: 18 additions & 0 deletions
18
superset/assets/javascripts/SqlLab/components/AlertsWrapper.jsx
This file contains 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 React from 'react'; | ||
import AlertContainer from 'react-alert'; | ||
|
||
export default class AlertsWrapper extends React.PureComponent { | ||
render() { | ||
return ( | ||
<AlertContainer | ||
ref={ref => { | ||
global.notify = ref; | ||
}} | ||
offset={14} | ||
position="top right" | ||
theme="dark" | ||
time={5000} | ||
transition="scale" | ||
/>); | ||
} | ||
} |
This file contains 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 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
139 changes: 139 additions & 0 deletions
139
superset/assets/javascripts/SqlLab/components/SaveQuery.jsx
This file contains 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,139 @@ | ||
/* global notify */ | ||
import React from 'react'; | ||
import { FormControl, FormGroup, Overlay, Popover, Row, Col } from 'react-bootstrap'; | ||
import Button from '../../components/Button'; | ||
const $ = window.$ = require('jquery'); | ||
|
||
const propTypes = { | ||
defaultLabel: React.PropTypes.string, | ||
sql: React.PropTypes.string, | ||
schema: React.PropTypes.string, | ||
dbId: React.PropTypes.number, | ||
animation: React.PropTypes.bool, | ||
}; | ||
const defaultProps = { | ||
defaultLabel: 'Undefined', | ||
animation: true, | ||
}; | ||
|
||
class SaveQuery extends React.PureComponent { | ||
constructor(props) { | ||
super(props); | ||
this.state = { | ||
description: '', | ||
label: props.defaultLabel, | ||
showSave: false, | ||
}; | ||
this.toggleSave = this.toggleSave.bind(this); | ||
this.onSave = this.onSave.bind(this); | ||
this.onCancel = this.onCancel.bind(this); | ||
this.onLabelChange = this.onLabelChange.bind(this); | ||
this.onDescriptionChange = this.onDescriptionChange.bind(this); | ||
} | ||
onSave() { | ||
const url = '/savedqueryviewapi/api/create'; | ||
const data = { | ||
label: this.state.label, | ||
description: this.state.description, | ||
db_id: this.props.dbId, | ||
schema: this.props.schema, | ||
sql: this.props.sql, | ||
csrf_token: $('input#csrf_token').val(), | ||
}; | ||
$.ajax({ | ||
type: 'POST', | ||
url, | ||
data, | ||
success: () => notify.success('The query was saved'), | ||
error: e => notify.error(`The query couldn't be saved. \n${e}`), | ||
dataType: 'json', | ||
}); | ||
this.setState({ showSave: false }); | ||
} | ||
onCancel() { | ||
this.setState({ showSave: false }); | ||
} | ||
onLabelChange(e) { | ||
this.setState({ label: e.target.value }); | ||
} | ||
onDescriptionChange(e) { | ||
this.setState({ description: e.target.value }); | ||
} | ||
renderPopover() { | ||
return ( | ||
<Popover id="embed-code-popover"> | ||
<FormGroup bsSize="small" style={{ width: '350px' }}> | ||
<Row> | ||
<Col md={12}> | ||
<small> | ||
<label className="control-label" htmlFor="embed-height"> | ||
Label | ||
</label> | ||
</small> | ||
<FormControl | ||
type="text" | ||
placeholder="Label for your query" | ||
value={this.state.label} | ||
onChange={this.onLabelChange} | ||
/> | ||
</Col> | ||
</Row> | ||
<br /> | ||
<Row> | ||
<Col md={12}> | ||
<small> | ||
<label className="control-label" htmlFor="embed-height">Description</label> | ||
</small> | ||
<FormControl | ||
componentClass="textarea" | ||
placeholder="textarea" | ||
value={this.state.description} | ||
onChange={this.onDescriptionChange} | ||
/> | ||
</Col> | ||
</Row> | ||
<br /> | ||
<Row> | ||
<Col md={12}> | ||
<Button | ||
bsStyle="primary" | ||
onClick={this.onSave} | ||
className="m-r-3" | ||
> | ||
Save | ||
</Button> | ||
<Button onClick={this.onCancel} className="cancelQuery"> | ||
Cancel | ||
</Button> | ||
</Col> | ||
</Row> | ||
</FormGroup> | ||
</Popover> | ||
); | ||
} | ||
toggleSave(e) { | ||
this.setState({ target: e.target, showSave: !this.state.showSave }); | ||
} | ||
render() { | ||
return ( | ||
<span className="SaveQuery"> | ||
<Overlay | ||
trigger="click" | ||
target={this.state.target} | ||
show={this.state.showSave} | ||
placement="bottom" | ||
animation={this.props.animation} | ||
> | ||
{this.renderPopover()} | ||
</Overlay> | ||
<Button bsSize="small" className="toggleSave" onClick={this.toggleSave}> | ||
<i className="fa fa-save" /> Save | ||
</Button> | ||
</span> | ||
); | ||
} | ||
} | ||
SaveQuery.propTypes = propTypes; | ||
SaveQuery.defaultProps = defaultProps; | ||
|
||
export default SaveQuery; |
This file contains 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 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 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
11 changes: 11 additions & 0 deletions
11
superset/assets/spec/javascripts/sqllab/AlertsWrapper_spec.jsx
This file contains 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 @@ | ||
import React from 'react'; | ||
import AlertsWrapper from '../../../javascripts/SqlLab/components/AlertsWrapper'; | ||
import { describe, it } from 'mocha'; | ||
import { expect } from 'chai'; | ||
|
||
|
||
describe('AlertsWrapper', () => { | ||
it('is valid', () => { | ||
expect(React.isValidElement(<AlertsWrapper />)).to.equal(true); | ||
}); | ||
}); |
Oops, something went wrong.