Skip to content

Commit

Permalink
fix: fix cluster filtering and refresh button on application list page
Browse files Browse the repository at this point in the history
Signed-off-by: Alexander Matyushentsev <[email protected]>
  • Loading branch information
alexmt committed Aug 24, 2023
1 parent acaae15 commit 444be23
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 17 deletions.
28 changes: 23 additions & 5 deletions server/application/application.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"fmt"
"math"
"reflect"
"regexp"
"sort"
"strconv"
"strings"
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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');
Expand Down

0 comments on commit 444be23

Please sign in to comment.