Skip to content

Commit

Permalink
Merge branch 'remove_bot_alerts_from_fe' of github.com:RickCarlino/fa…
Browse files Browse the repository at this point in the history
…rmbot-web-app into fri
  • Loading branch information
RickCarlino committed Jul 14, 2019
2 parents 23119d4 + c12c221 commit a119276
Show file tree
Hide file tree
Showing 19 changed files with 34 additions and 38 deletions.
2 changes: 1 addition & 1 deletion frontend/app.tsx
Expand Up @@ -75,7 +75,7 @@ export function mapStateToProps(props: Everything): AppProps {
tour: props.resources.consumers.help.currentTour,
resources: props.resources.index,
autoSync: !!(fbosConfig && fbosConfig.auto_sync),
alertCount: getAlerts(props.resources.index, props.bot).length,
alertCount: getAlerts(props.resources.index).length,
};
}
/** Time at which the app gives up and asks the user to refresh */
Expand Down
1 change: 1 addition & 0 deletions frontend/devices/__tests__/devices_test.tsx
Expand Up @@ -32,6 +32,7 @@ describe("<Devices/>", () => {
env: {},
saveFarmwareEnv: jest.fn(),
timeSettings: fakeTimeSettings(),
alerts: [],
});

it("renders relevant panels", () => {
Expand Down
1 change: 1 addition & 0 deletions frontend/devices/__tests__/state_to_props_test.tsx
Expand Up @@ -6,6 +6,7 @@ let mockFbosConfig: TaggedFbosConfig | undefined = fakeFbosConfig();
const mockImages: TaggedImage | undefined = fakeImage();

jest.mock("../../resources/selectors_by_kind", () => ({
selectAllAlerts: () => [],
selectAllFarmEvents: () => [],
selectAllRegimens: () => [],
selectAllLogs: () => [],
Expand Down
Expand Up @@ -29,6 +29,7 @@ describe("<FarmbotOsSettings/>", () => {
diagnostics: [],
dispatch: jest.fn(),
bot,
alerts: [],
botToMqttLastSeen: "",
botToMqttStatus: "up",
sourceFbosConfig: x =>
Expand Down
1 change: 1 addition & 0 deletions frontend/devices/components/farmbot_os_settings.tsx
Expand Up @@ -150,6 +150,7 @@ export class FarmbotOsSettings
<BoardType
botOnline={botOnline}
bot={bot}
alerts={this.props.alerts}
dispatch={this.props.dispatch}
shouldDisplay={this.props.shouldDisplay}
timeSettings={this.props.timeSettings}
Expand Down
Expand Up @@ -23,6 +23,7 @@ describe("<BoardType/>", () => {

const fakeProps = (): BoardTypeProps => ({
bot,
alerts: [],
dispatch: jest.fn(x => x(jest.fn(), () => state)),
sourceFbosConfig: () => ({ value: true, consistent: true }),
shouldDisplay: () => false,
Expand Down
Expand Up @@ -17,7 +17,7 @@ import { fakeTimeSettings } from "../../../../__test_support__/fake_time_setting

describe("<FirmwareHardwareStatusDetails />", () => {
const fakeProps = (): FirmwareHardwareStatusDetailsProps => ({
bot,
alerts: [],
botOnline: true,
apiFirmwareValue: undefined,
botFirmwareValue: undefined,
Expand Down Expand Up @@ -76,6 +76,7 @@ describe("<FirmwareHardwareStatusIcon />", () => {
describe("<FirmwareHardwareStatus />", () => {
const fakeProps = (): FirmwareHardwareStatusProps => ({
bot,
alerts: [],
botOnline: true,
apiFirmwareValue: undefined,
shouldDisplay: () => true,
Expand Down
3 changes: 1 addition & 2 deletions frontend/devices/components/fbos_settings/board_type.tsx
Expand Up @@ -105,8 +105,6 @@ export class BoardType extends React.Component<BoardTypeProps, BoardTypeState> {
return FIRMWARE_CHOICES_DDI["farmduino_k14"];
case "express_k10":
return FIRMWARE_CHOICES_DDI["express_k10"];
case "none":
return FIRMWARE_CHOICES_DDI["none"];
case "unknown":
// If unknown/disconnected, display API FirmwareHardware value if valid
return (this.sending && this.apiValue)
Expand Down Expand Up @@ -148,6 +146,7 @@ export class BoardType extends React.Component<BoardTypeProps, BoardTypeState> {
<FirmwareHardwareStatus
botOnline={this.props.botOnline}
apiFirmwareValue={this.apiValue}
alerts={this.props.alerts}
bot={this.props.bot}
dispatch={this.props.dispatch}
timeSettings={this.props.timeSettings}
Expand Down
Expand Up @@ -7,6 +7,7 @@ import { BotState, Feature, ShouldDisplay } from "../../interfaces";
import { FirmwareAlerts } from "../../../messages/alerts";
import { TimeSettings } from "../../../interfaces";
import { trim } from "../../../util";
import { Alert } from "farmbot";

export interface FirmwareHardwareStatusIconProps {
firmwareHardware: string | undefined;
Expand All @@ -30,7 +31,7 @@ const lookup = (value: string | undefined) =>

export interface FirmwareHardwareStatusDetailsProps {
botOnline: boolean;
bot: BotState;
alerts: Alert[];
apiFirmwareValue: string | undefined;
botFirmwareValue: string | undefined;
mcuFirmwareValue: string | undefined;
Expand Down Expand Up @@ -87,7 +88,7 @@ export const FirmwareHardwareStatusDetails =
botOnline={props.botOnline} />
</div>}
<FirmwareAlerts
bot={props.bot}
alerts={props.alerts}
dispatch={props.dispatch}
apiFirmwareValue={props.apiFirmwareValue}
timeSettings={props.timeSettings} />
Expand All @@ -96,6 +97,7 @@ export const FirmwareHardwareStatusDetails =

export interface FirmwareHardwareStatusProps {
apiFirmwareValue: string | undefined;
alerts: Alert[];
bot: BotState;
botOnline: boolean;
timeSettings: TimeSettings;
Expand All @@ -113,7 +115,7 @@ export const FirmwareHardwareStatus = (props: FirmwareHardwareStatusProps) => {
firmwareHardware={firmware_hardware}
status={status} />
<FirmwareHardwareStatusDetails
bot={props.bot}
alerts={props.alerts}
botOnline={props.botOnline}
apiFirmwareValue={props.apiFirmwareValue}
botFirmwareValue={firmware_hardware}
Expand Down
3 changes: 2 additions & 1 deletion frontend/devices/components/fbos_settings/interfaces.ts
Expand Up @@ -2,7 +2,7 @@ import {
SourceFbosConfig, BotState, ControlPanelState, ShouldDisplay,
SaveFarmwareEnv, UserEnv
} from "../../interfaces";
import { InformationalSettings, TaggedDevice } from "farmbot";
import { InformationalSettings, TaggedDevice, Alert } from "farmbot";
import { TimeSettings } from "../../../interfaces";

export interface AutoSyncRowProps {
Expand Down Expand Up @@ -30,6 +30,7 @@ export interface CameraSelectionState {
export interface BoardTypeProps {
botOnline: boolean;
bot: BotState;
alerts: Alert[];
dispatch: Function;
shouldDisplay: ShouldDisplay;
timeSettings: TimeSettings;
Expand Down
1 change: 1 addition & 0 deletions frontend/devices/devices.tsx
Expand Up @@ -28,6 +28,7 @@ export class Devices extends React.Component<Props, {}> {
diagnostics={selectAllDiagnosticDumps(this.props.resources)}
deviceAccount={this.props.deviceAccount}
dispatch={this.props.dispatch}
alerts={this.props.alerts}
bot={this.props.bot}
timeSettings={this.props.timeSettings}
botToMqttLastSeen={botToMqttLastSeen}
Expand Down
3 changes: 3 additions & 0 deletions frontend/devices/interfaces.ts
Expand Up @@ -10,6 +10,7 @@ import {
TaggedFarmwareInstallation,
JobProgress,
FirmwareHardware,
Alert,
} from "farmbot";
import { ResourceIndex } from "../resources/interfaces";
import { WD_ENV } from "../farmware/weed_detector/remote_env/interfaces";
Expand Down Expand Up @@ -40,6 +41,7 @@ export interface Props {
env: UserEnv;
saveFarmwareEnv: SaveFarmwareEnv;
timeSettings: TimeSettings;
alerts: Alert[];
}

/** Function to save a Farmware env variable to the API. */
Expand Down Expand Up @@ -149,6 +151,7 @@ export type UserEnv = Record<string, string | undefined>;

export interface FarmbotOsProps {
bot: BotState;
alerts: Alert[];
diagnostics: TaggedDiagnosticDump[];
deviceAccount: TaggedDevice;
botToMqttStatus: NetworkState;
Expand Down
2 changes: 2 additions & 0 deletions frontend/devices/state_to_props.ts
Expand Up @@ -18,6 +18,7 @@ import {
} from "../farmware/state_to_props";
import { getFbosConfig, getFirmwareConfig } from "../resources/getters";
import { DevSettings } from "../account/dev/dev_support";
import { getAlerts } from "../messages/state_to_props";

export function mapStateToProps(props: Everything): Props {
const { hardware } = props.bot;
Expand Down Expand Up @@ -49,5 +50,6 @@ export function mapStateToProps(props: Everything): Props {
env,
saveFarmwareEnv: saveOrEditFarmwareEnv(props.resources.index),
timeSettings: maybeGetTimeSettings(props.resources.index),
alerts: getAlerts(props.resources.index),
};
}
10 changes: 3 additions & 7 deletions frontend/messages/__tests__/alerts_test.tsx
@@ -1,7 +1,6 @@
import * as React from "react";
import { mount } from "enzyme";
import { FirmwareAlerts, sortAlerts, Alerts } from "../alerts";
import { bot } from "../../__test_support__/fake_state/bot";
import { fakeTimeSettings } from "../../__test_support__/fake_time_settings";
import { AlertsProps, FirmwareAlertsProps } from "../interfaces";
import { Alert } from "farmbot";
Expand Down Expand Up @@ -69,25 +68,22 @@ describe("<Alerts />", () => {

describe("<FirmwareAlerts />", () => {
const fakeProps = (): FirmwareAlertsProps => ({
bot,
alerts: [],
apiFirmwareValue: undefined,
timeSettings: fakeTimeSettings(),
dispatch: jest.fn(),
});

it("renders no alerts", () => {
const p = fakeProps();
p.bot.hardware.alerts = undefined;
p.alerts = [];
const wrapper = mount(<FirmwareAlerts {...p} />);
expect(wrapper.html()).toEqual(`<div class="firmware-alerts"></div>`);
});

it("renders alerts", () => {
const p = fakeProps();
p.bot.hardware.alerts = {
[FIRMWARE_MISSING_ALERT.slug]: FIRMWARE_MISSING_ALERT,
[UNKNOWN_ALERT.slug]: UNKNOWN_ALERT
};
p.alerts = [FIRMWARE_MISSING_ALERT, UNKNOWN_ALERT];
const wrapper = mount(<FirmwareAlerts {...p} />);
expect(wrapper.text()).toContain("1");
expect(wrapper.text()).toContain("Your device has no firmware");
Expand Down
7 changes: 0 additions & 7 deletions frontend/messages/__tests__/state_to_props_test.ts
Expand Up @@ -6,13 +6,6 @@ import {
} from "../../__test_support__/fake_state/resources";

describe("mapStateToProps()", () => {
it("handles undefined", () => {
const state = fakeState();
state.bot.hardware.alerts = undefined;
const props = mapStateToProps(state);
expect(props.alerts).toEqual([]);
});

it("shows API alerts", () => {
const state = fakeState();
const alert = fakeAlert();
Expand Down
4 changes: 1 addition & 3 deletions frontend/messages/alerts.tsx
@@ -1,5 +1,4 @@
import * as React from "react";
import { betterCompact } from "../util";
import { sortBy, isNumber } from "lodash";
import { ProblemTag, FirmwareAlertsProps, AlertsProps } from "./interfaces";
import { AlertCard } from "./cards";
Expand All @@ -17,8 +16,7 @@ const filterIncompleteAlerts = (x: Alert) =>
x.problem_tag && isNumber(x.priority) && x.created_at;

export const FirmwareAlerts = (props: FirmwareAlertsProps) => {
const alerts = betterCompact(Object.values(props.bot.hardware.alerts || {}));
const firmwareAlerts = sortAlerts(alerts)
const firmwareAlerts = sortAlerts(props.alerts)
.filter(filterIncompleteAlerts)
.filter(x => splitProblemTag(x.problem_tag).noun === "firmware");
return <div className="firmware-alerts">
Expand Down
3 changes: 1 addition & 2 deletions frontend/messages/interfaces.ts
@@ -1,6 +1,5 @@
import { FirmwareHardware, Alert } from "farmbot";
import { TimeSettings } from "../interfaces";
import { BotState } from "../devices/interfaces";
import { UUID } from "../resources/interfaces";

export interface MessagesProps {
Expand All @@ -26,7 +25,7 @@ export interface ProblemTag {
}

export interface FirmwareAlertsProps {
bot: BotState;
alerts: Alert[];
apiFirmwareValue: string | undefined;
timeSettings: TimeSettings;
dispatch: Function;
Expand Down
14 changes: 5 additions & 9 deletions frontend/messages/state_to_props.ts
@@ -1,14 +1,13 @@
import { Everything } from "../interfaces";
import { MessagesProps } from "./interfaces";
import { validFbosConfig, betterCompact } from "../util";
import { validFbosConfig } from "../util";
import { getFbosConfig } from "../resources/getters";
import { sourceFbosConfigValue } from "../devices/components/source_config_value";
import {
selectAllAlerts, maybeGetTimeSettings, findResourceById
} from "../resources/selectors";
import { isFwHardwareValue } from "../devices/components/fbos_settings/board_type";
import { ResourceIndex, UUID } from "../resources/interfaces";
import { BotState } from "../devices/interfaces";
import { Alert } from "farmbot";

export const mapStateToProps = (props: Everything): MessagesProps => {
Expand All @@ -20,7 +19,7 @@ export const mapStateToProps = (props: Everything): MessagesProps => {
const findApiAlertById = (id: number): UUID =>
findResourceById(props.resources.index, "Alert", id);
return {
alerts: getAlerts(props.resources.index, props.bot),
alerts: getAlerts(props.resources.index),
apiFirmwareValue: isFwHardwareValue(apiFirmwareValue)
? apiFirmwareValue : undefined,
timeSettings: maybeGetTimeSettings(props.resources.index),
Expand All @@ -29,9 +28,6 @@ export const mapStateToProps = (props: Everything): MessagesProps => {
};
};

export const getAlerts =
(resourceIndex: ResourceIndex, bot: BotState): Alert[] => {
const botAlerts = betterCompact(Object.values(bot.hardware.alerts || {}));
const apiAlerts = selectAllAlerts(resourceIndex).map(x => x.body);
return botAlerts.concat(apiAlerts);
};
export const getAlerts = (resourceIndex: ResourceIndex): Alert[] => {
return selectAllAlerts(resourceIndex).map(x => x.body);
};
4 changes: 2 additions & 2 deletions frontend/sequences/sequence_editor_middle_active.tsx
Expand Up @@ -92,7 +92,7 @@ export const SequenceSettingsMenu =
label={t("Confirm step deletion")}
description={Content.CONFIRM_STEP_DELETION} />
<SequenceSetting {...commonProps}
setting={"confirm_sequence_deletion" as BooleanConfigKey}
setting={BooleanSetting.confirm_sequence_deletion}
defaultOn={true}
label={t("Confirm sequence deletion")}
description={Content.CONFIRM_SEQUENCE_DELETION} />
Expand Down Expand Up @@ -140,7 +140,7 @@ const SequenceBtnGroup = ({
className="fb-button red"
onClick={() => {
const confirm = getWebAppConfigValue(
"confirm_sequence_deletion" as BooleanConfigKey);
BooleanSetting.confirm_sequence_deletion);
const force = isUndefined(confirm) ? false : !confirm;
dispatch(destroy(sequence.uuid, force))
.then(() => push("/app/sequences/"));
Expand Down

0 comments on commit a119276

Please sign in to comment.