2024-12-03 15:29:19 +08:00
//Components
2025-07-23 09:03:51 -04:00
import {
2025-07-23 20:01:39 -04:00
Box ,
Button ,
ButtonGroup ,
FormControlLabel ,
Stack ,
Switch ,
Tooltip ,
Typography ,
2025-07-23 09:03:51 -04:00
} from "@mui/material" ;
2024-12-03 15:29:19 +08:00
import Breadcrumbs from "../../../Components/Breadcrumbs" ;
2024-11-26 12:21:42 +08:00
import TextInput from "../../../Components/Inputs/TextInput" ;
import { HttpAdornment } from "../../../Components/Inputs/TextInput/Adornments" ;
2024-12-03 15:29:19 +08:00
import Radio from "../../../Components/Inputs/Radio" ;
import Select from "../../../Components/Inputs/Select" ;
2024-12-18 12:20:18 -08:00
import ConfigBox from "../../../Components/ConfigBox" ;
2025-06-09 12:55:45 +08:00
import NotificationsConfig from "../../../Components/NotificationConfig" ;
2025-06-13 11:07:37 +08:00
import Checkbox from "../../../Components/Inputs/Checkbox" ;
2025-07-23 09:03:51 -04:00
import Dialog from "../../../Components/Dialog" ;
import PulseDot from "../../../Components/Animated/PulseDot" ;
import SkeletonLayout from "./skeleton" ;
2025-06-12 12:44:46 +08:00
// Utils
2025-07-25 13:37:17 -04:00
import PropTypes from "prop-types" ;
2025-06-12 12:44:46 +08:00
import { useTheme } from "@emotion/react" ;
2025-07-23 15:31:26 -07:00
import { useEffect , useState } from "react" ;
2025-06-12 12:44:46 +08:00
import { useTranslation } from "react-i18next" ;
import { monitorValidation } from "../../../Validation/validation" ;
import { createToast } from "../../../Utils/toastUtils" ;
2025-07-23 09:03:51 -04:00
import {
2025-07-23 20:01:39 -04:00
PauseOutlined as PauseOutlinedIcon ,
PlayArrowOutlined as PlayArrowOutlinedIcon ,
2025-07-23 09:03:51 -04:00
} from "@mui/icons-material" ;
import { useMonitorUtils } from "../../../Hooks/useMonitorUtils" ;
2025-06-12 12:44:46 +08:00
import { useGetNotificationsByTeamId } from "../../../Hooks/useNotifications" ;
2025-07-23 15:31:26 -07:00
import { useParams } from "react-router-dom" ;
2025-07-23 09:03:51 -04:00
import {
2025-07-24 13:38:14 -04:00
useCreateMonitor ,
2025-07-23 20:01:39 -04:00
useDeleteMonitor ,
useUpdateMonitor ,
usePauseMonitor ,
useFetchMonitorById ,
2025-08-03 13:19:55 +03:00
useFetchMonitorGames ,
2025-07-23 09:03:51 -04:00
} from "../../../Hooks/monitorHooks" ;
2025-06-09 12:55:45 +08:00
2025-07-23 09:03:51 -04:00
/**
* Create page renders monitor creation or configuration views.
* @component
*/
2025-07-25 13:37:17 -04:00
const UptimeCreate = ({ isClone = false }) => {
2025-07-23 20:01:39 -04:00
const { monitorId } = useParams ();
2025-07-25 13:37:17 -04:00
const isCreate = typeof monitorId === "undefined" || isClone ;
2025-06-09 12:55:45 +08:00
2025-07-23 20:01:39 -04:00
// States
2025-06-09 12:55:45 +08:00
const [ monitor , setMonitor ] = useState ({
type : "http" ,
2025-08-18 15:34:30 -07:00
statusWindowSize : 5 ,
statusWindowThreshold : 60 ,
2025-06-09 12:55:45 +08:00
matchMethod : "equal" ,
2025-06-13 11:07:37 +08:00
expectedValue : "" ,
jsonPath : "" ,
2025-06-09 12:55:45 +08:00
notifications : [],
2025-07-23 20:01:39 -04:00
interval : 60000 ,
2025-06-09 12:55:45 +08:00
ignoreTlsErrors : false ,
2025-07-23 20:01:39 -04:00
...( isCreate ? { url : "" , name : "" } : { port : undefined }),
2025-06-09 12:55:45 +08:00
});
2025-07-23 20:01:39 -04:00
const [ errors , setErrors ] = useState ({});
const [ https , setHttps ] = useState ( true );
const [ isOpen , setIsOpen ] = useState ( false );
const [ useAdvancedMatching , setUseAdvancedMatching ] = useState ( false );
const [ updateTrigger , setUpdateTrigger ] = useState ( false );
2025-08-03 13:19:55 +03:00
const [ games , setGames ] = useState ({});
2025-07-23 20:01:39 -04:00
const triggerUpdate = () => {
setUpdateTrigger ( ! updateTrigger );
2025-07-23 15:31:26 -07:00
};
2025-07-23 20:01:39 -04:00
// Hooks
const [ notifications , notificationsAreLoading , notificationsError ] =
useGetNotificationsByTeamId ();
const { determineState , statusColor } = useMonitorUtils ();
2025-08-03 13:19:55 +03:00
// Fetch monitor details
const [ isFetchingMonitor ] = useFetchMonitorById ({
2025-07-23 15:31:26 -07:00
monitorId ,
2025-07-24 13:38:14 -04:00
setMonitor ,
2025-07-23 15:31:26 -07:00
updateTrigger : true ,
});
2025-08-03 13:19:55 +03:00
// Fetch games
const [ isFetchingGames ] = useFetchMonitorGames ({
setGames ,
triggerUpdate : true ,
});
// Combine the loading states
const isLoading = isFetchingMonitor || isFetchingGames ;
2025-07-23 20:01:39 -04:00
const [ createMonitor , isCreating ] = useCreateMonitor ();
const [ pauseMonitor , isPausing ] = usePauseMonitor ({});
const [ deleteMonitor , isDeleting ] = useDeleteMonitor ();
const [ updateMonitor , isUpdating ] = useUpdateMonitor ();
2025-06-09 12:55:45 +08:00
2025-07-23 20:01:39 -04:00
// Setup
const theme = useTheme ();
const { t } = useTranslation ();
2024-12-03 15:29:19 +08:00
2025-07-23 20:01:39 -04:00
// Constants
const MS_PER_MINUTE = 60000 ;
const FREQUENCIES = [
{ _id : 1 , name : t ( "time.oneMinute" ) },
{ _id : 2 , name : t ( "time.twoMinutes" ) },
{ _id : 3 , name : t ( "time.threeMinutes" ) },
{ _id : 4 , name : t ( "time.fourMinutes" ) },
{ _id : 5 , name : t ( "time.fiveMinutes" ) },
];
2025-08-02 02:25:58 +03:00
2025-08-03 13:19:55 +03:00
const GAMELIST = Object . entries ( games ). map (([ key , value ]) => ({
2025-08-02 02:04:06 +03:00
_id : key ,
2025-08-02 02:25:58 +03:00
name : value . name ,
2025-08-02 02:04:06 +03:00
}));
2025-07-23 20:01:39 -04:00
const CRUMBS = [
{ name : "uptime" , path : "/uptime" },
...( isCreate
? [{ name : "create" , path : `/uptime/create` }]
: [
{ name : "details" , path : `/uptime/ ${ monitorId } ` },
{ name : "configure" , path : `/uptime/configure/ ${ monitorId } ` },
]),
];
2025-02-14 02:45:24 +00:00
const matchMethodOptions = [
2025-07-23 20:01:39 -04:00
{ _id : "equal" , name : t ( "matchMethodOptions.equal" ) },
{ _id : "include" , name : t ( "matchMethodOptions.include" ) },
{ _id : "regex" , name : t ( "matchMethodOptions.regex" ) },
2025-02-14 02:45:24 +00:00
];
const expectedValuePlaceholders = {
2025-07-23 20:01:39 -04:00
regex : t ( "matchMethodOptions.regexPlaceholder" ),
equal : t ( "matchMethodOptions.equalPlaceholder" ),
include : t ( "matchMethodOptions.includePlaceholder" ),
2025-02-14 02:45:24 +00:00
};
2024-12-04 09:53:06 +08:00
const monitorTypeMaps = {
http : {
2025-07-23 20:01:39 -04:00
label : t ( "monitorType.http.label" ),
placeholder : t ( "monitorType.http.placeholder" ),
namePlaceholder : t ( "monitorType.http.namePlaceholder" ),
2024-12-04 09:53:06 +08:00
},
ping : {
2025-07-23 20:01:39 -04:00
label : t ( "monitorType.ping.label" ),
placeholder : t ( "monitorType.ping.placeholder" ),
namePlaceholder : t ( "monitorType.ping.namePlaceholder" ),
2024-12-04 09:53:06 +08:00
},
docker : {
2025-07-23 20:01:39 -04:00
label : t ( "monitorType.docker.label" ),
placeholder : t ( "monitorType.docker.placeholder" ),
namePlaceholder : t ( "monitorType.docker.namePlaceholder" ),
2024-12-04 09:53:06 +08:00
},
2024-12-27 11:16:58 -08:00
port : {
2025-07-23 20:01:39 -04:00
label : t ( "monitorType.port.label" ),
placeholder : t ( "monitorType.port.placeholder" ),
namePlaceholder : t ( "monitorType.port.namePlaceholder" ),
2024-12-27 11:16:58 -08:00
},
2025-08-02 02:04:06 +03:00
game : {
label : t ( "monitorType.game.label" ),
placeholder : t ( "monitorType.game.placeholder" ),
namePlaceholder : t ( "monitorType.game.namePlaceholder" ),
2025-08-02 02:25:58 +03:00
},
2024-12-04 09:53:06 +08:00
};
2025-06-09 12:55:45 +08:00
// Handlers
const onSubmit = async ( event ) => {
2024-10-17 12:05:06 +08:00
event . preventDefault ();
2025-06-09 12:55:45 +08:00
const { notifications , ... rest } = monitor ;
2025-07-23 20:01:39 -04:00
let form = {};
if ( isCreate ) {
form = {
url :
2025-07-25 11:11:39 -04:00
monitor . type === "http" && ! isClone
2025-07-23 20:01:39 -04:00
? `http ${ https ? "s" : "" } ://` + monitor . url
: monitor . url ,
name : monitor . name || monitor . url . substring ( 0 , 50 ),
2025-08-18 15:34:30 -07:00
statusWindowSize : monitor . statusWindowSize ,
statusWindowThreshold : monitor . statusWindowThreshold ,
2025-07-23 20:01:39 -04:00
type : monitor . type ,
2025-08-18 15:34:30 -07:00
2025-08-02 02:25:58 +03:00
port :
monitor . type === "port" || monitor . type === "game" ? monitor . port : undefined ,
2025-07-23 20:01:39 -04:00
interval : monitor . interval ,
2025-07-25 11:11:39 -04:00
matchMethod : monitor . matchMethod ,
expectedValue : monitor . expectedValue ,
jsonPath : monitor . jsonPath ,
ignoreTlsErrors : monitor . ignoreTlsErrors ,
2025-08-02 02:04:06 +03:00
gameId : monitor . gameId || undefined ,
2025-07-23 20:01:39 -04:00
};
} else {
form = {
_id : monitor . _id ,
url : monitor . url ,
name : monitor . name || monitor . url . substring ( 0 , 50 ),
2025-08-18 15:34:30 -07:00
statusWindowSize : monitor . statusWindowSize ,
statusWindowThreshold : monitor . statusWindowThreshold ,
2025-07-23 20:01:39 -04:00
type : monitor . type ,
matchMethod : monitor . matchMethod ,
expectedValue : monitor . expectedValue ,
jsonPath : monitor . jsonPath ,
interval : monitor . interval ,
teamId : monitor . teamId ,
userId : monitor . userId ,
2025-08-02 02:25:58 +03:00
port :
monitor . type === "port" || monitor . type === "game" ? monitor . port : undefined ,
2025-07-23 20:01:39 -04:00
ignoreTlsErrors : monitor . ignoreTlsErrors ,
2025-08-02 02:04:06 +03:00
gameId : monitor . gameId || undefined ,
2025-07-23 20:01:39 -04:00
};
}
2025-06-09 12:55:45 +08:00
if ( ! useAdvancedMatching ) {
2025-07-23 20:01:39 -04:00
form . matchMethod = isCreate ? undefined : "" ;
form . expectedValue = isCreate ? undefined : "" ;
form . jsonPath = isCreate ? undefined : "" ;
2025-02-13 00:54:24 +00:00
}
2024-10-17 12:05:06 +08:00
const { error } = monitorValidation . validate ( form , {
abortEarly : false ,
});
2024-07-18 12:11:27 -07:00
2024-10-17 12:05:06 +08:00
if ( error ) {
const newErrors = {};
error . details . forEach (( err ) => {
newErrors [ err . path [ 0 ]] = err . message ;
});
setErrors ( newErrors );
2025-07-23 20:01:39 -04:00
createToast ({ body : t ( "checkFormError" ) });
2024-12-03 15:29:19 +08:00
return ;
}
form = {
... form ,
2025-02-01 22:14:27 +08:00
description : monitor . name || monitor . url ,
2024-12-03 15:29:19 +08:00
notifications : monitor . notifications ,
};
2025-06-09 12:55:45 +08:00
2025-07-23 20:01:39 -04:00
if ( isCreate ) {
await createMonitor ({ monitor : form , redirect : "/uptime" });
} else {
await updateMonitor ({ monitor : form , redirect : "/uptime" });
}
2024-12-03 15:29:19 +08:00
};
2025-06-09 12:55:45 +08:00
const onChange = ( event ) => {
2025-07-23 20:01:39 -04:00
let { name , value , checked } = event . target ;
2025-06-18 10:10:14 +08:00
2025-06-09 12:55:45 +08:00
if ( name === "ignoreTlsErrors" ) {
2025-07-23 20:01:39 -04:00
value = checked ;
2025-06-09 12:55:45 +08:00
}
2025-06-13 11:07:37 +08:00
if ( name === "useAdvancedMatching" ) {
setUseAdvancedMatching ( checked );
return ;
}
2025-07-23 20:01:39 -04:00
if ( name === "interval" ) {
value = value * MS_PER_MINUTE ;
}
2025-06-09 12:55:45 +08:00
2025-07-23 20:01:39 -04:00
setMonitor (( prev ) => ({ ... prev , [ name ] : value }));
2024-12-03 15:29:19 +08:00
2025-08-06 00:53:35 +03:00
if ( name === "type" ) {
setErrors ({});
return ;
}
2024-12-03 15:29:19 +08:00
const { error } = monitorValidation . validate (
2025-07-23 20:01:39 -04:00
{ type : monitor . type , [ name ] : value },
2024-12-03 15:29:19 +08:00
{ abortEarly : false }
);
2024-10-12 22:58:39 +05:30
2025-06-09 12:55:45 +08:00
setErrors (( prev ) => ({
2024-12-03 15:29:19 +08:00
... prev ,
2025-08-06 00:53:35 +03:00
...( error && error . details [ 0 ]. path [ 0 ] === name
? { [ name ] : error . details [ 0 ]. message }
: { [ name ] : undefined }),
2024-12-03 15:29:19 +08:00
}));
2024-10-17 12:05:06 +08:00
};
2024-06-27 16:44:56 -04:00
2025-07-23 20:01:39 -04:00
const handlePause = async () => {
await pauseMonitor ({ monitorId , triggerUpdate });
};
2025-06-13 11:07:37 +08:00
2025-07-23 20:01:39 -04:00
const handleRemove = async ( event ) => {
event . preventDefault ();
await deleteMonitor ({ monitor , redirect : "/uptime" });
};
2025-06-09 12:55:45 +08:00
2025-07-23 20:01:39 -04:00
const isBusy = isLoading || isCreating || isDeleting || isUpdating || isPausing ;
2025-07-24 13:38:14 -04:00
const displayInterval = monitor ? . interval / MS_PER_MINUTE || 1 ;
2025-08-19 01:11:56 +05:30
const parsedUrl = monitor ? . url ;
2025-07-23 20:01:39 -04:00
const protocol = parsedUrl ? . protocol ? . replace ( ":" , "" ) || "" ;
2024-12-03 15:29:19 +08:00
2025-07-23 20:01:39 -04:00
useEffect (() => {
2025-07-25 11:11:39 -04:00
if ( ! isCreate || isClone ) {
2025-07-23 20:01:39 -04:00
if ( monitor . matchMethod ) {
setUseAdvancedMatching ( true );
} else {
setUseAdvancedMatching ( false );
}
}
2025-07-23 21:13:19 -04:00
}, [ monitor , isCreate ]);
if ( Object . keys ( monitor ). length === 0 ) {
return < SkeletonLayout />;
}
2024-10-12 22:58:39 +05:30
2024-10-17 12:05:06 +08:00
return (
2025-06-09 12:55:45 +08:00
< Stack gap = { theme . spacing ( 10 )}>
2025-07-23 20:01:39 -04:00
< Breadcrumbs list = { CRUMBS } />
2025-06-09 12:55:45 +08:00
2024-10-17 12:05:06 +08:00
< Stack
component = "form"
2025-07-23 20:01:39 -04:00
onSubmit = { onSubmit }
2025-06-09 12:55:45 +08:00
noValidate
2025-07-23 20:01:39 -04:00
spellCheck = "false"
2024-10-17 12:05:06 +08:00
gap = { theme . spacing ( 12 )}
2025-07-23 20:01:39 -04:00
flex = { 1 }
2024-10-17 12:05:06 +08:00
>
2025-07-23 20:01:39 -04:00
< Stack
direction = "row"
gap = { theme . spacing ( 12 )}
>
2024-10-17 12:05:06 +08:00
< Box >
2025-05-27 09:10:32 -07:00
< Typography
2025-07-23 20:01:39 -04:00
component = "h1"
variant = "h1"
2025-05-27 09:10:32 -07:00
>
2025-07-23 20:01:39 -04:00
< Typography
component = "span"
fontSize = "inherit"
color = {
! isCreate ? theme . palette . primary . contrastTextSecondary : undefined
}
>
{ ! isCreate ? monitor . name : t ( "createYour" ) + " " }
</ Typography >
{ isCreate && (
< Typography
component = "span"
fontSize = "inherit"
fontWeight = "inherit"
color = { theme . palette . primary . contrastTextSecondary }
>
{ t ( "monitor" )}
</ Typography >
)}
2024-10-17 12:05:06 +08:00
</ Typography >
2025-07-23 20:01:39 -04:00
{ ! isCreate && (
< Stack
direction = "row"
alignItems = "center"
height = "fit-content"
gap = { theme . spacing ( 2 )}
>
< Tooltip
title = { t ( `statusMsg. ${ [ determineState ( monitor )] } ` )}
disableInteractive
slotProps = {{
popper : {
modifiers : [
{
name : "offset" ,
options : {
offset : [ 0 , - 8 ],
},
},
],
},
}}
>
< Box >
< PulseDot color = { statusColor [ determineState ( monitor )]} />
</ Box >
</ Tooltip >
< Typography
component = "h2"
variant = "monitorUrl"
>
{ monitor . url ? . replace ( /^https?:\/\// , "" ) || "..." }
</ Typography >
< Typography
position = "relative"
variant = "body2"
ml = { theme . spacing ( 6 )}
mt = { theme . spacing ( 1 )}
sx = {{
"&:before" : {
position : "absolute" ,
content : `""` ,
2025-07-23 21:13:19 -04:00
width : theme . spacing ( 2 ),
height : theme . spacing ( 2 ),
2025-07-23 20:01:39 -04:00
borderRadius : "50%" ,
backgroundColor : theme . palette . primary . contrastTextTertiary ,
opacity : 0.8 ,
2025-07-23 21:13:19 -04:00
left : theme . spacing ( - 5 ),
2025-07-23 20:01:39 -04:00
top : "50%" ,
transform : "translateY(-50%)" ,
},
}}
>
{ t ( "editing" )}
</ Typography >
</ Stack >
)}
2024-10-17 12:05:06 +08:00
</ Box >
2025-07-23 20:01:39 -04:00
{ ! isCreate && (
< Box
justifyContent = "space-between"
sx = {{
alignSelf : "flex-end" ,
ml : "auto" ,
display : "flex" ,
gap : theme . spacing ( 2 ),
}}
>
< Button
variant = "contained"
color = "secondary"
loading = { isBusy }
startIcon = {
monitor ? . isActive ? < PauseOutlinedIcon /> : < PlayArrowOutlinedIcon />
}
onClick = { handlePause }
>
{ monitor ? . isActive ? t ( "pause" ) : t ( "resume" )}
</ Button >
< Button
loading = { isBusy }
variant = "contained"
color = "error"
sx = {{ px : theme . spacing ( 8 ) }}
onClick = {() => setIsOpen ( true )}
>
{ t ( "remove" )}
</ Button >
</ Box >
)}
</ Stack >
{ isCreate && (
< ConfigBox >
< Box >
< Typography
component = "h2"
variant = "h2"
>
{ t ( "distributedUptimeCreateChecks" )}
</ Typography >
< Typography component = "p" >
{ t ( "distributedUptimeCreateChecksDescription" )}
</ Typography >
</ Box >
< Stack gap = { theme . spacing ( 12 )}>
< Stack gap = { theme . spacing ( 6 )}>
< Radio
name = "type"
title = { t ( "websiteMonitoring" )}
desc = { t ( "websiteMonitoringDescription" )}
size = "small"
value = "http"
checked = { monitor . type === "http" }
onChange = { onChange }
/>
{ monitor . type === "http" ? (
< ButtonGroup sx = {{ ml : theme . spacing ( 16 ) }}>
< Button
variant = "group"
filled = { https . toString ()}
onClick = {() => setHttps ( true )}
>
{ t ( "https" )}
</ Button >
< Button
variant = "group"
filled = {( ! https ). toString ()}
onClick = {() => setHttps ( false )}
>
{ t ( "http" )}
</ Button >
</ ButtonGroup >
) : (
""
)}
</ Stack >
2024-10-17 12:05:06 +08:00
< Radio
2025-06-09 12:55:45 +08:00
name = "type"
2025-07-23 20:01:39 -04:00
title = { t ( "pingMonitoring" )}
desc = { t ( "pingMonitoringDescription" )}
2024-10-17 12:05:06 +08:00
size = "small"
2025-07-23 20:01:39 -04:00
value = "ping"
checked = { monitor . type === "ping" }
2025-06-09 12:55:45 +08:00
onChange = { onChange }
2024-10-17 12:05:06 +08:00
/>
2025-07-23 20:01:39 -04:00
< Radio
name = "type"
title = { t ( "dockerContainerMonitoring" )}
desc = { t ( "dockerContainerMonitoringDescription" )}
size = "small"
value = "docker"
checked = { monitor . type === "docker" }
onChange = { onChange }
/>
< Radio
name = "type"
title = { t ( "portMonitoring" )}
desc = { t ( "portMonitoringDescription" )}
size = "small"
value = "port"
checked = { monitor . type === "port" }
onChange = { onChange }
/>
2025-08-02 02:04:06 +03:00
< Radio
name = "type"
title = { t ( "gameServerMonitoring" )}
desc = { t ( "gameServerMonitoringDescription" )}
size = "small"
value = "game"
checked = { monitor . type === "game" }
onChange = { onChange }
/>
2025-07-23 20:01:39 -04:00
{ errors [ "type" ] ? (
< Box className = "error-container" >
< Typography
component = "p"
className = "input-error"
color = { theme . palette . error . contrastText }
2024-10-17 12:05:06 +08:00
>
2025-07-23 20:01:39 -04:00
{ errors [ "type" ]}
</ Typography >
</ Box >
2024-10-17 12:05:06 +08:00
) : (
""
)}
</ Stack >
2025-07-23 20:01:39 -04:00
</ ConfigBox >
)}
2025-01-26 20:50:12 -05:00
< ConfigBox >
< Box >
2025-05-27 09:10:32 -07:00
< Typography
component = "h2"
variant = "h2"
>
{ t ( "settingsGeneralSettings" )}
</ Typography >
2025-06-08 08:14:17 +08:00
< Typography component = "p" >
2025-07-23 20:01:39 -04:00
{ isCreate
? t ( `uptimeGeneralInstructions. ${ monitor . type } ` )
: t ( "distributedUptimeCreateSelectURL" )}
2025-06-08 08:14:17 +08:00
</ Typography >
2025-01-26 20:50:12 -05:00
</ Box >
2025-07-23 20:01:39 -04:00
< Stack gap = { theme . spacing ( 20 )}>
2025-01-26 20:50:12 -05:00
< TextInput
2025-07-23 20:01:39 -04:00
id = "monitor-url"
2025-06-09 12:55:45 +08:00
name = "url"
2025-07-23 20:01:39 -04:00
type = { monitor ? . type === "http" ? "url" : "text" }
label = {
( monitor . type === "http" || monitor . type === "port" ) && ! isCreate
? t ( "url" )
: monitorTypeMaps [ monitor . type ]. label || t ( "urlMonitor" )
2025-01-26 20:50:12 -05:00
}
placeholder = { monitorTypeMaps [ monitor . type ]. placeholder || "" }
2025-07-24 13:38:14 -04:00
value = { parsedUrl ? . host + parsedUrl ? . pathname || monitor ? . url || "" }
2025-07-23 20:01:39 -04:00
https = { isCreate ? https : protocol === "https" }
startAdornment = {
monitor ? . type === "http" && (
< HttpAdornment https = { isCreate ? https : protocol === "https" } />
)
}
2025-01-26 20:50:12 -05:00
helperText = { errors [ "url" ]}
2025-07-23 20:01:39 -04:00
onChange = { onChange }
disabled = { ! isCreate }
2025-01-26 20:50:12 -05:00
/>
< TextInput
2025-06-09 12:55:45 +08:00
name = "port"
2025-01-26 20:50:12 -05:00
type = "number"
2025-03-17 01:16:42 +05:30
label = { t ( "portToMonitor" )}
2025-01-26 20:50:12 -05:00
placeholder = "5173"
2025-07-23 20:01:39 -04:00
value = { monitor . port || "" }
2025-06-09 12:55:45 +08:00
onChange = { onChange }
2025-01-26 20:50:12 -05:00
error = { errors [ "port" ] ? true : false }
helperText = { errors [ "port" ]}
2025-08-02 02:04:06 +03:00
hidden = { monitor . type !== "port" && monitor . type !== "game" }
2025-01-26 20:50:12 -05:00
/>
2025-08-02 02:25:58 +03:00
{ monitor . type === "game" && (
< Select
name = "gameId"
label = { t ( "chooseGame" )}
value = { monitor . gameId || "" }
placeholder = { t ( "chooseGame" )}
onChange = { onChange }
items = { GAMELIST }
2025-08-06 00:53:35 +03:00
error = { errors [ "gameId" ] ? true : false }
2025-08-02 02:25:58 +03:00
/>
)}
2025-01-26 20:50:12 -05:00
< TextInput
2025-06-09 12:55:45 +08:00
name = "name"
2025-01-26 20:50:12 -05:00
type = "text"
2025-03-17 01:16:42 +05:30
label = { t ( "displayName" )}
2025-01-26 20:50:12 -05:00
isOptional = { true }
2025-07-23 20:01:39 -04:00
placeholder = { monitorTypeMaps [ monitor . type ]. namePlaceholder }
value = { monitor . name || "" }
2025-06-09 12:55:45 +08:00
onChange = { onChange }
2025-01-26 20:50:12 -05:00
error = { errors [ "name" ] ? true : false }
helperText = { errors [ "name" ]}
/>
</ Stack >
</ ConfigBox >
2025-08-18 15:34:30 -07:00
< ConfigBox >
< Box >
< Typography
component = "h2"
variant = "h2"
>
Incidents
</ Typography >
< Typography component = "p" >
{
"A sliding window is used to determine when a monitor goes down. The status of a monitor will only change when the percentage of checks in the sliding window meet the specified value."
}
</ Typography >
</ Box >
< Stack gap = { theme . spacing ( 20 )}>
< TextInput
name = "statusWindowSize"
label = { "How many checks should be in the sliding window?" }
type = "number"
value = { monitor . statusWindowSize }
onChange = { onChange }
error = { errors [ "statusWindowSize" ] ? true : false }
helperText = { errors [ "statusWindowSize" ]}
/>
< TextInput
name = "statusWindowThreshold"
label = {
"What percentage of checks in the sliding window fail/succeed before monitor status changes?"
}
type = "number"
value = { monitor . statusWindowThreshold }
onChange = { onChange }
error = { errors [ "statusWindowThreshold" ] ? true : false }
helperText = { errors [ "statusWindowThreshold" ]}
/>
</ Stack >
</ ConfigBox >
2024-10-17 12:05:06 +08:00
< ConfigBox >
< Box >
2025-07-28 16:28:44 -04:00
< Typography
component = "h2"
variant = "h2"
>
{ t ( "notificationConfig.title" )}
</ Typography >
2025-06-09 14:22:11 +08:00
< Typography component = "p" >{ t ( "notificationConfig.description" )}</ Typography >
2024-10-17 12:05:06 +08:00
</ Box >
2025-06-09 12:55:45 +08:00
< NotificationsConfig
notifications = { notifications }
setMonitor = { setMonitor }
2025-07-23 20:01:39 -04:00
setNotifications = { isCreate ? null : monitor . notifications }
2025-06-09 12:55:45 +08:00
/>
2024-10-17 12:05:06 +08:00
</ ConfigBox >
2025-05-08 15:28:44 +05:30
< ConfigBox >
< Box >
2025-05-27 09:10:32 -07:00
< Typography
component = "h2"
variant = "h2"
>
{ t ( "ignoreTLSError" )}
</ Typography >
2025-05-08 15:47:20 +05:30
< Typography component = "p" >{ t ( "ignoreTLSErrorDescription" )}</ Typography >
2025-05-08 15:28:44 +05:30
</ Box >
< Stack >
< FormControlLabel
2025-07-23 20:01:39 -04:00
sx = {{ marginLeft : theme . spacing ( 0 ) }}
2025-05-08 15:28:44 +05:30
control = {
< Switch
2025-06-09 12:55:45 +08:00
name = "ignoreTlsErrors"
2025-05-08 15:28:44 +05:30
checked = { monitor . ignoreTlsErrors }
2025-06-09 12:55:45 +08:00
onChange = { onChange }
2025-05-08 15:28:44 +05:30
sx = {{ mr : theme . spacing ( 2 ) }}
/>
}
2025-05-08 15:47:20 +05:30
label = { t ( "tlsErrorIgnored" )}
2025-05-08 15:28:44 +05:30
/>
</ Stack >
</ ConfigBox >
2024-10-17 12:05:06 +08:00
< ConfigBox >
< Box >
2025-05-27 09:10:32 -07:00
< Typography
component = "h2"
variant = "h2"
>
2025-03-19 09:02:30 -07:00
{ t ( "distributedUptimeCreateAdvancedSettings" )}
</ Typography >
2024-10-17 12:05:06 +08:00
</ Box >
2025-07-23 20:01:39 -04:00
< Stack gap = { theme . spacing ( 20 )}>
2024-10-17 12:05:06 +08:00
< Select
2025-06-09 12:55:45 +08:00
name = "interval"
2025-07-23 20:01:39 -04:00
label = { t ( "checkFrequency" )}
2025-07-24 13:38:14 -04:00
value = { displayInterval }
2025-06-13 11:07:37 +08:00
onChange = { onChange }
2025-07-23 20:01:39 -04:00
items = { FREQUENCIES }
2025-06-13 11:07:37 +08:00
/>
2025-07-23 20:01:39 -04:00
{ monitor . type === "http" && (
< Checkbox
name = "useAdvancedMatching"
label = { t ( "advancedMatching" )}
isChecked = { useAdvancedMatching }
onChange = { onChange }
/>
)}
2025-06-13 11:07:37 +08:00
{ monitor . type === "http" && useAdvancedMatching && (
2025-02-24 14:33:25 -08:00
<>
2025-02-13 00:54:24 +00:00
< Select
2025-06-09 12:55:45 +08:00
name = "matchMethod"
2025-07-23 20:01:39 -04:00
label = { t ( "matchMethod" )}
2025-02-13 00:54:24 +00:00
value = { monitor . matchMethod || "equal" }
2025-06-09 12:55:45 +08:00
onChange = { onChange }
2025-02-14 02:45:24 +00:00
items = { matchMethodOptions }
2025-02-13 00:54:24 +00:00
/>
< Stack >
< TextInput
type = "text"
2025-07-23 20:01:39 -04:00
name = "expectedValue"
label = { t ( "expectedValue" )}
2025-02-13 00:54:24 +00:00
isOptional = { true }
2025-02-24 14:33:25 -08:00
placeholder = {
expectedValuePlaceholders [ monitor . matchMethod || "equal" ]
}
2025-02-13 00:54:24 +00:00
value = { monitor . expectedValue }
2025-06-09 12:55:45 +08:00
onChange = { onChange }
2025-02-13 00:54:24 +00:00
error = { errors [ "expectedValue" ] ? true : false }
helperText = { errors [ "expectedValue" ]}
/>
< Typography
component = "span"
color = { theme . palette . primary . contrastTextTertiary }
opacity = { 0.8 }
>
2025-03-17 01:16:42 +05:30
{ t ( "uptimeCreate" )}
2025-02-13 00:54:24 +00:00
</ Typography >
</ Stack >
< Stack >
< TextInput
2025-06-09 12:55:45 +08:00
name = "jsonPath"
2025-02-13 00:54:24 +00:00
type = "text"
2025-07-23 20:01:39 -04:00
label = { t ( "uptimeAdvancedMatching.jsonPath" )}
2025-02-13 00:54:24 +00:00
isOptional = { true }
2025-03-25 20:54:50 -04:00
placeholder = "data.status"
2025-02-13 00:54:24 +00:00
value = { monitor . jsonPath }
2025-06-09 12:55:45 +08:00
onChange = { onChange }
2025-02-13 00:54:24 +00:00
error = { errors [ "jsonPath" ] ? true : false }
helperText = { errors [ "jsonPath" ]}
/>
< Typography
component = "span"
color = { theme . palette . primary . contrastTextTertiary }
opacity = { 0.8 }
>
2025-07-23 20:01:39 -04:00
{ t ( "uptimeCreateJsonPath" ) + " " }
2025-02-24 14:33:25 -08:00
< Typography
component = "a"
href = "https://jmespath.org/"
target = "_blank"
color = "info"
>
2025-02-13 00:54:24 +00:00
jmespath . org
</ Typography >
2025-07-23 20:01:39 -04:00
{ " " + t ( "uptimeCreateJsonPathQuery" )}
2025-02-13 00:54:24 +00:00
</ Typography >
</ Stack >
</>
2025-02-24 14:33:25 -08:00
)}
2024-10-17 12:05:06 +08:00
</ Stack >
</ ConfigBox >
< Stack
direction = "row"
justifyContent = "flex-end"
>
2025-02-13 15:20:12 -08:00
< Button
2025-06-09 12:55:45 +08:00
type = "submit"
2024-11-13 15:18:03 +08:00
variant = "contained"
2025-01-14 08:09:03 -05:00
color = "accent"
2024-12-03 15:29:19 +08:00
disabled = { ! Object . values ( errors ). every (( value ) => value === undefined )}
2025-07-23 20:01:39 -04:00
loading = { isBusy }
sx = {{ px : theme . spacing ( 12 ) }}
2024-11-13 15:18:03 +08:00
>
2025-07-23 20:01:39 -04:00
{ t ( "settingsSave" )}
2025-02-13 15:20:12 -08:00
</ Button >
2024-10-17 12:05:06 +08:00
</ Stack >
</ Stack >
2025-06-09 12:55:45 +08:00
2025-07-23 20:01:39 -04:00
{ ! isCreate && (
< Dialog
open = { isOpen }
theme = { theme }
title = { t ( "deleteDialogTitle" )}
description = { t ( "deleteDialogDescription" )}
onCancel = {() => setIsOpen ( false )}
confirmationButtonLabel = { t ( "delete" )}
onConfirm = { handleRemove }
isLoading = { isLoading }
/>
)}
2025-06-09 12:55:45 +08:00
</ Stack >
2024-10-17 12:05:06 +08:00
);
2024-06-18 22:39:58 +03:30
};
2025-07-25 13:37:17 -04:00
UptimeCreate . propTypes = {
isClone : PropTypes . bool ,
};
2025-07-23 09:03:51 -04:00
export default UptimeCreate ;