From e79c4b48190c9c1867210399b13e8e4d7386fcd0 Mon Sep 17 00:00:00 2001 From: moonrailgun Date: Fri, 23 Feb 2024 00:07:30 +0800 Subject: [PATCH] feat: add telemetry event count --- src/client/App.tsx | 6 ++--- .../components/telemetry/TelemetryCounter.tsx | 17 +++++++++++++ .../components/telemetry/TelemetryList.tsx | 13 ++++++++++ src/client/pages/Layout.tsx | 4 ++- src/server/trpc/routers/telemetry.ts | 25 +++++++++++++++++++ 5 files changed, 61 insertions(+), 4 deletions(-) create mode 100644 src/client/components/telemetry/TelemetryCounter.tsx diff --git a/src/client/App.tsx b/src/client/App.tsx index 7d4844c..550698f 100644 --- a/src/client/App.tsx +++ b/src/client/App.tsx @@ -22,14 +22,14 @@ import { StatusPage } from './pages/Status'; import { TelemetryPage } from './pages/Telemetry'; export const AppRoutes: React.FC = React.memo(() => { - const { info } = useUserStore(); + const { info: userInfo } = useUserStore(); const { allowRegister } = useGlobalConfig(); useInjectWebsiteScript(); return ( - {info ? ( + {userInfo ? ( }> } /> } /> @@ -50,7 +50,7 @@ export const AppRoutes: React.FC = React.memo(() => { + } /> diff --git a/src/client/components/telemetry/TelemetryCounter.tsx b/src/client/components/telemetry/TelemetryCounter.tsx new file mode 100644 index 0000000..ff3a237 --- /dev/null +++ b/src/client/components/telemetry/TelemetryCounter.tsx @@ -0,0 +1,17 @@ +import React from 'react'; +import { trpc } from '../../api/trpc'; +import { useCurrentWorkspaceId } from '../../store/user'; +import { formatNumber } from '../../utils/common'; + +export const TelemetryCounter: React.FC<{ + telemetryId: string; +}> = React.memo((props) => { + const workspaceId = useCurrentWorkspaceId(); + const { data = 0 } = trpc.telemetry.eventCount.useQuery({ + workspaceId, + telemetryId: props.telemetryId, + }); + + return {formatNumber(data)}; +}); +TelemetryCounter.displayName = 'TelemetryCounter'; diff --git a/src/client/components/telemetry/TelemetryList.tsx b/src/client/components/telemetry/TelemetryList.tsx index 5aae552..8a3dc2e 100644 --- a/src/client/components/telemetry/TelemetryList.tsx +++ b/src/client/components/telemetry/TelemetryList.tsx @@ -12,6 +12,7 @@ import { import { useNavigate } from 'react-router'; import { PageHeader } from '../PageHeader'; import { useEvent } from '../../hooks/useEvent'; +import { TelemetryCounter } from './TelemetryCounter'; type TelemetryInfo = AppRouterOutput['telemetry']['all'][number]; @@ -108,8 +109,20 @@ const TelemetryListTable: React.FC<{ dataIndex: 'name', title: t('Name'), }, + { + dataIndex: 'id', + title: t('Count'), + align: 'center', + width: 130, + render: (id) => { + return ; + }, + }, { key: 'action', + title: t('Actions'), + align: 'right', + width: 240, render: (_, record) => { return (
diff --git a/src/client/pages/Layout.tsx b/src/client/pages/Layout.tsx index 22c2c93..ef5fc9a 100644 --- a/src/client/pages/Layout.tsx +++ b/src/client/pages/Layout.tsx @@ -157,7 +157,9 @@ export const Layout: React.FC = React.memo(() => { - + {alphaMode && ( + + )}
diff --git a/src/server/trpc/routers/telemetry.ts b/src/server/trpc/routers/telemetry.ts index df66c08..917ab0e 100644 --- a/src/server/trpc/routers/telemetry.ts +++ b/src/server/trpc/routers/telemetry.ts @@ -33,6 +33,31 @@ export const telemetryRouter = router({ return res; }), + eventCount: workspaceProcedure + .meta( + buildTelemetryOpenapi({ + method: 'GET', + path: '/eventCount', + }) + ) + .input( + z.object({ + telemetryId: z.string(), + }) + ) + .output(z.number()) + .query(async ({ input }) => { + const { workspaceId, telemetryId } = input; + + const count = await prisma.telemetryEvent.count({ + where: { + workspaceId, + telemetryId, + }, + }); + + return count; + }), upsert: workspaceOwnerProcedure .meta( buildTelemetryOpenapi({