Handle select returns scopedeclaration now
parent
47d924f8a9
commit
90104252b8
|
@ -1,7 +0,0 @@
|
||||||
I hope that we can someday not use this folder and use all the @types/* repositories.
|
|
||||||
|
|
||||||
Some (legacy) libraries don't work with the newer typings (eg: react-redux).
|
|
||||||
|
|
||||||
In those rare circumstances, we can put them in here.
|
|
||||||
|
|
||||||
Hopefully, this folder will go away some day.
|
|
|
@ -19,7 +19,7 @@ export const ParentVariableForm =
|
||||||
const { sequence, resources, onChange } = props;
|
const { sequence, resources, onChange } = props;
|
||||||
const { x, y, z } = props.parent.location;
|
const { x, y, z } = props.parent.location;
|
||||||
const isDisabled = !props.parent.editable;
|
const isDisabled = !props.parent.editable;
|
||||||
|
const list = generateList(resources, [PARENT]);
|
||||||
return <div className="parent-variable-form">
|
return <div className="parent-variable-form">
|
||||||
<Row>
|
<Row>
|
||||||
<Col xs={12}>
|
<Col xs={12}>
|
||||||
|
@ -27,9 +27,11 @@ export const ParentVariableForm =
|
||||||
<FBSelect
|
<FBSelect
|
||||||
key={JSON.stringify(sequence)}
|
key={JSON.stringify(sequence)}
|
||||||
allowEmpty={true}
|
allowEmpty={true}
|
||||||
list={generateList(resources, [PARENT])}
|
list={list}
|
||||||
selectedItem={props.parent.dropdown}
|
selectedItem={props.parent.dropdown}
|
||||||
onChange={(ddi) => {
|
onChange={(ddi) => {
|
||||||
|
const list2 = generateList(resources, [PARENT]);
|
||||||
|
console.dir(list2);
|
||||||
console.error("FINISH ME");
|
console.error("FINISH ME");
|
||||||
handleSelect(props.resources, ddi);
|
handleSelect(props.resources, ddi);
|
||||||
onChange({ x: -23, y: -23, z: -23 });
|
onChange({ x: -23, y: -23, z: -23 });
|
||||||
|
|
|
@ -32,19 +32,6 @@ describe("handleSelect()", () => {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it("handles 'parameter_declaration's", () => {
|
|
||||||
const result = handleSelect(fakeResourceIndex(), {
|
|
||||||
headingId: "parameter",
|
|
||||||
value: "parent",
|
|
||||||
label: "1"
|
|
||||||
});
|
|
||||||
expect(result.kind).toBe("parameter_declaration");
|
|
||||||
if (result.kind == "parameter_declaration") {
|
|
||||||
expect(result.args.label).toBe("parent");
|
|
||||||
expect(result.args.data_type).toBe("point");
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
it("returns location data: identifier", () => {
|
it("returns location data: identifier", () => {
|
||||||
const location = handleSelect(fakeResourceIndex(),
|
const location = handleSelect(fakeResourceIndex(),
|
||||||
{
|
{
|
||||||
|
|
|
@ -2,50 +2,73 @@
|
||||||
* figures out the corresponding Tool | Coordinate | Point */
|
* figures out the corresponding Tool | Coordinate | Point */
|
||||||
import { DropDownItem } from "../../../ui/index";
|
import { DropDownItem } from "../../../ui/index";
|
||||||
import { ResourceIndex } from "../../../resources/interfaces";
|
import { ResourceIndex } from "../../../resources/interfaces";
|
||||||
import { KnownGroupTag, LocationData } from "./interfaces";
|
import { LocationData } from "./interfaces";
|
||||||
import { findPointerByTypeAndId, findToolById } from "../../../resources/selectors";
|
import {
|
||||||
import { bail } from "../../../util";
|
ParameterDeclaration,
|
||||||
import { ParameterDeclaration, Coordinate } from "farmbot";
|
Coordinate,
|
||||||
|
ScopeDeclaration,
|
||||||
|
ScopeDeclarationBodyItem,
|
||||||
|
VariableDeclaration
|
||||||
|
} from "farmbot";
|
||||||
|
|
||||||
export type CeleryVariable = LocationData | ParameterDeclaration;
|
export type CeleryVariable = LocationData | ParameterDeclaration;
|
||||||
export const EMPTY_COORD: Coordinate = {
|
export const EMPTY_COORD: Coordinate =
|
||||||
kind: "coordinate",
|
({ kind: "coordinate", args: { x: 0, y: 0, z: 0 } });
|
||||||
args: { x: 0, y: 0, z: 0 }
|
|
||||||
};
|
|
||||||
|
|
||||||
/** Takes a DropDownItem and turns it into data suitable
|
const toolVar = (value: string | number): VariableDeclaration => ({
|
||||||
* for MoveAbsolute["args"]["location"] */
|
kind: "variable_declaration",
|
||||||
export let handleSelect = (index: ResourceIndex, input: DropDownItem): CeleryVariable => {
|
args: {
|
||||||
const tag = input.headingId as (KnownGroupTag | "parameter");
|
label: "parent",
|
||||||
const label = "" + input.value;
|
data_value: {
|
||||||
const id = parseInt(label);
|
kind: "tool",
|
||||||
switch (tag) {
|
args: {
|
||||||
case "ToolSlot":
|
tool_id: parseInt("" + value)
|
||||||
case "GenericPointer":
|
|
||||||
case "Plant":
|
|
||||||
const p = findPointerByTypeAndId(index, tag, id);
|
|
||||||
if (p && p.body.id) {
|
|
||||||
return {
|
|
||||||
kind: "point",
|
|
||||||
args: { pointer_type: tag, pointer_id: p.body.id }
|
|
||||||
};
|
|
||||||
} else {
|
|
||||||
return bail("Bad point_id: " + JSON.stringify(p));
|
|
||||||
}
|
}
|
||||||
case "Tool":
|
}
|
||||||
const tool_id = findToolById(index, id)
|
}
|
||||||
.body
|
});
|
||||||
.id || bail("No id");
|
|
||||||
return { kind: "tool", args: { tool_id } };
|
const pointVar =
|
||||||
case "identifier":
|
(pointer_type: "Plant" | "GenericPointer", value: string | number): VariableDeclaration => ({
|
||||||
return { kind: "identifier", args: { label } };
|
kind: "variable_declaration",
|
||||||
case "parameter":
|
args: {
|
||||||
// AUTHOR'S NOTE: At the time of writing, the only parameter supported
|
label: "parent",
|
||||||
// is `parent` which is always has a `data_type` of `point`. This will
|
data_value: {
|
||||||
// need to be updated later.
|
kind: "point",
|
||||||
const data_type = "point";
|
args: { pointer_type, pointer_id: parseInt("" + value) }
|
||||||
return { kind: "parameter_declaration", args: { label, data_type } };
|
}
|
||||||
default:
|
}
|
||||||
return EMPTY_COORD;
|
});
|
||||||
|
|
||||||
|
const manualEntry: VariableDeclaration = {
|
||||||
|
kind: "variable_declaration",
|
||||||
|
args: {
|
||||||
|
label: "parent",
|
||||||
|
data_value: { kind: "coordinate", args: { x: 0, y: 0, z: 0 } }
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const parentParameter: ParameterDeclaration = {
|
||||||
|
kind: "parameter_declaration",
|
||||||
|
args: { label: "parent", data_type: "point" }
|
||||||
|
};
|
||||||
|
const createNewParent =
|
||||||
|
(_index: ResourceIndex, input: DropDownItem): ScopeDeclarationBodyItem | undefined => {
|
||||||
|
switch (input.headingId) {
|
||||||
|
case "Plant":
|
||||||
|
case "GenericPointer": return pointVar(input.headingId, input.value);
|
||||||
|
case "Tool": return toolVar(input.value);
|
||||||
|
case "parameter": return parentParameter; // Caller decides X/Y/Z
|
||||||
|
case "Other": return manualEntry;
|
||||||
|
}
|
||||||
|
return undefined;
|
||||||
|
};
|
||||||
|
|
||||||
|
export let handleSelect =
|
||||||
|
(index: ResourceIndex, input: DropDownItem): ScopeDeclaration => {
|
||||||
|
const sd: ScopeDeclaration =
|
||||||
|
({ kind: "scope_declaration", args: {}, body: [] });
|
||||||
|
const parent = createNewParent(index, input);
|
||||||
|
parent && sd.body /** lol */ && sd.body.push(parent);
|
||||||
|
return sd;
|
||||||
|
};
|
||||||
|
|
|
@ -1,13 +1,12 @@
|
||||||
import * as React from "react";
|
import * as React from "react";
|
||||||
import { generateList, PARENT_DDI } from "./generate_list";
|
import { generateList, PARENT_DDI } from "./generate_list";
|
||||||
import { handleSelect } from "./handle_select";
|
|
||||||
import { formatSelectedDropdown } from "./format_selected_dropdown";
|
import { formatSelectedDropdown } from "./format_selected_dropdown";
|
||||||
import { TileMoveAbsProps } from "./interfaces";
|
import { TileMoveAbsProps } from "./interfaces";
|
||||||
import { FBSelect, DropDownItem } from "../../../ui/index";
|
import { FBSelect, DropDownItem } from "../../../ui/index";
|
||||||
import { Feature } from "../../../devices/interfaces";
|
import { Feature } from "../../../devices/interfaces";
|
||||||
|
|
||||||
export function TileMoveAbsSelect(props: TileMoveAbsProps) {
|
export function TileMoveAbsSelect(props: TileMoveAbsProps) {
|
||||||
const { selectedItem, resources, onChange, shouldDisplay } = props;
|
const { selectedItem, resources, shouldDisplay } = props;
|
||||||
const i = selectedItem;
|
const i = selectedItem;
|
||||||
const additionalItems: DropDownItem[] =
|
const additionalItems: DropDownItem[] =
|
||||||
shouldDisplay(Feature.variables) ? PARENT_DDI : [];
|
shouldDisplay(Feature.variables) ? PARENT_DDI : [];
|
||||||
|
@ -15,9 +14,7 @@ export function TileMoveAbsSelect(props: TileMoveAbsProps) {
|
||||||
allowEmpty={true}
|
allowEmpty={true}
|
||||||
list={generateList(resources, additionalItems)}
|
list={generateList(resources, additionalItems)}
|
||||||
selectedItem={formatSelectedDropdown(resources, i)}
|
selectedItem={formatSelectedDropdown(resources, i)}
|
||||||
onChange={(x: DropDownItem) => {
|
onChange={(_x: DropDownItem) => {
|
||||||
const y = handleSelect(resources, x);
|
console.error("RE-write this!");
|
||||||
// This guard is only to please the type checker. -RC 10 Aug 18
|
|
||||||
(y.kind !== "parameter_declaration") && onChange(y);
|
|
||||||
}} />;
|
}} />;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue