Skip to content

Modern Docker Management, Designed for Everyone

feat: project status filter selector (#1484)

Kyle Mendell90932df46841
diff --git a/backend/internal/huma/handlers/projects.go b/backend/internal/huma/handlers/projects.go
index f3d8217be..7b8ea6437 100644
--- a/backend/internal/huma/handlers/projects.go
+++ b/backend/internal/huma/handlers/projects.go
@@ -41,6 +41,7 @@ type ListProjectsInput struct {
Order string `query:"order" default:"asc" doc:"Sort direction (asc or desc)"`
Start int `query:"start" default:"0" doc:"Start index for pagination"`
Limit int `query:"limit" default:"20" doc:"Number of items per page"`
+ Status string `query:"status" doc:"Filter by status (comma-separated: running,stopped,partially running)"`
}
type ListProjectsOutput struct {
@@ -338,6 +339,9 @@ func (h *ProjectHandler) ListProjects(ctx context.Context, input *ListProjectsIn
Start: input.Start,
Limit: input.Limit,
},
+ Filters: map[string]string{
+ "status": input.Status,
+ },
}
projects, paginationResp, err := h.projectService.ListProjects(ctx, params)
diff --git a/backend/internal/services/project_service.go b/backend/internal/services/project_service.go
index e0f4058e1..4acb0a8cd 100644
--- a/backend/internal/services/project_service.go
+++ b/backend/internal/services/project_service.go
@@ -1226,6 +1226,114 @@ func (s *ProjectService) StreamProjectLogs(ctx context.Context, projectID string
func (s *ProjectService) ListProjects(ctx context.Context, params pagination.QueryParams) ([]project.Details, pagination.Response, error) {
var projectsArray []models.Project
query := s.db.WithContext(ctx).Model(&models.Project{})
+ statusFilter := ""
+ if params.Filters != nil {
+ statusFilter = strings.TrimSpace(params.Filters["status"])
+ }
+ if statusFilter != "" {
+ if term := strings.TrimSpace(params.Search); term != "" {
+ searchPattern := "%" + term + "%"
+ query = query.Where(
+ "name LIKE ? OR path LIKE ? OR status LIKE ? OR COALESCE(dir_name, '') LIKE ?",
+ searchPattern, searchPattern, searchPattern, searchPattern,
+ )
+ }
+ if err := query.Find(&projectsArray).Error; err != nil {
+ return nil, pagination.Response{}, fmt.Errorf("failed to list projects: %w", err)
+ }
+
+ items := s.fetchProjectStatusConcurrently(ctx, projectsArray)
+
+ limit := params.Limit
+ if limit <= 0 {
+ limit = 20
+ } else if limit > 100 {
+ limit = 100
+ }
+ params.Limit = limit
+
+ config := pagination.Config[project.Details]{
+ SearchAccessors: []pagination.SearchAccessor[project.Details]{
+ func(p project.Details) (string, error) { return p.Name, nil },
+ func(p project.Details) (string, error) { return p.Path, nil },
+ func(p project.Details) (string, error) { return p.Status, nil },
+ func(p project.Details) (string, error) { return p.DirName, nil },
+ },
+ SortBindings: []pagination.SortBinding[project.Details]{
+ {
+ Key: "name",
+ Fn: func(a, b project.Details) int {
+ return strings.Compare(a.Name, b.Name)
+ },
+ },
+ {
+ Key: "status",
+ Fn: func(a, b project.Details) int {
+ return strings.Compare(a.Status, b.Status)
+ },
+ },
+ {
+ Key: "serviceCount",
+ Fn: func(a, b project.Details) int {
+ if a.ServiceCount < b.ServiceCount {
+ return -1
+ }
+ if a.ServiceCount > b.ServiceCount {
+ return 1
+ }
+ return 0
+ },
+ },
+ {
+ Key: "createdAt",
+ Fn: func(a, b project.Details) int {
+ at, aerr := time.Parse(time.RFC3339, a.CreatedAt)
+ bt, berr := time.Parse(time.RFC3339, b.CreatedAt)
+ if aerr != nil || berr != nil {
+ return strings.Compare(a.CreatedAt, b.CreatedAt)
+ }
+ if at.Before(bt) {
+ return -1
+ }
+ if at.After(bt) {
+ return 1
+ }
+ return 0
+ },
+ },
+ },
+ FilterAccessors: []pagination.FilterAccessor[project.Details]{
+ {
+ Key: "status",
+ Fn: func(p project.Details, filterValue string) bool {
+ return strings.EqualFold(strings.TrimSpace(p.Status), strings.TrimSpace(filterValue))
+ },
+ },
+ },
+ }
+
+ result := pagination.SearchOrderAndPaginate(items, params, config)
+
+ totalPages := int64(0)
+ if params.Limit > 0 {
+ totalPages = (int64(result.TotalCount) + int64(params.Limit) - 1) / int64(params.Limit)
+ }
+
+ page := 1
+ if params.Limit > 0 {
+ page = (params.Start / params.Limit) + 1
+ }
+
+ paginationResp := pagination.Response{
+ TotalPages: totalPages,
+ TotalItems: int64(result.TotalCount),
+ CurrentPage: page,
+ ItemsPerPage: params.Limit,
+ GrandTotalItems: int64(result.TotalAvailable),
+ }
+
+ return result.Items, paginationResp, nil
+ }
if term := strings.TrimSpace(params.Search); term != "" {
searchPattern := "%" + term + "%"
@@ -1235,6 +1343,8 @@ func (s *ProjectService) ListProjects(ctx context.Context, params pagination.Que
)
}
+ query = pagination.ApplyFilter(query, "status", params.Filters["status"])
+
paginationResp, err := pagination.PaginateAndSortDB(params, query, &projectsArray)
if err != nil {
return nil, pagination.Response{}, fmt.Errorf("failed to paginate projects: %w", err)
diff --git a/frontend/messages/en.json b/frontend/messages/en.json
index e04605a6d..a0c3ae099 100644
--- a/frontend/messages/en.json
+++ b/frontend/messages/en.json
@@ -666,6 +666,7 @@
"projects_col_provider": "Provider",
"projects_provider_local": "Local",
"projects_provider_git": "Git",
+ "projects_status_partial": "Partially Running",
"compose_subtitle": "View and Manage Compose Projects",
"compose_services": "Services",
"compose_services_description": "Docker Compose services and their current status",
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 49b0a046b..7dd98f3f4 100644
--- a/frontend/src/lib/components/arcane-table/arcane-table-toolbar.svelte
+++ b/frontend/src/lib/components/arcane-table/arcane-table-toolbar.svelte
@@ -2,7 +2,7 @@
import type { Table } from '@tanstack/table-core';
import { DataTableFacetedFilter, DataTableViewOptions } from './index.js';
import { Input } from '$lib/components/ui/input/index.js';
- import { imageUpdateFilters, usageFilters, severityFilters, templateTypeFilters } from './data.js';
+ import { imageUpdateFilters, usageFilters, severityFilters, templateTypeFilters, projectStatusFilters } from './data.js';
import { debounced } from '$lib/utils/utils.js';
import { ArcaneButton } from '$lib/components/arcane-button';
import { m } from '$lib/paraglide/messages';
@@ -39,6 +39,10 @@
const severityColumn = $derived(
table.getAllColumns().some((col) => col.id === 'severity') ? table.getColumn('severity') : undefined
);
+ const statusColumn = $derived(table.getAllColumns().some((col) => col.id === 'status') ? table.getColumn('status') : undefined);
+ const serviceCountColumn = $derived(
+ table.getAllColumns().some((col) => col.id === 'serviceCount') ? table.getColumn('serviceCount') : undefined
+ );
const typeColumn = $derived(table.getAllColumns().some((col) => col.id === 'type') ? table.getColumn('type') : undefined);
const debouncedSetGlobal = debounced((v: string) => table.setGlobalFilter(v), 300);
@@ -83,6 +87,9 @@
{#if severityColumn}
<DataTableFacetedFilter column={severityColumn} title={m.events_col_severity()} options={severityFilters} />
{/if}
+ {#if statusColumn && serviceCountColumn}
+ <DataTableFacetedFilter column={statusColumn} title={m.common_status()} options={projectStatusFilters} />
+ {/if}
{#if isFiltered}
<ArcaneButton
@@ -107,7 +114,7 @@
{#if hasSelection}
{#if hasBulkActions}
<div class="flex flex-wrap items-center gap-2">
- {#each bulkActions as bulkAction}
+ {#each bulkActions as bulkAction (bulkAction.id)}
{@const actionType = bulkAction.action === 'up' ? 'start' : bulkAction.action === 'down' ? 'stop' : bulkAction.action}
<ArcaneButton
action={actionType}
diff --git a/frontend/src/lib/components/arcane-table/data.ts b/frontend/src/lib/components/arcane-table/data.ts
index 9a063ee42..bff9f7d37 100644
--- a/frontend/src/lib/components/arcane-table/data.ts
+++ b/frontend/src/lib/components/arcane-table/data.ts
@@ -1,5 +1,16 @@
import { m } from '$lib/paraglide/messages';
-import { GlobeIcon, FolderOpenIcon, VerifiedCheckIcon, AlertIcon, InfoIcon, CloseIcon, CheckIcon, UpdateIcon } from '$lib/icons';
+import {
+ GlobeIcon,
+ FolderOpenIcon,
+ VerifiedCheckIcon,
+ AlertIcon,
+ InfoIcon,
+ CloseIcon,
+ CheckIcon,
+ UpdateIcon,
+ StartIcon,
+ StopIcon
+} from '$lib/icons';
export const usageFilters = [
{
@@ -62,3 +73,26 @@ export const templateTypeFilters = [
icon: GlobeIcon
}
];
+
+export const projectStatusFilters = [
+ {
+ value: 'running',
+ label: m.common_running(),
+ icon: StartIcon
+ },
+ {
+ value: 'stopped',
+ label: m.common_stopped(),
+ icon: StopIcon
+ },
+ {
+ value: 'partially running',
+ label: m.projects_status_partial(),
+ icon: AlertIcon
+ },
+ {
+ value: 'unknown',
+ label: m.common_unknown(),
+ icon: InfoIcon
+ }
+];