Skip to content

Commit

Permalink
[explorev2] making Datasource an Viz controls not clearable (#1845)
Browse files Browse the repository at this point in the history
* [explorev2] making Datasource an Viz controls not clearable

* Making choices default to empty list
  • Loading branch information
mistercrunch authored Dec 15, 2016
1 parent 92aa1a6 commit bf67d64
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 11 deletions.
27 changes: 16 additions & 11 deletions superset/assets/javascripts/explorev2/components/SelectField.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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,
choices: [],
clearable: true,
description: null,
freeForm: false,
value: '',
label: null,
description: null,
multi: false,
onChange: () => {},
value: '',
};

export default class SelectField extends React.Component {
Expand Down Expand Up @@ -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 });
}
Expand All @@ -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),
};
Expand Down
2 changes: 2 additions & 0 deletions superset/assets/javascripts/explorev2/stores/fields.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ export const fields = {
datasource: {
type: 'SelectField',
label: 'Datasource',
clearable: false,
default: null,
choices: [],
description: '',
Expand All @@ -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',
Expand Down

0 comments on commit bf67d64

Please sign in to comment.