Skip to content

Modern Docker Management, Designed for Everyone

chore: simplify filter logic

Kyle Mendelld7b75cb38228
diff --git a/backend/internal/utils/pagination/filters.go b/backend/internal/utils/pagination/filters.go
index 72c0bc390..69868d1bf 100644
--- a/backend/internal/utils/pagination/filters.go
+++ b/backend/internal/utils/pagination/filters.go
@@ -43,41 +43,46 @@ func filterFn[T any](items []T, filters map[string]string, accessors []FilterAcc
results := []T{}
for _, item := range items {
- matches := true
- for key, value := range filters {
- found := false
- for _, accessor := range accessors {
- if accessor.Key == key {
- 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
- break
- }
- }
- if !found {
- matches = false
- }
- if !matches {
- break
- }
- }
- if matches {
+ if itemMatches(item, filters, accessors) {
results = append(results, item)
}
}
return results
}
+
+func itemMatches[T any](item T, filters map[string]string, accessors []FilterAccessor[T]) bool {
+ for key, value := range filters {
+ accessor := getAccessor(key, accessors)
+ if accessor == nil {
+ return false
+ }
+
+ if !matchValue(item, value, accessor) {
+ return false
+ }
+ }
+ return true
+}
+
+func getAccessor[T any](key string, accessors []FilterAccessor[T]) *FilterAccessor[T] {
+ for i := range accessors {
+ if accessors[i].Key == key {
+ return &accessors[i]
+ }
+ }
+ return nil
+}
+
+func matchValue[T any](item T, value string, accessor *FilterAccessor[T]) bool {
+ if strings.Contains(value, ",") {
+ values := strings.Split(value, ",")
+ for _, v := range values {
+ v = strings.TrimSpace(v)
+ if accessor.Fn(item, v) {
+ return true
+ }
+ }
+ return false
+ }
+ return accessor.Fn(item, value)
+}
diff --git a/frontend/src/routes/(app)/containers/container-table.svelte b/frontend/src/routes/(app)/containers/container-table.svelte
index c893c3d0d..ae390506f 100644
--- a/frontend/src/routes/(app)/containers/container-table.svelte
+++ b/frontend/src/routes/(app)/containers/container-table.svelte
@@ -81,6 +81,13 @@
return { repo: imageRef, tag: 'latest' };
}
+ function getContainerDisplayName(container: ContainerSummaryDto): string {
+ if (container.names && container.names.length > 0) {
+ return container.names[0].replace(/^\//, '');
+ }
+ return container.id.substring(0, 12);
+ }
+
function getActionStatusMessage(status: ActionStatus): string {
const messages: Record<ActionStatus, () => string> = {
starting: () => m.common_action_starting(),
@@ -154,10 +161,10 @@
}
}
- async function handleRemoveContainer(id: string) {
+ async function handleRemoveContainer(id: string, name: string) {
openConfirmDialog({
title: m.containers_remove_confirm_title(),
- message: m.containers_remove_confirm_message(),
+ message: m.containers_remove_confirm_message({ resource: name }),
checkboxes: [
{
id: 'force',
@@ -194,7 +201,7 @@
}
async function handleUpdateContainer(container: ContainerSummaryDto) {
- const containerName = container.names?.[0]?.replace(/^\//, '') || container.id.substring(0, 12);
+ const containerName = getContainerDisplayName(container);
openConfirmDialog({
title: m.containers_update_confirm_title(),
@@ -681,7 +688,7 @@
<DropdownMenu.Item
variant="destructive"
- onclick={() => handleRemoveContainer(item.id)}
+ onclick={() => handleRemoveContainer(item.id, getContainerDisplayName(item))}
disabled={status === 'removing' || isAnyLoading}
>
{#if status === 'removing'}