From b25bf1e341e2f500d873c5ca23824b6789cd4d2d Mon Sep 17 00:00:00 2001 From: Oscar Zhou <100548325+oscarzhou-portainer@users.noreply.github.com> Date: Mon, 10 Feb 2025 21:08:27 +1300 Subject: [PATCH] fix(podman): missing filter in homepage [BE-11502] (#404) --- .../EnvironmentList/EnvironmentList.tsx | 1 + .../EnvironmentListFilters.tsx | 15 ++++++++-- .../environments/environment.service/index.ts | 2 ++ .../queries/useEnvironmentList.ts | 29 ++++++++++++++++++- 4 files changed, 44 insertions(+), 3 deletions(-) diff --git a/app/react/portainer/HomeView/EnvironmentList/EnvironmentList.tsx b/app/react/portainer/HomeView/EnvironmentList/EnvironmentList.tsx index 4805ce6e6..9884048b3 100644 --- a/app/react/portainer/HomeView/EnvironmentList/EnvironmentList.tsx +++ b/app/react/portainer/HomeView/EnvironmentList/EnvironmentList.tsx @@ -109,6 +109,7 @@ export function EnvironmentList({ onClickBrowse, onRefresh }: Props) { agentVersions, updateInformation: isBE, edgeAsync: getEdgeAsyncValue(connectionTypes), + platformTypes, }; const queryWithSort = { diff --git a/app/react/portainer/HomeView/EnvironmentList/EnvironmentListFilters.tsx b/app/react/portainer/HomeView/EnvironmentList/EnvironmentListFilters.tsx index 3c4d993e4..06d1c5108 100644 --- a/app/react/portainer/HomeView/EnvironmentList/EnvironmentListFilters.tsx +++ b/app/react/portainer/HomeView/EnvironmentList/EnvironmentListFilters.tsx @@ -209,6 +209,7 @@ function getPlatformTypeOptions(connectionTypes: ConnectionType[]) { { value: PlatformType.Docker, label: 'Docker' }, { value: PlatformType.Azure, label: 'Azure' }, { value: PlatformType.Kubernetes, label: 'Kubernetes' }, + { value: PlatformType.Podman, label: 'Podman' }, ]; if (connectionTypes.length === 0) { @@ -216,15 +217,25 @@ function getPlatformTypeOptions(connectionTypes: ConnectionType[]) { } const connectionTypePlatformType = { - [ConnectionType.API]: [PlatformType.Docker, PlatformType.Azure], - [ConnectionType.Agent]: [PlatformType.Docker, PlatformType.Kubernetes], + [ConnectionType.API]: [ + PlatformType.Docker, + PlatformType.Azure, + PlatformType.Podman, + ], + [ConnectionType.Agent]: [ + PlatformType.Docker, + PlatformType.Kubernetes, + PlatformType.Podman, + ], [ConnectionType.EdgeAgentStandard]: [ PlatformType.Kubernetes, PlatformType.Docker, + PlatformType.Podman, ], [ConnectionType.EdgeAgentAsync]: [ PlatformType.Docker, PlatformType.Kubernetes, + PlatformType.Podman, ], }; diff --git a/app/react/portainer/environments/environment.service/index.ts b/app/react/portainer/environments/environment.service/index.ts index 09844e6ce..8971a4af0 100644 --- a/app/react/portainer/environments/environment.service/index.ts +++ b/app/react/portainer/environments/environment.service/index.ts @@ -6,6 +6,7 @@ import { EnvironmentSecuritySettings, EnvironmentStatus, EnvironmentGroupId, + PlatformType, } from '@/react/portainer/environments/types'; import { type TagId } from '@/portainer/tags/types'; import { UserId } from '@/portainer/users/types'; @@ -45,6 +46,7 @@ export interface BaseEnvironmentsQueryParams { agentVersions?: string[]; updateInformation?: boolean; edgeCheckInPassedSeconds?: number; + platformTypes?: PlatformType[]; } export type EnvironmentsQueryParams = BaseEnvironmentsQueryParams & diff --git a/app/react/portainer/environments/queries/useEnvironmentList.ts b/app/react/portainer/environments/queries/useEnvironmentList.ts index ef545b06f..850fc7cfd 100644 --- a/app/react/portainer/environments/queries/useEnvironmentList.ts +++ b/app/react/portainer/environments/queries/useEnvironmentList.ts @@ -1,8 +1,11 @@ import { useQuery } from '@tanstack/react-query'; import { withError } from '@/react-tools/react-query'; +import { + PlatformType, + EnvironmentStatus, +} from '@/react/portainer/environments/types'; -import { EnvironmentStatus } from '../types'; import { EnvironmentsQueryParams, getEnvironments, @@ -98,6 +101,30 @@ export function useEnvironmentList( } ); + if (data?.value && query && query.platformTypes) { + const platforms = Array.from(query.platformTypes); + + if ( + platforms.includes(PlatformType.Podman) !== + platforms.includes(PlatformType.Docker) + ) { + const isPodmanSelected = platforms.includes(PlatformType.Podman); + const containerEngineToExclude = isPodmanSelected ? 'docker' : 'podman'; + + const filteredList = data?.value.filter( + (env) => env.ContainerEngine !== containerEngineToExclude + ); + + return { + isLoading, + environments: filteredList, + totalCount: data ? data.totalCount : 0, + totalAvailable: data ? data.totalAvailable : 0, + updateAvailable: data ? data.updateAvailable : false, + }; + } + } + return { isLoading, environments: data ? data.value : [],