mirror of
https://github.com/apache/superset.git
synced 2026-06-06 16:19:18 +00:00
[explore V2] render all control panels and fields dynamically for each vis type (#1493)
* export functions directly rather than object at the bottom * move viztypes to controlPanelMappings, add fieldset rows and section data * for each viz type, render a controlPanelsContainer, controlPanelSections, FieldSetRows, and FieldsSets * add comments, move mappings to store * organize store and add default sections * render all the needed sections * add tooltip to sections * remove console log * use only panel panel-default, not panel-body, no need the padding * render fields for all fields in field set * add the rest of the control panel sections and field overrides * fix naming * add fieldTypes array * don't use default section * pass only needed state via mapStateToProps * fix code climate errors * linting * move field components to their own files * render field sets as lists * fix field components * use SFC * update modal trigger test to be more accurate * add FieldSetRow test * add test for controlpanelsContainer * fix test * make code climate happy * add freeform select field
This commit is contained in:
@@ -1,27 +1,62 @@
|
||||
import React from 'react';
|
||||
import React, { PropTypes } from 'react';
|
||||
import { bindActionCreators } from 'redux';
|
||||
import * as actions from '../actions/exploreActions';
|
||||
import { connect } from 'react-redux';
|
||||
import { Panel } from 'react-bootstrap';
|
||||
import { DefaultControls, VIZ_CONTROL_MAPPING } from '../constants';
|
||||
import { visTypes, commonControlPanelSections } from '../stores/store';
|
||||
import ControlPanelSection from './ControlPanelSection';
|
||||
import FieldSetRow from './FieldSetRow';
|
||||
|
||||
const propTypes = {
|
||||
vizType: React.PropTypes.string,
|
||||
vizType: PropTypes.string,
|
||||
datasourceId: PropTypes.number.isRequired,
|
||||
datasourceType: PropTypes.string.isRequired,
|
||||
actions: PropTypes.object.isRequired,
|
||||
};
|
||||
|
||||
const defaultProps = {
|
||||
vizType: null,
|
||||
};
|
||||
|
||||
function ControlPanelsContainer(props) {
|
||||
return (
|
||||
<Panel>
|
||||
<div className="scrollbar-container">
|
||||
<div className="scrollbar-content">
|
||||
{DefaultControls}
|
||||
{VIZ_CONTROL_MAPPING[props.vizType]}
|
||||
function getSectionsToRender(vizSections) {
|
||||
const { datasourceAndVizType, sqlClause } = commonControlPanelSections;
|
||||
const sectionsToRender = [datasourceAndVizType].concat(vizSections, sqlClause);
|
||||
return sectionsToRender;
|
||||
}
|
||||
|
||||
class ControlPanelsContainer extends React.Component {
|
||||
componentWillMount() {
|
||||
const { datasourceId, datasourceType } = this.props;
|
||||
if (datasourceId) {
|
||||
this.props.actions.setFormOpts(datasourceId, datasourceType);
|
||||
}
|
||||
}
|
||||
|
||||
render() {
|
||||
const viz = visTypes[this.props.vizType];
|
||||
const sectionsToRender = getSectionsToRender(viz.controlPanelSections);
|
||||
|
||||
return (
|
||||
<Panel>
|
||||
<div className="scrollbar-container">
|
||||
<div className="scrollbar-content">
|
||||
{sectionsToRender.map((section) => (
|
||||
<ControlPanelSection
|
||||
key={section.label}
|
||||
label={section.label}
|
||||
tooltip={section.description}
|
||||
>
|
||||
{section.fieldSetRows.map((fieldSets, i) => (
|
||||
<FieldSetRow key={`${section.label}-fieldSetRow-${i}`} fieldSets={fieldSets} />
|
||||
))}
|
||||
</ControlPanelSection>
|
||||
))}
|
||||
{/* TODO: add filters section */}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</Panel>
|
||||
);
|
||||
</Panel>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
ControlPanelsContainer.propTypes = propTypes;
|
||||
@@ -29,12 +64,18 @@ ControlPanelsContainer.defaultProps = defaultProps;
|
||||
|
||||
function mapStateToProps(state) {
|
||||
return {
|
||||
datasourceId: state.datasourceId,
|
||||
datasourceType: state.datasourceType,
|
||||
vizType: state.viz.formData.vizType,
|
||||
};
|
||||
}
|
||||
|
||||
function mapDispatchToProps() {
|
||||
return {};
|
||||
function mapDispatchToProps(dispatch) {
|
||||
return {
|
||||
actions: bindActionCreators(actions, dispatch),
|
||||
};
|
||||
}
|
||||
|
||||
export { ControlPanelsContainer };
|
||||
|
||||
export default connect(mapStateToProps, mapDispatchToProps)(ControlPanelsContainer);
|
||||
|
||||
Reference in New Issue
Block a user