From d889c930ed7c9a6e8b4892403cbcaff79adc2070 Mon Sep 17 00:00:00 2001 From: moonrailgun Date: Thu, 19 Oct 2023 23:22:39 +0800 Subject: [PATCH] feat: add monitor edit feature --- src/client/api/model/monitor.ts | 14 ++++------ src/client/components/monitor/MonitorInfo.tsx | 27 +++++++++++++++---- src/client/pages/Monitor/Edit.tsx | 4 +-- 3 files changed, 29 insertions(+), 16 deletions(-) diff --git a/src/client/api/model/monitor.ts b/src/client/api/model/monitor.ts index 5575918..7e9387b 100644 --- a/src/client/api/model/monitor.ts +++ b/src/client/api/model/monitor.ts @@ -1,16 +1,12 @@ -import { useQueryClient } from '@tanstack/react-query'; -import { - defaultErrorHandler, - defaultSuccessHandler, - getQueryKey, - trpc, -} from '../trpc'; +import { defaultErrorHandler, defaultSuccessHandler, trpc } from '../trpc'; export function useMonitorUpsert() { - const queryClient = useQueryClient(); + const context = trpc.useContext(); const mutation = trpc.monitor.upsert.useMutation({ onSuccess: (data) => { - queryClient.resetQueries(getQueryKey(trpc.monitor.all)); + context.monitor.all.reset({ + workspaceId: data.workspaceId, + }); defaultSuccessHandler(); }, diff --git a/src/client/components/monitor/MonitorInfo.tsx b/src/client/components/monitor/MonitorInfo.tsx index 5d4d0fd..72d116a 100644 --- a/src/client/components/monitor/MonitorInfo.tsx +++ b/src/client/components/monitor/MonitorInfo.tsx @@ -1,4 +1,4 @@ -import { Card, Select, Space } from 'antd'; +import { Button, Card, Select, Space, Spin } from 'antd'; import dayjs, { Dayjs } from 'dayjs'; import React, { useMemo, useState } from 'react'; import { trpc } from '../../api/trpc'; @@ -13,6 +13,7 @@ import { useSocketSubscribeList } from '../../api/socketio'; import { last, uniqBy } from 'lodash-es'; import { ErrorTip } from '../ErrorTip'; import { ColorTag } from '../ColorTag'; +import { useNavigate } from 'react-router'; interface MonitorInfoProps { monitorId: string; @@ -21,13 +22,18 @@ export const MonitorInfo: React.FC = React.memo((props) => { const workspaceId = useCurrentWorkspaceId(); const { monitorId } = props; const [currectResponse, setCurrentResponse] = useState(0); + const navigate = useNavigate(); - const { data: monitorInfo, isLoading } = trpc.monitor.get.useQuery({ + const { + data: monitorInfo, + isInitialLoading, + isLoading, + } = trpc.monitor.get.useQuery({ workspaceId, id: monitorId, }); - if (isLoading) { + if (isInitialLoading) { return ; } @@ -36,7 +42,7 @@ export const MonitorInfo: React.FC = React.memo((props) => { } return ( -
+
@@ -56,6 +62,17 @@ export const MonitorInfo: React.FC = React.memo((props) => {
+
+ +
+ = React.memo((props) => { - + ); }); MonitorInfo.displayName = 'MonitorInfo'; diff --git a/src/client/pages/Monitor/Edit.tsx b/src/client/pages/Monitor/Edit.tsx index b2a3029..78c3cc4 100644 --- a/src/client/pages/Monitor/Edit.tsx +++ b/src/client/pages/Monitor/Edit.tsx @@ -33,11 +33,11 @@ export const MonitorEdit: React.FC = React.memo(() => { { - await mutation.mutateAsync({ + const monitor = await mutation.mutateAsync({ ...value, workspaceId: currentWorkspaceId, }); - navigate('/monitor', { replace: true }); + navigate(`/monitor/${monitor.id}`, { replace: true }); }} />