groups FE updates

pull/1131/head
gabrielburnworth 2019-03-13 12:05:54 -07:00
parent 0d45dd79c9
commit 4a53ca3203
10 changed files with 35 additions and 14 deletions

View File

@ -64,6 +64,7 @@ export enum Feature {
sensors = "sensors",
change_ownership = "change_ownership",
variables = "variables",
loops = "loops",
api_pin_bindings = "api_pin_bindings",
farmduino_k14 = "farmduino_k14",
jest_feature = "jest_feature", // for tests

View File

@ -60,7 +60,8 @@ describe("determineDropdown", () => {
kind: "parameter_application",
args: {
label: "x",
data_value: { kind: "every_point", args: { every_point_type: "Plant" } }
// tslint:disable-next-line:no-any
data_value: { kind: "every_point", args: { every_point_type: "Plant" } } as any
}
}, buildResourceIndex([]).index);
expect(r.label).toBe("All plants");

View File

@ -12,6 +12,7 @@ import {
formatPoint, safeEveryPointType, everyPointDDI, NO_VALUE_SELECTED_DDI
} from "../sequences/locals_list/location_form_list";
import { VariableNode } from "../sequences/locals_list/locals_list_support";
import { EveryPointShape } from "../sequences/locals_list/handle_select";
export interface SequenceMeta {
celeryNode: VariableNode;
@ -65,8 +66,9 @@ export const determineDropdown =
return { label: `Coordinate (${x}, ${y}, ${z})`, value: "?" };
case "identifier":
return { label: capitalize(data_value.args.label), value: "?" };
case "every_point":
const { every_point_type } = data_value.args;
// tslint:disable-next-line:no-any
case "every_point" as any:
const { every_point_type } = (data_value as unknown as EveryPointShape).args;
return everyPointDDI(safeEveryPointType(every_point_type));
case "point":
const { pointer_id, pointer_type } = data_value.args;

View File

@ -96,7 +96,8 @@ describe("convertDDItoDeclaration()", () => {
label: "label",
data_value: {
kind: "every_point", args: { every_point_type: "Plant" }
}
// tslint:disable-next-line:no-any
} as any
}
};
expect(variable).toEqual(expected);

View File

@ -12,7 +12,7 @@ import {
LocationFormProps, PARENT, AllowedVariableNodes
} from "../locals_list_support";
import { difference } from "lodash";
import { locationFormList } from "../location_form_list";
import { locationFormList, everyPointDDI } from "../location_form_list";
import { convertDDItoVariable } from "../handle_select";
describe("<LocationForm/>", () => {
@ -85,4 +85,13 @@ describe("<LocationForm/>", () => {
const wrapper = shallow(<LocationForm {...p} />);
expect(wrapper.find(FBSelect).first().props().list).not.toContain(PARENT);
});
it("shows groups in dropdown", () => {
const p = fakeProps();
p.shouldDisplay = () => true;
p.disallowGroups = false;
const wrapper = shallow(<LocationForm {...p} />);
expect(wrapper.find(FBSelect).first().props().list)
.toContainEqual(everyPointDDI("Tool"));
});
});

View File

@ -9,7 +9,6 @@ import {
Identifier,
Point,
Tool,
EveryPoint,
ScopeDeclarationBodyItem,
VariableDeclaration,
PointType,
@ -25,6 +24,12 @@ import { betterCompact } from "../../util";
// tslint:disable-next-line:no-any
export const NOTHING_SELECTED: any = { kind: "nothing", args: {} };
export interface EveryPointShape {
kind: "every_point";
args: { every_point_type: PointType; }
}
// tslint:disable-next-line:no-any
type EveryPoint = any;
type DataValue = Coordinate | Identifier | Point | Tool | EveryPoint;
type CreateVariableDeclaration =

View File

@ -76,7 +76,8 @@ export const LocationForm =
const isDisabled = !determineEditable(celeryNode);
const variableListItems = (props.shouldDisplay(Feature.variables) &&
allowedVariableNodes !== AllowedVariableNodes.variable) ? [PARENT] : [];
const list = locationFormList(resources, variableListItems, !disallowGroups);
const displayGroups = props.shouldDisplay(Feature.loops) && !disallowGroups;
const list = locationFormList(resources, variableListItems, displayGroups);
/** Variable name. */
const { label } = celeryNode.args;
const editableVariable = defensiveClone(celeryNode);

View File

@ -4,9 +4,8 @@ import {
selectAllActivePoints
} from "../../resources/selectors";
import { betterCompact } from "../../util";
import { TaggedTool, TaggedPoint } from "farmbot";
import { TaggedTool, TaggedPoint, Vector3 } from "farmbot";
import { DropDownItem } from "../../ui";
import { Vector3 } from "farmbot/dist";
import { t } from "i18next";
import { capitalize } from "lodash";
import { joinKindAndId } from "../../resources/reducer_support";

View File

@ -135,12 +135,14 @@ describe("<TileMoveAbsolute/>", () => {
it("does not handle every_point nodes", () => {
const p = fakeProps();
const block = ordinaryMoveAbs(p);
const data_value = {
kind: "every_point",
args: { every_point_type: "Plant" }
// tslint:disable-next-line:no-any
} as any;
const boom = () => block.updateLocation({
kind: "parameter_application",
args: {
label: "parent",
data_value: { kind: "every_point", args: { every_point_type: "Plant" } }
}
args: { label: "parent", data_value }
});
expect(boom).toThrowError("Can't put `every_point` into `move_abs");
});

View File

@ -45,7 +45,7 @@ export class TileMoveAbsolute extends React.Component<StepParams, MoveAbsState>
/** Handle changes to step.args.location. */
updateLocation = (variable: ParameterApplication) => {
const location = variable.args.data_value;
if (location.kind === "every_point") {
if (location.kind === "every_point" as unknown) {
throw new Error("Can't put `every_point` into `move_abs");
} else {
this.updateArgs({ location });