refactor logs settings source
parent
a5e786a6a9
commit
1c05dde5fe
|
@ -4,26 +4,6 @@ jest.mock("react-redux", () => ({
|
|||
|
||||
const mockStorj: Dictionary<number | boolean> = {};
|
||||
|
||||
jest.mock("../../session", () => {
|
||||
return {
|
||||
Session: {
|
||||
deprecatedGetNum: (k: string) => {
|
||||
return mockStorj[k];
|
||||
},
|
||||
deprecatedSetNum: (k: string, v: number) => {
|
||||
mockStorj[k] = v;
|
||||
},
|
||||
deprecatedGetBool: (k: string) => {
|
||||
mockStorj[k] = !!mockStorj[k];
|
||||
return mockStorj[k];
|
||||
}
|
||||
},
|
||||
// tslint:disable-next-line:no-any
|
||||
safeNumericSetting: (x: any) => x
|
||||
|
||||
};
|
||||
});
|
||||
|
||||
import * as React from "react";
|
||||
import { mount } from "enzyme";
|
||||
import { Logs } from "../index";
|
||||
|
@ -50,7 +30,8 @@ describe("<Logs />", () => {
|
|||
bot,
|
||||
timeOffset: 0,
|
||||
dispatch: jest.fn(),
|
||||
sourceFbosConfig: jest.fn()
|
||||
sourceFbosConfig: jest.fn(),
|
||||
getConfigValue: x => mockStorj[x],
|
||||
};
|
||||
};
|
||||
|
||||
|
|
|
@ -7,26 +7,6 @@ jest.mock("../../../device", () => ({
|
|||
|
||||
const mockStorj: Dictionary<number | boolean> = {};
|
||||
|
||||
jest.mock("../../../session", () => {
|
||||
return {
|
||||
Session: {
|
||||
deprecatedGetNum: (k: string) => {
|
||||
return mockStorj[k];
|
||||
},
|
||||
setNum: (k: string, v: number) => {
|
||||
mockStorj[k] = v;
|
||||
},
|
||||
deprecatedGetBool: (k: string) => {
|
||||
mockStorj[k] = !!mockStorj[k];
|
||||
return mockStorj[k];
|
||||
}
|
||||
},
|
||||
// tslint:disable-next-line:no-any
|
||||
safeNumericSetting: (x: any) => x
|
||||
|
||||
};
|
||||
});
|
||||
|
||||
import * as React from "react";
|
||||
import { mount } from "enzyme";
|
||||
import { LogsSettingsMenu } from "../settings_menu";
|
||||
|
@ -43,7 +23,8 @@ describe("<LogsSettingsMenu />", () => {
|
|||
dispatch: jest.fn(x => x(jest.fn(), fakeState)),
|
||||
sourceFbosConfig: (x) => {
|
||||
return { value: bot.hardware.configuration[x], consistent: true };
|
||||
}
|
||||
},
|
||||
getConfigValue: x => mockStorj[x],
|
||||
};
|
||||
};
|
||||
|
||||
|
|
|
@ -5,7 +5,7 @@ import { ToolTips } from "../../constants";
|
|||
import { ToggleButton } from "../../controls/toggle_button";
|
||||
import { updateConfig } from "../../devices/actions";
|
||||
import { LogSettingProps, LogsSettingsMenuProps, Filters } from "../interfaces";
|
||||
import { Session, safeNumericSetting } from "../../session";
|
||||
import { safeNumericSetting } from "../../session";
|
||||
import { ConfigurationName } from "farmbot";
|
||||
|
||||
interface LogSettingRecord {
|
||||
|
@ -55,7 +55,7 @@ const LogSetting = (props: LogSettingProps) => {
|
|||
/** Update the current filter level to a minimum needed for log display. */
|
||||
const updateMinFilterLevel = (name: keyof Filters, level: number) => {
|
||||
const currentLevel =
|
||||
Session.deprecatedGetNum(safeNumericSetting(name + "_log")) || 0;
|
||||
props.getConfigValue(safeNumericSetting(name + "_log")) || 0;
|
||||
if (currentLevel < level) { setFilterLevel(name)(level); }
|
||||
};
|
||||
const config = sourceFbosConfig(setting);
|
||||
|
@ -92,7 +92,7 @@ const LogSetting = (props: LogSettingProps) => {
|
|||
};
|
||||
|
||||
export const LogsSettingsMenu = (props: LogsSettingsMenuProps) => {
|
||||
const { setFilterLevel, sourceFbosConfig } = props;
|
||||
const { setFilterLevel, sourceFbosConfig, getConfigValue } = props;
|
||||
const LogSettingRow = (settingProps: LogSettingRecord) => {
|
||||
const { label, setting, tooltip } = settingProps;
|
||||
return <LogSetting
|
||||
|
@ -101,7 +101,8 @@ export const LogsSettingsMenu = (props: LogsSettingsMenuProps) => {
|
|||
toolTip={tooltip}
|
||||
setFilterLevel={setFilterLevel}
|
||||
dispatch={props.dispatch}
|
||||
sourceFbosConfig={sourceFbosConfig} />;
|
||||
sourceFbosConfig={sourceFbosConfig}
|
||||
getConfigValue={getConfigValue} />;
|
||||
};
|
||||
return <div className={"logs-settings-menu"}>
|
||||
{t("Create logs for sequence:")}
|
||||
|
|
|
@ -10,10 +10,11 @@ import { ToolTips } from "../constants";
|
|||
import { LogsSettingsMenu } from "./components/settings_menu";
|
||||
import { LogsFilterMenu } from "./components/filter_menu";
|
||||
import { LogsTable } from "./components/logs_table";
|
||||
import { Session, safeNumericSetting } from "../session";
|
||||
import { safeNumericSetting } from "../session";
|
||||
import { isUndefined } from "lodash";
|
||||
import { NumericSetting } from "../session_keys";
|
||||
import { NumberConfigKey } from "../config_storage/web_app_configs";
|
||||
import { setWebAppConfigValue } from "../config_storage/actions";
|
||||
|
||||
/** Format log date and time for display in the app. */
|
||||
export const formatLogTime = (created_at: number, timeoffset: number) =>
|
||||
|
@ -24,12 +25,13 @@ export class Logs extends React.Component<LogsProps, Partial<LogsState>> {
|
|||
|
||||
/** Initialize log type verbosity level to the configured or default value. */
|
||||
initialize = (name: NumberConfigKey, defaultValue: number): number => {
|
||||
const currentValue = Session.deprecatedGetNum(safeNumericSetting(name));
|
||||
const currentValue = this.props.getConfigValue(safeNumericSetting(name));
|
||||
if (isUndefined(currentValue)) {
|
||||
Session.deprecatedSetNum(safeNumericSetting(name), defaultValue);
|
||||
this.props.dispatch(
|
||||
setWebAppConfigValue(safeNumericSetting(name), defaultValue));
|
||||
return defaultValue;
|
||||
} else {
|
||||
return currentValue;
|
||||
return currentValue as number;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -50,7 +52,8 @@ export class Logs extends React.Component<LogsProps, Partial<LogsState>> {
|
|||
const newSetting = this.state[name] === 0 ? 1 : 0;
|
||||
return () => {
|
||||
this.setState({ [name]: newSetting });
|
||||
Session.deprecatedSetNum(safeNumericSetting(name + "_log"), newSetting);
|
||||
this.props.dispatch(
|
||||
setWebAppConfigValue(safeNumericSetting(name + "_log"), newSetting));
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -58,7 +61,8 @@ export class Logs extends React.Component<LogsProps, Partial<LogsState>> {
|
|||
setFilterLevel = (name: keyof Filters) => {
|
||||
return (value: number) => {
|
||||
this.setState({ [name]: value });
|
||||
Session.deprecatedSetNum(safeNumericSetting(name + "_log"), value);
|
||||
this.props.dispatch(
|
||||
setWebAppConfigValue(safeNumericSetting(name + "_log"), value));
|
||||
};
|
||||
};
|
||||
|
||||
|
@ -89,7 +93,8 @@ export class Logs extends React.Component<LogsProps, Partial<LogsState>> {
|
|||
<LogsSettingsMenu
|
||||
setFilterLevel={this.setFilterLevel}
|
||||
dispatch={this.props.dispatch}
|
||||
sourceFbosConfig={this.props.sourceFbosConfig} />
|
||||
sourceFbosConfig={this.props.sourceFbosConfig}
|
||||
getConfigValue={this.props.getConfigValue} />
|
||||
</Popover>
|
||||
</div>
|
||||
<div className={"settings-menu-button"}>
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
import { TaggedLog, ConfigurationName, ALLOWED_MESSAGE_TYPES } from "farmbot";
|
||||
import { BotState, SourceFbosConfig } from "../devices/interfaces";
|
||||
import { GetWebAppConfigValue } from "../config_storage/actions";
|
||||
|
||||
export interface LogsProps {
|
||||
logs: TaggedLog[];
|
||||
|
@ -7,6 +8,7 @@ export interface LogsProps {
|
|||
timeOffset: number;
|
||||
dispatch: Function;
|
||||
sourceFbosConfig: SourceFbosConfig;
|
||||
getConfigValue: GetWebAppConfigValue;
|
||||
}
|
||||
|
||||
export type Filters = Record<ALLOWED_MESSAGE_TYPES, number>;
|
||||
|
@ -37,10 +39,12 @@ export interface LogSettingProps {
|
|||
setFilterLevel: SetNumSetting;
|
||||
dispatch: Function;
|
||||
sourceFbosConfig: SourceFbosConfig;
|
||||
getConfigValue: GetWebAppConfigValue;
|
||||
}
|
||||
|
||||
export interface LogsSettingsMenuProps {
|
||||
setFilterLevel: SetNumSetting;
|
||||
dispatch: Function;
|
||||
sourceFbosConfig: SourceFbosConfig;
|
||||
getConfigValue: GetWebAppConfigValue;
|
||||
}
|
||||
|
|
|
@ -9,6 +9,7 @@ import { getFbosConfig } from "../resources/selectors_by_kind";
|
|||
import { validFbosConfig } from "../util";
|
||||
import { ResourceIndex } from "../resources/interfaces";
|
||||
import { TaggedLog } from "farmbot";
|
||||
import { getWebAppConfigValue } from "../config_storage/actions";
|
||||
|
||||
/** Take the specified number of logs after sorting by time created. */
|
||||
export function takeSortedLogs(
|
||||
|
@ -28,7 +29,8 @@ export function mapStateToProps(props: Everything): LogsProps {
|
|||
sourceFbosConfig: sourceFbosConfigValue(fbosConfig, hardware.configuration),
|
||||
logs: takeSortedLogs(250, props.resources.index),
|
||||
bot: props.bot,
|
||||
timeOffset: maybeGetTimeOffset(props.resources.index)
|
||||
timeOffset: maybeGetTimeOffset(props.resources.index),
|
||||
getConfigValue: getWebAppConfigValue(() => props),
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -50,22 +50,23 @@ export namespace Session {
|
|||
return LegacyShim.getBoolViaRedux(key);
|
||||
}
|
||||
|
||||
/** Store a boolean value in `localStorage` */
|
||||
/** @deprecated Store a boolean value in `localStorage` */
|
||||
export function setBool(key: BooleanConfigKey, val: boolean): boolean {
|
||||
return LegacyShim.setBoolViaRedux(key, val);
|
||||
}
|
||||
|
||||
/** @deprecated */
|
||||
export function invertBool(key: BooleanConfigKey): boolean {
|
||||
return Session.setBool(key, !Session.deprecatedGetBool(key));
|
||||
}
|
||||
|
||||
/** Extract numeric settings from `localStorage`. Returns `undefined` when
|
||||
/** @deprecated Extract numeric settings from `localStorage`. Returns `undefined` when
|
||||
* none are found. */
|
||||
export function deprecatedGetNum(key: NumberConfigKey): number | undefined {
|
||||
return LegacyShim.getNumViaRedux(key);
|
||||
}
|
||||
|
||||
/** Set a numeric value in `localStorage`. */
|
||||
/** @deprecated Set a numeric value in `localStorage`. */
|
||||
export function deprecatedSetNum(key: NumberConfigKey, val: number): void {
|
||||
LegacyShim.setNumViaRedux(key, val);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue