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

97 lines
3.6 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: {
uprn: string;
building_id: number;
description?: string;
planning_application_link?: string;
registered_with_local_authority_date?: string;
decision_date?: string;
last_synced_date?: string;
data_source: string;
data_source_link?: string;
}[];
2022-10-05 13:52:14 -04:00
}
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 07:34:19 -04:00
const MissingData = "not provided by data source"
2022-10-31 03:49:13 -04:00
function ShowIfAvailable(data) {
return <>{data ? data.toString() : MissingData }</>
}
2022-10-31 05:32:37 -04:00
const LinkIfAvailable = (link) => {
return <>{link ? <a href={link.toString()}>{link.toString()}</a> : 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>);
}
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>
<div><i>Planning application status is streamed using live data uploaded by local authorities to the {item["data_source_link"] ? <a href={item["data_source_link"]}>{item["data_source"]}</a> : item["data_source"] }.</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>
2022-10-31 05:32:37 -04:00
<div><b>Planning application link</b>: {LinkIfAvailable(item["planning_application_link"])}</div>
2022-10-31 05:20:41 -04:00
<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;