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

Added controls for Table Viz #1253

Merged
merged 4 commits into from
Oct 5, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
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
49 changes: 30 additions & 19 deletions caravel/assets/javascripts/explorev2/actions/exploreActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ export const SET_GROUPBY_COLUMNS = 'SET_GROUPBY_COLUMNS';
export const SET_GROUPBY_COLUMN_OPTS = 'SET_GROUPBY_COLUMN_OPTS';
export const SET_METRICS = 'SET_METRICS';
export const SET_METRICS_OPTS = 'SET_METRICS_OPTS';
export const ADD_COLUMN = 'ADD_COLUMN';
export const REMOVE_COLUMN = 'REMOVE_COLUMN';
export const ADD_ORDERING = 'ADD_ORDERING';
export const REMOVE_ORDERING = 'REMOVE_ORDERING';
export const SET_TIME_STAMP = 'SET_TIME_STAMP';
export const SET_COLUMN_OPTS = 'SET_COLUMN_OPTS';
export const SET_NOT_GROUPBY_COLUMNS = 'SET_NOT_GROUPBY_COLUMNS';
export const SET_ORDERING_OPTS = 'SET_ORDERING_OPTS';
export const SET_ORDERINGS = 'SET_ORDERINGS';
export const SET_TIME_STAMP_FORMAT = 'SET_TIME_STAMP_FORMAT';
export const SET_ROW_LIMIT = 'SET_ROW_LIMIT';
export const TOGGLE_SEARCHBOX = 'TOGGLE_SEARCHBOX';
export const SET_FILTER_COLUMN_OPTS = 'SET_FILTER_COLUMN_OPTS';
Expand Down Expand Up @@ -47,6 +47,14 @@ export function setMetricsOpts(metricsOpts) {
return { type: SET_METRICS_OPTS, metricsOpts };
}

export function setColumnOpts(columnOpts) {
return { type: SET_COLUMN_OPTS, columnOpts };
}

export function setOrderingOpts(orderingOpts) {
return { type: SET_ORDERING_OPTS, orderingOpts };
}

