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