Make enum names consistent in session_keys.ts
parent
c78aafb6d8
commit
894ae96b92
|
@ -114,15 +114,15 @@ export function refresh(resource: TaggedResource, urlNeedsId = false) {
|
|||
};
|
||||
}
|
||||
|
||||
function refreshStart(uuid: string): ReduxAction<string> {
|
||||
export function refreshStart(uuid: string): ReduxAction<string> {
|
||||
return { type: Actions.REFRESH_RESOURCE_START, payload: uuid };
|
||||
}
|
||||
|
||||
function refreshOK(payload: TaggedResource): ReduxAction<TaggedResource> {
|
||||
export function refreshOK(payload: TaggedResource): ReduxAction<TaggedResource> {
|
||||
return { type: Actions.REFRESH_RESOURCE_OK, payload };
|
||||
}
|
||||
|
||||
function refreshNO(payload: GeneralizedError): ReduxAction<GeneralizedError> {
|
||||
export function refreshNO(payload: GeneralizedError): ReduxAction<GeneralizedError> {
|
||||
return { type: Actions.REFRESH_RESOURCE_NO, payload };
|
||||
}
|
||||
|
||||
|
|
|
@ -69,28 +69,28 @@ export let initialState: BotState = {
|
|||
currentOSVersion: undefined,
|
||||
currentFWVersion: undefined,
|
||||
axis_inversion: {
|
||||
x: !!Session.getBool(BooleanSetting.X_AXIS_INVERTED),
|
||||
y: !!Session.getBool(BooleanSetting.Y_AXIS_INVERTED),
|
||||
z: !!Session.getBool(BooleanSetting.Z_AXIS_INVERTED),
|
||||
x: !!Session.getBool(BooleanSetting.xAxisInverted),
|
||||
y: !!Session.getBool(BooleanSetting.yAxisInverted),
|
||||
z: !!Session.getBool(BooleanSetting.zAxisInverted),
|
||||
},
|
||||
encoder_visibility: {
|
||||
raw_encoders: !!Session.getBool(BooleanSetting.RAW_ENCODERS),
|
||||
scaled_encoders: !!Session.getBool(BooleanSetting.SCALED_ENCODERS),
|
||||
raw_encoders: !!Session.getBool(BooleanSetting.rawEncoders),
|
||||
scaled_encoders: !!Session.getBool(BooleanSetting.scaledEncoders),
|
||||
}
|
||||
};
|
||||
|
||||
/** Translate X/Y/Z to the name that is used in `localStorage` */
|
||||
export const INVERSION_MAPPING: Record<Xyz, BooleanSetting> = {
|
||||
x: BooleanSetting.X_AXIS_INVERTED,
|
||||
y: BooleanSetting.Y_AXIS_INVERTED,
|
||||
z: BooleanSetting.Z_AXIS_INVERTED,
|
||||
x: BooleanSetting.xAxisInverted,
|
||||
y: BooleanSetting.yAxisInverted,
|
||||
z: BooleanSetting.zAxisInverted,
|
||||
};
|
||||
|
||||
/** Translate `encode_visibility` key name to the name that is
|
||||
* used in `localStorage` */
|
||||
export const ENCODER_MAPPING: Record<EncoderDisplay, BooleanSetting> = {
|
||||
raw_encoders: BooleanSetting.RAW_ENCODERS,
|
||||
scaled_encoders: BooleanSetting.SCALED_ENCODERS,
|
||||
raw_encoders: BooleanSetting.rawEncoders,
|
||||
scaled_encoders: BooleanSetting.scaledEncoders,
|
||||
};
|
||||
|
||||
export let botReducer = generateReducer<BotState>(initialState)
|
||||
|
|
|
@ -3,8 +3,8 @@ import { Session } from "./session";
|
|||
import { BooleanSetting } from "./session_keys";
|
||||
|
||||
function generateUrl(langCode: string) {
|
||||
let lang = langCode.slice(0, 2);
|
||||
let url = "//" + location.host.split(":")
|
||||
const lang = langCode.slice(0, 2);
|
||||
const url = "//" + location.host.split(":")
|
||||
[0] + ":" + location.port + "/app-resources/languages/" + lang + ".js";
|
||||
return url;
|
||||
}
|
||||
|
@ -19,8 +19,8 @@ export function detectLanguage() {
|
|||
return getUserLang(navigator.language).then(function (lang) {
|
||||
// NOTE: Some international users prefer using the app in English.
|
||||
// This preference is stored in `DISABLE_I18N`.
|
||||
let choice = Session.getBool(BooleanSetting.DISABLE_I18N) ? "en" : lang;
|
||||
let langi = require("../public/app-resources/languages/" + choice + ".js");
|
||||
const choice = Session.getBool(BooleanSetting.disableI18n) ? "en" : lang;
|
||||
const langi = require("../public/app-resources/languages/" + choice + ".js");
|
||||
return {
|
||||
nsSeparator: "",
|
||||
keySeparator: "",
|
||||
|
|
|
@ -21,11 +21,11 @@ describe("<LangToggle/>", () => {
|
|||
};
|
||||
});
|
||||
const el = mount(<LangToggle />);
|
||||
expect(Session.getBool(BooleanSetting.DISABLE_I18N)).toBeFalsy();
|
||||
expect(Session.getBool(BooleanSetting.disableI18n)).toBeFalsy();
|
||||
expect(el.text().toLocaleLowerCase()).toContain("set page to english");
|
||||
el.find("a").first().simulate("click");
|
||||
el.update();
|
||||
expect(Session.getBool(BooleanSetting.DISABLE_I18N)).toBeTruthy();
|
||||
expect(Session.getBool(BooleanSetting.disableI18n)).toBeTruthy();
|
||||
expect(el.text().toLocaleLowerCase()).not.toContain("set page to english");
|
||||
expect(el.text().toLocaleLowerCase()).toContain("internationalize page");
|
||||
});
|
||||
|
|
|
@ -14,11 +14,11 @@ export class LangToggle extends React.Component<Props, State> {
|
|||
state: State = {};
|
||||
|
||||
toggle = () => {
|
||||
Session.setBool(BooleanSetting.DISABLE_I18N, !this.disabled());
|
||||
Session.setBool(BooleanSetting.disableI18n, !this.disabled());
|
||||
this.setState({ clicked: true });
|
||||
};
|
||||
|
||||
disabled = () => Session.getBool(BooleanSetting.DISABLE_I18N);
|
||||
disabled = () => Session.getBool(BooleanSetting.disableI18n);
|
||||
|
||||
verbiage() {
|
||||
return (this.disabled() ? "Internationalize Page" : "Set Page to English");
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import { resourceReducer } from "../reducer";
|
||||
import { fakeState } from "../../__test_support__/fake_state";
|
||||
import { overwrite } from "../../api/crud";
|
||||
import { SpecialStatus, TaggedSequence } from "../tagged_resources";
|
||||
import { overwrite, refreshStart, refreshOK, refreshNO } from "../../api/crud";
|
||||
import { SpecialStatus, TaggedSequence, TaggedDevice } from "../tagged_resources";
|
||||
|
||||
describe("resource reducer", () => {
|
||||
it("marks resources as DIRTY when reducing OVERWRITE_RESOURCE", () => {
|
||||
|
@ -18,4 +18,27 @@ describe("resource reducer", () => {
|
|||
const seq2 = next.index.references[uuid] as TaggedSequence;
|
||||
expect(seq2.specialStatus).toBe(SpecialStatus.DIRTY);
|
||||
});
|
||||
|
||||
it("marks resources as SAVING when reducing REFRESH_RESOURCE_START", () => {
|
||||
const state = fakeState().resources;
|
||||
const uuid = state.index.byKind.device[0];
|
||||
const device = state.index.references[uuid] as TaggedSequence;
|
||||
expect(device).toBeTruthy();
|
||||
|
||||
expect(device.kind).toBe("device");
|
||||
const afterStart = resourceReducer(state, refreshStart(device.uuid));
|
||||
const dev2 = afterStart.index.references[uuid] as TaggedDevice;
|
||||
expect(dev2.specialStatus).toBe(SpecialStatus.SAVING);
|
||||
|
||||
// SCENARIO: REFRESH_START ===> REFRESH_OK
|
||||
const afterOk = resourceReducer(afterStart, refreshOK(device));
|
||||
const dev3 = afterOk.index.references[uuid] as TaggedDevice;
|
||||
expect(dev3.specialStatus).toBe(undefined);
|
||||
|
||||
// SCENARIO: REFRESH_START ===> REFRESH_NO
|
||||
const afterNo =
|
||||
resourceReducer(afterStart, refreshNO({ err: "X", uuid: dev3.uuid }));
|
||||
const dev4 = afterNo.index.references[uuid] as TaggedDevice;
|
||||
expect(dev4.specialStatus).toBe(undefined);
|
||||
});
|
||||
});
|
||||
|
|
|
@ -32,6 +32,7 @@ import {
|
|||
} from "../farmware/reducer";
|
||||
import { Actions } from "../constants";
|
||||
import { maybeTagSteps as dontTouchThis } from "./sequence_tagging";
|
||||
import { GeneralizedError } from "./actions";
|
||||
|
||||
const consumerReducer = combineReducers<RestResources["consumers"]>({
|
||||
regimens,
|
||||
|
@ -241,8 +242,8 @@ export let resourceReducer = generateReducer
|
|||
mutateSpecialStatus(a.payload.uuid, s.index, undefined);
|
||||
return s;
|
||||
})
|
||||
.add<string>(Actions.REFRESH_RESOURCE_NO, (s, a) => {
|
||||
mutateSpecialStatus(a.payload, s.index, undefined);
|
||||
.add<GeneralizedError>(Actions.REFRESH_RESOURCE_NO, (s, a) => {
|
||||
mutateSpecialStatus(a.payload.uuid, s.index, undefined);
|
||||
return s;
|
||||
});
|
||||
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
export enum BooleanSetting {
|
||||
/** TODO: Convert these guys to a consistentCase before submitting PR. -RC */
|
||||
X_AXIS_INVERTED = "x_axis_inverted",
|
||||
Y_AXIS_INVERTED = "y_axis_inverted",
|
||||
Z_AXIS_INVERTED = "z_axis_inverted",
|
||||
RAW_ENCODERS = "raw_encoders",
|
||||
SCALED_ENCODERS = "scaled_encoders",
|
||||
DISABLE_I18N = "disable_i18n",
|
||||
xAxisInverted = "xAxisInverted",
|
||||
yAxisInverted = "yAxisInverted",
|
||||
zAxisInverted = "zAxisInverted",
|
||||
rawEncoders = "rawEncoders",
|
||||
scaledEncoders = "scaledEncoders",
|
||||
disableI18n = "disableI18n",
|
||||
legendMenuOpen = "legendMenuOpen",
|
||||
showPlants = "showPlants",
|
||||
showPoints = "showPoints",
|
||||
|
|
Loading…
Reference in New Issue