From c317b77d12edbe3ddd2a4bfc4a75c3f0470d65be Mon Sep 17 00:00:00 2001 From: moonrailgun Date: Sat, 30 Dec 2023 01:02:57 +0800 Subject: [PATCH] feat: add delete monitor data/events button --- src/client/components/monitor/MonitorInfo.tsx | 73 ++++++++++++++++++- 1 file changed, 72 insertions(+), 1 deletion(-) diff --git a/src/client/components/monitor/MonitorInfo.tsx b/src/client/components/monitor/MonitorInfo.tsx index 5549fb5..9edc4a1 100644 --- a/src/client/components/monitor/MonitorInfo.tsx +++ b/src/client/components/monitor/MonitorInfo.tsx @@ -1,4 +1,4 @@ -import { Button, Card, Popconfirm, Space, Spin } from 'antd'; +import { Button, Card, Dropdown, Popconfirm, Space, Spin, Modal } from 'antd'; import dayjs from 'dayjs'; import React, { useState } from 'react'; import { @@ -19,6 +19,7 @@ import { MonitorEventList } from './MonitorEventList'; import { useEvent } from '../../hooks/useEvent'; import { MonitorDataMetrics } from './MonitorDataMetrics'; import { MonitorDataChart } from './MonitorDataChart'; +import { DeleteOutlined } from '@ant-design/icons'; interface MonitorInfoProps { monitorId: string; @@ -45,6 +46,14 @@ export const MonitorInfo: React.FC = React.memo((props) => { onSuccess: defaultSuccessHandler, onError: defaultErrorHandler, }); + const clearEventsMutation = trpc.monitor.clearEvents.useMutation({ + onSuccess: defaultSuccessHandler, + onError: defaultErrorHandler, + }); + const clearDataMutation = trpc.monitor.clearData.useMutation({ + onSuccess: defaultSuccessHandler, + onError: defaultErrorHandler, + }); const trpcUtils = trpc.useContext(); @@ -93,6 +102,44 @@ export const MonitorInfo: React.FC = React.memo((props) => { navigate('/monitor'); }); + const handleClearEvents = useEvent(() => { + Modal.confirm({ + title: 'Warning', + content: 'Are you sure want to delete all events for this monitor?', + okButtonProps: { + danger: true, + }, + onOk: async () => { + await clearEventsMutation.mutateAsync({ + workspaceId, + monitorId, + }); + trpcUtils.monitor.events.refetch({ + workspaceId, + monitorId, + }); + }, + }); + }); + + const handleClearData = useEvent(() => { + Modal.confirm({ + title: 'Warning', + content: 'Are you sure want to delete all heartbeats for this monitor?', + okButtonProps: { + danger: true, + }, + onOk: async () => { + await clearDataMutation.mutateAsync({ + workspaceId, + monitorId, + }); + trpcUtils.monitor.data.reset(); + trpcUtils.monitor.recentData.reset(); + }, + }); + }); + if (isInitialLoading) { return ; } @@ -189,6 +236,30 @@ export const MonitorInfo: React.FC = React.memo((props) => { +
+ + + +
+