2019-08-06 14:58:00 -06:00
|
|
|
import React from "react";
|
2020-02-07 16:05:16 -07:00
|
|
|
import { TaggedPointGroup, TaggedPoint } from "farmbot";
|
2019-08-06 14:58:00 -06:00
|
|
|
import { t } from "../../i18next_wrapper";
|
2020-02-07 16:05:16 -07:00
|
|
|
import { pointsSelectedByGroup } from "./criteria";
|
2020-04-02 10:53:55 -06:00
|
|
|
import { ErrorBoundary } from "../../error_boundary";
|
|
|
|
import { DevSettings } from "../../account/dev/dev_support";
|
|
|
|
import { destroy } from "../../api/crud";
|
2019-08-06 14:58:00 -06:00
|
|
|
|
2020-02-07 16:05:16 -07:00
|
|
|
export interface GroupInventoryItemProps {
|
2019-08-06 14:58:00 -06:00
|
|
|
group: TaggedPointGroup;
|
2020-02-07 16:05:16 -07:00
|
|
|
allPoints: TaggedPoint[];
|
2019-08-06 14:58:00 -06:00
|
|
|
hovered: boolean;
|
|
|
|
dispatch: Function;
|
|
|
|
onClick(): void;
|
|
|
|
}
|
|
|
|
|
|
|
|
export function GroupInventoryItem(props: GroupInventoryItemProps) {
|
2020-04-02 10:53:55 -06:00
|
|
|
const { group } = props;
|
|
|
|
const delMode = DevSettings.quickDeleteEnabled();
|
2019-08-06 14:58:00 -06:00
|
|
|
return <div
|
2020-04-02 10:53:55 -06:00
|
|
|
onClick={delMode ? () => props.dispatch(destroy(group.uuid)) : props.onClick}
|
|
|
|
className={["group-search-item",
|
|
|
|
props.hovered ? "hovered" : "",
|
|
|
|
delMode ? "quick-del" : ""].join(" ")}>
|
2019-10-09 06:55:30 -06:00
|
|
|
<span className="group-search-item-name">
|
2020-04-02 10:53:55 -06:00
|
|
|
{group.body.name}
|
2019-08-06 14:58:00 -06:00
|
|
|
</span>
|
2020-04-02 10:53:55 -06:00
|
|
|
<ErrorBoundary fallback={<i className="group-item-count">{t("? items")}</i>}>
|
|
|
|
<GroupItemCount group={group} allPoints={props.allPoints} />
|
|
|
|
</ErrorBoundary>
|
2019-08-06 14:58:00 -06:00
|
|
|
</div>;
|
|
|
|
}
|
2020-04-02 10:53:55 -06:00
|
|
|
|
|
|
|
interface GroupItemCountProps {
|
|
|
|
group: TaggedPointGroup;
|
|
|
|
allPoints: TaggedPoint[];
|
|
|
|
}
|
|
|
|
|
|
|
|
const GroupItemCount = (props: GroupItemCountProps) => {
|
|
|
|
const count = pointsSelectedByGroup(props.group, props.allPoints).length;
|
|
|
|
return <i className="group-item-count">
|
|
|
|
{t("{{count}} items", { count })}
|
|
|
|
</i>;
|
|
|
|
};
|