Modern Docker Management, Designed for Everyone
Go composecontainer-managementcontainersdockerdocker-composedocker-managementgoself-hostedsveltekittypescriptweb-ui
fix: git sync counts only showing paginated values
Kyle Mendellbe8b99b22013
diff --git a/backend/internal/huma/handlers/gitops_syncs.go b/backend/internal/huma/handlers/gitops_syncs.goindex 7f3fa2ff9..ad2ac89d4 100644--- a/backend/internal/huma/handlers/gitops_syncs.go+++ b/backend/internal/huma/handlers/gitops_syncs.go@@ -25,6 +25,7 @@ type GitOpsSyncHandler struct {type GitOpsSyncPaginatedResponse struct {Success bool `json:"success"`Data []gitops.GitOpsSync `json:"data"`+ Counts gitops.SyncCounts `json:"counts"`Pagination base.PaginationResponse `json:"pagination"`}@@ -253,7 +254,7 @@ func (h *GitOpsSyncHandler) ListSyncs(ctx context.Context, input *ListGitOpsSyncparams := buildPaginationParams(0, input.Start, input.Limit, input.Sort, input.Order, input.Search)- syncs, paginationResp, err := h.syncService.GetSyncsPaginated(ctx, input.EnvironmentID, params)+ syncs, paginationResp, counts, err := h.syncService.GetSyncsPaginated(ctx, input.EnvironmentID, params)if err != nil {return nil, huma.Error500InternalServerError((&common.GitOpsSyncListError{Err: err}).Error())}@@ -262,6 +263,7 @@ func (h *GitOpsSyncHandler) ListSyncs(ctx context.Context, input *ListGitOpsSyncBody: GitOpsSyncPaginatedResponse{Success: true,Data: syncs,+ Counts: counts,Pagination: base.PaginationResponse{TotalPages: paginationResp.TotalPages,TotalItems: paginationResp.TotalItems,diff --git a/backend/internal/services/gitops_sync_service.go b/backend/internal/services/gitops_sync_service.goindex a8b2b28cd..c30c68db0 100644--- a/backend/internal/services/gitops_sync_service.go+++ b/backend/internal/services/gitops_sync_service.go@@ -72,9 +72,9 @@ func (s *GitOpsSyncService) UpdateSyncIntervalMinutes(ctx context.Context, id stUpdate("sync_interval", minutes).Error}-func (s *GitOpsSyncService) GetSyncsPaginated(ctx context.Context, environmentID string, params pagination.QueryParams) ([]gitops.GitOpsSync, pagination.Response, error) {+func (s *GitOpsSyncService) GetSyncsPaginated(ctx context.Context, environmentID string, params pagination.QueryParams) ([]gitops.GitOpsSync, pagination.Response, gitops.SyncCounts, error) {var syncs []models.GitOpsSync- q := s.db.WithContext(ctx).Model(&models.GitOpsSync{}).Preload("Repository").Preload("Project").+ q := s.db.WithContext(ctx).Model(&models.GitOpsSync{}).Where("environment_id = ?", environmentID)if term := strings.TrimSpace(params.Search); term != "" {@@ -90,17 +90,45 @@ func (s *GitOpsSyncService) GetSyncsPaginated(ctx context.Context, environmentIDq = pagination.ApplyFilter(q, "repository_id", params.Filters["repositoryId"])q = pagination.ApplyFilter(q, "project_id", params.Filters["projectId"])- paginationResp, err := pagination.PaginateAndSortDB(params, q, &syncs)+ counts, err := s.getFilteredSyncCounts(q)if err != nil {- return nil, pagination.Response{}, fmt.Errorf("failed to paginate gitops syncs: %w", err)+ return nil, pagination.Response{}, gitops.SyncCounts{}, fmt.Errorf("failed to get sync counts: %w", err)+ }++ paginationResp, err := pagination.PaginateAndSortDB(params, q.Preload("Repository").Preload("Project"), &syncs)+ if err != nil {+ return nil, pagination.Response{}, gitops.SyncCounts{}, fmt.Errorf("failed to paginate gitops syncs: %w", err)}out, mapErr := mapper.MapSlice[models.GitOpsSync, gitops.GitOpsSync](syncs)if mapErr != nil {- return nil, pagination.Response{}, fmt.Errorf("failed to map syncs: %w", mapErr)+ return nil, pagination.Response{}, gitops.SyncCounts{}, fmt.Errorf("failed to map syncs: %w", mapErr)+ }++ return out, paginationResp, counts, nil+}++func (s *GitOpsSyncService) getFilteredSyncCounts(query *gorm.DB) (gitops.SyncCounts, error) {+ var totalSyncs int64+ if err := query.Session(&gorm.Session{}).Count(&totalSyncs).Error; err != nil {+ return gitops.SyncCounts{}, err+ }++ var activeSyncs int64+ if err := query.Session(&gorm.Session{}).Where("auto_sync = ?", true).Count(&activeSyncs).Error; err != nil {+ return gitops.SyncCounts{}, err}- return out, paginationResp, nil+ var successfulSyncs int64+ if err := query.Session(&gorm.Session{}).Where("last_sync_status = ?", "success").Count(&successfulSyncs).Error; err != nil {+ return gitops.SyncCounts{}, err+ }++ return gitops.SyncCounts{+ TotalSyncs: int(totalSyncs),+ ActiveSyncs: int(activeSyncs),+ SuccessfulSyncs: int(successfulSyncs),+ }, nil}func (s *GitOpsSyncService) GetSyncByID(ctx context.Context, environmentID, id string) (*models.GitOpsSync, error) {diff --git a/frontend/src/lib/services/gitops-sync-service.ts b/frontend/src/lib/services/gitops-sync-service.tsindex c79be22f8..5a4b7b927 100644--- a/frontend/src/lib/services/gitops-sync-service.ts+++ b/frontend/src/lib/services/gitops-sync-service.ts@@ -3,6 +3,7 @@ import type {GitOpsSyncCreateDto,GitOpsSyncUpdateDto,GitOpsSync,+ GitOpsSyncCounts,SyncResult,SyncStatus,BrowseResponse,@@ -13,7 +14,7 @@ import type { Paginated, SearchPaginationSortRequest } from '$lib/types/paginatiimport { transformPaginationParams } from '$lib/utils/params.util';export default class GitOpsSyncService extends BaseAPIService {- async getSyncs(environmentId: string, options?: SearchPaginationSortRequest): Promise<Paginated<GitOpsSync>> {+ async getSyncs(environmentId: string, options?: SearchPaginationSortRequest): Promise<Paginated<GitOpsSync, GitOpsSyncCounts>> {const params = transformPaginationParams(options);const res = await this.api.get(`/environments/${environmentId}/gitops-syncs`, { params });return res.data;diff --git a/frontend/src/lib/types/gitops.type.ts b/frontend/src/lib/types/gitops.type.tsindex c8e4077be..e5302a91e 100644--- a/frontend/src/lib/types/gitops.type.ts+++ b/frontend/src/lib/types/gitops.type.ts@@ -75,6 +75,12 @@ export interface GitOpsSync {updatedAt: string;}+export interface GitOpsSyncCounts {+ totalSyncs: number;+ activeSyncs: number;+ successfulSyncs: number;+}+export interface SyncResult {success: boolean;message: string;diff --git a/frontend/src/routes/(app)/environments/[id]/gitops/+page.svelte b/frontend/src/routes/(app)/environments/[id]/gitops/+page.svelteindex 1186cf817..726b9cc00 100644--- a/frontend/src/routes/(app)/environments/[id]/gitops/+page.svelte+++ b/frontend/src/routes/(app)/environments/[id]/gitops/+page.svelte@@ -1,6 +1,12 @@<script lang="ts">import { toast } from 'svelte-sonner';- import type { GitOpsSync, GitOpsSyncCreateDto, GitOpsSyncUpdateDto, ImportGitOpsSyncRequest } from '$lib/types/gitops.type';+ import type {+ GitOpsSync,+ GitOpsSyncCounts,+ GitOpsSyncCreateDto,+ GitOpsSyncUpdateDto,+ ImportGitOpsSyncRequest+ } from '$lib/types/gitops.type';import GitOpsSyncFormSheet from '$lib/components/dialogs/gitops-sync-dialog.svelte';import GitOpsImportDialog from '$lib/components/dialogs/gitops-import-dialog.svelte';import { handleApiResultWithCallbacks } from '$lib/utils/api.util';@@ -31,8 +37,12 @@import: false});- const activeSyncs = $derived(syncs.data?.filter((s) => s.autoSync).length ?? 0);- const successfulSyncs = $derived(syncs.data?.filter((s) => s.lastSyncStatus === 'success').length ?? 0);+ const syncCountsFallback: GitOpsSyncCounts = {+ totalSyncs: 0,+ activeSyncs: 0,+ successfulSyncs: 0+ };+ const syncCounts = $derived(syncs?.counts ?? syncCountsFallback);$effect(() => {if (page.url.searchParams.get('action') === 'create') {@@ -162,21 +172,21 @@const statCards = $derived<StatCardConfig[]>([{title: m.common_total(),- value: syncs?.pagination?.totalItems ?? 0,+ value: syncCounts.totalSyncs,icon: RefreshIcon,iconColor: 'text-blue-500',bgColor: 'bg-blue-500/10'},{title: m.common_active(),- value: activeSyncs,+ value: syncCounts.activeSyncs,icon: ClockIcon,iconColor: 'text-purple-500',bgColor: 'bg-purple-500/10'},{title: m.common_successful(),- value: successfulSyncs,+ value: syncCounts.successfulSyncs,icon: SuccessIcon,iconColor: 'text-green-500',bgColor: 'bg-green-500/10'diff --git a/types/gitops/gitops.go b/types/gitops/gitops.goindex 871e64c3b..b18d1cfbd 100644--- a/types/gitops/gitops.go+++ b/types/gitops/gitops.go@@ -143,6 +143,24 @@ type GitOpsSync struct {UpdatedAt time.Time `json:"updatedAt"`}+// SyncCounts contains counts of syncs by status within the current filtered set.+type SyncCounts struct {+ // TotalSyncs is the total number of syncs in the current filtered set.+ //+ // Required: true+ TotalSyncs int `json:"totalSyncs"`++ // ActiveSyncs is the number of auto-sync enabled syncs in the current filtered set.+ //+ // Required: true+ ActiveSyncs int `json:"activeSyncs"`++ // SuccessfulSyncs is the number of syncs with last status "success" in the current filtered set.+ //+ // Required: true+ SuccessfulSyncs int `json:"successfulSyncs"`+}+// CreateRepositoryRequest represents the request to create a git repository.type CreateRepositoryRequest struct {// Name of the git repository.