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

108 lines
4.1 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/index";
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 { selectAllDiagnosticDumps } from "../resources/selectors";
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 };
/** 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 = () => {
this.props.dispatch(resetConnectionInfo());
2017-09-26 13:05:01 -06:00
};
2017-06-29 12:54:02 -06:00
render() {
if (this.props.auth) {
2018-01-24 17:32:50 -07:00
const { botToMqtt } = this.props;
const botToMqttStatus = botToMqtt ? botToMqtt.state : "down";
2018-01-25 13:10:50 -07:00
const botToMqttLastSeen = (botToMqtt && botToMqttStatus === "up")
? botToMqtt.at
: "";
2017-06-29 12:54:02 -06:00
return <Page className="devices">
<Row>
<Col xs={12} sm={6}>
<FarmbotOsSettings
diagnostics={selectAllDiagnosticDumps(this.props.resources)}
account={this.props.deviceAccount}
dispatch={this.props.dispatch}
bot={this.props.bot}
2018-01-24 17:32:50 -07:00
botToMqttLastSeen={botToMqttLastSeen}
2018-01-27 02:29:13 -07:00
botToMqttStatus={botToMqttStatus}
2018-03-07 22:08:00 -07:00
sourceFbosConfig={this.props.sourceFbosConfig}
shouldDisplay={this.props.shouldDisplay}
isValidFbosConfig={this.props.isValidFbosConfig} />
<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}
2018-01-27 02:29:13 -07:00
botToMqttStatus={botToMqttStatus}
shouldDisplay={this.props.shouldDisplay}
2018-03-08 21:03:02 -07:00
sourceFbosConfig={this.props.sourceFbosConfig}
2018-03-09 02:34:24 -07:00
sourceFwConfig={this.props.sourceFwConfig}
2018-03-08 21:03:02 -07:00
firmwareConfig={this.props.firmwareConfig} />
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}
2018-03-13 18:34:30 -06:00
botToMqttStatus={botToMqttStatus}
shouldDisplay={this.props.shouldDisplay} />}
</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
}