[STABLE] Removing confusing selector
parent
c260d843e7
commit
11d1b887e8
|
@ -89,34 +89,6 @@ export let findSlotByToolId = (index: ResourceIndex, tool_id: number) => {
|
|||
}
|
||||
};
|
||||
|
||||
/** I dislike this method. */
|
||||
export function findToolBySlotId(input: ResourceIndex):
|
||||
TaggedTool | undefined {
|
||||
if (JSON.parse("true")) {
|
||||
throw new Error("This method does not actually find tools by slot id...");
|
||||
}
|
||||
const wow = input
|
||||
.byKind
|
||||
.Point
|
||||
.map(x => input.references[x])
|
||||
.map((x) => {
|
||||
if (x
|
||||
&& (x.kind === "Point")
|
||||
&& x.body.pointer_type === "ToolSlot"
|
||||
&& x.body.tool_id) {
|
||||
return maybeFindToolById(input, x.body.tool_id);
|
||||
} else {
|
||||
return undefined;
|
||||
}
|
||||
})
|
||||
.filter(x => x)[0];
|
||||
if (wow && wow.kind === "Tool") {
|
||||
return wow;
|
||||
} else {
|
||||
return undefined;
|
||||
}
|
||||
}
|
||||
|
||||
/** Unlike other findById methods, this one allows undefined (missed) values */
|
||||
export function maybeFindPlantById(index: ResourceIndex, id: number) {
|
||||
const uuid = index.byKindAndId[joinKindAndId("Point", id)];
|
||||
|
|
|
@ -18,8 +18,9 @@ import {
|
|||
TaggedPeripheral,
|
||||
TaggedWebAppConfig,
|
||||
TaggedFirmwareConfig,
|
||||
TaggedToolSlotPointer,
|
||||
} from "./tagged_resources";
|
||||
import { sortResourcesById } from "../util";
|
||||
import { sortResourcesById, betterCompact } from "../util";
|
||||
import { error } from "farmbot-toastr";
|
||||
import { assertUuid } from "./selectors";
|
||||
|
||||
|
@ -67,6 +68,15 @@ export const selectAllLogs = (i: ResourceIndex) => findAll<TaggedLog>(i, "Log");
|
|||
export const selectAllPeripherals =
|
||||
(i: ResourceIndex) => findAll<TaggedPeripheral>(i, "Peripheral");
|
||||
export const selectAllPoints = (i: ResourceIndex) => findAll<TaggedPoint>(i, "Point");
|
||||
|
||||
export const selectAllToolSlots = (i: ResourceIndex): TaggedToolSlotPointer[] => {
|
||||
return betterCompact(selectAllPoints(i)
|
||||
.map((x): TaggedToolSlotPointer | undefined => {
|
||||
const y = x.body; // Hack around TS taggedUnion issues (I think).
|
||||
return (y.pointer_type === "ToolSlot") ? { ...x, body: y } : undefined;
|
||||
}));
|
||||
};
|
||||
|
||||
export const selectAllRegimens = (i: ResourceIndex) => findAll<TaggedRegimen>(i, "Regimen");
|
||||
export const selectAllSensors = (i: ResourceIndex) => findAll<TaggedSensor>(i, "Sensor");
|
||||
export const selectAllSequences = (i: ResourceIndex) => findAll<TaggedSequence>(i, "Sequence");
|
||||
|
|
|
@ -5,7 +5,7 @@ import { dropDownName, PARENT_DDI } from "./generate_list";
|
|||
import {
|
||||
findToolById,
|
||||
findPointerByTypeAndId,
|
||||
findToolBySlotId
|
||||
maybeFindToolById
|
||||
} from "../../../resources/selectors";
|
||||
import { Point, Tool } from "farmbot/dist";
|
||||
|
||||
|
@ -32,7 +32,7 @@ function point(ri: ResourceIndex, ld: Point): DropDownItem {
|
|||
let label: string;
|
||||
switch (p.pointer_type) {
|
||||
case "ToolSlot":
|
||||
const tool = p.tool_id && findToolBySlotId(ri);
|
||||
const tool = maybeFindToolById(ri, p.tool_id);
|
||||
label = dropDownName(p.pointer_type,
|
||||
tool ? ("using " + tool.body.name) : "no tool",
|
||||
{ x: p.x, y: p.y, z: p.z });
|
||||
|
|
Loading…
Reference in New Issue