import * as React from "react"; import { Row, Col, FBSelect, DropDownItem, Checkbox } from "../../../ui"; import { AddEqCriteria, editCriteria, AddNumberCriteria, editGtLtCriteriaField, removeEqCriteriaValue, clearCriteriaField, dayCriteriaEmpty, ClearCategory, } from "."; import { EqCriteriaSelectionProps, NumberCriteriaProps, LocationSelectionProps, NumberLtGtInputProps, PointGroupCriteria, DaySelectionProps, } from "./interfaces"; import { t } from "../../../i18next_wrapper"; import { ToggleButton } from "../../../controls/toggle_button"; import { Actions } from "../../../constants"; import { spaceSelected } from "../../map/layers/zones/zones"; /** Add and view string or number equal criteria. */ export class EqCriteriaSelection extends React.Component> { render() { const { eqCriteria, criteriaKey, group, dispatch } = this.props; return
group={group} dispatch={dispatch} type={this.props.type} eqCriteria={eqCriteria} criteriaKey={criteriaKey} /> {eqCriteria && Object.entries(eqCriteria) .map(([key, values]: [string, T[]], keyIndex) => values && values.length > 0 &&
{key} {values.map((value, valueIndex) => )}
)}
; } } /** Add and view > or < number criteria. */ export const NumberCriteriaSelection = (props: NumberCriteriaProps) => { const criteriaField = props.criteria[props.criteriaKey]; return
{criteriaField && Object.entries(criteriaField) .map(([key, value], keyIndex) =>

{key}

{props.criteriaKey == "number_gt" ? ">" : "<"}

{value}

)}
; }; const DAY_OPERATOR_DDI_LOOKUP = (): { [x: string]: DropDownItem } => ({ ["<"]: { label: t("Less than"), value: "<" }, [">"]: { label: t("Greater than"), value: ">" }, }); /** Edit and view day criteria. */ export const DaySelection = (props: DaySelectionProps) => { const { group, criteria, dispatch, advanced } = props; const dayCriteria = criteria.day; const noDayCriteria = !advanced && dayCriteriaEmpty(dayCriteria) && !props.dayChanged; return
{advanced ? :

{t("Age")}

} {!advanced &&
{ dispatch(editCriteria(group, { day: { op: "<", days_ago: 0 } })); props.changeDay(false); }} checked={noDayCriteria} disabled={noDayCriteria} title={t("clear age selection")} customDisabledText={t("age selection empty")} />

{t("all")}

} "]]} selectedItem={noDayCriteria ? { label: t("Select one"), value: "" } : DAY_OPERATOR_DDI_LOOKUP()[dayCriteria.op]} onChange={ddi => { dispatch(editCriteria(group, { day: { days_ago: dayCriteria.days_ago, op: ddi.value as PointGroupCriteria["day"]["op"] } })); props.changeDay(true); }} /> { const { op } = dayCriteria; const days_ago = parseInt(e.currentTarget.value); dispatch(editCriteria(group, { day: { days_ago, op } })); props.changeDay(true); }} />

{t("days old")}

; }; /** Edit number < and > criteria. */ export const NumberLtGtInput = (props: NumberLtGtInputProps) => { const { group, dispatch, criteriaKey, pointerType } = props; const gtCriteria = props.group.body.criteria.number_gt; const ltCriteria = props.group.body.criteria.number_lt; return dispatch(editGtLtCriteriaField( group, "number_gt", criteriaKey, pointerType)(e))} />

{"<"}

{criteriaKey}

{"<"}

dispatch(editGtLtCriteriaField( group, "number_lt", criteriaKey, pointerType)(e))} />
; }; /** Form inputs to define a 2D group criteria area. */ export const LocationSelection = (props: LocationSelectionProps) =>

{t("Location")}

{!spaceSelected(props.group, props.botSize) &&

{t("Invalid selection.")}

} {["x", "y"].map((axis: "x" | "y") => )}
props.dispatch({ type: Actions.EDIT_GROUP_AREA_IN_MAP, payload: !props.editGroupAreaInMap })} />
;