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:
19
app/shared/utils/deleteImpactUtils.ts
Normal file
19
app/shared/utils/deleteImpactUtils.ts
Normal file
@@ -0,0 +1,19 @@
|
||||
export const resolveDeleteImpact = (entity: Record<string, any>): string[] => {
|
||||
const impacts: string[] = []
|
||||
const machineLinks = Array.isArray(entity?.machineLinks) ? entity.machineLinks.length : entity?.machineLinksCount ?? 0
|
||||
const documents = Array.isArray(entity?.documents) ? entity.documents.length : entity?.documentsCount ?? 0
|
||||
const customFields = Array.isArray(entity?.customFieldValues) ? entity.customFieldValues.length : entity?.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
|
||||
}
|
||||
|
||||
export const buildDeleteMessage = (entityName: string, impacts: string[]): string => {
|
||||
const lines = [`Voulez-vous vraiment supprimer « ${entityName} » ?`]
|
||||
if (impacts.length) {
|
||||
lines.push(`Cela supprimera également :\n• ${impacts.join('\n• ')}`)
|
||||
}
|
||||
lines.push('Cette action est irréversible.')
|
||||
return lines.join('\n\n')
|
||||
}
|
||||
Reference in New Issue
Block a user