Add patern data entry to location number

This commit is contained in:
Maciej Ziarkowski 2021-06-16 21:35:09 +01:00
parent 8ea5c077c0
commit b6ecbb61c2
3 changed files with 51 additions and 4 deletions

View File

@ -0,0 +1,43 @@
import React, { Fragment } from 'react';
import { BaseDataEntryProps } from './data-entry';
import { DataTitleCopyable } from './data-title';
interface PatternDataEntryProps extends BaseDataEntryProps {
value?: string;
placeholder?: string;
/**
* This is not a JS RegExp, so there's no validation in code, because we're passing it to HTML input as a string
*/
pattern: string;
maxLength?: number;
}
export const PatternDataEntry: React.FC<PatternDataEntryProps> = props => {
const handleChange = (value: string) => {
props.onChange?.(props.slug, value);
};
return (
<>
<DataTitleCopyable
slug={props.slug}
slugModifier={props.slugModifier}
title={props.title}
tooltip={props.tooltip}
disabled={props.disabled || props.value == undefined || props.value == ''}
copy={props.copy}
/>
<input className="form-control" type={props.isUrl? "url" : "text"}
value={props.value || ''}
required={props.required}
disabled={props.mode === 'view' || props.disabled}
placeholder={props.placeholder}
pattern={props.pattern}
maxLength={props.maxLength}
onChange={e => handleChange(e.target.value)}
/>
</>
);
}

View File

@ -7,9 +7,12 @@ import NumericDataEntry from '../data-components/numeric-data-entry';
import UPRNsDataEntry from '../data-components/uprns-data-entry'; import UPRNsDataEntry from '../data-components/uprns-data-entry';
import Verification from '../data-components/verification'; import Verification from '../data-components/verification';
import withCopyEdit from '../data-container'; import withCopyEdit from '../data-container';
import { PatternDataEntry } from '../data-components/pattern-data-entry';
import { CategoryViewProps } from './category-view-props'; import { CategoryViewProps } from './category-view-props';
const locationNumberPattern = "[1-9]\\d*[a-z]?(-([1-9]\\d*))?"; ///[1-9]\d*[a-z]?(-([1-9]\d*))?/;
const LocationView: React.FunctionComponent<CategoryViewProps> = (props) => ( const LocationView: React.FunctionComponent<CategoryViewProps> = (props) => (
<Fragment> <Fragment>
<InfoBox msg="Text-based address fields are disabled at the moment. We're looking into how best to collect this data." /> <InfoBox msg="Text-based address fields are disabled at the moment. We're looking into how best to collect this data." />
@ -33,15 +36,15 @@ const LocationView: React.FunctionComponent<CategoryViewProps> = (props) => (
verified_count={props.building.verified.location_name} verified_count={props.building.verified.location_name}
/> />
<NumericDataEntry <PatternDataEntry
title={dataFields.location_number.title} title={dataFields.location_number.title}
slug="location_number" slug="location_number"
value={props.building.location_number} value={props.building.location_number}
pattern={locationNumberPattern}
mode={props.mode} mode={props.mode}
copy={props.copy} copy={props.copy}
onChange={props.onChange} onChange={props.onChange}
step={1} tooltip={dataFields.location_number.tooltip}
min={1}
/> />
<Verification <Verification
slug="location_number" slug="location_number"

View File

@ -57,7 +57,8 @@ export const dataFields = { /* eslint-disable @typescript-eslint/camelcase */
location_number: { location_number: {
category: Category.Location, category: Category.Location,
title: "Building number", title: "Building number",
example: 12, example: '12b',
tooltip: 'Numbers with an optional lowercase letter are accepted, e.g. 141 or 12b'
}, },
location_street: { location_street: {
category: Category.Location, category: Category.Location,