remove commented code
parent
c1ac3277ed
commit
9ce2478532
|
@ -15,8 +15,6 @@ const mockDevice = {
|
|||
sync: jest.fn(() => { return Promise.resolve(); }),
|
||||
readStatus: jest.fn(() => Promise.resolve()),
|
||||
updateConfig: jest.fn(() => Promise.resolve()),
|
||||
registerGpio: jest.fn(() => Promise.reject()),
|
||||
unregisterGpio: jest.fn(() => Promise.reject()),
|
||||
dumpInfo: jest.fn(() => Promise.resolve()),
|
||||
};
|
||||
|
||||
|
@ -537,22 +535,6 @@ describe("updateConfig()", () => {
|
|||
});
|
||||
});
|
||||
|
||||
describe("registerGpioPin()", () => {
|
||||
// CC: @gabrielburworth - leaving this in place for now. Feel free to delete
|
||||
// or modify based on future needs.
|
||||
it("is deprecated. Delete this later.", async () => {
|
||||
await actions.registerGpioPin({ pin_number: 1, sequence_id: 1 })(jest.fn());
|
||||
await expect(mockDevice.registerGpio).not.toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
|
||||
describe("unregisterGpioPin()", () => {
|
||||
it("is deprecated. Delete this later.", async () => {
|
||||
await actions.unregisterGpioPin(1)(jest.fn());
|
||||
await expect(mockDevice.unregisterGpio).not.toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
|
||||
describe("badVersion()", () => {
|
||||
it("warns of old FBOS version", () => {
|
||||
actions.badVersion();
|
||||
|
|
|
@ -410,29 +410,6 @@ export function updateConfig(config: Configuration) {
|
|||
};
|
||||
}
|
||||
|
||||
/** Register a sequence to an RPi GPIO pin (FBOS < 6.4.4). */
|
||||
export function registerGpioPin(
|
||||
_pinBinding: { pin_number: number, sequence_id: number }) {
|
||||
// const noun = "Register GPIO Pin";
|
||||
return function (_dispatch: Function) {
|
||||
// getDevice()
|
||||
// .registerGpio(pinBinding)
|
||||
// .then(() => updateOK(dispatch))
|
||||
// .catch(() => updateNO(dispatch, noun));
|
||||
};
|
||||
}
|
||||
|
||||
/** Remove binding from an RPi GPIO pin (FBOS < 6.4.4). */
|
||||
export function unregisterGpioPin(_pin_number: number) {
|
||||
// const noun = "Unregister GPIO Pin";
|
||||
return function (_dispatch: Function) {
|
||||
// getDevice()
|
||||
// .unregisterGpio({ pin_number })
|
||||
// .then(() => updateOK(dispatch))
|
||||
// .catch(() => updateNO(dispatch, noun));
|
||||
};
|
||||
}
|
||||
|
||||
/** Change jog button movement amount. */
|
||||
export function changeStepSize(integer: number) {
|
||||
return {
|
||||
|
|
|
@ -93,13 +93,9 @@ export class Devices extends React.Component<Props, {}> {
|
|||
sourceFbosConfig={this.props.sourceFbosConfig}
|
||||
sourceFwConfig={this.props.sourceFwConfig}
|
||||
firmwareConfig={this.props.firmwareConfig} />
|
||||
{this.props.bot.hardware.gpio_registry &&
|
||||
<PinBindings
|
||||
dispatch={this.props.dispatch}
|
||||
bot={this.props.bot}
|
||||
resources={this.props.resources}
|
||||
botToMqttStatus={botToMqttStatus}
|
||||
shouldDisplay={this.props.shouldDisplay} />}
|
||||
<PinBindings
|
||||
dispatch={this.props.dispatch}
|
||||
resources={this.props.resources} />
|
||||
</Col>
|
||||
</Row>
|
||||
</Page>;
|
||||
|
|
|
@ -48,7 +48,6 @@ describe("<PinBindingInputGroup/>", () => {
|
|||
],
|
||||
dispatch: jest.fn(),
|
||||
resources: resources,
|
||||
shouldDisplay: () => false,
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -75,22 +74,9 @@ describe("<PinBindingInputGroup/>", () => {
|
|||
expect(error).toHaveBeenCalledWith("Please select a sequence or action.");
|
||||
});
|
||||
|
||||
// it("registers pin: bot", () => {
|
||||
// const p = fakeProps();
|
||||
// p.dispatch = jest.fn(x => x(jest.fn()));
|
||||
// const wrapper = mount(<PinBindingInputGroup {...p} />);
|
||||
// const buttons = wrapper.find("button");
|
||||
// expect(buttons.last().text()).toEqual("BIND");
|
||||
// wrapper.setState({ pinNumberInput: 1, sequenceIdInput: 2 });
|
||||
// buttons.last().simulate("click");
|
||||
// expect(mockDevice.registerGpio)
|
||||
// .toHaveBeenCalledWith({ pin_number: 1, sequence_id: 2 });
|
||||
// });
|
||||
|
||||
it("registers pin: api", () => {
|
||||
const p = fakeProps();
|
||||
p.dispatch = jest.fn();
|
||||
p.shouldDisplay = () => true;
|
||||
const wrapper = mount(<PinBindingInputGroup {...p} />);
|
||||
const buttons = wrapper.find("button");
|
||||
expect(buttons.last().text()).toEqual("BIND");
|
||||
|
@ -108,7 +94,6 @@ describe("<PinBindingInputGroup/>", () => {
|
|||
it("registers pin: api (special action)", () => {
|
||||
const p = fakeProps();
|
||||
p.dispatch = jest.fn();
|
||||
p.shouldDisplay = () => true;
|
||||
const wrapper = mount(<PinBindingInputGroup {...p} />);
|
||||
const buttons = wrapper.find("button");
|
||||
expect(buttons.last().text()).toEqual("BIND");
|
||||
|
@ -202,7 +187,6 @@ describe("<BindingTypeDropDown />", () => {
|
|||
const setBindingType = jest.fn();
|
||||
const wrapper = shallow(<BindingTypeDropDown
|
||||
bindingType={PinBindingType.standard}
|
||||
shouldDisplay={() => true}
|
||||
setBindingType={setBindingType} />);
|
||||
const ddi = { label: "", value: PinBindingType.special };
|
||||
wrapper.find("FBSelect").simulate("change", ddi);
|
||||
|
|
|
@ -55,7 +55,6 @@ describe("<PinBindingsList/>", () => {
|
|||
],
|
||||
dispatch: jest.fn(),
|
||||
resources: resources,
|
||||
shouldDisplay: () => false,
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -67,22 +66,12 @@ describe("<PinBindingsList/>", () => {
|
|||
expect(buttons.length).toBe(2);
|
||||
});
|
||||
|
||||
// it("unregisters pin: bot", () => {
|
||||
// const p = fakeProps();
|
||||
// p.dispatch = jest.fn(x => x(jest.fn()));
|
||||
// const wrapper = mount(<PinBindingsList {...p} />);
|
||||
// const buttons = wrapper.find("button");
|
||||
// buttons.first().simulate("click");
|
||||
// expect(mockDevice.unregisterGpio).toHaveBeenCalledWith({ pin_number: 10 });
|
||||
// });
|
||||
|
||||
it("unregisters pin: api", () => {
|
||||
const p = fakeProps();
|
||||
const s = fakeSequence();
|
||||
s.body.id = 1;
|
||||
const b = fakePinBinding();
|
||||
p.resources = buildResourceIndex([b, s]).index;
|
||||
p.shouldDisplay = () => true;
|
||||
p.pinBindings = [{ pin_number: 10, sequence_id: 1, uuid: b.uuid }];
|
||||
const wrapper = mount(<PinBindingsList {...p} />);
|
||||
const buttons = wrapper.find("button");
|
||||
|
@ -93,7 +82,6 @@ describe("<PinBindingsList/>", () => {
|
|||
|
||||
it("restricts deletion of built-in bindings", () => {
|
||||
const p = fakeProps();
|
||||
p.shouldDisplay = () => true;
|
||||
p.pinBindings = sysBtnBindingData;
|
||||
const wrapper = mount(<PinBindingsList {...p} />);
|
||||
const buttons = wrapper.find("button");
|
||||
|
|
|
@ -45,27 +45,12 @@ describe("<PinBindings/>", () => {
|
|||
};
|
||||
return {
|
||||
dispatch: jest.fn(),
|
||||
bot: bot,
|
||||
resources: resources,
|
||||
botToMqttStatus: "up",
|
||||
shouldDisplay: () => false,
|
||||
};
|
||||
}
|
||||
|
||||
it("renders: bot", () => {
|
||||
const wrapper = mount(<PinBindings {...fakeProps()} />);
|
||||
["pin bindings", "pin number", "none", "bind"].map(string =>
|
||||
expect(wrapper.text().toLowerCase()).toContain(string));
|
||||
["pi gpio 10", "sequence 1", "pi gpio 11", "sequence 2"].map(string =>
|
||||
expect(wrapper.text().toLowerCase()).toContain(string));
|
||||
const buttons = wrapper.find("button");
|
||||
expect(buttons.length).toBe(6);
|
||||
expect(wrapper.text().toLowerCase()).not.toContain("stock bindings");
|
||||
});
|
||||
|
||||
it("renders: api", () => {
|
||||
it("renders", () => {
|
||||
const p = fakeProps();
|
||||
p.shouldDisplay = () => true;
|
||||
const wrapper = mount(<PinBindings {...p} />);
|
||||
["pin bindings", "pin number", "none", "bind", "stock bindings"]
|
||||
.map(string => expect(wrapper.text().toLowerCase()).toContain(string));
|
||||
|
|
|
@ -14,11 +14,6 @@ describe("<StockPinBindingsButton />", () => {
|
|||
dispatch: jest.fn(),
|
||||
});
|
||||
|
||||
it("doesn't render button", () => {
|
||||
const wrapper = mount(<StockPinBindingsButton {...fakeProps()} />);
|
||||
expect(wrapper.find("button").length).toEqual(0);
|
||||
});
|
||||
|
||||
it("adds bindings", () => {
|
||||
const p = fakeProps();
|
||||
p.shouldDisplay = () => true;
|
||||
|
|
|
@ -1,5 +1,3 @@
|
|||
import { BotState, ShouldDisplay } from "../interfaces";
|
||||
import { NetworkState } from "../../connectivity/interfaces";
|
||||
import { ResourceIndex } from "../../resources/interfaces";
|
||||
import {
|
||||
PinBindingType,
|
||||
|
@ -7,11 +5,8 @@ import {
|
|||
} from "farmbot/dist/resources/api_resources";
|
||||
|
||||
export interface PinBindingsProps {
|
||||
bot: BotState;
|
||||
dispatch: Function;
|
||||
botToMqttStatus: NetworkState;
|
||||
resources: ResourceIndex;
|
||||
shouldDisplay: ShouldDisplay;
|
||||
}
|
||||
|
||||
export interface PinBindingListItems {
|
||||
|
@ -25,14 +20,12 @@ export interface PinBindingListItems {
|
|||
export interface PinBindingsListProps {
|
||||
pinBindings: PinBindingListItems[];
|
||||
resources: ResourceIndex;
|
||||
shouldDisplay: ShouldDisplay;
|
||||
dispatch: Function;
|
||||
}
|
||||
|
||||
export interface PinBindingInputGroupProps {
|
||||
dispatch: Function;
|
||||
resources: ResourceIndex;
|
||||
shouldDisplay: ShouldDisplay;
|
||||
pinBindings: PinBindingListItems[];
|
||||
}
|
||||
|
||||
|
|
|
@ -6,7 +6,6 @@ import {
|
|||
import { DropDownItem } from "../../ui";
|
||||
import { gpio } from "./rpi_gpio_diagram";
|
||||
import { flattenDeep, isNumber } from "lodash";
|
||||
import { ShouldDisplay, Feature } from "../interfaces";
|
||||
import { sysBtnBindings } from "./tagged_pin_binding_init";
|
||||
|
||||
export const bindingTypeLabelLookup: { [x: string]: string } = {
|
||||
|
@ -15,12 +14,9 @@ export const bindingTypeLabelLookup: { [x: string]: string } = {
|
|||
"": t("Sequence"),
|
||||
};
|
||||
|
||||
export const bindingTypeList = (shouldDisplay: ShouldDisplay): DropDownItem[] =>
|
||||
export const bindingTypeList = (): DropDownItem[] =>
|
||||
Object.entries(bindingTypeLabelLookup)
|
||||
.filter(([value, _]) => !(value == ""))
|
||||
.filter(([value, _]) =>
|
||||
shouldDisplay(Feature.api_pin_bindings)
|
||||
|| !(value == PinBindingType.special))
|
||||
.map(([value, label]) => ({ label, value }));
|
||||
|
||||
export const specialActionLabelLookup: { [x: string]: string } = {
|
||||
|
@ -62,11 +58,19 @@ enum LEDPin {
|
|||
btn5 = 21,
|
||||
}
|
||||
|
||||
const sysLedBindings = Object.values(LEDPin);
|
||||
/** All pin numbers used by FarmBot OS that cannot be used in pin bindings. */
|
||||
export const sysBindings = sysLedBindings.concat(sysBtnBindings);
|
||||
/** Other pins used by FarmBot OS that cannot be used in pin bindings. */
|
||||
enum SystemPins {
|
||||
sda = 2,
|
||||
scl = 3,
|
||||
reset = 19,
|
||||
}
|
||||
|
||||
const piI2cPins = [0, 1, 2, 3];
|
||||
const sysLedBindings = Object.values(LEDPin);
|
||||
const otherSysBindings = Object.values(SystemPins);
|
||||
/** All pin numbers used by FarmBot OS that cannot be used in pin bindings. */
|
||||
export const sysBindings = sysLedBindings.concat(sysBtnBindings, otherSysBindings);
|
||||
|
||||
const piI2cPins = [0, 1];
|
||||
/** Pin numbers used for special purposes by the RPi. (internal pullup, etc.) */
|
||||
export const reservedPiGPIO = piI2cPins;
|
||||
|
||||
|
@ -88,7 +92,6 @@ export const validGpioPins: number[] =
|
|||
flattenDeep(gpio)
|
||||
.filter(x => isNumber(x))
|
||||
.map((x: number) => x);
|
||||
// .filter(n => !reservedPiGPIO.includes(n));
|
||||
|
||||
/** Sort fn for pin numbers using their labels. */
|
||||
export const sortByNameAndPin = (a: number, b: number) => {
|
||||
|
|
|
@ -9,10 +9,8 @@ import {
|
|||
PinBindingInputGroupState
|
||||
} from "./interfaces";
|
||||
import { isNumber, includes } from "lodash";
|
||||
import { Feature, ShouldDisplay } from "../interfaces";
|
||||
import { initSave } from "../../api/crud";
|
||||
import { pinBindingBody } from "./tagged_pin_binding_init";
|
||||
import { registerGpioPin } from "../actions";
|
||||
import { error, warning } from "farmbot-toastr";
|
||||
import {
|
||||
validGpioPins, sysBindings, generatePinLabel, RpiPinList,
|
||||
|
@ -48,7 +46,7 @@ export class PinBindingInputGroup
|
|||
error(t("Invalid Raspberry Pi GPIO pin number."));
|
||||
}
|
||||
} else {
|
||||
error(t("Raspberry Pi GPIO pin already bound."));
|
||||
error(t("Raspberry Pi GPIO pin already bound or in use."));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -60,30 +58,23 @@ export class PinBindingInputGroup
|
|||
|
||||
/** Validate and save a pin binding. */
|
||||
bindPin = () => {
|
||||
const { shouldDisplay, dispatch } = this.props;
|
||||
const { dispatch } = this.props;
|
||||
const {
|
||||
pinNumberInput, sequenceIdInput, bindingType, specialActionInput
|
||||
} = this.state;
|
||||
if (isNumber(pinNumberInput)) {
|
||||
if (bindingType && (sequenceIdInput || specialActionInput)) {
|
||||
if (shouldDisplay(Feature.api_pin_bindings)) {
|
||||
bindingType == PinBindingType.special
|
||||
? dispatch(initSave("PinBinding", pinBindingBody({
|
||||
pin_num: pinNumberInput,
|
||||
special_action: specialActionInput,
|
||||
binding_type: bindingType
|
||||
})))
|
||||
: dispatch(initSave("PinBinding", pinBindingBody({
|
||||
pin_num: pinNumberInput,
|
||||
sequence_id: sequenceIdInput,
|
||||
binding_type: bindingType
|
||||
})));
|
||||
} else {
|
||||
dispatch(registerGpioPin({
|
||||
pin_number: pinNumberInput,
|
||||
sequence_id: sequenceIdInput || 0
|
||||
}));
|
||||
}
|
||||
bindingType == PinBindingType.special
|
||||
? dispatch(initSave("PinBinding", pinBindingBody({
|
||||
pin_num: pinNumberInput,
|
||||
special_action: specialActionInput,
|
||||
binding_type: bindingType
|
||||
})))
|
||||
: dispatch(initSave("PinBinding", pinBindingBody({
|
||||
pin_num: pinNumberInput,
|
||||
sequence_id: sequenceIdInput,
|
||||
binding_type: bindingType
|
||||
})));
|
||||
this.setState({
|
||||
pinNumberInput: undefined,
|
||||
sequenceIdInput: undefined,
|
||||
|
@ -116,7 +107,6 @@ export class PinBindingInputGroup
|
|||
const {
|
||||
pinNumberInput, bindingType, specialActionInput, sequenceIdInput
|
||||
} = this.state;
|
||||
const { shouldDisplay, resources } = this.props;
|
||||
|
||||
return <Row>
|
||||
<Col xs={PinBindingColWidth.pin}>
|
||||
|
@ -128,7 +118,6 @@ export class PinBindingInputGroup
|
|||
<Col xs={PinBindingColWidth.type}>
|
||||
<BindingTypeDropDown
|
||||
bindingType={bindingType}
|
||||
shouldDisplay={shouldDisplay}
|
||||
setBindingType={this.setBindingType} />
|
||||
</Col>
|
||||
<Col xs={PinBindingColWidth.target}>
|
||||
|
@ -138,7 +127,7 @@ export class PinBindingInputGroup
|
|||
setSpecialAction={this.setSpecialAction} />
|
||||
: <SequenceTargetDropDown
|
||||
sequenceIdInput={sequenceIdInput}
|
||||
resources={resources}
|
||||
resources={this.props.resources}
|
||||
setSequenceIdInput={this.setSequenceIdInput} />}
|
||||
</Col>
|
||||
<Col xs={PinBindingColWidth.button}>
|
||||
|
@ -189,10 +178,9 @@ export const PinNumberInputGroup = (props: {
|
|||
/** binding type selection: sequence or action */
|
||||
export const BindingTypeDropDown = (props: {
|
||||
bindingType: PinBindingType,
|
||||
shouldDisplay: ShouldDisplay,
|
||||
setBindingType: (ddi: DropDownItem) => void,
|
||||
}) => {
|
||||
const { bindingType, shouldDisplay, setBindingType } = props;
|
||||
const { bindingType, setBindingType } = props;
|
||||
return <FBSelect
|
||||
key={"binding_type_input_" + bindingType}
|
||||
onChange={setBindingType}
|
||||
|
@ -200,7 +188,7 @@ export const BindingTypeDropDown = (props: {
|
|||
label: bindingTypeLabelLookup[bindingType],
|
||||
value: bindingType
|
||||
}}
|
||||
list={bindingTypeList(shouldDisplay)} />;
|
||||
list={bindingTypeList()} />;
|
||||
};
|
||||
|
||||
/** sequence selection */
|
||||
|
|
|
@ -1,14 +1,9 @@
|
|||
import * as React from "react";
|
||||
import { t } from "i18next";
|
||||
import { Widget, WidgetBody, WidgetHeader, Row, Col } from "../../ui/index";
|
||||
import { Widget, WidgetBody, WidgetHeader, Row, Col } from "../../ui";
|
||||
import { ToolTips } from "../../constants";
|
||||
import { Feature, BotState } from "../interfaces";
|
||||
import { selectAllPinBindings } from "../../resources/selectors";
|
||||
import { MustBeOnline } from "../must_be_online";
|
||||
import {
|
||||
PinBindingsProps,
|
||||
PinBindingListItems
|
||||
} from "./interfaces";
|
||||
import { PinBindingsProps, PinBindingListItems } from "./interfaces";
|
||||
import { PinBindingsList } from "./pin_bindings_list";
|
||||
import { PinBindingInputGroup } from "./pin_binding_input_group";
|
||||
import {
|
||||
|
@ -58,25 +53,28 @@ const apiPinBindings = (resources: ResourceIndex): PinBindingListItems[] => {
|
|||
return userBindings.concat(sysBtnBindingData);
|
||||
};
|
||||
|
||||
/** Return bot state pin binding data. */
|
||||
const botPinBindings = (bot: BotState): PinBindingListItems[] => {
|
||||
const { gpio_registry } = bot.hardware;
|
||||
return Object.entries(gpio_registry || {})
|
||||
.map(([pin_number, sequence_id]) => {
|
||||
return {
|
||||
pin_number: parseInt(pin_number),
|
||||
sequence_id: parseInt(sequence_id || "")
|
||||
};
|
||||
});
|
||||
};
|
||||
const PinBindingsListHeader = () =>
|
||||
<Row>
|
||||
<Col xs={PinBindingColWidth.pin}>
|
||||
<label>
|
||||
{t("Pin Number")}
|
||||
</label>
|
||||
</Col>
|
||||
<Col xs={PinBindingColWidth.type}>
|
||||
<label>
|
||||
{t("Binding")}
|
||||
</label>
|
||||
</Col>
|
||||
<Col xs={PinBindingColWidth.target}>
|
||||
<label>
|
||||
{t("target")}
|
||||
</label>
|
||||
</Col>
|
||||
</Row>;
|
||||
|
||||
export const PinBindings = (props: PinBindingsProps) => {
|
||||
const { dispatch, resources, shouldDisplay, botToMqttStatus, bot } = props;
|
||||
|
||||
const pinBindings =
|
||||
shouldDisplay(Feature.api_pin_bindings)
|
||||
? apiPinBindings(resources)
|
||||
: botPinBindings(bot);
|
||||
const { dispatch, resources } = props;
|
||||
const pinBindings = apiPinBindings(resources);
|
||||
|
||||
return <Widget className="pin-bindings-widget">
|
||||
<WidgetHeader
|
||||
|
@ -91,44 +89,18 @@ export const PinBindings = (props: PinBindingsProps) => {
|
|||
{ToolTips.PIN_BINDING_WARNING}
|
||||
</div>
|
||||
</Popover>
|
||||
<StockPinBindingsButton
|
||||
dispatch={dispatch}
|
||||
shouldDisplay={shouldDisplay} />
|
||||
<StockPinBindingsButton dispatch={dispatch} />
|
||||
</WidgetHeader>
|
||||
<WidgetBody>
|
||||
<MustBeOnline
|
||||
syncStatus={bot.hardware.informational_settings.sync_status}
|
||||
networkState={botToMqttStatus}
|
||||
lockOpen={shouldDisplay(Feature.api_pin_bindings)
|
||||
|| process.env.NODE_ENV !== "production"}>
|
||||
<Row>
|
||||
<Col xs={PinBindingColWidth.pin}>
|
||||
<label>
|
||||
{t("Pin Number")}
|
||||
</label>
|
||||
</Col>
|
||||
<Col xs={PinBindingColWidth.type}>
|
||||
<label>
|
||||
{t("Binding")}
|
||||
</label>
|
||||
</Col>
|
||||
<Col xs={PinBindingColWidth.target}>
|
||||
<label>
|
||||
{t("target")}
|
||||
</label>
|
||||
</Col>
|
||||
</Row>
|
||||
<PinBindingsList
|
||||
pinBindings={pinBindings}
|
||||
dispatch={dispatch}
|
||||
resources={resources}
|
||||
shouldDisplay={shouldDisplay} />
|
||||
<PinBindingInputGroup
|
||||
pinBindings={pinBindings}
|
||||
dispatch={dispatch}
|
||||
resources={resources}
|
||||
shouldDisplay={shouldDisplay} />
|
||||
</MustBeOnline>
|
||||
<PinBindingsListHeader />
|
||||
<PinBindingsList
|
||||
pinBindings={pinBindings}
|
||||
dispatch={dispatch}
|
||||
resources={resources} />
|
||||
<PinBindingInputGroup
|
||||
pinBindings={pinBindings}
|
||||
dispatch={dispatch}
|
||||
resources={resources} />
|
||||
</WidgetBody>
|
||||
</Widget>;
|
||||
};
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
import * as React from "react";
|
||||
import { t } from "i18next";
|
||||
import { Feature } from "../interfaces";
|
||||
import {
|
||||
bindingTypeLabelLookup, specialActionLabelLookup,
|
||||
generatePinLabel, sortByNameAndPin
|
||||
|
@ -9,23 +8,18 @@ import { destroy } from "../../api/crud";
|
|||
import { error } from "farmbot-toastr";
|
||||
import { Row, Col } from "../../ui";
|
||||
import { findSequenceById } from "../../resources/selectors";
|
||||
import { unregisterGpioPin } from "../actions";
|
||||
import { PinBindingColWidth } from "./pin_bindings";
|
||||
import { PinBindingsListProps } from "./interfaces";
|
||||
import { sysBtnBindings } from "./tagged_pin_binding_init";
|
||||
|
||||
export const PinBindingsList = (props: PinBindingsListProps) => {
|
||||
const { pinBindings, resources, shouldDisplay, dispatch } = props;
|
||||
const { pinBindings, resources, dispatch } = props;
|
||||
|
||||
const deleteBinding = (pin: number, uuid?: string) => {
|
||||
if (shouldDisplay(Feature.api_pin_bindings)) {
|
||||
if (!sysBtnBindings.includes(pin)) {
|
||||
dispatch(destroy(uuid || ""));
|
||||
} else {
|
||||
error(t("Cannot delete built-in pin binding."));
|
||||
}
|
||||
if (!sysBtnBindings.includes(pin)) {
|
||||
dispatch(destroy(uuid || ""));
|
||||
} else {
|
||||
dispatch(unregisterGpioPin(pin));
|
||||
error(t("Cannot delete built-in pin binding."));
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
@ -5,7 +5,6 @@ import {
|
|||
PinBinding
|
||||
} from "farmbot/dist/resources/api_resources";
|
||||
import { PinBindingListItems } from "./interfaces";
|
||||
import { ShouldDisplay, Feature } from "../interfaces";
|
||||
import { stockPinBindings } from "./list_and_label_support";
|
||||
import { initSave } from "../../api/crud";
|
||||
import { t } from "i18next";
|
||||
|
@ -36,20 +35,16 @@ export const pinBindingBody =
|
|||
};
|
||||
|
||||
/** Add default pin bindings. */
|
||||
export const StockPinBindingsButton =
|
||||
({ shouldDisplay, dispatch }: {
|
||||
shouldDisplay: ShouldDisplay, dispatch: Function
|
||||
}) =>
|
||||
<div className="stock-pin-bindings-button">
|
||||
{shouldDisplay(Feature.api_pin_bindings) &&
|
||||
<button
|
||||
className="fb-button green"
|
||||
onClick={() => stockPinBindings.map(binding =>
|
||||
dispatch(initSave("PinBinding", pinBindingBody(binding))))}>
|
||||
<i className="fa fa-plus" />
|
||||
{t("v1.4 Stock Bindings")}
|
||||
</button>}
|
||||
</div>;
|
||||
export const StockPinBindingsButton = ({ dispatch }: { dispatch: Function }) =>
|
||||
<div className="stock-pin-bindings-button">
|
||||
<button
|
||||
className="fb-button green"
|
||||
onClick={() => stockPinBindings.map(binding =>
|
||||
dispatch(initSave("PinBinding", pinBindingBody(binding))))}>
|
||||
<i className="fa fa-plus" />
|
||||
{t("v1.4 Stock Bindings")}
|
||||
</button>
|
||||
</div>;
|
||||
|
||||
/** FarmBot OS built-in pin binding data used by Pin Bindings widget. */
|
||||
export const sysBtnBindingData: PinBindingListItems[] = [];
|
||||
|
|
|
@ -172,7 +172,7 @@ export function scrollToBottom(elementId: string) {
|
|||
|
||||
export function validBotLocationData(
|
||||
botLocationData: BotLocationData | undefined): BotLocationData {
|
||||
if (botLocationData) {
|
||||
if (botLocationData && botLocationData.position && botLocationData.position.x) {
|
||||
return botLocationData;
|
||||
}
|
||||
return {
|
||||
|
|
Loading…
Reference in New Issue