Merge branch 'develop' into 1067-fe-hardware-monitoring-create-hardware-monitor

This commit is contained in:
Shemy Gan committed 2024-11-14 11:03:38 -05:00
commit aa6e881c1a
61 files changed
+2551 -1049

No files matched your search

+3
View File
@@ -31,6 +31,9 @@ const icons = {
const Alert = ({ variant, title, body, isToast, hasIcon = true, onClick }) => {
const theme = useTheme();
/* TODO
This needs fixing. text bg and border not necessarilly exist. Probably text becomes contrastText. border becomes contrastText. bg becomes dark.
Check possible variants, see implementation in light and dark theme, and adjust */
const { text, bg, border } = theme.palette[variant];
const icon = icons[variant];
@@ -5,6 +5,7 @@ import { useEffect, useState } from "react";
import "./index.css";
import { useSelector } from "react-redux";
/* TODO add prop validation and jsdocs */
const BarChart = ({ checks = [] }) => {
const theme = useTheme();
const [animate, setAnimate] = useState(false);
@@ -65,7 +66,9 @@ const BarChart = ({ checks = [] }) => {
width={theme.spacing(4)}
height={theme.spacing(4)}
backgroundColor={
check.status ? theme.palette.success.main : theme.palette.error.text
check.status
? theme.palette.success.main
: theme.palette.error.contrastText
}
sx={{ borderRadius: "50%" }}
/>
@@ -111,7 +114,7 @@ const BarChart = ({ checks = [] }) => {
],
sx: {
"& .MuiTooltip-tooltip": {
backgroundColor: theme.palette.background.main,
backgroundColor: theme.palette.secondary.main,
border: 1,
borderColor: theme.palette.border.dark,
borderRadius: theme.shape.borderRadius,
@@ -138,7 +141,9 @@ const BarChart = ({ checks = [] }) => {
width="9px"
height="100%"
backgroundColor={
check.status ? theme.palette.success.bg : theme.palette.error.bg
check.status
? theme.palette.success.contrastText
: theme.palette.error.dark
}
sx={{
borderRadius: theme.spacing(1.5),
@@ -153,7 +158,9 @@ const BarChart = ({ checks = [] }) => {
width="100%"
height={`${animate ? check.responseTime : 0}%`}
backgroundColor={
check.status ? theme.palette.success.main : theme.palette.error.text
check.status
? theme.palette.success.main
: theme.palette.error.contrastText
}
sx={{
borderRadius: theme.spacing(1.5),
+1 -1
View File
@@ -24,7 +24,7 @@ const Check = ({ text, noHighlightText, variant = "info", outlined = false }) =>
const theme = useTheme();
const colors = {
success: theme.palette.success.main,
error: theme.palette.error.text,
error: theme.palette.error.contrastText,
info: theme.palette.info.border,
};
@@ -0,0 +1,37 @@
import { useEffect } from "react";
import { useNavigate } from "react-router-dom";
import { logger } from "../../Utils/Logger";
import { networkService } from "../../main";
const withAdminCheck = (WrappedComponent) => {
const WithAdminCheck = (props) => {
const navigate = useNavigate();
useEffect(() => {
networkService
.doesSuperAdminExist()
.then((response) => {
if (response.data.data === true) {
navigate("/login");
}
})
.catch((error) => {
logger.error(error);
});
}, [navigate]);
return (
<WrappedComponent
{...props}
isSuperAdmin={true}
/>
);
};
const wrappedComponentName =
WrappedComponent.displayName || WrappedComponent.name || "Component";
WithAdminCheck.displayName = `WithAdminCheck(${wrappedComponentName})`;
return WithAdminCheck;
};
export default withAdminCheck;
@@ -0,0 +1,25 @@
import { useSelector } from "react-redux";
const withAdminProp = (WrappedComponent) => {
const WithAdminProp = (props) => {
const { user } = useSelector((state) => state.auth);
const isAdmin =
(user?.role?.includes("admin") ?? false) ||
(user?.role?.includes("superadmin") ?? false);
return (
<WrappedComponent
{...props}
isAdmin={isAdmin}
/>
);
};
const wrappedComponentName =
WrappedComponent.displayName || WrappedComponent.name || "Component";
WithAdminProp.displayName = `WithAdminProp(${wrappedComponentName})`;
return WithAdminProp;
};
export default withAdminProp;
+29
View File
@@ -0,0 +1,29 @@
import { Typography } from "@mui/material";
import PropTypes from "prop-types";
/**
* A heading component that renders text with a specific heading level.
*
* @param {Object} props - The properties passed to the Heading component.
* @param {('h1'|'h2'|'h3')} props.component - The heading level for the component.
* @param {string} props.children - The content to display inside the heading.
* @returns {JSX.Element} The Typography component with specified heading properties.
*/
function Heading({ component, children }) {
return (
<Typography
component={component}
variant="h2"
fontWeight={600}
>
{children}
</Typography>
);
}
Heading.propTypes = {
component: PropTypes.oneOf(["h1", "h2", "h3"]).isRequired,
children: PropTypes.string.isRequired,
};
export { Heading };
+3 -3
View File
@@ -68,7 +68,7 @@ const Field = forwardRef(
borderColor: theme.palette.border.dark,
},
"&:has(.input-error) .MuiOutlinedInput-root fieldset": {
borderColor: theme.palette.error.text,
borderColor: theme.palette.error.contrastText,
},
display: hidden ? "none" : "",
}}
@@ -84,7 +84,7 @@ const Field = forwardRef(
<Typography
component="span"
ml={theme.spacing(1)}
color={theme.palette.error.text}
color={theme.palette.error.contrastText}
>
*
</Typography>
@@ -191,7 +191,7 @@ const Field = forwardRef(
component="span"
className="input-error"
hidden={className? true: false}
color={theme.palette.error.text}
color={theme.palette.error.contrastText}
mt={theme.spacing(2)}
sx={{
opacity: 0.8,
+1 -1
View File
@@ -41,7 +41,7 @@ const Radio = (props) => {
color: "transparent",
width: 16,
height: 16,
boxShadow: "inset 0 0 0 1px #656a74",
boxShadow: `inset 0 0 0 1px ${theme.palette.secondary.main}`,
mt: theme.spacing(0.5),
}}
/>
@@ -99,7 +99,7 @@ const Search = ({
<Typography
component="span"
className="input-error"
color={theme.palette.error.text}
color={theme.palette.error.contrastText}
mt={theme.spacing(2)}
sx={{
opacity: 0.8,
-1
View File
@@ -1,5 +1,4 @@
.label {
border: 1px solid #000;
display: inline-flex;
justify-content: center;
align-items: center;
+7 -7
View File
@@ -31,7 +31,7 @@ const BaseLabel = ({ label, styles, children }) => {
className="label"
sx={{
borderRadius: borderRadius,
borderColor: theme.palette.text.tertiary,
border: `1px solid ${theme.palette.text.tertiary}`,
color: theme.palette.text.tertiary,
padding: padding,
...styles,
@@ -127,22 +127,22 @@ const StatusLabel = ({ status, text, customStyles }) => {
const colors = {
up: {
dotColor: theme.palette.success.main,
bgColor: theme.palette.success.bg,
borderColor: theme.palette.success.light,
bgColor: theme.palette.success./* dark */ contrastText,
borderColor: theme.palette.success.main /* light */,
},
down: {
dotColor: theme.palette.error.text,
bgColor: theme.palette.error.bg,
dotColor: theme.palette.error.contrastText,
bgColor: theme.palette.error.dark,
borderColor: theme.palette.error.light,
},
paused: {
dotColor: theme.palette.warning.main,
bgColor: theme.palette.warning.bg,
bgColor: theme.palette.warning.dark,
borderColor: theme.palette.warning.light,
},
pending: {
dotColor: theme.palette.warning.main,
bgColor: theme.palette.warning.bg,
bgColor: theme.palette.warning.dark,
borderColor: theme.palette.warning.light,
},
"cannot resolve": {
@@ -0,0 +1,38 @@
.home-layout {
position: relative;
min-height: 100vh;
max-width: 1400px;
margin: 0 auto;
padding: var(--env-var-spacing-2);
}
.home-layout aside {
position: sticky;
top: var(--env-var-spacing-2);
left: 0;
height: calc(100vh - var(--env-var-spacing-2) * 2);
max-width: var(--env-var-side-bar-width);
}
.home-layout > div {
min-height: calc(100vh - var(--env-var-spacing-2) * 2);
flex: 1;
}
.home-layout > div:has(> [class*="fallback__"]) .background-pattern-svg {
position: absolute;
top: 0;
left: 50%;
transform: translate(-50%, -50%);
z-index: 0;
width: 100%;
max-width: 800px;
height: 100%;
max-height: 800px;
background-position: center;
background-size: cover;
background-repeat: no-repeat;
}
@@ -0,0 +1,20 @@
import Sidebar from "../../Sidebar";
import { Outlet } from "react-router";
import { Stack } from "@mui/material";
import "./index.css";
const HomeLayout = () => {
return (
<Stack
className="home-layout"
flexDirection="row"
gap={14}
>
<Sidebar />
<Outlet />
</Stack>
);
};
export default HomeLayout;
+3 -3
View File
@@ -34,11 +34,11 @@ const ProgressUpload = ({ icon, label, size, progress = 0, onClick, error }) =>
backgroundColor: theme.palette.background.fill,
"&:has(.input-error)": {
borderColor: theme.palette.error.main,
backgroundColor: theme.palette.error.bg,
backgroundColor: theme.palette.error.dark,
py: theme.spacing(4),
px: theme.spacing(8),
"& > .MuiStack-root > svg": {
fill: theme.palette.error.text,
fill: theme.palette.error.contrastText,
width: "20px",
height: "20px",
},
@@ -85,7 +85,7 @@ const ProgressUpload = ({ icon, label, size, progress = 0, onClick, error }) =>
<Typography
component="p"
className="input-error"
color={theme.palette.error.text}
color={theme.palette.error.contrastText}
>
{error}
</Typography>
+13 -21
View File
@@ -19,7 +19,7 @@ import { useLocation, useNavigate } from "react-router";
import { useTheme } from "@emotion/react";
import { useDispatch, useSelector } from "react-redux";
import { clearAuthState } from "../../Features/Auth/authSlice";
import { setMode, toggleSidebar } from "../../Features/UI/uiSlice";
import { toggleSidebar } from "../../Features/UI/uiSlice";
import { clearUptimeMonitorState } from "../../Features/UptimeMonitors/uptimeMonitorsSlice";
import Avatar from "../Avatar";
import LockSvg from "../../assets/icons/lock.svg?react";
@@ -29,7 +29,6 @@ import LogoutSvg from "../../assets/icons/logout.svg?react";
import Support from "../../assets/icons/support.svg?react";
import Dashboard from "../../assets/icons/dashboard.svg?react";
import Account from "../../assets/icons/user-edit.svg?react";
import StatusPages from "../../assets/icons/status-pages.svg?react";
import Maintenance from "../../assets/icons/maintenance.svg?react";
import Monitors from "../../assets/icons/monitors.svg?react";
import Incidents from "../../assets/icons/incidents.svg?react";
@@ -54,6 +53,7 @@ const menu = [
nested: [
{ name: "Monitors", path: "monitors", icon: <Monitors /> },
{ name: "Pagespeed", path: "pagespeed", icon: <PageSpeed /> },
{ name: "Infrastructure", path: "infrastructure", icon: <Integrations /> },
],
},
{ name: "Incidents", path: "incidents", icon: <Incidents /> },
@@ -113,7 +113,6 @@ function Sidebar() {
const [popup, setPopup] = useState();
const { user } = useSelector((state) => state.auth);
// Remove demo password if demo
const accountMenuItem = menu.find((item) => item.name === "Account");
if (user.role?.includes("demo") && accountMenuItem) {
accountMenuItem.nested = accountMenuItem.nested.filter((item) => {
@@ -148,7 +147,9 @@ function Sidebar() {
if (matchedKey) {
setOpen((prev) => ({ ...prev, [PATH_MAP[matchedKey]]: true }));
}
}, []);
}, [location]);
/* TODO refactor this, there are a some ternaries and comments in the return */
return (
<Stack
@@ -181,7 +182,13 @@ function Sidebar() {
direction="row"
alignItems="center"
gap={theme.spacing(4)}
onClick={() => window.open("https://github.com/bluewave-labs/bluewave-uptime", "_blank", "noreferrer")}
onClick={() =>
window.open(
"https://github.com/bluewave-labs/bluewave-uptime",
"_blank",
"noreferrer"
)
}
sx={{ cursor: "pointer" }}
>
<Stack
@@ -297,6 +304,7 @@ function Sidebar() {
</ListItemButton>
</Tooltip>
) : collapsed ? (
/* TODO Do we ever get here? */
<React.Fragment key={item.name}>
<Tooltip
placement="right"
@@ -616,22 +624,6 @@ function Sidebar() {
</MenuItem>
)}
{collapsed && <Divider />}
{/* <MenuItem
onClick={() => {
dispatch(setMode("light"));
closePopup();
}}
>
Light
</MenuItem>
<MenuItem
onClick={() => {
dispatch(setMode("dark"));
closePopup();
}}
>
Dark
</MenuItem> */}
<Divider />
<MenuItem
onClick={logout}