WIP
This commit is contained in:
parent
aa31ff76ca
commit
fa92fe0e14
|
@ -62,7 +62,7 @@ describe("Pin and Peripheral support files", () => {
|
|||
.map((x: DropDownItem) => x.headingId)
|
||||
.uniq()
|
||||
.value();
|
||||
expect(values).toEqual([PinGroupName.pin]);
|
||||
expect(values).toEqual([PinGroupName.Pin]);
|
||||
});
|
||||
|
||||
it("Makes a list of Peripheral drop downs", () => {
|
||||
|
@ -74,7 +74,7 @@ describe("Pin and Peripheral support files", () => {
|
|||
expect(result[0]).toBe(PERIPHERAL_HEADING);
|
||||
expect(result[1]).toEqual({
|
||||
label: p.body.label,
|
||||
headingId: PinGroupName.peripheral,
|
||||
headingId: PinGroupName.Peripheral,
|
||||
value: expect.stringContaining("Peripheral.")
|
||||
});
|
||||
});
|
||||
|
@ -88,7 +88,7 @@ describe("Pin and Peripheral support files", () => {
|
|||
expect(result[0]).toBe(SENSOR_HEADING);
|
||||
expect(result[1]).toEqual({
|
||||
label: s.body.label,
|
||||
headingId: PinGroupName.sensor,
|
||||
headingId: PinGroupName.Sensor,
|
||||
value: expect.stringContaining("Sensor.")
|
||||
});
|
||||
});
|
||||
|
@ -179,7 +179,7 @@ describe("Pin and Peripheral support files", () => {
|
|||
const expected: DropDownItem = {
|
||||
label: p.body.label,
|
||||
value: p.body.id || NaN,
|
||||
headingId: PinGroupName.peripheral
|
||||
headingId: PinGroupName.Peripheral
|
||||
};
|
||||
expect(result).toEqual(expected);
|
||||
});
|
||||
|
|
|
@ -18,9 +18,9 @@ import { ShouldDisplay, Feature } from "../../devices/interfaces";
|
|||
|
||||
/** `headingIds` required to group the three kinds of pins. */
|
||||
export enum PinGroupName {
|
||||
sensor = "Sensor",
|
||||
peripheral = "Peripheral",
|
||||
pin = "Pin"
|
||||
Sensor = "Sensor",
|
||||
Peripheral = "Peripheral",
|
||||
Pin = "Pin"
|
||||
}
|
||||
|
||||
export const PERIPHERAL_HEADING: DropDownItem =
|
||||
|
@ -38,21 +38,21 @@ export const pinNumber2DropDown =
|
|||
(n: number) => {
|
||||
const analog = n > 53 ? ` (A${n - 54})` : "";
|
||||
const label = `${t("Pin")} ${n}${analog}`;
|
||||
return { label, value: valueFormat(n), headingId: PinGroupName.pin };
|
||||
return { label, value: valueFormat(n), headingId: PinGroupName.Pin };
|
||||
};
|
||||
|
||||
const peripheral2DropDown =
|
||||
(x: TaggedPeripheral): DropDownItem => ({
|
||||
label: x.body.label,
|
||||
value: x.uuid,
|
||||
headingId: PinGroupName.peripheral
|
||||
headingId: PinGroupName.Peripheral
|
||||
});
|
||||
|
||||
const sensor2DropDown =
|
||||
(x: TaggedSensor): DropDownItem => ({
|
||||
label: x.body.label,
|
||||
value: x.uuid,
|
||||
headingId: PinGroupName.sensor
|
||||
headingId: PinGroupName.Sensor
|
||||
});
|
||||
|
||||
export function peripheralsAsDropDowns(input: ResourceIndex): DropDownItem[] {
|
||||
|
@ -81,8 +81,8 @@ export const pinsAsDropDowns =
|
|||
];
|
||||
|
||||
const TYPE_MAPPING: Record<AllowedPinTypes, PinGroupName> = {
|
||||
"Peripheral": PinGroupName.peripheral,
|
||||
"Sensor": PinGroupName.sensor
|
||||
"Peripheral": PinGroupName.Peripheral,
|
||||
"Sensor": PinGroupName.Sensor
|
||||
};
|
||||
|
||||
export const isPinType =
|
||||
|
|
|
@ -9,6 +9,7 @@ import {
|
|||
Col, Row, FBSelect, DropDownItem, NULL_CHOICE
|
||||
} from "../../../ui/index";
|
||||
import { ALLOWED_OPS } from "farmbot/dist";
|
||||
import { updateLhs } from "./update_lhs";
|
||||
|
||||
const IS_UNDEFINED: ALLOWED_OPS = "is_undefined";
|
||||
const label_ops: Record<ALLOWED_OPS, string> = {
|
||||
|
@ -36,7 +37,9 @@ export function If_(props: IfParams) {
|
|||
const seqCopy = defensiveClone(sequence).body;
|
||||
const val = e.value;
|
||||
seqCopy.body = seqCopy.body || [];
|
||||
if (_.isString(val)) { stepCopy.args[field] = val; }
|
||||
if (_.isString(val)) {
|
||||
stepCopy.args[field] = val;
|
||||
}
|
||||
seqCopy.body[index] = stepCopy;
|
||||
dispatch(overwrite(sequence, seqCopy));
|
||||
};
|
||||
|
@ -53,7 +56,7 @@ export function If_(props: IfParams) {
|
|||
<FBSelect
|
||||
list={lhsOptions}
|
||||
placeholder="Left hand side"
|
||||
onChange={updateField("lhs")}
|
||||
onChange={updateLhs(props)}
|
||||
selectedItem={lhsOptions
|
||||
.filter(x => x.value === lhs)[0] || NULL_CHOICE} />
|
||||
</Col>
|
||||
|
|
|
@ -1,3 +1,11 @@
|
|||
import { TaggedSequence } from "../../../resources/tagged_resources";
|
||||
import { If } from "farmbot";
|
||||
import { ResourceIndex } from "../../../resources/interfaces";
|
||||
import { defensiveClone, fancyDebug } from "../../../util";
|
||||
import { DropDownItem } from "../../../ui";
|
||||
import { overwrite } from "../../../api/crud";
|
||||
import { isString } from "lodash";
|
||||
import { PinGroupName } from "../pin_and_peripheral_support";
|
||||
|
||||
interface LhsUpdateProps {
|
||||
currentSequence: TaggedSequence;
|
||||
|
@ -6,15 +14,30 @@ interface LhsUpdateProps {
|
|||
index: number;
|
||||
resources: ResourceIndex;
|
||||
}
|
||||
|
||||
export const updateLhs =
|
||||
(props: IfParams) =>
|
||||
(ddi: DropDownItem) => {
|
||||
(props: LhsUpdateProps) => {
|
||||
const { currentStep, currentSequence, dispatch, index } = props;
|
||||
return (e: DropDownItem) => {
|
||||
fancyDebug(e);
|
||||
const stepCopy = defensiveClone(step);
|
||||
const seqCopy = defensiveClone(sequence).body;
|
||||
const stepCopy = defensiveClone(currentStep);
|
||||
const seqCopy = defensiveClone(currentSequence).body;
|
||||
const val = e.value;
|
||||
seqCopy.body = seqCopy.body || [];
|
||||
if (_.isString(val)) { stepCopy.args[field] = val; }
|
||||
if (isString(val)) {
|
||||
switch (e.headingId) {
|
||||
case PinGroupName.Peripheral:
|
||||
throw new Error("Implement peripherals");
|
||||
case PinGroupName.Sensor:
|
||||
throw new Error("Implement sensors");
|
||||
case PinGroupName.Pin:
|
||||
stepCopy.args.lhs = val;
|
||||
break;
|
||||
default:
|
||||
throw new Error("Unhandled heading ID: " + e.headingId);
|
||||
}
|
||||
}
|
||||
seqCopy.body[index] = stepCopy;
|
||||
dispatch(overwrite(sequence, seqCopy));
|
||||
}
|
||||
dispatch(overwrite(currentSequence, seqCopy));
|
||||
};
|
||||
};
|
||||
|
|
|
@ -103,13 +103,11 @@ export function shouldDisplay(
|
|||
current: string | undefined, lookupData: MinOsFeatureLookup | undefined) {
|
||||
return function (feature: Feature): boolean {
|
||||
/** Escape hatch for platform developers doing offline development. */
|
||||
if (localStorage.getItem("IM_A_DEVELOPER")) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (isString(current)) {
|
||||
const override = localStorage.getItem("IM_A_DEVELOPER");
|
||||
const target = override || current;
|
||||
if (isString(target)) {
|
||||
const min = (lookupData || {})[feature] || MinVersionOverride.NEVER;
|
||||
switch (semverCompare(current, min)) {
|
||||
switch (semverCompare(target, min)) {
|
||||
case SemverResult.LEFT_IS_GREATER:
|
||||
case SemverResult.EQUAL:
|
||||
return true;
|
||||
|
|
Loading…
Reference in a new issue