Reshuffle strucutre of connectivity state tree branch
parent
1a8d7024a7
commit
adfb11cd1b
|
@ -56,8 +56,11 @@ export let bot: Everything["bot"] = {
|
||||||
"dirty": false,
|
"dirty": false,
|
||||||
"currentOSVersion": "3.1.6",
|
"currentOSVersion": "3.1.6",
|
||||||
"connectivity": {
|
"connectivity": {
|
||||||
"bot.mqtt": undefined,
|
uptime: {
|
||||||
"user.mqtt": undefined,
|
"bot.mqtt": undefined,
|
||||||
"user.api": undefined,
|
"user.mqtt": undefined,
|
||||||
|
"user.api": undefined,
|
||||||
|
},
|
||||||
|
pings: {}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -118,7 +118,7 @@ export class App extends React.Component<AppProps, {}> {
|
||||||
const currentPage = getPathArray()[2];
|
const currentPage = getPathArray()[2];
|
||||||
const { location_data, mcu_params } = this.props.bot.hardware;
|
const { location_data, mcu_params } = this.props.bot.hardware;
|
||||||
const { sync_status } = this.props.bot.hardware.informational_settings;
|
const { sync_status } = this.props.bot.hardware.informational_settings;
|
||||||
const bot2mqtt = this.props.bot.connectivity["bot.mqtt"];
|
const bot2mqtt = this.props.bot.connectivity.uptime["bot.mqtt"];
|
||||||
return <div className="app">
|
return <div className="app">
|
||||||
{!syncLoaded && <LoadingPlant animate={this.props.animate} />}
|
{!syncLoaded && <LoadingPlant animate={this.props.animate} />}
|
||||||
<HotKeys dispatch={this.props.dispatch} />
|
<HotKeys dispatch={this.props.dispatch} />
|
||||||
|
|
|
@ -6,7 +6,7 @@ describe("connectivityReducer", () => {
|
||||||
const state = connectivityReducer(DEFAULT_STATE,
|
const state = connectivityReducer(DEFAULT_STATE,
|
||||||
networkUp("user.mqtt", undefined, "tests"));
|
networkUp("user.mqtt", undefined, "tests"));
|
||||||
expect(state).toBeDefined();
|
expect(state).toBeDefined();
|
||||||
const x = state && state["user.mqtt"];
|
const x = state && state.uptime["user.mqtt"];
|
||||||
if (x) {
|
if (x) {
|
||||||
expect(x.state).toBe("up");
|
expect(x.state).toBe("up");
|
||||||
expect(x.at).toBeTruthy();
|
expect(x.at).toBeTruthy();
|
||||||
|
@ -18,7 +18,7 @@ describe("connectivityReducer", () => {
|
||||||
it("goes down", () => {
|
it("goes down", () => {
|
||||||
const state = connectivityReducer(DEFAULT_STATE,
|
const state = connectivityReducer(DEFAULT_STATE,
|
||||||
networkDown("user.api", undefined, "tests"));
|
networkDown("user.api", undefined, "tests"));
|
||||||
const x = state && state["user.api"];
|
const x = state && state.uptime["user.api"];
|
||||||
if (x) {
|
if (x) {
|
||||||
expect(x.state).toBe("down");
|
expect(x.state).toBe("down");
|
||||||
expect(x.at).toBeTruthy();
|
expect(x.at).toBeTruthy();
|
||||||
|
|
|
@ -6,11 +6,11 @@ describe("Connectivity Reducer - RESET_NETWORK", () => {
|
||||||
it("clears all network status", () => {
|
it("clears all network status", () => {
|
||||||
const action: ReduxAction<{}> = resetNetwork();
|
const action: ReduxAction<{}> = resetNetwork();
|
||||||
const result = connectivityReducer(DEFAULT_STATE, action);
|
const result = connectivityReducer(DEFAULT_STATE, action);
|
||||||
const values: (keyof typeof DEFAULT_STATE)[] = [
|
const values: (keyof typeof DEFAULT_STATE["uptime"])[] = [
|
||||||
"bot.mqtt",
|
"bot.mqtt",
|
||||||
"user.mqtt",
|
"user.mqtt",
|
||||||
"user.api"
|
"user.api"
|
||||||
];
|
];
|
||||||
values.map((x) => expect(result[x]).toBeUndefined());
|
values.map((x) => expect(result.uptime[x]).toBeUndefined());
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -8,6 +8,6 @@ describe("Connectivity Reducer - RESOURCE_READY", () => {
|
||||||
device.body.last_saw_mq = "Tue, 03 Oct 2017 09:00:00 -0500";
|
device.body.last_saw_mq = "Tue, 03 Oct 2017 09:00:00 -0500";
|
||||||
const action = resourceReady("Device", device);
|
const action = resourceReady("Device", device);
|
||||||
const result = connectivityReducer(DEFAULT_STATE, action);
|
const result = connectivityReducer(DEFAULT_STATE, action);
|
||||||
expect(result["bot.mqtt"]).not.toBe(undefined);
|
expect(result.uptime["bot.mqtt"]).not.toBe(undefined);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -25,7 +25,10 @@ type ConnectionRecord = Record<Edge, ConnectionStatus | undefined>;
|
||||||
|
|
||||||
/** Mapping of known connection status.
|
/** Mapping of known connection status.
|
||||||
* An `undefined` value means we don't know. */
|
* An `undefined` value means we don't know. */
|
||||||
export type ConnectionState = ConnectionRecord;
|
export type ConnectionState = {
|
||||||
|
uptime: ConnectionRecord;
|
||||||
|
pings: {}
|
||||||
|
};
|
||||||
|
|
||||||
export interface UpdateMqttData<T extends TaggedResource> {
|
export interface UpdateMqttData<T extends TaggedResource> {
|
||||||
status: "UPDATE"
|
status: "UPDATE"
|
||||||
|
|
|
@ -7,28 +7,32 @@ import { SyncBodyContents } from "../sync/actions";
|
||||||
import { arrayUnwrap } from "../resources/util";
|
import { arrayUnwrap } from "../resources/util";
|
||||||
|
|
||||||
export const DEFAULT_STATE: ConnectionState = {
|
export const DEFAULT_STATE: ConnectionState = {
|
||||||
"bot.mqtt": undefined,
|
uptime: {
|
||||||
"user.mqtt": undefined,
|
"bot.mqtt": undefined,
|
||||||
"user.api": undefined
|
"user.mqtt": undefined,
|
||||||
|
"user.api": undefined
|
||||||
|
},
|
||||||
|
pings: {
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
export let connectivityReducer =
|
export let connectivityReducer =
|
||||||
generateReducer<ConnectionState>(DEFAULT_STATE)
|
generateReducer<ConnectionState>(DEFAULT_STATE)
|
||||||
.add<EdgeStatus>(Actions.NETWORK_EDGE_CHANGE, (s, { payload }) => {
|
.add<EdgeStatus>(Actions.NETWORK_EDGE_CHANGE, (s, { payload }) => {
|
||||||
s[payload.name] = payload.status;
|
s.uptime[payload.name] = payload.status;
|
||||||
return s;
|
return s;
|
||||||
})
|
})
|
||||||
.add<SyncBodyContents<TaggedDevice>>(Actions.RESOURCE_READY, (s, a) => {
|
.add<SyncBodyContents<TaggedDevice>>(Actions.RESOURCE_READY, (s, a) => {
|
||||||
const d = arrayUnwrap(a.payload.body);
|
const d = arrayUnwrap(a.payload.body);
|
||||||
if (d && d.kind === "Device") {
|
if (d && d.kind === "Device") {
|
||||||
s["bot.mqtt"] = computeBestTime(s["bot.mqtt"], d && d.body.last_saw_mq);
|
s.uptime["bot.mqtt"] = computeBestTime(s.uptime["bot.mqtt"], d && d.body.last_saw_mq);
|
||||||
}
|
}
|
||||||
return s;
|
return s;
|
||||||
})
|
})
|
||||||
.add<Actions.RESET_NETWORK>(Actions.RESET_NETWORK, (s, _) => {
|
.add<Actions.RESET_NETWORK>(Actions.RESET_NETWORK, (s, _) => {
|
||||||
type Keys = (keyof ConnectionState)[];
|
type Keys = (keyof ConnectionState["uptime"])[];
|
||||||
const keys: Keys = ["bot.mqtt", "user.mqtt", "user.api"];
|
const keys: Keys = ["bot.mqtt", "user.mqtt", "user.api"];
|
||||||
keys.map(x => (s[x] = undefined));
|
keys.map(x => (s.uptime[x] = undefined));
|
||||||
|
|
||||||
return s;
|
return s;
|
||||||
});
|
});
|
||||||
|
|
|
@ -34,7 +34,7 @@ export function mapStateToProps(props: Everything): Props {
|
||||||
bot: props.bot,
|
bot: props.bot,
|
||||||
peripherals: uniq(selectAllPeripherals(props.resources.index)),
|
peripherals: uniq(selectAllPeripherals(props.resources.index)),
|
||||||
sensors: uniq(selectAllSensors(props.resources.index)),
|
sensors: uniq(selectAllSensors(props.resources.index)),
|
||||||
botToMqttStatus: getStatus(props.bot.connectivity["bot.mqtt"]),
|
botToMqttStatus: getStatus(props.bot.connectivity.uptime["bot.mqtt"]),
|
||||||
firmwareSettings: fwConfig || mcu_params,
|
firmwareSettings: fwConfig || mcu_params,
|
||||||
getWebAppConfigVal: getWebAppConfigValue(() => props),
|
getWebAppConfigVal: getWebAppConfigValue(() => props),
|
||||||
shouldDisplay,
|
shouldDisplay,
|
||||||
|
|
|
@ -17,9 +17,9 @@ export const connectivityData = (props: ConnectivityDataProps) => {
|
||||||
|
|
||||||
/** A record of all the things we know about connectivity right now. */
|
/** A record of all the things we know about connectivity right now. */
|
||||||
const data: Record<DiagnosisName, StatusRowProps> = {
|
const data: Record<DiagnosisName, StatusRowProps> = {
|
||||||
userMQTT: browserToMQTT(props.bot.connectivity["user.mqtt"]),
|
userMQTT: browserToMQTT(props.bot.connectivity.uptime["user.mqtt"]),
|
||||||
userAPI: browserToAPI(props.bot.connectivity["user.api"]),
|
userAPI: browserToAPI(props.bot.connectivity.uptime["user.api"]),
|
||||||
botMQTT: botToMQTT(props.bot.connectivity["bot.mqtt"]),
|
botMQTT: botToMQTT(props.bot.connectivity.uptime["bot.mqtt"]),
|
||||||
botAPI: botToAPI(props.device.body.last_saw_api),
|
botAPI: botToAPI(props.device.body.last_saw_api),
|
||||||
botFirmware: botToFirmware(fwVersion),
|
botFirmware: botToFirmware(fwVersion),
|
||||||
};
|
};
|
||||||
|
|
|
@ -73,9 +73,12 @@ export let initialState = (): BotState => ({
|
||||||
currentBetaOSVersion: undefined,
|
currentBetaOSVersion: undefined,
|
||||||
minOsFeatureData: undefined,
|
minOsFeatureData: undefined,
|
||||||
connectivity: {
|
connectivity: {
|
||||||
"bot.mqtt": undefined,
|
uptime: {
|
||||||
"user.mqtt": undefined,
|
"bot.mqtt": undefined,
|
||||||
"user.api": undefined
|
"user.mqtt": undefined,
|
||||||
|
"user.api": undefined
|
||||||
|
},
|
||||||
|
pings: {}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -152,7 +155,7 @@ export let botReducer = generateReducer<BotState>(initialState())
|
||||||
s.hardware.informational_settings.sync_status = undefined;
|
s.hardware.informational_settings.sync_status = undefined;
|
||||||
break;
|
break;
|
||||||
case "up":
|
case "up":
|
||||||
const currentState = s.connectivity["bot.mqtt"];
|
const currentState = s.connectivity.uptime["bot.mqtt"];
|
||||||
// Going from "down" to "up"
|
// Going from "down" to "up"
|
||||||
const backOnline = currentState && currentState.state === "down";
|
const backOnline = currentState && currentState.state === "down";
|
||||||
backOnline && unstash(s);
|
backOnline && unstash(s);
|
||||||
|
|
|
@ -33,9 +33,9 @@ export function mapStateToProps(props: Everything): Props {
|
||||||
? reduceFarmwareEnv(props.resources.index)
|
? reduceFarmwareEnv(props.resources.index)
|
||||||
: props.bot.hardware.user_env;
|
: props.bot.hardware.user_env;
|
||||||
return {
|
return {
|
||||||
userToApi: props.bot.connectivity["user.api"],
|
userToApi: props.bot.connectivity.uptime["user.api"],
|
||||||
userToMqtt: props.bot.connectivity["user.mqtt"],
|
userToMqtt: props.bot.connectivity.uptime["user.mqtt"],
|
||||||
botToMqtt: props.bot.connectivity["bot.mqtt"],
|
botToMqtt: props.bot.connectivity.uptime["bot.mqtt"],
|
||||||
deviceAccount: getDeviceAccountSettings(props.resources.index),
|
deviceAccount: getDeviceAccountSettings(props.resources.index),
|
||||||
auth: props.auth,
|
auth: props.auth,
|
||||||
bot: props.bot,
|
bot: props.bot,
|
||||||
|
|
|
@ -19,7 +19,7 @@ import { isBotOnline } from "../devices/must_be_online";
|
||||||
import { getStatus } from "../connectivity/reducer_support";
|
import { getStatus } from "../connectivity/reducer_support";
|
||||||
|
|
||||||
export function mapStateToProps(props: Everything): MoveToProps {
|
export function mapStateToProps(props: Everything): MoveToProps {
|
||||||
const botToMqttStatus = getStatus(props.bot.connectivity["bot.mqtt"]);
|
const botToMqttStatus = getStatus(props.bot.connectivity.uptime["bot.mqtt"]);
|
||||||
const { sync_status } = props.bot.hardware.informational_settings;
|
const { sync_status } = props.bot.hardware.informational_settings;
|
||||||
return {
|
return {
|
||||||
chosenLocation: props.resources.consumers.farm_designer.chosenLocation,
|
chosenLocation: props.resources.consumers.farm_designer.chosenLocation,
|
||||||
|
|
|
@ -136,7 +136,7 @@ describe("mapStateToProps()", () => {
|
||||||
it("returns bot status", () => {
|
it("returns bot status", () => {
|
||||||
const state = fakeState();
|
const state = fakeState();
|
||||||
state.bot.hardware.informational_settings.sync_status = "sync_now";
|
state.bot.hardware.informational_settings.sync_status = "sync_now";
|
||||||
state.bot.connectivity["bot.mqtt"] = { state: "up", at: "" };
|
state.bot.connectivity.uptime["bot.mqtt"] = { state: "up", at: "" };
|
||||||
const props = mapStateToProps(state);
|
const props = mapStateToProps(state);
|
||||||
expect(props.syncStatus).toEqual("sync_now");
|
expect(props.syncStatus).toEqual("sync_now");
|
||||||
expect(props.botToMqttStatus).toEqual("up");
|
expect(props.botToMqttStatus).toEqual("up");
|
||||||
|
|
|
@ -107,7 +107,7 @@ export function mapStateToProps(props: Everything): FarmwareProps {
|
||||||
.reverse()
|
.reverse()
|
||||||
.value();
|
.value();
|
||||||
|
|
||||||
const botToMqttStatus = getStatus(props.bot.connectivity["bot.mqtt"]);
|
const botToMqttStatus = getStatus(props.bot.connectivity.uptime["bot.mqtt"]);
|
||||||
const syncStatus = props.bot.hardware.informational_settings.sync_status;
|
const syncStatus = props.bot.hardware.informational_settings.sync_status;
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
|
|
@ -9,7 +9,7 @@ const stateFetchMiddleware: Middleware =
|
||||||
(store) => (next) => (action: any) => {
|
(store) => (next) => (action: any) => {
|
||||||
// tslint:disable-next-line:no-any
|
// tslint:disable-next-line:no-any
|
||||||
const s: Everything = store.getState() as any;
|
const s: Everything = store.getState() as any;
|
||||||
maybeRefresh(s.bot.connectivity["bot.mqtt"]);
|
maybeRefresh(s.bot.connectivity.uptime["bot.mqtt"]);
|
||||||
next(action);
|
next(action);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue