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