Skip to content

Commit

Permalink
feat: add server count in desktop layout
Browse files Browse the repository at this point in the history
  • Loading branch information
moonrailgun committed Apr 21, 2024
1 parent 92f8700 commit 720a1d7
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/client/pages/Layout/DesktopLayout.tsx
Expand Up @@ -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',
},
Expand Down
9 changes: 8 additions & 1 deletion 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';
Expand Down Expand Up @@ -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;
}
5 changes: 5 additions & 0 deletions src/server/trpc/routers/workspace.ts
Expand Up @@ -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
Expand Down Expand Up @@ -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(),
})
Expand Down Expand Up @@ -76,9 +78,12 @@ export const workspaceRouter = router({
}),
]);

const server = getServerCount(workspaceId);

return {
website,
monitor,
server,
telemetry,
page,
};
Expand Down

0 comments on commit 720a1d7

Please sign in to comment.