Merge pull request #34 from gabrielburnworth/remove_bot_alerts_from_fe
remove bot alerts from FEpull/1270/head^2
commit
c12c2214e2
|
@ -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 */
|
||||
|
|
|
@ -32,6 +32,7 @@ describe("<Devices/>", () => {
|
|||
env: {},
|
||||
saveFarmwareEnv: jest.fn(),
|
||||
timeSettings: fakeTimeSettings(),
|
||||
alerts: [],
|
||||
});
|
||||
|
||||
it("renders relevant panels", () => {
|
||||
|
|
|
@ -6,6 +6,7 @@ let mockFbosConfig: TaggedFbosConfig | undefined = fakeFbosConfig();
|
|||
const mockImages: TaggedImage | undefined = fakeImage();
|
||||
|
||||
jest.mock("../../resources/selectors_by_kind", () => ({
|
||||
selectAllAlerts: () => [],
|
||||
selectAllFarmEvents: () => [],
|
||||
selectAllRegimens: () => [],
|
||||
selectAllLogs: () => [],
|
||||
|
|
|
@ -29,6 +29,7 @@ describe("<FarmbotOsSettings/>", () => {
|
|||
diagnostics: [],
|
||||
dispatch: jest.fn(),
|
||||
bot,
|
||||
alerts: [],
|
||||
botToMqttLastSeen: "",
|
||||
botToMqttStatus: "up",
|
||||
sourceFbosConfig: x =>
|
||||
|
|
|
@ -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}
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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,
|
||||
|
@ -76,6 +76,7 @@ describe("<FirmwareHardwareStatusIcon />", () => {
|
|||
describe("<FirmwareHardwareStatus />", () => {
|
||||
const fakeProps = (): FirmwareHardwareStatusProps => ({
|
||||
bot,
|
||||
alerts: [],
|
||||
botOnline: true,
|
||||
apiFirmwareValue: undefined,
|
||||
shouldDisplay: () => true,
|
||||
|
|
|
@ -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)
|
||||
|
@ -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}
|
||||
|
|
|
@ -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;
|
||||
|
@ -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;
|
||||
|
@ -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} />
|
||||
|
@ -96,6 +97,7 @@ export const FirmwareHardwareStatusDetails =
|
|||
|
||||
export interface FirmwareHardwareStatusProps {
|
||||
apiFirmwareValue: string | undefined;
|
||||
alerts: Alert[];
|
||||
bot: BotState;
|
||||
botOnline: boolean;
|
||||
timeSettings: TimeSettings;
|
||||
|
@ -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}
|
||||
|
|
|
@ -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 {
|
||||
|
@ -30,6 +30,7 @@ export interface CameraSelectionState {
|
|||
export interface BoardTypeProps {
|
||||
botOnline: boolean;
|
||||
bot: BotState;
|
||||
alerts: Alert[];
|
||||
dispatch: Function;
|
||||
shouldDisplay: ShouldDisplay;
|
||||
timeSettings: TimeSettings;
|
||||
|
|
|
@ -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}
|
||||
|
|
|
@ -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";
|
||||
|
@ -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. */
|
||||
|
@ -149,6 +151,7 @@ export type UserEnv = Record<string, string | undefined>;
|
|||
|
||||
export interface FarmbotOsProps {
|
||||
bot: BotState;
|
||||
alerts: Alert[];
|
||||
diagnostics: TaggedDiagnosticDump[];
|
||||
deviceAccount: TaggedDevice;
|
||||
botToMqttStatus: NetworkState;
|
||||
|
|
|
@ -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;
|
||||
|
@ -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),
|
||||
};
|
||||
}
|
||||
|
|
|
@ -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";
|
||||
|
@ -69,7 +68,7 @@ describe("<Alerts />", () => {
|
|||
|
||||
describe("<FirmwareAlerts />", () => {
|
||||
const fakeProps = (): FirmwareAlertsProps => ({
|
||||
bot,
|
||||
alerts: [],
|
||||
apiFirmwareValue: undefined,
|
||||
timeSettings: fakeTimeSettings(),
|
||||
dispatch: jest.fn(),
|
||||
|
@ -77,17 +76,14 @@ describe("<FirmwareAlerts />", () => {
|
|||
|
||||
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");
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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";
|
||||
|
@ -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">
|
||||
|
|
|
@ -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 {
|
||||
|
@ -26,7 +25,7 @@ export interface ProblemTag {
|
|||
}
|
||||
|
||||
export interface FirmwareAlertsProps {
|
||||
bot: BotState;
|
||||
alerts: Alert[];
|
||||
apiFirmwareValue: string | undefined;
|
||||
timeSettings: TimeSettings;
|
||||
dispatch: Function;
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
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 {
|
||||
|
@ -8,7 +8,6 @@ import {
|
|||
} 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 => {
|
||||
|
@ -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),
|
||||
|
@ -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);
|
||||
};
|
||||
|
|
|
@ -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} />
|
||||
|
@ -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/"));
|
||||
|
|
Loading…
Reference in New Issue