Skip to content

Commit

Permalink
fix(filters): add min value to input instead of 'or' operator (#1462)
Browse files Browse the repository at this point in the history
* add min value to input instead of or operator

* fix: amend logic in other numeric inputs and query builder default value

Co-authored-by: Jose Rego <jose@lightdash.com>
  • Loading branch information
Sync271 and ZeRego committed Feb 28, 2022
1 parent 8f14534 commit fb144a9
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 4 deletions.
4 changes: 2 additions & 2 deletions packages/backend/src/queryBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,9 @@ const renderNumberFilterSql = (
case FilterOperator.NOT_NULL:
return `(${dimensionSql}) IS NOT NULL`;
case FilterOperator.GREATER_THAN:
return `(${dimensionSql}) > ${filter.values?.[0]}`;
return `(${dimensionSql}) > (${filter.values?.[0] || 0})`;
case FilterOperator.LESS_THAN:
return `(${dimensionSql}) < ${filter.values?.[0]}`;
return `(${dimensionSql}) < (${filter.values?.[0] || 0})`;
default:
throw Error(
`No function implemented to render sql for filter type ${filterType} on dimension of number type`,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,11 +109,13 @@ const DateFilterInputs: FC<FilterInputsProps<DateFilterRule>> = (props) => {
/>
);
case FilterOperator.IN_THE_PAST:
const parsedValue = parseInt(filterRule.values?.[0], 10);
return (
<MultipleInputsWrapper>
<NumericInput
fill
value={parseInt(filterRule.values?.[0], 10) || 1}
value={isNaN(parsedValue) ? undefined : parsedValue}
min={0}
onValueChange={(value) =>
onChange({
...filterRule,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,12 @@ const DefaultFilterInputs: FC<FilterInputsProps> = ({
case FilterOperator.LESS_THAN:
case FilterOperator.LESS_THAN_OR_EQUAL:
case FilterOperator.IN_THE_PAST:
const parsedValue = parseInt(filterRule.values?.[0], 10);
return (
<NumericInput
fill
value={filterRule.values?.[0]}
value={isNaN(parsedValue) ? undefined : parsedValue}
min={0}
onValueChange={(value) =>
onChange({
...filterRule,
Expand Down

0 comments on commit fb144a9

Please sign in to comment.