Set timezone on initial app load. TODO: Docs, tests.
parent
88fcb85d40
commit
8eb0a0bb16
|
@ -160,10 +160,10 @@ GEM
|
|||
addressable (~> 2.3)
|
||||
letter_opener (1.7.0)
|
||||
launchy (~> 2.2)
|
||||
lol_dba (2.1.5)
|
||||
actionpack (>= 3.0)
|
||||
activerecord (>= 3.0)
|
||||
railties (>= 3.0)
|
||||
lol_dba (2.1.7)
|
||||
actionpack (>= 3.0, < 6.0)
|
||||
activerecord (>= 3.0, < 6.0)
|
||||
railties (>= 3.0, < 6.0)
|
||||
loofah (2.2.3)
|
||||
crass (~> 1.0.2)
|
||||
nokogiri (>= 1.5.9)
|
||||
|
|
|
@ -11,6 +11,7 @@ if Rails.env == "development"
|
|||
eggplant endive garlic jicama kale kohlrabi leek lettuce okra onion
|
||||
parsnip pepper potato pumpkin radicchio radish raspberry rhubarb spinach
|
||||
squash tomato turnip zucchini)
|
||||
|
||||
[
|
||||
Sensor,
|
||||
Peripheral,
|
||||
|
|
|
@ -11,6 +11,7 @@ import {
|
|||
} from "../../__test_support__/fake_state/resources";
|
||||
import { Dictionary } from "farmbot";
|
||||
import { Props } from "../interfaces";
|
||||
import { fakeDevice } from "../../__test_support__/resource_index_builder";
|
||||
|
||||
describe("<Controls />", () => {
|
||||
const mockConfig: Dictionary<boolean> = {};
|
||||
|
@ -28,6 +29,7 @@ describe("<Controls />", () => {
|
|||
getWebAppConfigVal: jest.fn((key) => (mockConfig[key])),
|
||||
sensorReadings: [],
|
||||
timeOffset: 0,
|
||||
device: fakeDevice()
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -10,11 +10,17 @@ import { Move } from "./move/move";
|
|||
import { BooleanSetting } from "../session_keys";
|
||||
import { Feature } from "../devices/interfaces";
|
||||
import { SensorReadings } from "./sensor_readings/sensor_readings";
|
||||
import { maybeSetTimezone } from "../devices/timezones/guess_timezone";
|
||||
|
||||
/** Controls page. */
|
||||
@connect(mapStateToProps)
|
||||
export class Controls extends React.Component<Props, {}> {
|
||||
|
||||
componentDidMount = () => {
|
||||
this.props.device &&
|
||||
maybeSetTimezone(this.props.dispatch, this.props.device);
|
||||
}
|
||||
|
||||
get arduinoBusy() {
|
||||
return !!this.props.bot.hardware.informational_settings.busy;
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import { BotState, Xyz, BotPosition, ShouldDisplay } from "../devices/interfaces";
|
||||
import { Vector3, McuParams } from "farmbot/dist";
|
||||
import { Vector3, McuParams, TaggedDevice } from "farmbot/dist";
|
||||
import {
|
||||
TaggedWebcamFeed,
|
||||
TaggedPeripheral,
|
||||
|
@ -21,6 +21,7 @@ export interface Props {
|
|||
getWebAppConfigVal: GetWebAppConfigValue;
|
||||
sensorReadings: TaggedSensorReading[];
|
||||
timeOffset: number;
|
||||
device: TaggedDevice | undefined;
|
||||
}
|
||||
|
||||
export interface AxisDisplayGroupProps {
|
||||
|
|
|
@ -16,16 +16,16 @@ import { getFirmwareConfig } from "../resources/getters";
|
|||
import { uniq } from "lodash";
|
||||
|
||||
export function mapStateToProps(props: Everything): Props {
|
||||
const peripherals = uniq(selectAllPeripherals(props.resources.index));
|
||||
const sensors = uniq(selectAllSensors(props.resources.index));
|
||||
const resources = props.resources;
|
||||
const { mcu_params } = props.bot.hardware;
|
||||
const bot2mqtt = props.bot.connectivity["bot.mqtt"];
|
||||
const botToMqttStatus = bot2mqtt ? bot2mqtt.state : "down";
|
||||
const device = maybeGetDevice(props.resources.index);
|
||||
const fwConfig = validFwConfig(getFirmwareConfig(props.resources.index));
|
||||
const { mcu_params } = props.bot.hardware;
|
||||
const installedOsVersion = determineInstalledOsVersion(
|
||||
props.bot, maybeGetDevice(props.resources.index));
|
||||
const getWebAppConfigVal = getWebAppConfigValue(() => props);
|
||||
const installedOsVersion = determineInstalledOsVersion(props.bot, device);
|
||||
const peripherals = uniq(selectAllPeripherals(props.resources.index));
|
||||
const resources = props.resources;
|
||||
const sensors = uniq(selectAllSensors(props.resources.index));
|
||||
|
||||
return {
|
||||
feeds: selectAllWebcamFeeds(resources.index),
|
||||
|
@ -39,5 +39,6 @@ export function mapStateToProps(props: Everything): Props {
|
|||
getWebAppConfigVal,
|
||||
sensorReadings: selectAllSensorReadings(props.resources.index),
|
||||
timeOffset: maybeGetTimeOffset(props.resources.index),
|
||||
device
|
||||
};
|
||||
}
|
||||
|
|
|
@ -1,14 +1,11 @@
|
|||
import { isString } from "lodash";
|
||||
import { TaggedDevice } from "farmbot";
|
||||
import { edit, save } from "../../api/crud";
|
||||
|
||||
/** Use browser's i18n functionality to guess timezone. */
|
||||
function maybeResolveTZ(): string | undefined {
|
||||
if (Intl && Intl.DateTimeFormat) {
|
||||
// WARNING SIDE EFFECTS!!!
|
||||
console.warn("Ding!");
|
||||
return Intl.DateTimeFormat().resolvedOptions().timeZone;
|
||||
}
|
||||
return undefined;
|
||||
}
|
||||
const maybeResolveTZ = (): string | undefined => Intl &&
|
||||
Intl.DateTimeFormat &&
|
||||
Intl.DateTimeFormat().resolvedOptions().timeZone;
|
||||
|
||||
export const inferTimezone = (current: string | undefined): string =>
|
||||
current || maybeResolveTZ() || "UTC";
|
||||
|
@ -26,3 +23,10 @@ export function timezoneMismatch(botTime: string | undefined,
|
|||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
export function maybeSetTimezone(dispatch: Function, device: TaggedDevice) {
|
||||
if (!device.body.timezone) {
|
||||
dispatch(edit(device, { timezone: inferTimezone(undefined) }));
|
||||
dispatch(save(device.uuid));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -24,11 +24,8 @@
|
|||
"strictNullChecks": true,
|
||||
"target": "es5",
|
||||
},
|
||||
"exclude": [
|
||||
"node_modules",
|
||||
"typings",
|
||||
"public",
|
||||
"docker_volumes"
|
||||
"include": [
|
||||
"frontend"
|
||||
],
|
||||
"compileOnSave": false,
|
||||
"buildOnSave": false
|
||||
|
|
Loading…
Reference in New Issue