mirror of
https://github.com/Buriburizaem0n/admin-frontend-domain.git
synced 2026-02-04 04:30:06 +00:00
@@ -1,5 +1,3 @@
|
||||
import { useMainStore } from "@/hooks/useMainStore";
|
||||
|
||||
interface CommonResponse<T> {
|
||||
success: boolean;
|
||||
error: string;
|
||||
|
||||
@@ -29,7 +29,7 @@ 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, ModelServiceResponse } from "@/types"
|
||||
import { ModelService } from "@/types"
|
||||
import { createService, updateService } from "@/api/service"
|
||||
import { Checkbox } from "@/components/ui/checkbox"
|
||||
import { Label } from "@/components/ui/label"
|
||||
@@ -48,7 +48,7 @@ import { useTranslation } from "react-i18next";
|
||||
|
||||
interface ServiceCardProps {
|
||||
data?: ModelService;
|
||||
mutate: KeyedMutator<ModelServiceResponse>;
|
||||
mutate: KeyedMutator<ModelService[]>;
|
||||
}
|
||||
|
||||
const serviceFormSchema = z.object({
|
||||
|
||||
@@ -9,10 +9,9 @@ import {
|
||||
TableHeader,
|
||||
TableRow,
|
||||
} from "@/components/ui/table";
|
||||
import { ModelServiceResponse, ModelServiceResponseItem as Service } from "@/types";
|
||||
import { ModelService 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";
|
||||
@@ -24,8 +23,8 @@ import { useTranslation } from "react-i18next";
|
||||
|
||||
export default function ServicePage() {
|
||||
const { t } = useTranslation();
|
||||
const { data, mutate, error, isLoading } = useSWR<ModelServiceResponse>(
|
||||
"/api/v1/service",
|
||||
const { data, mutate, error, isLoading } = useSWR<Service[]>(
|
||||
"/api/v1/service/list",
|
||||
swrFetcher
|
||||
);
|
||||
|
||||
@@ -62,33 +61,33 @@ export default function ServicePage() {
|
||||
},
|
||||
{
|
||||
header: "ID",
|
||||
accessorKey: "service.id",
|
||||
accessorFn: (row) => row.service.id,
|
||||
accessorKey: "id",
|
||||
accessorFn: (row) => row.id,
|
||||
},
|
||||
{
|
||||
header: t("Name"),
|
||||
accessorFn: (row) => row.service.name,
|
||||
accessorKey: "service.name",
|
||||
accessorFn: (row) => row.name,
|
||||
accessorKey: "name",
|
||||
cell: ({ row }) => {
|
||||
const s = row.original;
|
||||
return <div className="max-w-24 whitespace-normal break-words">{s.service.name}</div>;
|
||||
return <div className="max-w-24 whitespace-normal break-words">{s.name}</div>;
|
||||
},
|
||||
},
|
||||
{
|
||||
header: t("Target"),
|
||||
accessorFn: (row) => row.service.target,
|
||||
accessorKey: "service.target",
|
||||
accessorFn: (row) => row.target,
|
||||
accessorKey: "target",
|
||||
cell: ({ row }) => {
|
||||
const s = row.original;
|
||||
return <div className="max-w-24 whitespace-normal break-words">{s.service.target}</div>;
|
||||
return <div className="max-w-24 whitespace-normal break-words">{s.target}</div>;
|
||||
},
|
||||
},
|
||||
{
|
||||
header: t("Coverage"),
|
||||
accessorKey: "service.cover",
|
||||
accessorFn: (row) => row.service.cover,
|
||||
accessorKey: "cover",
|
||||
accessorFn: (row) => row.cover,
|
||||
cell: ({ row }) => {
|
||||
const s = row.original.service;
|
||||
const s = row.original;
|
||||
return (
|
||||
<div className="max-w-48 whitespace-normal break-words">
|
||||
{(() => {
|
||||
@@ -107,39 +106,39 @@ export default function ServicePage() {
|
||||
},
|
||||
{
|
||||
header: t("SpecificServers"),
|
||||
accessorKey: "service.skipServers",
|
||||
accessorFn: (row) => Object.keys(row.service.skip_servers ?? {}),
|
||||
accessorKey: "skipServers",
|
||||
accessorFn: (row) => Object.keys(row.skip_servers ?? {}),
|
||||
},
|
||||
{
|
||||
header: t("Type"),
|
||||
accessorKey: "service.type",
|
||||
accessorFn: (row) => row.service.type,
|
||||
cell: ({ row }) => serviceTypes[row.original.service.type] || "",
|
||||
accessorKey: "type",
|
||||
accessorFn: (row) => row.type,
|
||||
cell: ({ row }) => serviceTypes[row.original.type] || "",
|
||||
},
|
||||
{
|
||||
header: t("Interval"),
|
||||
accessorKey: "service.duration",
|
||||
accessorFn: (row) => row.service.duration,
|
||||
accessorKey: "duration",
|
||||
accessorFn: (row) => row.duration,
|
||||
},
|
||||
{
|
||||
header: t("NotifierGroupID"),
|
||||
accessorKey: "service.ngroup",
|
||||
accessorFn: (row) => row.service.notification_group_id,
|
||||
accessorKey: "ngroup",
|
||||
accessorFn: (row) => row.notification_group_id,
|
||||
},
|
||||
{
|
||||
header: t("Trigger"),
|
||||
accessorKey: "service.triggerTask",
|
||||
accessorFn: (row) => row.service.enable_trigger_task ?? false,
|
||||
accessorKey: "triggerTask",
|
||||
accessorFn: (row) => row.enable_trigger_task ?? false,
|
||||
},
|
||||
{
|
||||
header: t("TasksToTriggerOnAlert"),
|
||||
accessorKey: "service.failTriggerTasks",
|
||||
accessorFn: (row) => row.service.fail_trigger_tasks,
|
||||
accessorKey: "failTriggerTasks",
|
||||
accessorFn: (row) => row.fail_trigger_tasks,
|
||||
},
|
||||
{
|
||||
header: t("TasksToTriggerAfterRecovery"),
|
||||
accessorKey: "service.recoverTriggerTasks",
|
||||
accessorFn: (row) => row.service.recover_trigger_tasks,
|
||||
accessorKey: "recoverTriggerTasks",
|
||||
accessorFn: (row) => row.recover_trigger_tasks,
|
||||
},
|
||||
{
|
||||
id: "actions",
|
||||
@@ -149,21 +148,21 @@ export default function ServicePage() {
|
||||
return (
|
||||
<ActionButtonGroup
|
||||
className="flex gap-2"
|
||||
delete={{ fn: deleteService, id: s.service.id, mutate: mutate }}
|
||||
delete={{ fn: deleteService, id: s.id, mutate: mutate }}
|
||||
>
|
||||
<ServiceCard mutate={mutate} data={s.service} />
|
||||
<ServiceCard mutate={mutate} data={s} />
|
||||
</ActionButtonGroup>
|
||||
);
|
||||
},
|
||||
},
|
||||
];
|
||||
|
||||
const dataArr = useMemo(() => {
|
||||
return conv.recordToArr(data?.services ?? {});
|
||||
}, [data?.services]);
|
||||
const dataCache = useMemo(() => {
|
||||
return data ?? [];
|
||||
}, [data]);
|
||||
|
||||
const table = useReactTable({
|
||||
data: dataArr,
|
||||
data: dataCache,
|
||||
columns,
|
||||
getCoreRowModel: getCoreRowModel(),
|
||||
});
|
||||
@@ -178,7 +177,7 @@ export default function ServicePage() {
|
||||
className="flex-2 flex ml-auto gap-2"
|
||||
delete={{
|
||||
fn: deleteService,
|
||||
id: selectedRows.map((r) => r.original.service.id),
|
||||
id: selectedRows.map((r) => r.original.id),
|
||||
mutate: mutate,
|
||||
}}
|
||||
>
|
||||
|
||||
@@ -63,6 +63,12 @@ export interface GithubComNezhahqNezhaModelCommonResponseArrayModelServerGroupRe
|
||||
success: boolean;
|
||||
}
|
||||
|
||||
export interface GithubComNezhahqNezhaModelCommonResponseArrayModelService {
|
||||
data: ModelService[];
|
||||
error: string;
|
||||
success: boolean;
|
||||
}
|
||||
|
||||
export interface GithubComNezhahqNezhaModelCommonResponseArrayModelServiceInfos {
|
||||
data: ModelServiceInfos[];
|
||||
error: string;
|
||||
@@ -555,7 +561,7 @@ export interface ModelServiceResponseItem {
|
||||
current_up: number;
|
||||
delay: number[];
|
||||
down: number[];
|
||||
service: ModelService;
|
||||
service_name: string;
|
||||
total_down: number;
|
||||
total_up: number;
|
||||
up: number[];
|
||||
@@ -604,6 +610,7 @@ export interface ModelSettingResponse {
|
||||
jwt_secret_key: string;
|
||||
/** 系统语言,默认 zh_CN */
|
||||
language: string;
|
||||
listen_host: string;
|
||||
listen_port: number;
|
||||
/** 时区,默认为 Asia/Shanghai */
|
||||
location: string;
|
||||
|
||||
Reference in New Issue
Block a user