WIP
This commit is contained in:
parent
e1e7f559a4
commit
d818eb3f59
|
@ -4,14 +4,13 @@ import { ReduxAction } from "../redux/interfaces";
|
|||
|
||||
type NetChange = ReduxAction<EdgeStatus>;
|
||||
|
||||
const change =
|
||||
(state: "up" | "down") =>
|
||||
(name: Edge, at = (new Date()).toJSON()): NetChange => {
|
||||
return {
|
||||
type: Actions.NETWORK_EDGE_CHANGE,
|
||||
payload: { name, status: { state, at } }
|
||||
};
|
||||
const change = (state: "up" | "down") =>
|
||||
(name: Edge, at = (new Date()).toJSON()): NetChange => {
|
||||
return {
|
||||
type: Actions.NETWORK_EDGE_CHANGE,
|
||||
payload: { name, status: { state, at } }
|
||||
};
|
||||
};
|
||||
|
||||
export const networkUp = change("up");
|
||||
|
||||
|
|
|
@ -128,7 +128,8 @@ describe("<FarmEventForm/>", () => {
|
|||
"repeat": "1",
|
||||
"timeUnit": "never",
|
||||
"executable_type": "Regimen",
|
||||
"executable_id": "1"
|
||||
"executable_id": "1",
|
||||
timeOffset: 0
|
||||
});
|
||||
expect(result.start_time).toContain("2017-08-01");
|
||||
expect(result.end_time).toContain("2017-08-01");
|
||||
|
|
|
@ -52,12 +52,13 @@ export interface FarmEventViewModel {
|
|||
timeUnit: string;
|
||||
executable_type: string;
|
||||
executable_id: string;
|
||||
timeOffset: number;
|
||||
}
|
||||
/** Breaks up a TaggedFarmEvent into a structure that can easily be used
|
||||
* by the edit form.
|
||||
* USE CASE EXAMPLE: We have a "date" and "time" field that are created from
|
||||
* a single "start_time" FarmEvent field. */
|
||||
function destructureFarmEvent(fe: TaggedFarmEvent): FarmEventViewModel {
|
||||
function destructureFarmEvent(fe: TaggedFarmEvent, timeOffset: number): FarmEventViewModel {
|
||||
|
||||
return {
|
||||
startDate: formatDate((fe.body.start_time).toString()),
|
||||
|
@ -67,18 +68,21 @@ function destructureFarmEvent(fe: TaggedFarmEvent): FarmEventViewModel {
|
|||
repeat: (fe.body.repeat || 1).toString(),
|
||||
timeUnit: fe.body.time_unit,
|
||||
executable_type: fe.body.executable_type,
|
||||
executable_id: (fe.body.executable_id || "").toString()
|
||||
executable_id: (fe.body.executable_id || "").toString(),
|
||||
timeOffset
|
||||
};
|
||||
}
|
||||
|
||||
type PartialFE = Partial<TaggedFarmEvent["body"]>;
|
||||
|
||||
/** Take a FormViewModel and recombine the fields into a Partial<FarmEvent>
|
||||
* that can be used to apply updates (such as a PUT request to the API). */
|
||||
export function recombine(vm: FarmEventViewModel): Partial<TaggedFarmEvent["body"]> {
|
||||
export function recombine(vm: FarmEventViewModel): PartialFE {
|
||||
// Make sure that `repeat` is set to `never` when dealing with regimens.
|
||||
const isReg = vm.executable_type === "Regimen";
|
||||
return {
|
||||
start_time: moment(vm.startDate + " " + vm.startTime).toISOString(),
|
||||
end_time: moment(vm.endDate + " " + vm.endTime).toISOString(),
|
||||
start_time: offsetTime(vm.startDate, vm.startTime, vm.timeOffset),
|
||||
end_time: offsetTime(vm.endDate, vm.endTime, vm.timeOffset),
|
||||
repeat: parseInt(vm.repeat, 10) || 1,
|
||||
time_unit: (isReg ? "never" : vm.timeUnit) as TimeUnit,
|
||||
executable_id: parseInt(vm.executable_id, 10),
|
||||
|
@ -86,6 +90,10 @@ export function recombine(vm: FarmEventViewModel): Partial<TaggedFarmEvent["body
|
|||
};
|
||||
}
|
||||
|
||||
function offsetTime(date: string, time: string, offset: number): string {
|
||||
return moment(`${date} ${time}`).utcOffset(offset).toISOString();
|
||||
}
|
||||
|
||||
export interface EditFEProps {
|
||||
deviceTimezone: string | undefined;
|
||||
executableOptions: DropDownItem[];
|
||||
|
|
Loading…
Reference in a new issue