Skip to content

Commit

Permalink
gantry_mounted dropdown support
Browse files Browse the repository at this point in the history
  • Loading branch information
gabrielburnworth committed Jun 8, 2019
1 parent 98d1150 commit 8c65f89
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 6 deletions.
@@ -1,5 +1,10 @@
import { locationFormList, dropDownName } from "../location_form_list";
import {
locationFormList, dropDownName, formatTool
} from "../location_form_list";
import { fakeResourceIndex } from "../test_helpers";
import {
fakeToolSlot, fakeTool
} from "../../../__test_support__/fake_state/resources";

describe("locationFormList()", () => {
it("returns dropdown list", () => {
Expand Down Expand Up @@ -52,6 +57,20 @@ describe("locationFormList()", () => {
});
});

describe("formatTool()", () => {
it("returns ddi for tool", () => {
const ddi = formatTool(fakeTool(), fakeToolSlot());
expect(ddi.label).toEqual("Foo (0, 0, 0)");
});

it("returns ddi for tool when gantry mounted", () => {
const toolSlot = fakeToolSlot();
toolSlot.body.gantry_mounted = true;
const ddi = formatTool(fakeTool(), toolSlot);
expect(ddi.label).toEqual("Foo (---, 0, 0)");
});
});

describe("dropDownName()", () => {
it("returns label", () => {
const label = dropDownName("Plant 1", { x: 10, y: 20, z: 30 });
Expand All @@ -62,4 +81,10 @@ describe("dropDownName()", () => {
const label = dropDownName("", { x: 10, y: 20, z: 30 });
expect(label).toEqual("Untitled (10, 20, 30)");
});

it("returns label with undefined coordinates", () => {
const label = dropDownName("Plant 1",
{ x: undefined, y: undefined, z: undefined });
expect(label).toEqual("Plant 1 (---, ---, ---)");
});
});
17 changes: 12 additions & 5 deletions frontend/sequences/locals_list/location_form_list.ts
Expand Up @@ -6,10 +6,10 @@ import {
} from "../../resources/selectors";
import { betterCompact } from "../../util";
import {
TaggedTool, TaggedPoint, Vector3, TaggedToolSlotPointer
TaggedTool, TaggedPoint, TaggedToolSlotPointer, Xyz
} from "farmbot";
import { DropDownItem } from "../../ui";
import { capitalize } from "lodash";
import { capitalize, isNumber } from "lodash";
import { Point } from "farmbot/dist/resources/api_resources";
import { t } from "../../i18next_wrapper";

Expand Down Expand Up @@ -92,7 +92,11 @@ export const formatTool =
(tool: TaggedTool, slot: TaggedToolSlotPointer | undefined): DropDownItem => {
const { id, name } = tool.body;
const coordinate = slot
? { x: slot.body.x, y: slot.body.y, z: slot.body.z }
? {
x: slot.body.gantry_mounted ? undefined : slot.body.x,
y: slot.body.y,
z: slot.body.z
}
: undefined;
return {
label: dropDownName((name || "Untitled tool"), coordinate),
Expand All @@ -102,9 +106,12 @@ export const formatTool =
};

/** Uniformly generate a label for things that have an X/Y/Z value. */
export function dropDownName(name: string, v?: Vector3) {
export function dropDownName(name: string, v?: Record<Xyz, number | undefined>) {
let label = name || "untitled";
if (v) { label += ` (${v.x}, ${v.y}, ${v.z})`; }
if (v) {
const labelFor = (axis: number | undefined) => isNumber(axis) ? axis : "---";
label += ` (${labelFor(v.x)}, ${labelFor(v.y)}, ${labelFor(v.z)})`;
}
return capitalize(label);
}

Expand Down

0 comments on commit 8c65f89

Please sign in to comment.