Merge branch 'develop' into feat/be/create-hardware-monitor
This commit is contained in:
commit
49fe463e95
19 files changed
+776
-562
No files matched your search
@@ -38,6 +38,7 @@ const SearchAdornment = () => {
|
|||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
//TODO keep search state inside of component
|
||||||
const Search = ({
|
const Search = ({
|
||||||
id,
|
id,
|
||||||
options,
|
options,
|
||||||
|
|||||||
@@ -12,45 +12,47 @@ import { useNavigate } from "react-router";
|
|||||||
import { getAppSettings, updateAppSettings } from "../../Features/Settings/settingsSlice";
|
import { getAppSettings, updateAppSettings } from "../../Features/Settings/settingsSlice";
|
||||||
import { useState, useEffect } from "react";
|
import { useState, useEffect } from "react";
|
||||||
import Select from "../../Components/Inputs/Select";
|
import Select from "../../Components/Inputs/Select";
|
||||||
|
import { advancedSettingsValidation } from "../../Validation/validation";
|
||||||
|
import { buildErrors, hasValidationErrors } from "../../Validation/error";
|
||||||
|
|
||||||
const AdvancedSettings = ({ isAdmin }) => {
|
const AdvancedSettings = ({ isAdmin }) => {
|
||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
|
useEffect(() => {
|
||||||
|
if (!isAdmin) {
|
||||||
|
navigate("/");
|
||||||
|
}
|
||||||
|
}, [navigate, isAdmin]);
|
||||||
|
|
||||||
useEffect(() => {
|
const theme = useTheme();
|
||||||
if (!isAdmin) {
|
const { authToken } = useSelector((state) => state.auth);
|
||||||
navigate("/");
|
const dispatch = useDispatch();
|
||||||
}
|
const settings = useSelector((state) => state.settings);
|
||||||
}, [navigate, isAdmin]);
|
const [localSettings, setLocalSettings] = useState({
|
||||||
|
apiBaseUrl: "",
|
||||||
|
logLevel: "debug",
|
||||||
|
systemEmailHost: "",
|
||||||
|
systemEmailPort: "",
|
||||||
|
systemEmailAddress: "",
|
||||||
|
systemEmailPassword: "",
|
||||||
|
jwtTTL: "",
|
||||||
|
dbType: "",
|
||||||
|
redisHost: "",
|
||||||
|
redisPort: "",
|
||||||
|
pagespeedApiKey: "",
|
||||||
|
});
|
||||||
|
const [errors, setErrors] = useState({});
|
||||||
|
|
||||||
const theme = useTheme();
|
useEffect(() => {
|
||||||
const { authToken } = useSelector((state) => state.auth);
|
const getSettings = async () => {
|
||||||
const dispatch = useDispatch();
|
const action = await dispatch(getAppSettings({ authToken }));
|
||||||
const settings = useSelector((state) => state.settings);
|
if (action.payload?.success) {
|
||||||
const [localSettings, setLocalSettings] = useState({
|
setLocalSettings(action.payload.data);
|
||||||
apiBaseUrl: "",
|
} else {
|
||||||
logLevel: "debug",
|
createToast({ body: "Failed to get settings" });
|
||||||
systemEmailHost: "",
|
}
|
||||||
systemEmailPort: "",
|
};
|
||||||
systemEmailAddress: "",
|
getSettings();
|
||||||
systemEmailPassword: "",
|
}, [authToken, dispatch]);
|
||||||
jwtTTL: "",
|
|
||||||
dbType: "",
|
|
||||||
redisHost: "",
|
|
||||||
redisPort: "",
|
|
||||||
pagespeedApiKey: "",
|
|
||||||
});
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
const getSettings = async () => {
|
|
||||||
const action = await dispatch(getAppSettings({ authToken }));
|
|
||||||
if (action.payload.success) {
|
|
||||||
setLocalSettings(action.payload.data);
|
|
||||||
} else {
|
|
||||||
createToast({ body: "Failed to get settings" });
|
|
||||||
}
|
|
||||||
};
|
|
||||||
getSettings();
|
|
||||||
}, [authToken, dispatch]);
|
|
||||||
|
|
||||||
const logItems = [
|
const logItems = [
|
||||||
{ _id: 1, name: "none" },
|
{ _id: 1, name: "none" },
|
||||||
@@ -72,189 +74,210 @@ const AdvancedSettings = ({ isAdmin }) => {
|
|||||||
setLocalSettings({ ...localSettings, logLevel: newLogLevel });
|
setLocalSettings({ ...localSettings, logLevel: newLogLevel });
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleChange = (event) => {
|
const handleChange = (event) => {
|
||||||
const { value, id } = event.target;
|
const { value, id } = event.target;
|
||||||
setLocalSettings({ ...localSettings, [id]: value });
|
setLocalSettings({ ...localSettings, [id]: value });
|
||||||
};
|
const { error } = advancedSettingsValidation.validate(
|
||||||
|
{ [id]: value },
|
||||||
|
{
|
||||||
|
abortEarly: false,
|
||||||
|
}
|
||||||
|
);
|
||||||
|
setErrors((prev) => {
|
||||||
|
return buildErrors(prev, id, error);
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
const handleSave = async () => {
|
const handleSave = async () => {
|
||||||
const action = await dispatch(
|
if (hasValidationErrors(localSettings, advancedSettingsValidation, setErrors))
|
||||||
updateAppSettings({ settings: localSettings, authToken })
|
return;
|
||||||
);
|
const action = await dispatch(
|
||||||
let body = "";
|
updateAppSettings({ settings: localSettings, authToken })
|
||||||
if (action.payload.success) {
|
);
|
||||||
console.log(action.payload.data);
|
let body = "";
|
||||||
setLocalSettings(action.payload.data);
|
if (action.payload.success) {
|
||||||
body = "Settings saved successfully";
|
console.log(action.payload.data);
|
||||||
} else {
|
setLocalSettings(action.payload.data);
|
||||||
body = "Failed to save settings";
|
body = "Settings saved successfully";
|
||||||
}
|
} else {
|
||||||
createToast({ body });
|
body = "Failed to save settings";
|
||||||
};
|
}
|
||||||
|
createToast({ body });
|
||||||
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Box
|
<Box
|
||||||
className="settings"
|
className="settings"
|
||||||
style={{
|
style={{
|
||||||
paddingBottom: 0,
|
paddingBottom: 0,
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<Stack
|
<Stack
|
||||||
component="form"
|
component="form"
|
||||||
gap={theme.spacing(12)}
|
gap={theme.spacing(12)}
|
||||||
noValidate
|
noValidate
|
||||||
spellCheck="false"
|
spellCheck="false"
|
||||||
>
|
>
|
||||||
<ConfigBox>
|
<ConfigBox>
|
||||||
<Box>
|
<Box>
|
||||||
<Typography component="h1">Client settings</Typography>
|
<Typography component="h1">Client settings</Typography>
|
||||||
<Typography sx={{ mt: theme.spacing(2) }}>
|
<Typography sx={{ mt: theme.spacing(2) }}>
|
||||||
Modify client settings here.
|
Modify client settings here.
|
||||||
</Typography>
|
</Typography>
|
||||||
</Box>
|
</Box>
|
||||||
<Stack gap={theme.spacing(20)}>
|
<Stack gap={theme.spacing(20)}>
|
||||||
<Field
|
<Field
|
||||||
id="apiBaseUrl"
|
id="apiBaseUrl"
|
||||||
label="API URL Host"
|
label="API URL Host"
|
||||||
value={localSettings.apiBaseUrl}
|
value={localSettings.apiBaseUrl}
|
||||||
onChange={handleChange}
|
onChange={handleChange}
|
||||||
/>
|
error={errors.apiBaseUrl}
|
||||||
<Select
|
/>
|
||||||
id="logLevel"
|
<Select
|
||||||
label="Log level"
|
id="logLevel"
|
||||||
name="logLevel"
|
label="Log level"
|
||||||
items={logItems}
|
name="logLevel"
|
||||||
value={logItemLookup[localSettings.logLevel]}
|
items={logItems}
|
||||||
onChange={handleLogLevel}
|
value={logItemLookup[localSettings.logLevel]}
|
||||||
/>
|
onChange={handleLogLevel}
|
||||||
</Stack>
|
error={errors.logLevel}
|
||||||
</ConfigBox>
|
/>
|
||||||
<ConfigBox>
|
</Stack>
|
||||||
<Box>
|
</ConfigBox>
|
||||||
<Typography component="h1">Email settings</Typography>
|
<ConfigBox>
|
||||||
<Typography sx={{ mt: theme.spacing(2) }}>
|
<Box>
|
||||||
Set your host email settings here. These settings are used for sending
|
<Typography component="h1">Email settings</Typography>
|
||||||
system emails.
|
<Typography sx={{ mt: theme.spacing(2) }}>
|
||||||
</Typography>
|
Set your host email settings here. These settings are used for
|
||||||
</Box>
|
sending system emails.
|
||||||
<Stack gap={theme.spacing(20)}>
|
</Typography>
|
||||||
<Field
|
</Box>
|
||||||
type="text"
|
<Stack gap={theme.spacing(20)}>
|
||||||
id="systemEmailHost"
|
<Field
|
||||||
label="Email host"
|
type="text"
|
||||||
name="systemEmailHost"
|
id="systemEmailHost"
|
||||||
value={localSettings.systemEmailHost}
|
label="Email host"
|
||||||
onChange={handleChange}
|
name="systemEmailHost"
|
||||||
/>
|
value={localSettings.systemEmailHost}
|
||||||
<Field
|
onChange={handleChange}
|
||||||
type="number"
|
error={errors.systemEmailHost}
|
||||||
id="systemEmailPort"
|
/>
|
||||||
label="System email address"
|
<Field
|
||||||
name="systemEmailPort"
|
type="number"
|
||||||
value={localSettings.systemEmailPort.toString()}
|
id="systemEmailPort"
|
||||||
onChange={handleChange}
|
label="System email address"
|
||||||
/>
|
name="systemEmailPort"
|
||||||
<Field
|
value={localSettings.systemEmailPort.toString()}
|
||||||
type="email"
|
onChange={handleChange}
|
||||||
id="systemEmailAddress"
|
error={errors.systemEmailPort}
|
||||||
label="System email address"
|
/>
|
||||||
name="systemEmailAddress"
|
<Field
|
||||||
value={localSettings.systemEmailAddress}
|
type="email"
|
||||||
onChange={handleChange}
|
id="systemEmailAddress"
|
||||||
/>
|
label="System email address"
|
||||||
<Field
|
name="systemEmailAddress"
|
||||||
type="text"
|
value={localSettings.systemEmailAddress}
|
||||||
id="systemEmailPassword"
|
onChange={handleChange}
|
||||||
label="System email password"
|
error={errors.systemEmailAddress}
|
||||||
name="systemEmailPassword"
|
/>
|
||||||
value={localSettings.systemEmailPassword}
|
<Field
|
||||||
onChange={handleChange}
|
type="text"
|
||||||
/>
|
id="systemEmailPassword"
|
||||||
</Stack>
|
label="System email password"
|
||||||
</ConfigBox>
|
name="systemEmailPassword"
|
||||||
<ConfigBox>
|
value={localSettings.systemEmailPassword}
|
||||||
<Box>
|
onChange={handleChange}
|
||||||
<Typography component="h1">Server settings</Typography>
|
error={errors.systemEmailPassword}
|
||||||
<Typography sx={{ mt: theme.spacing(2) }}>
|
/>
|
||||||
Modify server settings here.
|
</Stack>
|
||||||
</Typography>
|
</ConfigBox>
|
||||||
</Box>
|
<ConfigBox>
|
||||||
<Stack gap={theme.spacing(20)}>
|
<Box>
|
||||||
<Field
|
<Typography component="h1">Server settings</Typography>
|
||||||
type="text"
|
<Typography sx={{ mt: theme.spacing(2) }}>
|
||||||
id="jwtTTL"
|
Modify server settings here.
|
||||||
label="JWT time to live"
|
</Typography>
|
||||||
name="jwtTTL"
|
</Box>
|
||||||
value={localSettings.jwtTTL}
|
<Stack gap={theme.spacing(20)}>
|
||||||
onChange={handleChange}
|
<Field
|
||||||
/>
|
type="text"
|
||||||
<Field
|
id="jwtTTL"
|
||||||
type="text"
|
label="JWT time to live"
|
||||||
id="dbType"
|
name="jwtTTL"
|
||||||
label="Database type"
|
value={localSettings.jwtTTL}
|
||||||
name="dbType"
|
onChange={handleChange}
|
||||||
value={localSettings.dbType}
|
error={errors.jwtTTL}
|
||||||
onChange={handleChange}
|
/>
|
||||||
/>
|
<Field
|
||||||
<Field
|
type="text"
|
||||||
type="text"
|
id="dbType"
|
||||||
id="redisHost"
|
label="Database type"
|
||||||
label="Redis host"
|
name="dbType"
|
||||||
name="redisHost"
|
value={localSettings.dbType}
|
||||||
value={localSettings.redisHost}
|
onChange={handleChange}
|
||||||
onChange={handleChange}
|
error={errors.dbType}
|
||||||
/>
|
/>
|
||||||
<Field
|
<Field
|
||||||
type="number"
|
type="text"
|
||||||
id="redisPort"
|
id="redisHost"
|
||||||
label="Redis port"
|
label="Redis host"
|
||||||
name="redisPort"
|
name="redisHost"
|
||||||
value={localSettings.redisPort.toString()}
|
value={localSettings.redisHost}
|
||||||
onChange={handleChange}
|
onChange={handleChange}
|
||||||
/>
|
error={errors.redisHost}
|
||||||
<Field
|
/>
|
||||||
type="text"
|
<Field
|
||||||
id="pagespeedApiKey"
|
type="number"
|
||||||
label="PageSpeed API key"
|
id="redisPort"
|
||||||
name="pagespeedApiKey"
|
label="Redis port"
|
||||||
value={localSettings.pagespeedApiKey}
|
name="redisPort"
|
||||||
onChange={handleChange}
|
value={localSettings.redisPort.toString()}
|
||||||
/>
|
onChange={handleChange}
|
||||||
</Stack>
|
error={errors.redisPort}
|
||||||
</ConfigBox>
|
/>
|
||||||
<ConfigBox>
|
<Field
|
||||||
<Box>
|
type="text"
|
||||||
<Typography component="h1">About</Typography>
|
id="pagespeedApiKey"
|
||||||
</Box>
|
label="PageSpeed API key"
|
||||||
<Box>
|
name="pagespeedApiKey"
|
||||||
<Typography component="h2">BlueWave Uptime v1.0.0</Typography>
|
value={localSettings.pagespeedApiKey}
|
||||||
<Typography sx={{ mt: theme.spacing(2), mb: theme.spacing(6), opacity: 0.6 }}>
|
onChange={handleChange}
|
||||||
Developed by Bluewave Labs.
|
error={errors.pagespeedApiKey}
|
||||||
</Typography>
|
/>
|
||||||
<Link
|
</Stack>
|
||||||
level="secondary"
|
</ConfigBox>
|
||||||
url="https://github.com/bluewave-labs"
|
<ConfigBox>
|
||||||
label="https://github.com/bluewave-labs"
|
<Box>
|
||||||
/>
|
<Typography component="h1">About</Typography>
|
||||||
</Box>
|
</Box>
|
||||||
</ConfigBox>
|
<Box>
|
||||||
<Stack
|
<Typography component="h2">BlueWave Uptime v1.0.0</Typography>
|
||||||
direction="row"
|
<Typography
|
||||||
justifyContent="flex-end"
|
sx={{ mt: theme.spacing(2), mb: theme.spacing(6), opacity: 0.6 }}
|
||||||
>
|
>
|
||||||
<LoadingButton
|
Developed by Bluewave Labs.
|
||||||
loading={settings.isLoading || settings.authIsLoading}
|
</Typography>
|
||||||
variant="contained"
|
<Link
|
||||||
color="primary"
|
level="secondary"
|
||||||
sx={{ px: theme.spacing(12), mt: theme.spacing(20) }}
|
url="https://github.com/bluewave-labs"
|
||||||
onClick={handleSave}
|
label="https://github.com/bluewave-labs"
|
||||||
>
|
/>
|
||||||
Save
|
</Box>
|
||||||
</LoadingButton>
|
</ConfigBox>
|
||||||
</Stack>
|
<Stack direction="row" justifyContent="flex-end">
|
||||||
</Stack>
|
<LoadingButton
|
||||||
</Box>
|
loading={settings.isLoading || settings.authIsLoading}
|
||||||
);
|
variant="contained"
|
||||||
|
color="primary"
|
||||||
|
sx={{ px: theme.spacing(12), mt: theme.spacing(20) }}
|
||||||
|
onClick={handleSave}
|
||||||
|
>
|
||||||
|
Save
|
||||||
|
</LoadingButton>
|
||||||
|
</Stack>
|
||||||
|
</Stack>
|
||||||
|
</Box>
|
||||||
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
AdvancedSettings.propTypes = {
|
AdvancedSettings.propTypes = {
|
||||||
|
|||||||
@@ -0,0 +1,32 @@
|
|||||||
|
import { useTheme } from "@emotion/react";
|
||||||
|
import PlaceholderLight from "../../../../assets/Images/data_placeholder.svg?react";
|
||||||
|
import PlaceholderDark from "../../../../assets/Images/data_placeholder_dark.svg?react";
|
||||||
|
import { Box, Typography } from "@mui/material";
|
||||||
|
import PropTypes from "prop-types";
|
||||||
|
|
||||||
|
const Empty = ({ styles, mode }) => {
|
||||||
|
const theme = useTheme();
|
||||||
|
return (
|
||||||
|
<Box sx={{ ...styles }}>
|
||||||
|
<Box
|
||||||
|
textAlign="center"
|
||||||
|
pb={theme.spacing(20)}
|
||||||
|
>
|
||||||
|
{mode === "light" ? <PlaceholderLight /> : <PlaceholderDark />}
|
||||||
|
</Box>
|
||||||
|
<Typography
|
||||||
|
textAlign="center"
|
||||||
|
color={theme.palette.text.secondary}
|
||||||
|
>
|
||||||
|
No incidents recorded yet.
|
||||||
|
</Typography>
|
||||||
|
</Box>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
Empty.propTypes = {
|
||||||
|
styles: PropTypes.object,
|
||||||
|
mode: PropTypes.string,
|
||||||
|
};
|
||||||
|
|
||||||
|
export { Empty };
|
||||||
@@ -0,0 +1,21 @@
|
|||||||
|
import { Skeleton /* , Stack */ } from "@mui/material";
|
||||||
|
const IncidentSkeleton = () => {
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<Skeleton
|
||||||
|
animation={"wave"}
|
||||||
|
variant="rounded"
|
||||||
|
width="100%"
|
||||||
|
height={300}
|
||||||
|
/>
|
||||||
|
<Skeleton
|
||||||
|
animation={"wave"}
|
||||||
|
variant="rounded"
|
||||||
|
width="100%"
|
||||||
|
height={100}
|
||||||
|
/>
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export { IncidentSkeleton };
|
||||||
@@ -24,6 +24,8 @@ import { useTheme } from "@emotion/react";
|
|||||||
import { formatDateWithTz } from "../../../Utils/timeUtils";
|
import { formatDateWithTz } from "../../../Utils/timeUtils";
|
||||||
import PlaceholderLight from "../../../assets/Images/data_placeholder.svg?react";
|
import PlaceholderLight from "../../../assets/Images/data_placeholder.svg?react";
|
||||||
import PlaceholderDark from "../../../assets/Images/data_placeholder_dark.svg?react";
|
import PlaceholderDark from "../../../assets/Images/data_placeholder_dark.svg?react";
|
||||||
|
import { Empty } from "./Empty/Empty";
|
||||||
|
import { IncidentSkeleton } from "./Skeleton/Skeleton";
|
||||||
|
|
||||||
const IncidentTable = ({ monitors, selectedMonitor, filter }) => {
|
const IncidentTable = ({ monitors, selectedMonitor, filter }) => {
|
||||||
const uiTimezone = useSelector((state) => state.ui.timezone);
|
const uiTimezone = useSelector((state) => state.ui.timezone);
|
||||||
@@ -37,6 +39,7 @@ const IncidentTable = ({ monitors, selectedMonitor, filter }) => {
|
|||||||
page: 0,
|
page: 0,
|
||||||
rowsPerPage: 14,
|
rowsPerPage: 14,
|
||||||
});
|
});
|
||||||
|
const [isLoading, setIsLoading] = useState(true);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
setPaginationController((prevPaginationController) => ({
|
setPaginationController((prevPaginationController) => ({
|
||||||
@@ -51,6 +54,7 @@ const IncidentTable = ({ monitors, selectedMonitor, filter }) => {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
|
setIsLoading(true);
|
||||||
let res;
|
let res;
|
||||||
if (selectedMonitor === "0") {
|
if (selectedMonitor === "0") {
|
||||||
res = await networkService.getChecksByTeam({
|
res = await networkService.getChecksByTeam({
|
||||||
@@ -79,6 +83,8 @@ const IncidentTable = ({ monitors, selectedMonitor, filter }) => {
|
|||||||
setChecksCount(res.data.data.checksCount);
|
setChecksCount(res.data.data.checksCount);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
logger.error(error);
|
logger.error(error);
|
||||||
|
} finally {
|
||||||
|
setIsLoading(false);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
fetchPage();
|
fetchPage();
|
||||||
@@ -129,24 +135,20 @@ const IncidentTable = ({ monitors, selectedMonitor, filter }) => {
|
|||||||
p: theme.spacing(30),
|
p: theme.spacing(30),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const hasChecks = checks?.length === 0;
|
||||||
|
const noIncidentsRecordedYet = hasChecks && selectedMonitor === "0";
|
||||||
|
const noIncidentsForThatMonitor = hasChecks && selectedMonitor !== "0";
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
{checks?.length === 0 && selectedMonitor === "0" ? (
|
{isLoading ? (
|
||||||
<Box sx={{ ...sharedStyles }}>
|
<IncidentSkeleton />
|
||||||
<Box
|
) : noIncidentsRecordedYet ? (
|
||||||
textAlign="center"
|
<Empty
|
||||||
pb={theme.spacing(20)}
|
mode={mode}
|
||||||
>
|
styles={sharedStyles}
|
||||||
{mode === "light" ? <PlaceholderLight /> : <PlaceholderDark />}
|
/>
|
||||||
</Box>
|
) : noIncidentsForThatMonitor ? (
|
||||||
<Typography
|
|
||||||
textAlign="center"
|
|
||||||
color={theme.palette.text.secondary}
|
|
||||||
>
|
|
||||||
No incidents recorded yet.
|
|
||||||
</Typography>
|
|
||||||
</Box>
|
|
||||||
) : checks?.length === 0 ? (
|
|
||||||
<Box sx={{ ...sharedStyles }}>
|
<Box sx={{ ...sharedStyles }}>
|
||||||
<Box
|
<Box
|
||||||
textAlign="center"
|
textAlign="center"
|
||||||
|
|||||||
@@ -17,56 +17,62 @@ const Incidents = () => {
|
|||||||
|
|
||||||
const [monitors, setMonitors] = useState({});
|
const [monitors, setMonitors] = useState({});
|
||||||
const [selectedMonitor, setSelectedMonitor] = useState("0");
|
const [selectedMonitor, setSelectedMonitor] = useState("0");
|
||||||
const [loading, setLoading] = useState(false);
|
const [isLoading, setIsLoading] = useState(true);
|
||||||
|
|
||||||
// TODO do something with these filters
|
// TODO do something with these filters
|
||||||
const [filter, setFilter] = useState("all");
|
const [filter, setFilter] = useState("all");
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const fetchMonitors = async () => {
|
const fetchMonitors = async () => {
|
||||||
setLoading(true);
|
try {
|
||||||
const res = await networkService.getMonitorsByTeamId({
|
setIsLoading(true);
|
||||||
authToken: authState.authToken,
|
const res = await networkService.getMonitorsByTeamId({
|
||||||
teamId: authState.user.teamId,
|
authToken: authState.authToken,
|
||||||
limit: -1,
|
teamId: authState.user.teamId,
|
||||||
types: null,
|
limit: -1,
|
||||||
status: null,
|
types: null,
|
||||||
checkOrder: null,
|
status: null,
|
||||||
normalize: null,
|
checkOrder: null,
|
||||||
page: null,
|
normalize: null,
|
||||||
rowsPerPage: null,
|
page: null,
|
||||||
filter: null,
|
rowsPerPage: null,
|
||||||
field: null,
|
filter: null,
|
||||||
order: null,
|
field: null,
|
||||||
});
|
order: null,
|
||||||
// Reduce to a lookup object for 0(1) lookup
|
});
|
||||||
if (res?.data?.data?.monitors?.length > 0) {
|
// Reduce to a lookup object for 0(1) lookup
|
||||||
const monitorLookup = res.data.data.monitors.reduce((acc, monitor) => {
|
if (res?.data?.data?.monitors?.length > 0) {
|
||||||
acc[monitor._id] = monitor;
|
const monitorLookup = res.data.data.monitors.reduce((acc, monitor) => {
|
||||||
return acc;
|
acc[monitor._id] = monitor;
|
||||||
}, {});
|
return acc;
|
||||||
setMonitors(monitorLookup);
|
}, {});
|
||||||
monitorId !== undefined && setSelectedMonitor(monitorId);
|
setMonitors(monitorLookup);
|
||||||
|
monitorId !== undefined && setSelectedMonitor(monitorId);
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.info(error);
|
||||||
|
} finally {
|
||||||
|
setIsLoading(false);
|
||||||
}
|
}
|
||||||
setLoading(false);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
fetchMonitors();
|
fetchMonitors();
|
||||||
}, [authState]);
|
}, [authState]);
|
||||||
|
|
||||||
useEffect(() => {}, []);
|
useEffect(() => {}, [monitors]);
|
||||||
|
|
||||||
const handleSelect = (event) => {
|
const handleSelect = (event) => {
|
||||||
setSelectedMonitor(event.target.value);
|
setSelectedMonitor(event.target.value);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const isActuallyLoading = isLoading && Object.keys(monitors)?.length === 0;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Stack
|
<Stack
|
||||||
className="incidents table-container"
|
className="incidents"
|
||||||
pt={theme.spacing(6)}
|
pt={theme.spacing(6)}
|
||||||
gap={theme.spacing(12)}
|
gap={theme.spacing(12)}
|
||||||
>
|
>
|
||||||
{loading ? (
|
{isActuallyLoading ? (
|
||||||
<SkeletonLayout />
|
<SkeletonLayout />
|
||||||
) : (
|
) : (
|
||||||
<>
|
<>
|
||||||
|
|||||||
@@ -28,6 +28,7 @@ import {
|
|||||||
MS_PER_WEEK,
|
MS_PER_WEEK,
|
||||||
} from "../../../Utils/timeUtils";
|
} from "../../../Utils/timeUtils";
|
||||||
import { useNavigate, useParams } from "react-router-dom";
|
import { useNavigate, useParams } from "react-router-dom";
|
||||||
|
import { buildErrors, hasValidationErrors } from "../../../Validation/error";
|
||||||
|
|
||||||
const getDurationAndUnit = (durationInMs) => {
|
const getDurationAndUnit = (durationInMs) => {
|
||||||
if (durationInMs % MS_PER_DAY === 0) {
|
if (durationInMs % MS_PER_DAY === 0) {
|
||||||
@@ -145,46 +146,36 @@ const CreateMaintenance = () => {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const res = await networkService.getMaintenanceWindowById({
|
const res = await networkService.getMaintenanceWindowById({
|
||||||
authToken: authToken,
|
authToken: authToken,
|
||||||
maintenanceWindowId: maintenanceWindowId,
|
maintenanceWindowId: maintenanceWindowId,
|
||||||
});
|
});
|
||||||
const maintenanceWindow = res.data.data;
|
const maintenanceWindow = res.data.data;
|
||||||
const { name, start, end, repeat, monitorId } = maintenanceWindow;
|
const { name, start, end, repeat, monitorId } = maintenanceWindow;
|
||||||
const startTime = dayjs(start);
|
const startTime = dayjs(start);
|
||||||
const endTime = dayjs(end);
|
const endTime = dayjs(end);
|
||||||
const durationInMs = endTime.diff(startTime, "milliseconds").toString();
|
const durationInMs = endTime.diff(startTime, "milliseconds").toString();
|
||||||
const { duration, durationUnit } = getDurationAndUnit(durationInMs);
|
const { duration, durationUnit } = getDurationAndUnit(durationInMs);
|
||||||
const monitor = monitors.find((monitor) => monitor._id === monitorId);
|
const monitor = monitors.find((monitor) => monitor._id === monitorId);
|
||||||
setForm({
|
setForm({
|
||||||
...form,
|
...form,
|
||||||
name,
|
name,
|
||||||
repeat: REVERSE_REPEAT_LOOKUP[repeat],
|
repeat: REVERSE_REPEAT_LOOKUP[repeat],
|
||||||
startDate: startTime,
|
startDate: startTime,
|
||||||
startTime,
|
startTime,
|
||||||
duration,
|
duration,
|
||||||
durationUnit,
|
durationUnit,
|
||||||
monitors: monitor ? [monitor] : [],
|
monitors: monitor ? [monitor] : [],
|
||||||
});
|
});
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
createToast({ body: "Failed to fetch data" });
|
createToast({ body: "Failed to fetch data" });
|
||||||
logger.error("Failed to fetch monitors", error);
|
logger.error("Failed to fetch monitors", error);
|
||||||
} finally {
|
} finally {
|
||||||
setIsLoading(false);
|
setIsLoading(false);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
fetchMonitors();
|
fetchMonitors();
|
||||||
}, [authToken, user]);
|
}, [authToken, user]);
|
||||||
|
|
||||||
const buildErrors = (prev, id, error) => {
|
|
||||||
const updatedErrors = { ...prev };
|
|
||||||
if (error) {
|
|
||||||
updatedErrors[id] = error.details[0].message;
|
|
||||||
} else {
|
|
||||||
delete updatedErrors[id];
|
|
||||||
}
|
|
||||||
return updatedErrors;
|
|
||||||
};
|
|
||||||
|
|
||||||
const handleSearch = (value) => {
|
const handleSearch = (value) => {
|
||||||
setSearch(value);
|
setSearch(value);
|
||||||
@@ -223,29 +214,17 @@ const CreateMaintenance = () => {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleSubmit = async () => {
|
const handleSubmit = async () => {
|
||||||
const { error } = maintenanceWindowValidation.validate(form, {
|
if(hasValidationErrors(form, maintenanceWindowValidation, setErrors))
|
||||||
abortEarly: false,
|
return;
|
||||||
});
|
// Build timestamp for maintenance window from startDate and startTime
|
||||||
|
const start = dayjs(form.startDate)
|
||||||
// If errors, return early
|
.set("hour", form.startTime.hour())
|
||||||
if (error) {
|
.set("minute", form.startTime.minute());
|
||||||
const newErrors = {};
|
// Build end timestamp for maintenance window
|
||||||
error.details.forEach((err) => {
|
const MS_MULTIPLIER = MS_LOOKUP[form.durationUnit];
|
||||||
newErrors[err.path[0]] = err.message;
|
const durationInMs = form.duration * MS_MULTIPLIER;
|
||||||
});
|
const end = start.add(durationInMs);
|
||||||
setErrors(newErrors);
|
|
||||||
logger.error(error);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
// Build timestamp for maintenance window from startDate and startTime
|
|
||||||
const start = dayjs(form.startDate)
|
|
||||||
.set("hour", form.startTime.hour())
|
|
||||||
.set("minute", form.startTime.minute());
|
|
||||||
// Build end timestamp for maintenance window
|
|
||||||
const MS_MULTIPLIER = MS_LOOKUP[form.durationUnit];
|
|
||||||
const durationInMs = form.duration * MS_MULTIPLIER;
|
|
||||||
const end = start.add(durationInMs);
|
|
||||||
|
|
||||||
// Get repeat value in milliseconds
|
// Get repeat value in milliseconds
|
||||||
const repeat = REPEAT_LOOKUP[form.repeat];
|
const repeat = REPEAT_LOOKUP[form.repeat];
|
||||||
|
|||||||
@@ -0,0 +1,79 @@
|
|||||||
|
import { useTheme } from "@emotion/react";
|
||||||
|
import { Box, Stack, Typography } from "@mui/material";
|
||||||
|
import Search from "../../../../Components/Inputs/Search";
|
||||||
|
import MemoizedMonitorTable from "../MonitorTable";
|
||||||
|
import { useState } from "react";
|
||||||
|
import useDebounce from "../../../../Utils/debounce";
|
||||||
|
import PropTypes from "prop-types";
|
||||||
|
|
||||||
|
const CurrentMonitoring = ({ totalMonitors, monitors, isAdmin }) => {
|
||||||
|
const theme = useTheme();
|
||||||
|
const [search, setSearch] = useState("");
|
||||||
|
const [isSearching, setIsSearching] = useState(false);
|
||||||
|
const debouncedFilter = useDebounce(search, 500);
|
||||||
|
const handleSearch = (value) => {
|
||||||
|
setIsSearching(true);
|
||||||
|
setSearch(value);
|
||||||
|
};
|
||||||
|
return (
|
||||||
|
<Box
|
||||||
|
flex={1}
|
||||||
|
px={theme.spacing(10)}
|
||||||
|
py={theme.spacing(8)}
|
||||||
|
border={1}
|
||||||
|
borderColor={theme.palette.border.light}
|
||||||
|
borderRadius={theme.shape.borderRadius}
|
||||||
|
backgroundColor={theme.palette.background.main}
|
||||||
|
>
|
||||||
|
<Stack
|
||||||
|
direction="row"
|
||||||
|
alignItems="center"
|
||||||
|
mb={theme.spacing(8)}
|
||||||
|
>
|
||||||
|
<Typography
|
||||||
|
component="h2"
|
||||||
|
variant="h2"
|
||||||
|
fontWeight={500}
|
||||||
|
letterSpacing={-0.2}
|
||||||
|
>
|
||||||
|
Actively monitoring
|
||||||
|
</Typography>
|
||||||
|
<Box
|
||||||
|
className="current-monitors-counter"
|
||||||
|
color={theme.palette.text.primary}
|
||||||
|
border={1}
|
||||||
|
borderColor={theme.palette.border.light}
|
||||||
|
backgroundColor={theme.palette.background.accent}
|
||||||
|
>
|
||||||
|
{totalMonitors}
|
||||||
|
</Box>
|
||||||
|
<Box
|
||||||
|
width="25%"
|
||||||
|
minWidth={150}
|
||||||
|
ml="auto"
|
||||||
|
>
|
||||||
|
<Search
|
||||||
|
options={monitors}
|
||||||
|
filteredBy="name"
|
||||||
|
inputValue={search}
|
||||||
|
handleInputChange={handleSearch}
|
||||||
|
/>
|
||||||
|
</Box>
|
||||||
|
</Stack>
|
||||||
|
<MemoizedMonitorTable
|
||||||
|
isAdmin={isAdmin}
|
||||||
|
filter={debouncedFilter}
|
||||||
|
setIsSearching={setIsSearching}
|
||||||
|
isSearching={isSearching}
|
||||||
|
/>
|
||||||
|
</Box>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
CurrentMonitoring.propTypes = {
|
||||||
|
totalMonitors: PropTypes.number,
|
||||||
|
monitors: PropTypes.array,
|
||||||
|
isAdmin: PropTypes.bool,
|
||||||
|
};
|
||||||
|
|
||||||
|
export { CurrentMonitoring };
|
||||||
@@ -0,0 +1,31 @@
|
|||||||
|
import { Skeleton, TableCell, TableRow } from "@mui/material";
|
||||||
|
const ROWS_NUMBER = 7;
|
||||||
|
const ROWS_ARRAY = Array.from({ length: ROWS_NUMBER }, (_, i) => i);
|
||||||
|
|
||||||
|
const TableBodySkeleton = () => {
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
{ROWS_ARRAY.map((row) => (
|
||||||
|
<TableRow key={row}>
|
||||||
|
<TableCell>
|
||||||
|
<Skeleton />
|
||||||
|
</TableCell>
|
||||||
|
<TableCell>
|
||||||
|
<Skeleton />
|
||||||
|
</TableCell>
|
||||||
|
<TableCell>
|
||||||
|
<Skeleton />
|
||||||
|
</TableCell>
|
||||||
|
<TableCell>
|
||||||
|
<Skeleton />
|
||||||
|
</TableCell>
|
||||||
|
<TableCell>
|
||||||
|
<Skeleton />
|
||||||
|
</TableCell>
|
||||||
|
</TableRow>
|
||||||
|
))}
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export { TableBodySkeleton };
|
||||||
@@ -12,6 +12,7 @@ import {
|
|||||||
Stack,
|
Stack,
|
||||||
Typography,
|
Typography,
|
||||||
Button,
|
Button,
|
||||||
|
CircularProgress,
|
||||||
} from "@mui/material";
|
} from "@mui/material";
|
||||||
import ArrowDownwardRoundedIcon from "@mui/icons-material/ArrowDownwardRounded";
|
import ArrowDownwardRoundedIcon from "@mui/icons-material/ArrowDownwardRounded";
|
||||||
import ArrowUpwardRoundedIcon from "@mui/icons-material/ArrowUpwardRounded";
|
import ArrowUpwardRoundedIcon from "@mui/icons-material/ArrowUpwardRounded";
|
||||||
@@ -34,6 +35,7 @@ import RightArrow from "../../../../assets/icons/right-arrow.svg?react";
|
|||||||
import SelectorVertical from "../../../../assets/icons/selector-vertical.svg?react";
|
import SelectorVertical from "../../../../assets/icons/selector-vertical.svg?react";
|
||||||
import ActionsMenu from "../actionsMenu";
|
import ActionsMenu from "../actionsMenu";
|
||||||
import useUtils from "../../utils";
|
import useUtils from "../../utils";
|
||||||
|
import { TableBodySkeleton } from "./Skeleton";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Component for pagination actions (first, previous, next, last).
|
* Component for pagination actions (first, previous, next, last).
|
||||||
@@ -107,17 +109,17 @@ TablePaginationActions.propTypes = {
|
|||||||
onPageChange: PropTypes.func.isRequired,
|
onPageChange: PropTypes.func.isRequired,
|
||||||
};
|
};
|
||||||
|
|
||||||
const MonitorTable = ({ isAdmin, filter, setLoading }) => {
|
const MonitorTable = ({ isAdmin, filter, setIsSearching, isSearching }) => {
|
||||||
const theme = useTheme();
|
const theme = useTheme();
|
||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
const dispatch = useDispatch();
|
const dispatch = useDispatch();
|
||||||
const { determineState } = useUtils();
|
const { determineState } = useUtils();
|
||||||
|
|
||||||
const { rowsPerPage } = useSelector((state) => state.ui.monitors);
|
const { rowsPerPage } = useSelector((state) => state.ui.monitors);
|
||||||
|
const authState = useSelector((state) => state.auth);
|
||||||
const [page, setPage] = useState(0);
|
const [page, setPage] = useState(0);
|
||||||
const [monitors, setMonitors] = useState([]);
|
const [monitors, setMonitors] = useState([]);
|
||||||
const [monitorCount, setMonitorCount] = useState(0);
|
const [monitorCount, setMonitorCount] = useState(0);
|
||||||
const authState = useSelector((state) => state.auth);
|
|
||||||
const [updateTrigger, setUpdateTrigger] = useState(false);
|
const [updateTrigger, setUpdateTrigger] = useState(false);
|
||||||
const [sort, setSort] = useState({});
|
const [sort, setSort] = useState({});
|
||||||
const prevFilter = useRef(filter);
|
const prevFilter = useRef(filter);
|
||||||
@@ -160,15 +162,25 @@ const MonitorTable = ({ isAdmin, filter, setLoading }) => {
|
|||||||
});
|
});
|
||||||
setMonitors(res?.data?.data?.monitors ?? []);
|
setMonitors(res?.data?.data?.monitors ?? []);
|
||||||
setMonitorCount(res?.data?.data?.monitorCount ?? 0);
|
setMonitorCount(res?.data?.data?.monitorCount ?? 0);
|
||||||
setLoading(false);
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
logger.error(error);
|
logger.error(error);
|
||||||
|
} finally {
|
||||||
|
setIsSearching(false);
|
||||||
}
|
}
|
||||||
}, [authState, page, rowsPerPage, filter, sort, setLoading]);
|
}, [authState, page, rowsPerPage, filter, sort, setIsSearching]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
fetchPage();
|
fetchPage();
|
||||||
}, [updateTrigger, authState, page, rowsPerPage, filter, sort, setLoading, fetchPage]);
|
}, [
|
||||||
|
updateTrigger,
|
||||||
|
authState,
|
||||||
|
page,
|
||||||
|
rowsPerPage,
|
||||||
|
filter,
|
||||||
|
sort,
|
||||||
|
setIsSearching,
|
||||||
|
fetchPage,
|
||||||
|
]);
|
||||||
|
|
||||||
// Listen for changes in filter, if new value reset the page
|
// Listen for changes in filter, if new value reset the page
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
@@ -220,7 +232,37 @@ const MonitorTable = ({ isAdmin, filter, setLoading }) => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<Box position="relative">
|
||||||
|
{isSearching && (
|
||||||
|
<>
|
||||||
|
<Box
|
||||||
|
width="100%"
|
||||||
|
height="100%"
|
||||||
|
position="absolute"
|
||||||
|
sx={{
|
||||||
|
backgroundColor: theme.palette.background.main,
|
||||||
|
opacity: 0.8,
|
||||||
|
zIndex: 100,
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
<Box
|
||||||
|
height="100%"
|
||||||
|
position="absolute"
|
||||||
|
top="20%"
|
||||||
|
left="50%"
|
||||||
|
sx={{
|
||||||
|
transform: "translateX(-50%)",
|
||||||
|
zIndex: 101,
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<CircularProgress
|
||||||
|
sx={{
|
||||||
|
color: theme.palette.other.icon,
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
</Box>
|
||||||
|
</>
|
||||||
|
)}
|
||||||
<TableContainer component={Paper}>
|
<TableContainer component={Paper}>
|
||||||
<Table>
|
<Table>
|
||||||
<TableHead>
|
<TableHead>
|
||||||
@@ -271,77 +313,82 @@ const MonitorTable = ({ isAdmin, filter, setLoading }) => {
|
|||||||
</TableRow>
|
</TableRow>
|
||||||
</TableHead>
|
</TableHead>
|
||||||
<TableBody>
|
<TableBody>
|
||||||
{monitors.map((monitor) => {
|
{/* TODO add empty state. Check if is searching, and empty => skeleton. Is empty, not searching => skeleton */}
|
||||||
let uptimePercentage = "";
|
{monitors.length > 0 ? (
|
||||||
let percentageColor = theme.palette.percentage.uptimeExcellent;
|
monitors.map((monitor) => {
|
||||||
|
let uptimePercentage = "";
|
||||||
|
let percentageColor = theme.palette.percentage.uptimeExcellent;
|
||||||
|
|
||||||
// Determine uptime percentage and color based on the monitor's uptimePercentage value
|
// Determine uptime percentage and color based on the monitor's uptimePercentage value
|
||||||
if (monitor.uptimePercentage !== undefined) {
|
if (monitor.uptimePercentage !== undefined) {
|
||||||
uptimePercentage =
|
uptimePercentage =
|
||||||
monitor.uptimePercentage === 0
|
monitor.uptimePercentage === 0
|
||||||
? "0"
|
? "0"
|
||||||
: (monitor.uptimePercentage * 100).toFixed(2);
|
: (monitor.uptimePercentage * 100).toFixed(2);
|
||||||
|
|
||||||
percentageColor =
|
percentageColor =
|
||||||
monitor.uptimePercentage < 0.25
|
monitor.uptimePercentage < 0.25
|
||||||
? theme.palette.percentage.uptimePoor
|
? theme.palette.percentage.uptimePoor
|
||||||
: monitor.uptimePercentage < 0.5
|
: monitor.uptimePercentage < 0.5
|
||||||
? theme.palette.percentage.uptimeFair
|
? theme.palette.percentage.uptimeFair
|
||||||
: monitor.uptimePercentage < 0.75
|
: monitor.uptimePercentage < 0.75
|
||||||
? theme.palette.percentage.uptimeGood
|
? theme.palette.percentage.uptimeGood
|
||||||
: theme.palette.percentage.uptimeExcellent;
|
: theme.palette.percentage.uptimeExcellent;
|
||||||
}
|
}
|
||||||
|
|
||||||
const params = {
|
const params = {
|
||||||
url: monitor.url,
|
url: monitor.url,
|
||||||
title: monitor.name,
|
title: monitor.name,
|
||||||
percentage: uptimePercentage,
|
percentage: uptimePercentage,
|
||||||
percentageColor,
|
percentageColor,
|
||||||
status: determineState(monitor),
|
status: determineState(monitor),
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<TableRow
|
<TableRow
|
||||||
key={monitor._id}
|
key={monitor._id}
|
||||||
sx={{
|
sx={{
|
||||||
cursor: "pointer",
|
cursor: "pointer",
|
||||||
"&:hover": {
|
"&:hover": {
|
||||||
backgroundColor: theme.palette.background.accent,
|
backgroundColor: theme.palette.background.accent,
|
||||||
},
|
},
|
||||||
}}
|
}}
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
navigate(`/monitors/${monitor._id}`);
|
navigate(`/monitors/${monitor._id}`);
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<TableCell>
|
<TableCell>
|
||||||
<Host
|
<Host
|
||||||
key={monitor._id}
|
key={monitor._id}
|
||||||
params={params}
|
params={params}
|
||||||
/>
|
/>
|
||||||
</TableCell>
|
</TableCell>
|
||||||
<TableCell>
|
<TableCell>
|
||||||
<StatusLabel
|
<StatusLabel
|
||||||
status={params.status}
|
status={params.status}
|
||||||
text={params.status}
|
text={params.status}
|
||||||
customStyles={{ textTransform: "capitalize" }}
|
customStyles={{ textTransform: "capitalize" }}
|
||||||
/>
|
/>
|
||||||
</TableCell>
|
</TableCell>
|
||||||
<TableCell>
|
<TableCell>
|
||||||
<BarChart checks={monitor.checks.slice().reverse()} />
|
<BarChart checks={monitor.checks.slice().reverse()} />
|
||||||
</TableCell>
|
</TableCell>
|
||||||
<TableCell>
|
<TableCell>
|
||||||
<span style={{ textTransform: "uppercase" }}>{monitor.type}</span>
|
<span style={{ textTransform: "uppercase" }}>{monitor.type}</span>
|
||||||
</TableCell>
|
</TableCell>
|
||||||
<TableCell>
|
<TableCell>
|
||||||
<ActionsMenu
|
<ActionsMenu
|
||||||
monitor={monitor}
|
monitor={monitor}
|
||||||
isAdmin={isAdmin}
|
isAdmin={isAdmin}
|
||||||
updateCallback={handleActionMenuDelete}
|
updateCallback={handleActionMenuDelete}
|
||||||
/>
|
/>
|
||||||
</TableCell>
|
</TableCell>
|
||||||
</TableRow>
|
</TableRow>
|
||||||
);
|
);
|
||||||
})}
|
})
|
||||||
|
) : (
|
||||||
|
<TableBodySkeleton />
|
||||||
|
)}
|
||||||
</TableBody>
|
</TableBody>
|
||||||
</Table>
|
</Table>
|
||||||
</TableContainer>
|
</TableContainer>
|
||||||
@@ -415,14 +462,15 @@ const MonitorTable = ({ isAdmin, filter, setLoading }) => {
|
|||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
</Stack>
|
</Stack>
|
||||||
</>
|
</Box>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
MonitorTable.propTypes = {
|
MonitorTable.propTypes = {
|
||||||
isAdmin: PropTypes.bool,
|
isAdmin: PropTypes.bool,
|
||||||
filter: PropTypes.string,
|
filter: PropTypes.string,
|
||||||
setLoading: PropTypes.func,
|
setIsSearching: PropTypes.func,
|
||||||
|
isSearching: PropTypes.bool,
|
||||||
};
|
};
|
||||||
|
|
||||||
const MemoizedMonitorTable = memo(MonitorTable);
|
const MemoizedMonitorTable = memo(MonitorTable);
|
||||||
|
|||||||
@@ -1,79 +1,74 @@
|
|||||||
import "./index.css";
|
import "./index.css";
|
||||||
import { useEffect, useState } from "react";
|
import { useEffect } from "react";
|
||||||
import { useSelector, useDispatch } from "react-redux";
|
import { useSelector, useDispatch } from "react-redux";
|
||||||
import { getUptimeMonitorsByTeamId } from "../../../Features/UptimeMonitors/uptimeMonitorsSlice";
|
import { getUptimeMonitorsByTeamId } from "../../../Features/UptimeMonitors/uptimeMonitorsSlice";
|
||||||
import { useNavigate } from "react-router-dom";
|
import { useNavigate } from "react-router-dom";
|
||||||
import { useTheme } from "@emotion/react";
|
import { useTheme } from "@emotion/react";
|
||||||
import { Box, Button, CircularProgress, Stack, Typography } from "@mui/material";
|
import { Box, Button, Stack } from "@mui/material";
|
||||||
import PropTypes from "prop-types";
|
import PropTypes from "prop-types";
|
||||||
import SkeletonLayout from "./skeleton";
|
import SkeletonLayout from "./skeleton";
|
||||||
import Fallback from "./fallback";
|
import Fallback from "./fallback";
|
||||||
import StatusBox from "./StatusBox";
|
import StatusBox from "./StatusBox";
|
||||||
import Breadcrumbs from "../../../Components/Breadcrumbs";
|
import Breadcrumbs from "../../../Components/Breadcrumbs";
|
||||||
import Greeting from "../../../Utils/greeting";
|
import Greeting from "../../../Utils/greeting";
|
||||||
import MonitorTable from "./MonitorTable";
|
import { CurrentMonitoring } from "./CurrentMonitoring";
|
||||||
import Search from "../../../Components/Inputs/Search";
|
|
||||||
import useDebounce from "../../../Utils/debounce";
|
|
||||||
|
|
||||||
const Monitors = ({ isAdmin }) => {
|
const Monitors = ({ isAdmin }) => {
|
||||||
const theme = useTheme();
|
const theme = useTheme();
|
||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
const monitorState = useSelector((state) => state.uptimeMonitors);
|
const monitorState = useSelector((state) => state.uptimeMonitors);
|
||||||
const authState = useSelector((state) => state.auth);
|
const authState = useSelector((state) => state.auth);
|
||||||
const [search, setSearch] = useState("");
|
|
||||||
const [isSearching, setIsSearching] = useState(false);
|
|
||||||
const dispatch = useDispatch({});
|
const dispatch = useDispatch({});
|
||||||
const debouncedFilter = useDebounce(search, 500);
|
|
||||||
|
|
||||||
const handleSearch = (value) => {
|
|
||||||
setIsSearching(true);
|
|
||||||
setSearch(value);
|
|
||||||
};
|
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
dispatch(getUptimeMonitorsByTeamId(authState.authToken));
|
dispatch(getUptimeMonitorsByTeamId(authState.authToken));
|
||||||
}, [authState.authToken, dispatch]);
|
}, [authState.authToken, dispatch]);
|
||||||
|
|
||||||
let loading =
|
//TODO bring fetching to this component, like on pageSpeed
|
||||||
monitorState?.isLoading && monitorState?.monitorsSummary?.monitors?.length === 0;
|
|
||||||
|
const loading = monitorState?.isLoading;
|
||||||
|
|
||||||
|
const totalMonitors = monitorState?.monitorsSummary?.monitorCounts?.total;
|
||||||
|
|
||||||
|
const hasMonitors = totalMonitors > 0;
|
||||||
|
const noMonitors = !hasMonitors;
|
||||||
|
const canAddMonitor = isAdmin && hasMonitors;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Stack
|
<Stack
|
||||||
className="monitors table-container"
|
className="monitors"
|
||||||
gap={theme.spacing(8)}
|
gap={theme.spacing(8)}
|
||||||
>
|
>
|
||||||
|
<Box>
|
||||||
|
<Breadcrumbs list={[{ name: `monitors`, path: "/monitors" }]} />
|
||||||
|
<Stack
|
||||||
|
direction="row"
|
||||||
|
justifyContent="space-between"
|
||||||
|
alignItems="center"
|
||||||
|
mt={theme.spacing(5)}
|
||||||
|
gap={theme.spacing(6)}
|
||||||
|
>
|
||||||
|
<Greeting type="uptime" />
|
||||||
|
{canAddMonitor && (
|
||||||
|
<Button
|
||||||
|
variant="contained"
|
||||||
|
color="primary"
|
||||||
|
onClick={() => {
|
||||||
|
navigate("/monitors/create");
|
||||||
|
}}
|
||||||
|
sx={{ fontWeight: 500 }}
|
||||||
|
>
|
||||||
|
Create monitor
|
||||||
|
</Button>
|
||||||
|
)}
|
||||||
|
</Stack>
|
||||||
|
</Box>
|
||||||
|
{noMonitors && <Fallback isAdmin={isAdmin} />}
|
||||||
{loading ? (
|
{loading ? (
|
||||||
<SkeletonLayout />
|
<SkeletonLayout />
|
||||||
) : (
|
) : (
|
||||||
<>
|
<>
|
||||||
<Box>
|
{hasMonitors && (
|
||||||
<Breadcrumbs list={[{ name: `monitors`, path: "/monitors" }]} />
|
|
||||||
<Stack
|
|
||||||
direction="row"
|
|
||||||
justifyContent="space-between"
|
|
||||||
alignItems="center"
|
|
||||||
mt={theme.spacing(5)}
|
|
||||||
>
|
|
||||||
<Greeting type="uptime" />
|
|
||||||
{isAdmin && monitorState?.monitorsSummary?.monitors?.length !== 0 && (
|
|
||||||
<Button
|
|
||||||
variant="contained"
|
|
||||||
color="primary"
|
|
||||||
onClick={() => {
|
|
||||||
navigate("/monitors/create");
|
|
||||||
}}
|
|
||||||
sx={{ fontWeight: 500 }}
|
|
||||||
>
|
|
||||||
Create monitor
|
|
||||||
</Button>
|
|
||||||
)}
|
|
||||||
</Stack>
|
|
||||||
</Box>
|
|
||||||
{isAdmin && monitorState?.monitorsSummary?.monitors?.length === 0 && (
|
|
||||||
<Fallback isAdmin={isAdmin} />
|
|
||||||
)}
|
|
||||||
|
|
||||||
{monitorState?.monitorsSummary?.monitors?.length !== 0 && (
|
|
||||||
<>
|
<>
|
||||||
<Stack
|
<Stack
|
||||||
gap={theme.spacing(8)}
|
gap={theme.spacing(8)}
|
||||||
@@ -93,88 +88,11 @@ const Monitors = ({ isAdmin }) => {
|
|||||||
value={monitorState?.monitorsSummary?.monitorCounts?.paused ?? 0}
|
value={monitorState?.monitorsSummary?.monitorCounts?.paused ?? 0}
|
||||||
/>
|
/>
|
||||||
</Stack>
|
</Stack>
|
||||||
<Box
|
<CurrentMonitoring
|
||||||
flex={1}
|
isAdmin={isAdmin}
|
||||||
px={theme.spacing(10)}
|
monitors={monitorState.monitorsSummary.monitors}
|
||||||
py={theme.spacing(8)}
|
totalMonitors={totalMonitors}
|
||||||
border={1}
|
/>
|
||||||
borderColor={theme.palette.border.light}
|
|
||||||
borderRadius={theme.shape.borderRadius}
|
|
||||||
backgroundColor={theme.palette.background.main}
|
|
||||||
>
|
|
||||||
<Stack
|
|
||||||
direction="row"
|
|
||||||
alignItems="center"
|
|
||||||
mb={theme.spacing(8)}
|
|
||||||
>
|
|
||||||
<Typography
|
|
||||||
component="h2"
|
|
||||||
variant="h2"
|
|
||||||
fontWeight={500}
|
|
||||||
letterSpacing={-0.2}
|
|
||||||
>
|
|
||||||
Actively monitoring
|
|
||||||
</Typography>
|
|
||||||
<Box
|
|
||||||
className="current-monitors-counter"
|
|
||||||
color={theme.palette.text.primary}
|
|
||||||
border={1}
|
|
||||||
borderColor={theme.palette.border.light}
|
|
||||||
backgroundColor={theme.palette.background.accent}
|
|
||||||
>
|
|
||||||
{monitorState?.monitorsSummary?.monitorCounts?.total || 0}
|
|
||||||
</Box>
|
|
||||||
<Box
|
|
||||||
width="25%"
|
|
||||||
minWidth={150}
|
|
||||||
ml="auto"
|
|
||||||
>
|
|
||||||
<Search
|
|
||||||
options={monitorState?.monitorsSummary?.monitors ?? []}
|
|
||||||
filteredBy="name"
|
|
||||||
inputValue={search}
|
|
||||||
handleInputChange={handleSearch}
|
|
||||||
/>
|
|
||||||
</Box>
|
|
||||||
</Stack>
|
|
||||||
<Box position="relative">
|
|
||||||
{isSearching && (
|
|
||||||
<>
|
|
||||||
<Box
|
|
||||||
width="100%"
|
|
||||||
height="100%"
|
|
||||||
position="absolute"
|
|
||||||
sx={{
|
|
||||||
backgroundColor: theme.palette.background.main,
|
|
||||||
opacity: 0.8,
|
|
||||||
zIndex: 100,
|
|
||||||
}}
|
|
||||||
/>
|
|
||||||
<Box
|
|
||||||
height="100%"
|
|
||||||
position="absolute"
|
|
||||||
top="20%"
|
|
||||||
left="50%"
|
|
||||||
sx={{
|
|
||||||
transform: "translateX(-50%)",
|
|
||||||
zIndex: 101,
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<CircularProgress
|
|
||||||
sx={{
|
|
||||||
color: theme.palette.other.icon,
|
|
||||||
}}
|
|
||||||
/>
|
|
||||||
</Box>
|
|
||||||
</>
|
|
||||||
)}
|
|
||||||
<MonitorTable
|
|
||||||
isAdmin={isAdmin}
|
|
||||||
filter={debouncedFilter}
|
|
||||||
setLoading={setIsSearching}
|
|
||||||
/>
|
|
||||||
</Box>
|
|
||||||
</Box>
|
|
||||||
</>
|
</>
|
||||||
)}
|
)}
|
||||||
</>
|
</>
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ const PageSpeed = ({ isAdmin }) => {
|
|||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
|
|
||||||
const { user, authToken } = useSelector((state) => state.auth);
|
const { user, authToken } = useSelector((state) => state.auth);
|
||||||
const [isLoading, setIsLoading] = useState(false);
|
const [isLoading, setIsLoading] = useState(true);
|
||||||
const [monitors, setMonitors] = useState([]);
|
const [monitors, setMonitors] = useState([]);
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
dispatch(getPageSpeedByTeamId(authToken));
|
dispatch(getPageSpeedByTeamId(authToken));
|
||||||
|
|||||||
@@ -0,0 +1,25 @@
|
|||||||
|
const buildErrors = (prev, id, error) => {
|
||||||
|
const updatedErrors = { ...prev };
|
||||||
|
if (error) {
|
||||||
|
updatedErrors[id] = error.details[0].message?? "Validation error";
|
||||||
|
} else {
|
||||||
|
delete updatedErrors[id];
|
||||||
|
}
|
||||||
|
return updatedErrors;
|
||||||
|
};
|
||||||
|
|
||||||
|
const hasValidationErrors = (form, validation, setErrors) => {
|
||||||
|
const { error } = validation.validate(form, {
|
||||||
|
abortEarly: false,
|
||||||
|
});
|
||||||
|
if (error) {
|
||||||
|
const newErrors = {};
|
||||||
|
error.details.forEach((err) => {
|
||||||
|
newErrors[err.path[0]] = err.message?? "Validation error";
|
||||||
|
});
|
||||||
|
setErrors(newErrors);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
};
|
||||||
|
export { buildErrors, hasValidationErrors };
|
||||||
@@ -128,10 +128,43 @@ const maintenanceWindowValidation = joi.object({
|
|||||||
monitors: joi.array().min(1),
|
monitors: joi.array().min(1),
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const advancedSettingsValidation = joi.object({
|
||||||
|
apiBaseUrl: joi.string().uri({ allowRelative: true }).trim().messages({
|
||||||
|
"string.empty": "API base url is required.",
|
||||||
|
"string.uri": "The URL you provided is not valid.",
|
||||||
|
}),
|
||||||
|
logLevel: joi.string().valid("debug", "none", "error", "warn").allow(""),
|
||||||
|
systemEmailHost: joi.string().allow(''),
|
||||||
|
systemEmailPort: joi.string().allow(''),
|
||||||
|
systemEmailAddress: joi
|
||||||
|
.string().allow(''),
|
||||||
|
systemEmailPassword: joi.string().allow(''),
|
||||||
|
jwtTTL: joi
|
||||||
|
.string()
|
||||||
|
.trim()
|
||||||
|
.messages({
|
||||||
|
"string.empty": "JWT TTL is required."
|
||||||
|
}),
|
||||||
|
dbType: joi.string().trim().messages({
|
||||||
|
"string.empty": "DB type is required",
|
||||||
|
}),
|
||||||
|
redisHost: joi.string().trim().messages({
|
||||||
|
"string.empty": "Redis host is required",
|
||||||
|
}),
|
||||||
|
redisPort: joi.string().allow('').custom((value, helpers) => {
|
||||||
|
if(value && isNaN(parseInt(value))){
|
||||||
|
return helpers.message("Redit port must be a number")
|
||||||
|
}
|
||||||
|
return value
|
||||||
|
}),
|
||||||
|
pagespeedApiKey: joi.string().allow('')
|
||||||
|
});
|
||||||
|
|
||||||
export {
|
export {
|
||||||
credentials,
|
credentials,
|
||||||
imageValidation,
|
imageValidation,
|
||||||
monitorValidation,
|
monitorValidation,
|
||||||
settingsValidation,
|
settingsValidation,
|
||||||
maintenanceWindowValidation,
|
maintenanceWindowValidation,
|
||||||
|
advancedSettingsValidation,
|
||||||
};
|
};
|
||||||
Vendored
+19
-17
@@ -1,24 +1,26 @@
|
|||||||
|
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
# Change directory to root Server directory for correct Docker Context
|
# Change directory to root Server directory for correct Docker Context
|
||||||
|
cd "$(dirname "$0")"
|
||||||
cd ../..
|
cd ../..
|
||||||
|
|
||||||
#Client
|
# Define an array of services and their Dockerfiles
|
||||||
client="./Docker/dist/client.Dockerfile"
|
declare -A services=(
|
||||||
|
["bluewave/uptime_client"]="./Docker/dist/client.Dockerfile"
|
||||||
|
["bluewave/database_mongo"]="./Docker/dist/mongoDB.Dockerfile"
|
||||||
|
["bluewave/uptime_redis"]="./Docker/dist/redis.Dockerfile"
|
||||||
|
["bluewave/uptime_server"]="./Docker/dist/server.Dockerfile"
|
||||||
|
)
|
||||||
|
|
||||||
# MongoDB
|
# Loop through each service and build the corresponding image
|
||||||
mongoDB="./Docker/dist/mongoDB.Dockerfile"
|
for service in "${!services[@]}"; do
|
||||||
|
docker build -f "${services[$service]}" -t "$service" .
|
||||||
|
|
||||||
|
# Check if the build succeeded
|
||||||
|
if [ $? -ne 0 ]; then
|
||||||
|
echo "Error building $service image. Exiting..."
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
# Redis
|
echo "All images built successfully"
|
||||||
redis="./Docker/dist/redis.Dockerfile"
|
|
||||||
|
|
||||||
# Server
|
|
||||||
server="./Docker/dist/server.Dockerfile"
|
|
||||||
|
|
||||||
docker build -f $client -t dist_uptime_client .
|
|
||||||
docker build -f $mongoDB -t dist_uptime_database_mongo .
|
|
||||||
docker build -f $redis -t dist_uptime_redis .
|
|
||||||
docker build -f $server -t dist_uptime_server .
|
|
||||||
|
|
||||||
echo "All images built"
|
|
||||||
+19
-17
@@ -1,24 +1,26 @@
|
|||||||
|
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
# Change directory to root directory for correct Docker Context
|
# Change directory to root directory for correct Docker Context
|
||||||
|
cd "$(dirname "$0")"
|
||||||
cd ../..
|
cd ../..
|
||||||
|
|
||||||
#Client
|
# Define an array of services and their Dockerfiles
|
||||||
client="./Docker/prod/client.Dockerfile"
|
declare -A services=(
|
||||||
|
["uptime_client"]="./Docker/prod/client.Dockerfile"
|
||||||
|
["uptime_database_mongo"]="./Docker/prod/mongoDB.Dockerfile"
|
||||||
|
["uptime_redis"]="./Docker/prod/redis.Dockerfile"
|
||||||
|
["uptime_server"]="./Docker/prod/server.Dockerfile"
|
||||||
|
)
|
||||||
|
|
||||||
# MongoDB
|
# Loop through each service and build the corresponding image
|
||||||
mongoDB="./Docker/prod/mongoDB.Dockerfile"
|
for service in "${!services[@]}"; do
|
||||||
|
docker build -f "${services[$service]}" -t "$service" .
|
||||||
|
|
||||||
|
# Check if the build succeeded
|
||||||
|
if [ $? -ne 0 ]; then
|
||||||
|
echo "Error building $service image. Exiting..."
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
# Redis
|
echo "All images built successfully"
|
||||||
redis="./Docker/prod/redis.Dockerfile"
|
|
||||||
|
|
||||||
# Server
|
|
||||||
server="./Docker/prod/server.Dockerfile"
|
|
||||||
|
|
||||||
docker build -f $client -t uptime_client .
|
|
||||||
docker build -f $mongoDB -t uptime_database_mongo .
|
|
||||||
docker build -f $redis -t uptime_redis .
|
|
||||||
docker build -f $server -t uptime_server .
|
|
||||||
|
|
||||||
echo "All images built"
|
|
||||||
@@ -46,8 +46,8 @@ const HardwareCheckSchema = mongoose.Schema(
|
|||||||
default: () => ({}),
|
default: () => ({}),
|
||||||
},
|
},
|
||||||
disk: {
|
disk: {
|
||||||
type: discSchema,
|
type: [discSchema],
|
||||||
default: () => ({}),
|
default: () => [],
|
||||||
},
|
},
|
||||||
host: {
|
host: {
|
||||||
type: hostSchema,
|
type: hostSchema,
|
||||||
|
|||||||
Generated
+6
@@ -0,0 +1,6 @@
|
|||||||
|
{
|
||||||
|
"name": "bluewave-uptime",
|
||||||
|
"lockfileVersion": 3,
|
||||||
|
"requires": true,
|
||||||
|
"packages": {}
|
||||||
|
}
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
{
|
||||||
|
"$schema": "https://docs.renovatebot.com/renovate-schema.json",
|
||||||
|
"extends": [
|
||||||
|
"config:recommended"
|
||||||
|
]
|
||||||
|
}
|
||||||
Reference in new issue
Block a user