Modern Docker Management, Designed for Everyone
Go composecontainer-managementcontainersdockerdocker-composedocker-managementgoself-hostedsveltekittypescriptweb-ui
fix: image update item not retreving the correct update data
Kyle Mendelld6c449cabae6
diff --git a/backend/internal/services/image_update_service.go b/backend/internal/services/image_update_service.goindex ae8ae194e..cca9feec4 100644--- a/backend/internal/services/image_update_service.go+++ b/backend/internal/services/image_update_service.go@@ -754,6 +754,31 @@ func (s *ImageUpdateService) saveUpdateResult(ctx context.Context, imageRef stri}func (s *ImageUpdateService) saveUpdateResultByID(ctx context.Context, imageID string, result *dto.ImageUpdateResponse) error {+ dockerClient, err := s.dockerService.CreateConnection(ctx)+ if err != nil {+ return fmt.Errorf("failed to connect to Docker: %w", err)+ }+ defer dockerClient.Close()++ dockerImage, err := dockerClient.ImageInspect(ctx, imageID)+ if err != nil {+ return fmt.Errorf("failed to inspect image: %w", err)+ }++ var repo, tag string+ if len(dockerImage.RepoTags) > 0 && dockerImage.RepoTags[0] != "<none>:<none>" {+ parts := strings.SplitN(dockerImage.RepoTags[0], ":", 2)+ repo = parts[0]+ if len(parts) > 1 {+ tag = parts[1]+ } else {+ tag = "latest"+ }+ } else {+ repo = "<none>"+ tag = "<none>"+ }+var lastError *stringif result.Error != "" {lastError = &result.Error@@ -771,14 +796,9 @@ func (s *ImageUpdateService) saveUpdateResultByID(ctx context.Context, imageID slatestDigest = &result.LatestDigest}- var image models.Image- if err := s.db.WithContext(ctx).Where("id = ?", imageID).First(&image).Error; err != nil {- return fmt.Errorf("image not found: %w", err)- }-currentVersion := result.CurrentVersionif currentVersion == "" {- currentVersion = image.Tag+ currentVersion = tag}var authMethod, authUsername, authRegistry *string@@ -794,8 +814,8 @@ func (s *ImageUpdateService) saveUpdateResultByID(ctx context.Context, imageID supdateRecord := &models.ImageUpdateRecord{ID: imageID,- Repository: image.Repo,- Tag: image.Tag,+ Repository: repo,+ Tag: tag,HasUpdate: result.HasUpdate,UpdateType: result.UpdateType,CurrentVersion: currentVersion,@@ -805,7 +825,6 @@ func (s *ImageUpdateService) saveUpdateResultByID(ctx context.Context, imageID sCheckTime: result.CheckTime,ResponseTimeMs: result.ResponseTimeMs,LastError: lastError,-AuthMethod: authMethod,AuthUsername: authUsername,AuthRegistry: authRegistry,diff --git a/frontend/src/lib/components/image-update-item.svelte b/frontend/src/lib/components/image-update-item.svelteindex f180c341a..68e088229 100644--- a/frontend/src/lib/components/image-update-item.svelte+++ b/frontend/src/lib/components/image-update-item.svelte@@ -93,12 +93,12 @@try {const result = await imageService.checkImageUpdateByID(imageId);if (result) {+ localUpdateInfo = result;+ onUpdated?.(result);+if (result.error) {- localUpdateInfo = result;toast.error(result.error || m.images_update_check_failed());} else {- localUpdateInfo = result;- onUpdated?.(result);toast.success(m.images_update_check_completed());}} else {@@ -106,7 +106,7 @@}} catch (error) {console.error('Error checking update:', error);- localUpdateInfo = {+ const errorInfo: ImageUpdateData = {hasUpdate: false,updateType: 'error',currentVersion: tag || '',@@ -117,7 +117,9 @@responseTimeMs: 0,error: (error as Error)?.message || m.images_update_check_failed()};- toast.error(localUpdateInfo?.error || m.images_update_check_failed());+ localUpdateInfo = errorInfo;+ onUpdated?.(errorInfo);+ toast.error(errorInfo.error);} finally {isChecking = false;}diff --git a/frontend/src/routes/images/+page.svelte b/frontend/src/routes/images/+page.svelteindex 338d66c75..d362da3cc 100644--- a/frontend/src/routes/images/+page.svelte+++ b/frontend/src/routes/images/+page.svelte@@ -158,7 +158,14 @@<ResourcePageLayout title={m.images_title()} subtitle={m.images_subtitle()} {actionButtons} {statCards} statCardsColumns={2}>{#snippet mainContent()}- <ImageTable bind:images bind:selectedIds bind:requestOptions />+ <ImageTable+ bind:images+ bind:selectedIds+ bind:requestOptions+ onImageUpdated={async () => {+ images = await imageService.getImages(requestOptions);+ }}+ />{/snippet}{#snippet additionalContent()}diff --git a/frontend/src/routes/images/image-table.svelte b/frontend/src/routes/images/image-table.svelteindex 2fd4eedde..432166fba 100644--- a/frontend/src/routes/images/image-table.svelte+++ b/frontend/src/routes/images/image-table.svelte@@ -17,7 +17,7 @@import { tryCatch } from '$lib/utils/try-catch';import ImageUpdateItem from '$lib/components/image-update-item.svelte';import type { Paginated, SearchPaginationSortRequest } from '$lib/types/pagination.type';- import type { ImageSummaryDto } from '$lib/types/image.type';+ import type { ImageSummaryDto, ImageUpdateInfoDto } from '$lib/types/image.type';import { format } from 'date-fns';import type { ColumnSpec } from '$lib/components/arcane-table';import { m } from '$lib/paraglide/messages';@@ -26,11 +26,13 @@let {images = $bindable(),selectedIds = $bindable(),- requestOptions = $bindable()+ requestOptions = $bindable(),+ onImageUpdated}: {images: Paginated<ImageSummaryDto>;selectedIds: string[];requestOptions: SearchPaginationSortRequest;+ onImageUpdated?: () => Promise<void>;} = $props();let isLoading = $state({@@ -149,6 +151,15 @@return { repo: repo || '<none>', tag: tag || '<none>' };}+ async function handleUpdateInfoChanged(imageId: string, newUpdateInfo: ImageUpdateInfoDto) {+ const imageIndex = images.data.findIndex((img) => img.id === imageId);+ if (imageIndex !== -1) {+ images.data[imageIndex].updateInfo = newUpdateInfo;+ images = { ...images, data: [...images.data] };+ }+ await onImageUpdated?.();+ }+const columns = [{ accessorKey: 'id', title: m.common_id(), hidden: true },{ accessorKey: 'repoTags', title: m.images_repository(), sortable: true, cell: RepoCell },@@ -158,26 +169,13 @@accessorKey: 'inUse',title: m.common_status(),sortable: true,- cell: StatusCell,- filterFn: (row, columnId, filterValue) => {- const selected = Array.isArray(filterValue) ? (filterValue as boolean[]) : [];- if (selected.length === 0) return true;- const value = Boolean(row.getValue<boolean>(columnId));- return selected.includes(value);- }+ cell: StatusCell},{id: 'updates',accessorFn: (row) => row.updateInfo?.hasUpdate ?? false,title: m.images_updates(),- cell: UpdatesCell,- filterFn: (row, columnId, filterValue) => {- const selected = Array.isArray(filterValue) ? (filterValue as boolean[]) : [];- if (selected.length === 0) return true;-- const hasUpdate = row.getValue(columnId) as boolean;- return selected.includes(hasUpdate);- }+ cell: UpdatesCell}] satisfies ColumnSpec<ImageSummaryDto>[];</script>@@ -208,7 +206,13 @@{#snippet UpdatesCell({ item }: { item: ImageSummaryDto })}{@const { repo, tag } = extractRepoAndTag(item.repoTags)}- <ImageUpdateItem updateInfo={item.updateInfo} imageId={item.id} {repo} {tag} />+ <ImageUpdateItem+ updateInfo={item.updateInfo}+ imageId={item.id}+ {repo}+ {tag}+ onUpdated={(newInfo) => handleUpdateInfoChanged(item.id, newInfo)}+ />{/snippet}{#snippet RowActions({ item }: { item: ImageSummaryDto })}