2019-04-16 11:03:44 -06:00
|
|
|
import * as React from "react";
|
2019-05-16 13:35:33 -06:00
|
|
|
import { sortBy, isNumber } from "lodash";
|
|
|
|
import { ProblemTag, FirmwareAlertsProps, AlertsProps } from "./interfaces";
|
2019-04-16 11:03:44 -06:00
|
|
|
import { AlertCard } from "./cards";
|
2019-05-16 13:35:33 -06:00
|
|
|
import { Alert } from "farmbot";
|
2019-04-16 11:03:44 -06:00
|
|
|
|
|
|
|
export const splitProblemTag = (problemTag: string): ProblemTag => {
|
|
|
|
const parts = problemTag.split(".");
|
|
|
|
return { author: parts[0], noun: parts[1], verb: parts[2] };
|
|
|
|
};
|
|
|
|
|
|
|
|
export const sortAlerts = (alerts: Alert[]): Alert[] =>
|
|
|
|
sortBy(alerts, "priority", "created_at");
|
|
|
|
|
2019-05-16 13:35:33 -06:00
|
|
|
const filterIncompleteAlerts = (x: Alert) =>
|
|
|
|
x.problem_tag && isNumber(x.priority) && x.created_at;
|
|
|
|
|
2020-03-13 15:06:40 -06:00
|
|
|
export const filterAlerts = (x: Alert) =>
|
|
|
|
x.problem_tag != "farmbot_os.firmware.missing";
|
|
|
|
|
2019-04-16 11:03:44 -06:00
|
|
|
export const FirmwareAlerts = (props: FirmwareAlertsProps) => {
|
2019-07-12 14:39:40 -06:00
|
|
|
const firmwareAlerts = sortAlerts(props.alerts)
|
2019-05-16 13:35:33 -06:00
|
|
|
.filter(filterIncompleteAlerts)
|
2019-04-16 11:03:44 -06:00
|
|
|
.filter(x => splitProblemTag(x.problem_tag).noun === "firmware");
|
|
|
|
return <div className="firmware-alerts">
|
2019-04-18 16:58:09 -06:00
|
|
|
{firmwareAlerts.map((x, i) =>
|
|
|
|
<AlertCard key={i}
|
|
|
|
alert={x}
|
|
|
|
dispatch={props.dispatch}
|
|
|
|
apiFirmwareValue={props.apiFirmwareValue}
|
|
|
|
timeSettings={props.timeSettings} />)}
|
2019-04-16 11:03:44 -06:00
|
|
|
</div>;
|
|
|
|
};
|
|
|
|
|
|
|
|
export const Alerts = (props: AlertsProps) =>
|
|
|
|
<div className="problem-alerts">
|
|
|
|
<div className="problem-alerts-content">
|
2019-04-18 16:58:09 -06:00
|
|
|
{sortAlerts(props.alerts)
|
2019-05-16 13:35:33 -06:00
|
|
|
.filter(filterIncompleteAlerts)
|
2020-03-13 15:06:40 -06:00
|
|
|
.filter(filterAlerts)
|
2019-05-03 13:51:02 -06:00
|
|
|
.map(x =>
|
|
|
|
<AlertCard key={x.slug + x.created_at}
|
2019-04-18 16:58:09 -06:00
|
|
|
alert={x}
|
|
|
|
dispatch={props.dispatch}
|
|
|
|
apiFirmwareValue={props.apiFirmwareValue}
|
|
|
|
timeSettings={props.timeSettings}
|
|
|
|
findApiAlertById={props.findApiAlertById} />)}
|
2019-04-16 11:03:44 -06:00
|
|
|
</div>
|
|
|
|
</div>;
|