This is an automated email from the ASF dual-hosted git repository. villebro pushed a commit to branch 0.37 in repository https://gitbox.apache.org/repos/asf/incubator-superset.git
commit 19cc65beb6009a65e7ab5e6a747acb09892702f1 Author: ʈᵃᵢ <tdupree...@gmail.com> AuthorDate: Fri Jul 24 13:17:44 2020 -0700 fix: allow creating table option and remove schema requirement in dataset add modal (#10369) (cherry picked from commit 09dfbab7ed7cdb518109fa3fb093ce20d52fa8af) --- superset-frontend/src/components/TableSelector.jsx | 70 ++++++++++++++-------- .../src/views/datasetList/DatasetModal.tsx | 4 +- 2 files changed, 46 insertions(+), 28 deletions(-) diff --git a/superset-frontend/src/components/TableSelector.jsx b/superset-frontend/src/components/TableSelector.jsx index a477c85..3055955 100644 --- a/superset-frontend/src/components/TableSelector.jsx +++ b/superset-frontend/src/components/TableSelector.jsx @@ -19,7 +19,7 @@ import React from 'react'; import styled from '@superset-ui/style'; import PropTypes from 'prop-types'; -import { Select, AsyncSelect } from 'src/components/Select'; +import { AsyncSelect, CreatableSelect, Select } from 'src/components/Select'; import { ControlLabel, Label } from 'react-bootstrap'; import { t } from '@superset-ui/translation'; import { SupersetClient } from '@superset-ui/connection'; @@ -342,31 +342,49 @@ export default class TableSelector extends React.PureComponent { tableSelectDisabled = true; } const options = this.state.tableOptions; - const select = this.props.schema ? ( - <Select - name="select-table" - isLoading={this.state.tableLoading} - ignoreAccents={false} - placeholder={t('Select table or type table name')} - autosize={false} - onChange={this.changeTable} - options={options} - value={this.state.tableName} - optionRenderer={this.renderTableOption} - /> - ) : ( - <AsyncSelect - name="async-select-table" - placeholder={tableSelectPlaceholder} - disabled={tableSelectDisabled} - autosize={false} - onChange={this.changeTable} - value={this.state.tableName} - loadOptions={this.getTableNamesBySubStr} - optionRenderer={this.renderTableOption} - isDisabled={this.props.formMode} - /> - ); + let select = null; + if (this.props.schema && !this.props.formMode) { + select = ( + <Select + name="select-table" + isLoading={this.state.tableLoading} + ignoreAccents={false} + placeholder={t('Select table or type table name')} + autosize={false} + onChange={this.changeTable} + options={options} + value={this.state.tableName} + optionRenderer={this.renderTableOption} + /> + ); + } else if (this.props.formMode) { + select = ( + <CreatableSelect + name="select-table" + isLoading={this.state.tableLoading} + ignoreAccents={false} + placeholder={t('Select table or type table name')} + autosize={false} + onChange={this.changeTable} + options={options} + value={this.state.tableName} + optionRenderer={this.renderTableOption} + /> + ); + } else { + select = ( + <AsyncSelect + name="async-select-table" + placeholder={tableSelectPlaceholder} + isDisabled={tableSelectDisabled} + autosize={false} + onChange={this.changeTable} + value={this.state.tableName} + loadOptions={this.getTableNamesBySubStr} + optionRenderer={this.renderTableOption} + /> + ); + } const refresh = !this.props.formMode && ( <RefreshLabel onClick={() => this.changeSchema({ value: this.props.schema }, true)} diff --git a/superset-frontend/src/views/datasetList/DatasetModal.tsx b/superset-frontend/src/views/datasetList/DatasetModal.tsx index 0e43d26..d6a0fb7 100644 --- a/superset-frontend/src/views/datasetList/DatasetModal.tsx +++ b/superset-frontend/src/views/datasetList/DatasetModal.tsx @@ -65,7 +65,7 @@ const DatasetModal: FunctionComponent<DatasetModalProps> = ({ tableName: string; }) => { setDatasourceId(dbId); - setDisableSave(isNil(dbId) || isEmpty(schema) || isEmpty(tableName)); + setDisableSave(isNil(dbId) || isEmpty(tableName)); setSchema(schema); setTableName(tableName); }; @@ -73,7 +73,7 @@ const DatasetModal: FunctionComponent<DatasetModalProps> = ({ const onSave = () => { const data = { database: datasourceId, - schema: currentSchema, + ...(currentSchema ? { schema: currentSchema } : {}), table_name: currentTableName, }; SupersetClient.post({