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

84 lines
2.9 KiB
TypeScript
Raw Normal View History

2019-08-23 15:18:28 -06:00
import * as React from "react";
import { connect } from "react-redux";
import {
2020-02-28 09:35:32 -07:00
DesignerPanel, DesignerPanelHeader, DesignerPanelContent,
2019-12-10 13:09:52 -07:00
} from "../designer_panel";
2019-08-23 15:18:28 -06:00
import { t } from "../../i18next_wrapper";
import { history, getPathArray } from "../../history";
2019-11-07 12:17:50 -07:00
import { Panel } from "../panel_header";
2019-08-23 15:18:28 -06:00
import { Everything } from "../../interfaces";
2019-11-07 12:17:50 -07:00
import { TaggedGenericPointer } from "farmbot";
2020-02-07 16:05:16 -07:00
import { maybeFindGenericPointerById } from "../../resources/selectors";
2019-11-07 12:17:50 -07:00
import { Actions } from "../../constants";
import {
2020-02-28 09:35:32 -07:00
EditPointProperties, updatePoint, PointActions,
2019-11-07 12:17:50 -07:00
} from "./point_edit_actions";
2020-04-13 13:24:38 -06:00
import { ListItem } from "../plants/plant_panel";
2019-09-16 08:55:02 -06:00
2019-08-23 15:18:28 -06:00
export interface EditPointProps {
dispatch: Function;
2019-11-07 12:17:50 -07:00
findPoint(id: number): TaggedGenericPointer | undefined;
2019-08-23 15:18:28 -06:00
}
export const mapStateToProps = (props: Everything): EditPointProps => ({
dispatch: props.dispatch,
2020-02-07 16:05:16 -07:00
findPoint: id => maybeFindGenericPointerById(props.resources.index, id),
2019-08-23 15:18:28 -06:00
});
2019-09-19 13:09:00 -06:00
export class RawEditPoint extends React.Component<EditPointProps, {}> {
2019-08-23 15:18:28 -06:00
get stringyID() { return getPathArray()[4] || ""; }
get point() {
if (this.stringyID) {
return this.props.findPoint(parseInt(this.stringyID));
}
}
2019-11-07 12:17:50 -07:00
get panelName() { return "point-info"; }
get backTo() { return "/app/designer/points"; }
2019-08-23 15:18:28 -06:00
2020-02-28 09:35:17 -07:00
render() {
!this.point && history.push(this.backTo);
2019-11-07 12:17:50 -07:00
return <DesignerPanel panelName={this.panelName} panel={Panel.Points}>
2019-08-23 15:18:28 -06:00
<DesignerPanelHeader
2019-11-07 12:17:50 -07:00
panelName={this.panelName}
2019-10-25 09:33:33 -06:00
panel={Panel.Points}
2019-11-20 12:48:55 -07:00
title={t("Edit point")}
2019-11-07 12:17:50 -07:00
backTo={this.backTo}
onBack={() => this.props.dispatch({
type: Actions.TOGGLE_HOVERED_POINT, payload: undefined
2019-12-26 13:20:10 -07:00
})} />
2019-11-07 12:17:50 -07:00
<DesignerPanelContent panelName={this.panelName}>
2020-02-28 09:35:17 -07:00
{this.point
? <div className={"point-panel-content-wrapper"}>
<EditPointProperties point={this.point}
updatePoint={updatePoint(this.point, this.props.dispatch)} />
2020-04-13 13:24:38 -06:00
<ul className="meta">
{Object.entries(this.point.body.meta).map(([key, value]) => {
switch (key) {
case "color":
case "created_by":
2020-04-13 19:15:11 -06:00
case "removal_method":
2020-04-13 13:24:38 -06:00
case "type":
return <div key={key}
className={`meta-${key}-not-displayed`} />;
default:
return <ListItem key={key} name={key}>
{value || ""}
</ListItem>;
}
})}
</ul>
2020-02-28 09:35:17 -07:00
<PointActions
x={this.point.body.x}
y={this.point.body.y}
z={this.point.body.z}
uuid={this.point.uuid}
dispatch={this.props.dispatch} />
</div>
: <span>{t("Redirecting")}...</span>}
2019-08-23 15:18:28 -06:00
</DesignerPanelContent>
</DesignerPanel>;
}
}
2019-09-19 13:09:00 -06:00
export const EditPoint = connect(mapStateToProps)(RawEditPoint);