From ca4750b0beafcca5351c5eb8a4f506f56884de09 Mon Sep 17 00:00:00 2001 From: Maciej Ziarkowski Date: Thu, 17 Oct 2019 13:15:48 +0100 Subject: [PATCH] Process input value inside DataEntry --- .../building/data-components/data-entry.tsx | 27 +++++++++++++++++-- .../data-components/numeric-data-entry.tsx | 11 ++------ .../building/data-containers/location.tsx | 14 +++++----- .../building/data-containers/planning.tsx | 22 +++++++-------- 4 files changed, 45 insertions(+), 29 deletions(-) diff --git a/app/src/frontend/building/data-components/data-entry.tsx b/app/src/frontend/building/data-components/data-entry.tsx index d4c84964..17008f15 100644 --- a/app/src/frontend/building/data-components/data-entry.tsx +++ b/app/src/frontend/building/data-components/data-entry.tsx @@ -3,7 +3,23 @@ import PropTypes from 'prop-types'; import { DataTitleCopyable } from './data-title'; -const DataEntry: React.FunctionComponent = (props) => { // TODO: remove any +interface BaseDataEntryProps { + slug: string; + title: string; + tooltip?: string; + disabled?: boolean; + copy: any; // CopyProps clashes with propTypes + mode: 'view' | 'edit' | 'multi-edit'; + onChange: (key: string, value: any) => void; +} + +interface DataEntryProps extends BaseDataEntryProps { + value: string; + maxLength?: number; + placeholder?: string; +} + +const DataEntry: React.FunctionComponent = (props) => { return ( = (props) => { // TODO: remove any maxLength={props.maxLength} disabled={props.mode === 'view' || props.disabled} placeholder={props.placeholder} - onChange={props.onChange} + onChange={e => + e.target.value === '' ? + null : + props.onChange(props.slug, e.target.value) + } /> ); @@ -43,3 +63,6 @@ DataEntry.propTypes = { } export default DataEntry; +export { + BaseDataEntryProps +}; 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 3c5bdaee..42c756d7 100644 --- a/app/src/frontend/building/data-components/numeric-data-entry.tsx +++ b/app/src/frontend/building/data-components/numeric-data-entry.tsx @@ -2,17 +2,10 @@ import React, { Fragment } from 'react'; import PropTypes from 'prop-types'; import { DataTitleCopyable } from './data-title'; +import { BaseDataEntryProps } from './data-entry'; -interface NumericDataEntryProps { - slug: string; - title: string; - tooltip?: string; - disabled?: boolean; - copy: any; // CopyProps clashes with propTypes - mode: 'view' | 'edit' | 'multi-edit'; - onChange: (key: string, value: any) => void; - +interface NumericDataEntryProps extends BaseDataEntryProps { value?: number; placeholder?: string; step?: number; diff --git a/app/src/frontend/building/data-containers/location.tsx b/app/src/frontend/building/data-containers/location.tsx index 7def0ab9..e9e7a9ea 100644 --- a/app/src/frontend/building/data-containers/location.tsx +++ b/app/src/frontend/building/data-containers/location.tsx @@ -15,7 +15,7 @@ const LocationView = (props) => ( value={props.building.location_name} mode={props.mode} copy={props.copy} - onChange={props.onChange} + onChange={props.onUpdate} tooltip="May not be needed for many buildings." placeholder="Building name (if any)" disabled={true} @@ -35,7 +35,7 @@ const LocationView = (props) => ( value={props.building.location_street} mode={props.mode} copy={props.copy} - onChange={props.onChange} + onChange={props.onUpdate} disabled={true} /> ( value={props.building.location_line_two} mode={props.mode} copy={props.copy} - onChange={props.onChange} + onChange={props.onUpdate} disabled={true} /> ( value={props.building.location_town} mode={props.mode} copy={props.copy} - onChange={props.onChange} + onChange={props.onUpdate} /> ( value={props.building.location_postcode} mode={props.mode} copy={props.copy} - onChange={props.onChange} + onChange={props.onUpdate} maxLength={8} /> ( mode={props.mode} copy={props.copy} tooltip="Ordnance Survey Topography Layer ID (to be filled automatically)" - onChange={props.onChange} + onChange={props.onUpdate} disabled={true} /> ( copy={props.copy} tooltip="OpenStreetMap feature ID" maxLength={20} - onChange={props.onChange} + onChange={props.onUpdate} /> ( value={props.building.planning_portal_link} mode={props.mode} copy={props.copy} - onChange={props.onChange} + onChange={props.onUpdate} /> ( value={props.building.planning_conservation_area_name} mode={props.mode} copy={props.copy} - onChange={props.onChange} + onChange={props.onUpdate} /> ( value={props.building.planning_list_id} mode={props.mode} copy={props.copy} - onChange={props.onChange} + onChange={props.onUpdate} /> ( value={props.building.planning_heritage_at_risk_id} mode={props.mode} copy={props.copy} - onChange={props.onChange} + onChange={props.onUpdate} /> ( value={props.building.planning_world_list_id} mode={props.mode} copy={props.copy} - onChange={props.onChange} + onChange={props.onUpdate} /> ( value={props.building.planning_glher_url} mode={props.mode} copy={props.copy} - onChange={props.onChange} + onChange={props.onUpdate} /> ( value={props.building.planning_apa_name} mode={props.mode} copy={props.copy} - onChange={props.onChange} + onChange={props.onUpdate} /> ( value={props.building.planning_apa_tier} mode={props.mode} copy={props.copy} - onChange={props.onChange} + onChange={props.onUpdate} /> ( value={props.building.planning_local_list_url} mode={props.mode} copy={props.copy} - onChange={props.onChange} + onChange={props.onUpdate} /> ( value={props.building.planning_historic_area_assessment_url} mode={props.mode} copy={props.copy} - onChange={props.onChange} + onChange={props.onUpdate} /> @@ -195,7 +195,7 @@ const PlanningView = (props) => ( value={props.building.planning_demolition_history} mode={props.mode} copy={props.copy} - onChange={props.onChange} + onChange={props.onUpdate} disabled={true} />