fix: afficher le détail des blocages avant suppression
This commit is contained in:
@@ -180,6 +180,30 @@ const resolvePreviewAlt = (component: Record<string, any>) => {
|
||||
return 'Aperçu du document'
|
||||
}
|
||||
|
||||
const resolveDeleteBlockingReasons = (component: Record<string, any>) => {
|
||||
const reasons: string[] = []
|
||||
const machineLinks = Array.isArray(component?.machineLinks)
|
||||
? component.machineLinks.length
|
||||
: component?.machineLinksCount ?? 0
|
||||
const documents = Array.isArray(component?.documents)
|
||||
? component.documents.length
|
||||
: component?.documentsCount ?? 0
|
||||
const customFields = Array.isArray(component?.customFieldValues)
|
||||
? component.customFieldValues.length
|
||||
: component?.customFieldValuesCount ?? 0
|
||||
|
||||
if (machineLinks > 0) {
|
||||
reasons.push(`${machineLinks} liaison${machineLinks > 1 ? 's' : ''} machine`)
|
||||
}
|
||||
if (documents > 0) {
|
||||
reasons.push(`${documents} document${documents > 1 ? 's' : ''}`)
|
||||
}
|
||||
if (customFields > 0) {
|
||||
reasons.push(`${customFields} valeur${customFields > 1 ? 's' : ''} de champ personnalisé`)
|
||||
}
|
||||
return reasons
|
||||
}
|
||||
|
||||
const resolveComparableName = (component: Record<string, any>) => {
|
||||
const toComparable = (value?: string | null) =>
|
||||
(value ?? '').toString().trim().toLowerCase()
|
||||
@@ -235,13 +259,14 @@ const visibleComposants = computed(() => {
|
||||
})
|
||||
|
||||
const handleDeleteComponent = async (component: Record<string, any>) => {
|
||||
const hasLinkedElements =
|
||||
(component?.machineLinks?.length ?? 0) > 0 ||
|
||||
(component?.documents?.length ?? 0) > 0 ||
|
||||
(component?.customFieldValues?.length ?? 0) > 0
|
||||
const blockingReasons = resolveDeleteBlockingReasons(component)
|
||||
|
||||
if (hasLinkedElements) {
|
||||
showError('Impossible de supprimer ce composant car il possède des éléments liés.')
|
||||
if (blockingReasons.length) {
|
||||
showError(
|
||||
`Impossible de supprimer ce composant car il possède encore: ${blockingReasons.join(
|
||||
', ',
|
||||
)}. Supprimez ou détachez ces éléments avant de réessayer.`
|
||||
)
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
@@ -182,6 +182,30 @@ const resolvePreviewAlt = (piece: Record<string, any>) => {
|
||||
return 'Aperçu du document'
|
||||
}
|
||||
|
||||
const resolveDeleteBlockingReasons = (piece: Record<string, any>) => {
|
||||
const reasons: string[] = []
|
||||
const machineLinks = Array.isArray(piece?.machineLinks)
|
||||
? piece.machineLinks.length
|
||||
: piece?.machineLinksCount ?? 0
|
||||
const documents = Array.isArray(piece?.documents)
|
||||
? piece.documents.length
|
||||
: piece?.documentsCount ?? 0
|
||||
const customFields = Array.isArray(piece?.customFieldValues)
|
||||
? piece.customFieldValues.length
|
||||
: piece?.customFieldValuesCount ?? 0
|
||||
|
||||
if (machineLinks > 0) {
|
||||
reasons.push(`${machineLinks} liaison${machineLinks > 1 ? 's' : ''} machine`)
|
||||
}
|
||||
if (documents > 0) {
|
||||
reasons.push(`${documents} document${documents > 1 ? 's' : ''}`)
|
||||
}
|
||||
if (customFields > 0) {
|
||||
reasons.push(`${customFields} valeur${customFields > 1 ? 's' : ''} de champ personnalisé`)
|
||||
}
|
||||
return reasons
|
||||
}
|
||||
|
||||
const resolveComparableName = (piece: Record<string, any>) => {
|
||||
const normalise = (value?: string | null) =>
|
||||
(value ?? '').toString().trim().toLowerCase()
|
||||
@@ -237,13 +261,14 @@ const visiblePieces = computed(() => {
|
||||
})
|
||||
|
||||
const handleDeletePiece = async (piece: Record<string, any>) => {
|
||||
const hasLinkedElements =
|
||||
(piece?.machineLinks?.length ?? 0) > 0 ||
|
||||
(piece?.documents?.length ?? 0) > 0 ||
|
||||
(piece?.customFieldValues?.length ?? 0) > 0
|
||||
const blockingReasons = resolveDeleteBlockingReasons(piece)
|
||||
|
||||
if (hasLinkedElements) {
|
||||
showError('Impossible de supprimer cette pièce car elle possède des éléments liés.')
|
||||
if (blockingReasons.length) {
|
||||
showError(
|
||||
`Impossible de supprimer cette pièce car elle possède encore: ${blockingReasons.join(
|
||||
', ',
|
||||
)}. Supprimez ou détachez ces éléments avant de réessayer.`
|
||||
)
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user