Skip to content

Modern Docker Management, Designed for Everyone

fix: resources not respecting multiple filters (#1391)

Kyle Mendell07eb0ff63716
diff --git a/backend/internal/services/container_registry_service.go b/backend/internal/services/container_registry_service.go
index 115209597..ed0ee5646 100644
--- a/backend/internal/services/container_registry_service.go
+++ b/backend/internal/services/container_registry_service.go
@@ -73,23 +73,8 @@ func (s *ContainerRegistryService) GetRegistriesPaginated(ctx context.Context, p
)
}
- if enabled := params.Filters["enabled"]; enabled != "" {
- switch enabled {
- case "true", "1":
- q = q.Where("enabled = ?", true)
- case "false", "0":
- q = q.Where("enabled = ?", false)
- }
- }
-
- if insecure := params.Filters["insecure"]; insecure != "" {
- switch insecure {
- case "true", "1":
- q = q.Where("insecure = ?", true)
- case "false", "0":
- q = q.Where("insecure = ?", false)
- }
- }
+ q = pagination.ApplyBooleanFilter(q, "enabled", params.Filters["enabled"])
+ q = pagination.ApplyBooleanFilter(q, "insecure", params.Filters["insecure"])
paginationResp, err := pagination.PaginateAndSortDB(params, q, &registries)
if err != nil {
diff --git a/backend/internal/services/environment_service.go b/backend/internal/services/environment_service.go
index 74ce47ffe..d53369f21 100644
--- a/backend/internal/services/environment_service.go
+++ b/backend/internal/services/environment_service.go
@@ -126,17 +126,8 @@ func (s *EnvironmentService) ListEnvironmentsPaginated(ctx context.Context, para
)
}
- if status := params.Filters["status"]; status != "" {
- q = q.Where("status = ?", status)
- }
- if enabled := params.Filters["enabled"]; enabled != "" {
- switch enabled {
- case "true", "1":
- q = q.Where("enabled = ?", true)
- case "false", "0":
- q = q.Where("enabled = ?", false)
- }
- }
+ q = pagination.ApplyFilter(q, "status", params.Filters["status"])
+ q = pagination.ApplyBooleanFilter(q, "enabled", params.Filters["enabled"])
paginationResp, err := pagination.PaginateAndSortDB(params, q, &envs)
if err != nil {
diff --git a/backend/internal/services/event_service.go b/backend/internal/services/event_service.go
index 8c10c6c13..22a7cbd6b 100644
--- a/backend/internal/services/event_service.go
+++ b/backend/internal/services/event_service.go
@@ -122,21 +122,11 @@ func (s *EventService) ListEventsPaginated(ctx context.Context, params paginatio
)
}
- if severity := params.Filters["severity"]; severity != "" {
- q = q.Where("severity = ?", severity)
- }
- if eventType := params.Filters["type"]; eventType != "" {
- q = q.Where("type = ?", eventType)
- }
- if resourceType := params.Filters["resourceType"]; resourceType != "" {
- q = q.Where("resource_type = ?", resourceType)
- }
- if username := params.Filters["username"]; username != "" {
- q = q.Where("username = ?", username)
- }
- if environmentId := params.Filters["environmentId"]; environmentId != "" {
- q = q.Where("environment_id = ?", environmentId)
- }
+ q = pagination.ApplyFilter(q, "severity", params.Filters["severity"])
+ q = pagination.ApplyFilter(q, "type", params.Filters["type"])
+ q = pagination.ApplyFilter(q, "resource_type", params.Filters["resourceType"])
+ q = pagination.ApplyFilter(q, "username", params.Filters["username"])
+ q = pagination.ApplyFilter(q, "environment_id", params.Filters["environmentId"])
paginationResp, err := pagination.PaginateAndSortDB(params, q, &events)
if err != nil {
@@ -163,18 +153,10 @@ func (s *EventService) GetEventsByEnvironmentPaginated(ctx context.Context, envi
)
}
- if severity := params.Filters["severity"]; severity != "" {
- q = q.Where("severity = ?", severity)
- }
- if eventType := params.Filters["type"]; eventType != "" {
- q = q.Where("type = ?", eventType)
- }
- if resourceType := params.Filters["resourceType"]; resourceType != "" {
- q = q.Where("resource_type = ?", resourceType)
- }
- if username := params.Filters["username"]; username != "" {
- q = q.Where("username = ?", username)
- }
+ q = pagination.ApplyFilter(q, "severity", params.Filters["severity"])
+ q = pagination.ApplyFilter(q, "type", params.Filters["type"])
+ q = pagination.ApplyFilter(q, "resource_type", params.Filters["resourceType"])
+ q = pagination.ApplyFilter(q, "username", params.Filters["username"])
paginationResp, err := pagination.PaginateAndSortDB(params, q, &events)
if err != nil {
diff --git a/backend/internal/services/git_repository_service.go b/backend/internal/services/git_repository_service.go
index 6b2f7b618..257e8e62e 100644
--- a/backend/internal/services/git_repository_service.go
+++ b/backend/internal/services/git_repository_service.go
@@ -42,18 +42,8 @@ func (s *GitRepositoryService) GetRepositoriesPaginated(ctx context.Context, par
)
}
- if enabled := params.Filters["enabled"]; enabled != "" {
- switch enabled {
- case "true", "1":
- q = q.Where("enabled = ?", true)
- case "false", "0":
- q = q.Where("enabled = ?", false)
- }
- }
-
- if authType := params.Filters["authType"]; authType != "" {
- q = q.Where("auth_type = ?", authType)
- }
+ q = pagination.ApplyBooleanFilter(q, "enabled", params.Filters["enabled"])
+ q = pagination.ApplyFilter(q, "auth_type", params.Filters["authType"])
paginationResp, err := pagination.PaginateAndSortDB(params, q, &repositories)
if err != nil {
diff --git a/backend/internal/services/gitops_sync_service.go b/backend/internal/services/gitops_sync_service.go
index 51edbf49a..4b848b047 100644
--- a/backend/internal/services/gitops_sync_service.go
+++ b/backend/internal/services/gitops_sync_service.go
@@ -45,31 +45,11 @@ func (s *GitOpsSyncService) GetSyncsPaginated(ctx context.Context, environmentID
)
}
- if enabled := params.Filters["enabled"]; enabled != "" {
- switch enabled {
- case "true", "1":
- q = q.Where("enabled = ?", true)
- case "false", "0":
- q = q.Where("enabled = ?", false)
- }
- }
-
- if autoSync := params.Filters["autoSync"]; autoSync != "" {
- switch autoSync {
- case "true", "1":
- q = q.Where("auto_sync = ?", true)
- case "false", "0":
- q = q.Where("auto_sync = ?", false)
- }
- }
-
- if repositoryID := params.Filters["repositoryId"]; repositoryID != "" {
- q = q.Where("repository_id = ?", repositoryID)
- }
+ q = pagination.ApplyBooleanFilter(q, "enabled", params.Filters["enabled"])
+ q = pagination.ApplyBooleanFilter(q, "auto_sync", params.Filters["autoSync"])
- if projectID := params.Filters["projectId"]; projectID != "" {
- q = q.Where("project_id = ?", projectID)
- }
+ q = pagination.ApplyFilter(q, "repository_id", params.Filters["repositoryId"])
+ q = pagination.ApplyFilter(q, "project_id", params.Filters["projectId"])
paginationResp, err := pagination.PaginateAndSortDB(params, q, &syncs)
if err != nil {
diff --git a/backend/internal/utils/pagination/db_utils.go b/backend/internal/utils/pagination/db_utils.go
new file mode 100644
index 000000000..253474fd7
--- /dev/null
+++ b/backend/internal/utils/pagination/db_utils.go
@@ -0,0 +1,52 @@
+package pagination
+
+import (
+ "strings"
+
+ "gorm.io/gorm"
+)
+
+// ApplyFilter adds a WHERE clause to the GORM query.
+// It detects comma-separated values and uses IN (?) for multiple values,
+// or = ? for single values.
+func ApplyFilter(q *gorm.DB, column string, value string) *gorm.DB {
+ if value == "" {
+ return q
+ }
+ if strings.Contains(value, ",") {
+ values := strings.Split(value, ",")
+ for i := range values {
+ values[i] = strings.TrimSpace(values[i])
+ }
+ return q.Where(column+" IN ?", values)
+ }
+ return q.Where(column+" = ?", value)
+}
+
+// ApplyBooleanFilter adds a WHERE clause for boolean columns.
+// It detects comma-separated values and maps "true"/"1" to true and "false"/"0" to false.
+func ApplyBooleanFilter(q *gorm.DB, column string, value string) *gorm.DB {
+ if value == "" {
+ return q
+ }
+
+ parts := strings.Split(value, ",")
+ var boolValues []bool
+
+ for _, part := range parts {
+ switch strings.TrimSpace(part) {
+ case "true", "1":
+ boolValues = append(boolValues, true)
+ case "false", "0":
+ boolValues = append(boolValues, false)
+ }
+ }
+
+ if len(boolValues) == 1 {
+ return q.Where(column+" = ?", boolValues[0])
+ } else if len(boolValues) > 1 {
+ return q.Where(column+" IN ?", boolValues)
+ }
+
+ return q
+}
diff --git a/backend/internal/utils/pagination/filters.go b/backend/internal/utils/pagination/filters.go
index ee6d3a34a..72c0bc390 100644
--- a/backend/internal/utils/pagination/filters.go
+++ b/backend/internal/utils/pagination/filters.go
@@ -1,5 +1,7 @@
package pagination
+import "strings"
+
type FilterResult[T any] struct {
Items []T
TotalCount int64
@@ -46,7 +48,20 @@ func filterFn[T any](items []T, filters map[string]string, accessors []FilterAcc
found := false
for _, accessor := range accessors {
if accessor.Key == key {
- if !accessor.Fn(item, value) {
+ if strings.Contains(value, ",") {
+ values := strings.Split(value, ",")
+ anyMatch := false
+ for _, v := range values {
+ v = strings.TrimSpace(v) // Trim space just in case
+ if accessor.Fn(item, v) {
+ anyMatch = true
+ break
+ }
+ }
+ if !anyMatch {
+ matches = false
+ }
+ } else if !accessor.Fn(item, value) {
matches = false
}
found = true
diff --git a/frontend/src/lib/components/arcane-table/arcane-table-filter.svelte b/frontend/src/lib/components/arcane-table/arcane-table-filter.svelte
index 41d367205..49d90f277 100644
--- a/frontend/src/lib/components/arcane-table/arcane-table-filter.svelte
+++ b/frontend/src/lib/components/arcane-table/arcane-table-filter.svelte
@@ -100,7 +100,7 @@
{#if selectedValues.size > 0}
<Command.Separator />
<Command.Group>
- <Command.Item onselect={() => column?.setFilterValue(undefined)} class="justify-center text-center">
+ <Command.Item onSelect={() => column?.setFilterValue(undefined)} class="justify-center text-center">
{m.common_clear_filters()}
</Command.Item>
</Command.Group>
diff --git a/frontend/src/lib/components/arcane-table/arcane-table-toolbar.svelte b/frontend/src/lib/components/arcane-table/arcane-table-toolbar.svelte
index d0cbba4b3..d3ace33be 100644
--- a/frontend/src/lib/components/arcane-table/arcane-table-toolbar.svelte
+++ b/frontend/src/lib/components/arcane-table/arcane-table-toolbar.svelte
@@ -90,8 +90,8 @@
icon={ResetIcon}
customLabel={m.common_reset()}
onclick={() => {
- table.resetColumnFilters();
- table.resetGlobalFilter();
+ table.setColumnFilters([]);
+ table.setGlobalFilter('');
}}
class="h-8 px-2 lg:px-3"
/>
diff --git a/frontend/src/lib/components/arcane-table/arcane-table.utils.ts b/frontend/src/lib/components/arcane-table/arcane-table.utils.ts
index ae46d0030..890368ae3 100644
--- a/frontend/src/lib/components/arcane-table/arcane-table.utils.ts
+++ b/frontend/src/lib/components/arcane-table/arcane-table.utils.ts
@@ -18,15 +18,15 @@ export function toFilterMap(filters: ColumnFiltersState): FilterMap {
for (const f of filters ?? []) {
const id = f.id;
let value: unknown = (f as any).value;
+
+ if (value instanceof Set) {
+ value = Array.from(value);
+ }
+
if (Array.isArray(value)) {
if (value.length === 0) continue;
- value = value[0];
- } else if (value && typeof value === 'object' && value instanceof Set) {
- const first = (value as Set<unknown>).values().next().value;
- if (first === undefined) continue;
- value = first;
- }
- if (value !== undefined && value !== null && String(value).trim() !== '') {
+ out[id] = value as any[];
+ } else if (value !== undefined && value !== null && String(value).trim() !== '') {
out[id] = value as any;
}
}