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 (#10369)
  • Loading branch information
nytai authored Jul 24, 2020
1 parent 0483c26 commit 09dfbab
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 @@ -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';
Expand Down Expand Up @@ -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)}
Expand Down
4 changes: 2 additions & 2 deletions superset-frontend/src/views/datasetList/AddDatasetModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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);
};
Expand All @@ -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' },
Expand Down

0 comments on commit 09dfbab

Please sign in to comment.