[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:
Maxime Beauchemin 2016-12-15 08:53:15 -08:00 committed by GitHub
parent 92aa1a6124
commit bf67d64708
2 changed files with 19 additions and 12 deletions

View File

@ -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),
};

View File

@ -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',