From 3e9760d895bf55e625aa35752e617b8b2701e29e Mon Sep 17 00:00:00 2001 From: moonrailgun Date: Sat, 6 Jan 2024 22:08:10 +0800 Subject: [PATCH] feat: add monitor badge #6 --- package.json | 1 + pnpm-lock.yaml | 3 + .../components/monitor/MonitorBadgeView.tsx | 101 ++++++++++++++++++ src/client/components/monitor/MonitorInfo.tsx | 33 +++++- src/server/main.ts | 2 + src/server/router/monitor.ts | 39 +++++++ 6 files changed, 178 insertions(+), 1 deletion(-) create mode 100644 src/client/components/monitor/MonitorBadgeView.tsx create mode 100644 src/server/router/monitor.ts diff --git a/package.json b/package.json index f0e35d1..e8ca996 100644 --- a/package.json +++ b/package.json @@ -42,6 +42,7 @@ "colord": "^2.9.3", "compose-middleware": "^5.0.1", "compression": "^1.7.4", + "copy-to-clipboard": "^3.3.3", "cors": "^2.8.5", "croner": "^7.0.1", "dayjs": "^1.11.9", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 84e6def..24b551f 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -61,6 +61,9 @@ dependencies: compression: specifier: ^1.7.4 version: 1.7.4 + copy-to-clipboard: + specifier: ^3.3.3 + version: 3.3.3 cors: specifier: ^2.8.5 version: 2.8.5 diff --git a/src/client/components/monitor/MonitorBadgeView.tsx b/src/client/components/monitor/MonitorBadgeView.tsx new file mode 100644 index 0000000..9116a99 --- /dev/null +++ b/src/client/components/monitor/MonitorBadgeView.tsx @@ -0,0 +1,101 @@ +import { Checkbox, Divider, Input, message } from 'antd'; +import React, { useMemo, useState } from 'react'; +import { useEvent } from '../../hooks/useEvent'; +import copy from 'copy-to-clipboard'; + +export const MonitorBadgeView: React.FC<{ + workspaceId: string; + monitorId: string; +}> = React.memo((props) => { + const { workspaceId, monitorId } = props; + + const [showDetail, setShowDetail] = useState(false); + + const url = useMemo(() => { + let url = `${window.location.origin}/monitor/${workspaceId}/${monitorId}/badge.svg`; + + if (showDetail) { + url += `?showDetail=true`; + } + + return url; + }, [showDetail]); + + const handleCopy = useEvent((text: string) => { + copy(text); + message.success('Copy success!'); + }); + + return ( +
+
+ +
+

This will show your recent result of your monitor

+
+ setShowDetail(e.target.checked)} + > + Show Detail Number + +
+ + + +

Share with...

+ +
+ `} + addonAfter={ +
handleCopy(``)} + > + Copy +
+ } + /> + + handleCopy(`![](${url})`)} + > + Copy +
+ } + /> + + handleCopy(`[img]${url}[/img]`)} + > + Copy +
+ } + /> + + handleCopy(url)}> + Copy + + } + /> + + + ); +}); +MonitorBadgeView.displayName = 'MonitorBadgeView'; diff --git a/src/client/components/monitor/MonitorInfo.tsx b/src/client/components/monitor/MonitorInfo.tsx index 9edc4a1..9bff6f2 100644 --- a/src/client/components/monitor/MonitorInfo.tsx +++ b/src/client/components/monitor/MonitorInfo.tsx @@ -19,7 +19,8 @@ import { MonitorEventList } from './MonitorEventList'; import { useEvent } from '../../hooks/useEvent'; import { MonitorDataMetrics } from './MonitorDataMetrics'; import { MonitorDataChart } from './MonitorDataChart'; -import { DeleteOutlined } from '@ant-design/icons'; +import { DeleteOutlined, MoreOutlined } from '@ant-design/icons'; +import { MonitorBadgeView } from './MonitorBadgeView'; interface MonitorInfoProps { monitorId: string; @@ -29,6 +30,7 @@ export const MonitorInfo: React.FC = React.memo((props) => { const { monitorId } = props; const [currectResponse, setCurrentResponse] = useState(0); const navigate = useNavigate(); + const [showBadge, setShowBadge] = useState(false); const { data: monitorInfo, @@ -209,6 +211,35 @@ export const MonitorInfo: React.FC = React.memo((props) => { > + + setShowBadge(true), + }, + ], + }} + > +