Vliu put datasource in store (#1610)

* Move datasource from global store object to form_data

* Moved datasource_id  and datasource_name to form_data

* Refetch defaultFormData when switching datasource

* Fixed js tests
This commit is contained in:
vera-liu
2016-11-17 09:26:25 -08:00
committed by GitHub
parent ab5da5ba28
commit 4f7f437527
9 changed files with 76 additions and 48 deletions

View File

@@ -9,7 +9,6 @@ import ControlPanelSection from './ControlPanelSection';
import FieldSetRow from './FieldSetRow';
const propTypes = {
datasource_id: PropTypes.number.isRequired,
datasource_type: PropTypes.string.isRequired,
actions: PropTypes.object.isRequired,
fields: PropTypes.object.isRequired,
@@ -20,14 +19,24 @@ const propTypes = {
class ControlPanelsContainer extends React.Component {
componentWillMount() {
const { datasource_id, datasource_type } = this.props;
const datasource_id = this.props.form_data.datasource;
const datasource_type = this.props.datasource_type;
if (datasource_id) {
this.props.actions.fetchFieldOptions(datasource_id, datasource_type);
}
}
onChange(name, value) {
this.props.actions.setFieldValue(name, value);
componentWillReceiveProps(nextProps) {
if (nextProps.form_data.datasource !== this.props.form_data.datasource) {
if (nextProps.form_data.datasource) {
this.props.actions.fetchFieldOptions(
nextProps.form_data.datasource, nextProps.datasource_type);
}
}
}
onChange(name, value, label) {
this.props.actions.setFieldValue(name, value, label);
}
sectionsToRender() {
@@ -82,7 +91,6 @@ function mapStateToProps(state) {
return {
isDatasourceMetaLoading: state.isDatasourceMetaLoading,
fields: state.fields,
datasource_id: state.datasource_id,
datasource_type: state.datasource_type,
form_data: state.viz.form_data,
};