Commit bf8eb3bb authored by alain's avatar alain 🐙
Browse files

stationInfo handle loading errors

parent ffef7742
......@@ -55,36 +55,45 @@ class StationInfo extends React.Component {
const source = parameter.sources.find(s => s.name === station.source)
const daysToFetch = source.daysToFetch
const dataFunction = source.detail
const start = getDaysAgoHourISO(daysToFetch)
const end = getNowISO()
const granularity = this.state.granularity
dataFunction(station, parameter.id, start, end, granularity).then(({stationMeta, data})=> {
const unit = (parameter.units ? parameter.units.find(x => x.id === this.props.unitStatus[parameter.id]) : null)
if(unit.conversion) {
data = data.map(d => {
d.value = unit.conversion(d.value)
if(d.minmax) {
d.minmax[0] = unit.conversion(d.minmax[0])
d.minmax[1] = unit.conversion(d.minmax[1])
}
const stationMeta = source.stationMeta(station, parameter)
this.setState({ stationMeta })
return d
})
}
source.stationData(station, parameter.id, start, end, granularity).then(response => {
if(this.mounted) {
this.setState({ data, stationMeta, unit })
if(response === 'error') {
this.setState({ error: true })
} else {
let data = response
const unit = (parameter.units ? parameter.units.find(x => x.id === this.props.unitStatus[parameter.id]) : null)
if(unit.conversion) {
data = response.map(d => {
d.value = unit.conversion(d.value)
if(d.minmax) {
d.minmax[0] = unit.conversion(d.minmax[0])
d.minmax[1] = unit.conversion(d.minmax[1])
}
return d
})
}
if(data.length > 0) {
const startIndex = (data.length - 7*24 > 0 ? data.length - 7*24 : 0)
const dataStart = moment(data[startIndex].timestamp)
const dataEnd = moment(data[data.length-1].timestamp)
this.setTickSettings(dataStart, dataEnd)
this.setState({ data, unit })
if(data.length > 0) {
const startIndex = (data.length - 7*24 > 0 ? data.length - 7*24 : 0)
const dataStart = moment(data[startIndex].timestamp)
const dataEnd = moment(data[data.length-1].timestamp)
this.setTickSettings(dataStart, dataEnd)
}
}
}
})
}
......@@ -121,7 +130,7 @@ class StationInfo extends React.Component {
render() {
moment.locale(appSettings.language)
const { stationMeta, data, chartHeight, downloadForm, unit, tickFormat, ticks } = this.state
const { error, stationMeta, data, chartHeight, downloadForm, unit, tickFormat, ticks } = this.state
const { id, source } = this.props.clickedObject
const parameter = this.props.activeLayer
......@@ -162,16 +171,19 @@ class StationInfo extends React.Component {
return (
<div ref={e => this.container = e}>
{ stationMeta ?
{ stationMeta &&
<div>
<h1>{stationMeta.name}</h1>
<p className="description">{ ReactHtmlParser(stationMeta.description) }</p>
</div> :
<div className="loading">
<span></span>{ texts.loading }
</div>
}
{ (!data && !error) && <div className="loading"><span></span>{ texts.loading }</div> }
{ (error) && <em>{ texts.loadingError }</em> }
{ (data && data.length === 0) && <em>{ texts.nodata }</em> }
{ (data && data.length > 0) &&
<div>
<div id="chart-header">
......@@ -197,7 +209,7 @@ class StationInfo extends React.Component {
<Tooltip content={ ChartTooltip } animationDuration={0} unit={unit.label} />
<Area type="natural" dataKey="minmax" stroke="none" fill="url(#yaxis)" />
<Area type="natural" dataKey="minmax" stroke="none" fill="url(#yaxis)" fillOpacity={0.5} />
<Line className={lineClass} type="natural" dataKey="value" { ...lineStyle } dot={false} strokeWidth={1} activeDot={{ r: 3 }} />
<Brush dataKey="timestamp" height={40} fill="#eee" stroke="none" travellerWidth={4}
......@@ -213,8 +225,6 @@ class StationInfo extends React.Component {
</ResponsiveContainer>
</div>
}
{ (stationMeta && data.length === 0) && <em>{ texts.nodata }</em> }
</div>
)
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment