Skip to content

Commit

Permalink
Changes based on comments
Browse files Browse the repository at this point in the history
  • Loading branch information
vera-liu committed Feb 28, 2017
1 parent e42ae92 commit b17fa85
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,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) {
Expand All @@ -59,15 +74,15 @@ export default class Filter extends React.Component {
value = event.value;
}
if (control === 'op') {
if (arrayFilterOps.indexOf(this.props.filter.op) !== -1
&& strFilterOps.indexOf(value) !== -1) {
this.props.changeFilter('val', this.props.filter.val[0]);
} else if (strFilterOps.indexOf(this.props.filter.op) !== -1
&& arrayFilterOps.indexOf(value) !== -1) {
this.props.changeFilter('val', [this.props.filter.val]);
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);
}
this.props.changeFilter(control, value);
if (control === 'col' && value !== null && this.props.datasource.filter_select) {
this.fetchFilterValues(value);
}
Expand All @@ -82,7 +97,7 @@ export default class Filter extends React.Component {
this.fetchFilterValues(filter.col);
}
}
if (this.props.having || strFilterOps.indexOf(filter.op) !== -1) {
if (strFilterOps.indexOf(filter.op) !== -1) {
// druid having filter or regex/==/!= filters
return (
<input
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down

0 comments on commit b17fa85

Please sign in to comment.