Skip to content

Modern Docker Management, Designed for Everyone

3.1 KB
Raw Blame
<script lang="ts">
	import { Badge } from '#lib/components/ui/badge/index.js';
	import { Progress } from '#lib/components/ui/progress/index.js';
	import { ArrowDownIcon } from '#lib/icons/index.js';
	import { m } from '#lib/paraglide/messages.js';
	import type { ActivityBatchGroup } from '#lib/types/activity.type.js';
	import { cn } from '#lib/utils.js';

	import {
		activityStatusAccentClass,
		activityStatusLabel,
		activityRunStatusLabel,
		activityStatusVariant,
		activityTypeIcon,
		activityTypeLabel
	} from './activity-labels';

	let {
		group,
		expanded = false
	}: {
		group: ActivityBatchGroup;
		expanded?: boolean;
	} = $props();

	// Batch groups are constructed with at least one member.
	const jobActivity = $derived(group.items.find((item) => item.type === 'job_run'));
	const leadActivity = $derived(jobActivity ?? group.items[0]!);
	const IconComponent = $derived(activityTypeIcon(leadActivity.type));
	const isActive = $derived(group.status === 'running' || group.status === 'queued');
</script>

<div
	class={cn(
		'group relative grid w-full grid-cols-icon-content-action items-start gap-3 border-b border-border/40 px-4 py-3 text-left transition-colors last:border-b-0 hover:bg-muted/30',
		expanded && 'bg-muted/40'
	)}
>
	<span
		aria-hidden="true"
		class={cn(
			'absolute top-2 bottom-2 left-0 rounded-r-full transition-all',
			activityStatusAccentClass(group.status),
			expanded ? 'w-1' : 'w-0.5'
		)}
	></span>

	<div
		class={cn(
			'mt-0.5 flex size-8 items-center justify-center rounded-md bg-muted/80 text-muted-foreground',
			(isActive || expanded) && 'bg-primary/10 text-primary'
		)}
	>
		<IconComponent class="size-4" aria-hidden="true" />
	</div>
	<div class="min-w-0 space-y-1.5">
		<div class="flex min-w-0 items-start justify-between gap-3">
			<div class="min-w-0 flex-1">
				<div class="flex min-w-0 items-center gap-2">
					<span class="truncate text-sm font-semibold text-foreground">{activityTypeLabel(leadActivity.type)}</span>
					<span class="shrink-0 text-2xs text-muted-foreground/70">· {m.activity_batch_items({ count: group.total })}</span>
				</div>
				{#if jobActivity?.resourceName}<div class="truncate text-xs text-muted-foreground">{jobActivity.resourceName}</div>{/if}
				<div class="flex min-w-0 flex-wrap items-center gap-x-1.5 text-xs text-muted-foreground">
					<span>{m.activity_batch_done_of_total({ done: group.done, total: group.total })}</span>
					{#if group.failed > 0}
						<span class="text-muted-foreground/50">·</span>
						<span class="text-destructive">{m.activity_batch_failed_count({ count: group.failed })}</span>
					{/if}
				</div>
			</div>
			<Badge variant={activityStatusVariant(group.status)} size="sm"
				>{jobActivity ? activityRunStatusLabel(jobActivity) : activityStatusLabel(group.status)}</Badge
			>
		</div>

		{#if isActive}
			<Progress value={100} indeterminate class="h-1.5" />
		{/if}
	</div>

	<div class="mt-1 flex size-6 shrink-0 items-center justify-center text-muted-foreground">
		<ArrowDownIcon class={cn('size-4 transition-transform duration-200', expanded && 'rotate-180')} aria-hidden="true" />
	</div>
</div>