mirror of
https://github.com/apache/superset.git
synced 2024-09-17 11:09:47 -04:00
[explorev2] making Datasource an Viz controls not clearable (#1845)
* [explorev2] making Datasource an Viz controls not clearable * Making choices default to empty list
This commit is contained in:
parent
92aa1a6124
commit
bf67d64708
@ -5,23 +5,26 @@ import Select, { Creatable } from 'react-select';
|
||||
|
||||
|
||||
const propTypes = {
|
||||
name: PropTypes.string.isRequired,
|
||||
choices: PropTypes.array,
|
||||
value: PropTypes.oneOfType([PropTypes.string, PropTypes.number, PropTypes.array]).isRequired,
|
||||
label: PropTypes.string,
|
||||
clearable: PropTypes.bool,
|
||||
description: PropTypes.string,
|
||||
onChange: PropTypes.func,
|
||||
multi: PropTypes.bool,
|
||||
freeForm: PropTypes.bool,
|
||||
label: PropTypes.string,
|
||||
multi: PropTypes.bool,
|
||||
name: PropTypes.string.isRequired,
|
||||
onChange: PropTypes.func,
|
||||
value: PropTypes.oneOfType([PropTypes.string, PropTypes.number, PropTypes.array]),
|
||||
};
|
||||
|
||||
const defaultProps = {
|
||||
multi: false,
|
||||
freeForm: false,
|
||||
value: '',
|
||||
label: null,
|
||||
choices: [],
|
||||
clearable: true,
|
||||
description: null,
|
||||
freeForm: false,
|
||||
label: null,
|
||||
multi: false,
|
||||
onChange: () => {},
|
||||
value: '',
|
||||
};
|
||||
|
||||
export default class SelectField extends React.Component {
|
||||
@ -50,10 +53,11 @@ export default class SelectField extends React.Component {
|
||||
return opt.label;
|
||||
}
|
||||
render() {
|
||||
const options = this.props.choices.map((c) => ({ value: c[0], label: c[1] }));
|
||||
const choices = this.props.choices;
|
||||
const options = choices.map((c) => ({ value: c[0], label: c[1] }));
|
||||
if (this.props.freeForm) {
|
||||
// For FreeFormSelect, insert value into options if not exist
|
||||
const values = this.props.choices.map((c) => c[0]);
|
||||
const values = choices.map((c) => c[0]);
|
||||
if (values.indexOf(this.props.value) === -1) {
|
||||
options.push({ value: this.props.value, label: this.props.value });
|
||||
}
|
||||
@ -62,10 +66,11 @@ export default class SelectField extends React.Component {
|
||||
const selectProps = {
|
||||
multi: this.props.multi,
|
||||
name: `select-${this.props.name}`,
|
||||
placeholder: `Select (${this.props.choices.length})`,
|
||||
placeholder: `Select (${choices.length})`,
|
||||
options,
|
||||
value: this.props.value,
|
||||
autosize: false,
|
||||
clearable: this.props.clearable,
|
||||
onChange: this.onChange.bind(this),
|
||||
optionRenderer: this.renderOption.bind(this),
|
||||
};
|
||||
|
@ -39,6 +39,7 @@ export const fields = {
|
||||
datasource: {
|
||||
type: 'SelectField',
|
||||
label: 'Datasource',
|
||||
clearable: false,
|
||||
default: null,
|
||||
choices: [],
|
||||
description: '',
|
||||
@ -47,6 +48,7 @@ export const fields = {
|
||||
viz_type: {
|
||||
type: 'SelectField',
|
||||
label: 'Viz',
|
||||
clearable: false,
|
||||
default: 'table',
|
||||
choices: formatSelectOptions(Object.keys(visTypes)),
|
||||
description: 'The type of visualization to display',
|
||||
|
Loading…
Reference in New Issue
Block a user