refactor(catalog) : extract shared delete impact logic and cleanup dead code

Extract duplicated resolveDeleteImpact/buildDeleteMessage into shared utility,
remove redundant computed wrappers, fix indentation, and remove dead code.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-03-08 01:35:21 +01:00
parent 592beb0fa7
commit 7b3eb1c5fc
6 changed files with 98 additions and 143 deletions

View File

@@ -36,7 +36,7 @@
v-else
:columns="columns"
:rows="productRows"
:loading="loadingProducts"
:loading="loading"
:sort="table.sort.value"
:pagination="paginationState"
:column-filters="table.columnFilters.value"
@@ -148,6 +148,7 @@ import { useToast } from '~/composables/useToast'
import { useDataTable } from '~/composables/useDataTable'
import DocumentThumbnail from '~/components/DocumentThumbnail.vue'
import { isImageDocument, isPdfDocument } from '~/utils/documentPreview'
import { resolveDeleteImpact, buildDeleteMessage } from '~/shared/utils/deleteImpactUtils'
const { canEdit } = usePermissions()
@@ -169,7 +170,6 @@ const table = useDataTable(
{ defaultSort: 'name', defaultDirection: 'asc', defaultPerPage: 20, persistToUrl: true },
)
const loadingProducts = computed(() => loading.value)
const errorMessage = computed(() => (typeof error.value === 'string' && error.value.length ? error.value : null))
const columns = [
@@ -296,26 +296,10 @@ const reload = () => fetchProducts()
const { confirm } = useConfirm()
const resolveDeleteImpact = (product: Record<string, any>) => {
const impacts: string[] = []
const machineLinks = Array.isArray(product?.machineLinks) ? product.machineLinks.length : product?.machineLinksCount ?? 0
const documents = Array.isArray(product?.documents) ? product.documents.length : product?.documentsCount ?? 0
const customFields = Array.isArray(product?.customFieldValues) ? product.customFieldValues.length : product?.customFieldValuesCount ?? 0
if (machineLinks > 0) impacts.push(`${machineLinks} liaison${machineLinks > 1 ? 's' : ''} machine`)
if (documents > 0) impacts.push(`${documents} document${documents > 1 ? 's' : ''}`)
if (customFields > 0) impacts.push(`${customFields} valeur${customFields > 1 ? 's' : ''} de champs personnalisés`)
return impacts
}
const confirmDelete = async (product: Record<string, any>) => {
const productName = product?.name || 'ce produit'
const impacts = resolveDeleteImpact(product)
const lines = [`Voulez-vous vraiment supprimer « ${productName} » ?`]
if (impacts.length) {
lines.push(`Cela supprimera également :\n• ${impacts.join('\n• ')}`)
}
lines.push('Cette action est irréversible.')
const confirmed = await confirm({ title: 'Supprimer le produit', message: lines.join('\n\n'), dangerous: true })
const message = buildDeleteMessage(productName, resolveDeleteImpact(product))
const confirmed = await confirm({ title: 'Supprimer le produit', message, dangerous: true })
if (!confirmed) return
const result = await deleteProduct(product.id)
if (result.success) {