This is an automated email from the ASF dual-hosted git repository. ccwilliams pushed a commit to branch chris--ajax-datasource-editor in repository https://gitbox.apache.org/repos/asf/incubator-superset.git
commit 089785fe7a28da3cc2218a772f1d14c01e3e4788 Author: Chris Williams <chris.willi...@airbnb.com> AuthorDate: Wed Oct 17 13:11:03 2018 -0700 [superset-client][datasource control] replace ajax with SupersetClient --- .../components/controls/DatasourceControl.jsx | 55 ++++++++++++---------- 1 file changed, 29 insertions(+), 26 deletions(-) diff --git a/superset/assets/src/explore/components/controls/DatasourceControl.jsx b/superset/assets/src/explore/components/controls/DatasourceControl.jsx index 69f398d..fcecdaf 100644 --- a/superset/assets/src/explore/components/controls/DatasourceControl.jsx +++ b/superset/assets/src/explore/components/controls/DatasourceControl.jsx @@ -9,7 +9,7 @@ import { Tooltip, Well, } from 'react-bootstrap'; -import $ from 'jquery'; +import { SupersetClient } from '@superset-ui/core'; import ControlHeader from '../ControlHeader'; import { t } from '../../../locales'; @@ -39,70 +39,72 @@ class DatasourceControl extends React.PureComponent { showEditDatasourceModal: false, loading: true, showDatasource: false, + datasources: null, }; this.toggleShowDatasource = this.toggleShowDatasource.bind(this); this.toggleEditDatasourceModal = this.toggleEditDatasourceModal.bind(this); this.setSearchRef = this.setSearchRef.bind(this); this.selectDatasource = this.selectDatasource.bind(this); } + onChange(vizType) { this.props.onChange(vizType); - this.setState({ showModal: false }); + this.setState(() => ({ showModal: false })); } + onEnterModal() { if (this.searchRef) { this.searchRef.focus(); } - const url = '/superset/datasources/'; - const that = this; if (!this.state.datasources) { - $.ajax({ - type: 'GET', - url, - success: (data) => { - const datasources = data.map(ds => ({ + SupersetClient.get({ endpoint: '/superset/datasources/' }) + .then(({ json }) => { + const datasources = json.map(ds => ({ rawName: ds.name, connection: ds.connection, schema: ds.schema, - name: ( - <a - href="#" - onClick={this.selectDatasource.bind(this, ds.uid)} - className="datasource-link" - > - {ds.name} - </a> - ), + name: ( + <a + href="#" + onClick={this.selectDatasource.bind(this, ds.uid)} + className="datasource-link" + > + {ds.name} + </a> + ), type: ds.type, })); - that.setState({ loading: false, datasources }); - }, - error() { - that.setState({ loading: false }); + this.setState(() => ({ loading: false, datasources })); + }) + .catch(() => { + this.setState(() => ({ loading: false })); this.props.addDangerToast(t('Something went wrong while fetching the datasource list')); - }, - }); + }); } } + setSearchRef(searchRef) { this.searchRef = searchRef; } + toggleShowDatasource() { this.setState({ showDatasource: !this.state.showDatasource }); } + toggleModal() { this.setState({ showModal: !this.state.showModal }); } + selectDatasource(datasourceId) { this.setState({ showModal: false }); this.props.onChange(datasourceId); } + toggleEditDatasourceModal() { this.setState({ showEditDatasourceModal: !this.state.showEditDatasourceModal }); } - renderModal() { - } + renderDatasource() { const datasource = this.props.datasource; return ( @@ -136,6 +138,7 @@ class DatasourceControl extends React.PureComponent { </div> ); } + render() { return ( <div>