Merge branch 'develop' into feat/create-monitor-display-name-v2

This commit is contained in:
Peter Carl Pardo committed 2024-11-30 23:06:06 +08:00
commit 0adc8fd037
39 files changed
+345 -744

No files matched your search

@@ -1,5 +1,5 @@
import { Box, Stack, Typography } from "@mui/material";
import Field from "../../../../Components/Inputs/Field";
import TextInput from "../../../../Components/Inputs/TextInput";
import Checkbox from "../../../../Components/Inputs/Checkbox";
import { useTheme } from "@emotion/react";
import PropTypes from "prop-types";
@@ -57,17 +57,17 @@ export const CustomThreshold = ({
justifyContent: "flex-end",
}}
>
<Field
<TextInput
maxWidth="var(--env-var-width-4)"
type="number"
className="field-infrastructure-alert"
id={fieldId}
value={infrastructureMonitor[fieldId]}
onBlur={onFieldBlur}
onChange={onFieldChange}
error={errors[fieldId]}
error={errors[fieldId] ? true : false}
disabled={!infrastructureMonitor[checkboxId]}
hideErrorText={true}
></Field>
/>
<Typography
component="p"
m={theme.spacing(3)}
@@ -12,9 +12,8 @@ import { useNavigate } from "react-router-dom";
import { useTheme } from "@emotion/react";
import { createToast } from "../../../Utils/toastUtils";
import Link from "../../../Components/Link";
import { ConfigBox } from "../../Monitors/styled";
import Field from "../../../Components/Inputs/Field";
import TextInput from "../../../Components/Inputs/TextInput";
import Select from "../../../Components/Inputs/Select";
import Checkbox from "../../../Components/Inputs/Checkbox";
import Breadcrumbs from "../../../Components/Breadcrumbs";
@@ -106,7 +105,6 @@ const CreateInfrastructureMonitor = () => {
event.preventDefault();
const { value, id } = event.target;
let name = appendedId ?? idMap[id] ?? id;
if (name.includes("notification-")) {
name = name.replace("notification-", "");
let hasNotif = infrastructureMonitor.notifications.some(
@@ -263,7 +261,7 @@ const CreateInfrastructureMonitor = () => {
</Stack>
</Box>
<Stack gap={theme.spacing(15)}>
<Field
<TextInput
type="text"
id="url"
label="Server URL"
@@ -271,9 +269,10 @@ const CreateInfrastructureMonitor = () => {
value={infrastructureMonitor.url}
onBlur={handleBlur}
onChange={handleChange}
error={errors["url"]}
error={errors["url"] ? true : false}
helperText={errors["url"]}
/>
<Field
<TextInput
type="text"
id="name"
label="Friendly name"
@@ -283,14 +282,15 @@ const CreateInfrastructureMonitor = () => {
onChange={handleChange}
error={errors["name"]}
/>
<Field
<TextInput
type="text"
id="secret"
label="Authorization secret"
value={infrastructureMonitor.secret}
onBlur={handleBlur}
onChange={handleChange}
error={errors["secret"]}
error={errors["secret"] ? true : false}
helperText={errors["secret"]}
/>
</Stack>
</ConfigBox>
@@ -378,15 +378,6 @@ const CreateInfrastructureMonitor = () => {
onBlur={(e) => handleBlur(e, "interval")}
items={frequencies}
/>
{/* <Field
type={"number"}
id="monitor-retries"
label="Maximum retries before the service is marked as down"
value={infrastructureMonitor.url}
onChange={handleChange}
onBlur={handleBlur}
error={errors["url"]}
/> */}
</Stack>
</ConfigBox>
<Stack
@@ -312,7 +312,7 @@ const InfrastructureDetails = () => {
};
const buildTemps = (checks) => {
let numCores = 0;
let numCores = 1;
if (checks === null) return { temps: [], tempKeys: [] };
for (const check of checks) {
@@ -321,19 +321,16 @@ const InfrastructureDetails = () => {
break;
}
}
if (numCores === 0) return { temps: [], tempKeys: [] };
const temps = checks.map((check) => {
if (check.cpu.temperature.length > numCores) {
numCores = check.cpu.temperature.length;
}
// If there's no data, set the temperature to 0
if (check.cpu.temperature.length === 0) {
if (
check?.cpu?.temperature?.length === 0 ||
check?.cpu?.temperature === undefined ||
check?.cpu?.temperature === null
) {
check.cpu.temperature = Array(numCores).fill(0);
}
return check.cpu.temperature.reduce(
const res = check?.cpu?.temperature?.reduce(
(acc, cur, idx) => {
acc[`core${idx + 1}`] = cur;
return acc;
@@ -342,9 +339,16 @@ const InfrastructureDetails = () => {
createdAt: check.createdAt,
}
);
return res;
});
// Slice to remove `createdAt` key
return { tempKeys: Object.keys(temps[0]).slice(1), temps };
if (temps.length === 0 || !temps[0]) {
return { temps: [], tempKeys: [] };
}
return {
tempKeys: Object.keys(temps[0] || {}).filter((key) => key !== "createdAt"),
temps,
};
};
const buildAreaChartConfigs = (checks) => {
@@ -401,10 +405,13 @@ const InfrastructureDetails = () => {
yLabel: "Temperature",
xTick: <TzTick />,
yDomain: [
Math.min(...tempData.temps.flatMap((t) => tempData.tempKeys.map((k) => t[k]))) *
0.9,
Math.max(...tempData.temps.flatMap((t) => tempData.tempKeys.map((k) => t[k]))) *
1.1,
0,
Math.max(
Math.max(
...tempData.temps.flatMap((t) => tempData.tempKeys.map((k) => t[k]))
) * 1.1,
200
),
],
toolTip: (
<TemperatureTooltip
@@ -537,10 +544,6 @@ const InfrastructureDetails = () => {
}}
>
{areaChartConfigs.map((config) => {
if (config?.data?.length === 0) {
return;
}
return (
<BaseBox key={`${config.type}-${config.diskIndex ?? ""}`}>
<Typography