[UNSTABLE] Saves, but breaks inconsistency checking.

pull/613/head
Rick Carlino 2018-01-10 16:28:22 -06:00
parent 6413cd1579
commit 6ba7a6d5df
8 changed files with 20 additions and 11 deletions

View File

@ -32,8 +32,8 @@ FarmBot::Application.routes.draw do
put "/password_resets" => "password_resets#update", as: :whatever
put "/users/verify/:token" => "users#verify", as: :users_verify
# Make life easier on API users by not adding special rules for singular
# resources. Otherwise methods like `save()` on the frontend would need to
# keep track of an `isSingular` property, which I would prefer to not do.
# resources.
# Might be safe to remove now with the advent of TaggerResource.kind
get "/device/:id" => "devices#show", as: :get_device_redirect
get "/export_data" => "devices#dump", as: :dump_device
put "/device/:id" => "devices#update", as: :put_device_redirect

View File

@ -115,6 +115,8 @@ export class API {
get logsPath() { return `${this.baseUrl}/api/logs/`; }
/** /api/webcam_feed */
get webcamFeedPath() { return `${this.baseUrl}/api/webcam_feeds/`; }
/** /api/webcam_feed */
get webAppConfigPath() { return `${this.baseUrl}/api/web_app_config/`; }
/** /api/users/verify/:token */
verificationPath = (token: string) => ("/api/users/verify/" + token);
}

View File

@ -215,7 +215,8 @@ export function urlFor(tag: ResourceName) {
Device: API.current.devicePath,
Image: API.current.imagesPath,
Log: API.current.logsPath,
WebcamFeed: API.current.webcamFeedPath
WebcamFeed: API.current.webcamFeedPath,
WebAppConfig: API.current.webAppConfigPath
};
const url = OPTIONS[tag];
if (url) {
@ -226,6 +227,8 @@ export function urlFor(tag: ResourceName) {
}
}
const SINGULAR_RESOURCE: ResourceName[] = ["WebAppConfig"];
/** Shared functionality in create() and update(). */
function updateViaAjax(payl: AjaxUpdatePayload) {
const { uuid, statusBeforeError, dispatch, index } = payl;
@ -235,7 +238,9 @@ function updateViaAjax(payl: AjaxUpdatePayload) {
let url = urlFor(kind);
if (body.id) {
verb = "put";
url += body.id;
if (!SINGULAR_RESOURCE.includes(payl.uuid.split(".")[0] as ResourceName)) {
url += body.id;
}
} else {
verb = "post";
}

View File

@ -29,8 +29,9 @@ export function setBoolViaRedux(key: BooleanConfigKey, val: boolean) {
if (conf) {
store.dispatch(edit(conf, { [key]: val }));
store.dispatch(save(conf.uuid));
return val;
} else {
throw new Error("Impossible?");
console.log("Be concerned.");
debugger;
}
return val;
}

View File

@ -12,7 +12,6 @@ import { mount } from "enzyme";
import { Move } from "../move";
import { bot } from "../../__test_support__/fake_state/bot";
import { MoveProps } from "../interfaces";
import { Actions } from "../../constants";
import { Session } from "../../session";
describe("<Move />", () => {
@ -75,10 +74,6 @@ describe("<Move />", () => {
// tslint:disable-next-line:no-any
const instance = wrapper.instance() as any;
instance.toggle_encoder_data("raw_encoders")();
expect(p.dispatch).toHaveBeenCalledWith({
type: Actions.DISPLAY_ENCODER_DATA,
payload: "raw_encoders"
});
expect(Session.invertBool).toHaveBeenCalledWith("raw_encoders");
});
});

View File

@ -125,6 +125,7 @@ export let resourceReducer = generateReducer
case "Tool":
case "User":
case "WebcamFeed":
case "WebAppConfig":
reindexResource(s.index, resource);
dontTouchThis(resource);
s.index.references[resource.uuid] = resource;
@ -151,6 +152,7 @@ export let resourceReducer = generateReducer
case "Tool":
case "User":
case "WebcamFeed":
case "WebAppConfig":
case "Image":
removeFromIndex(s.index, resource);
break;

View File

@ -554,5 +554,7 @@ export function getWebAppConfig(i: ResourceIndex): TaggedWebAppConfig | undefine
const conf = i.references[i.byKind.WebAppConfig[0] || "NO"];
if (conf && conf.kind === "WebAppConfig") {
return conf;
} else {
// debugger;
}
}

View File

@ -13,6 +13,7 @@ import { ResourceName } from "../resources/tagged_resources";
import { User } from "../auth/interfaces";
import { HttpData } from "../util";
import { WebcamFeed } from "../controls/interfaces";
import { WebAppConfig } from "../config_storage/web_app_configs";
export interface ResourceReadyPayl {
name: ResourceName;
@ -38,6 +39,7 @@ export function fetchSyncData(dispatch: Function) {
fetch<User>("User", API.current.usersPath);
fetch<DeviceAccountSettings>("Device", API.current.devicePath);
fetch<WebcamFeed>("WebcamFeed", API.current.webcamFeedPath);
fetch<WebAppConfig>("WebAppConfig", API.current.webAppConfigPath);
fetch<FarmEvent[]>("FarmEvent", API.current.farmEventsPath);
fetch<Image[]>("Image", API.current.imagesPath);
fetch<Log[]>("Log", API.current.logsPath);