forked from verdnatura/salix-front
perf: optimize get packing type function
This commit is contained in:
parent
4bde0dffa7
commit
1daa8be635
|
@ -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>
|
||||
|
||||
|
|
Loading…
Reference in New Issue