From 05349d8ffe9c298c190afb7790d6fa354ffcdf25 Mon Sep 17 00:00:00 2001 From: Lukas Martinelli Date: Sun, 15 Jan 2017 13:39:40 +0100 Subject: [PATCH] Convert filter value to number if possible #63 --- src/components/filter/SingleFilterEditor.jsx | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/components/filter/SingleFilterEditor.jsx b/src/components/filter/SingleFilterEditor.jsx index 0cadda9..8902625 100644 --- a/src/components/filter/SingleFilterEditor.jsx +++ b/src/components/filter/SingleFilterEditor.jsx @@ -5,6 +5,12 @@ import StringInput from '../inputs/StringInput' import AutocompleteInput from '../inputs/AutocompleteInput' import SelectInput from '../inputs/SelectInput' +function tryParseInt(v) { + if (v === '') return v + if (isNaN(v)) return v + return parseFloat(v) +} + class SingleFilterEditor extends React.Component { static propTypes = { filter: React.PropTypes.array.isRequired, @@ -17,8 +23,7 @@ class SingleFilterEditor extends React.Component { } onFilterPartChanged(filterOp, propertyName, filterArgs) { - let newFilter = [filterOp, propertyName, ...filterArgs] - console.log('filter changed', filterOp, propertyName, filterArgs) + let newFilter = [filterOp, propertyName, ...filterArgs.map(tryParseInt)] if(filterOp === 'has' || filterOp === '!has') { newFilter = [filterOp, propertyName] } else if(filterArgs.length === 0) {