Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Translate string to array for multi fields in getControlsState #5057

Merged
merged 2 commits into from
May 24, 2018
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions superset/assets/src/explore/store.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,10 @@ export function getControlsState(state, form_data) {
delete control.mapStateToProps;
}

if (control.multi && typeof formData[k] === 'string') {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: formData[k] = (control.multi && typeof formData[k] === 'string') ? [formData[k]] : formData[k]

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would !Array.isArray(formData[k]) be better?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we'd want to stick with typeof formData[k] === 'string' because formData[k] might be undefined or null and we would want to leave it as null.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Though I think it can be a int / float too.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah ok, updated it to formData[k] && !Array.isArray(formData[k]).

formData[k] = [formData[k]];
}

// If the value is not valid anymore based on choices, clear it
if (control.type === 'SelectControl' && control.choices && k !== 'datasource' && formData[k]) {
const choiceValues = control.choices.map(c => c[0]);
Expand Down