2017-09-20 01:27:37 -06:00
|
|
|
import * as React from "react";
|
2019-04-09 20:09:57 -06:00
|
|
|
import { Row, Col, DropDownItem, FBSelect } from "../../../ui";
|
2019-06-24 15:39:49 -06:00
|
|
|
import { info } from "../../../toast/toast";
|
2017-12-07 21:05:22 -07:00
|
|
|
import { ColWidth } from "../farmbot_os_settings";
|
2018-01-27 02:29:13 -07:00
|
|
|
import { updateConfig } from "../../actions";
|
|
|
|
import { BoardTypeProps } from "./interfaces";
|
2019-04-02 13:59:37 -06:00
|
|
|
import { t } from "../../../i18next_wrapper";
|
2019-04-09 20:09:57 -06:00
|
|
|
import { FirmwareHardwareStatus } from "./firmware_hardware_status";
|
2019-07-15 16:53:28 -06:00
|
|
|
import {
|
2020-02-28 09:35:32 -07:00
|
|
|
isFwHardwareValue, getFirmwareChoices, FIRMWARE_CHOICES_DDI,
|
2019-07-15 16:53:28 -06:00
|
|
|
} from "../firmware_hardware_support";
|
2020-02-18 12:21:09 -07:00
|
|
|
import { Highlight } from "../maybe_highlight";
|
|
|
|
import { DeviceSetting } from "../../../constants";
|
2020-03-13 15:06:40 -06:00
|
|
|
import { DevSettings } from "../../../account/dev/dev_support";
|
2017-09-20 01:27:37 -06:00
|
|
|
|
2019-07-15 16:53:28 -06:00
|
|
|
interface BoardTypeState { sending: boolean }
|
2018-01-27 02:29:13 -07:00
|
|
|
|
|
|
|
export class BoardType extends React.Component<BoardTypeProps, BoardTypeState> {
|
|
|
|
state = {
|
|
|
|
sending: this.sending
|
|
|
|
};
|
|
|
|
|
2019-08-26 10:13:33 -06:00
|
|
|
UNSAFE_componentWillReceiveProps() {
|
2018-01-27 02:29:13 -07:00
|
|
|
this.setState({ sending: this.sending });
|
|
|
|
}
|
|
|
|
|
|
|
|
get sending() {
|
|
|
|
return !this.props.sourceFbosConfig("firmware_hardware").consistent;
|
|
|
|
}
|
2017-09-20 01:27:37 -06:00
|
|
|
|
2018-01-27 02:29:13 -07:00
|
|
|
get selectedBoard(): DropDownItem | undefined {
|
2020-03-13 15:06:40 -06:00
|
|
|
return this.props.firmwareHardware
|
|
|
|
? FIRMWARE_CHOICES_DDI[this.props.firmwareHardware]
|
|
|
|
: undefined;
|
2017-10-04 00:53:26 -06:00
|
|
|
}
|
|
|
|
|
2018-01-27 02:29:13 -07:00
|
|
|
sendOffConfig = (selectedItem: DropDownItem) => {
|
|
|
|
const firmware_hardware = selectedItem.value;
|
|
|
|
if (selectedItem && isFwHardwareValue(firmware_hardware)) {
|
2017-10-04 00:53:26 -06:00
|
|
|
info(t("Sending firmware configuration..."), t("Sending"));
|
2018-01-27 02:29:13 -07:00
|
|
|
this.props.dispatch(updateConfig({ firmware_hardware }));
|
|
|
|
this.setState({ sending: true });
|
|
|
|
this.forceUpdate();
|
2017-10-04 00:53:26 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-03-13 15:06:40 -06:00
|
|
|
FirmwareSelection = () =>
|
|
|
|
<FBSelect
|
|
|
|
key={this.props.firmwareHardware}
|
|
|
|
extraClass={this.state.sending ? "dim" : ""}
|
|
|
|
list={getFirmwareChoices()}
|
|
|
|
selectedItem={this.selectedBoard}
|
|
|
|
onChange={this.sendOffConfig} />
|
|
|
|
|
2017-09-20 01:27:37 -06:00
|
|
|
render() {
|
2020-03-13 15:06:40 -06:00
|
|
|
const newFormat = DevSettings.futureFeaturesEnabled();
|
|
|
|
return <Highlight settingName={DeviceSetting.firmware}>
|
|
|
|
<Row>
|
2020-02-18 12:21:09 -07:00
|
|
|
<Col xs={ColWidth.label}>
|
|
|
|
<label>
|
|
|
|
{t("FIRMWARE")}
|
|
|
|
</label>
|
|
|
|
</Col>
|
2020-03-13 15:06:40 -06:00
|
|
|
{!newFormat &&
|
|
|
|
<Col xs={ColWidth.description}>
|
|
|
|
<this.FirmwareSelection />
|
|
|
|
</Col>}
|
2020-02-18 12:21:09 -07:00
|
|
|
<Col xs={ColWidth.button}>
|
|
|
|
<FirmwareHardwareStatus
|
|
|
|
botOnline={this.props.botOnline}
|
2020-03-13 15:06:40 -06:00
|
|
|
apiFirmwareValue={this.props.firmwareHardware}
|
2020-02-18 12:21:09 -07:00
|
|
|
alerts={this.props.alerts}
|
|
|
|
bot={this.props.bot}
|
|
|
|
dispatch={this.props.dispatch}
|
|
|
|
timeSettings={this.props.timeSettings} />
|
|
|
|
</Col>
|
2020-03-13 15:06:40 -06:00
|
|
|
</Row>
|
|
|
|
{newFormat &&
|
|
|
|
<Row>
|
|
|
|
<Col xs={12} className="no-pad">
|
|
|
|
<this.FirmwareSelection />
|
|
|
|
</Col>
|
|
|
|
</Row>}
|
|
|
|
</Highlight>;
|
2017-09-20 01:27:37 -06:00
|
|
|
}
|
|
|
|
}
|