header create
This commit is contained in:
1 parent
d877ecf061
commit
b852293447
4 files changed
+47
-12
No files matched your search
@@ -1,14 +1,27 @@
|
|||||||
import { Stack } from "@mui/material";
|
import { Stack } from "@mui/material";
|
||||||
import { useNavigate } from "react-router-dom";
|
import { useNavigate } from "react-router-dom";
|
||||||
import { ButtonInput } from "../../inputs/Button";
|
import { ButtonInput } from "../../inputs/Button";
|
||||||
|
import { useTranslation } from "react-i18next";
|
||||||
|
|
||||||
interface HeaderCreateProps {
|
interface HeaderCreateProps {
|
||||||
label?: string;
|
label?: string;
|
||||||
path: string;
|
path: string;
|
||||||
|
isLoading?: boolean;
|
||||||
|
isAdmin?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
export const HeaderCreate = ({ label = "Create", path }: HeaderCreateProps) => {
|
export const HeaderCreate = ({
|
||||||
|
label,
|
||||||
|
path,
|
||||||
|
isLoading = false,
|
||||||
|
isAdmin = false,
|
||||||
|
}: HeaderCreateProps) => {
|
||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
|
const { t } = useTranslation();
|
||||||
|
|
||||||
|
if (!isAdmin) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
const handleClick = () => {
|
const handleClick = () => {
|
||||||
navigate(path);
|
navigate(path);
|
||||||
@@ -25,8 +38,9 @@ export const HeaderCreate = ({ label = "Create", path }: HeaderCreateProps) => {
|
|||||||
variant="contained"
|
variant="contained"
|
||||||
color="primary"
|
color="primary"
|
||||||
onClick={handleClick}
|
onClick={handleClick}
|
||||||
|
loading={isLoading}
|
||||||
>
|
>
|
||||||
{label}
|
{label || t("common.buttons.create")}
|
||||||
</ButtonInput>
|
</ButtonInput>
|
||||||
</Stack>
|
</Stack>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -8,6 +8,8 @@ import {
|
|||||||
import { TextField } from "@/Components/v2/inputs";
|
import { TextField } from "@/Components/v2/inputs";
|
||||||
import Stack from "@mui/material/Stack";
|
import Stack from "@mui/material/Stack";
|
||||||
import { MonitorTable } from "@/Pages/Uptime/Monitors/Components/UptimeMonitorsTable";
|
import { MonitorTable } from "@/Pages/Uptime/Monitors/Components/UptimeMonitorsTable";
|
||||||
|
import { HeaderCreate } from "@/Components/v2/common";
|
||||||
|
|
||||||
import { useTranslation } from "react-i18next";
|
import { useTranslation } from "react-i18next";
|
||||||
import useMediaQuery from "@mui/material/useMediaQuery";
|
import useMediaQuery from "@mui/material/useMediaQuery";
|
||||||
import { useGet } from "@/Hooks/UseApi";
|
import { useGet } from "@/Hooks/UseApi";
|
||||||
@@ -15,7 +17,7 @@ import type { Monitor, MonitorType, MonitorsWithChecksResponse } from "@/Types/M
|
|||||||
import { useState, useMemo, useCallback } from "react";
|
import { useState, useMemo, useCallback } from "react";
|
||||||
import { useSelector, useDispatch } from "react-redux";
|
import { useSelector, useDispatch } from "react-redux";
|
||||||
import { setRowsPerPage } from "@/Features/UI/uiSlice.js";
|
import { setRowsPerPage } from "@/Features/UI/uiSlice.js";
|
||||||
|
import { useIsAdmin } from "@/Hooks/useIsAdmin";
|
||||||
import type { RootState } from "@/Types/state";
|
import type { RootState } from "@/Types/state";
|
||||||
import { useTheme } from "@mui/material";
|
import { useTheme } from "@mui/material";
|
||||||
|
|
||||||
@@ -24,7 +26,7 @@ const UptimeMonitorsPage = () => {
|
|||||||
const theme = useTheme();
|
const theme = useTheme();
|
||||||
const isSmall = useMediaQuery(theme.breakpoints.down("md"));
|
const isSmall = useMediaQuery(theme.breakpoints.down("md"));
|
||||||
const dispatch = useDispatch();
|
const dispatch = useDispatch();
|
||||||
|
const isAdmin = useIsAdmin();
|
||||||
// Redux state
|
// Redux state
|
||||||
const rowsPerPage = useSelector(
|
const rowsPerPage = useSelector(
|
||||||
(state: RootState) => state.ui?.monitors?.rowsPerPage ?? 10
|
(state: RootState) => state.ui?.monitors?.rowsPerPage ?? 10
|
||||||
@@ -84,7 +86,7 @@ const UptimeMonitorsPage = () => {
|
|||||||
// Data fetching
|
// Data fetching
|
||||||
const {
|
const {
|
||||||
data: monitors,
|
data: monitors,
|
||||||
isLoading,
|
isLoading: monitorsLoading,
|
||||||
error,
|
error,
|
||||||
} = useGet<Monitor[]>("/monitors/team?type=http&type=ping&type=port&type=docker");
|
} = useGet<Monitor[]>("/monitors/team?type=http&type=ping&type=port&type=docker");
|
||||||
|
|
||||||
@@ -109,14 +111,21 @@ const UptimeMonitorsPage = () => {
|
|||||||
setSearch("");
|
setSearch("");
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
|
const isLoading = monitorsLoading || monitorsWithChecksLoading;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<MonitorBasePageWithStates
|
<MonitorBasePageWithStates
|
||||||
loading={isLoading || monitorsWithChecksLoading}
|
loading={isLoading}
|
||||||
error={error || monitorsWithChecksError}
|
error={error || monitorsWithChecksError}
|
||||||
items={monitors || []}
|
items={monitors || []}
|
||||||
page="uptime"
|
page="uptime"
|
||||||
actionLink="/uptime/create"
|
actionLink="/uptime/create"
|
||||||
>
|
>
|
||||||
|
<HeaderCreate
|
||||||
|
path="/uptime/create"
|
||||||
|
isLoading={isLoading}
|
||||||
|
isAdmin={isAdmin}
|
||||||
|
/>
|
||||||
<Stack
|
<Stack
|
||||||
direction={isSmall ? "column" : "row"}
|
direction={isSmall ? "column" : "row"}
|
||||||
gap={theme.spacing(8)}
|
gap={theme.spacing(8)}
|
||||||
|
|||||||
@@ -1,14 +1,25 @@
|
|||||||
import store from "../store";
|
|
||||||
const LOG_LEVEL = import.meta.env.VITE_APP_LOG_LEVEL || "debug";
|
const LOG_LEVEL = import.meta.env.VITE_APP_LOG_LEVEL || "debug";
|
||||||
const NO_OP = () => {};
|
const NO_OP = () => {};
|
||||||
|
|
||||||
class Logger {
|
class Logger {
|
||||||
constructor() {
|
constructor() {
|
||||||
let logLevel = LOG_LEVEL;
|
let logLevel = LOG_LEVEL;
|
||||||
this.unsubscribe = store.subscribe(() => {
|
this.updateLogLevel(logLevel);
|
||||||
logLevel = "debug";
|
// Defer store subscription to avoid circular dependency during HMR
|
||||||
this.updateLogLevel(logLevel);
|
setTimeout(() => {
|
||||||
});
|
try {
|
||||||
|
import("../store").then(({ default: store }) => {
|
||||||
|
if (store) {
|
||||||
|
this.unsubscribe = store.subscribe(() => {
|
||||||
|
logLevel = "debug";
|
||||||
|
this.updateLogLevel(logLevel);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
} catch (e) {
|
||||||
|
// Store not ready yet, ignore
|
||||||
|
}
|
||||||
|
}, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
updateLogLevel(logLevel) {
|
updateLogLevel(logLevel) {
|
||||||
|
|||||||
@@ -3,7 +3,8 @@
|
|||||||
"appName": "Checkmate",
|
"appName": "Checkmate",
|
||||||
"monitoringAgentName": "Capture",
|
"monitoringAgentName": "Capture",
|
||||||
"buttons": {
|
"buttons": {
|
||||||
"toggleTheme": "Toggles light & dark"
|
"toggleTheme": "Toggles light & dark",
|
||||||
|
"create": "Create"
|
||||||
},
|
},
|
||||||
"toasts": {
|
"toasts": {
|
||||||
"networkError": "Network error",
|
"networkError": "Network error",
|
||||||
|
|||||||
Reference in new issue
Block a user