refactor service
This commit is contained in:
1 parent
82cb59ae9e
commit
56aa7b3e1a
21 files changed
+301
-162
No files matched your search
@@ -70,7 +70,7 @@ const DockerMonitorsPage = () => {
|
||||
const monitorLimitReached = useLimitReached("monitorsMax", count);
|
||||
|
||||
const handleConfirm = async () => {
|
||||
await deleteFn(`/monitors/${selectedMonitor?._id}`);
|
||||
await deleteFn(`/monitors/${selectedMonitor?.id}`);
|
||||
setSelectedMonitor(null);
|
||||
refetch();
|
||||
};
|
||||
|
||||
@@ -58,17 +58,17 @@ export const DockerMonitorsTable = ({
|
||||
{
|
||||
id: 2,
|
||||
label: t("monitors.common.actions.details"),
|
||||
action: () => navigate(`/docker/${monitor._id}`),
|
||||
action: () => navigate(`/docker/${monitor.id}`),
|
||||
},
|
||||
{
|
||||
id: 3,
|
||||
label: t("monitors.common.actions.incidents"),
|
||||
action: () => navigate(`/incidents?monitorId=${monitor._id}`),
|
||||
action: () => navigate(`/incidents?monitorId=${monitor.id}`),
|
||||
},
|
||||
{
|
||||
id: 4,
|
||||
label: t("monitors.common.actions.configure"),
|
||||
action: () => navigate(`/docker/${monitor._id}/configure`),
|
||||
action: () => navigate(`/docker/${monitor.id}/configure`),
|
||||
},
|
||||
{
|
||||
id: 6,
|
||||
@@ -77,7 +77,7 @@ export const DockerMonitorsTable = ({
|
||||
? t("common.buttons.resume")
|
||||
: t("common.buttons.pause"),
|
||||
action: async () => {
|
||||
await patch(`/monitors/${monitor._id}/active`);
|
||||
await patch(`/monitors/${monitor.id}/active`);
|
||||
refetch();
|
||||
},
|
||||
closeMenu: true,
|
||||
@@ -124,7 +124,7 @@ export const DockerMonitorsTable = ({
|
||||
),
|
||||
render: (row) => {
|
||||
const containerCount = (
|
||||
checksMap[row._id]?.[0]?.dockerContainers || []
|
||||
checksMap[row.id]?.[0]?.dockerContainers || []
|
||||
).filter((c: any) => c?.running).length;
|
||||
return containerCount;
|
||||
},
|
||||
@@ -145,7 +145,7 @@ export const DockerMonitorsTable = ({
|
||||
<Table
|
||||
headers={headers}
|
||||
data={monitors}
|
||||
onRowClick={(row) => navigate(`/docker/${row._id}`)}
|
||||
onRowClick={(row) => navigate(`/docker/${row.id}`)}
|
||||
/>
|
||||
<Pagination
|
||||
component="div"
|
||||
|
||||
@@ -70,7 +70,7 @@ const InfraMonitorsPage = () => {
|
||||
const monitorLimitReached = useLimitReached("monitorsMax", count);
|
||||
|
||||
const handleConfirm = async () => {
|
||||
await deleteFn(`/monitors/${selectedMonitor?._id}`);
|
||||
await deleteFn(`/monitors/${selectedMonitor?.id}`);
|
||||
setSelectedMonitor(null);
|
||||
refetch();
|
||||
};
|
||||
|
||||
@@ -97,21 +97,21 @@ export const InfraMonitorsTable = ({
|
||||
id: 2,
|
||||
label: t("monitors.common.actions.details"),
|
||||
action: () => {
|
||||
navigate(`${monitor._id}`);
|
||||
navigate(`${monitor.id}`);
|
||||
},
|
||||
},
|
||||
{
|
||||
id: 3,
|
||||
label: t("monitors.common.actions.incidents"),
|
||||
action: () => {
|
||||
navigate(`/incidents?monitorId=${monitor._id}`);
|
||||
navigate(`/incidents?monitorId=${monitor.id}`);
|
||||
},
|
||||
},
|
||||
{
|
||||
id: 4,
|
||||
label: t("monitors.common.actions.configure"),
|
||||
action: () => {
|
||||
navigate(`/infrastructure/${monitor._id}/configure`);
|
||||
navigate(`/infrastructure/${monitor.id}/configure`);
|
||||
},
|
||||
},
|
||||
// {
|
||||
@@ -128,7 +128,7 @@ export const InfraMonitorsTable = ({
|
||||
? t("common.buttons.resume")
|
||||
: t("common.buttons.pause"),
|
||||
action: async () => {
|
||||
await patch(`/monitors/${monitor._id}/active`);
|
||||
await patch(`/monitors/${monitor.id}/active`);
|
||||
refetch();
|
||||
},
|
||||
closeMenu: true,
|
||||
@@ -208,7 +208,7 @@ export const InfraMonitorsTable = ({
|
||||
content: t("monitors.infrastructure.table.headers.cpu"),
|
||||
render: (row) => {
|
||||
const cpuUsage =
|
||||
(checksMap[row._id]?.[0]?.system?.cpu?.usage_percent || 0) * 100;
|
||||
(checksMap[row.id]?.[0]?.system?.cpu?.usage_percent || 0) * 100;
|
||||
return <Gauge progress={cpuUsage} />;
|
||||
},
|
||||
},
|
||||
@@ -217,7 +217,7 @@ export const InfraMonitorsTable = ({
|
||||
content: t("monitors.infrastructure.table.headers.memory"),
|
||||
render: (row) => {
|
||||
const memoryUsage =
|
||||
(checksMap[row._id]?.[0]?.system?.memory?.usage_percent || 0) * 100;
|
||||
(checksMap[row.id]?.[0]?.system?.memory?.usage_percent || 0) * 100;
|
||||
return <Gauge progress={memoryUsage} />;
|
||||
},
|
||||
},
|
||||
@@ -225,11 +225,11 @@ export const InfraMonitorsTable = ({
|
||||
id: "disk",
|
||||
content: t("monitors.infrastructure.table.headers.disk"),
|
||||
render: (row) => {
|
||||
const totalDiskUsage = checksMap[row._id]?.[0]?.system?.disk?.reduce(
|
||||
const totalDiskUsage = checksMap[row.id]?.[0]?.system?.disk?.reduce(
|
||||
(acc, disk) => acc + disk.usage_percent,
|
||||
0
|
||||
);
|
||||
const diskCount = checksMap[row._id]?.[0]?.system?.disk?.length || 1;
|
||||
const diskCount = checksMap[row.id]?.[0]?.system?.disk?.length || 1;
|
||||
const diskUsage = ((totalDiskUsage || 0) / diskCount) * 100;
|
||||
return <Gauge progress={diskUsage} />;
|
||||
},
|
||||
@@ -257,7 +257,7 @@ export const InfraMonitorsTable = ({
|
||||
headers={headers}
|
||||
data={monitors}
|
||||
onRowClick={(row) => {
|
||||
navigate(`/infrastructure/${row._id}`);
|
||||
navigate(`/infrastructure/${row.id}`);
|
||||
}}
|
||||
/>
|
||||
<Pagination
|
||||
|
||||
@@ -98,21 +98,21 @@ export const PageSpeedMonitorTable = ({
|
||||
id: 2,
|
||||
label: t("monitors.common.actions.details"),
|
||||
action: () => {
|
||||
navigate(`${monitor._id}`);
|
||||
navigate(`${monitor.id}`);
|
||||
},
|
||||
},
|
||||
{
|
||||
id: 3,
|
||||
label: t("monitors.common.actions.incidents"),
|
||||
action: () => {
|
||||
navigate(`/incidents?monitorId=${monitor._id}`);
|
||||
navigate(`/incidents?monitorId=${monitor.id}`);
|
||||
},
|
||||
},
|
||||
{
|
||||
id: 4,
|
||||
label: t("monitors.common.actions.configure"),
|
||||
action: () => {
|
||||
navigate(`/pagespeed/${monitor._id}/configure`);
|
||||
navigate(`/pagespeed/${monitor.id}/configure`);
|
||||
},
|
||||
},
|
||||
// {
|
||||
@@ -129,7 +129,7 @@ export const PageSpeedMonitorTable = ({
|
||||
? t("common.buttons.resume")
|
||||
: t("common.buttons.pause"),
|
||||
action: async () => {
|
||||
await patch(`/monitors/${monitor._id}/active`);
|
||||
await patch(`/monitors/${monitor.id}/active`);
|
||||
refetch();
|
||||
},
|
||||
closeMenu: true,
|
||||
@@ -207,7 +207,7 @@ export const PageSpeedMonitorTable = ({
|
||||
return (
|
||||
<Stack alignItems={"center"}>
|
||||
<HistogramPageSpeed
|
||||
checks={checksMap[row._id] ?? []}
|
||||
checks={checksMap[row.id] ?? []}
|
||||
status={row.status}
|
||||
/>
|
||||
</Stack>
|
||||
@@ -237,7 +237,7 @@ export const PageSpeedMonitorTable = ({
|
||||
headers={headers}
|
||||
data={monitors}
|
||||
onRowClick={(row) => {
|
||||
navigate(`/pagespeed/${row._id}`);
|
||||
navigate(`/pagespeed/${row.id}`);
|
||||
}}
|
||||
/>
|
||||
<Pagination
|
||||
|
||||
@@ -71,7 +71,7 @@ const PageSpeedMonitorsPage = () => {
|
||||
const monitorLimitReached = useLimitReached("monitorsMax", count);
|
||||
|
||||
const handleConfirm = async () => {
|
||||
await deleteFn(`/monitors/${selectedMonitor?._id}`);
|
||||
await deleteFn(`/monitors/${selectedMonitor?.id}`);
|
||||
setSelectedMonitor(null);
|
||||
refetch();
|
||||
};
|
||||
|
||||
@@ -155,7 +155,7 @@ const UptimeDetailsPage = () => {
|
||||
<ChartAvgResponse avg={avgResponseTime} max={maxResponseTime} />
|
||||
</Stack>
|
||||
<ChartResponseTime checks={checksAll} range={range} />
|
||||
<CheckTable monitorId={monitor?._id} />
|
||||
<CheckTable monitorId={monitor?.id} />
|
||||
</BasePage>
|
||||
);
|
||||
};
|
||||
|
||||
@@ -97,7 +97,7 @@ const UptimeMonitors = () => {
|
||||
const monitorLimitReached = useLimitReached("monitorsMax", count);
|
||||
|
||||
const handleConfirm = async () => {
|
||||
await deleteFn(`/monitors/${selectedMonitor?._id}`);
|
||||
await deleteFn(`/monitors/${selectedMonitor?.id}`);
|
||||
setSelectedMonitor(null);
|
||||
refetch();
|
||||
};
|
||||
|
||||
@@ -102,21 +102,21 @@ export const MonitorTable = ({
|
||||
id: 2,
|
||||
label: t("monitors.common.actions.details"),
|
||||
action: () => {
|
||||
navigate(`${monitor._id}`);
|
||||
navigate(`${monitor.id}`);
|
||||
},
|
||||
},
|
||||
{
|
||||
id: 3,
|
||||
label: t("monitors.common.actions.incidents"),
|
||||
action: () => {
|
||||
navigate(`/incidents?monitorId=${monitor._id}`);
|
||||
navigate(`/incidents?monitorId=${monitor.id}`);
|
||||
},
|
||||
},
|
||||
{
|
||||
id: 4,
|
||||
label: t("monitors.common.actions.configure"),
|
||||
action: () => {
|
||||
navigate(`/uptime/${monitor._id}/configure`);
|
||||
navigate(`/uptime/${monitor.id}/configure`);
|
||||
},
|
||||
},
|
||||
// {
|
||||
@@ -133,7 +133,7 @@ export const MonitorTable = ({
|
||||
? t("common.buttons.resume")
|
||||
: t("common.buttons.pause"),
|
||||
action: async () => {
|
||||
await patch(`/monitors/${monitor._id}/active`);
|
||||
await patch(`/monitors/${monitor.id}/active`);
|
||||
refetch();
|
||||
},
|
||||
closeMenu: true,
|
||||
@@ -209,9 +209,9 @@ export const MonitorTable = ({
|
||||
content: t("monitors.uptime.table.headers.responseTime"),
|
||||
render: (row) => {
|
||||
if (chartType === "histogram") {
|
||||
return <HistogramResponseTime checks={checksMap[row._id] ?? []} />;
|
||||
return <HistogramResponseTime checks={checksMap[row.id] ?? []} />;
|
||||
} else {
|
||||
return <HeatmapResponseTime checks={checksMap[row._id] ?? []} />;
|
||||
return <HeatmapResponseTime checks={checksMap[row.id] ?? []} />;
|
||||
}
|
||||
},
|
||||
},
|
||||
@@ -253,7 +253,7 @@ export const MonitorTable = ({
|
||||
headers={headers}
|
||||
data={monitors}
|
||||
onRowClick={(row) => {
|
||||
navigate(`/uptime/${row._id}`);
|
||||
navigate(`/uptime/${row.id}`);
|
||||
}}
|
||||
/>
|
||||
<Pagination
|
||||
|
||||
@@ -19,11 +19,13 @@ export const MonitorStatuses = [
|
||||
"down",
|
||||
"paused",
|
||||
"initializing",
|
||||
"resuming",
|
||||
] as const;
|
||||
|
||||
export type MonitorStatus = (typeof MonitorStatuses)[number];
|
||||
|
||||
export interface IMonitor {
|
||||
id: string;
|
||||
checks: ICheck[];
|
||||
createdAt: string;
|
||||
createdBy: string;
|
||||
@@ -47,7 +49,6 @@ export interface IMonitor {
|
||||
temperature: number;
|
||||
};
|
||||
__v: number;
|
||||
_id: string;
|
||||
}
|
||||
|
||||
export interface IMonitorWithStats {
|
||||
|
||||
@@ -21,6 +21,7 @@ export const getStatusPalette = (status: MonitorStatus): PaletteKey => {
|
||||
down: "error",
|
||||
paused: "warning",
|
||||
initializing: "warning",
|
||||
resuming: "warning",
|
||||
};
|
||||
return paletteMap[status];
|
||||
};
|
||||
@@ -40,6 +41,7 @@ export const getStatusColor = (status: MonitorStatus, theme: any): string => {
|
||||
down: theme.palette.error.light,
|
||||
paused: theme.palette.warning.light,
|
||||
initializing: theme.palette.warning.light,
|
||||
resuming: theme.palette.warning.light,
|
||||
};
|
||||
return statusColors[status];
|
||||
};
|
||||
|
||||
Reference in new issue
Block a user