Skip to content

Commit

Permalink
refactor: add server filter
Browse files Browse the repository at this point in the history
  • Loading branch information
Siumauricio committed Jan 1, 2025
1 parent 7fd6436 commit 1f9d60a
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -62,25 +62,27 @@ const Schema = z.object({

type Schema = z.infer<typeof Schema>;

const extractServicesFromProjects = (projects: any[] | undefined) => {
if (!projects) return [];

const allServices = projects.flatMap((project) => {
const services = extractServices(project);
return services.map((service) => service.appName);
});

// Remove duplicates
return [...new Set(allServices)];
};

export const SetupMonitoring = ({ serverId }: Props) => {
const { data, isLoading } = api.server.one.useQuery({
serverId,
});

const { data: projects } = api.project.all.useQuery();

const extractServicesFromProjects = (projects: any[] | undefined) => {
if (!projects) return [];

const allServices = projects.flatMap((project) => {
const services = extractServices(project);
return services
.filter((service) => service.serverId === serverId)
.map((service) => service.appName);
});

// Remove duplicates
return [...new Set(allServices)];
};

const services = extractServicesFromProjects(projects);

const form = useForm<Schema>({
Expand Down Expand Up @@ -245,7 +247,10 @@ export const SetupMonitoring = ({ serverId }: Props) => {
/>
<CommandEmpty>No service found.</CommandEmpty>
<CommandGroup className="max-h-[200px] overflow-hidden">
<ScrollArea className="h-[200px]" onWheel={(e) => e.stopPropagation()}>
<ScrollArea
className="h-[200px]"
onWheel={(e) => e.stopPropagation()}
>
{availableServices?.map((service) => (
<CommandItem
key={service}
Expand Down Expand Up @@ -333,7 +338,10 @@ export const SetupMonitoring = ({ serverId }: Props) => {
/>
<CommandEmpty>No service found.</CommandEmpty>
<CommandGroup className="max-h-[200px] overflow-hidden">
<ScrollArea className="h-[200px]" onWheel={(e) => e.stopPropagation()}>
<ScrollArea
className="h-[200px]"
onWheel={(e) => e.stopPropagation()}
>
{availableServicesToExclude.map((service) => (
<CommandItem
key={service}
Expand Down
8 changes: 8 additions & 0 deletions apps/dokploy/pages/dashboard/project/[projectId].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ import superjson from "superjson";

export type Services = {
appName: string;
serverId?: string | null;
name: string;
type:
| "mariadb"
Expand Down Expand Up @@ -74,6 +75,7 @@ export const extractServices = (data: Project | undefined) => {
createdAt: item.createdAt,
status: item.applicationStatus,
description: item.description,
serverId: item.serverId,
})) || [];

const mariadb: Services[] =
Expand All @@ -85,6 +87,7 @@ export const extractServices = (data: Project | undefined) => {
createdAt: item.createdAt,
status: item.applicationStatus,
description: item.description,
serverId: item.serverId,
})) || [];

const postgres: Services[] =
Expand All @@ -96,6 +99,7 @@ export const extractServices = (data: Project | undefined) => {
createdAt: item.createdAt,
status: item.applicationStatus,
description: item.description,
serverId: item.serverId,
})) || [];

const mongo: Services[] =
Expand All @@ -107,6 +111,7 @@ export const extractServices = (data: Project | undefined) => {
createdAt: item.createdAt,
status: item.applicationStatus,
description: item.description,
serverId: item.serverId,
})) || [];

const redis: Services[] =
Expand All @@ -118,6 +123,7 @@ export const extractServices = (data: Project | undefined) => {
createdAt: item.createdAt,
status: item.applicationStatus,
description: item.description,
serverId: item.serverId,
})) || [];

const mysql: Services[] =
Expand All @@ -129,6 +135,7 @@ export const extractServices = (data: Project | undefined) => {
createdAt: item.createdAt,
status: item.applicationStatus,
description: item.description,
serverId: item.serverId,
})) || [];

const compose: Services[] =
Expand All @@ -140,6 +147,7 @@ export const extractServices = (data: Project | undefined) => {
createdAt: item.createdAt,
status: item.composeStatus,
description: item.description,
serverId: item.serverId,
})) || [];

applications.push(
Expand Down

0 comments on commit 1f9d60a

Please sign in to comment.