mirror of
https://github.com/Buriburizaem0n/admin-frontend-domain.git
synced 2026-02-04 04:30:06 +00:00
further implementing service page (#3)
This commit is contained in:
32
package-lock.json
generated
32
package-lock.json
generated
@@ -15,6 +15,7 @@
|
||||
"@radix-ui/react-dropdown-menu": "^2.1.2",
|
||||
"@radix-ui/react-label": "^2.1.0",
|
||||
"@radix-ui/react-navigation-menu": "^1.2.1",
|
||||
"@radix-ui/react-scroll-area": "^1.2.1",
|
||||
"@radix-ui/react-select": "^2.1.2",
|
||||
"@radix-ui/react-slot": "^1.1.0",
|
||||
"@tanstack/react-table": "^8.20.5",
|
||||
@@ -1695,6 +1696,37 @@
|
||||
}
|
||||
}
|
||||
},
|
||||
"node_modules/@radix-ui/react-scroll-area": {
|
||||
"version": "1.2.1",
|
||||
"resolved": "https://registry.npmjs.org/@radix-ui/react-scroll-area/-/react-scroll-area-1.2.1.tgz",
|
||||
"integrity": "sha512-FnM1fHfCtEZ1JkyfH/1oMiTcFBQvHKl4vD9WnpwkLgtF+UmnXMCad6ECPTaAjcDjam+ndOEJWgHyKDGNteWSHw==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@radix-ui/number": "1.1.0",
|
||||
"@radix-ui/primitive": "1.1.0",
|
||||
"@radix-ui/react-compose-refs": "1.1.0",
|
||||
"@radix-ui/react-context": "1.1.1",
|
||||
"@radix-ui/react-direction": "1.1.0",
|
||||
"@radix-ui/react-presence": "1.1.1",
|
||||
"@radix-ui/react-primitive": "2.0.0",
|
||||
"@radix-ui/react-use-callback-ref": "1.1.0",
|
||||
"@radix-ui/react-use-layout-effect": "1.1.0"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"@types/react": "*",
|
||||
"@types/react-dom": "*",
|
||||
"react": "^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc",
|
||||
"react-dom": "^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc"
|
||||
},
|
||||
"peerDependenciesMeta": {
|
||||
"@types/react": {
|
||||
"optional": true
|
||||
},
|
||||
"@types/react-dom": {
|
||||
"optional": true
|
||||
}
|
||||
}
|
||||
},
|
||||
"node_modules/@radix-ui/react-select": {
|
||||
"version": "2.1.2",
|
||||
"resolved": "https://registry.npmjs.org/@radix-ui/react-select/-/react-select-2.1.2.tgz",
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
"@radix-ui/react-dropdown-menu": "^2.1.2",
|
||||
"@radix-ui/react-label": "^2.1.0",
|
||||
"@radix-ui/react-navigation-menu": "^1.2.1",
|
||||
"@radix-ui/react-scroll-area": "^1.2.1",
|
||||
"@radix-ui/react-select": "^2.1.2",
|
||||
"@radix-ui/react-slot": "^1.1.0",
|
||||
"@tanstack/react-table": "^8.20.5",
|
||||
|
||||
@@ -2,11 +2,11 @@ import { ModelServiceForm } from "@/types"
|
||||
import { fetcher, FetcherMethod } from "./api"
|
||||
|
||||
export const createService = async (data: ModelServiceForm): Promise<number> => {
|
||||
return fetcher<number>(FetcherMethod.POST, '/api/v1/profile', data)
|
||||
return fetcher<number>(FetcherMethod.POST, '/api/v1/service', data)
|
||||
}
|
||||
|
||||
export const updateService = async (id: number, data: ModelServiceForm): Promise<void> => {
|
||||
return fetcher<void>(FetcherMethod.PATCH, `/api/v1/profile/${id}`, data)
|
||||
return fetcher<void>(FetcherMethod.PATCH, `/api/v1/service/${id}`, data)
|
||||
}
|
||||
|
||||
export const deleteService = async (id: number[]): Promise<void> => {
|
||||
|
||||
50
src/components/action-button-group.tsx
Normal file
50
src/components/action-button-group.tsx
Normal file
@@ -0,0 +1,50 @@
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { TrashButton } from "@/components/xui/icon-buttons";
|
||||
import {
|
||||
Dialog,
|
||||
DialogContent,
|
||||
DialogDescription,
|
||||
DialogFooter,
|
||||
DialogHeader,
|
||||
DialogTitle,
|
||||
DialogTrigger,
|
||||
DialogClose,
|
||||
} from "@/components/ui/dialog"
|
||||
import { KeyedMutator } from "swr";
|
||||
|
||||
interface ButtonGroupProps<T> {
|
||||
className?: string;
|
||||
children: React.ReactNode;
|
||||
delete: { fn: (id: number[]) => Promise<void>, id: number, mutate: KeyedMutator<T> };
|
||||
}
|
||||
|
||||
export function ActionButtonGroup<T>({ className, children, delete: { fn, id, mutate } }: ButtonGroupProps<T>) {
|
||||
const handleDelete = async () => {
|
||||
await fn([id]);
|
||||
await mutate();
|
||||
}
|
||||
|
||||
return (
|
||||
<div className={className}>
|
||||
{children}
|
||||
<Dialog>
|
||||
<DialogTrigger asChild>
|
||||
<TrashButton variant="outline" />
|
||||
</DialogTrigger>
|
||||
<DialogContent className="sm:max-w-lg">
|
||||
<DialogHeader>
|
||||
<DialogTitle>Confirm Deletion?</DialogTitle>
|
||||
<DialogDescription>
|
||||
This operation is unrecoverable!
|
||||
</DialogDescription>
|
||||
</DialogHeader>
|
||||
<DialogFooter>
|
||||
<DialogClose asChild>
|
||||
<Button type="submit" variant="destructive" onClick={handleDelete}>Confirm</Button>
|
||||
</DialogClose>
|
||||
</DialogFooter>
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
64
src/components/header-button-group.tsx
Normal file
64
src/components/header-button-group.tsx
Normal file
@@ -0,0 +1,64 @@
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { TrashButton } from "@/components/xui/icon-buttons";
|
||||
import {
|
||||
Dialog,
|
||||
DialogContent,
|
||||
DialogDescription,
|
||||
DialogFooter,
|
||||
DialogHeader,
|
||||
DialogTitle,
|
||||
DialogTrigger,
|
||||
DialogClose,
|
||||
} from "@/components/ui/dialog"
|
||||
import { KeyedMutator } from "swr";
|
||||
import { toast } from "sonner"
|
||||
|
||||
interface ButtonGroupProps<T> {
|
||||
className?: string;
|
||||
children: React.ReactNode;
|
||||
delete: { fn: (id: number[]) => Promise<void>, id: number[], mutate: KeyedMutator<T> };
|
||||
}
|
||||
|
||||
export function HeaderButtonGroup<T>({ className, children, delete: { fn, id, mutate } }: ButtonGroupProps<T>) {
|
||||
const handleDelete = async () => {
|
||||
await fn(id);
|
||||
await mutate();
|
||||
}
|
||||
|
||||
return (
|
||||
<div className={className}>
|
||||
{id.length < 1 ? (
|
||||
<>
|
||||
<TrashButton variant="destructive" onClick={() => {
|
||||
toast("Error", {
|
||||
description: "No rows are selected."
|
||||
});
|
||||
}} />
|
||||
{children}
|
||||
</>
|
||||
) : (
|
||||
<>
|
||||
<Dialog>
|
||||
<DialogTrigger asChild>
|
||||
<TrashButton variant="destructive" />
|
||||
</DialogTrigger>
|
||||
<DialogContent className="sm:max-w-lg">
|
||||
<DialogHeader>
|
||||
<DialogTitle>Confirm Deletion?</DialogTitle>
|
||||
<DialogDescription>
|
||||
This operation is unrecoverable!
|
||||
</DialogDescription>
|
||||
</DialogHeader>
|
||||
<DialogFooter>
|
||||
<DialogClose asChild>
|
||||
<Button type="submit" variant="destructive" onClick={handleDelete}>Confirm</Button>
|
||||
</DialogClose>
|
||||
</DialogFooter>
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
{children}
|
||||
</>
|
||||
)}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@@ -13,12 +13,14 @@ import { NzNavigationMenuLink } from "./xui/navigation-menu";
|
||||
import { DropdownMenu, DropdownMenuContent, DropdownMenuGroup, DropdownMenuItem, DropdownMenuLabel, DropdownMenuPortal, DropdownMenuSeparator, DropdownMenuShortcut, DropdownMenuSub, DropdownMenuSubContent, DropdownMenuSubTrigger, DropdownMenuTrigger } from "./ui/dropdown-menu";
|
||||
import { User, LogOut } from "lucide-react";
|
||||
import { useAuth } from "@/hooks/useAuth";
|
||||
import { Link } from "react-router-dom";
|
||||
|
||||
import { Link, useLocation } from "react-router-dom";
|
||||
|
||||
export default function Header() {
|
||||
const { logout } = useAuth()
|
||||
const profile = useMainStore(store => store.profile)
|
||||
const { logout } = useAuth();
|
||||
const profile = useMainStore(store => store.profile);
|
||||
|
||||
const location = useLocation();
|
||||
|
||||
return <header className="h-16 flex items-center border-b-2 px-4">
|
||||
<NavigationMenu className="max-w-full">
|
||||
<NavigationMenuList>
|
||||
@@ -31,12 +33,12 @@ export default function Header() {
|
||||
{
|
||||
profile && <>
|
||||
<NavigationMenuItem>
|
||||
<NzNavigationMenuLink asChild active className={navigationMenuTriggerStyle()}>
|
||||
<NzNavigationMenuLink asChild active={location.pathname === "/dashboard"} className={navigationMenuTriggerStyle()}>
|
||||
<Link to="/dashboard">Server</Link>
|
||||
</NzNavigationMenuLink>
|
||||
</NavigationMenuItem>
|
||||
<NavigationMenuItem>
|
||||
<NzNavigationMenuLink asChild className={navigationMenuTriggerStyle()}>
|
||||
<NzNavigationMenuLink asChild active={location.pathname === "/dashboard/service"} className={navigationMenuTriggerStyle()}>
|
||||
<Link to="/dashboard/service">Service</Link>
|
||||
</NzNavigationMenuLink>
|
||||
</NavigationMenuItem>
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
import { Plus } from "lucide-react"
|
||||
import { Button } from "@/components/ui/button"
|
||||
import {
|
||||
Dialog,
|
||||
DialogClose,
|
||||
DialogContent,
|
||||
DialogDescription,
|
||||
DialogFooter,
|
||||
DialogHeader,
|
||||
DialogTitle,
|
||||
@@ -25,184 +25,388 @@ import {
|
||||
FormLabel,
|
||||
FormMessage,
|
||||
} from "@/components/ui/form"
|
||||
import { ScrollArea } from "@/components/ui/scroll-area"
|
||||
import { useForm } from "react-hook-form"
|
||||
import { z } from "zod"
|
||||
import { zodResolver } from "@hookform/resolvers/zod"
|
||||
import { ModelService } from "@/types"
|
||||
import { ModelService, ModelServiceResponse } from "@/types"
|
||||
import { createService, updateService } from "@/api/service"
|
||||
import { Checkbox } from "./ui/checkbox"
|
||||
import { Label } from "./ui/label"
|
||||
import { Checkbox } from "@/components/ui/checkbox"
|
||||
import { Label } from "@/components/ui/label"
|
||||
import { conv } from "@/lib/utils"
|
||||
import { useState } from "react"
|
||||
import { KeyedMutator } from "swr"
|
||||
import { asOptionalField } from "@/lib/utils"
|
||||
import { EditButton, PlusButton } from "@/components/xui/icon-buttons"
|
||||
import { serviceTypes, serviceCoverageTypes } from "@/types"
|
||||
|
||||
interface ServiceCardProps {
|
||||
className?: string;
|
||||
data?: ModelService;
|
||||
mutate: KeyedMutator<ModelServiceResponse>;
|
||||
}
|
||||
|
||||
const serviceFormSchema = z.object({
|
||||
cover: z.number(),
|
||||
duration: z.number().min(30),
|
||||
enable_show_in_service: z.boolean().default(false),
|
||||
enable_trigger_task: z.boolean().default(false),
|
||||
fail_trigger_tasks: z.array(z.number()),
|
||||
latency_notify: z.boolean(),
|
||||
max_latency: z.number(),
|
||||
min_latency: z.number(),
|
||||
name: z.string(),
|
||||
notification_group_id: z.number(),
|
||||
notify: z.boolean(),
|
||||
recover_trigger_tasks: z.array(z.number()),
|
||||
cover: z.coerce.number().min(0),
|
||||
duration: z.coerce.number().min(30),
|
||||
enable_show_in_service: asOptionalField(z.boolean()),
|
||||
enable_trigger_task: asOptionalField(z.boolean()),
|
||||
fail_trigger_tasks: z.array(z.string()).transform((v => {
|
||||
return v.filter(Boolean).map(Number);
|
||||
})),
|
||||
latency_notify: asOptionalField(z.boolean()),
|
||||
max_latency: z.coerce.number().min(0),
|
||||
min_latency: z.coerce.number().min(0),
|
||||
name: z.string().min(1),
|
||||
notification_group_id: z.coerce.number(),
|
||||
notify: asOptionalField(z.boolean()),
|
||||
recover_trigger_tasks: z.array(z.string()).transform((v => {
|
||||
return v.filter(Boolean).map(Number);
|
||||
})),
|
||||
skip_servers: z.record(z.boolean()),
|
||||
target: z.string(),
|
||||
type: z.number(),
|
||||
target: z.string().url(),
|
||||
type: z.coerce.number().min(0),
|
||||
});
|
||||
|
||||
const serviceTypes = {
|
||||
1: "HTTP GET (Certificate expiration and changes)",
|
||||
2: "ICMP Ping",
|
||||
3: "TCPing",
|
||||
}
|
||||
|
||||
const serviceCoverageTypes = {
|
||||
0: "All excludes specific servers",
|
||||
1: "Only specific servers",
|
||||
}
|
||||
|
||||
export const ServiceCard: React.FC<ServiceCardProps> = ({ className, data }) => {
|
||||
export const ServiceCard: React.FC<ServiceCardProps> = ({ data, mutate }) => {
|
||||
const form = useForm<z.infer<typeof serviceFormSchema>>({
|
||||
resolver: zodResolver(serviceFormSchema),
|
||||
defaultValues: data,
|
||||
defaultValues: data ? data : {
|
||||
type: 1,
|
||||
cover: 0,
|
||||
name: "",
|
||||
target: "",
|
||||
max_latency: 0.0,
|
||||
min_latency: 0.0,
|
||||
duration: 30,
|
||||
notification_group_id: 0,
|
||||
fail_trigger_tasks: [],
|
||||
recover_trigger_tasks: [],
|
||||
skip_servers: {},
|
||||
},
|
||||
resetOptions: {
|
||||
keepDefaultValues: false,
|
||||
}
|
||||
})
|
||||
|
||||
const onSubmit = (values: z.infer<typeof serviceFormSchema>) => {
|
||||
data?.id ? updateService(data.id, values)
|
||||
: createService(values);
|
||||
const [open, setOpen] = useState(false);
|
||||
|
||||
const onSubmit = async (values: z.infer<typeof serviceFormSchema>) => {
|
||||
data?.id ? await updateService(data.id, values) : await createService(values);
|
||||
setOpen(false);
|
||||
await mutate();
|
||||
form.reset();
|
||||
}
|
||||
|
||||
return (
|
||||
<Dialog>
|
||||
<Dialog open={open} onOpenChange={setOpen}>
|
||||
<DialogTrigger asChild>
|
||||
<Button className={`${className}`}>
|
||||
<Plus /> Add New Service
|
||||
</Button>
|
||||
{data
|
||||
?
|
||||
<EditButton variant="outline" />
|
||||
:
|
||||
<PlusButton />
|
||||
}
|
||||
</DialogTrigger>
|
||||
<DialogContent className="sm:max-w-md">
|
||||
<DialogHeader>
|
||||
<DialogTitle>New Service</DialogTitle>
|
||||
</DialogHeader>
|
||||
<div className="items-center">
|
||||
<Form {...form}>
|
||||
<form onSubmit={form.handleSubmit(onSubmit)} className="space-y-2">
|
||||
<FormField
|
||||
control={form.control}
|
||||
name="name"
|
||||
render={({ field }) => (
|
||||
<FormItem>
|
||||
<FormLabel>Service Name</FormLabel>
|
||||
<FormControl>
|
||||
<Input {...field} />
|
||||
</FormControl>
|
||||
<FormMessage />
|
||||
</FormItem>
|
||||
)}
|
||||
/>
|
||||
<FormField
|
||||
control={form.control}
|
||||
name="target"
|
||||
render={({ field }) => (
|
||||
<FormItem>
|
||||
<FormLabel>Target</FormLabel>
|
||||
<FormControl>
|
||||
<Input type="link" placeholder="HTTP (https://t.tt)|Ping (t.tt)|TCP (t.tt:80)" {...field} />
|
||||
</FormControl>
|
||||
<FormMessage />
|
||||
</FormItem>
|
||||
)}
|
||||
/>
|
||||
<FormField
|
||||
control={form.control}
|
||||
name="type"
|
||||
render={({ field }) => (
|
||||
<FormItem>
|
||||
<FormLabel>Type</FormLabel>
|
||||
<Select onValueChange={field.onChange} defaultValue={`${field.value}`}>
|
||||
<DialogContent className="sm:max-w-xl">
|
||||
<ScrollArea className="max-h-[calc(100dvh-5rem)] p-3">
|
||||
<div className="items-center mx-1">
|
||||
<DialogHeader>
|
||||
<DialogTitle>New Service</DialogTitle>
|
||||
<DialogDescription />
|
||||
</DialogHeader>
|
||||
<Form {...form}>
|
||||
<form onSubmit={form.handleSubmit(onSubmit)} className="space-y-2 my-2">
|
||||
<FormField
|
||||
control={form.control}
|
||||
name="name"
|
||||
render={({ field }) => (
|
||||
<FormItem>
|
||||
<FormLabel>Service Name</FormLabel>
|
||||
<FormControl>
|
||||
<SelectTrigger>
|
||||
<SelectValue placeholder="Select service type" />
|
||||
</SelectTrigger>
|
||||
</FormControl>
|
||||
<SelectContent>
|
||||
{Object.entries(serviceTypes).map(([k, v]) => (
|
||||
<SelectItem value={k}>{v}</SelectItem>
|
||||
))}
|
||||
</SelectContent>
|
||||
</Select>
|
||||
<FormMessage />
|
||||
</FormItem>
|
||||
)}
|
||||
/>
|
||||
<FormField
|
||||
control={form.control}
|
||||
name="enable_show_in_service"
|
||||
render={({ field }) => (
|
||||
<FormItem className="flex items-center space-x-2">
|
||||
<FormControl>
|
||||
<div className="flex items-center gap-2">
|
||||
<Checkbox
|
||||
checked={field.value}
|
||||
onCheckedChange={field.onChange}
|
||||
<Input
|
||||
placeholder="My Service Monitor"
|
||||
{...field}
|
||||
/>
|
||||
<Label className="text-sm">Show in Service</Label>
|
||||
</div>
|
||||
</FormControl>
|
||||
<FormMessage />
|
||||
</FormItem>
|
||||
)}
|
||||
/>
|
||||
<FormField
|
||||
control={form.control}
|
||||
name="duration"
|
||||
render={({ field }) => (
|
||||
<FormItem>
|
||||
<FormLabel>Interval</FormLabel>
|
||||
<FormControl>
|
||||
<Input type="number" placeholder="Seconds" {...field} />
|
||||
</FormControl>
|
||||
<FormMessage />
|
||||
</FormItem>
|
||||
)}
|
||||
/>
|
||||
<FormField
|
||||
control={form.control}
|
||||
name="cover"
|
||||
render={({ field }) => (
|
||||
<FormItem>
|
||||
<FormLabel>Coverage</FormLabel>
|
||||
<Select onValueChange={field.onChange} defaultValue={`${field.value}`}>
|
||||
<FormControl>
|
||||
<SelectTrigger>
|
||||
<SelectValue placeholder="Select service type" />
|
||||
</SelectTrigger>
|
||||
</FormControl>
|
||||
<SelectContent>
|
||||
{Object.entries(serviceCoverageTypes).map(([k, v]) => (
|
||||
<SelectItem value={k}>{v}</SelectItem>
|
||||
))}
|
||||
</SelectContent>
|
||||
</Select>
|
||||
<FormMessage />
|
||||
</FormItem>
|
||||
)}
|
||||
/>
|
||||
</form>
|
||||
</Form>
|
||||
</div>
|
||||
<DialogFooter className="sm:justify-start">
|
||||
<DialogClose asChild>
|
||||
<Button type="button" variant="secondary">
|
||||
Close
|
||||
</Button>
|
||||
</DialogClose>
|
||||
</DialogFooter>
|
||||
<FormMessage />
|
||||
</FormItem>
|
||||
)}
|
||||
/>
|
||||
<FormField
|
||||
control={form.control}
|
||||
name="target"
|
||||
render={({ field }) => (
|
||||
<FormItem>
|
||||
<FormLabel>Target</FormLabel>
|
||||
<FormControl>
|
||||
<Input
|
||||
placeholder="HTTP (https://t.tt)|Ping (t.tt)|TCP (t.tt:80)"
|
||||
{...field}
|
||||
/>
|
||||
</FormControl>
|
||||
<FormMessage />
|
||||
</FormItem>
|
||||
)}
|
||||
/>
|
||||
<FormField
|
||||
control={form.control}
|
||||
name="type"
|
||||
render={({ field }) => (
|
||||
<FormItem>
|
||||
<FormLabel>Type</FormLabel>
|
||||
<Select onValueChange={field.onChange} defaultValue={`${field.value}`}>
|
||||
<FormControl>
|
||||
<SelectTrigger>
|
||||
<SelectValue placeholder="Select service type" />
|
||||
</SelectTrigger>
|
||||
</FormControl>
|
||||
<SelectContent>
|
||||
{Object.entries(serviceTypes).map(([k, v]) => (
|
||||
<SelectItem key={k} value={k}>{v}</SelectItem>
|
||||
))}
|
||||
</SelectContent>
|
||||
</Select>
|
||||
<FormMessage />
|
||||
</FormItem>
|
||||
)}
|
||||
/>
|
||||
<FormField
|
||||
control={form.control}
|
||||
name="enable_show_in_service"
|
||||
render={({ field }) => (
|
||||
<FormItem className="flex items-center space-x-2">
|
||||
<FormControl>
|
||||
<div className="flex items-center gap-2">
|
||||
<Checkbox
|
||||
checked={field.value}
|
||||
onCheckedChange={field.onChange}
|
||||
/>
|
||||
<Label className="text-sm">Show in Service</Label>
|
||||
</div>
|
||||
</FormControl>
|
||||
<FormMessage />
|
||||
</FormItem>
|
||||
)}
|
||||
/>
|
||||
<FormField
|
||||
control={form.control}
|
||||
name="duration"
|
||||
render={({ field }) => (
|
||||
<FormItem>
|
||||
<FormLabel>Interval (s)</FormLabel>
|
||||
<FormControl>
|
||||
<Input
|
||||
type="number"
|
||||
placeholder="30"
|
||||
{...field}
|
||||
/>
|
||||
</FormControl>
|
||||
<FormMessage />
|
||||
</FormItem>
|
||||
)}
|
||||
/>
|
||||
<FormField
|
||||
control={form.control}
|
||||
name="cover"
|
||||
render={({ field }) => (
|
||||
<FormItem>
|
||||
<FormLabel>Coverage</FormLabel>
|
||||
<Select onValueChange={field.onChange} defaultValue={`${field.value}`}>
|
||||
<FormControl>
|
||||
<SelectTrigger>
|
||||
<SelectValue placeholder="Select service type" />
|
||||
</SelectTrigger>
|
||||
</FormControl>
|
||||
<SelectContent>
|
||||
{Object.entries(serviceCoverageTypes).map(([k, v]) => (
|
||||
<SelectItem key={k} value={k}>{v}</SelectItem>
|
||||
))}
|
||||
</SelectContent>
|
||||
</Select>
|
||||
<FormMessage />
|
||||
</FormItem>
|
||||
)}
|
||||
/>
|
||||
<FormField
|
||||
control={form.control}
|
||||
name="skip_servers"
|
||||
render={({ field }) => (
|
||||
<FormItem>
|
||||
<FormLabel>Specific Servers (separate with comma)</FormLabel>
|
||||
<FormControl>
|
||||
<Input
|
||||
placeholder="1,2,3"
|
||||
{...field}
|
||||
value={conv.recordToStr(field.value ?? {})}
|
||||
onChange={e => {
|
||||
const rec = conv.strToRecord(e.target.value);
|
||||
field.onChange(rec);
|
||||
}}
|
||||
/>
|
||||
</FormControl>
|
||||
<FormMessage />
|
||||
</FormItem>
|
||||
)}
|
||||
/>
|
||||
<FormField
|
||||
control={form.control}
|
||||
name="notification_group_id"
|
||||
render={({ field }) => (
|
||||
<FormItem>
|
||||
<FormLabel>Notification Group ID</FormLabel>
|
||||
<FormControl>
|
||||
<Input
|
||||
type="number"
|
||||
placeholder="1"
|
||||
{...field}
|
||||
/>
|
||||
</FormControl>
|
||||
<FormMessage />
|
||||
</FormItem>
|
||||
)}
|
||||
/>
|
||||
<FormField
|
||||
control={form.control}
|
||||
name="notify"
|
||||
render={({ field }) => (
|
||||
<FormItem className="flex items-center space-x-2">
|
||||
<FormControl>
|
||||
<div className="flex items-center gap-2">
|
||||
<Checkbox
|
||||
checked={field.value}
|
||||
onCheckedChange={field.onChange}
|
||||
/>
|
||||
<Label className="text-sm">Enable Failure Notification</Label>
|
||||
</div>
|
||||
</FormControl>
|
||||
<FormMessage />
|
||||
</FormItem>
|
||||
)}
|
||||
/>
|
||||
<FormField
|
||||
control={form.control}
|
||||
name="max_latency"
|
||||
render={({ field }) => (
|
||||
<FormItem>
|
||||
<FormLabel>Maximum Latency Time (ms)</FormLabel>
|
||||
<FormControl>
|
||||
<Input
|
||||
type="number"
|
||||
placeholder="100.88"
|
||||
{...field}
|
||||
/>
|
||||
</FormControl>
|
||||
<FormMessage />
|
||||
</FormItem>
|
||||
)}
|
||||
/>
|
||||
<FormField
|
||||
control={form.control}
|
||||
name="min_latency"
|
||||
render={({ field }) => (
|
||||
<FormItem>
|
||||
<FormLabel>Minimum Latency Time (ms)</FormLabel>
|
||||
<FormControl>
|
||||
<Input
|
||||
type="number"
|
||||
placeholder="100.88"
|
||||
{...field}
|
||||
/>
|
||||
</FormControl>
|
||||
<FormMessage />
|
||||
</FormItem>
|
||||
)}
|
||||
/>
|
||||
<FormField
|
||||
control={form.control}
|
||||
name="latency_notify"
|
||||
render={({ field }) => (
|
||||
<FormItem className="flex items-center space-x-2">
|
||||
<FormControl>
|
||||
<div className="flex items-center gap-2">
|
||||
<Checkbox
|
||||
checked={field.value}
|
||||
onCheckedChange={field.onChange}
|
||||
/>
|
||||
<Label className="text-sm">Enable Latency Notification</Label>
|
||||
</div>
|
||||
</FormControl>
|
||||
<FormMessage />
|
||||
</FormItem>
|
||||
)}
|
||||
/>
|
||||
<FormField
|
||||
control={form.control}
|
||||
name="enable_trigger_task"
|
||||
render={({ field }) => (
|
||||
<FormItem className="flex items-center space-x-2">
|
||||
<FormControl>
|
||||
<div className="flex items-center gap-2">
|
||||
<Checkbox
|
||||
checked={field.value}
|
||||
onCheckedChange={field.onChange}
|
||||
/>
|
||||
<Label className="text-sm">Enable Trigger Task</Label>
|
||||
</div>
|
||||
</FormControl>
|
||||
<FormMessage />
|
||||
</FormItem>
|
||||
)}
|
||||
/>
|
||||
<FormField
|
||||
control={form.control}
|
||||
name="fail_trigger_tasks"
|
||||
render={({ field }) => (
|
||||
<FormItem>
|
||||
<FormLabel>Tasks to trigger on an alarm (Separate with comma)</FormLabel>
|
||||
<FormControl>
|
||||
<Input
|
||||
placeholder="1,2,3"
|
||||
{...field}
|
||||
value={conv.arrToStr(field.value ?? [])}
|
||||
onChange={e => {
|
||||
const arr = conv.strToArr(e.target.value);
|
||||
field.onChange(arr);
|
||||
}}
|
||||
/>
|
||||
</FormControl>
|
||||
<FormMessage />
|
||||
</FormItem>
|
||||
)}
|
||||
/>
|
||||
<FormField
|
||||
control={form.control}
|
||||
name="recover_trigger_tasks"
|
||||
render={({ field }) => (
|
||||
<FormItem>
|
||||
<FormLabel>Tasks to trigger after recovery (Separate with comma)</FormLabel>
|
||||
<FormControl>
|
||||
<Input
|
||||
placeholder="1,2,3"
|
||||
{...field}
|
||||
value={conv.arrToStr(field.value ?? [])}
|
||||
onChange={e => {
|
||||
const arr = conv.strToArr(e.target.value);
|
||||
field.onChange(arr);
|
||||
}}
|
||||
/>
|
||||
</FormControl>
|
||||
<FormMessage />
|
||||
</FormItem>
|
||||
)}
|
||||
/>
|
||||
<DialogFooter className="justify-end">
|
||||
<DialogClose asChild>
|
||||
<Button type="button" className="my-2" variant="secondary">
|
||||
Close
|
||||
</Button>
|
||||
</DialogClose>
|
||||
<Button type="submit" className="my-2">Submit</Button>
|
||||
</DialogFooter>
|
||||
</form>
|
||||
</Form>
|
||||
</div>
|
||||
</ScrollArea>
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
)
|
||||
|
||||
@@ -11,7 +11,7 @@ const Checkbox = React.forwardRef<
|
||||
<CheckboxPrimitive.Root
|
||||
ref={ref}
|
||||
className={cn(
|
||||
"peer h-4 w-4 shrink-0 rounded-sm border border-primary ring-offset-background focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50 data-[state=checked]:bg-primary data-[state=checked]:text-primary-foreground",
|
||||
"flex peer h-4 w-4 shrink-0 rounded-sm border border-primary ring-offset-background focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50 data-[state=checked]:bg-primary data-[state=checked]:text-primary-foreground",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
|
||||
46
src/components/ui/scroll-area.tsx
Normal file
46
src/components/ui/scroll-area.tsx
Normal file
@@ -0,0 +1,46 @@
|
||||
import * as React from "react"
|
||||
import * as ScrollAreaPrimitive from "@radix-ui/react-scroll-area"
|
||||
|
||||
import { cn } from "@/lib/utils"
|
||||
|
||||
const ScrollArea = React.forwardRef<
|
||||
React.ElementRef<typeof ScrollAreaPrimitive.Root>,
|
||||
React.ComponentPropsWithoutRef<typeof ScrollAreaPrimitive.Root>
|
||||
>(({ className, children, ...props }, ref) => (
|
||||
<ScrollAreaPrimitive.Root
|
||||
ref={ref}
|
||||
className={cn("relative overflow-hidden", className)}
|
||||
{...props}
|
||||
>
|
||||
<ScrollAreaPrimitive.Viewport className="h-full w-full rounded-[inherit]">
|
||||
{children}
|
||||
</ScrollAreaPrimitive.Viewport>
|
||||
<ScrollBar />
|
||||
<ScrollAreaPrimitive.Corner />
|
||||
</ScrollAreaPrimitive.Root>
|
||||
))
|
||||
ScrollArea.displayName = ScrollAreaPrimitive.Root.displayName
|
||||
|
||||
const ScrollBar = React.forwardRef<
|
||||
React.ElementRef<typeof ScrollAreaPrimitive.ScrollAreaScrollbar>,
|
||||
React.ComponentPropsWithoutRef<typeof ScrollAreaPrimitive.ScrollAreaScrollbar>
|
||||
>(({ className, orientation = "vertical", ...props }, ref) => (
|
||||
<ScrollAreaPrimitive.ScrollAreaScrollbar
|
||||
ref={ref}
|
||||
orientation={orientation}
|
||||
className={cn(
|
||||
"flex touch-none select-none transition-colors",
|
||||
orientation === "vertical" &&
|
||||
"h-full w-2.5 border-l border-l-transparent p-[1px]",
|
||||
orientation === "horizontal" &&
|
||||
"h-2.5 flex-col border-t border-t-transparent p-[1px]",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
>
|
||||
<ScrollAreaPrimitive.ScrollAreaThumb className="relative flex-1 rounded-full bg-border" />
|
||||
</ScrollAreaPrimitive.ScrollAreaScrollbar>
|
||||
))
|
||||
ScrollBar.displayName = ScrollAreaPrimitive.ScrollAreaScrollbar.displayName
|
||||
|
||||
export { ScrollArea, ScrollBar }
|
||||
15
src/components/ui/skeleton.tsx
Normal file
15
src/components/ui/skeleton.tsx
Normal file
@@ -0,0 +1,15 @@
|
||||
import { cn } from "@/lib/utils"
|
||||
|
||||
function Skeleton({
|
||||
className,
|
||||
...props
|
||||
}: React.HTMLAttributes<HTMLDivElement>) {
|
||||
return (
|
||||
<div
|
||||
className={cn("animate-pulse rounded-md bg-muted", className)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
export { Skeleton }
|
||||
27
src/components/xui/icon-buttons.tsx
Normal file
27
src/components/xui/icon-buttons.tsx
Normal file
@@ -0,0 +1,27 @@
|
||||
import { Plus, Edit2, Trash2 } from "lucide-react"
|
||||
import { Button, ButtonProps } from "@/components/ui/button"
|
||||
import { forwardRef } from "react";
|
||||
|
||||
export const EditButton = forwardRef<HTMLButtonElement, ButtonProps>((props, ref) => {
|
||||
return (
|
||||
<Button {...props} ref={ref} size="icon">
|
||||
<Edit2 />
|
||||
</Button>
|
||||
);
|
||||
});
|
||||
|
||||
export const TrashButton = forwardRef<HTMLButtonElement, ButtonProps>((props, ref) => {
|
||||
return (
|
||||
<Button {...props} ref={ref} size="icon">
|
||||
<Trash2 />
|
||||
</Button>
|
||||
);
|
||||
});
|
||||
|
||||
export const PlusButton = forwardRef<HTMLButtonElement, ButtonProps>((props, ref) => {
|
||||
return (
|
||||
<Button {...props} ref={ref} size="icon">
|
||||
<Plus />
|
||||
</Button>
|
||||
);
|
||||
});
|
||||
@@ -32,8 +32,9 @@ export const AuthProvider = ({ children }: {
|
||||
|
||||
const login = async (username: string, password: string) => {
|
||||
try {
|
||||
await loginRequest(username, password)
|
||||
setProfile({ username: username });
|
||||
await loginRequest(username, password);
|
||||
const user = await getProfile();
|
||||
setProfile(user);
|
||||
navigate("/dashboard");
|
||||
} catch (error: any) {
|
||||
toast(error.message);
|
||||
|
||||
@@ -1,6 +1,44 @@
|
||||
import { clsx, type ClassValue } from "clsx"
|
||||
import { twMerge } from "tailwind-merge"
|
||||
import { z } from "zod"
|
||||
|
||||
export function cn(...inputs: ClassValue[]) {
|
||||
return twMerge(clsx(inputs))
|
||||
}
|
||||
|
||||
const emptyStringToUndefined = z.literal('').transform(() => undefined);
|
||||
|
||||
export function asOptionalField<T extends z.ZodTypeAny>(schema: T) {
|
||||
return schema.optional().or(emptyStringToUndefined);
|
||||
}
|
||||
|
||||
export const conv = {
|
||||
recordToStr: (rec: Record<string, boolean>) => {
|
||||
const arr: string[] = [];
|
||||
for (const key in rec) {
|
||||
arr.push(key);
|
||||
}
|
||||
|
||||
return arr.join(',');
|
||||
},
|
||||
strToRecord: (str: string) => {
|
||||
const arr = str.split(',');
|
||||
return arr.reduce((acc, num) => {
|
||||
acc[num] = true;
|
||||
return acc;
|
||||
}, {} as Record<string, boolean>);
|
||||
},
|
||||
arrToStr: <T>(arr: T[]) => {
|
||||
return arr.join(',');
|
||||
},
|
||||
strToArr: (str: string) => {
|
||||
return str.split(',');
|
||||
},
|
||||
recordToArr: <T>(rec: Record<string, T>) => {
|
||||
const arr: T[] = [];
|
||||
for (const val of Object.values(rec)) {
|
||||
arr.push(val);
|
||||
}
|
||||
return arr;
|
||||
},
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@ import { Toaster } from "@/components/ui/sonner";
|
||||
export default function Root() {
|
||||
return (
|
||||
<ThemeProvider defaultTheme="dark" storageKey="vite-ui-theme">
|
||||
<Card className="text-sm max-w-6xl mx-auto mt-5 min-h-[90%] flex flex-col justify-between">
|
||||
<Card className="text-sm max-w-7xl mx-auto mt-5 min-h-[90%] flex flex-col justify-between">
|
||||
<div>
|
||||
<Header />
|
||||
<Outlet />
|
||||
|
||||
@@ -113,4 +113,4 @@ export default function ServerPage() {
|
||||
</TableBody>
|
||||
</Table>
|
||||
</div>
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,11 +2,28 @@ import { swrFetcher } from "@/api/api"
|
||||
import { Checkbox } from "@/components/ui/checkbox"
|
||||
import { ServiceCard } from "@/components/service"
|
||||
import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow } from "@/components/ui/table"
|
||||
import { ModelService as Service } from "@/types"
|
||||
import { ModelServiceResponse, ModelServiceResponseItem as Service } from "@/types"
|
||||
import { ColumnDef, flexRender, getCoreRowModel, useReactTable } from "@tanstack/react-table"
|
||||
import useSWR from "swr"
|
||||
import { conv } from "@/lib/utils"
|
||||
import { useEffect, useMemo } from "react"
|
||||
import { serviceTypes } from "@/types"
|
||||
import { ActionButtonGroup } from "@/components/action-button-group"
|
||||
import { deleteService } from "@/api/service"
|
||||
import { HeaderButtonGroup } from "@/components/header-button-group"
|
||||
import { Skeleton } from "@/components/ui/skeleton"
|
||||
import { toast } from "sonner"
|
||||
|
||||
export default function ServicePage() {
|
||||
const { data, mutate, error, isLoading } = useSWR<ModelServiceResponse>('/api/v1/service', swrFetcher)
|
||||
|
||||
useEffect(() => {
|
||||
if (error)
|
||||
toast("Error", {
|
||||
description: "Error fetching resource.",
|
||||
})
|
||||
}, [error])
|
||||
|
||||
const columns: ColumnDef<Service>[] = [
|
||||
{
|
||||
id: "select",
|
||||
@@ -32,18 +49,67 @@ export default function ServicePage() {
|
||||
},
|
||||
{
|
||||
header: "ID",
|
||||
accessorKey: "id",
|
||||
accessorFn: (row) => row.id,
|
||||
accessorKey: "service.id",
|
||||
accessorFn: row => row.service.id,
|
||||
},
|
||||
{
|
||||
header: "Name",
|
||||
accessorKey: "name",
|
||||
accessorFn: (row) => row.name,
|
||||
accessorKey: "service.name",
|
||||
accessorFn: row => row.service.name,
|
||||
},
|
||||
{
|
||||
header: "Target",
|
||||
accessorKey: "service.target",
|
||||
accessorFn: row => row.service.target,
|
||||
},
|
||||
{
|
||||
header: "Coverage",
|
||||
accessorKey: "service.cover",
|
||||
accessorFn: row => {
|
||||
switch (row.service.cover) {
|
||||
case 0: {
|
||||
return "Cover All"
|
||||
}
|
||||
case 1: {
|
||||
return "Ignore All"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
header: "Specific Servers",
|
||||
accessorKey: "service.skipServers",
|
||||
accessorFn: row => Object.keys(row.service.skip_servers ?? {}),
|
||||
},
|
||||
{
|
||||
header: "Type",
|
||||
accessorKey: "service.type",
|
||||
accessorFn: (row) => row.type,
|
||||
accessorFn: row => serviceTypes[row.service.type] || '',
|
||||
},
|
||||
{
|
||||
header: "Interval",
|
||||
accessorKey: "service.duration",
|
||||
accessorFn: row => row.service.duration,
|
||||
},
|
||||
{
|
||||
header: "Notification Group ID",
|
||||
accessorKey: "service.ngroup",
|
||||
accessorFn: row => row.service.notification_group_id,
|
||||
},
|
||||
{
|
||||
header: "Enable Trigger Task",
|
||||
accessorKey: "service.triggerTask",
|
||||
accessorFn: row => row.service.enable_trigger_task ?? false,
|
||||
},
|
||||
{
|
||||
header: "Tasks to trigger on an alarm",
|
||||
accessorKey: "service.failTriggerTasks",
|
||||
accessorFn: row => row.service.fail_trigger_tasks,
|
||||
},
|
||||
{
|
||||
header: "Tasks to trigger after recovery",
|
||||
accessorKey: "service.recoverTriggerTasks",
|
||||
accessorFn: row => row.service.recover_trigger_tasks,
|
||||
},
|
||||
{
|
||||
id: "actions",
|
||||
@@ -51,68 +117,90 @@ export default function ServicePage() {
|
||||
cell: ({ row }) => {
|
||||
const s = row.original
|
||||
return (
|
||||
<>{s.id}</>
|
||||
<ActionButtonGroup className="flex gap-2" delete={{ fn: deleteService, id: s.service.id, mutate: mutate }}>
|
||||
<ServiceCard mutate={mutate} data={s.service} />
|
||||
</ActionButtonGroup>
|
||||
)
|
||||
},
|
||||
},
|
||||
]
|
||||
|
||||
const { data, error, isLoading } = useSWR<Service[]>('/api/v1/service', swrFetcher)
|
||||
const dataArr = useMemo(() => {
|
||||
return conv.recordToArr(data?.services ?? {});
|
||||
}, [data?.services]);
|
||||
|
||||
const table = useReactTable({
|
||||
data: data ?? [],
|
||||
data: dataArr,
|
||||
columns,
|
||||
getCoreRowModel: getCoreRowModel(),
|
||||
})
|
||||
|
||||
return <div className="px-9">
|
||||
<div className="flex space-between mt-4 pb-4">
|
||||
<h1 className="text-3xl font-bold tracking-tight">
|
||||
Service
|
||||
</h1>
|
||||
<ServiceCard className="ml-auto" />
|
||||
</div>
|
||||
<Table>
|
||||
<TableHeader>
|
||||
{table.getHeaderGroups().map((headerGroup) => (
|
||||
<TableRow key={headerGroup.id}>
|
||||
{headerGroup.headers.map((header) => {
|
||||
return (
|
||||
<TableHead key={header.id}>
|
||||
{header.isPlaceholder
|
||||
? null
|
||||
: flexRender(
|
||||
header.column.columnDef.header,
|
||||
header.getContext()
|
||||
)}
|
||||
</TableHead>
|
||||
)
|
||||
})}
|
||||
</TableRow>
|
||||
))}
|
||||
</TableHeader>
|
||||
<TableBody>
|
||||
{table.getRowModel().rows?.length ? (
|
||||
table.getRowModel().rows.map((row) => (
|
||||
<TableRow
|
||||
key={row.id}
|
||||
data-state={row.getIsSelected() && "selected"}
|
||||
>
|
||||
{row.getVisibleCells().map((cell) => (
|
||||
<TableCell key={cell.id}>
|
||||
{flexRender(cell.column.columnDef.cell, cell.getContext())}
|
||||
const selectedRows = table.getSelectedRowModel().rows;
|
||||
|
||||
return (
|
||||
<div className="px-8">
|
||||
<div className="flex mt-6 mb-4">
|
||||
<h1 className="flex-1 text-3xl font-bold tracking-tight">
|
||||
Service
|
||||
</h1>
|
||||
<HeaderButtonGroup className="flex-2 flex ml-auto gap-2" delete={{
|
||||
fn: deleteService,
|
||||
id: selectedRows.map(r => r.original.service.id),
|
||||
mutate: mutate,
|
||||
}}>
|
||||
<ServiceCard mutate={mutate} />
|
||||
</HeaderButtonGroup>
|
||||
</div>
|
||||
{isLoading ? (
|
||||
<div className="flex flex-col items-center space-y-4">
|
||||
<Skeleton className="h-[60px] w-[100%] rounded-lg" />
|
||||
<Skeleton className="h-[60px] w-[100%] rounded-lg" />
|
||||
<Skeleton className="h-[60px] w-[100%] rounded-lg" />
|
||||
</div>
|
||||
) : (
|
||||
<Table>
|
||||
<TableHeader>
|
||||
{table.getHeaderGroups().map((headerGroup) => (
|
||||
<TableRow key={headerGroup.id}>
|
||||
{headerGroup.headers.map((header) => {
|
||||
return (
|
||||
<TableHead key={header.id} className="text-sm">
|
||||
{header.isPlaceholder
|
||||
? null
|
||||
: flexRender(
|
||||
header.column.columnDef.header,
|
||||
header.getContext()
|
||||
)}
|
||||
</TableHead>
|
||||
)
|
||||
})}
|
||||
</TableRow>
|
||||
))}
|
||||
</TableHeader>
|
||||
<TableBody>
|
||||
{table.getRowModel().rows?.length ? (
|
||||
table.getRowModel().rows.map((row) => (
|
||||
<TableRow
|
||||
key={row.id}
|
||||
data-state={row.getIsSelected() && "selected"}
|
||||
>
|
||||
{row.getVisibleCells().map((cell) => (
|
||||
<TableCell key={cell.id} className="text-xsm">
|
||||
{flexRender(cell.column.columnDef.cell, cell.getContext())}
|
||||
</TableCell>
|
||||
))}
|
||||
</TableRow>
|
||||
))
|
||||
) : (
|
||||
<TableRow>
|
||||
<TableCell colSpan={columns.length} className="h-24 text-center">
|
||||
No results.
|
||||
</TableCell>
|
||||
))}
|
||||
</TableRow>
|
||||
))
|
||||
) : (
|
||||
<TableRow>
|
||||
<TableCell colSpan={columns.length} className="h-24 text-center">
|
||||
No results.
|
||||
</TableCell>
|
||||
</TableRow>
|
||||
)}
|
||||
</TableBody>
|
||||
</Table>
|
||||
</div >
|
||||
}
|
||||
</TableRow>
|
||||
)}
|
||||
</TableBody>
|
||||
</Table>
|
||||
)}
|
||||
</div >
|
||||
)
|
||||
}
|
||||
|
||||
125
src/types/api.ts
125
src/types/api.ts
@@ -142,14 +142,16 @@ export interface ModelAlertRule {
|
||||
}
|
||||
|
||||
export interface ModelAlertRuleForm {
|
||||
enable: boolean;
|
||||
enable?: boolean;
|
||||
/** 失败时触发的任务id */
|
||||
fail_trigger_tasks: number[];
|
||||
/** @minLength 1 */
|
||||
name: string;
|
||||
notification_group_id: number;
|
||||
/** 恢复时触发的任务id */
|
||||
recover_trigger_tasks: number[];
|
||||
rules: ModelRule[];
|
||||
/** @default 0 */
|
||||
trigger_mode: number;
|
||||
}
|
||||
|
||||
@@ -219,43 +221,52 @@ export interface ModelCron {
|
||||
}
|
||||
|
||||
export interface ModelCronForm {
|
||||
command: string;
|
||||
command?: string;
|
||||
/** @default 0 */
|
||||
cover: number;
|
||||
id: number;
|
||||
/** @minLength 1 */
|
||||
name: string;
|
||||
notification_group_id: number;
|
||||
push_successful: boolean;
|
||||
push_successful?: boolean;
|
||||
scheduler: string;
|
||||
servers: number[];
|
||||
/** 0:计划任务 1:触发任务 */
|
||||
/**
|
||||
* 0:计划任务 1:触发任务
|
||||
* @default 0
|
||||
*/
|
||||
task_type: number;
|
||||
}
|
||||
|
||||
export interface ModelCycleTransferStats {
|
||||
from?: string;
|
||||
max?: number;
|
||||
min?: number;
|
||||
name?: string;
|
||||
nextUpdate?: Record<string, string>;
|
||||
serverName?: Record<string, string>;
|
||||
to?: string;
|
||||
transfer?: Record<string, number>;
|
||||
from: string;
|
||||
max: number;
|
||||
min: number;
|
||||
name: string;
|
||||
next_update: Record<string, string>;
|
||||
server_name: Record<string, string>;
|
||||
to: string;
|
||||
transfer: Record<string, number>;
|
||||
}
|
||||
|
||||
export interface ModelDDNSForm {
|
||||
access_id: string;
|
||||
access_secret: string;
|
||||
access_id?: string;
|
||||
access_secret?: string;
|
||||
domains: string[];
|
||||
enable_ipv4: boolean;
|
||||
enable_ipv6: boolean;
|
||||
enable_ipv4?: boolean;
|
||||
enable_ipv6?: boolean;
|
||||
/** @default 3 */
|
||||
max_retries: number;
|
||||
/** @minLength 1 */
|
||||
name: string;
|
||||
provider: string;
|
||||
webhook_headers: string;
|
||||
webhook_method: number;
|
||||
webhook_request_body: string;
|
||||
webhook_request_type: number;
|
||||
webhook_url: string;
|
||||
webhook_headers?: string;
|
||||
/** @default 1 */
|
||||
webhook_method?: number;
|
||||
webhook_request_body?: string;
|
||||
/** @default 1 */
|
||||
webhook_request_type?: number;
|
||||
webhook_url?: string;
|
||||
}
|
||||
|
||||
export interface ModelDDNSProfile {
|
||||
@@ -328,16 +339,17 @@ export interface ModelNAT {
|
||||
created_at: string;
|
||||
deleted_at: GormDeletedAt;
|
||||
domain: string;
|
||||
host?: string;
|
||||
host: string;
|
||||
id: number;
|
||||
name?: string;
|
||||
serverID?: number;
|
||||
name: string;
|
||||
server_id: number;
|
||||
updated_at: string;
|
||||
}
|
||||
|
||||
export interface ModelNATForm {
|
||||
domain: string;
|
||||
host: string;
|
||||
/** @minLength 1 */
|
||||
name: string;
|
||||
server_id: number;
|
||||
}
|
||||
@@ -357,14 +369,15 @@ export interface ModelNotification {
|
||||
}
|
||||
|
||||
export interface ModelNotificationForm {
|
||||
/** @minLength 1 */
|
||||
name: string;
|
||||
request_body: string;
|
||||
request_header: string;
|
||||
request_method: number;
|
||||
request_type: number;
|
||||
skip_check: boolean;
|
||||
skip_check?: boolean;
|
||||
url: string;
|
||||
verify_tls: boolean;
|
||||
verify_tls?: boolean;
|
||||
}
|
||||
|
||||
export interface ModelNotificationGroup {
|
||||
@@ -376,6 +389,7 @@ export interface ModelNotificationGroup {
|
||||
}
|
||||
|
||||
export interface ModelNotificationGroupForm {
|
||||
/** @minLength 1 */
|
||||
name: string;
|
||||
notifications: number[];
|
||||
}
|
||||
@@ -442,17 +456,20 @@ export interface ModelServer {
|
||||
export interface ModelServerForm {
|
||||
/** DDNS配置 */
|
||||
ddns_profiles: number[];
|
||||
/** 展示排序,越大越靠前 */
|
||||
/**
|
||||
* 展示排序,越大越靠前
|
||||
* @default 0
|
||||
*/
|
||||
display_index: number;
|
||||
/** 启用DDNS */
|
||||
enable_ddns: boolean;
|
||||
enable_ddns?: boolean;
|
||||
/** 对游客隐藏 */
|
||||
hide_for_guest: boolean;
|
||||
hide_for_guest?: boolean;
|
||||
name: string;
|
||||
/** 管理员可见备注 */
|
||||
note: string;
|
||||
note?: string;
|
||||
/** 公开备注 */
|
||||
public_note: string;
|
||||
public_note?: string;
|
||||
}
|
||||
|
||||
export interface ModelServerGroup {
|
||||
@@ -464,6 +481,7 @@ export interface ModelServerGroup {
|
||||
}
|
||||
|
||||
export interface ModelServerGroupForm {
|
||||
/** @minLength 1 */
|
||||
name: string;
|
||||
servers: number[];
|
||||
}
|
||||
@@ -501,15 +519,18 @@ export interface ModelService {
|
||||
export interface ModelServiceForm {
|
||||
cover: number;
|
||||
duration: number;
|
||||
enable_show_in_service: boolean;
|
||||
enable_trigger_task: boolean;
|
||||
enable_show_in_service?: boolean;
|
||||
enable_trigger_task?: boolean;
|
||||
fail_trigger_tasks: number[];
|
||||
latency_notify: boolean;
|
||||
latency_notify?: boolean;
|
||||
/** @default 0 */
|
||||
max_latency: number;
|
||||
/** @default 0 */
|
||||
min_latency: number;
|
||||
/** @minLength 1 */
|
||||
name: string;
|
||||
notification_group_id: number;
|
||||
notify: boolean;
|
||||
notify?: boolean;
|
||||
recover_trigger_tasks: number[];
|
||||
skip_servers: Record<string, boolean>;
|
||||
target: string;
|
||||
@@ -526,30 +547,30 @@ export interface ModelServiceInfos {
|
||||
}
|
||||
|
||||
export interface ModelServiceResponse {
|
||||
cycleTransferStats?: Record<string, ModelCycleTransferStats>;
|
||||
services?: Record<string, ModelServiceResponseItem>;
|
||||
cycle_transfer_stats: Record<string, ModelCycleTransferStats>;
|
||||
services: Record<string, ModelServiceResponseItem>;
|
||||
}
|
||||
|
||||
export interface ModelServiceResponseItem {
|
||||
currentDown?: number;
|
||||
currentUp?: number;
|
||||
delay?: number[];
|
||||
down?: number[];
|
||||
service?: ModelService;
|
||||
totalDown?: number;
|
||||
totalUp?: number;
|
||||
up?: number[];
|
||||
current_down: number;
|
||||
current_up: number;
|
||||
delay: number[];
|
||||
down: number[];
|
||||
service: ModelService;
|
||||
total_down: number;
|
||||
total_up: number;
|
||||
up: number[];
|
||||
}
|
||||
|
||||
export interface ModelSettingForm {
|
||||
cover: number;
|
||||
custom_code: string;
|
||||
custom_code_dashboard: string;
|
||||
custom_nameservers: string;
|
||||
enable_ip_change_notification: boolean;
|
||||
enable_plain_ip_in_notification: boolean;
|
||||
ignored_ip_notification: string;
|
||||
install_host: string;
|
||||
custom_code?: string;
|
||||
custom_code_dashboard?: string;
|
||||
custom_nameservers?: string;
|
||||
enable_ip_change_notification?: boolean;
|
||||
enable_plain_ip_in_notification?: boolean;
|
||||
ignored_ip_notification?: string;
|
||||
install_host?: string;
|
||||
/** IP变更提醒的通知组 */
|
||||
ip_change_notification_group_id: number;
|
||||
language: string;
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
export * from './mainStore';
|
||||
export * from './authContext';
|
||||
export * from './api';
|
||||
export * from './api';
|
||||
export * from './service';
|
||||
|
||||
10
src/types/service.ts
Normal file
10
src/types/service.ts
Normal file
@@ -0,0 +1,10 @@
|
||||
export const serviceTypes: Record<number, string> = {
|
||||
1: "HTTP GET",
|
||||
2: "ICMP Ping",
|
||||
3: "TCPing",
|
||||
}
|
||||
|
||||
export const serviceCoverageTypes: Record<number, string> = {
|
||||
0: "All excludes specific servers",
|
||||
1: "Only specific servers",
|
||||
}
|
||||
@@ -1,57 +1,60 @@
|
||||
/** @type {import('tailwindcss').Config} */
|
||||
export default {
|
||||
darkMode: ["class"],
|
||||
content: ["./index.html", "./src/**/*.{ts,tsx,js,jsx}"],
|
||||
theme: {
|
||||
extend: {
|
||||
borderRadius: {
|
||||
lg: 'var(--radius)',
|
||||
md: 'calc(var(--radius) - 2px)',
|
||||
sm: 'calc(var(--radius) - 4px)'
|
||||
},
|
||||
colors: {
|
||||
background: 'hsl(var(--background))',
|
||||
foreground: 'hsl(var(--foreground))',
|
||||
card: {
|
||||
DEFAULT: 'hsl(var(--card))',
|
||||
foreground: 'hsl(var(--card-foreground))'
|
||||
},
|
||||
popover: {
|
||||
DEFAULT: 'hsl(var(--popover))',
|
||||
foreground: 'hsl(var(--popover-foreground))'
|
||||
},
|
||||
primary: {
|
||||
DEFAULT: 'hsl(var(--primary))',
|
||||
foreground: 'hsl(var(--primary-foreground))'
|
||||
},
|
||||
secondary: {
|
||||
DEFAULT: 'hsl(var(--secondary))',
|
||||
foreground: 'hsl(var(--secondary-foreground))'
|
||||
},
|
||||
muted: {
|
||||
DEFAULT: 'hsl(var(--muted))',
|
||||
foreground: 'hsl(var(--muted-foreground))'
|
||||
},
|
||||
accent: {
|
||||
DEFAULT: 'hsl(var(--accent))',
|
||||
foreground: 'hsl(var(--accent-foreground))'
|
||||
},
|
||||
destructive: {
|
||||
DEFAULT: 'hsl(var(--destructive))',
|
||||
foreground: 'hsl(var(--destructive-foreground))'
|
||||
},
|
||||
border: 'hsl(var(--border))',
|
||||
input: 'hsl(var(--input))',
|
||||
ring: 'hsl(var(--ring))',
|
||||
chart: {
|
||||
'1': 'hsl(var(--chart-1))',
|
||||
'2': 'hsl(var(--chart-2))',
|
||||
'3': 'hsl(var(--chart-3))',
|
||||
'4': 'hsl(var(--chart-4))',
|
||||
'5': 'hsl(var(--chart-5))'
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
plugins: [require("tailwindcss-animate")],
|
||||
darkMode: ["class"],
|
||||
content: ["./index.html", "./src/**/*.{ts,tsx,js,jsx}"],
|
||||
theme: {
|
||||
extend: {
|
||||
borderRadius: {
|
||||
lg: 'var(--radius)',
|
||||
md: 'calc(var(--radius) - 2px)',
|
||||
sm: 'calc(var(--radius) - 4px)'
|
||||
},
|
||||
colors: {
|
||||
background: 'hsl(var(--background))',
|
||||
foreground: 'hsl(var(--foreground))',
|
||||
card: {
|
||||
DEFAULT: 'hsl(var(--card))',
|
||||
foreground: 'hsl(var(--card-foreground))'
|
||||
},
|
||||
popover: {
|
||||
DEFAULT: 'hsl(var(--popover))',
|
||||
foreground: 'hsl(var(--popover-foreground))'
|
||||
},
|
||||
primary: {
|
||||
DEFAULT: 'hsl(var(--primary))',
|
||||
foreground: 'hsl(var(--primary-foreground))'
|
||||
},
|
||||
secondary: {
|
||||
DEFAULT: 'hsl(var(--secondary))',
|
||||
foreground: 'hsl(var(--secondary-foreground))'
|
||||
},
|
||||
muted: {
|
||||
DEFAULT: 'hsl(var(--muted))',
|
||||
foreground: 'hsl(var(--muted-foreground))'
|
||||
},
|
||||
accent: {
|
||||
DEFAULT: 'hsl(var(--accent))',
|
||||
foreground: 'hsl(var(--accent-foreground))'
|
||||
},
|
||||
destructive: {
|
||||
DEFAULT: 'hsl(var(--destructive))',
|
||||
foreground: 'hsl(var(--destructive-foreground))'
|
||||
},
|
||||
border: 'hsl(var(--border))',
|
||||
input: 'hsl(var(--input))',
|
||||
ring: 'hsl(var(--ring))',
|
||||
chart: {
|
||||
'1': 'hsl(var(--chart-1))',
|
||||
'2': 'hsl(var(--chart-2))',
|
||||
'3': 'hsl(var(--chart-3))',
|
||||
'4': 'hsl(var(--chart-4))',
|
||||
'5': 'hsl(var(--chart-5))'
|
||||
},
|
||||
},
|
||||
fontSize: {
|
||||
xsm: ['0.825rem', '1.25rem'],
|
||||
},
|
||||
}
|
||||
},
|
||||
plugins: [require("tailwindcss-animate")],
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user