export function setFilterColumnOpts(filterColumnOpts) {
return { type: SET_FILTER_COLUMN_OPTS, filterColumnOpts };
}
Expand All @@ -71,6 +79,8 @@ export function setFormOpts(datasourceId, datasourceType) {
const metricsOpts = [];
const filterColumnOpts = [];
const timeGrainOpts = [];
const columnOpts = [];
const orderingOpts = [];

if (datasourceId) {
const params = [`datasource_id=${datasourceId}`, `datasource_type=${datasourceType}`];
Expand All @@ -93,12 +103,21 @@ export function setFormOpts(datasourceId, datasourceType) {
data.time_grains.forEach((d) => {
if (d) timeGrainOpts.push({ value: d, label: d });
});
data.columns.forEach((d) => {
if (d) columnOpts.push({ value: d, label: d });
});
data.ordering_cols.forEach((d) => {
if (d) orderingOpts.push({ value: d, label: d });
});

// Repopulate options for controls
dispatch(setTimeColumnOpts(timeColumnOpts));
dispatch(setTimeGrainOpts(timeGrainOpts));
dispatch(setGroupByColumnOpts(groupByColumnOpts));
dispatch(setMetricsOpts(metricsOpts));
dispatch(setFilterColumnOpts(filterColumnOpts));
dispatch(setColumnOpts(columnOpts));
dispatch(setOrderingOpts(orderingOpts));
}
});
} else {
Expand Down Expand Up @@ -140,24 +159,16 @@ export function setMetrics(metrics) {
return { type: SET_METRICS, metrics };
}

export function addColumn(column) {
return { type: ADD_COLUMN, column };
}

export function removeColumn(column) {
return { type: REMOVE_COLUMN, column };
}

export function addOrdering(ordering) {
return { type: ADD_ORDERING, ordering };
export function setNotGroupByColumns(columns) {
return { type: SET_NOT_GROUPBY_COLUMNS, columns };
}

export function removeOrdering(ordering) {
return { type: REMOVE_ORDERING, ordering };
export function setOrderings(orderings) {
return { type: SET_ORDERINGS, orderings };
}

export function setTimeStamp(timeStampFormat) {
return { type: SET_TIME_STAMP, timeStampFormat };
export function setTimeStampFormat(timeStampFormat) {
return { type: SET_TIME_STAMP_FORMAT, timeStampFormat };
}

export function setRowLimit(rowLimit) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,36 @@
import React from 'react';
import { connect } from 'react-redux';
import { Panel } from 'react-bootstrap';
import TimeFilter from './TimeFilter';
import ChartControl from './ChartControl';
import GroupBy from './GroupBy';
import SqlClause from './SqlClause';
import Filters from './Filters';
import { DefaultControls, VIZ_CONTROL_MAPPING } from '../constants';

const ControlPanelsContainer = function () {
const propTypes = {
vizType: React.PropTypes.string,
};

const defaultProps = {
vizType: null,
};

function ControlPanelsContainer(props) {
return (
<Panel>
<ChartControl />
<TimeFilter />
<GroupBy />
<SqlClause />
<Filters />
{DefaultControls}
{VIZ_CONTROL_MAPPING[props.vizType]}
</Panel>
);
};
export default ControlPanelsContainer;
}

ControlPanelsContainer.propTypes = propTypes;
ControlPanelsContainer.defaultProps = defaultProps;

function mapStateToProps(state) {
return {
vizType: state.vizType,
};
}

function mapDispatchToProps() {
return {};
}

export default connect(mapStateToProps, mapDispatchToProps)(ControlPanelsContainer);
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,6 @@ class Filters extends React.Component {
}

Filters.propTypes = propTypes;

Filters.defaultProps = defaultProps;

function mapStateToProps(state) {
Expand Down
8 changes: 4 additions & 4 deletions caravel/assets/javascripts/explorev2/components/GroupBy.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ const defaultProps = {
};

class GroupBy extends React.Component {
changeColumns(groupByColumnOpts) {
this.props.actions.setGroupByColumns(groupByColumnOpts);
changeColumns(groupByColumns) {
this.props.actions.setGroupByColumns(groupByColumns);
}
changeMetrics(metricsOpts) {
this.props.actions.setMetrics(metricsOpts);
changeMetrics(metrics) {
this.props.actions.setMetrics(metrics);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Change the variable names here to avoid confusion: Opts variables are for dropdown menu values, non-Opts values are for selected ones.

}
render() {
return (
Expand Down
82 changes: 82 additions & 0 deletions caravel/assets/javascripts/explorev2/components/NotGroupBy.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
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,
columnOpts: React.PropTypes.array,
columns: React.PropTypes.array,
orderingOpts: React.PropTypes.array,
orderings: React.PropTypes.array,
};

const defaultProps = {
columnOpts: [],
columns: [],
orderingOpts: [],
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>
</div>
);
}
}

NotGroupBy.propTypes = propTypes;
NotGroupBy.defaultProps = defaultProps;

function mapStateToProps(state) {
return {
columnOpts: state.columnOpts,
columns: state.columns,
orderingOpts: state.orderingOpts,
orderings: state.orderings,
};
}

function mapDispatchToProps(dispatch) {
return {
actions: bindActionCreators(actions, dispatch),
};
}

export default connect(mapStateToProps, mapDispatchToProps)(NotGroupBy);
76 changes: 76 additions & 0 deletions caravel/assets/javascripts/explorev2/components/Options.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
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 { timestampOptions, rowLimitOptions } from '../constants';

const propTypes = {
actions: React.PropTypes.object,
timeStampFormat: React.PropTypes.string,
rowLimit: React.PropTypes.number,
};

const defaultProps = {
timeStampFormat: null,
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>
</div>
);
}
}

Options.propTypes = propTypes;
Options.defaultProps = defaultProps;

function mapStateToProps(state) {
return {
timeStampFormat: state.timeStampFormat,
rowLimit: state.rowLimit,
};
}

function mapDispatchToProps(dispatch) {
return {
actions: bindActionCreators(actions, dispatch),
};
}

export default connect(mapStateToProps, mapDispatchToProps)(Options);
41 changes: 41 additions & 0 deletions caravel/assets/javascripts/explorev2/constants.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
import React from 'react';
import TimeFilter from './components/TimeFilter';
import ChartControl from './components/ChartControl';
import GroupBy from './components/GroupBy';
import SqlClause from './components/SqlClause';
import Filters from './components/Filters';
import NotGroupBy from './components/NotGroupBy';
import Options from './components/Options';

export const VIZ_TYPES = [
{ value: 'dist_bar', label: 'Distribution - Bar Chart', requiresTime: false },
{ value: 'pie', label: 'Pie Chart', requiresTime: false },
Expand Down Expand Up @@ -33,3 +42,35 @@ export const sinceOptions = ['1 hour ago', '12 hours ago', '1 day ago',
'7 days ago', '28 days ago', '90 days ago', '1 year ago'];
export const untilOptions = ['now', '1 day ago', '7 days ago',
'28 days ago', '90 days ago', '1 year ago'];

export const timestampOptions = [
['smart_date', 'Adaptative formating'],
['%m/%d/%Y', '"%m/%d/%Y" | 01/14/2019'],
['%Y-%m-%d', '"%Y-%m-%d" | 2019-01-14'],
['%Y-%m-%d %H:%M:%S',
'"%Y-%m-%d %H:%M:%S" | 2019-01-14 01:32:10'],
['%H:%M:%S', '"%H:%M:%S" | 01:32:10'],
];

export const rowLimitOptions = [10, 50, 100, 250, 500, 1000, 5000, 10000, 50000];

export const DefaultControls = (
<div>
<ChartControl />
<TimeFilter />
<GroupBy />
<SqlClause />
<Filters />
</div>
);

export const TableVizControls = (
<div>
<NotGroupBy />
<Options />
</div>
);

export const VIZ_CONTROL_MAPPING = {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The viz-control panel mapping is stored here

table: TableVizControls,
};
Loading