mirror of
https://github.com/apache/superset.git
synced 2026-04-21 17:14:57 +00:00
Put formData in store (#1281)
* Put formData in store * Reform actions and reducers * Maded modifications based on comments:
This commit is contained in:
@@ -32,13 +32,13 @@ class ChartControl extends React.Component {
|
||||
this.props.actions.resetFormData();
|
||||
this.props.actions.setFormOpts(val, this.props.datasourceType);
|
||||
}
|
||||
changeViz(vizOpt) {
|
||||
const val = (vizOpt) ? vizOpt.value : null;
|
||||
this.props.actions.setVizType(val);
|
||||
changeViz(opt) {
|
||||
const val = opt ? opt.value : null;
|
||||
this.props.actions.setFormData('vizType', val);
|
||||
}
|
||||
render() {
|
||||
return (
|
||||
<div className="panel space-1">
|
||||
<div className="panel">
|
||||
<div className="panel-header">Chart Options</div>
|
||||
<div className="panel-body">
|
||||
<h5 className="section-heading">Datasource</h5>
|
||||
@@ -77,7 +77,7 @@ function mapStateToProps(state) {
|
||||
datasources: state.datasources,
|
||||
datasourceId: state.datasourceId,
|
||||
datasourceType: state.datasourceType,
|
||||
vizType: state.vizType,
|
||||
vizType: state.viz.formData.vizType,
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -29,7 +29,7 @@ ControlPanelsContainer.defaultProps = defaultProps;
|
||||
|
||||
function mapStateToProps(state) {
|
||||
return {
|
||||
vizType: state.vizType,
|
||||
vizType: state.viz.formData.vizType,
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import React from 'react';
|
||||
import Select from 'react-select';
|
||||
import { bindActionCreators } from 'redux';
|
||||
import * as actions from '../actions/exploreActions';
|
||||
import { connect } from 'react-redux';
|
||||
import SelectArray from './SelectArray';
|
||||
|
||||
const propTypes = {
|
||||
actions: React.PropTypes.object,
|
||||
@@ -19,47 +19,33 @@ const defaultProps = {
|
||||
groupByColumns: [],
|
||||
};
|
||||
|
||||
class GroupBy extends React.Component {
|
||||
changeColumns(groupByColumns) {
|
||||
this.props.actions.setGroupByColumns(groupByColumns);
|
||||
}
|
||||
changeMetrics(metrics) {
|
||||
this.props.actions.setMetrics(metrics);
|
||||
}
|
||||
render() {
|
||||
return (
|
||||
<div className="panel space-1">
|
||||
<div className="panel-header">GroupBy</div>
|
||||
<div className="panel-body">
|
||||
<div className="row">
|
||||
<h5 className="section-heading">GroupBy Column</h5>
|
||||
<Select
|
||||
multi
|
||||
name="select-time-column"
|
||||
placeholder="Select groupby columns"
|
||||
options={this.props.groupByColumnOpts}
|
||||
value={this.props.groupByColumns}
|
||||
autosize={false}
|
||||
onChange={this.changeColumns.bind(this)}
|
||||
/>
|
||||
</div>
|
||||
<div className="row">
|
||||
<h5 className="section-heading">Metrics</h5>
|
||||
<Select
|
||||
multi
|
||||
name="select-since"
|
||||
placeholder="Select metrics"
|
||||
options={this.props.metricsOpts}
|
||||
value={this.props.metrics}
|
||||
autosize={false}
|
||||
onChange={this.changeMetrics.bind(this)}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
const GroupBy = (props) => {
|
||||
const selects = [
|
||||
{
|
||||
key: 'groupByColumns',
|
||||
title: 'Group By',
|
||||
options: props.groupByColumnOpts,
|
||||
value: props.groupByColumns,
|
||||
multi: true,
|
||||
width: '12',
|
||||
},
|
||||
{
|
||||
key: 'metrics',
|
||||
title: 'Metrics',
|
||||
options: props.metricsOpts,
|
||||
value: props.metrics,
|
||||
multi: true,
|
||||
width: '12',
|
||||
}];
|
||||
return (
|
||||
<div className="panel">
|
||||
<div className="panel-header">GroupBy</div>
|
||||
<div className="panel-body">
|
||||
<SelectArray selectArray={selects} />
|
||||
</div>
|
||||
);
|
||||
}
|
||||
}
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
GroupBy.propTypes = propTypes;
|
||||
GroupBy.defaultProps = defaultProps;
|
||||
@@ -67,9 +53,9 @@ GroupBy.defaultProps = defaultProps;
|
||||
function mapStateToProps(state) {
|
||||
return {
|
||||
metricsOpts: state.metricsOpts,
|
||||
metrics: state.metrics,
|
||||
metrics: state.viz.formData.metrics,
|
||||
groupByColumnOpts: state.groupByColumnOpts,
|
||||
groupByColumns: state.groupByColumns,
|
||||
groupByColumns: state.viz.formData.groupByColumns,
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import React from 'react';
|
||||
import Select from 'react-select';
|
||||
import SelectArray from './SelectArray';
|
||||
import { bindActionCreators } from 'redux';
|
||||
import * as actions from '../actions/exploreActions';
|
||||
import { connect } from 'react-redux';
|
||||
@@ -19,47 +19,33 @@ const defaultProps = {
|
||||
orderings: [],
|
||||
};
|
||||
|
||||
class NotGroupBy extends React.Component {
|
||||
changeColumns(columns) {
|
||||
this.props.actions.setNotGroupByColumns(columns);
|
||||
}
|
||||
changeOrderings(orderings) {
|
||||
this.props.actions.setOrderings(orderings);
|
||||
}
|
||||
render() {
|
||||
return (
|
||||
<div className="panel space-1">
|
||||
<div className="panel-header">Not GroupBy</div>
|
||||
<div className="panel-body">
|
||||
<div className="row">
|
||||
<h5 className="section-heading">Columns</h5>
|
||||
<Select
|
||||
multi
|
||||
name="select-column"
|
||||
placeholder="Select columns"
|
||||
options={this.props.columnOpts}
|
||||
value={this.props.columns}
|
||||
autosize={false}
|
||||
onChange={this.changeColumns.bind(this)}
|
||||
/>
|
||||
</div>
|
||||
<div className="row">
|
||||
<h5 className="section-heading">Orderings</h5>
|
||||
<Select
|
||||
multi
|
||||
name="select-orderings"
|
||||
placeholder="Select orderings"
|
||||
options={this.props.orderingOpts}
|
||||
value={this.props.orderings}
|
||||
autosize={false}
|
||||
onChange={this.changeOrderings.bind(this)}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
const NotGroupBy = (props) => {
|
||||
const selects = [
|
||||
{
|
||||
key: 'columns',
|
||||
title: 'Columns',
|
||||
options: props.columnOpts,
|
||||
value: props.columns,
|
||||
multi: true,
|
||||
width: '12',
|
||||
},
|
||||
{
|
||||
key: 'orderings',
|
||||
title: 'Orderings',
|
||||
options: props.orderingOpts,
|
||||
value: props.orderings,
|
||||
multi: true,
|
||||
width: '12',
|
||||
}];
|
||||
return (
|
||||
<div className="panel">
|
||||
<div className="panel-header">Not GroupBy</div>
|
||||
<div className="panel-body">
|
||||
<SelectArray selectArray={selects} />
|
||||
</div>
|
||||
);
|
||||
}
|
||||
}
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
NotGroupBy.propTypes = propTypes;
|
||||
NotGroupBy.defaultProps = defaultProps;
|
||||
@@ -67,9 +53,9 @@ NotGroupBy.defaultProps = defaultProps;
|
||||
function mapStateToProps(state) {
|
||||
return {
|
||||
columnOpts: state.columnOpts,
|
||||
columns: state.columns,
|
||||
columns: state.viz.formData.columns,
|
||||
orderingOpts: state.orderingOpts,
|
||||
orderings: state.orderings,
|
||||
orderings: state.viz.formData.orderings,
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import React from 'react';
|
||||
import Select from 'react-select';
|
||||
import SelectArray from './SelectArray';
|
||||
import { bindActionCreators } from 'redux';
|
||||
import * as actions from '../actions/exploreActions';
|
||||
import { connect } from 'react-redux';
|
||||
@@ -16,54 +16,39 @@ const defaultProps = {
|
||||
rowLimit: null,
|
||||
};
|
||||
|
||||
class Options extends React.Component {
|
||||
changeTimeStampFormat(timeStampFormat) {
|
||||
const val = (timeStampFormat) ? timeStampFormat.value : null;
|
||||
this.props.actions.setTimeStampFormat(val);
|
||||
}
|
||||
changeRowLimit(rowLimit) {
|
||||
this.props.actions.setRowLimit(rowLimit);
|
||||
}
|
||||
render() {
|
||||
return (
|
||||
<div className="panel space-1">
|
||||
<div className="panel-header">Options</div>
|
||||
<div className="panel-body">
|
||||
<div className="row">
|
||||
<h5 className="section-heading">Table Timestamp Format</h5>
|
||||
<Select
|
||||
name="select-timestamp-format"
|
||||
placeholder="Select timestamp format"
|
||||
options={timestampOptions.map((t) => ({ value: t[0], label: t[1] }))}
|
||||
value={this.props.timeStampFormat}
|
||||
autosize={false}
|
||||
onChange={this.changeTimeStampFormat.bind(this)}
|
||||
/>
|
||||
</div>
|
||||
<div className="row">
|
||||
<h5 className="section-heading">Row Limit</h5>
|
||||
<Select
|
||||
name="select-row-limit"
|
||||
placeholder="Select row limit"
|
||||
options={rowLimitOptions.map((r) => ({ value: r, label: r }))}
|
||||
value={this.props.rowLimit}
|
||||
autosize={false}
|
||||
onChange={this.changeRowLimit.bind(this)}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
const Options = (props) => {
|
||||
const selects = [
|
||||
{
|
||||
key: 'timeStampFormat',
|
||||
title: 'Timestamp Format',
|
||||
options: timestampOptions.map((t) => ({ value: t[0], label: t[1] })),
|
||||
value: props.timeStampFormat,
|
||||
width: '12',
|
||||
},
|
||||
{
|
||||
key: 'rowLimit',
|
||||
title: 'Row Limit',
|
||||
options: rowLimitOptions.map((r) => ({ value: r, label: r })),
|
||||
value: props.rowLimit,
|
||||
width: '12',
|
||||
}];
|
||||
return (
|
||||
<div className="panel">
|
||||
<div className="panel-header">Options</div>
|
||||
<div className="panel-body">
|
||||
<SelectArray selectArray={selects} />
|
||||
</div>
|
||||
);
|
||||
}
|
||||
}
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
Options.propTypes = propTypes;
|
||||
Options.defaultProps = defaultProps;
|
||||
|
||||
function mapStateToProps(state) {
|
||||
return {
|
||||
timeStampFormat: state.timeStampFormat,
|
||||
rowLimit: state.rowLimit,
|
||||
timeStampFormat: state.viz.formData.timeStampFormat,
|
||||
rowLimit: state.viz.formData.rowLimit,
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,74 @@
|
||||
import React from 'react';
|
||||
import Select from 'react-select';
|
||||
import { bindActionCreators } from 'redux';
|
||||
import * as actions from '../actions/exploreActions';
|
||||
import { connect } from 'react-redux';
|
||||
|
||||
const propTypes = {
|
||||
actions: React.PropTypes.object,
|
||||
selectArray: React.PropTypes.arrayOf(
|
||||
React.PropTypes.shape({
|
||||
key: React.PropTypes.string.isRequired,
|
||||
title: React.PropTypes.string.isRequired,
|
||||
options: React.PropTypes.array.isRequired,
|
||||
value: React.PropTypes.oneOfType([
|
||||
React.PropTypes.string,
|
||||
React.PropTypes.array,
|
||||
]),
|
||||
width: React.PropTypes.string,
|
||||
multi: React.PropTypes.bool,
|
||||
})
|
||||
).isRequired,
|
||||
};
|
||||
|
||||
const defaultProps = {
|
||||
selectArray: [],
|
||||
};
|
||||
|
||||
class SelectArray extends React.Component {
|
||||
changeSelectData(key, multi, opt) {
|
||||
if (multi) this.props.actions.setFormData(key, opt);
|
||||
else {
|
||||
const val = opt ? opt.value : null;
|
||||
this.props.actions.setFormData(key, val);
|
||||
}
|
||||
}
|
||||
render() {
|
||||
const selects = this.props.selectArray.map((obj) => (
|
||||
<div
|
||||
className={(obj.width) ? `col-sm-${obj.width}` : 'col-sm-6'}
|
||||
key={obj.key}
|
||||
>
|
||||
<h5 className="section-heading">{obj.title}</h5>
|
||||
<Select
|
||||
multi={obj.multi}
|
||||
name={`select-${obj.key}`}
|
||||
options={obj.options}
|
||||
value={obj.value}
|
||||
autosize={false}
|
||||
onChange={this.changeSelectData.bind(this, obj.key, obj.multi)}
|
||||
/>
|
||||
</div>
|
||||
));
|
||||
return (
|
||||
<div>
|
||||
{selects}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
SelectArray.propTypes = propTypes;
|
||||
SelectArray.defaultProps = defaultProps;
|
||||
|
||||
function mapStateToProps() {
|
||||
return {};
|
||||
}
|
||||
|
||||
function mapDispatchToProps(dispatch) {
|
||||
return {
|
||||
actions: bindActionCreators(actions, dispatch),
|
||||
};
|
||||
}
|
||||
|
||||
export default connect(mapStateToProps, mapDispatchToProps)(SelectArray);
|
||||
@@ -8,22 +8,19 @@ const propTypes = {
|
||||
};
|
||||
|
||||
class SqlClause extends React.Component {
|
||||
changeWhere(whereClause) {
|
||||
this.props.actions.setWhereClause(whereClause);
|
||||
}
|
||||
changeHaving(havingClause) {
|
||||
this.props.actions.setHavingClause(havingClause);
|
||||
onChange(key, event) {
|
||||
this.props.actions.setFormData(key, event.target.value);
|
||||
}
|
||||
render() {
|
||||
return (
|
||||
<div className="panel space-1">
|
||||
<div className="panel">
|
||||
<div className="panel-header">SQL</div>
|
||||
<div className="panel-body">
|
||||
<div className="row">
|
||||
<h5 className="section-heading">Where</h5>
|
||||
<input
|
||||
type="text"
|
||||
onChange={this.changeWhere.bind(this)}
|
||||
onChange={this.onChange.bind(this, 'where')}
|
||||
className="form-control input-sm"
|
||||
placeholder="Where Clause"
|
||||
/>
|
||||
@@ -32,7 +29,7 @@ class SqlClause extends React.Component {
|
||||
<h5 className="section-heading">Having</h5>
|
||||
<input
|
||||
type="text"
|
||||
onChange={this.changeHaving.bind(this)}
|
||||
onChange={this.onChange.bind(this, 'having')}
|
||||
className="form-control input-sm"
|
||||
placeholder="Having Clause"
|
||||
/>
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
import React from 'react';
|
||||
import Select from 'react-select';
|
||||
import { bindActionCreators } from 'redux';
|
||||
import * as actions from '../actions/exploreActions';
|
||||
import { connect } from 'react-redux';
|
||||
import { sinceOptions, untilOptions } from '../constants';
|
||||
import SelectArray from './SelectArray';
|
||||
|
||||
const propTypes = {
|
||||
actions: React.PropTypes.object,
|
||||
datasourceClass: React.PropTypes.string,
|
||||
datasourceType: React.PropTypes.string,
|
||||
timeColumnOpts: React.PropTypes.array,
|
||||
timeColumn: React.PropTypes.string,
|
||||
timeGrainOpts: React.PropTypes.array,
|
||||
@@ -25,92 +25,57 @@ const defaultProps = {
|
||||
until: null,
|
||||
};
|
||||
|
||||
class TimeFilter extends React.Component {
|
||||
changeTimeColumn(timeColumnOpt) {
|
||||
const val = (timeColumnOpt) ? timeColumnOpt.value : null;
|
||||
this.props.actions.setTimeColumn(val);
|
||||
}
|
||||
changeTimeGrain(timeGrainOpt) {
|
||||
const val = (timeGrainOpt) ? timeGrainOpt.value : null;
|
||||
this.props.actions.setTimeGrain(val);
|
||||
}
|
||||
changeSince(sinceOpt) {
|
||||
const val = (sinceOpt) ? sinceOpt.value : null;
|
||||
this.props.actions.setSince(val);
|
||||
}
|
||||
changeUntil(untilOpt) {
|
||||
const val = (untilOpt) ? untilOpt.value : null;
|
||||
this.props.actions.setUntil(val);
|
||||
}
|
||||
render() {
|
||||
const timeColumnPlaceHolder =
|
||||
(this.props.datasourceClass === 'SqlaTable') ? 'Time Column' : 'Time Granularity';
|
||||
const timeGrainPlaceHolder =
|
||||
(this.props.datasourceClass === 'SqlaTable') ? 'Time Grain' : 'Origin';
|
||||
return (
|
||||
<div className="panel space-1">
|
||||
<div className="panel-header">Time Filter</div>
|
||||
<div className="panel-body">
|
||||
<div className="row">
|
||||
<h5 className="section-heading">Time Column & Grains</h5>
|
||||
<Select
|
||||
className="col-sm-6"
|
||||
name="select-time-column"
|
||||
placeholder={`Select a ${timeColumnPlaceHolder}`}
|
||||
options={this.props.timeColumnOpts}
|
||||
value={this.props.timeColumn}
|
||||
autosize={false}
|
||||
onChange={this.changeTimeColumn.bind(this)}
|
||||
/>
|
||||
<Select
|
||||
className="col-sm-6"
|
||||
name="select-time-grain"
|
||||
placeholder={`Select a ${timeGrainPlaceHolder}`}
|
||||
options={this.props.timeGrainOpts}
|
||||
value={this.props.timeGrain}
|
||||
autosize={false}
|
||||
onChange={this.changeTimeGrain.bind(this)}
|
||||
/>
|
||||
</div>
|
||||
<div className="row">
|
||||
<h5 className="section-heading">Since - Until</h5>
|
||||
<Select
|
||||
className="col-sm-6"
|
||||
name="select-since"
|
||||
placeholder="Select Since Time"
|
||||
options={sinceOptions.map((s) => ({ value: s, label: s }))}
|
||||
value={this.props.since}
|
||||
autosize={false}
|
||||
onChange={this.changeSince.bind(this)}
|
||||
/>
|
||||
<Select
|
||||
className="col-sm-6"
|
||||
name="select-until"
|
||||
placeholder="Select Until Time"
|
||||
options={untilOptions.map((u) => ({ value: u, label: u }))}
|
||||
value={this.props.until}
|
||||
autosize={false}
|
||||
onChange={this.changeUntil.bind(this)}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
const TimeFilter = (props) => {
|
||||
const isDatasourceTypeTable = props.datasourceType === 'table';
|
||||
const timeColumnTitle = isDatasourceTypeTable ? 'Time Column' : 'Time Granularity';
|
||||
const timeGrainTitle = isDatasourceTypeTable ? 'Time Grain' : 'Origin';
|
||||
const selects = [
|
||||
{
|
||||
key: 'timeColumn',
|
||||
title: timeColumnTitle,
|
||||
options: props.timeColumnOpts,
|
||||
value: props.timeColumn,
|
||||
},
|
||||
{
|
||||
key: 'timeGrain',
|
||||
title: timeGrainTitle,
|
||||
options: props.timeGrainOpts,
|
||||
value: props.timeGrain,
|
||||
},
|
||||
{
|
||||
key: 'since',
|
||||
title: 'Since',
|
||||
options: sinceOptions.map((s) => ({ value: s, label: s })),
|
||||
value: props.since,
|
||||
},
|
||||
{
|
||||
key: 'until',
|
||||
title: 'Until',
|
||||
options: untilOptions.map((u) => ({ value: u, label: u })),
|
||||
value: props.until,
|
||||
}];
|
||||
return (
|
||||
<div className="panel">
|
||||
<div className="panel-header">Time Filter</div>
|
||||
<div className="panel-body">
|
||||
<SelectArray selectArray={selects} />
|
||||
</div>
|
||||
);
|
||||
}
|
||||
}
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
TimeFilter.propTypes = propTypes;
|
||||
TimeFilter.defaultProps = defaultProps;
|
||||
|
||||
function mapStateToProps(state) {
|
||||
return {
|
||||
datasourceClass: state.datasourceClass,
|
||||
datasourceType: state.datasourceType,
|
||||
timeColumnOpts: state.timeColumnOpts,
|
||||
timeColumn: state.timeColumn,
|
||||
timeColumn: state.viz.formData.timeColumn,
|
||||
timeGrainOpts: state.timeGrainOpts,
|
||||
timeGrain: state.timeGrain,
|
||||
since: state.since,
|
||||
until: state.until,
|
||||
timeGrain: state.viz.formData.timeGrain,
|
||||
since: state.viz.formData.since,
|
||||
until: state.viz.formData.until,
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user