Calculate total floors

#1192
This commit is contained in:
Mike Simpson 2023-06-29 11:09:12 +01:00
parent 1708d6e5f0
commit ff8618beb8

View File

@ -15,7 +15,22 @@ import { MultiDataEntry } from '../data-components/multi-data-entry/multi-data-e
/**
* Size view/edit section
*/
const SizeView: React.FunctionComponent<CategoryViewProps> = (props) => (
const SizeView: React.FunctionComponent<CategoryViewProps> = (props) => {
// Calculate the total number of floors
let total_floors = 0;
if (props.building.size_storeys_attic != null) {
total_floors += props.building.size_storeys_attic;
}
if (props.building.size_storeys_core != null) {
total_floors += props.building.size_storeys_core;
}
if (props.building.size_storeys_basement != null) {
total_floors += props.building.size_storeys_basement;
}
return (
<Fragment>
<DataEntryGroup name="Number of floors/storeys">
<NumericDataEntry
@ -75,6 +90,18 @@ const SizeView: React.FunctionComponent<CategoryViewProps> = (props) => (
user_verified_as={props.user_verified.size_storeys_basement}
verified_count={props.building.verified.size_storeys_basement}
/>
<NumericDataEntry
title="Total number of floors"
slug="size_total_floors"
value={total_floors}
mode={props.mode}
copy={props.copy}
tooltip="Total number of floors, calculated from other values."
onChange={props.onChange}
step={1}
min={0}
disabled={true}
/>
<SelectDataEntry
title={dataFields.size_storeys_source_type.title}
slug="size_storeys_source_type"
@ -449,7 +476,8 @@ const SizeView: React.FunctionComponent<CategoryViewProps> = (props) => (
}
</DataEntryGroup>
</Fragment>
);
)
};
const SizeContainer = withCopyEdit(SizeView);
export default SizeContainer;