mirror of
https://github.com/apache/superset.git
synced 2026-04-18 15:44:57 +00:00
[hotfix] Fix filter for sqlalchemy and druid (#2293)
* [table viz] allow showing time granularity in table (#2284) The time granularity currently does not show up in table viz. Now defining a granularity will add an extra ISO-formatted time column in the table. The column will be added for both grouped by and not grouped by. * Changes based on comments
This commit is contained in:
@@ -4,6 +4,9 @@ import Select from 'react-select';
|
||||
import { Button, Row, Col } from 'react-bootstrap';
|
||||
import SelectControl from './SelectControl';
|
||||
|
||||
const arrayFilterOps = ['in', 'not in'];
|
||||
const strFilterOps = ['==', '!=', '>', '<', '>=', '<=', 'regex'];
|
||||
|
||||
const propTypes = {
|
||||
choices: PropTypes.array,
|
||||
changeFilter: PropTypes.func,
|
||||
@@ -47,6 +50,21 @@ export default class Filter extends React.Component {
|
||||
});
|
||||
}
|
||||
}
|
||||
switchFilterValue(prevFilter, nextOp) {
|
||||
const prevOp = prevFilter.op;
|
||||
let newVal = null;
|
||||
if (arrayFilterOps.indexOf(prevOp) !== -1
|
||||
&& strFilterOps.indexOf(nextOp) !== -1) {
|
||||
// switch from array to string
|
||||
newVal = this.props.filter.val.length > 0 ? this.props.filter.val[0] : '';
|
||||
}
|
||||
if (strFilterOps.indexOf(prevOp) !== -1
|
||||
&& arrayFilterOps.indexOf(nextOp) !== -1) {
|
||||
// switch from string to array
|
||||
newVal = this.props.filter.val === '' ? [] : [this.props.filter.val];
|
||||
}
|
||||
return newVal;
|
||||
}
|
||||
changeFilter(control, event) {
|
||||
let value = event;
|
||||
if (event && event.target) {
|
||||
@@ -55,7 +73,16 @@ export default class Filter extends React.Component {
|
||||
if (event && event.value) {
|
||||
value = event.value;
|
||||
}
|
||||
this.props.changeFilter(control, value);
|
||||
if (control === 'op') {
|
||||
const newVal = this.switchFilterValue(this.props.filter, value);
|
||||
if (newVal) {
|
||||
this.props.changeFilter(['op', 'val'], [value, newVal]);
|
||||
} else {
|
||||
this.props.changeFilter(control, value);
|
||||
}
|
||||
} else {
|
||||
this.props.changeFilter(control, value);
|
||||
}
|
||||
if (control === 'col' && value !== null && this.props.datasource.filter_select) {
|
||||
this.fetchFilterValues(value);
|
||||
}
|
||||
@@ -70,13 +97,13 @@ export default class Filter extends React.Component {
|
||||
this.fetchFilterValues(filter.col);
|
||||
}
|
||||
}
|
||||
if (this.props.having) {
|
||||
// druid having filter
|
||||
if (strFilterOps.indexOf(filter.op) !== -1) {
|
||||
// druid having filter or regex/==/!= filters
|
||||
return (
|
||||
<input
|
||||
type="text"
|
||||
onChange={this.changeFilter.bind(this, 'val')}
|
||||
value={filter.value}
|
||||
value={filter.val}
|
||||
className="form-control input-sm"
|
||||
placeholder="Filter value"
|
||||
/>
|
||||
|
||||
@@ -29,7 +29,13 @@ export default class FilterControl extends React.Component {
|
||||
changeFilter(index, control, value) {
|
||||
const newFilters = Object.assign([], this.props.value);
|
||||
const modifiedFilter = Object.assign({}, newFilters[index]);
|
||||
modifiedFilter[control] = value;
|
||||
if (typeof control === 'string') {
|
||||
modifiedFilter[control] = value;
|
||||
} else {
|
||||
control.forEach((c, i) => {
|
||||
modifiedFilter[c] = value[i];
|
||||
});
|
||||
}
|
||||
newFilters.splice(index, 1, modifiedFilter);
|
||||
this.props.onChange(newFilters);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user