From 444be23df724a8b601d728f6948a574c79d5eef6 Mon Sep 17 00:00:00 2001 From: Alexander Matyushentsev Date: Mon, 12 Jun 2023 14:57:11 -0700 Subject: [PATCH] fix: fix cluster filtering and refresh button on application list page Signed-off-by: Alexander Matyushentsev --- server/application/application.go | 28 +++++++++++++++---- .../applications-list/applications-list.tsx | 16 +++-------- 2 files changed, 27 insertions(+), 17 deletions(-) diff --git a/server/application/application.go b/server/application/application.go index 02a468da32c85..f92619294dcee 100644 --- a/server/application/application.go +++ b/server/application/application.go @@ -7,6 +7,7 @@ import ( "fmt" "math" "reflect" + "regexp" "sort" "strconv" "strings" @@ -72,9 +73,10 @@ const ( ) var ( - watchAPIBufferSize = env.ParseNumFromEnv(argocommon.EnvWatchAPIBufferSize, 1000, 0, math.MaxInt32) - permissionDeniedErr = status.Error(codes.PermissionDenied, "permission denied") - maxListLimit = env.ParseNumFromEnv(argocommon.EnvMaxResourceListLimit, 3000, 0, math.MaxInt32) + watchAPIBufferSize = env.ParseNumFromEnv(argocommon.EnvWatchAPIBufferSize, 1000, 0, math.MaxInt32) + permissionDeniedErr = status.Error(codes.PermissionDenied, "permission denied") + maxListLimit = env.ParseNumFromEnv(argocommon.EnvMaxResourceListLimit, 3000, 0, math.MaxInt32) + clusterNameFilterRegex = regexp.MustCompile(`^(.*) [(](http.*)[)]$`) ) // Server provides an Application service @@ -2395,8 +2397,24 @@ func (s *Server) getAppFilter(ctx context.Context, q *application.ApplicationQue return false } - if len(q.GetClusters()) > 0 && !sets.NewString(q.GetClusters()...).Has(app.Spec.Destination.Server) { - return false + if len(q.GetClusters()) > 0 { + for _, item := range q.GetClusters() { + url := "" + name := "" + if res := clusterNameFilterRegex.FindStringSubmatch(item); len(res) == 3 { + name = res[1] + url = res[2] + } else if strings.HasPrefix(item, "http") { + url = item + } else { + name = item + } + if app.Spec.Destination.Server != "" && app.Spec.Destination.Server != url { + return false + } else if app.Spec.Destination.Name != "" && app.Spec.Destination.Name != name { + return false + } + } } if len(q.GetNamespaces()) > 0 && !sets.NewString(q.GetNamespaces()...).Has(app.Spec.Destination.Namespace) { diff --git a/ui/src/app/applications/components/applications-list/applications-list.tsx b/ui/src/app/applications/components/applications-list/applications-list.tsx index ec380656efa3c..7b18fab436151 100644 --- a/ui/src/app/applications/components/applications-list/applications-list.tsx +++ b/ui/src/app/applications/components/applications-list/applications-list.tsx @@ -336,16 +336,7 @@ const prefsToQuery = (prefs: AppsListPreferences & {page: number; pageSize: numb query.namespaces = prefs.namespacesFilter; } if (prefs.clustersFilter) { - query.clusters = prefs.clustersFilter - .map(item => { - const match = item.match('^(.*) [(](http.*)[)]$'); - if (match?.length === 3) { - return match[2]; - } - const urlMatch = item.match('^http.*$'); - return urlMatch && urlMatch[0]; - }) - .filter(item => !!item); + query.clusters = prefs.clustersFilter; } if (prefs.autoSyncFilter?.length > 0) { query.autoSyncEnabled = prefs.autoSyncFilter.findIndex(item => item === 'Enabled') > -1; @@ -374,11 +365,12 @@ export const ApplicationsList = (props: RouteComponentProps<{}>) => { // app refreshing might be done too quickly so that UI might miss it due to event batching // add refreshing annotation in the UI to improve user experience if (loaderRef.current) { - const applications = loaderRef.current.getData() as models.Application[]; + const data = loaderRef.current.getData() as {applications: models.Application[]; stats: models.ApplicationListStats}; + const applications = data.applications.slice(); const app = applications.find(item => item.metadata.name === appName && item.metadata.namespace === appNamespace); if (app) { AppUtils.setAppRefreshing(app); - loaderRef.current.setData(applications); + loaderRef.current.setData({...data, applications}); } } services.applications.get(appName, appNamespace, 'normal');