Farmbot-Web-App/frontend/controls/sensor_readings/sensor_readings.tsx

112 lines
4.2 KiB
TypeScript
Raw Normal View History

2018-07-19 23:48:32 -06:00
import * as React from "react";
import { Widget, WidgetHeader, WidgetBody, WidgetFooter } from "../../ui";
import { SensorReadingsProps, SensorReadingsState } from "./interfaces";
import { SensorReadingsTable } from "./table";
import { filterSensorReadings } from "./filter_readings";
import {
TimePeriodSelection, DateDisplay, getEndDate
} from "./time_period_selection";
import { LocationSelection, LocationDisplay } from "./location_selection";
import { SensorSelection } from "./sensor_selection";
import { ToolTips } from "../../constants";
2018-08-01 07:03:35 -06:00
import { TaggedSensor } from "farmbot";
2018-07-19 23:48:32 -06:00
import { AxisInputBoxGroupState } from "../interfaces";
2018-07-24 21:45:38 -06:00
import { SensorReadingsPlot } from "./graph";
2019-04-02 13:59:37 -06:00
import { t } from "../../i18next_wrapper";
2018-07-19 23:48:32 -06:00
export class SensorReadings
extends React.Component<SensorReadingsProps, SensorReadingsState> {
state: SensorReadingsState = {
sensor: undefined,
timePeriod: 3600 * 24,
endDate: getEndDate(this.props.sensorReadings),
2020-02-28 09:34:28 -07:00
xyzLocation: undefined,
2018-07-19 23:48:32 -06:00
showPreviousPeriod: false,
deviation: 0,
2018-07-24 21:45:38 -06:00
hovered: undefined,
2018-07-19 23:48:32 -06:00
};
/** Toggle display of previous time period. */
togglePrevious = () =>
this.setState({ showPreviousPeriod: !this.state.showPreviousPeriod });
setSensor = (sensor: TaggedSensor | undefined) => this.setState({ sensor });
setEndDate = (endDate: number) => this.setState({ endDate });
setTimePeriod = (timePeriod: number) => this.setState({ timePeriod });
2020-02-28 09:34:28 -07:00
setLocation = (xyzLocation: AxisInputBoxGroupState | undefined) =>
this.setState({ xyzLocation });
2018-07-19 23:48:32 -06:00
setDeviation = (deviation: number) => this.setState({ deviation });
2018-07-24 21:45:38 -06:00
hover = (hovered: string | undefined) => this.setState({ hovered });
clearFilters = () => this.setState({
sensor: undefined,
timePeriod: 3600 * 24,
endDate: getEndDate(this.props.sensorReadings),
2020-02-28 09:34:28 -07:00
xyzLocation: undefined,
2018-07-24 21:45:38 -06:00
showPreviousPeriod: false,
deviation: 0,
});
2018-07-19 23:48:32 -06:00
render() {
/** Return filtered sensor readings for the specified period.
* Must be in render() so that state updates. */
const readingsForPeriod =
filterSensorReadings(this.props.sensorReadings, this.state);
return <Widget className="sensor-history-widget">
<WidgetHeader
title={t("Sensor History")}
2018-07-24 21:45:38 -06:00
helpText={ToolTips.SENSOR_HISTORY}>
2020-02-28 09:34:28 -07:00
<button className="fb-button gray"
title={t("clear filters")}
onClick={this.clearFilters}>
2018-07-24 21:45:38 -06:00
{t("clear filters")}
</button>
</WidgetHeader>
2018-07-19 23:48:32 -06:00
<WidgetBody>
<SensorSelection
selectedSensor={this.state.sensor}
sensors={this.props.sensors}
setSensor={this.setSensor} />
<TimePeriodSelection
timePeriod={this.state.timePeriod}
endDate={this.state.endDate}
showPreviousPeriod={this.state.showPreviousPeriod}
setEndDate={this.setEndDate}
setPeriod={this.setTimePeriod}
togglePrevious={this.togglePrevious} />
<LocationSelection
2020-02-28 09:34:28 -07:00
xyzLocation={this.state.xyzLocation}
2018-07-19 23:48:32 -06:00
deviation={this.state.deviation}
setLocation={this.setLocation}
setDeviation={this.setDeviation} />
<hr />
2018-07-24 21:45:38 -06:00
<SensorReadingsPlot
readingsForPeriod={readingsForPeriod}
endDate={this.state.endDate}
2019-04-09 23:17:03 -06:00
timeSettings={this.props.timeSettings}
2018-07-24 21:45:38 -06:00
hover={this.hover}
hovered={this.state.hovered}
showPreviousPeriod={this.state.showPreviousPeriod}
timePeriod={this.state.timePeriod} />
2018-07-19 23:48:32 -06:00
<SensorReadingsTable
readingsForPeriod={readingsForPeriod}
sensors={this.props.sensors}
2019-04-09 23:17:03 -06:00
timeSettings={this.props.timeSettings}
2018-07-24 21:45:38 -06:00
hover={this.hover}
hovered={this.state.hovered} />
2018-07-19 23:48:32 -06:00
</WidgetBody>
<WidgetFooter>
<div className="sensor-history-footer">
<DateDisplay
endDate={this.state.endDate}
showPreviousPeriod={this.state.showPreviousPeriod}
timePeriod={this.state.timePeriod}
2019-04-09 23:17:03 -06:00
timeSettings={this.props.timeSettings} />
2018-07-19 23:48:32 -06:00
<LocationDisplay
2020-02-28 09:34:28 -07:00
xyzLocation={this.state.xyzLocation}
2018-07-19 23:48:32 -06:00
deviation={this.state.deviation} />
</div>
</WidgetFooter>
</Widget>;
}
}