Farmbot-Web-App/frontend/sequences/step_tiles/tile_reboot.tsx

65 lines
2.1 KiB
TypeScript
Raw Normal View History

2019-12-26 09:25:03 -07:00
import * as React from "react";
import { StepParams } from "../interfaces";
2020-04-28 08:18:04 -06:00
import { Content } from "../../constants";
2019-12-26 09:25:03 -07:00
import { StepWrapper, StepHeader, StepContent } from "../step_ui/index";
import { t } from "../../i18next_wrapper";
import { ALLOWED_PACKAGES, SequenceBodyItem, Reboot } from "farmbot";
import { editStep } from "../../api/crud";
2020-01-07 14:00:25 -07:00
// import { StepRadio } from "../step_ui/step_radio";
// const PACKAGE_CHOICES = (): Record<ALLOWED_PACKAGES, string> => ({
// "arduino_firmware": t("Just the Arduino"),
// "farmbot_os": t("Entire system")
// });
2019-12-26 09:25:03 -07:00
function assertReboot(x: SequenceBodyItem): asserts x is Reboot {
if (x.kind !== "reboot") {
2020-01-03 13:13:49 -07:00
throw new Error(`${x.kind} is not "reboot"`);
2019-12-26 09:25:03 -07:00
}
}
2020-01-02 08:11:11 -07:00
type RELEVANT_KEYS = "currentStep" | "currentSequence" | "index" | "dispatch";
type RebootEditProps = Pick<StepParams, RELEVANT_KEYS>;
export const rebootExecutor =
(pkg: ALLOWED_PACKAGES) => (step: SequenceBodyItem) => {
assertReboot(step);
step.args.package = pkg;
};
export const editTheRebootStep =
(props: RebootEditProps) => (pkg: ALLOWED_PACKAGES) => {
const { currentStep, index, currentSequence } = props;
props.dispatch(editStep({
step: currentStep,
index,
sequence: currentSequence,
executor: rebootExecutor(pkg),
}));
};
2019-12-26 09:25:03 -07:00
export function TileReboot(props: StepParams) {
const { dispatch, currentStep, index, currentSequence } = props;
2020-01-03 13:13:49 -07:00
const className = "reboot-step";
2019-12-26 09:25:03 -07:00
assertReboot(currentStep);
return <StepWrapper>
<StepHeader
className={className}
2020-04-28 08:18:04 -06:00
helpText={Content.RESTART_FARMBOT}
2019-12-26 09:25:03 -07:00
currentSequence={currentSequence}
currentStep={currentStep}
dispatch={dispatch}
index={index}
confirmStepDeletion={props.confirmStepDeletion} />
<StepContent className={className}>
2020-01-07 14:00:25 -07:00
<p>
2020-04-28 08:18:04 -06:00
{t(Content.REBOOT_STEP)}
2020-01-07 14:00:25 -07:00
</p>
{/* <StepRadio
2020-01-03 13:13:49 -07:00
choices={Object.keys(PACKAGE_CHOICES())}
choiceLabelLookup={PACKAGE_CHOICES()}
2019-12-26 09:25:03 -07:00
currentChoice={currentStep.args.package as ALLOWED_PACKAGES}
2020-01-07 14:00:25 -07:00
onChange={editTheRebootStep(props)} /> */}
2019-12-26 09:25:03 -07:00
</StepContent>
</StepWrapper>;
}