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

61 lines
1.7 KiB
TypeScript
Raw Normal View History

2019-06-05 14:48:31 -06:00
import * as React from "react";
2019-11-22 12:57:22 -07:00
import { edit } from "../api/crud";
2019-06-05 14:48:31 -06:00
import { FBSelect } from "../ui";
import {
2020-02-28 09:35:32 -07:00
pinDropdowns,
2019-06-05 14:48:31 -06:00
} from "../sequences/step_tiles/pin_and_peripheral_support";
import { PIN_MODES } from "../sequences/step_tiles/tile_pin_support";
import { t } from "../i18next_wrapper";
import { TaggedPeripheral, TaggedSensor } from "farmbot";
2019-06-17 19:43:44 -06:00
import { isNumber } from "lodash";
2019-11-22 12:57:22 -07:00
2019-08-26 12:20:46 -06:00
const MODES = (): { [s: string]: string } => ({
2019-06-05 14:48:31 -06:00
0: t("Digital"),
1: t("Analog")
2019-08-26 12:20:46 -06:00
});
2019-06-05 14:48:31 -06:00
interface NameInputBoxProps {
dispatch: Function;
value: string | undefined;
resource: TaggedPeripheral | TaggedSensor;
}
export const NameInputBox = (props: NameInputBoxProps) =>
<input type="text"
2020-02-28 09:34:28 -07:00
name="name"
2019-06-05 14:48:31 -06:00
placeholder={t("Name")}
value={props.value}
onChange={e => props.dispatch(edit(props.resource, {
label: e.currentTarget.value
}))} />;
interface PinDropdownProps {
dispatch: Function;
value: number | undefined;
resource: TaggedPeripheral | TaggedSensor;
}
export const PinDropdown = (props: PinDropdownProps) =>
<FBSelect
2019-06-17 19:43:44 -06:00
selectedItem={isNumber(props.value)
? { label: t("Pin ") + `${props.value}`, value: props.value || "" }
: { label: t("Select a pin "), value: "" }}
2019-06-05 14:48:31 -06:00
onChange={d => props.dispatch(edit(props.resource, {
pin: parseInt(d.value.toString(), 10)
}))}
list={pinDropdowns(n => n)} />;
interface ModeDropdownProps {
dispatch: Function;
value: number;
resource: TaggedPeripheral | TaggedSensor;
}
export const ModeDropdown = (props: ModeDropdownProps) =>
<FBSelect
2019-08-26 12:20:46 -06:00
onChange={d => props.dispatch(edit(props.resource, {
mode: parseInt(d.value.toString(), 10)
}))}
selectedItem={{ label: MODES()[props.value], value: props.value }}
list={PIN_MODES()} />;