|
| 1 | +<script setup lang="ts"> |
| 2 | +import { useMutation } from '@vue/apollo-composable'; |
| 3 | +
|
| 4 | +import gql from 'graphql-tag'; |
| 5 | +
|
| 6 | +import type { DockerContainer } from '@/composables/gql/graphql'; |
| 7 | +
|
| 8 | +interface Props { |
| 9 | + orphanedContainers: DockerContainer[]; |
| 10 | +} |
| 11 | +
|
| 12 | +const props = withDefaults(defineProps<Props>(), { |
| 13 | + orphanedContainers: () => [], |
| 14 | +}); |
| 15 | +
|
| 16 | +const emit = defineEmits<{ (e: 'refresh'): void }>(); |
| 17 | +
|
| 18 | +const REMOVE_CONTAINER = gql` |
| 19 | + mutation RemoveContainer($id: PrefixedID!) { |
| 20 | + removeContainer(id: $id) |
| 21 | + } |
| 22 | +`; |
| 23 | +
|
| 24 | +const { mutate: removeContainer, loading: removing } = useMutation(REMOVE_CONTAINER); |
| 25 | +
|
| 26 | +async function handleRemove(container: DockerContainer) { |
| 27 | + const name = container.names[0]?.replace(/^\//, '') || 'container'; |
| 28 | + if (!confirm(`Are you sure you want to remove orphaned container "${name}"?`)) return; |
| 29 | +
|
| 30 | + try { |
| 31 | + await removeContainer({ id: container.id }); |
| 32 | + emit('refresh'); |
| 33 | + } catch (e) { |
| 34 | + console.error('Failed to remove container', e); |
| 35 | + // Simple alert for now, ideally use a toast notification service |
| 36 | + alert('Failed to remove container'); |
| 37 | + } |
| 38 | +} |
| 39 | +
|
| 40 | +function formatContainerName(container: DockerContainer): string { |
| 41 | + return container.names[0]?.replace(/^\//, '') || 'Unknown'; |
| 42 | +} |
| 43 | +</script> |
| 44 | + |
| 45 | +<template> |
| 46 | + <div |
| 47 | + class="rounded-lg border border-amber-200 bg-amber-50 p-4 text-sm text-amber-900 dark:border-amber-400/50 dark:bg-amber-400/10 dark:text-amber-100" |
| 48 | + > |
| 49 | + <div class="flex items-start gap-3"> |
| 50 | + <UIcon |
| 51 | + name="i-lucide-triangle-alert" |
| 52 | + class="mt-1 h-5 w-5 flex-shrink-0 text-amber-500 dark:text-amber-300" |
| 53 | + aria-hidden="true" |
| 54 | + /> |
| 55 | + <div class="w-full space-y-3"> |
| 56 | + <div> |
| 57 | + <p class="text-sm font-semibold"> |
| 58 | + Orphaned containers detected ({{ orphanedContainers.length }}) |
| 59 | + </p> |
| 60 | + <p class="text-xs text-amber-900/80 dark:text-amber-100/80"> |
| 61 | + These containers do not have a corresponding template. You can remove them if they are no |
| 62 | + longer needed. |
| 63 | + </p> |
| 64 | + </div> |
| 65 | + <div class="space-y-4"> |
| 66 | + <div class="space-y-2"> |
| 67 | + <div |
| 68 | + class="rounded-md border border-amber-200/70 bg-white/80 p-3 dark:border-amber-300/30 dark:bg-transparent" |
| 69 | + > |
| 70 | + <div class="mt-2 flex flex-wrap gap-2"> |
| 71 | + <button |
| 72 | + v-for="container in orphanedContainers" |
| 73 | + :key="container.id" |
| 74 | + type="button" |
| 75 | + class="inline-flex items-center gap-1 rounded-full border border-amber-300 bg-amber-100 px-2 py-1 text-xs font-medium text-amber-900 transition hover:bg-amber-200 focus-visible:ring-2 focus-visible:ring-amber-400 focus-visible:outline-none dark:border-amber-200/40 dark:bg-transparent dark:text-amber-100" |
| 76 | + :title="`Remove ${formatContainerName(container)}`" |
| 77 | + :disabled="removing" |
| 78 | + @click="handleRemove(container)" |
| 79 | + > |
| 80 | + <span>{{ formatContainerName(container) }}</span> |
| 81 | + <UIcon name="i-lucide-trash-2" class="h-3.5 w-3.5" aria-hidden="true" /> |
| 82 | + </button> |
| 83 | + </div> |
| 84 | + </div> |
| 85 | + </div> |
| 86 | + </div> |
| 87 | + </div> |
| 88 | + </div> |
| 89 | + </div> |
| 90 | +</template> |
0 commit comments