diff --git a/src/client/pages/Layout/DesktopLayout.tsx b/src/client/pages/Layout/DesktopLayout.tsx index e79bdd1..69678f3 100644 --- a/src/client/pages/Layout/DesktopLayout.tsx +++ b/src/client/pages/Layout/DesktopLayout.tsx @@ -81,7 +81,7 @@ export const DesktopLayout: React.FC = React.memo((props) => { }, { title: t('Servers'), - label: '', + label: String(serviceCount?.server ?? ''), icon: LuServer, to: '/server', }, diff --git a/src/server/model/serverStatus.ts b/src/server/model/serverStatus.ts index d63aa54..8db9f4d 100644 --- a/src/server/model/serverStatus.ts +++ b/src/server/model/serverStatus.ts @@ -1,4 +1,3 @@ -import dayjs from 'dayjs'; import { ServerStatusInfo } from '../../types'; import { createSubscribeInitializer, subscribeEventBus } from '../ws/shared'; import _ from 'lodash'; @@ -75,3 +74,11 @@ export function clearOfflineServerStatus(workspaceId: string) { return serverMap[workspaceId]; } + +export function getServerCount(workspaceId: string): number { + if (!serverMap[workspaceId]) { + return 0; + } + + return Object.keys(serverMap[workspaceId]).length; +} diff --git a/src/server/trpc/routers/workspace.ts b/src/server/trpc/routers/workspace.ts index 5eea5ad..ef7afed 100644 --- a/src/server/trpc/routers/workspace.ts +++ b/src/server/trpc/routers/workspace.ts @@ -11,6 +11,7 @@ import { workspaceDashboardLayoutSchema } from '../../model/_schema'; import { Prisma } from '@prisma/client'; import { OPENAPI_TAG } from '../../utils/const'; import { OpenApiMeta } from 'trpc-openapi'; +import { getServerCount } from '../../model/serverStatus'; export const workspaceRouter = router({ getUserWorkspaceRole: publicProcedure @@ -46,6 +47,7 @@ export const workspaceRouter = router({ z.object({ website: z.number(), monitor: z.number(), + server: z.number(), telemetry: z.number(), page: z.number(), }) @@ -76,9 +78,12 @@ export const workspaceRouter = router({ }), ]); + const server = getServerCount(workspaceId); + return { website, monitor, + server, telemetry, page, };