Files
users/components/dialogs/create-alert-rule-dialog.tsx
v0 b17b488f8e refactor: restructure navigation and module layout
Reorganize navigation and module structure based on new requirements.

Co-authored-by: null <4804959+fnvtk@users.noreply.github.com>
2026-01-31 04:32:36 +00:00

167 lines
6.1 KiB
TypeScript

"use client"
import { useState } from "react"
import { Dialog, DialogContent, DialogHeader, DialogTitle, DialogFooter } from "@/components/ui/dialog"
import { Button } from "@/components/ui/button"
import { Input } from "@/components/ui/input"
import { Label } from "@/components/ui/label"
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "@/components/ui/select"
import { RadioGroup, RadioGroupItem } from "@/components/ui/radio-group"
import { Checkbox } from "@/components/ui/checkbox"
interface CreateAlertRuleDialogProps {
open: boolean
onOpenChange: (open: boolean) => void
}
export function CreateAlertRuleDialog({ open, onOpenChange }: CreateAlertRuleDialogProps) {
const [formData, setFormData] = useState({
name: "",
metric: "",
operator: "gt",
threshold: "",
duration: "5",
severity: "warning",
channels: [] as string[],
})
const toggleChannel = (channel: string) => {
setFormData({
...formData,
channels: formData.channels.includes(channel)
? formData.channels.filter((c) => c !== channel)
: [...formData.channels, channel],
})
}
const handleSubmit = () => {
console.log("创建告警规则:", formData)
onOpenChange(false)
}
return (
<Dialog open={open} onOpenChange={onOpenChange}>
<DialogContent className="sm:max-w-[500px]">
<DialogHeader>
<DialogTitle></DialogTitle>
</DialogHeader>
<div className="space-y-4 py-4">
<div className="space-y-2">
<Label></Label>
<Input
placeholder="输入规则名称"
value={formData.name}
onChange={(e) => setFormData({ ...formData, name: e.target.value })}
/>
</div>
<div className="space-y-2">
<Label></Label>
<Select value={formData.metric} onValueChange={(value) => setFormData({ ...formData, metric: value })}>
<SelectTrigger>
<SelectValue placeholder="选择监控指标" />
</SelectTrigger>
<SelectContent>
<SelectItem value="cpu">CPU使用率</SelectItem>
<SelectItem value="memory">使</SelectItem>
<SelectItem value="disk">使</SelectItem>
<SelectItem value="api_latency">API延迟(P99)</SelectItem>
<SelectItem value="api_error_rate">API错误率</SelectItem>
<SelectItem value="qps">QPS</SelectItem>
<SelectItem value="service_status"></SelectItem>
</SelectContent>
</Select>
</div>
<div className="grid grid-cols-3 gap-4">
<div className="space-y-2">
<Label></Label>
<Select
value={formData.operator}
onValueChange={(value) => setFormData({ ...formData, operator: value })}
>
<SelectTrigger>
<SelectValue />
</SelectTrigger>
<SelectContent>
<SelectItem value="gt"></SelectItem>
<SelectItem value="lt"></SelectItem>
<SelectItem value="eq"></SelectItem>
<SelectItem value="gte"></SelectItem>
<SelectItem value="lte"></SelectItem>
</SelectContent>
</Select>
</div>
<div className="space-y-2">
<Label></Label>
<Input
placeholder="80"
value={formData.threshold}
onChange={(e) => setFormData({ ...formData, threshold: e.target.value })}
/>
</div>
<div className="space-y-2">
<Label>()</Label>
<Input
type="number"
value={formData.duration}
onChange={(e) => setFormData({ ...formData, duration: e.target.value })}
/>
</div>
</div>
<div className="space-y-2">
<Label></Label>
<RadioGroup
value={formData.severity}
onValueChange={(value) => setFormData({ ...formData, severity: value })}
className="flex gap-4"
>
<div className="flex items-center space-x-2">
<RadioGroupItem value="info" id="info" />
<Label htmlFor="info" className="text-blue-600">
</Label>
</div>
<div className="flex items-center space-x-2">
<RadioGroupItem value="warning" id="warning" />
<Label htmlFor="warning" className="text-amber-600">
</Label>
</div>
<div className="flex items-center space-x-2">
<RadioGroupItem value="critical" id="critical" />
<Label htmlFor="critical" className="text-red-600">
</Label>
</div>
</RadioGroup>
</div>
<div className="space-y-2">
<Label></Label>
<div className="flex flex-wrap gap-4">
{["邮件", "短信", "企业微信", "钉钉", "Webhook"].map((channel) => (
<div key={channel} className="flex items-center space-x-2">
<Checkbox
id={channel}
checked={formData.channels.includes(channel)}
onCheckedChange={() => toggleChannel(channel)}
/>
<Label htmlFor={channel}>{channel}</Label>
</div>
))}
</div>
</div>
</div>
<DialogFooter>
<Button variant="outline" onClick={() => onOpenChange(false)}>
</Button>
<Button onClick={handleSubmit}></Button>
</DialogFooter>
</DialogContent>
</Dialog>
)
}