import urlapi from 'url'; import React, { Fragment } from 'react'; import { Link, NavLink } from 'react-router-dom'; import Sidebar from './sidebar'; import Tooltip from './tooltip'; import InfoBox from './info-box'; import { EditIcon } from './icons'; import { parseCategoryURL } from '../parse'; import CONFIG from './fields-config.json'; const BuildingView = (props) => { if (!props.building_id){ return (
Back to maps
); } const cat = parseCategoryURL(props.match.url); return ( { CONFIG.map(section_props => ( { section_props.fields.map(field_props => { switch (field_props.type) { case "uprn_list": return case "text_multi": return case "like": return default: return } }) } )) } ); } const DataSection = (props) => { const match = props.cat === props.slug; return (
match}>

{props.title}

{ match? !props.inactive?
{props.children}
:

{props.intro}

: null }
); } const DataEntry = (props) => (
{ props.title } { props.tooltip? : null }
{ (props.value != null && props.value !== "")? (typeof(props.value) === "boolean")? (props.value)? 'Yes' : 'No' : props.value : '\u00A0'}
); const LikeDataEntry = (props) => (
{ props.title } { props.tooltip? : null }
{ (props.value != null)? (props.value === 1)? `${props.value} person likes this building` : `${props.value} people like this building` : '\u00A0' }
{ (props.user_building_like)?
…including you!
: null }
); const MultiDataEntry = (props) => { let content; if (props.value && props.value.length) { content = } else { content = '\u00A0' } return (
{ props.title } { props.tooltip? : null }
{ content }
); } function sanitise_url(string){ let url_ // http or https if (!(string.substring(0, 7) === 'http://' || string.substring(0, 8) === 'https://')){ return null } try { url_ = document.createElement('a') url_.href = string } catch (error) { try { url_ = urlapi.parse(string) } catch (error) { return null } } // required (www.example.com) if (!url_.hostname || url_.hostname === '' || url_.hostname === 'localhost'){ return null } // optional (/some/path) // url_.pathname; // optional (?name=value) // url_.search; // optional (#anchor) // url_.hash; return `${url_.protocol}//${url_.hostname}${url_.pathname || ''}${url_.search || ''}${url_.hash || ''}` } const UPRNsDataEntry = (props) => { const uprns = props.value || []; const no_parent = uprns.filter(uprn => uprn.parent_uprn == null); const with_parent = uprns.filter(uprn => uprn.parent_uprn != null); return (
{ props.title } { props.tooltip? : null }
) } export default BuildingView;