Farmbot-Web-App/frontend/farm_designer/points/point_inventory_item.tsx

55 lines
1.6 KiB
TypeScript
Raw Normal View History

2019-08-23 15:18:28 -06:00
import * as React from "react";
import { TaggedGenericPointer } from "farmbot";
import { Saucer } from "../../ui";
2019-11-07 12:17:50 -07:00
import { Actions } from "../../constants";
2019-08-23 15:18:28 -06:00
import { push } from "../../history";
export interface PointInventoryItemProps {
tpp: TaggedGenericPointer;
dispatch: Function;
2019-11-07 12:17:50 -07:00
hovered: boolean;
navName: "points" | "weeds";
2019-08-23 15:18:28 -06:00
}
// The individual points that show up in the farm designer sub nav.
export class PointInventoryItem extends
React.Component<PointInventoryItemProps, {}> {
render() {
const point = this.props.tpp.body;
2019-11-07 12:17:50 -07:00
const { tpp, dispatch } = this.props;
2019-08-23 15:18:28 -06:00
const pointId = (point.id || "ERR_NO_POINT_ID").toString();
2019-11-07 12:17:50 -07:00
const toggle = (action: "enter" | "leave") => {
const isEnter = action === "enter";
dispatch({
type: Actions.TOGGLE_HOVERED_POINT,
payload: isEnter ? tpp.uuid : undefined
});
};
2019-08-23 15:18:28 -06:00
const click = () => {
2019-11-07 12:17:50 -07:00
push(`/app/designer/${this.props.navName}/${pointId}`);
dispatch({ type: Actions.TOGGLE_HOVERED_POINT, payload: [tpp.uuid] });
2019-08-23 15:18:28 -06:00
};
2019-11-07 12:17:50 -07:00
// Name given from OpenFarm's API.
const label = point.name || "Unknown plant";
2019-08-23 15:18:28 -06:00
return <div
2019-11-07 12:17:50 -07:00
className={`point-search-item ${this.props.hovered ? "hovered" : ""}`}
2019-08-23 15:18:28 -06:00
key={pointId}
2019-11-07 12:17:50 -07:00
onMouseEnter={() => toggle("enter")}
onMouseLeave={() => toggle("leave")}
2019-08-23 15:18:28 -06:00
onClick={click}>
<Saucer color={point.meta.color || "green"} />
<span className="point-search-item-name">
{label}
</span>
<p className="point-search-item-info">
{`(${point.x}, ${point.y}) ⌀${point.radius * 2}`}
</p>
</div>;
}
}