bulk scheduler bulk days selection
parent
dbb541efa1
commit
a411fcfebf
|
@ -311,6 +311,8 @@ export enum Actions {
|
|||
// Regimens
|
||||
PUSH_WEEK = "PUSH_WEEK",
|
||||
POP_WEEK = "POP_WEEK",
|
||||
DESELECT_ALL_DAYS = "DESELECT_ALL_DAYS",
|
||||
SELECT_ALL_DAYS = "SELECT_ALL_DAYS",
|
||||
TOGGLE_DAY = "TOGGLE_DAY",
|
||||
SELECT_REGIMEN = "SELECT_REGIMEN",
|
||||
SET_SEQUENCE = "SET_SEQUENCE",
|
||||
|
|
|
@ -14,7 +14,7 @@ const STATE = {
|
|||
"day4": true,
|
||||
"day5": true,
|
||||
"day6": true,
|
||||
"day7": true
|
||||
"day7": false
|
||||
}
|
||||
}
|
||||
]
|
||||
|
@ -27,3 +27,35 @@ describe("Regimens reducer", () => {
|
|||
expect(nextState.weeks[0].days["day4"]).toBeFalsy();
|
||||
});
|
||||
});
|
||||
|
||||
describe("selectDays()", () => {
|
||||
it("selects all days", () => {
|
||||
const ACTION = { type: Actions.SELECT_ALL_DAYS, payload: undefined };
|
||||
let nextState = regimensReducer(STATE, ACTION);
|
||||
expect(nextState.weeks[0].days["day7"]).toBeTruthy();
|
||||
});
|
||||
});
|
||||
|
||||
describe("deselectDays()", () => {
|
||||
it("deselects all days", () => {
|
||||
const ACTION = { type: Actions.DESELECT_ALL_DAYS, payload: undefined };
|
||||
let nextState = regimensReducer(STATE, ACTION);
|
||||
expect(nextState.weeks[0].days["day6"]).toBeFalsy();
|
||||
});
|
||||
});
|
||||
|
||||
describe("pushWeek()", () => {
|
||||
it("add a week", () => {
|
||||
const ACTION = { type: Actions.PUSH_WEEK, payload: undefined };
|
||||
let nextState = regimensReducer(STATE, ACTION);
|
||||
expect(nextState.weeks.length).toEqual(2);
|
||||
});
|
||||
});
|
||||
|
||||
describe("popWeek()", () => {
|
||||
it("remove a week", () => {
|
||||
const ACTION = { type: Actions.POP_WEEK, payload: undefined };
|
||||
let nextState = regimensReducer(STATE, ACTION);
|
||||
expect(nextState.weeks.length).toEqual(0);
|
||||
});
|
||||
});
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
let mockErr = jest.fn();
|
||||
jest.mock("i18next", () => ({ t: (i: string) => i }))
|
||||
jest.mock("i18next", () => ({ t: (i: string) => i }));
|
||||
jest.mock("farmbot-toastr", () => ({ error: mockErr }));
|
||||
|
||||
import { commitBulkEditor } from "../actions";
|
||||
|
|
|
@ -2,7 +2,7 @@ import { isNaN, isNumber } from "lodash";
|
|||
import { t } from "i18next";
|
||||
import { error, warning } from "farmbot-toastr";
|
||||
import { ReduxAction, Thunk } from "../../redux/interfaces";
|
||||
import { ToggleDayParams } from "./interfaces";
|
||||
import { ToggleDayParams, Week } from "./interfaces";
|
||||
import { assertUuid, findSequence, findRegimen } from "../../resources/selectors";
|
||||
import { groupRegimenItemsByWeek } from "./group_regimen_items_by_week";
|
||||
import { defensiveClone } from "../../util";
|
||||
|
@ -21,6 +21,18 @@ export function popWeek() {
|
|||
};
|
||||
}
|
||||
|
||||
export function deselectDays() {
|
||||
return {
|
||||
type: "DESELECT_ALL_DAYS"
|
||||
};
|
||||
}
|
||||
|
||||
export function selectDays() {
|
||||
return {
|
||||
type: "SELECT_ALL_DAYS"
|
||||
};
|
||||
}
|
||||
|
||||
/** Sets daily offset of a regimen */
|
||||
export function setTimeOffset(ms: number) {
|
||||
if (isNaN(ms) || !isNumber(ms)) {
|
||||
|
|
|
@ -47,7 +47,7 @@ export interface SequenceListProps {
|
|||
export interface WeekGridProps {
|
||||
weeks: Week[];
|
||||
dispatch: Function;
|
||||
};
|
||||
}
|
||||
|
||||
export interface WeekRowProps {
|
||||
week: Week;
|
||||
|
@ -62,4 +62,3 @@ export interface DayProps {
|
|||
id: string;
|
||||
active: boolean;
|
||||
}
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import * as React from "react";
|
||||
import { WeekRow } from "./week_row";
|
||||
import { WeekGridProps } from "./interfaces";
|
||||
import { pushWeek, popWeek } from "./actions";
|
||||
import { pushWeek, popWeek, deselectDays, selectDays } from "./actions";
|
||||
import { t } from "i18next";
|
||||
import { Row, Col } from "../../ui/index";
|
||||
|
||||
|
@ -26,7 +26,15 @@ export function WeekGrid({ weeks, dispatch }: WeekGridProps) {
|
|||
onClick={() => dispatch(popWeek())}>
|
||||
<i className="fa fa-minus" /> {t("Week")}
|
||||
</button>
|
||||
<button className="gray widget-control fb-button"
|
||||
onClick={() => dispatch(deselectDays())}>
|
||||
{t("Deselect all")}
|
||||
</button>
|
||||
<button className="gray widget-control fb-button"
|
||||
onClick={() => dispatch(selectDays())}>
|
||||
{t("Select all")}
|
||||
</button>
|
||||
</Col>
|
||||
</Row>
|
||||
</div>;
|
||||
};
|
||||
</div >;
|
||||
}
|
||||
|
|
|
@ -63,6 +63,32 @@ export let regimensReducer = generateReducer<RegimenState>(initialState)
|
|||
s.weeks.pop();
|
||||
return s;
|
||||
})
|
||||
.add<void>(Actions.DESELECT_ALL_DAYS, (s, a) => {
|
||||
let newWeeks: Week[];
|
||||
newWeeks = Object.assign([], s.weeks);
|
||||
newWeeks.map(function (week, i) {
|
||||
let neww: Week[];
|
||||
[1, 2, 3, 4, 5, 6, 7].map(function (day) {
|
||||
let lookup = `day${day}`;
|
||||
(week.days as { [day: string]: boolean })[lookup] = false;
|
||||
});
|
||||
});
|
||||
s.weeks = newWeeks;
|
||||
return s;
|
||||
})
|
||||
.add<void>(Actions.SELECT_ALL_DAYS, (s, a) => {
|
||||
let newWeeks: Week[];
|
||||
newWeeks = Object.assign([], s.weeks);
|
||||
newWeeks.map(function (week, i) {
|
||||
let neww: Week[];
|
||||
[1, 2, 3, 4, 5, 6, 7].map(function (day) {
|
||||
let lookup = `day${day}`;
|
||||
(week.days as { [day: string]: boolean })[lookup] = true;
|
||||
});
|
||||
});
|
||||
s.weeks = newWeeks;
|
||||
return s;
|
||||
})
|
||||
.add<{ week: number, day: number }>(Actions.TOGGLE_DAY, (s, { payload }) => {
|
||||
let week = s.weeks[payload.week];
|
||||
let day = `day${payload.day}`;
|
||||
|
|
Loading…
Reference in New Issue