Skip to content

Commit

Permalink
fix: allow creating table option and remove schema requirement in dat…
Browse files Browse the repository at this point in the history
…aset add modal (apache#10369)

(cherry picked from commit 09dfbab)
  • Loading branch information
nytai authored and craig-rueda committed Aug 24, 2020
1 parent d81e52a commit 7fcee82
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 28 deletions.
70 changes: 44 additions & 26 deletions superset-frontend/src/components/TableSelector.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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)}
Expand Down
4 changes: 2 additions & 2 deletions superset-frontend/src/views/datasetList/DatasetModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -65,15 +65,15 @@ const DatasetModal: FunctionComponent<DatasetModalProps> = ({
tableName: string;
}) => {
setDatasourceId(dbId);
setDisableSave(isNil(dbId) || isEmpty(schema) || isEmpty(tableName));
setDisableSave(isNil(dbId) || isEmpty(tableName));
setSchema(schema);
setTableName(tableName);
};

const onSave = () => {
const data = {
database: datasourceId,
schema: currentSchema,
...(currentSchema ? { schema: currentSchema } : {}),
table_name: currentTableName,
};
SupersetClient.post({
Expand Down

0 comments on commit 7fcee82

Please sign in to comment.