import * as React from "react"; import { t } from "../../../i18next_wrapper"; import { DaySelection, EqCriteriaSelection, SubCriteriaSection, NumberCriteriaSelection, LocationSelection, togglePointTypeCriteria, } from "."; import { GroupCriteriaProps, GroupPointCountBreakdownProps, GroupCriteriaState, DEFAULT_CRITERIA, ClearCriteriaProps, ClearPointIdsProps, POINTER_TYPES, PointerType, PointTypeSelectionProps, } from "./interfaces"; import { ToggleButton } from "../../../controls/toggle_button"; import { Popover } from "@blueprintjs/core"; import { selectPoint } from "../../map/actions"; import { FBSelect, Checkbox, Help } from "../../../ui"; import { POINTER_TYPE_LIST, POINTER_TYPE_DDI_LOOKUP, isPointType, validPointTypes, setSelectionPointType, } from "../../plants/select_plants"; import { ToolTips } from "../../../constants"; import { overwriteGroup } from "../actions"; import { sortGroupBy } from "../point_group_sort"; import { PointGroupItem } from "../point_group_item"; import { Feature } from "../../../devices/interfaces"; import { TaggedPoint } from "farmbot"; export const CRITERIA_POINT_TYPE_LOOKUP = (): Record => ({ Plant: t("Plants"), GenericPointer: t("Points"), Weed: t("Weeds"), ToolSlot: t("Slots"), }); export class GroupCriteria extends React.Component { state: GroupCriteriaState = { advanced: false, clearCount: 0, dayChanged: false }; componentDidMount() { const { pointer_type } = this.props.group.body.criteria.string_eq; this.props.dispatch(setSelectionPointType(validPointTypes(pointer_type))); } AdvancedToggleMenu = () =>
this.setState({ advanced: !this.state.advanced })} />
changeDay = (state: boolean) => this.setState({ dayChanged: state }); render() { const { group, dispatch, slugs } = this.props; const { criteria } = group.body; const commonProps = { group, criteria, dispatch }; const dayProps = { dayChanged: this.state.dayChanged, changeDay: this.changeDay, advanced: this.state.advanced, }; const pointTypes = validPointTypes(criteria.string_eq.pointer_type) || []; return
{!this.state.advanced ?
{!pointTypes.includes("ToolSlot") && }
:
{...commonProps} type={"string"} eqCriteria={criteria.string_eq} criteriaKey={"string_eq"} /> {...commonProps} type={"number"} eqCriteria={criteria.number_eq} criteriaKey={"number_eq"} />
}
; } } /** Reset all group criteria to defaults. */ const ClearCriteria = (props: ClearCriteriaProps) => ; /** Clear manually selected points. */ const ClearPointIds = (props: ClearPointIdsProps) => ; /** Show counts of manual and criteria selections. */ export const GroupPointCountBreakdown = (props: GroupPointCountBreakdownProps) => { const manuallyAddedIds = props.group.body.point_ids; const sortedPoints = sortGroupBy(props.group.body.sort_type, props.pointsSelectedByGroup); const manualPoints = sortedPoints .filter(p => manuallyAddedIds.includes(p.body.id || 0)); const criteriaPoints = sortedPoints .filter(p => !manuallyAddedIds.includes(p.body.id || 0)); const generatePointIcons = (point: TaggedPoint) => ; return

{`${manualPoints.length} ${t("manually selected")}`}

{props.iconDisplay && manualPoints.length > 0 &&
{manualPoints.map(generatePointIcons)}
} {props.shouldDisplay(Feature.criteria_groups) &&

{`${criteriaPoints.length} ${t("selected by filters")}`}

{props.iconDisplay && criteriaPoints.length > 0 &&
{criteriaPoints.map(generatePointIcons)}
}
}
; }; /** Select pointer_type string equal criteria, * which determines if any additional criteria is shown. */ export const PointTypeSelection = (props: PointTypeSelectionProps) =>

{t("Select all")}

{ if (isPointType(ddi.value)) { props.dispatch(togglePointTypeCriteria(props.group, ddi.value, true)); props.dispatch(setSelectionPointType([ddi.value])); } }} /> {props.pointTypes.length > 1 && POINTER_TYPES.map(pointerType =>
props.dispatch(togglePointTypeCriteria(props.group, pointerType))} checked={props.pointTypes.includes(pointerType)} title={CRITERIA_POINT_TYPE_LOOKUP()[pointerType]} />

{CRITERIA_POINT_TYPE_LOOKUP()[pointerType]}

)}
;