import React from "react"; import { connect } from "react-redux"; import { DesignerPanel, DesignerPanelTop, DesignerPanelContent, } from "../designer_panel"; import { DesignerNavTabs, Panel, TAB_COLOR } from "../panel_header"; import { EmptyStateWrapper, EmptyStateGraphic, } from "../../ui/empty_state_wrapper"; import { t } from "../../i18next_wrapper"; import { TaggedTool, TaggedToolSlotPointer, TaggedSensor } from "farmbot"; import { Content } from "../../constants"; import { history } from "../../history"; import { Row, Col, Help } from "../../ui"; import { botPositionLabel } from "../map/layers/farmbot/bot_position_label"; import { Link } from "../../link"; import { edit, save } from "../../api/crud"; import { readPin } from "../../devices/actions"; import { isBotOnlineFromState } from "../../devices/must_be_online"; import { setToolHover, ToolSlotSVG, ToolSVG, } from "../map/layers/tool_slots/tool_graphics"; import { ToolSelection } from "./tool_slot_edit_components"; import { error } from "../../toast/toast"; import { hasUTM } from "../../devices/components/firmware_hardware_support"; import { ToolsProps, ToolsState } from "./interfaces"; import { mapStateToProps } from "./state_to_props"; import { BotOriginQuadrant } from "../interfaces"; import { mapPointClickAction } from "../map/actions"; import { getMode } from "../map/util"; import { Mode } from "../map/interfaces"; import { SearchField } from "../../ui/search_field"; const toolStatus = (value: number | undefined): string => { switch (value) { case 1: return t("disconnected"); case 0: return t("connected"); default: return t("unknown"); } }; export class RawTools extends React.Component { state: ToolsState = { searchTerm: "" }; getToolName = (toolId: number | undefined): string | undefined => { const foundTool = this.props.tools.filter(tool => tool.body.id === toolId)[0]; return foundTool ? foundTool.body.name : undefined; }; get mountedToolId() { return this.props.device.body.mounted_tool_id; } get mountedTool() { return this.props.findTool(this.mountedToolId || 0); } get toolVerificationPin() { const toolVerificationSensor = this.props.sensors.filter(sensor => sensor.body.label.toLowerCase() .includes("tool verification"))[0] as TaggedSensor | undefined; return toolVerificationSensor ? toolVerificationSensor.body.pin || 63 : 63; } get pins() { return this.props.bot.hardware.pins; } get toolVerificationValue() { const pinData = this.pins[this.toolVerificationPin]; return pinData ? pinData.value : undefined; } get arduinoBusy() { return !!this.props.bot.hardware.informational_settings.busy; } get botOnline() { return isBotOnlineFromState(this.props.bot); } get noUTM() { return !hasUTM(this.props.firmwareHardware); } MountedToolInfo = () =>
{ this.props.dispatch(edit(this.props.device, { mounted_tool_id: tool_id })); this.props.dispatch(save(this.props.device.uuid)); }} isActive={this.props.isActive} filterSelectedTool={true} filterActiveTools={false} />

{t("status")}: {toolStatus(this.toolVerificationValue)}

ToolSlots = () =>
{this.props.toolSlots .filter(p => (this.getToolName(p.body.tool_id) || "").toLowerCase() .includes(this.state.searchTerm.toLowerCase())) .map(toolSlot => )}
Tools = () =>
{this.props.tools .filter(tool => !tool.body.name || tool.body.name && tool.body.name.toLowerCase() .includes(this.state.searchTerm.toLowerCase())) .filter(tool => tool.body.id) .map(tool => )}
get strings() { return { placeholder: this.noUTM ? t("Search your seed containers...") : t("Search your tools..."), titleText: this.noUTM ? t("Add a seed container") : t("Add a tool or seed container"), emptyStateText: this.noUTM ? Content.NO_SEED_CONTAINERS : Content.NO_TOOLS, tools: this.noUTM ? t("seed containers") : t("tools and seed containers"), toolSlots: t("slots"), addSlot: t("Add slot"), }; } render() { const panelName = "tools"; const hasTools = this.props.tools.length > 0; return this.setState({ searchTerm })} /> {!this.noUTM && } ; } } export interface ToolSlotInventoryItemProps { toolSlot: TaggedToolSlotPointer; tools: TaggedTool[]; hovered: boolean; dispatch: Function; isActive(id: number | undefined): boolean; xySwap: boolean; quadrant: BotOriginQuadrant; hideDropdown?: boolean; } export const ToolSlotInventoryItem = (props: ToolSlotInventoryItemProps) => { const { x, y, z, id, tool_id, gantry_mounted } = props.toolSlot.body; const toolName = props.tools .filter(tool => tool.body.id == tool_id)[0]?.body.name; return
{ if (getMode() == Mode.boxSelect) { mapPointClickAction(props.dispatch, props.toolSlot.uuid)(); props.dispatch(setToolHover(undefined)); } else { history.push(`/app/designer/tool-slots/${id}`); } }} onMouseEnter={() => props.dispatch(setToolHover(props.toolSlot.uuid))} onMouseLeave={() => props.dispatch(setToolHover(undefined))}> {props.hideDropdown ? {toolName || t("Empty")} :
e.stopPropagation()}> tool.body.id == tool_id)[0]} onChange={update => { props.dispatch(edit(props.toolSlot, update)); props.dispatch(save(props.toolSlot.uuid)); }} isActive={props.isActive} filterSelectedTool={false} filterActiveTools={true} />
}

{botPositionLabel({ x, y, z }, gantry_mounted)}

; }; interface ToolInventoryItemProps { toolName: string; toolId: number | undefined; mounted: boolean; active: boolean; } const ToolInventoryItem = (props: ToolInventoryItemProps) => { const activeText = props.active ? t("in slot") : t("inactive"); return
history.push(`/app/designer/tools/${props.toolId}`)}>

{t(props.toolName)}

{props.mounted ? t("mounted") : activeText}

; }; export const Tools = connect(mapStateToProps)(RawTools);