import * as React from "react"; import { connect } from "react-redux"; import { Everything } from "../../interfaces"; import { Panel, DesignerNavTabs } from "../panel_header"; import { t } from "../../i18next_wrapper"; import { DesignerPanel, DesignerPanelTop, DesignerPanelContent } from "../designer_panel"; import { findAll } from "../../resources/find_all"; import { TaggedPointGroup, TaggedPoint } from "farmbot"; import { history } from "../../history"; import { GroupInventoryItem } from "./group_inventory_item"; import { EmptyStateWrapper, EmptyStateGraphic } from "../../ui/empty_state_wrapper"; import { Content } from "../../constants"; import { selectAllActivePoints } from "../../resources/selectors"; export interface GroupListPanelProps { dispatch: Function; groups: TaggedPointGroup[]; allPoints: TaggedPoint[]; } interface State { searchTerm: string; } export function mapStateToProps(props: Everything): GroupListPanelProps { return { groups: findAll(props.resources.index, "PointGroup"), dispatch: props.dispatch, allPoints: selectAllActivePoints(props.resources.index) }; } export class RawGroupListPanel extends React.Component { state: State = { searchTerm: "" }; update = ({ currentTarget }: React.SyntheticEvent) => { this.setState({ searchTerm: currentTarget.value }); } navigate = (id: number) => history.push(`/app/designer/groups/${id}`); render() { return 0} title={t("No groups yet.")} text={t(Content.NO_GROUPS)} colorScheme="groups" graphic={EmptyStateGraphic.groups}> {this.props.groups .filter(p => p.body.name.toLowerCase() .includes(this.state.searchTerm.toLowerCase())) .map(group => this.navigate(group.body.id || 0)} />)} ; } } export const GroupListPanel = connect(mapStateToProps)(RawGroupListPanel);