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

[filter_box] option to delay filtering with apply button #2338

Merged
merged 2 commits into from
Mar 6, 2017
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
Original file line number Diff line number Diff line change
Expand Up @@ -101,10 +101,9 @@ class ChartContainer extends React.PureComponent {

height: getHeight,

setFilter: () => {
// set filter according to data in store
// used in FilterBox.onChange()
},
setFilter: () => {},

addFilter: () => {},

getFilters: () => (
// return filter objects from viz.formData
Expand Down
11 changes: 11 additions & 0 deletions superset/assets/javascripts/explorev2/stores/controls.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -840,6 +840,17 @@ export const controls = {
description: 'Font size for the biggest value in the list',
},

instant_filtering: {
type: 'CheckboxControl',
label: 'Instant Filtering',
renderTrigger: true,
default: true,
description: (
'Whether to apply filters as they change, or wait for' +
'users to hit an [Apply] button'
),
},

show_brush: {
type: 'CheckboxControl',
label: 'Range Filter',
Expand Down
2 changes: 1 addition & 1 deletion superset/assets/javascripts/explorev2/stores/visTypes.js
Original file line number Diff line number Diff line change
Expand Up @@ -607,7 +607,7 @@ const visTypes = {
{
label: null,
controlSetRows: [
['date_filter'],
['date_filter', 'instant_filtering'],
['groupby'],
['metric'],
],
Expand Down
8 changes: 4 additions & 4 deletions superset/assets/javascripts/modules/superset.js
Original file line number Diff line number Diff line change
Expand Up @@ -244,11 +244,11 @@ const px = function () {
resize() {
this.render();
},
addFilter(col, vals) {
controller.addFilter(sliceId, col, vals);
addFilter(col, vals, merge = true, refresh = true) {
controller.addFilter(sliceId, col, vals, merge, refresh);
},
setFilter(col, vals) {
controller.setFilter(sliceId, col, vals);
setFilter(col, vals, refresh = true) {
controller.setFilter(sliceId, col, vals, refresh);
},
getFilters() {
return controller.filters[sliceId];
Expand Down
25 changes: 22 additions & 3 deletions superset/assets/visualizations/filter_box.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,14 @@ import ReactDOM from 'react-dom';

import Select from 'react-select';
import '../stylesheets/react-select/select.less';
import { Button } from 'react-bootstrap';

import './filter_box.css';
import { TIME_CHOICES } from './constants.js';

const propTypes = {
origSelectedValues: React.PropTypes.object,
instantFiltering: React.PropTypes.bool,
filtersChoices: React.PropTypes.object,
onChange: React.PropTypes.func,
showDateFilter: React.PropTypes.bool,
Expand All @@ -21,15 +23,21 @@ const defaultProps = {
origSelectedValues: {},
onChange: () => {},
showDateFilter: false,
instantFiltering: true,
};

class FilterBox extends React.Component {
constructor(props) {
super(props);
this.state = {
selectedValues: props.origSelectedValues,
hasChanged: false,
};
}
clickApply() {
this.props.onChange(Object.keys(this.state.selectedValues)[0], [], true, true);
this.setState({ hasChanged: false });
}
changeFilter(filter, options) {
let vals = null;
if (options) {
Expand All @@ -41,8 +49,8 @@ class FilterBox extends React.Component {
}
const selectedValues = Object.assign({}, this.state.selectedValues);
selectedValues[filter] = vals;
this.setState({ selectedValues });
this.props.onChange(filter, vals);
this.setState({ selectedValues, hasChanged: true });
this.props.onChange(filter, vals, false, !this.props.instantFiltering);
}
render() {
let dateFilter;
Expand Down Expand Up @@ -101,6 +109,16 @@ class FilterBox extends React.Component {
<div>
{dateFilter}
{filters}
{this.props.instantFiltering &&
<Button
bsSize="small"
bsStyle="primary"
onClick={this.clickApply.bind(this)}
disabled={!this.state.hasChanged}
>
Apply
</Button>
}
</div>
);
}
Expand All @@ -124,9 +142,10 @@ function filterBox(slice, payload) {
ReactDOM.render(
<FilterBox
filtersChoices={filtersChoices}
onChange={slice.setFilter}
onChange={slice.addFilter}
showDateFilter={fd.date_filter}
origSelectedValues={slice.getFilters() || {}}
instantFiltering={fd.instant_filtering}
/>,
document.getElementById(slice.containerId)
);
Expand Down