From ec591f0c54eed0af66a40c0ade64e11c32c8164c Mon Sep 17 00:00:00 2001 From: moonrailgun Date: Sat, 13 Jan 2024 02:16:57 +0800 Subject: [PATCH] feat: allow display current response value in monitor list useful for monitor page to display current value --- nodemon.json | 2 +- prisma/zod/schemas/index.ts | 1 + .../components/monitor/MonitorDataChart.tsx | 14 ++-- .../components/monitor/MonitorHealthBar.tsx | 1 - src/client/components/monitor/MonitorList.tsx | 1 + .../components/monitor/MonitorListItem.tsx | 61 +++++++++++++---- .../monitor/StatusPage/EditForm.tsx | 65 +++++++++++++------ .../monitor/StatusPage/Services.tsx | 9 ++- .../components/monitor/provider/index.ts | 18 +++++ src/types/index.ts | 7 +- src/types/monitor.ts | 1 + 11 files changed, 133 insertions(+), 47 deletions(-) diff --git a/nodemon.json b/nodemon.json index 30c46b8..7752c48 100644 --- a/nodemon.json +++ b/nodemon.json @@ -1,6 +1,6 @@ { "verbose": true, - "watch": ["./src/server"], + "watch": ["./src/server", "./prisma"], "ext": "ts", "delay": 1000, "exec": "ts-node --transpileOnly ./src/server/main.ts" diff --git a/prisma/zod/schemas/index.ts b/prisma/zod/schemas/index.ts index cc452cc..4253045 100644 --- a/prisma/zod/schemas/index.ts +++ b/prisma/zod/schemas/index.ts @@ -3,5 +3,6 @@ import { z } from 'zod'; export const MonitorStatusPageListSchema = z.array( z.object({ id: z.string(), + showCurrent: z.boolean().default(false).optional(), }) ); diff --git a/src/client/components/monitor/MonitorDataChart.tsx b/src/client/components/monitor/MonitorDataChart.tsx index 6701a30..760a3f8 100644 --- a/src/client/components/monitor/MonitorDataChart.tsx +++ b/src/client/components/monitor/MonitorDataChart.tsx @@ -6,7 +6,7 @@ import React, { useState, useMemo } from 'react'; import { useSocketSubscribeList } from '../../api/socketio'; import { trpc } from '../../api/trpc'; import { useCurrentWorkspaceId } from '../../store/user'; -import { getMonitorProvider } from './provider'; +import { getMonitorProvider, getProviderDisplay } from './provider'; export const MonitorDataChart: React.FC<{ monitorId: string }> = React.memo( (props) => { @@ -122,16 +122,14 @@ export const MonitorDataChart: React.FC<{ monitorId: string }> = React.memo( return dayjs(datum.time).format('YYYY-MM-DD HH:mm'); }, formatter(datum) { - const name = providerInfo?.valueLabel - ? providerInfo?.valueLabel - : 'usage'; - const formatterFn = providerInfo?.valueFormatter - ? providerInfo?.valueFormatter - : (value: number) => `${value}ms`; + const { name, text } = getProviderDisplay( + datum.value, + providerInfo + ); return { name, - value: datum.value ? formatterFn(datum.value) : 'null', + value: datum.value ? text : 'null', }; }, }, diff --git a/src/client/components/monitor/MonitorHealthBar.tsx b/src/client/components/monitor/MonitorHealthBar.tsx index 619c755..25c1d68 100644 --- a/src/client/components/monitor/MonitorHealthBar.tsx +++ b/src/client/components/monitor/MonitorHealthBar.tsx @@ -4,7 +4,6 @@ import { takeRight, last } from 'lodash-es'; import { HealthBar, HealthBarBeat, HealthBarProps } from '../HealthBar'; import dayjs from 'dayjs'; import { trpc } from '../../api/trpc'; -import { useCurrentWorkspaceId } from '../../store/user'; import { useWatch } from '../../hooks/useWatch'; interface MonitorHealthBarProps { diff --git a/src/client/components/monitor/MonitorList.tsx b/src/client/components/monitor/MonitorList.tsx index 1d752bf..184e4d8 100644 --- a/src/client/components/monitor/MonitorList.tsx +++ b/src/client/components/monitor/MonitorList.tsx @@ -44,6 +44,7 @@ export const MonitorList: React.FC = React.memo(() => { workspaceId={workspaceId} monitorId={monitor.id} monitorName={monitor.name} + monitorType={monitor.type} onClick={() => { navigate(`/monitor/${monitor.id}`); }} diff --git a/src/client/components/monitor/MonitorListItem.tsx b/src/client/components/monitor/MonitorListItem.tsx index b8321f3..aea4bba 100644 --- a/src/client/components/monitor/MonitorListItem.tsx +++ b/src/client/components/monitor/MonitorListItem.tsx @@ -1,15 +1,28 @@ import clsx from 'clsx'; import React, { useMemo, useState } from 'react'; import { MonitorHealthBar } from './MonitorHealthBar'; +import { last } from 'lodash-es'; +import { getMonitorProvider, getProviderDisplay } from './provider'; +import { Tooltip } from 'antd'; export const MonitorListItem: React.FC<{ className?: string; workspaceId: string; monitorId: string; monitorName: string; + monitorType: string; + showCurrentResponse?: boolean; onClick?: () => void; }> = React.memo((props) => { - const { className, workspaceId, monitorId, monitorName, onClick } = props; + const { + className, + workspaceId, + monitorId, + monitorName, + monitorType, + showCurrentResponse = false, + onClick, + } = props; const [beats, setBeats] = useState< ({ @@ -33,11 +46,29 @@ export const MonitorListItem: React.FC<{ return parseFloat(((up / beats.length) * 100).toFixed(1)); }, [beats]); + const provider = getMonitorProvider(monitorType); + + const latestResponse = useMemo((): string | false => { + const val = last(beats)?.value; + + if (!val) { + return false; + } + + if (!provider) { + return String(val); + } + + const { text } = getProviderDisplay(val, provider); + + return text; + }, [beats, provider]); + return (
{monitorName}
{/*
- {monitor.tags.map((tag) => ( - - {tag.label} - - ))} -
*/} + {monitor.tags.map((tag) => ( + + {tag.label} + + ))} +
*/} + {showCurrentResponse && latestResponse && ( + +
+ {latestResponse} +
+
+ )} +
return ( <> - {fields.map((field, index) => ( -
- - - +
+ {fields.map((field, index) => ( + // monitor item + <> + {index !== 0 && } - remove(field.name)} - /> -
- ))} +
+ + + + +
+
+ + + + + + Show Current Response + +
+ + remove(field.name)} + /> +
+
+ + ))} +