fix: allow creating table option and remove schema requirement in dataset add modal (#10369)

This commit is contained in:
ʈᵃᵢ 2020-07-24 13:17:44 -07:00 committed by GitHub
parent 0483c26254
commit 09dfbab7ed
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 46 additions and 28 deletions

View File

@ -20,7 +20,7 @@ import React from 'react';
import styled from '@superset-ui/style';
import PropTypes from 'prop-types';
import rison from 'rison';
import { Select, AsyncSelect } from 'src/components/Select';
import { AsyncSelect, CreatableSelect, Select } from 'src/components/Select';
import { Label } from 'react-bootstrap';
import { t } from '@superset-ui/translation';
import { SupersetClient } from '@superset-ui/connection';
@ -358,31 +358,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)}

View File

@ -73,7 +73,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);
};
@ -83,7 +83,7 @@ const DatasetModal: FunctionComponent<DatasetModalProps> = ({
endpoint: '/api/v1/dataset/',
body: JSON.stringify({
database: datasourceId,
schema: currentSchema,
...(currentSchema ? { schema: currentSchema } : {}),
table_name: currentTableName,
}),
headers: { 'Content-Type': 'application/json' },