import * as React from "react"; import { Everything } from "../interfaces"; import { connect } from "react-redux"; import { Content } from "../constants"; import { DesignerPanel, DesignerPanelContent } from "./designer_panel"; import { t } from "../i18next_wrapper"; import { GetWebAppConfigValue, getWebAppConfigValue, setWebAppConfigValue } from "../config_storage/actions"; import { Row, Col } from "../ui"; import { ToggleButton } from "../controls/toggle_button"; import { BooleanConfigKey } from "farmbot/dist/resources/configs/web_app"; import { BooleanSetting, NumericSetting } from "../session_keys"; import { resetVirtualTrail } from "./map/layers/farmbot/bot_trail"; import { MapSizeInputs } from "./map_size_setting"; import { DesignerNavTabs, Panel } from "./panel_header"; import { isUndefined } from "lodash"; export const mapStateToProps = (props: Everything): DesignerSettingsProps => ({ dispatch: props.dispatch, getConfigValue: getWebAppConfigValue(() => props), }); export interface DesignerSettingsProps { dispatch: Function; getConfigValue: GetWebAppConfigValue; } export class RawDesignerSettings extends React.Component { render() { const { getConfigValue, dispatch } = this.props; const settingsProps = { getConfigValue, dispatch }; return {DESIGNER_SETTINGS(settingsProps).map(setting => )} ; } } interface SettingDescriptionProps { setting?: BooleanConfigKey; title: string; description: string; invert?: boolean; callback?: () => void; children?: React.ReactChild; defaultOn?: boolean; disabled?: boolean; } interface SettingProps extends DesignerSettingsProps, SettingDescriptionProps { } const Setting = (props: SettingProps) => { const { title, setting, callback, defaultOn } = props; const raw_value = setting ? props.getConfigValue(setting) : undefined; const value = (defaultOn && isUndefined(raw_value)) ? true : !!raw_value; return
{setting && { props.dispatch(setWebAppConfigValue(setting, !value)); callback?.(); }} title={`${t("toggle")} ${title}`} customText={{ textFalse: t("off"), textTrue: t("on") }} />}

{t(props.description)}

{props.children}
; }; const DESIGNER_SETTINGS = (settingsProps: DesignerSettingsProps): SettingDescriptionProps[] => ([ { title: t("Display plant animations"), description: t(Content.PLANT_ANIMATIONS), setting: BooleanSetting.disable_animations, invert: true }, { title: t("Display virtual FarmBot trail"), description: t(Content.VIRTUAL_TRAIL), setting: BooleanSetting.display_trail, callback: resetVirtualTrail, }, { title: t("Dynamic map size"), description: t(Content.DYNAMIC_MAP_SIZE), setting: BooleanSetting.dynamic_map, }, { title: t("Map size"), description: t(Content.MAP_SIZE), children: , disabled: !!settingsProps.getConfigValue(BooleanSetting.dynamic_map), }, { title: t("Rotate map"), description: t(Content.MAP_SWAP_XY), setting: BooleanSetting.xy_swap, }, { title: t("Map origin"), description: t(Content.MAP_ORIGIN), children: }, { title: t("Confirm plant deletion"), description: t(Content.CONFIRM_PLANT_DELETION), setting: BooleanSetting.confirm_plant_deletion, defaultOn: true, }, ]); const OriginSelector = (props: DesignerSettingsProps) => { const quadrant = props.getConfigValue(NumericSetting.bot_origin_quadrant); const update = (value: number) => () => props.dispatch(setWebAppConfigValue( NumericSetting.bot_origin_quadrant, value)); return
{[2, 1, 3, 4].map(q =>
)}
; }; export const DesignerSettings = connect(mapStateToProps)(RawDesignerSettings);