import * as React from "react"; import { FormattedPlantInfo } from "./map_state_to_props"; import { round } from "../map/util"; import { history } from "../../history"; import { FBSelect, DropDownItem, BlurableInput, Row, Col } from "../../ui"; import { PlantOptions } from "../interfaces"; import { PlantStage } from "farmbot"; import { Moment } from "moment"; import moment from "moment"; import { Actions } from "../../constants"; import { Link } from "../../link"; import { DesignerPanelContent } from "./designer_panel"; import { parseIntInput } from "../../util"; import { startCase } from "lodash"; import { t } from "../../i18next_wrapper"; import { TimeSettings } from "../../interfaces"; export interface PlantPanelProps { info: FormattedPlantInfo; onDestroy(uuid: string): void; updatePlant(uuid: string, update: PlantOptions): void; inSavedGarden: boolean; dispatch: Function; timeSettings?: TimeSettings; } export const PLANT_STAGES: DropDownItem[] = [ { value: "planned", label: t("Planned") }, { value: "planted", label: t("Planted") }, { value: "sprouted", label: t("Sprouted") }, { value: "harvested", label: t("Harvested") }, ]; export const PLANT_STAGES_DDI = { [PLANT_STAGES[0].value]: { label: PLANT_STAGES[0].label, value: PLANT_STAGES[0].value }, [PLANT_STAGES[1].value]: { label: PLANT_STAGES[1].label, value: PLANT_STAGES[1].value }, [PLANT_STAGES[2].value]: { label: PLANT_STAGES[2].label, value: PLANT_STAGES[2].value }, [PLANT_STAGES[3].value]: { label: PLANT_STAGES[3].label, value: PLANT_STAGES[3].value }, }; interface EditPlantProperty { uuid: string; updatePlant(uuid: string, update: PlantOptions): void; } export interface EditPlantStatusProps extends EditPlantProperty { plantStatus: PlantStage; } export function EditPlantStatus(props: EditPlantStatusProps) { const { plantStatus, updatePlant, uuid } = props; return { const plant_stage = e.value as PlantStage; const update: PlantOptions = { plant_stage }; switch (plant_stage) { case "planned": update.planted_at = undefined; break; case "planted": update.planted_at = moment().toISOString(); } updatePlant(uuid, update); }} />; } export interface EditDatePlantedProps extends EditPlantProperty { datePlanted: Moment; timeSettings: TimeSettings; } export const EditDatePlanted = (props: EditDatePlantedProps) => { const { datePlanted, updatePlant, uuid, timeSettings } = props; return updatePlant(uuid, { planted_at: moment(e.currentTarget.value) .utcOffset(timeSettings.utcOffset).toISOString() })} />; }; export interface EditPlantLocationProps extends EditPlantProperty { location: Record<"x" | "y", number>; } export const EditPlantLocation = (props: EditPlantLocationProps) => { const { location, updatePlant, uuid } = props; return {["x", "y"].map((axis: "x" | "y") => updatePlant(uuid, { [axis]: round(parseIntInput(e.currentTarget.value)) })} /> )} ; }; const chooseLocation = (to: Record<"x" | "y", number | undefined>) => (dispatch: Function): Promise => { dispatch({ type: Actions.CHOOSE_LOCATION, payload: { x: to.x, y: to.y, z: undefined } }); return Promise.resolve(); }; interface MoveToPlantProps { x: number; y: number; dispatch: Function; } const MoveToPlant = (props: MoveToPlantProps) => ; interface DeleteButtonsProps { destroy(): void; } const DeleteButtons = (props: DeleteButtonsProps) =>
; interface ListItemProps { name: string; children: React.ReactChild; } export const ListItem = (props: ListItemProps) =>
  • {props.name}

    {props.children}
  • ; export function PlantPanel(props: PlantPanelProps) { const { info, onDestroy, updatePlant, dispatch, inSavedGarden, timeSettings } = props; const { slug, plantedAt, daysOld, uuid, plantStatus } = info; const { x, y } = info; const destroy = () => onDestroy(uuid); return
      {startCase(slug)} {(timeSettings && !inSavedGarden) && {`${daysOld} ${t("days old")}`} } {(!inSavedGarden) ? : t(startCase(plantStatus))}
    ; }