Preserve pick list item ordering by creation time
This commit is contained in:
@@ -78,25 +78,20 @@ export const ActivePickListScreen = () => {
|
|||||||
|
|
||||||
const sortedItems = useMemo(() => {
|
const sortedItems = useMemo(() => {
|
||||||
return [...itemsVisibleByStatus].sort((a, b) => {
|
return [...itemsVisibleByStatus].sort((a, b) => {
|
||||||
|
const timeA = a.created_at ?? 0;
|
||||||
|
const timeB = b.created_at ?? 0;
|
||||||
|
|
||||||
|
if (timeA !== timeB) {
|
||||||
|
return timeA - timeB;
|
||||||
|
}
|
||||||
|
|
||||||
const productA = productMap.get(a.product_id);
|
const productA = productMap.get(a.product_id);
|
||||||
const productB = productMap.get(b.product_id);
|
const productB = productMap.get(b.product_id);
|
||||||
|
|
||||||
const nameA = productA?.name.trim().toLowerCase() ?? '';
|
const nameA = productA?.name.trim().toLowerCase() ?? '';
|
||||||
const nameB = productB?.name.trim().toLowerCase() ?? '';
|
const nameB = productB?.name.trim().toLowerCase() ?? '';
|
||||||
|
|
||||||
const nameComparison = nameA.localeCompare(nameB, undefined, { sensitivity: 'base' });
|
return nameA.localeCompare(nameB, undefined, { sensitivity: 'base' });
|
||||||
if (nameComparison !== 0) {
|
|
||||||
return nameComparison;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (a.is_carton !== b.is_carton) {
|
|
||||||
return a.is_carton ? 1 : -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
const timeA = a.updated_at ?? a.created_at;
|
|
||||||
const timeB = b.updated_at ?? b.created_at;
|
|
||||||
|
|
||||||
return timeA - timeB;
|
|
||||||
});
|
});
|
||||||
}, [itemsVisibleByStatus, productMap]);
|
}, [itemsVisibleByStatus, productMap]);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user