feat: add server count in desktop layout

This commit is contained in:
moonrailgun 2024-04-21 16:36:34 +08:00
parent 92f8700254
commit 720a1d744e
3 changed files with 14 additions and 2 deletions

View File

@ -81,7 +81,7 @@ export const DesktopLayout: React.FC<LayoutProps> = React.memo((props) => {
},
{
title: t('Servers'),
label: '',
label: String(serviceCount?.server ?? ''),
icon: LuServer,
to: '/server',
},

View File

@ -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;
}

View File

@ -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,
};