0
0
Fork 0

perf: optimize get packing type function

This commit is contained in:
Jon Elias 2024-10-25 09:41:28 +02:00
parent 4bde0dffa7
commit 1daa8be635
1 changed files with 12 additions and 9 deletions

View File

@ -152,17 +152,20 @@ const setShippedColor = (date) => {
}; };
const getItemPackagingType = (ticketSales) => { const getItemPackagingType = (ticketSales) => {
if (!ticketSales || ticketSales.length === 0) return '-'; if (!ticketSales?.length) return '-';
const packagingTypes = ticketSales const packagingTypes = ticketSales.reduce((types, sale) => {
.map((sale) => sale.item?.itemPackingTypeFk) const { itemPackingTypeFk } = sale.item;
.filter((type) => type !== undefined && type !== null); if (
!types.includes(itemPackingTypeFk) &&
(itemPackingTypeFk === 'H' || itemPackingTypeFk === 'V')
) {
types.push(itemPackingTypeFk);
}
return types;
}, []);
const uniquePackagingTypes = [...new Set(packagingTypes)]; return dashIfEmpty(packagingTypes.join(', ') || '-');
return dashIfEmpty(
uniquePackagingTypes.length > 0 ? uniquePackagingTypes.join(', ') : '-'
);
}; };
</script> </script>