feat: supprimer automatiquement les valeurs de champs si besoin
This commit is contained in:
@@ -180,8 +180,8 @@ const resolvePreviewAlt = (component: Record<string, any>) => {
|
|||||||
return 'Aperçu du document'
|
return 'Aperçu du document'
|
||||||
}
|
}
|
||||||
|
|
||||||
const resolveDeleteBlockingReasons = (component: Record<string, any>) => {
|
const resolveDeleteGuard = (component: Record<string, any>) => {
|
||||||
const reasons: string[] = []
|
const blockingReasons: string[] = []
|
||||||
const machineLinks = Array.isArray(component?.machineLinks)
|
const machineLinks = Array.isArray(component?.machineLinks)
|
||||||
? component.machineLinks.length
|
? component.machineLinks.length
|
||||||
: component?.machineLinksCount ?? 0
|
: component?.machineLinksCount ?? 0
|
||||||
@@ -193,15 +193,15 @@ const resolveDeleteBlockingReasons = (component: Record<string, any>) => {
|
|||||||
: component?.customFieldValuesCount ?? 0
|
: component?.customFieldValuesCount ?? 0
|
||||||
|
|
||||||
if (machineLinks > 0) {
|
if (machineLinks > 0) {
|
||||||
reasons.push(`${machineLinks} liaison${machineLinks > 1 ? 's' : ''} machine`)
|
blockingReasons.push(`${machineLinks} liaison${machineLinks > 1 ? 's' : ''} machine`)
|
||||||
}
|
}
|
||||||
if (documents > 0) {
|
if (documents > 0) {
|
||||||
reasons.push(`${documents} document${documents > 1 ? 's' : ''}`)
|
blockingReasons.push(`${documents} document${documents > 1 ? 's' : ''}`)
|
||||||
}
|
}
|
||||||
if (customFields > 0) {
|
return {
|
||||||
reasons.push(`${customFields} valeur${customFields > 1 ? 's' : ''} de champ personnalisé`)
|
blockingReasons,
|
||||||
|
hasCustomFields: customFields > 0,
|
||||||
}
|
}
|
||||||
return reasons
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const resolveComparableName = (component: Record<string, any>) => {
|
const resolveComparableName = (component: Record<string, any>) => {
|
||||||
@@ -259,7 +259,7 @@ const visibleComposants = computed(() => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
const handleDeleteComponent = async (component: Record<string, any>) => {
|
const handleDeleteComponent = async (component: Record<string, any>) => {
|
||||||
const blockingReasons = resolveDeleteBlockingReasons(component)
|
const { blockingReasons, hasCustomFields } = resolveDeleteGuard(component)
|
||||||
|
|
||||||
if (blockingReasons.length) {
|
if (blockingReasons.length) {
|
||||||
showError(
|
showError(
|
||||||
@@ -271,7 +271,16 @@ const handleDeleteComponent = async (component: Record<string, any>) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const componentName = component?.name || 'ce composant'
|
const componentName = component?.name || 'ce composant'
|
||||||
const confirmed = window.confirm(`Voulez-vous vraiment supprimer ${componentName} ?`)
|
const confirmLines = [
|
||||||
|
`Voulez-vous vraiment supprimer ${componentName} ?`,
|
||||||
|
]
|
||||||
|
if (hasCustomFields) {
|
||||||
|
confirmLines.push(
|
||||||
|
'Les valeurs de champs personnalisés associées seront également supprimées.'
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
const confirmed = window.confirm(confirmLines.join('\n\n'))
|
||||||
if (!confirmed) {
|
if (!confirmed) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -182,8 +182,8 @@ const resolvePreviewAlt = (piece: Record<string, any>) => {
|
|||||||
return 'Aperçu du document'
|
return 'Aperçu du document'
|
||||||
}
|
}
|
||||||
|
|
||||||
const resolveDeleteBlockingReasons = (piece: Record<string, any>) => {
|
const resolveDeleteGuard = (piece: Record<string, any>) => {
|
||||||
const reasons: string[] = []
|
const blockingReasons: string[] = []
|
||||||
const machineLinks = Array.isArray(piece?.machineLinks)
|
const machineLinks = Array.isArray(piece?.machineLinks)
|
||||||
? piece.machineLinks.length
|
? piece.machineLinks.length
|
||||||
: piece?.machineLinksCount ?? 0
|
: piece?.machineLinksCount ?? 0
|
||||||
@@ -195,15 +195,15 @@ const resolveDeleteBlockingReasons = (piece: Record<string, any>) => {
|
|||||||
: piece?.customFieldValuesCount ?? 0
|
: piece?.customFieldValuesCount ?? 0
|
||||||
|
|
||||||
if (machineLinks > 0) {
|
if (machineLinks > 0) {
|
||||||
reasons.push(`${machineLinks} liaison${machineLinks > 1 ? 's' : ''} machine`)
|
blockingReasons.push(`${machineLinks} liaison${machineLinks > 1 ? 's' : ''} machine`)
|
||||||
}
|
}
|
||||||
if (documents > 0) {
|
if (documents > 0) {
|
||||||
reasons.push(`${documents} document${documents > 1 ? 's' : ''}`)
|
blockingReasons.push(`${documents} document${documents > 1 ? 's' : ''}`)
|
||||||
}
|
}
|
||||||
if (customFields > 0) {
|
return {
|
||||||
reasons.push(`${customFields} valeur${customFields > 1 ? 's' : ''} de champ personnalisé`)
|
blockingReasons,
|
||||||
|
hasCustomFields: customFields > 0,
|
||||||
}
|
}
|
||||||
return reasons
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const resolveComparableName = (piece: Record<string, any>) => {
|
const resolveComparableName = (piece: Record<string, any>) => {
|
||||||
@@ -261,7 +261,7 @@ const visiblePieces = computed(() => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
const handleDeletePiece = async (piece: Record<string, any>) => {
|
const handleDeletePiece = async (piece: Record<string, any>) => {
|
||||||
const blockingReasons = resolveDeleteBlockingReasons(piece)
|
const { blockingReasons, hasCustomFields } = resolveDeleteGuard(piece)
|
||||||
|
|
||||||
if (blockingReasons.length) {
|
if (blockingReasons.length) {
|
||||||
showError(
|
showError(
|
||||||
@@ -273,7 +273,17 @@ const handleDeletePiece = async (piece: Record<string, any>) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const pieceName = piece?.name || 'cette pièce'
|
const pieceName = piece?.name || 'cette pièce'
|
||||||
const confirmed = window.confirm(`Voulez-vous vraiment supprimer ${pieceName} ?`)
|
const confirmLines = [
|
||||||
|
`Voulez-vous vraiment supprimer ${pieceName} ?`,
|
||||||
|
]
|
||||||
|
|
||||||
|
if (hasCustomFields) {
|
||||||
|
confirmLines.push(
|
||||||
|
'Les valeurs de champs personnalisés associées seront également supprimées.'
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
const confirmed = window.confirm(confirmLines.join('\n\n'))
|
||||||
if (!confirmed) {
|
if (!confirmed) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user