<commit_before>import PropTypes from 'prop-types'
import React from 'react'
import Page, {mapDispatchToProps, propTypes as pagePropTypes} from 'components/Page'
import autobind from 'autobind-decorator'

import Form from 'components/Form'
import Fieldset from 'components/Fieldset'
import Breadcrumbs from 'components/Breadcrumbs'
import Messages, {setMessages} from 'components/Messages'
import Leaflet from 'components/Leaflet'
import LinkTo from 'components/LinkTo'
import ReportCollection from 'components/ReportCollection'

import GQL from 'graphqlapi'
import {Location, Person} from 'models'

import AppContext from 'components/AppContext'
import { connect } from 'react-redux'

class BaseLocationShow extends Page {

	static propTypes = {
		...pagePropTypes,
		currentUser: PropTypes.instanceOf(Person),
	}

	static modelName = 'Location'

	constructor(props) {
		super(props)
		this.state = {
			location: new Location()
		}
		setMessages(props,this.state)
	}

	fetchData(props) {
		let reportsQuery = new GQL.Part(/* GraphQL */`
			reports: reportList(query: $reportsQuery) {
				pageNum, pageSize, totalCount, list {
					${ReportCollection.GQL_REPORT_FIELDS}
				}
			}
		`).addVariable("reportsQuery", "ReportSearchQueryInput", {
			pageSize: 10,
			pageNum: this.state.reportsPageNum,
			locationId: props.match.params.id,
		})

		let locationQuery = new GQL.Part(/* GraphQL */`
			location(id:${props.match.params.id}) {
				id, name, lat, lng
			}
		`)

		return GQL.run([reportsQuery, locationQuery]).then(data => {
            this.setState({
                location: new Location(data.location),
				reports: data.reports,
            })
        })
	}

	render() {
		let {location, reports} = this.state
		const { currentUser } = this.props
		let markers=[]
		let latlng = 'None'
		if (Location.hasCoordinates(location)) {
			latlng = location.lat + ', ' + location.lng
			markers.push({name: location.name, lat: location.lat, lng: location.lng})
		}

		return (
			<div>
				<Breadcrumbs items={[[location.name || 'Location', Location.pathFor(location)]]} />

				<Messages success={this.state.success} error={this.state.error} />

				<Form static formFor={location} horizontal >
					<Fieldset title={location.name} action={currentUser.isSuperUser() && <LinkTo anetLocation={location} edit button="primary">Edit</LinkTo>} >
						<Form.Field id="status" />

						<Form.Field id="latlng" value={latlng} label="Lat/Lon" />
					</Fieldset>

					<Leaflet markers={markers} />
				</Form>

				<Fieldset title="Reports at this location">
					<ReportCollection paginatedReports={reports} goToPage={this.goToReportsPage} />
				</Fieldset>
			</div>
		)
	}

	@autobind
	goToReportsPage(pageNum) {
		this.setState({reportsPageNum: pageNum}, () => this.loadData())
	}
}

const LocationShow = (props) => (
	<AppContext.Consumer>
		{context =>
			<BaseLocationShow currentUser={context.currentUser} {...props} />
		}
	</AppContext.Consumer>
)

export default connect(null, mapDispatchToProps)(LocationShow)
<commit_msg>NCI-Agency/anet#844: Fix display of location status<commit_after>import PropTypes from 'prop-types'
import React from 'react'
import Page, {mapDispatchToProps, propTypes as pagePropTypes} from 'components/Page'
import autobind from 'autobind-decorator'

import Form from 'components/Form'
import Fieldset from 'components/Fieldset'
import Breadcrumbs from 'components/Breadcrumbs'
import Messages, {setMessages} from 'components/Messages'
import Leaflet from 'components/Leaflet'
import LinkTo from 'components/LinkTo'
import ReportCollection from 'components/ReportCollection'

import GQL from 'graphqlapi'
import {Location, Person} from 'models'

import AppContext from 'components/AppContext'
import { connect } from 'react-redux'

class BaseLocationShow extends Page {

	static propTypes = {
		...pagePropTypes,
		currentUser: PropTypes.instanceOf(Person),
	}

	static modelName = 'Location'

	constructor(props) {
		super(props)
		this.state = {
			location: new Location()
		}
		setMessages(props,this.state)
	}

	fetchData(props) {
		let reportsQuery = new GQL.Part(/* GraphQL */`
			reports: reportList(query: $reportsQuery) {
				pageNum, pageSize, totalCount, list {
					${ReportCollection.GQL_REPORT_FIELDS}
				}
			}
		`).addVariable("reportsQuery", "ReportSearchQueryInput", {
			pageSize: 10,
			pageNum: this.state.reportsPageNum,
			locationId: props.match.params.id,
		})

		let locationQuery = new GQL.Part(/* GraphQL */`
			location(id:${props.match.params.id}) {
				id, name, lat, lng, status
			}
		`)

		return GQL.run([reportsQuery, locationQuery]).then(data => {
            this.setState({
                location: new Location(data.location),
				reports: data.reports,
            })
        })
	}

	render() {
		let {location, reports} = this.state
		const { currentUser } = this.props
		let markers=[]
		let latlng = 'None'
		if (Location.hasCoordinates(location)) {
			latlng = location.lat + ', ' + location.lng
			markers.push({name: location.name, lat: location.lat, lng: location.lng})
		}

		return (
			<div>
				<Breadcrumbs items={[[location.name || 'Location', Location.pathFor(location)]]} />

				<Messages success={this.state.success} error={this.state.error} />

				<Form static formFor={location} horizontal >
					<Fieldset title={location.name} action={currentUser.isSuperUser() && <LinkTo anetLocation={location} edit button="primary">Edit</LinkTo>} >
						<Form.Field id="status" />

						<Form.Field id="latlng" value={latlng} label="Lat/Lon" />
					</Fieldset>

					<Leaflet markers={markers} />
				</Form>

				<Fieldset title="Reports at this location">
					<ReportCollection paginatedReports={reports} goToPage={this.goToReportsPage} />
				</Fieldset>
			</div>
		)
	}

	@autobind
	goToReportsPage(pageNum) {
		this.setState({reportsPageNum: pageNum}, () => this.loadData())
	}
}

const LocationShow = (props) => (
	<AppContext.Consumer>
		{context =>
			<BaseLocationShow currentUser={context.currentUser} {...props} />
		}
	</AppContext.Consumer>
)

export default connect(null, mapDispatchToProps)(LocationShow)

{'fraction_non_alphanumeric': 0.1362446843310435, 'fraction_numerical': 0.001144913313706248, 'mean_word_length': 4.041220115416323, 'pattern_counts': {'":': 0, '<': 41, '<?xml version=': 0, '>': 49, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '503508', 'n_tokens_mistral': 2208, 'n_tokens_neox': 1944, 'n_words': 422}