From 75a780a033b638e055c8de3f2f4f7a7a6a9f640e Mon Sep 17 00:00:00 2001 From: gabrielburnworth Date: Wed, 1 Aug 2018 18:27:19 -0700 Subject: [PATCH] misc refactoring --- .../components/hardware_settings/motors.tsx | 113 +++++++-------- webpack/farm_designer/map/drag_helpers.tsx | 69 +++++---- .../plants/__tests__/create_points_test.tsx | 12 +- .../farm_designer/plants/create_points.tsx | 134 ++++++++++-------- 4 files changed, 168 insertions(+), 160 deletions(-) diff --git a/webpack/devices/components/hardware_settings/motors.tsx b/webpack/devices/components/hardware_settings/motors.tsx index 10778ec07..c912ac5da 100644 --- a/webpack/devices/components/hardware_settings/motors.tsx +++ b/webpack/devices/components/hardware_settings/motors.tsx @@ -14,6 +14,23 @@ import { McuInputBox } from "../mcu_input_box"; import { minFwVersionCheck } from "../../../util"; import { StepsPerMmSettings } from "./steps_per_mm_settings"; +const SingleSettingRow = + ({ label, tooltip, settingType, children }: { + label: string, + tooltip: string, + children: React.ReactChild, + settingType: "button" | "input", + }) => + + + + + + {settingType === "button" + ? {children} + : {children}} + ; + export function Motors(props: MotorsProps) { const { dispatch, firmwareVersion, sourceFbosConfig, controlPanelState, @@ -30,35 +47,23 @@ export function Motors(props: MotorsProps) { name={"motors"} dispatch={dispatch} /> - - - - - - - - - - - - - - - - dispatch( - settingToggle("param_e_stop_on_mov_err", sourceFwConfig))} /> - - + + + + + dispatch( + settingToggle("param_e_stop_on_mov_err", sourceFwConfig))} /> + - - - - - - - dispatch( - settingToggle("movement_secondary_motor_x", sourceFwConfig))} /> - - - - - - - - - dispatch( - settingToggle("movement_secondary_motor_invert_x", sourceFwConfig))} /> - - + + dispatch( + settingToggle("movement_secondary_motor_x", sourceFwConfig))} /> + + + dispatch( + settingToggle("movement_secondary_motor_invert_x", sourceFwConfig))} /> + ; } diff --git a/webpack/farm_designer/map/drag_helpers.tsx b/webpack/farm_designer/map/drag_helpers.tsx index ce8296cb9..7a9124386 100644 --- a/webpack/farm_designer/map/drag_helpers.tsx +++ b/webpack/farm_designer/map/drag_helpers.tsx @@ -19,42 +19,41 @@ enum Line { Down = 270, } +function getAlignment( + activeXYZ: BotPosition | undefined, + plantXYZ: BotPosition, + swappedXY: Boolean +): Alignment { + if (activeXYZ && !isUndefined(activeXYZ.x) && !isUndefined(activeXYZ.y)) { + // Plant editing (dragging) is occuring + const activeXY = { x: round(activeXYZ.x), y: round(activeXYZ.y) }; + if (activeXY.x == plantXYZ.x && activeXY.y == plantXYZ.y) { + return Alignment.BOTH; + } + if (activeXY.x == plantXYZ.x) { + return swappedXY ? Alignment.HORIZONTAL : Alignment.VERTICAL; + } + if (activeXY.y == plantXYZ.y) { + return swappedXY ? Alignment.VERTICAL : Alignment.HORIZONTAL; + } + } + return Alignment.NONE; +} + +function rotationArray(alignment: Alignment): number[] { + switch (alignment) { + case (Alignment.HORIZONTAL): + return [Line.Left, Line.Right]; + case (Alignment.VERTICAL): + return [Line.Up, Line.Down]; + case (Alignment.BOTH): + return [Line.Left, Line.Right, Line.Up, Line.Down]; + default: + return []; + } +} + export function DragHelpers(props: DragHelpersProps) { - - function getAlignment( - activeXYZ: BotPosition | undefined, - plantXYZ: BotPosition, - swappedXY: Boolean - ): Alignment { - if (activeXYZ && !isUndefined(activeXYZ.x) && !isUndefined(activeXYZ.y)) { - // Plant editing (dragging) is occuring - const activeXY = { x: round(activeXYZ.x), y: round(activeXYZ.y) }; - if (activeXY.x == plantXYZ.x && activeXY.y == plantXYZ.y) { - return Alignment.BOTH; - } - if (activeXY.x == plantXYZ.x) { - return swappedXY ? Alignment.HORIZONTAL : Alignment.VERTICAL; - } - if (activeXY.y == plantXYZ.y) { - return swappedXY ? Alignment.VERTICAL : Alignment.HORIZONTAL; - } - } - return Alignment.NONE; - } - - function rotationArray(alignment: Alignment): number[] { - switch (alignment) { - case (Alignment.HORIZONTAL): - return [Line.Left, Line.Right]; - case (Alignment.VERTICAL): - return [Line.Up, Line.Down]; - case (Alignment.BOTH): - return [Line.Left, Line.Right, Line.Up, Line.Down]; - default: - return []; - } - } - const { dragging, plant, zoomLvl, activeDragXY, mapTransformProps, plantAreaOffset } = props; diff --git a/webpack/farm_designer/plants/__tests__/create_points_test.tsx b/webpack/farm_designer/plants/__tests__/create_points_test.tsx index 45737ab6d..700cbffdf 100644 --- a/webpack/farm_designer/plants/__tests__/create_points_test.tsx +++ b/webpack/farm_designer/plants/__tests__/create_points_test.tsx @@ -67,8 +67,11 @@ describe("", () => { it("changes color", () => { const p = fakeProps(); p.currentPoint = { cx: 0, cy: 0, r: 0 }; - const wrapper = shallow(); - wrapper.find("ColorPicker").simulate("change", "red"); + const wrapper = mount(); + // tslint:disable-next-line:no-any + const instance = wrapper.instance() as any; + const component = shallow(); + component.find("ColorPicker").simulate("change", "red"); expect(p.dispatch).toHaveBeenCalledWith({ payload: { color: "red", cx: 0, cy: 0, r: 0 }, type: Actions.SET_CURRENT_POINT_DATA @@ -79,7 +82,10 @@ describe("", () => { const p = fakeProps(); p.currentPoint = { cx: 0, cy: 0, r: 0 }; const wrapper = shallow(); - wrapper.find("BlurableInput").first().simulate("commit", { + // tslint:disable-next-line:no-any + const instance = wrapper.instance() as any; + const component = shallow(); + component.find("BlurableInput").first().simulate("commit", { currentTarget: { value: "10" } }); expect(p.dispatch).toHaveBeenCalledWith({ diff --git a/webpack/farm_designer/plants/create_points.tsx b/webpack/farm_designer/plants/create_points.tsx index 9a69f81f6..251c7b16b 100644 --- a/webpack/farm_designer/plants/create_points.tsx +++ b/webpack/farm_designer/plants/create_points.tsx @@ -119,8 +119,76 @@ export class CreatePoints this.cancel(); } - render() { + PointProperties = () => { const { cx, cy, r, color } = this.state; + return + + + + + + + + + + + + + + + + + ; + } + + PointActions = () => + + + + + + + DeleteAllPoints = () => + +
+ +

{t("Delete all of the points created through this panel.")}

+ +
+
+ + render() { return
@@ -134,67 +202,9 @@ export class CreatePoints
- - - - - - - - - - - - - - - - - - - - - - - - -
- -

{t("Delete all of the points created through this panel.")}

- -
-
+ + +
; }