import {RefreshCw, Trash2} from 'lucide-react' import {useMutation, useQuery, useQueryClient} from '@tanstack/react-query' import {deleteFlatItem, listFlatItems} from '@/api/cloudProxyClient' import type {CloudResource} from '@/types/resource' interface EcrImageBrowserProps { resource?: CloudResource runtimeReachable: boolean } export function EcrImageBrowser({resource, runtimeReachable}: EcrImageBrowserProps) { const queryClient = useQueryClient() const imagesQuery = useQuery({ queryKey: ['ecr-images', resource?.id], queryFn: ({signal}) => listFlatItems('aws', 'ecr', resource?.id ?? '', undefined, signal), enabled: Boolean(resource) && runtimeReachable, }) const deleteMutation = useMutation({ mutationFn: (imageDigest: string) => deleteFlatItem('aws', 'ecr', resource?.id ?? '', imageDigest), onSuccess: () => queryClient.invalidateQueries({queryKey: ['ecr-images', resource?.id]}), }) if (!resource) { return

Select a repository

Choose an ECR repository to browse its images.

} const images = imagesQuery.data?.items ?? [] return (

Repository images

{images.length} images in {resource.name}
{imagesQuery.error instanceof Error &&

{imagesQuery.error.message}

} {imagesQuery.isLoading &&
Loading images
} {imagesQuery.isSuccess && images.length === 0 &&

No images

Push an image to this repository to see it here.

} {images.length > 0 &&
{images.map((image) => { const tags = Array.isArray(image.body.imageTags) ? image.body.imageTags.filter((tag): tag is string => typeof tag === 'string') : [] const size = typeof image.body.imageSizeInBytes === 'number' ? formatBytes(image.body.imageSizeInBytes) : '-' return })}
TagsDigestPushedSize
{tags.length ? tags.join(', ') : Untagged} {shortDigest(image.id)} {image.timestamp ? new Date(image.timestamp).toLocaleString() : '-'} {size}
}
) } function shortDigest(digest: string): string { return digest.length > 20 ? `${digest.slice(0, 19)}...` : digest } function formatBytes(bytes: number): string { if (bytes < 1024) return `${bytes} B` if (bytes < 1024 * 1024) return `${(bytes / 1024).toFixed(1)} KiB` return `${(bytes / (1024 * 1024)).toFixed(1)} MiB` }