Update Action interfaces to use Actions enum;
parent
1d0c56437c
commit
6dafdaed7e
|
@ -16,22 +16,25 @@ import { EditResourceParams } from "./interfaces";
|
||||||
import { ResourceIndex } from "../resources/interfaces";
|
import { ResourceIndex } from "../resources/interfaces";
|
||||||
import { SequenceBodyItem } from "farmbot/dist";
|
import { SequenceBodyItem } from "farmbot/dist";
|
||||||
import * as _ from "lodash";
|
import * as _ from "lodash";
|
||||||
|
import { Actions } from "../constants";
|
||||||
|
|
||||||
export function edit(tr: TaggedResource, update: Partial<typeof tr.body>):
|
export function edit(tr: TaggedResource, changes: Partial<typeof tr.body>):
|
||||||
ReduxAction<EditResourceParams> {
|
ReduxAction<EditResourceParams> {
|
||||||
return {
|
return {
|
||||||
type: "EDIT_RESOURCE",
|
type: Actions.EDIT_RESOURCE,
|
||||||
payload: { uuid: tr.uuid, update: update }
|
payload: { uuid: tr.uuid, update: changes }
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Rather than update (patch) a TaggedResource, this method will overwrite
|
/** Rather than update (patch) a TaggedResource, this method will overwrite
|
||||||
* everything within the `.body` property. */
|
* everything within the `.body` property. */
|
||||||
export function overwrite(tr: TaggedResource, update: typeof tr.body):
|
export function overwrite(tr: TaggedResource,
|
||||||
|
changeset: typeof tr.body):
|
||||||
ReduxAction<EditResourceParams> {
|
ReduxAction<EditResourceParams> {
|
||||||
|
|
||||||
return {
|
return {
|
||||||
type: "OVERWRITE_RESOURCE",
|
type: Actions.OVERWRITE_RESOURCE,
|
||||||
payload: { uuid: tr.uuid, update: update }
|
payload: { uuid: tr.uuid, update: changeset }
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -64,7 +67,7 @@ export function init(resource: TaggedResource): ReduxAction<TaggedResource> {
|
||||||
resource.dirty = true;
|
resource.dirty = true;
|
||||||
/** Technically, this happens in the reducer, but I like to be extra safe. */
|
/** Technically, this happens in the reducer, but I like to be extra safe. */
|
||||||
resource.uuid = generateUuid(resource.body.id, resource.kind);
|
resource.uuid = generateUuid(resource.body.id, resource.kind);
|
||||||
return { type: "INIT_RESOURCE", payload: resource };
|
return { type: Actions.INIT_RESOURCE, payload: resource };
|
||||||
}
|
}
|
||||||
|
|
||||||
export function initSave(resource: TaggedResource) {
|
export function initSave(resource: TaggedResource) {
|
||||||
|
|
|
@ -282,6 +282,7 @@ export enum Actions {
|
||||||
// Config
|
// Config
|
||||||
CHANGE_API_PORT = "CHANGE_API_PORT",
|
CHANGE_API_PORT = "CHANGE_API_PORT",
|
||||||
CHANGE_API_HOST = "CHANGE_API_HOST",
|
CHANGE_API_HOST = "CHANGE_API_HOST",
|
||||||
|
LOGOUT = "LOGOUT",
|
||||||
|
|
||||||
// Devices
|
// Devices
|
||||||
TOGGLE_CONTROL_PANEL_OPTION = "TOGGLE_CONTROL_PANEL_OPTION",
|
TOGGLE_CONTROL_PANEL_OPTION = "TOGGLE_CONTROL_PANEL_OPTION",
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
import { draggableReducer } from "../reducer";
|
import { draggableReducer } from "../reducer";
|
||||||
import { DraggableState } from "../interfaces";
|
import { DraggableState } from "../interfaces";
|
||||||
|
import { Actions } from "../../constants";
|
||||||
|
|
||||||
describe("draggableReducer", () => {
|
describe("draggableReducer", () => {
|
||||||
function emptyState(): DraggableState {
|
function emptyState(): DraggableState {
|
||||||
|
@ -20,7 +21,7 @@ describe("draggableReducer", () => {
|
||||||
|
|
||||||
it("puts a step", () => {
|
it("puts a step", () => {
|
||||||
let payload = { uuid: "FOO" };
|
let payload = { uuid: "FOO" };
|
||||||
let action = { type: "PUT_DATA_XFER", payload };
|
let action = { type: Actions.PUT_DATA_XFER, payload };
|
||||||
let nextState = draggableReducer(emptyState(), action);
|
let nextState = draggableReducer(emptyState(), action);
|
||||||
let dt = nextState.dataTransfer;
|
let dt = nextState.dataTransfer;
|
||||||
expect(Object.keys(dt)).toContain(payload.uuid);
|
expect(Object.keys(dt)).toContain(payload.uuid);
|
||||||
|
@ -30,9 +31,9 @@ describe("draggableReducer", () => {
|
||||||
|
|
||||||
it("drops a step", () => {
|
it("drops a step", () => {
|
||||||
let payload = "BAR";
|
let payload = "BAR";
|
||||||
let action = { type: "DROP_DATA_XFER", payload };
|
let action = { type: Actions.DROP_DATA_XFER, payload };
|
||||||
let nextState = draggableReducer(emptyState(), action);
|
let nextState = draggableReducer(emptyState(), action);
|
||||||
expect(Object.keys(nextState.dataTransfer).length)
|
expect(Object.keys(nextState.dataTransfer).length)
|
||||||
.toEqual(0);
|
.toEqual(0);
|
||||||
});
|
});
|
||||||
})
|
});
|
||||||
|
|
|
@ -4,6 +4,7 @@ import { SequenceBodyItem as Step } from "farmbot";
|
||||||
import { Everything } from "../interfaces";
|
import { Everything } from "../interfaces";
|
||||||
import { ReduxAction } from "../redux/interfaces";
|
import { ReduxAction } from "../redux/interfaces";
|
||||||
import * as React from "react";
|
import * as React from "react";
|
||||||
|
import { Actions } from "../constants";
|
||||||
export const STEP_DATATRANSFER_IDENTIFER = "farmbot/sequence-step";
|
export const STEP_DATATRANSFER_IDENTIFER = "farmbot/sequence-step";
|
||||||
|
|
||||||
/** SIDE EFFECT-Y!! Stores a step into state.draggable.dataTransfer and
|
/** SIDE EFFECT-Y!! Stores a step into state.draggable.dataTransfer and
|
||||||
|
@ -17,7 +18,7 @@ export function stepPut(value: Step,
|
||||||
let uuid = id();
|
let uuid = id();
|
||||||
ev.dataTransfer.setData(STEP_DATATRANSFER_IDENTIFER, uuid);
|
ev.dataTransfer.setData(STEP_DATATRANSFER_IDENTIFER, uuid);
|
||||||
return {
|
return {
|
||||||
type: "PUT_DATA_XFER",
|
type: Actions.PUT_DATA_XFER,
|
||||||
payload: {
|
payload: {
|
||||||
intent,
|
intent,
|
||||||
uuid,
|
uuid,
|
||||||
|
@ -25,7 +26,7 @@ export function stepPut(value: Step,
|
||||||
draggerId
|
draggerId
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
};
|
}
|
||||||
|
|
||||||
/** Used by a React component reacting to a "drop" event. Takes a UUID and looks
|
/** Used by a React component reacting to a "drop" event. Takes a UUID and looks
|
||||||
* for a step stored in store.draggable.data_transfer. Removes it from the store
|
* for a step stored in store.draggable.data_transfer. Removes it from the store
|
||||||
|
|
|
@ -1,10 +1,11 @@
|
||||||
import { Everything } from "../interfaces";
|
import { Everything } from "../interfaces";
|
||||||
import { Store } from "redux";
|
import { Store } from "redux";
|
||||||
|
import { Actions } from "../constants";
|
||||||
|
|
||||||
export type Store = Store<Everything>;
|
export type Store = Store<Everything>;
|
||||||
|
|
||||||
export interface ReduxAction<T> {
|
export interface ReduxAction<T> {
|
||||||
readonly type: string;
|
readonly type: Actions;
|
||||||
readonly payload: T;
|
readonly payload: T;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -5,8 +5,9 @@ import { draggableReducer as draggable } from "../draggable/reducer";
|
||||||
import { combineReducers } from "redux";
|
import { combineReducers } from "redux";
|
||||||
import { ReduxAction } from "./interfaces";
|
import { ReduxAction } from "./interfaces";
|
||||||
import { Session } from "../session";
|
import { Session } from "../session";
|
||||||
import { resourceReducer as resources } from "../resources/reducer"
|
import { resourceReducer as resources } from "../resources/reducer";
|
||||||
import { Everything } from "../interfaces";
|
import { Everything } from "../interfaces";
|
||||||
|
import { Actions } from "../constants";
|
||||||
|
|
||||||
export let reducers = combineReducers({
|
export let reducers = combineReducers({
|
||||||
auth,
|
auth,
|
||||||
|
@ -21,10 +22,10 @@ export function rootReducer(
|
||||||
/** Sorry for the `any` here. */
|
/** Sorry for the `any` here. */
|
||||||
state: any,
|
state: any,
|
||||||
action: ReduxAction<{}>) {
|
action: ReduxAction<{}>) {
|
||||||
if (action.type === "LOGOUT") {
|
if (action.type === Actions.LOGOUT) {
|
||||||
Session.clear(true);
|
Session.clear(true);
|
||||||
}
|
}
|
||||||
// TODO: Get rid of this nasty type case / hack. Resulted from TSC 2.4 upgrade
|
// TODO: Get rid of this nasty type case / hack. Resulted from TSC 2.4 upgrade
|
||||||
// - RC 30 JUN 17
|
// - RC 30 JUN 17
|
||||||
return reducers(state, action) as Everything;
|
return reducers(state, action) as Everything;
|
||||||
};
|
}
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
|
|
||||||
import { regimensReducer } from "../reducer";
|
import { regimensReducer } from "../reducer";
|
||||||
|
import { Actions } from "../../constants";
|
||||||
|
|
||||||
const STATE = {
|
const STATE = {
|
||||||
"dailyOffsetMs": 300000,
|
"dailyOffsetMs": 300000,
|
||||||
|
@ -17,12 +18,12 @@ const STATE = {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
};
|
||||||
|
|
||||||
describe("Regimens reducer", () => {
|
describe("Regimens reducer", () => {
|
||||||
it("initializes", () => {
|
it("initializes", () => {
|
||||||
const ACTION = { type: "TOGGLE_DAY", payload: { week: 0, day: 4 } };
|
const ACTION = { type: Actions.TOGGLE_DAY, payload: { week: 0, day: 4 } };
|
||||||
let nextState = regimensReducer(STATE, ACTION);
|
let nextState = regimensReducer(STATE, ACTION);
|
||||||
expect(nextState.weeks[0].days["day4"]).toBeFalsy();
|
expect(nextState.weeks[0].days["day4"]).toBeFalsy();
|
||||||
})
|
});
|
||||||
})
|
});
|
||||||
|
|
|
@ -7,6 +7,7 @@ import { assertUuid, findSequence, findRegimen } from "../../resources/selectors
|
||||||
import { groupRegimenItemsByWeek } from "./group_regimen_items_by_week";
|
import { groupRegimenItemsByWeek } from "./group_regimen_items_by_week";
|
||||||
import { defensiveClone } from "../../util";
|
import { defensiveClone } from "../../util";
|
||||||
import { overwrite } from "../../api/crud";
|
import { overwrite } from "../../api/crud";
|
||||||
|
import { Actions } from "../../constants";
|
||||||
|
|
||||||
export function pushWeek() {
|
export function pushWeek() {
|
||||||
return {
|
return {
|
||||||
|
@ -27,7 +28,7 @@ export function setTimeOffset(ms: number) {
|
||||||
throw new Error("Bad time input on regimen page: " + JSON.stringify(ms));
|
throw new Error("Bad time input on regimen page: " + JSON.stringify(ms));
|
||||||
} else {
|
} else {
|
||||||
return { type: "SET_TIME_OFFSET", payload: ms };
|
return { type: "SET_TIME_OFFSET", payload: ms };
|
||||||
};
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export function toggleDay({ week, day }: ToggleDayParams) {
|
export function toggleDay({ week, day }: ToggleDayParams) {
|
||||||
|
@ -42,11 +43,11 @@ export function toggleDay({ week, day }: ToggleDayParams) {
|
||||||
|
|
||||||
export function setSequence(uuid: string): ReduxAction<string> {
|
export function setSequence(uuid: string): ReduxAction<string> {
|
||||||
assertUuid("sequences", uuid);
|
assertUuid("sequences", uuid);
|
||||||
return { type: "SET_SEQUENCE", payload: uuid };
|
return { type: Actions.SET_SEQUENCE, payload: uuid };
|
||||||
};
|
}
|
||||||
|
|
||||||
export function commitBulkEditor(): Thunk {
|
export function commitBulkEditor(): Thunk {
|
||||||
return function(dispatch, getState) {
|
return function (dispatch, getState) {
|
||||||
let res = getState().resources;
|
let res = getState().resources;
|
||||||
let { weeks, dailyOffsetMs, selectedSequenceUUID, currentRegimen } =
|
let { weeks, dailyOffsetMs, selectedSequenceUUID, currentRegimen } =
|
||||||
res.consumers.regimens;
|
res.consumers.regimens;
|
||||||
|
|
|
@ -56,7 +56,7 @@ export class SequenceEditorMiddleActive
|
||||||
pushStep(xfer.value, dispatch, sequence);
|
pushStep(xfer.value, dispatch, sequence);
|
||||||
} else {
|
} else {
|
||||||
pushStep(xfer.value, dispatch, sequence);
|
pushStep(xfer.value, dispatch, sequence);
|
||||||
};
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
let isSaving = sequence.saving;
|
let isSaving = sequence.saving;
|
||||||
|
|
|
@ -20,7 +20,6 @@
|
||||||
],
|
],
|
||||||
"no-invalid-this": true,
|
"no-invalid-this": true,
|
||||||
"no-switch-case-fall-through": true,
|
"no-switch-case-fall-through": true,
|
||||||
"no-string-literal": true,
|
|
||||||
"no-eval": true,
|
"no-eval": true,
|
||||||
"no-any": true,
|
"no-any": true,
|
||||||
"no-duplicate-variable": true,
|
"no-duplicate-variable": true,
|
||||||
|
|
Loading…
Reference in New Issue