feat : creation du composant datatable (WIP)

This commit is contained in:
2026-02-17 14:52:23 +01:00
parent 850e412840
commit 74de31721c
15 changed files with 355 additions and 567 deletions

View File

@@ -4,7 +4,7 @@ export const formatBovinShipments = (value: unknown): string => {
const label = item?.shipmentType?.label ?? item?.shipmentType?.code ??
'Type inconnu'
const qty = item?.nbBovinSend ?? '-'
return `${label} (${qty})`
return `${label} : ${qty}`
}).join(', ')
}
@@ -13,29 +13,53 @@ export const formatWeights = (value: unknown): string => {
return value
.map((item: any) => {
const type = item?.type === 'tare'
? 'Poids à vide'
: item?.type === 'gross'
? 'Poids à plein'
: (item?.type ?? 'Poids')
const type = item?.type === 'tare' ? 'Poids à vide': item?.type === 'gross' ? 'Poids à plein': (item?.type ?? 'Poids')
const weight = item?.weight ?? '-'
return `${type}: ${weight}`
})
.join('\n ')
}
export const formatRoleLabels = (
value: unknown,
roleLabelByValue: Map<string, string>,
): string => {
if (!Array.isArray(value) || value.length === 0) {
return ' - '
}
return value
.map((role) => {
const key = String(role)
return roleLabelByValue.get(key) ?? key
})
.join(', ')
}
export const formatPelletBuildings = (value: unknown): string => {
if (!Array.isArray(value) || value.length === 0) return '-'
export const formatAddresses = (value: unknown): string => {
if (!Array.isArray(value) || value.length === 0) {
return " - "
}
if (typeof value[0] === 'string') {
return 'Adresses non chargées'
}
return value
.map((item: any) => {
const pelletLabel =
item?.pelletType?.label ?? item?.pelletType?.code ?? 'Granule inconnu'
const buildingLabel =
item?.building?.label ?? item?.building?.code ?? 'Bâtiment inconnu'
.map((item) => {
if (!item || typeof item !== 'object') return '-'
const address = item as Record<string, unknown>
const street = String(address.street ?? '').trim()
const street2 = String(address.street2 ?? '').trim()
const postalCode = String(address.postalCode ?? '').trim()
const city = String(address.city ?? '').trim()
const countryCode = String(address.countryCode ?? '').trim().toUpperCase()
return `${pelletLabel} : ${buildingLabel}`
const firstLine = [street, street2].filter(Boolean).join(', ')
const secondLine = [postalCode, city].filter(Boolean).join(' ')
const finalLine = [firstLine, secondLine, countryCode].filter(Boolean).join(', ')
return finalLine || '-'
})
.join('\n')
}