From b6846b0419a8126db1e7ddd4ba3b63d64970c133 Mon Sep 17 00:00:00 2001 From: moonrailgun Date: Tue, 7 Nov 2023 23:13:44 +0800 Subject: [PATCH] feat: add clear offlline node button --- src/client/pages/Servers.tsx | 47 ++++++++++++++++++++----- src/server/model/serverStatus.ts | 28 +++++++++++++++ src/server/trpc/routers/index.ts | 2 ++ src/server/trpc/routers/serverStatus.ts | 12 +++++++ src/shared/index.ts | 1 + src/shared/server.ts | 5 +++ 6 files changed, 86 insertions(+), 9 deletions(-) create mode 100644 src/server/trpc/routers/serverStatus.ts create mode 100644 src/shared/server.ts diff --git a/src/client/pages/Servers.tsx b/src/client/pages/Servers.tsx index 4fa46a8..900e5f1 100644 --- a/src/client/pages/Servers.tsx +++ b/src/client/pages/Servers.tsx @@ -1,11 +1,13 @@ -import React, { useEffect, useMemo, useReducer, useRef, useState } from 'react'; +import React, { useMemo, useRef, useState } from 'react'; import { Badge, Button, + Divider, Empty, Form, Input, Modal, + Popconfirm, Steps, Switch, Table, @@ -28,15 +30,31 @@ import { Loading } from '../components/Loading'; import { without } from 'lodash-es'; import { useIntervalUpdate } from '../hooks/useIntervalUpdate'; import clsx from 'clsx'; +import { isServerOnline } from '../../shared'; +import { defaultErrorHandler, trpc } from '../api/trpc'; +import { useEvent } from '../hooks/useEvent'; +import { useRequest } from '../hooks/useRequest'; export const Servers: React.FC = React.memo(() => { const [isModalOpen, setIsModalOpen] = useState(false); const [hideOfflineServer, setHideOfflineServer] = useState(false); + const workspaceId = useCurrentWorkspaceId(); const handleOk = () => { setIsModalOpen(false); }; + const clearOfflineNodeMutation = + trpc.serverStatus.clearOfflineServerStatus.useMutation({ + onError: defaultErrorHandler, + }); + + const [{ loading }, handleClearOfflineNode] = useRequest(async (e) => { + await clearOfflineNodeMutation.mutateAsync({ + workspaceId, + }); + }); + return (
@@ -50,6 +68,21 @@ export const Servers: React.FC = React.memo(() => { Hide Offline
+
+ + + +
+ + +