diff --git a/apps/dokploy/pages/dashboard/project/[projectId]/environment/[environmentId].tsx b/apps/dokploy/pages/dashboard/project/[projectId]/environment/[environmentId].tsx index 886756ab2..a2e54ad51 100644 --- a/apps/dokploy/pages/dashboard/project/[projectId]/environment/[environmentId].tsx +++ b/apps/dokploy/pages/dashboard/project/[projectId]/environment/[environmentId].tsx @@ -1,4 +1,4 @@ -import type { findProjectById } from "@dokploy/server"; +import type { findEnvironmentById } from "@dokploy/server"; import { validateRequest } from "@dokploy/server/lib/auth"; import { createServerSideHelpers } from "@trpc/react-query/server"; import { @@ -102,6 +102,7 @@ import { api } from "@/utils/api"; export type Services = { appName: string; serverId?: string | null; + serverName?: string | null; name: string; type: | "mariadb" @@ -118,8 +119,7 @@ export type Services = { lastDeployDate?: Date | null; }; -type Project = Awaited>; -type Environment = Project["environments"][0]; +type Environment = Awaited>; export const extractServicesFromEnvironment = ( environment: Environment | undefined, @@ -154,6 +154,7 @@ export const extractServicesFromEnvironment = ( status: item.applicationStatus, description: item.description, serverId: item.serverId, + serverName: item?.server?.name || null, lastDeployDate, }; }) || []; @@ -168,6 +169,7 @@ export const extractServicesFromEnvironment = ( status: item.applicationStatus, description: item.description, serverId: item.serverId, + serverName: item?.server?.name || null, })) || []; const postgres: Services[] = @@ -180,6 +182,7 @@ export const extractServicesFromEnvironment = ( status: item.applicationStatus, description: item.description, serverId: item.serverId, + serverName: item?.server?.name || null, })) || []; const mongo: Services[] = @@ -192,6 +195,7 @@ export const extractServicesFromEnvironment = ( status: item.applicationStatus, description: item.description, serverId: item.serverId, + serverName: item?.server?.name || null, })) || []; const redis: Services[] = @@ -204,6 +208,7 @@ export const extractServicesFromEnvironment = ( status: item.applicationStatus, description: item.description, serverId: item.serverId, + serverName: item?.server?.name || null, })) || []; const mysql: Services[] = @@ -216,6 +221,7 @@ export const extractServicesFromEnvironment = ( status: item.applicationStatus, description: item.description, serverId: item.serverId, + serverName: item?.server?.name || null, })) || []; const compose: Services[] = @@ -244,6 +250,7 @@ export const extractServicesFromEnvironment = ( status: item.composeStatus, description: item.description, serverId: item.serverId, + serverName: item?.server?.name || null, lastDeployDate, }; }) || []; @@ -392,6 +399,7 @@ const EnvironmentPage = ( const [isDropdownOpen, setIsDropdownOpen] = useState(false); const [isBulkDeleteDialogOpen, setIsBulkDeleteDialogOpen] = useState(false); const [deleteVolumes, setDeleteVolumes] = useState(false); + const [selectedServerId, setSelectedServerId] = useState("all"); const handleSelectAll = () => { if (selectedServices.length === filteredServices.length) { @@ -781,6 +789,27 @@ const EnvironmentPage = ( setIsBulkActionLoading(false); }; + // Get unique servers from services + const availableServers = useMemo(() => { + if (!applications) return []; + const servers = new Map(); + applications.forEach((service) => { + if (service.serverId && service.serverName) { + servers.set(service.serverId, { + serverId: service.serverId, + serverName: service.serverName, + }); + } + }); + return Array.from(servers.values()); + }, [applications]); + + // Check if there are services without a server (Dokploy server) + const hasServicesWithoutServer = useMemo(() => { + if (!applications) return false; + return applications.some((service) => !service.serverId); + }, [applications]); + const filteredServices = useMemo(() => { if (!applications) return []; const filtered = applications.filter( @@ -789,10 +818,14 @@ const EnvironmentPage = ( service.description ?.toLowerCase() .includes(searchQuery.toLowerCase())) && - (selectedTypes.length === 0 || selectedTypes.includes(service.type)), + (selectedTypes.length === 0 || selectedTypes.includes(service.type)) && + (selectedServerId === "" || + selectedServerId === "all" || + (selectedServerId === "dokploy-server" && !service.serverId) || + service.serverId === selectedServerId), ); return sortServices(filtered); - }, [applications, searchQuery, selectedTypes, sortBy]); + }, [applications, searchQuery, selectedTypes, selectedServerId, sortBy]); const selectedServicesWithRunningStatus = useMemo(() => { return filteredServices.filter( @@ -1366,6 +1399,39 @@ const EnvironmentPage = ( + {(availableServers.length > 0 || + hasServicesWithoutServer) && ( + + )} @@ -1471,7 +1537,15 @@ const EnvironmentPage = ( -
+
+ {service.serverName && ( +
+ + + {service.serverName} + +
+ )} Created diff --git a/packages/server/src/services/environment.ts b/packages/server/src/services/environment.ts index c35862714..fb1952818 100644 --- a/packages/server/src/services/environment.ts +++ b/packages/server/src/services/environment.ts @@ -37,16 +37,38 @@ export const findEnvironmentById = async (environmentId: string) => { applications: { with: { deployments: true, + server: true, + }, + }, + mariadb: { + with: { + server: true, + }, + }, + mongo: { + with: { + server: true, + }, + }, + mysql: { + with: { + server: true, + }, + }, + postgres: { + with: { + server: true, + }, + }, + redis: { + with: { + server: true, }, }, - mariadb: true, - mongo: true, - mysql: true, - postgres: true, - redis: true, compose: { with: { deployments: true, + server: true, }, }, project: true,