1.18升级
This commit is contained in:
parent
2badfa63e3
commit
19ea644e6e
@ -382,6 +382,8 @@ export const AlertRuleFormDialog: React.FC<AlertRuleFormDialogProps> = ({
|
|||||||
render={({ field }) => {
|
render={({ field }) => {
|
||||||
const currentAlertType = form.watch('alertType');
|
const currentAlertType = form.watch('alertType');
|
||||||
const isServerStatus = currentAlertType === AlertType.SERVER_STATUS;
|
const isServerStatus = currentAlertType === AlertType.SERVER_STATUS;
|
||||||
|
const isNetworkType = currentAlertType === AlertType.NETWORK;
|
||||||
|
const maxValue = isNetworkType ? 10000 : 100;
|
||||||
const [localValue, setLocalValue] = React.useState<string>(
|
const [localValue, setLocalValue] = React.useState<string>(
|
||||||
field.value?.toString() ?? ''
|
field.value?.toString() ?? ''
|
||||||
);
|
);
|
||||||
@ -401,7 +403,7 @@ export const AlertRuleFormDialog: React.FC<AlertRuleFormDialogProps> = ({
|
|||||||
<Input
|
<Input
|
||||||
type="number"
|
type="number"
|
||||||
min="0"
|
min="0"
|
||||||
max="100"
|
max={maxValue}
|
||||||
step={isServerStatus ? "1" : "0.1"}
|
step={isServerStatus ? "1" : "0.1"}
|
||||||
value={localValue}
|
value={localValue}
|
||||||
onChange={(e) => {
|
onChange={(e) => {
|
||||||
@ -440,6 +442,8 @@ export const AlertRuleFormDialog: React.FC<AlertRuleFormDialogProps> = ({
|
|||||||
render={({ field }) => {
|
render={({ field }) => {
|
||||||
const currentAlertType = form.watch('alertType');
|
const currentAlertType = form.watch('alertType');
|
||||||
const isServerStatus = currentAlertType === AlertType.SERVER_STATUS;
|
const isServerStatus = currentAlertType === AlertType.SERVER_STATUS;
|
||||||
|
const isNetworkType = currentAlertType === AlertType.NETWORK;
|
||||||
|
const maxValue = isNetworkType ? 10000 : 100;
|
||||||
const [localValue, setLocalValue] = React.useState<string>(
|
const [localValue, setLocalValue] = React.useState<string>(
|
||||||
field.value?.toString() ?? ''
|
field.value?.toString() ?? ''
|
||||||
);
|
);
|
||||||
@ -459,7 +463,7 @@ export const AlertRuleFormDialog: React.FC<AlertRuleFormDialogProps> = ({
|
|||||||
<Input
|
<Input
|
||||||
type="number"
|
type="number"
|
||||||
min="0"
|
min="0"
|
||||||
max="100"
|
max={maxValue}
|
||||||
step={isServerStatus ? "1" : "0.1"}
|
step={isServerStatus ? "1" : "0.1"}
|
||||||
value={localValue}
|
value={localValue}
|
||||||
onChange={(e) => {
|
onChange={(e) => {
|
||||||
|
|||||||
@ -82,17 +82,51 @@ export const alertRuleFormSchema = z.object({
|
|||||||
alertType: z.nativeEnum(AlertType, {
|
alertType: z.nativeEnum(AlertType, {
|
||||||
errorMap: () => ({ message: '请选择告警类型' })
|
errorMap: () => ({ message: '请选择告警类型' })
|
||||||
}),
|
}),
|
||||||
warningThreshold: z.number()
|
warningThreshold: z.number().min(0, '警告阈值不能小于0'),
|
||||||
.min(0, '警告阈值不能小于0')
|
criticalThreshold: z.number().min(0, '严重阈值不能小于0'),
|
||||||
.max(100, '警告阈值不能大于100'),
|
|
||||||
criticalThreshold: z.number()
|
|
||||||
.min(0, '严重阈值不能小于0')
|
|
||||||
.max(100, '严重阈值不能大于100'),
|
|
||||||
durationMinutes: z.number()
|
durationMinutes: z.number()
|
||||||
.min(1, '持续时长至少为1分钟'),
|
.min(1, '持续时长至少为1分钟'),
|
||||||
enabled: z.boolean().default(true),
|
enabled: z.boolean().default(true),
|
||||||
description: z.string().max(500, '描述不能超过500个字符').optional(),
|
description: z.string().max(500, '描述不能超过500个字符').optional(),
|
||||||
}).superRefine((data, ctx) => {
|
}).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) {
|
if (data.criticalThreshold <= data.warningThreshold) {
|
||||||
ctx.addIssue({
|
ctx.addIssue({
|
||||||
|
|||||||
@ -286,54 +286,98 @@ export const ReleaseEditDialog: React.FC<ReleaseEditDialogProps> = ({
|
|||||||
<FormField
|
<FormField
|
||||||
control={form.control}
|
control={form.control}
|
||||||
name="delayMinutes"
|
name="delayMinutes"
|
||||||
render={({ field }) => (
|
render={({ field }) => {
|
||||||
<FormItem>
|
const [localValue, setLocalValue] = React.useState<string>(
|
||||||
<FormLabel>
|
field.value?.toString() ?? ''
|
||||||
延迟执行(分钟) <span className="text-destructive">*</span>
|
);
|
||||||
</FormLabel>
|
|
||||||
<FormControl>
|
React.useEffect(() => {
|
||||||
<Input
|
setLocalValue(field.value?.toString() ?? '');
|
||||||
type="number"
|
}, [field.value]);
|
||||||
min="0"
|
|
||||||
placeholder="创建后多久开始维护"
|
return (
|
||||||
{...field}
|
<FormItem>
|
||||||
value={field.value ?? 0}
|
<FormLabel>
|
||||||
onChange={(e) => field.onChange(e.target.value ? parseInt(e.target.value) : 0)}
|
延迟执行(分钟) <span className="text-destructive">*</span>
|
||||||
/>
|
</FormLabel>
|
||||||
</FormControl>
|
<FormControl>
|
||||||
<p className="text-xs text-muted-foreground mt-1">
|
<Input
|
||||||
延迟执行分钟数(0表示立即执行)
|
type="number"
|
||||||
</p>
|
min="0"
|
||||||
<FormMessage />
|
placeholder="创建后多久开始维护"
|
||||||
</FormItem>
|
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
|
<FormField
|
||||||
control={form.control}
|
control={form.control}
|
||||||
name="estimatedDuration"
|
name="estimatedDuration"
|
||||||
render={({ field }) => (
|
render={({ field }) => {
|
||||||
<FormItem>
|
const [localValue, setLocalValue] = React.useState<string>(
|
||||||
<FormLabel>
|
field.value?.toString() ?? ''
|
||||||
预计时长(分钟) <span className="text-destructive">*</span>
|
);
|
||||||
</FormLabel>
|
|
||||||
<FormControl>
|
React.useEffect(() => {
|
||||||
<Input
|
setLocalValue(field.value?.toString() ?? '');
|
||||||
type="number"
|
}, [field.value]);
|
||||||
min="1"
|
|
||||||
placeholder="预计维护时长"
|
return (
|
||||||
{...field}
|
<FormItem>
|
||||||
value={field.value ?? 30}
|
<FormLabel>
|
||||||
onChange={(e) => field.onChange(e.target.value ? parseInt(e.target.value) : 30)}
|
预计时长(分钟) <span className="text-destructive">*</span>
|
||||||
/>
|
</FormLabel>
|
||||||
</FormControl>
|
<FormControl>
|
||||||
<p className="text-xs text-muted-foreground mt-1">
|
<Input
|
||||||
预计维护所需时长(分钟)
|
type="number"
|
||||||
</p>
|
min="1"
|
||||||
<FormMessage />
|
placeholder="预计维护时长"
|
||||||
</FormItem>
|
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