Farmbot-Web-App/webpack/devices/devices.tsx

97 lines
3.5 KiB
TypeScript
Raw Normal View History

2017-06-29 12:54:02 -06:00
import * as React from "react";
import { connect } from "react-redux";
import { HardwareSettings } from "./components/hardware_settings";
import { FarmbotOsSettings } from "./components/farmbot_os_settings";
import { Page, Col, Row } from "../ui";
2017-06-29 12:54:02 -06:00
import { mapStateToProps } from "./state_to_props";
import { Props } from "./interfaces";
2017-09-26 13:05:01 -06:00
import { ConnectivityPanel } from "./connectivity/index";
2017-09-27 21:41:34 -06:00
import {
botToMQTT, botToAPI, browserToMQTT, botToFirmware, browserToAPI
2017-09-27 21:41:34 -06:00
} from "./connectivity/status_checks";
import { Diagnosis, DiagnosisName } from "./connectivity/diagnosis";
2017-09-26 13:05:01 -06:00
import { StatusRowProps } from "./connectivity/connectivity_row";
2017-11-01 08:11:18 -06:00
import { resetConnectionInfo } from "./actions";
2017-11-30 20:43:35 -07:00
import { PinBindings } from "./components/pin_bindings";
import { catchErrors } from "../util";
2017-09-25 12:37:24 -06:00
2017-06-29 12:54:02 -06:00
@connect(mapStateToProps)
export class Devices extends React.Component<Props, {}> {
state = { online: navigator.onLine };
componentDidCatch(x: Error, y: React.ErrorInfo) { catchErrors(x, y); }
/** A record of all the things we know about connectivity right now. */
get flags(): Record<DiagnosisName, StatusRowProps> {
2017-09-27 21:41:34 -06:00
const fwVersion = this.props.bot.hardware
.informational_settings.firmware_version;
2017-10-02 08:58:03 -06:00
return {
2017-10-03 14:59:39 -06:00
userMQTT: browserToMQTT(this.props.userToMqtt),
2017-10-02 08:58:03 -06:00
userAPI: browserToAPI(this.props.userToApi),
botMQTT: botToMQTT(this.props.botToMqtt),
2017-10-03 14:59:39 -06:00
botAPI: botToAPI(this.props.deviceAccount.body.last_saw_api),
botFirmware: botToFirmware(fwVersion),
};
}
/** Shuffle these around to change the ordering of the status table. */
get rowData(): StatusRowProps[] {
2017-09-27 21:41:34 -06:00
return [
this.flags.userAPI,
2017-09-27 21:41:34 -06:00
this.flags.userMQTT,
this.flags.botMQTT,
this.flags.botAPI,
this.flags.botFirmware,
2017-09-27 21:41:34 -06:00
];
2017-09-25 12:37:24 -06:00
}
2017-09-26 13:05:01 -06:00
refresh = () => {
2017-11-01 08:11:18 -06:00
this.props.dispatch(resetConnectionInfo(this.props.deviceAccount));
2017-09-26 13:05:01 -06:00
};
2017-06-29 12:54:02 -06:00
render() {
if (this.props.auth) {
const botToMqttStatus =
this.props.botToMqtt ? this.props.botToMqtt.state : "down";
2017-06-29 12:54:02 -06:00
return <Page className="devices">
<Row>
<Col xs={12} sm={6}>
<FarmbotOsSettings
account={this.props.deviceAccount}
dispatch={this.props.dispatch}
bot={this.props.bot}
auth={this.props.auth}
botToMqttStatus={botToMqttStatus} />
<ConnectivityPanel
status={this.props.deviceAccount.specialStatus}
onRefresh={this.refresh}
rowData={this.rowData}>
<Diagnosis
userAPI={!!this.flags.userAPI}
userMQTT={!!this.flags.userMQTT.connectionStatus}
botMQTT={!!this.flags.botMQTT.connectionStatus}
botAPI={!!this.flags.botAPI.connectionStatus}
botFirmware={!!this.flags.botFirmware.connectionStatus} />
</ConnectivityPanel>
</Col>
<Col xs={12} sm={6}>
<HardwareSettings
controlPanelState={this.props.bot.controlPanelState}
dispatch={this.props.dispatch}
bot={this.props.bot}
botToMqttStatus={botToMqttStatus} />
2017-11-30 20:43:35 -07:00
{this.props.bot.hardware.gpio_registry &&
<PinBindings
dispatch={this.props.dispatch}
bot={this.props.bot}
resources={this.props.resources}
botToMqttStatus={botToMqttStatus} />}
</Col>
</Row>
2017-06-29 12:54:02 -06:00
</Page>;
} else {
throw new Error("Log in first");
}
}
2017-07-04 07:20:51 -06:00
}