Farmbot-Web-App/frontend/farm_designer/point_groups/group_list_panel.tsx

81 lines
2.7 KiB
TypeScript
Raw Normal View History

2019-08-06 14:00:58 -06:00
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";
2019-08-23 15:18:28 -06:00
import {
2020-02-28 09:35:32 -07:00
DesignerPanel, DesignerPanelTop, DesignerPanelContent,
2019-12-10 13:09:52 -07:00
} from "../designer_panel";
2019-08-06 14:00:58 -06:00
import { findAll } from "../../resources/find_all";
2020-02-07 16:05:16 -07:00
import { TaggedPointGroup, TaggedPoint } from "farmbot";
2019-08-06 14:58:00 -06:00
import { history } from "../../history";
import { GroupInventoryItem } from "./group_inventory_item";
2020-04-13 13:24:38 -06:00
import {
EmptyStateWrapper, EmptyStateGraphic,
} from "../../ui/empty_state_wrapper";
2019-08-23 15:18:28 -06:00
import { Content } from "../../constants";
2020-02-07 16:05:16 -07:00
import { selectAllActivePoints } from "../../resources/selectors";
2020-04-13 13:24:38 -06:00
import { createGroup } from "./actions";
2020-04-13 19:15:11 -06:00
import { SearchField } from "../../ui/search_field";
2019-08-06 14:00:58 -06:00
2019-08-23 15:18:28 -06:00
export interface GroupListPanelProps {
2019-08-06 14:00:58 -06:00
dispatch: Function;
groups: TaggedPointGroup[];
2020-02-07 16:05:16 -07:00
allPoints: TaggedPoint[];
2019-08-06 14:00:58 -06:00
}
interface State {
searchTerm: string;
}
2019-09-09 07:23:28 -06:00
export function mapStateToProps(props: Everything): GroupListPanelProps {
2020-02-07 16:05:16 -07:00
return {
groups: findAll<TaggedPointGroup>(props.resources.index, "PointGroup"),
dispatch: props.dispatch,
allPoints: selectAllActivePoints(props.resources.index)
};
2019-08-06 14:00:58 -06:00
}
2020-04-13 13:24:38 -06:00
export class RawGroupListPanel
extends React.Component<GroupListPanelProps, State> {
2019-08-06 14:00:58 -06:00
state: State = { searchTerm: "" };
2019-08-20 10:02:36 -06:00
navigate = (id: number) => history.push(`/app/designer/groups/${id}`);
2019-08-06 14:00:58 -06:00
render() {
2019-10-25 09:33:33 -06:00
return <DesignerPanel panelName={"groups"} panel={Panel.Groups}>
2019-08-06 14:00:58 -06:00
<DesignerNavTabs />
<DesignerPanelTop
panel={Panel.Groups}
2020-04-13 13:24:38 -06:00
onClick={() => this.props.dispatch(createGroup({ pointUuids: [] }))}
2020-02-20 19:38:50 -07:00
title={t("Add group")}>
2020-04-13 19:15:11 -06:00
<SearchField searchTerm={this.state.searchTerm}
placeholder={t("Search your groups...")}
onChange={searchTerm => this.setState({ searchTerm })} />
2019-08-06 14:00:58 -06:00
</DesignerPanelTop>
<DesignerPanelContent panelName={"groups"}>
2019-08-23 15:18:28 -06:00
<EmptyStateWrapper
notEmpty={this.props.groups.length > 0}
title={t("No groups yet.")}
text={t(Content.NO_GROUPS)}
colorScheme="groups"
2019-09-09 10:10:08 -06:00
graphic={EmptyStateGraphic.groups}>
2019-08-23 15:18:28 -06:00
{this.props.groups
.filter(p => p.body.name.toLowerCase()
.includes(this.state.searchTerm.toLowerCase()))
.map(group => <GroupInventoryItem
key={group.uuid}
group={group}
2020-02-07 16:05:16 -07:00
allPoints={this.props.allPoints}
2019-08-23 15:18:28 -06:00
hovered={false}
dispatch={this.props.dispatch}
onClick={() => this.navigate(group.body.id || 0)}
/>)}
</EmptyStateWrapper>
2019-08-06 14:00:58 -06:00
</DesignerPanelContent>
</DesignerPanel>;
}
}
2019-09-19 13:09:00 -06:00
export const GroupListPanel = connect(mapStateToProps)(RawGroupListPanel);