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) => {
if (!ticketSales || ticketSales.length === 0) return '-';
if (!ticketSales?.length) return '-';
const packagingTypes = ticketSales
.map((sale) => sale.item?.itemPackingTypeFk)
.filter((type) => type !== undefined && type !== null);
const packagingTypes = ticketSales.reduce((types, sale) => {
const { itemPackingTypeFk } = sale.item;
if (
!types.includes(itemPackingTypeFk) &&
(itemPackingTypeFk === 'H' || itemPackingTypeFk === 'V')
) {
types.push(itemPackingTypeFk);
}
return types;
}, []);
const uniquePackagingTypes = [...new Set(packagingTypes)];
return dashIfEmpty(
uniquePackagingTypes.length > 0 ? uniquePackagingTypes.join(', ') : '-'
);
return dashIfEmpty(packagingTypes.join(', ') || '-');
};
</script>