colouring-montreal/app/src/frontend/building/data-components/planning-data-entry.tsx

85 lines
3.1 KiB
TypeScript
Raw Normal View History

2022-10-05 13:52:14 -04:00
import React, { Fragment } from 'react';
import InfoBox from '../../components/info-box';
import CheckboxDataEntry from '../data-components/checkbox-data-entry';
interface PlanningDataOfficialDataEntryProps {
value: any; // TODO: proper structuring!
}
const {useState} = React;
const LongText = ({ content,limit}) => {
const [showAll, setShowAll] = useState(false);
const showMore = () => setShowAll(true);
const showLess = () => setShowAll(false);
2022-10-31 03:49:13 -04:00
if (content == null) {
return <div>{MissingData}</div>
}
2022-10-05 13:52:14 -04:00
if (content.length <= limit) {
return <div>{content}</div>
}
if (showAll) {
return <div>
{content}
2022-08-29 07:28:06 -04:00
<br/>
<b onClick={showLess}>Shorten description</b>
2022-10-05 13:52:14 -04:00
</div>
}
const toShow = content.substring(0, limit).trim() + "... ";
return <div>
{toShow}
2022-08-29 07:28:06 -04:00
<br/>
<b onClick={showMore}>Show full description</b>
2022-10-05 13:52:14 -04:00
</div>
}
const Disclaimer = () => { return <Fragment><div><i><u>Disclaimer</u>: these data are currently incomplete and also often do not provide information on minor alterations. For comprehensive information on all applications please visit the local authorities' planning websites.</i></div></Fragment> }
2022-08-30 06:25:20 -04:00
2022-10-31 03:49:13 -04:00
const MissingData = "not available"
function ShowIfAvailable(data) {
return <>{data ? data.toString() : MissingData }</>
}
2022-10-05 13:52:14 -04:00
const PlanningDataOfficialDataEntry: React.FC<PlanningDataOfficialDataEntryProps> = (props) => {
const data = props.value || [];
if(data.length == 0) {
return (<Fragment>
2022-09-14 06:57:47 -04:00
<InfoBox type='success'>
2022-08-30 06:25:20 -04:00
<i>No live planning data available currently for this building polygon via the Planning London DataHub.</i>
<br/>
2022-08-30 06:25:20 -04:00
<Disclaimer />
2022-10-05 13:52:14 -04:00
</InfoBox>
</Fragment>);
}
2022-10-31 05:20:41 -04:00
return (data.map((item) => (
2022-10-05 13:52:14 -04:00
<Fragment>
<InfoBox type='success'>
2022-09-14 06:57:47 -04:00
<Fragment>
2022-10-31 05:20:41 -04:00
<div><i>Planning application status is streamed using live data uploaded by local authorities to the <a href={item["data_source_link"]}>{item["data_source"]}</a>.</i></div>
2022-09-15 07:14:35 -04:00
<br/>
2022-10-31 05:20:41 -04:00
<div><b>Current planning application status for this site:</b> {ShowIfAvailable(item["status"])}</div>
<div><b>Planning application ID:</b> {ShowIfAvailable(item["planning_application_id"])}</div>
<div><b>Date registered by the planning authority (validation date)</b>: {ShowIfAvailable(item["registered_with_local_authority_date"])}</div>
<div><b>Decision date</b>: {ShowIfAvailable(item["decision_date"])}</div>
<div><b>Planning application link</b>: {ShowIfAvailable(item["planning_application_link"])}</div>
<div><b>Description of proposed work</b>: {item["description"] ? <LongText content = {item["description"]} limit = {400}/> : MissingData}</div>
<div><b>Most recent update by data provider:</b> {ShowIfAvailable(item["decision_date"])}</div>
<br/>
2022-08-30 06:25:20 -04:00
<Disclaimer />
2022-09-15 07:34:09 -04:00
</Fragment>
</InfoBox>
2022-10-05 13:52:14 -04:00
</Fragment>
2022-10-31 05:20:41 -04:00
)
)
)
2022-10-05 13:52:14 -04:00
};
export default PlanningDataOfficialDataEntry;