1.18升级
This commit is contained in:
parent
2badfa63e3
commit
19ea644e6e
@ -382,6 +382,8 @@ export const AlertRuleFormDialog: React.FC<AlertRuleFormDialogProps> = ({
|
||||
render={({ field }) => {
|
||||
const currentAlertType = form.watch('alertType');
|
||||
const isServerStatus = currentAlertType === AlertType.SERVER_STATUS;
|
||||
const isNetworkType = currentAlertType === AlertType.NETWORK;
|
||||
const maxValue = isNetworkType ? 10000 : 100;
|
||||
const [localValue, setLocalValue] = React.useState<string>(
|
||||
field.value?.toString() ?? ''
|
||||
);
|
||||
@ -401,7 +403,7 @@ export const AlertRuleFormDialog: React.FC<AlertRuleFormDialogProps> = ({
|
||||
<Input
|
||||
type="number"
|
||||
min="0"
|
||||
max="100"
|
||||
max={maxValue}
|
||||
step={isServerStatus ? "1" : "0.1"}
|
||||
value={localValue}
|
||||
onChange={(e) => {
|
||||
@ -440,6 +442,8 @@ export const AlertRuleFormDialog: React.FC<AlertRuleFormDialogProps> = ({
|
||||
render={({ field }) => {
|
||||
const currentAlertType = form.watch('alertType');
|
||||
const isServerStatus = currentAlertType === AlertType.SERVER_STATUS;
|
||||
const isNetworkType = currentAlertType === AlertType.NETWORK;
|
||||
const maxValue = isNetworkType ? 10000 : 100;
|
||||
const [localValue, setLocalValue] = React.useState<string>(
|
||||
field.value?.toString() ?? ''
|
||||
);
|
||||
@ -459,7 +463,7 @@ export const AlertRuleFormDialog: React.FC<AlertRuleFormDialogProps> = ({
|
||||
<Input
|
||||
type="number"
|
||||
min="0"
|
||||
max="100"
|
||||
max={maxValue}
|
||||
step={isServerStatus ? "1" : "0.1"}
|
||||
value={localValue}
|
||||
onChange={(e) => {
|
||||
|
||||
@ -82,17 +82,51 @@ export const alertRuleFormSchema = z.object({
|
||||
alertType: z.nativeEnum(AlertType, {
|
||||
errorMap: () => ({ message: '请选择告警类型' })
|
||||
}),
|
||||
warningThreshold: z.number()
|
||||
.min(0, '警告阈值不能小于0')
|
||||
.max(100, '警告阈值不能大于100'),
|
||||
criticalThreshold: z.number()
|
||||
.min(0, '严重阈值不能小于0')
|
||||
.max(100, '严重阈值不能大于100'),
|
||||
warningThreshold: z.number().min(0, '警告阈值不能小于0'),
|
||||
criticalThreshold: z.number().min(0, '严重阈值不能小于0'),
|
||||
durationMinutes: z.number()
|
||||
.min(1, '持续时长至少为1分钟'),
|
||||
enabled: z.boolean().default(true),
|
||||
description: z.string().max(500, '描述不能超过500个字符').optional(),
|
||||
}).superRefine((data, ctx) => {
|
||||
// 根据告警类型验证阈值范围
|
||||
const isPercentageType = [AlertType.CPU, AlertType.MEMORY, AlertType.DISK].includes(data.alertType);
|
||||
const isNetworkType = data.alertType === AlertType.NETWORK;
|
||||
|
||||
if (isPercentageType) {
|
||||
// CPU/内存/磁盘使用率:0-100
|
||||
if (data.warningThreshold > 100) {
|
||||
ctx.addIssue({
|
||||
code: 'custom',
|
||||
message: '警告阈值不能大于100',
|
||||
path: ['warningThreshold'],
|
||||
});
|
||||
}
|
||||
if (data.criticalThreshold > 100) {
|
||||
ctx.addIssue({
|
||||
code: 'custom',
|
||||
message: '严重阈值不能大于100',
|
||||
path: ['criticalThreshold'],
|
||||
});
|
||||
}
|
||||
} else if (isNetworkType) {
|
||||
// 网络流量:0-10000 MB/s
|
||||
if (data.warningThreshold > 10000) {
|
||||
ctx.addIssue({
|
||||
code: 'custom',
|
||||
message: '警告阈值不能大于10000',
|
||||
path: ['warningThreshold'],
|
||||
});
|
||||
}
|
||||
if (data.criticalThreshold > 10000) {
|
||||
ctx.addIssue({
|
||||
code: 'custom',
|
||||
message: '严重阈值不能大于10000',
|
||||
path: ['criticalThreshold'],
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
// 严重阈值必须大于警告阈值
|
||||
if (data.criticalThreshold <= data.warningThreshold) {
|
||||
ctx.addIssue({
|
||||
|
||||
@ -286,54 +286,98 @@ export const ReleaseEditDialog: React.FC<ReleaseEditDialogProps> = ({
|
||||
<FormField
|
||||
control={form.control}
|
||||
name="delayMinutes"
|
||||
render={({ field }) => (
|
||||
<FormItem>
|
||||
<FormLabel>
|
||||
延迟执行(分钟) <span className="text-destructive">*</span>
|
||||
</FormLabel>
|
||||
<FormControl>
|
||||
<Input
|
||||
type="number"
|
||||
min="0"
|
||||
placeholder="创建后多久开始维护"
|
||||
{...field}
|
||||
value={field.value ?? 0}
|
||||
onChange={(e) => field.onChange(e.target.value ? parseInt(e.target.value) : 0)}
|
||||
/>
|
||||
</FormControl>
|
||||
<p className="text-xs text-muted-foreground mt-1">
|
||||
延迟执行分钟数(0表示立即执行)
|
||||
</p>
|
||||
<FormMessage />
|
||||
</FormItem>
|
||||
)}
|
||||
render={({ field }) => {
|
||||
const [localValue, setLocalValue] = React.useState<string>(
|
||||
field.value?.toString() ?? ''
|
||||
);
|
||||
|
||||
React.useEffect(() => {
|
||||
setLocalValue(field.value?.toString() ?? '');
|
||||
}, [field.value]);
|
||||
|
||||
return (
|
||||
<FormItem>
|
||||
<FormLabel>
|
||||
延迟执行(分钟) <span className="text-destructive">*</span>
|
||||
</FormLabel>
|
||||
<FormControl>
|
||||
<Input
|
||||
type="number"
|
||||
min="0"
|
||||
placeholder="创建后多久开始维护"
|
||||
value={localValue}
|
||||
onChange={(e) => {
|
||||
const value = e.target.value;
|
||||
setLocalValue(value);
|
||||
if (value !== '') {
|
||||
field.onChange(parseInt(value));
|
||||
}
|
||||
}}
|
||||
onBlur={() => {
|
||||
if (localValue === '') {
|
||||
field.onChange(undefined);
|
||||
}
|
||||
field.onBlur();
|
||||
}}
|
||||
name={field.name}
|
||||
/>
|
||||
</FormControl>
|
||||
<p className="text-xs text-muted-foreground mt-1">
|
||||
延迟执行分钟数(0表示立即执行)
|
||||
</p>
|
||||
<FormMessage />
|
||||
</FormItem>
|
||||
);
|
||||
}}
|
||||
/>
|
||||
|
||||
{/* 预计维护时长 */}
|
||||
<FormField
|
||||
control={form.control}
|
||||
name="estimatedDuration"
|
||||
render={({ field }) => (
|
||||
<FormItem>
|
||||
<FormLabel>
|
||||
预计时长(分钟) <span className="text-destructive">*</span>
|
||||
</FormLabel>
|
||||
<FormControl>
|
||||
<Input
|
||||
type="number"
|
||||
min="1"
|
||||
placeholder="预计维护时长"
|
||||
{...field}
|
||||
value={field.value ?? 30}
|
||||
onChange={(e) => field.onChange(e.target.value ? parseInt(e.target.value) : 30)}
|
||||
/>
|
||||
</FormControl>
|
||||
<p className="text-xs text-muted-foreground mt-1">
|
||||
预计维护所需时长(分钟)
|
||||
</p>
|
||||
<FormMessage />
|
||||
</FormItem>
|
||||
)}
|
||||
render={({ field }) => {
|
||||
const [localValue, setLocalValue] = React.useState<string>(
|
||||
field.value?.toString() ?? ''
|
||||
);
|
||||
|
||||
React.useEffect(() => {
|
||||
setLocalValue(field.value?.toString() ?? '');
|
||||
}, [field.value]);
|
||||
|
||||
return (
|
||||
<FormItem>
|
||||
<FormLabel>
|
||||
预计时长(分钟) <span className="text-destructive">*</span>
|
||||
</FormLabel>
|
||||
<FormControl>
|
||||
<Input
|
||||
type="number"
|
||||
min="1"
|
||||
placeholder="预计维护时长"
|
||||
value={localValue}
|
||||
onChange={(e) => {
|
||||
const value = e.target.value;
|
||||
setLocalValue(value);
|
||||
if (value !== '') {
|
||||
field.onChange(parseInt(value));
|
||||
}
|
||||
}}
|
||||
onBlur={() => {
|
||||
if (localValue === '') {
|
||||
field.onChange(undefined);
|
||||
}
|
||||
field.onBlur();
|
||||
}}
|
||||
name={field.name}
|
||||
/>
|
||||
</FormControl>
|
||||
<p className="text-xs text-muted-foreground mt-1">
|
||||
预计维护所需时长(分钟)
|
||||
</p>
|
||||
<FormMessage />
|
||||
</FormItem>
|
||||
);
|
||||
}}
|
||||
/>
|
||||
|
||||
{/* 是否自动停止服务 */}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user