Farmbot-Web-App/frontend/regimens/bulk_scheduler/index.tsx

82 lines
2.4 KiB
TypeScript
Raw Normal View History

2017-06-29 12:54:02 -06:00
import * as React from "react";
import { BulkEditorProps } from "./interfaces";
import { AddButton } from "./add_button";
import { WeekGrid } from "./week_grid";
import { commitBulkEditor, setTimeOffset, setSequence } from "./actions";
import {
2018-06-14 12:48:30 -06:00
BlurableInput, Row, Col, FBSelect, DropDownItem, NULL_CHOICE
} from "../../ui/index";
2019-02-04 13:54:17 -07:00
import moment from "moment";
2019-01-10 20:10:55 -07:00
import { isString } from "lodash";
import { betterCompact, bail } from "../../util";
2019-01-10 20:10:55 -07:00
import { msToTime, timeToMs } from "./utils";
2019-04-02 13:59:37 -06:00
import { t } from "../../i18next_wrapper";
const BAD_UUID = "WARNING: Not a sequence UUID.";
2017-06-29 12:54:02 -06:00
2018-06-14 12:48:30 -06:00
export class BulkScheduler extends React.Component<BulkEditorProps, {}> {
selected = (): DropDownItem => {
2017-08-28 05:49:13 -06:00
const s = this.props.selectedSequence;
2020-01-03 13:04:45 -07:00
return (s?.body.id)
2019-01-10 20:10:55 -07:00
? { label: s.body.name, value: s.uuid }
: NULL_CHOICE;
};
all = (): DropDownItem[] => {
return betterCompact(this.props.sequences.map(x => {
if (x.body.id) {
return { value: x.uuid, label: x.body.name };
}
}));
};
commitChange = (uuid: string) => {
this.props.dispatch(setSequence(uuid));
}
onChange = (event: DropDownItem) => {
const uuid = event.value;
2019-01-10 20:10:55 -07:00
isString(uuid) ? this.commitChange(uuid) : bail(BAD_UUID);
}
2019-01-10 20:10:55 -07:00
SequenceSelectBox = () =>
<Col xs={6}>
<div>
<label>{t("Sequence")}</label>
<FBSelect onChange={this.onChange}
selectedItem={this.selected()}
2019-04-26 10:34:36 -06:00
list={this.all()} />
2019-01-10 20:10:55 -07:00
</div>
</Col>
TimeSelection = () =>
<Col xs={6}>
<div>
<label>{t("Time")}</label>
<i className="fa fa-clock-o" onClick={() =>
this.props.dispatch(setTimeOffset(timeToMs(
moment().add(3, "minutes").format("HH:mm"))))} />
<BlurableInput type="time"
value={msToTime(this.props.dailyOffsetMs)}
onCommit={({ currentTarget }) => {
this.props.dispatch(setTimeOffset(timeToMs(currentTarget.value)));
}} />
</div>
</Col>
render() {
2019-01-10 20:10:55 -07:00
const { dispatch, weeks, sequences } = this.props;
2020-01-03 13:04:45 -07:00
const active = !!(sequences?.length);
2019-04-11 21:17:18 -06:00
return <div className="bulk-scheduler-content">
<AddButton
active={active}
2019-10-21 13:37:16 -06:00
onClick={() => dispatch(commitBulkEditor())} />
<Row>
2019-01-10 20:10:55 -07:00
<this.SequenceSelectBox />
<this.TimeSelection />
</Row>
<WeekGrid weeks={weeks} dispatch={dispatch} />
</div>;
}
2017-06-29 12:54:02 -06:00
}