From 866e103a807361cfad08052534055c55453ffbcc Mon Sep 17 00:00:00 2001 From: Maciej Ziarkowski Date: Fri, 22 Nov 2019 16:03:36 +0000 Subject: [PATCH 1/2] Handle nullish, not falsey values in numeric input --- .../building/data-components/numeric-data-entry.tsx | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/src/frontend/building/data-components/numeric-data-entry.tsx b/app/src/frontend/building/data-components/numeric-data-entry.tsx index 3c1a21fe..1e9342da 100644 --- a/app/src/frontend/building/data-components/numeric-data-entry.tsx +++ b/app/src/frontend/building/data-components/numeric-data-entry.tsx @@ -27,10 +27,10 @@ const NumericDataEntry: React.FunctionComponent = (props) type="number" id={props.slug} name={props.slug} - value={props.value || ''} - step={props.step || 1} + value={props.value == undefined ? '' : props.value} + step={props.step == undefined ? 1 : props.step} max={props.max} - min={props.min || 0} + min={props.min} disabled={props.mode === 'view' || props.disabled} placeholder={props.placeholder} onChange={e => From 06dfae011362c87cf091945e43972436ab98bffd Mon Sep 17 00:00:00 2001 From: Maciej Ziarkowski Date: Thu, 28 Nov 2019 12:22:10 +0000 Subject: [PATCH 2/2] Set bounds for numbers, increase lat/lon precision --- .../data-components/year-data-entry.tsx | 8 ++ .../frontend/building/data-containers/age.tsx | 132 +++++++++--------- .../building/data-containers/location.tsx | 13 +- .../building/data-containers/size.tsx | 10 ++ 4 files changed, 96 insertions(+), 67 deletions(-) diff --git a/app/src/frontend/building/data-components/year-data-entry.tsx b/app/src/frontend/building/data-components/year-data-entry.tsx index 1d35f8ee..3a9c2996 100644 --- a/app/src/frontend/building/data-components/year-data-entry.tsx +++ b/app/src/frontend/building/data-components/year-data-entry.tsx @@ -30,6 +30,8 @@ class YearDataEntry extends Component { // TODO handle changes internally, reporting out date_year, date_upper, date_lower render() { const props = this.props; + + const currentYear = new Date().getFullYear(); return ( { mode={props.mode} copy={props.copy} onChange={props.onChange} + min={1} + max={currentYear} // "type": "year_estimator" /> { copy={props.copy} onChange={props.onChange} step={1} + min={1} + max={currentYear} tooltip={dataFields.date_upper.tooltip} /> { copy={props.copy} onChange={props.onChange} step={1} + min={1} + max={currentYear} tooltip={dataFields.date_lower.tooltip} /> diff --git a/app/src/frontend/building/data-containers/age.tsx b/app/src/frontend/building/data-containers/age.tsx index 1f1728b6..0e886d16 100644 --- a/app/src/frontend/building/data-containers/age.tsx +++ b/app/src/frontend/building/data-containers/age.tsx @@ -13,69 +13,75 @@ import { CategoryViewProps } from './category-view-props'; /** * Age view/edit section */ -const AgeView: React.FunctionComponent = (props) => ( - - - - - - - -); +const AgeView: React.FunctionComponent = (props) => { + const currentYear = new Date().getFullYear(); + + return ( + + + + + + + + ); +}; const AgeContainer = withCopyEdit(AgeView); export default AgeContainer; diff --git a/app/src/frontend/building/data-containers/location.tsx b/app/src/frontend/building/data-containers/location.tsx index 5e437b1f..8d82445e 100644 --- a/app/src/frontend/building/data-containers/location.tsx +++ b/app/src/frontend/building/data-containers/location.tsx @@ -31,6 +31,7 @@ const LocationView: React.FunctionComponent = (props) => ( copy={props.copy} onChange={props.onChange} step={1} + min={1} /> = (props) => ( value={props.building.location_latitude} mode={props.mode} copy={props.copy} - step={0.0001} - placeholder="51" + step={0.00001} + min={-90} + max={90} + placeholder="Latitude, e.g. 51.5467" onChange={props.onChange} /> = (props) => ( value={props.building.location_longitude} mode={props.mode} copy={props.copy} - step={0.0001} - placeholder="0" + step={0.00001} + min={-180} + max={180} + placeholder="Longitude, e.g. -0.0586" onChange={props.onChange} /> diff --git a/app/src/frontend/building/data-containers/size.tsx b/app/src/frontend/building/data-containers/size.tsx index 7ae4c2cf..114d2c5d 100644 --- a/app/src/frontend/building/data-containers/size.tsx +++ b/app/src/frontend/building/data-containers/size.tsx @@ -24,6 +24,7 @@ const SizeView: React.FunctionComponent = (props) => ( tooltip={dataFields.size_storeys_core.tooltip} onChange={props.onChange} step={1} + min={0} /> = (props) => ( tooltip={dataFields.size_storeys_attic.tooltip} onChange={props.onChange} step={1} + min={0} /> = (props) => ( tooltip={dataFields.size_storeys_basement.tooltip} onChange={props.onChange} step={1} + min={0} /> @@ -55,6 +58,7 @@ const SizeView: React.FunctionComponent = (props) => ( copy={props.copy} onChange={props.onChange} step={0.1} + min={0} /> = (props) => ( copy={props.copy} onChange={props.onChange} step={0.1} + min={0} /> @@ -76,6 +81,7 @@ const SizeView: React.FunctionComponent = (props) => ( copy={props.copy} onChange={props.onChange} step={0.1} + min={0} /> = (props) => ( copy={props.copy} onChange={props.onChange} step={0.1} + min={0} /> = (props) => ( copy={props.copy} onChange={props.onChange} step={0.1} + min={0} /> = (props) => ( copy={props.copy} onChange={props.onChange} step={0.1} + min={0} disabled={true} /> = (props) => ( copy={props.copy} onChange={props.onChange} step={0.1} + min={0} disabled={true} />